what-the-bank/sources/io/github/inflationx/calligraphy3/CalligraphyConfig.java

156 lines
6.0 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package io.github.inflationx.calligraphy3;
import android.text.TextUtils;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.MultiAutoCompleteTextView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.ToggleButton;
import androidx.appcompat.widget.AppCompatAutoCompleteTextView;
import androidx.appcompat.widget.AppCompatButton;
import androidx.appcompat.widget.AppCompatCheckBox;
import androidx.appcompat.widget.AppCompatCheckedTextView;
import androidx.appcompat.widget.AppCompatEditText;
import androidx.appcompat.widget.AppCompatMultiAutoCompleteTextView;
import androidx.appcompat.widget.AppCompatRadioButton;
import androidx.appcompat.widget.AppCompatTextView;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/* loaded from: classes.dex */
public class CalligraphyConfig {
private static final Map<Class<? extends TextView>, Integer> DEFAULT_STYLES;
private final Set<Class<?>> hasTypefaceViews;
private final int mAttrId;
private final Map<Class<? extends TextView>, Integer> mClassStyleAttributeMap;
private final boolean mCustomViewTypefaceSupport;
private final FontMapper mFontMapper;
private final String mFontPath;
private final boolean mIsFontSet;
static {
HashMap hashMap = new HashMap();
DEFAULT_STYLES = hashMap;
hashMap.put(TextView.class, Integer.valueOf(android.R.attr.textViewStyle));
hashMap.put(Button.class, Integer.valueOf(android.R.attr.buttonStyle));
hashMap.put(EditText.class, Integer.valueOf(android.R.attr.editTextStyle));
Integer valueOf = Integer.valueOf(android.R.attr.autoCompleteTextViewStyle);
hashMap.put(AutoCompleteTextView.class, valueOf);
hashMap.put(MultiAutoCompleteTextView.class, valueOf);
hashMap.put(CheckBox.class, Integer.valueOf(android.R.attr.checkboxStyle));
hashMap.put(RadioButton.class, Integer.valueOf(android.R.attr.radioButtonStyle));
hashMap.put(ToggleButton.class, Integer.valueOf(android.R.attr.buttonStyleToggle));
if (CalligraphyUtils.canAddV7AppCompatViews()) {
addAppCompatViews();
}
}
private static void addAppCompatViews() {
Map<Class<? extends TextView>, Integer> map = DEFAULT_STYLES;
map.put(AppCompatTextView.class, Integer.valueOf(android.R.attr.textViewStyle));
map.put(AppCompatButton.class, Integer.valueOf(android.R.attr.buttonStyle));
map.put(AppCompatEditText.class, Integer.valueOf(android.R.attr.editTextStyle));
Integer valueOf = Integer.valueOf(android.R.attr.autoCompleteTextViewStyle);
map.put(AppCompatAutoCompleteTextView.class, valueOf);
map.put(AppCompatMultiAutoCompleteTextView.class, valueOf);
map.put(AppCompatCheckBox.class, Integer.valueOf(android.R.attr.checkboxStyle));
map.put(AppCompatRadioButton.class, Integer.valueOf(android.R.attr.radioButtonStyle));
map.put(AppCompatCheckedTextView.class, Integer.valueOf(android.R.attr.checkedTextViewStyle));
}
private CalligraphyConfig(Builder builder) {
this.mIsFontSet = builder.isFontSet;
this.mFontPath = builder.fontAssetPath;
this.mAttrId = builder.attrId;
this.mCustomViewTypefaceSupport = builder.customViewTypefaceSupport;
HashMap hashMap = new HashMap(DEFAULT_STYLES);
hashMap.putAll(builder.mStyleClassMap);
this.mClassStyleAttributeMap = Collections.unmodifiableMap(hashMap);
this.hasTypefaceViews = Collections.unmodifiableSet(builder.mHasTypefaceClasses);
this.mFontMapper = builder.fontMapper;
}
public boolean isCustomViewHasTypeface(View view) {
return this.hasTypefaceViews.contains(view.getClass());
}
/* loaded from: classes.dex */
public static class Builder {
public static final int INVALID_ATTR_ID = -1;
private FontMapper fontMapper;
private boolean customViewTypefaceSupport = false;
private int attrId = R.attr.fontPath;
private boolean isFontSet = false;
private String fontAssetPath = null;
private Map<Class<? extends TextView>, Integer> mStyleClassMap = new HashMap();
private Set<Class<?>> mHasTypefaceClasses = new HashSet();
public Builder setDefaultFontPath(String str) {
this.isFontSet = !TextUtils.isEmpty(str);
this.fontAssetPath = str;
return this;
}
public Builder addCustomStyle(Class<? extends TextView> cls, int i) {
if (cls != null && i != 0) {
this.mStyleClassMap.put(cls, Integer.valueOf(i));
}
return this;
}
public Builder addCustomViewWithSetTypeface(Class<?> cls) {
this.customViewTypefaceSupport = true;
this.mHasTypefaceClasses.add(cls);
return this;
}
public CalligraphyConfig build() {
this.isFontSet = !TextUtils.isEmpty(this.fontAssetPath);
return new CalligraphyConfig(this);
}
public Builder setFontMapper(FontMapper fontMapper) {
this.fontMapper = fontMapper;
return this;
}
public Builder setFontAttrId(int i) {
this.attrId = i;
return this;
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public boolean isFontSet() {
return this.mIsFontSet;
}
public boolean isCustomViewTypefaceSupport() {
return this.mCustomViewTypefaceSupport;
}
public String getFontPath() {
return this.mFontPath;
}
public FontMapper getFontMapper() {
return this.mFontMapper;
}
/* JADX INFO: Access modifiers changed from: package-private */
public Map<Class<? extends TextView>, Integer> getClassStyles() {
return this.mClassStyleAttributeMap;
}
public int getAttrId() {
return this.mAttrId;
}
}