<commit_before>package com.WazaBe.HoloEverywhere.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build.VERSION;
import android.util.AttributeSet;

import com.WazaBe.HoloEverywhere.R;

public class TextView extends android.widget.TextView {
    private boolean allCaps = false;
    private CharSequence originalText;
    private BufferType originalType;
    private String fontFamily;

    public TextView(Context context) {
        this(context, null);
    }

    public TextView(Context context, AttributeSet attrs) {
        this(context, attrs, android.R.attr.textViewStyle);
    }

    public TextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        int[] attrsArray = new int[] {
                android.R.attr.textAppearance, // 0
        };
        TypedArray ta = context.obtainStyledAttributes(attrs, attrsArray);
        int ap = ta.getResourceId(0, -1);
        TypedArray appearance = null;
        if (ap != -1) {
            appearance = context.obtainStyledAttributes(ap, R.styleable.TextAppearance);
        }
        if (appearance != null) {
            int n = appearance.getIndexCount();
            for (int i = 0; i < n; i++) {
                int attr = appearance.getIndex(i);
                switch (attr) {
                case R.styleable.TextAppearance_android_fontFamily:
                    fontFamily = appearance.getString(attr);
                    break;
                }
            }
            appearance.recycle();
        }
        ta.recycle();

        TypedArray a = getContext().obtainStyledAttributes(attrs,
                R.styleable.TextView, defStyle, 0);
        if (a.hasValue(R.styleable.TextView_android_textAllCaps)) {
            allCaps = a.getBoolean(R.styleable.TextView_android_textAllCaps,
                    false);
        } else {
            allCaps = a.getBoolean(R.styleable.TextView_textAllCaps, false);
        }
        CharSequence text = null;
        if (a.hasValue(R.styleable.TextView_android_text)) {
            text = a.getText(R.styleable.TextView_android_text);
        }

        if (a.hasValue(R.styleable.TextView_android_fontFamily)) {
            fontFamily = a.getString(R.styleable.TextView_android_fontFamily);
        }
        a.recycle();
        if (text != null) {
            setText(text);
        }<commit_msg>improved font family parsing<commit_after>package com.WazaBe.HoloEverywhere.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build.VERSION;
import android.text.TextUtils;
import android.util.AttributeSet;

import com.WazaBe.HoloEverywhere.FontLoader;
import com.WazaBe.HoloEverywhere.R;

public class TextView extends android.widget.TextView {
    private boolean allCaps = false;
    private CharSequence originalText;
    private BufferType originalType;
    private String fontFamily;

    public TextView(Context context) {
        this(context, null);
    }

    public TextView(Context context, AttributeSet attrs) {
        this(context, attrs, android.R.attr.textViewStyle);
    }

    public TextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        int[] attrsArray = new int[] {
                android.R.attr.textAppearance, // 0
        };
        TypedArray ta = context.obtainStyledAttributes(attrs, attrsArray,
                android.R.attr.textViewStyle, defStyle);
        int ap = ta.getResourceId(0, -1);
        TypedArray appearance = null;
        if (ap != -1) {
            appearance = context.obtainStyledAttributes(ap, R.styleable.TextAppearance);
        }
        if (appearance != null) {
            int n = appearance.getIndexCount();
            for (int i = 0; i < n; i++) {
                int attr = appearance.getIndex(i);
                switch (attr) {
                case R.styleable.TextAppearance_android_fontFamily:
                    fontFamily = appearance.getString(attr);
                    break;
                }
            }
            appearance.recycle();
        }
        ta.recycle();

        TypedArray a = getContext().obtainStyledAttributes(attrs,
                R.styleable.TextView, defStyle, 0);
        if (a.hasValue(R.styleable.TextView_android_textAllCaps)) {
            allCaps = a.getBoolean(R.styleable.TextView_android_textAllCaps,
                    false);
        } else {
            allCaps = a.getBoolean(R.styleable.TextView_textAllCaps, false);
        }
        CharSequence text = null;
        if (a.hasValue(R.styleable.TextView_android_text)) {
            text = a.getText(R.styleable.TextView_android_text);
        }

        if (a.hasValue(R.styleable.TextView_android_fontFamily)) {
            fontFamily = a.getString(R.styleable.TextView_android_fontFamily);
        }
        a.recycle();
        if (text != null) {
            setText(text);
        }
    }

    @Override
    public void setTextAppearance(Context context, int resid) {
        super.setTextAppearance(context, resid);
        TypedArray appearance =
                context.obtainStyledAttributes(resid,
                        R.styleable.TextAppearance);
        if (appearance != null) {
            String newFontFamily = null;
            int n = appearance.getIndexCount();
            for (int i = 0; i < n; i++) {
                int attr = appearance.getIndex(i);
                switch (attr) {
                case R.styleable.TextAppearance_android_fontFamily:
                    newFontFamily = appearance.getString(attr);
                    break;
                }

                if (!TextUtils.equals(newFontFamily, fontFamily)) {
                    FontLoader.apply(this);
                }
            }
            appearance.recycle();
        }
{'fraction_non_alphanumeric': 0.09717076456719434, 'fraction_numerical': 0.0021892893230043785, 'mean_word_length': 2.051901336073998, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3953318', 'n_tokens_mistral': 1662, 'n_tokens_neox': 1628, 'n_words': 321}