1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
package ml.docilealligator.infinityforreddit.customviews;
import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.preference.EditTextPreference;
import androidx.preference.PreferenceViewHolder;
import ml.docilealligator.infinityforreddit.CustomFontReceiver;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapperReceiver;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
public class CustomFontEditTextPreference extends EditTextPreference implements CustomFontReceiver, CustomThemeWrapperReceiver {
private CustomThemeWrapper customThemeWrapper;
private Typeface typeface;
public CustomFontEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public CustomFontEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public CustomFontEditTextPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomFontEditTextPreference(Context context) {
super(context);
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
View iconImageView = holder.findViewById(android.R.id.icon);
View titleTextView = holder.findViewById(android.R.id.title);
View summaryTextView = holder.findViewById(android.R.id.summary);
if (customThemeWrapper != null) {
if (iconImageView instanceof ImageView) {
if (isEnabled()) {
((ImageView) iconImageView).setColorFilter(customThemeWrapper.getPrimaryIconColor(), android.graphics.PorterDuff.Mode.SRC_IN);
} else {
((ImageView) iconImageView).setColorFilter(customThemeWrapper.getSecondaryTextColor(), android.graphics.PorterDuff.Mode.SRC_IN);
}
}
if (titleTextView instanceof TextView) {
((TextView) titleTextView).setTextColor(customThemeWrapper.getPrimaryTextColor());
}
if (summaryTextView instanceof TextView) {
((TextView) summaryTextView).setTextColor(customThemeWrapper.getSecondaryTextColor());
}
}
if (typeface != null) {
if (titleTextView instanceof TextView) {
((TextView) titleTextView).setTypeface(typeface);
}
if (summaryTextView instanceof TextView) {
((TextView) summaryTextView).setTypeface(typeface);
}
}
}
@Override
public void setCustomFont(Typeface typeface, Typeface titleTypeface, Typeface contentTypeface) {
this.typeface = typeface;
}
@Override
public void setCustomThemeWrapper(CustomThemeWrapper customThemeWrapper) {
this.customThemeWrapper = customThemeWrapper;
}
}
|