-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
SkinCompatAutoCompleteTextView.java
116 lines (99 loc) · 4.08 KB
/
SkinCompatAutoCompleteTextView.java
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package skin.support.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import androidx.annotation.DrawableRes;
import androidx.appcompat.widget.AppCompatAutoCompleteTextView;
import android.util.AttributeSet;
import skin.support.appcompat.R;
import skin.support.content.res.SkinCompatVectorResources;
import static skin.support.widget.SkinCompatHelper.INVALID_ID;
/**
* Created by ximsfei on 2017/1/13.
*/
public class SkinCompatAutoCompleteTextView extends AppCompatAutoCompleteTextView implements SkinCompatSupportable {
private static final int[] TINT_ATTRS = {
android.R.attr.popupBackground
};
private int mDropDownBackgroundResId = INVALID_ID;
private SkinCompatTextHelper mTextHelper;
private SkinCompatBackgroundHelper mBackgroundTintHelper;
public SkinCompatAutoCompleteTextView(Context context) {
this(context, null);
}
public SkinCompatAutoCompleteTextView(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.autoCompleteTextViewStyle);
}
public SkinCompatAutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray a = context.obtainStyledAttributes(attrs, TINT_ATTRS, defStyleAttr, 0);
if (a.hasValue(0)) {
mDropDownBackgroundResId = a.getResourceId(0, INVALID_ID);
}
a.recycle();
applyDropDownBackgroundResource();
mBackgroundTintHelper = new SkinCompatBackgroundHelper(this);
mBackgroundTintHelper.loadFromAttributes(attrs, defStyleAttr);
mTextHelper = SkinCompatTextHelper.create(this);
mTextHelper.loadFromAttributes(attrs, defStyleAttr);
}
@Override
public void setDropDownBackgroundResource(@DrawableRes int resId) {
super.setDropDownBackgroundResource(resId);
mDropDownBackgroundResId = resId;
applyDropDownBackgroundResource();
}
private void applyDropDownBackgroundResource() {
mDropDownBackgroundResId = SkinCompatHelper.checkResourceId(mDropDownBackgroundResId);
if (mDropDownBackgroundResId != INVALID_ID) {
Drawable drawable = SkinCompatVectorResources.getDrawableCompat(getContext(), mDropDownBackgroundResId);
if (drawable != null) {
setDropDownBackgroundDrawable(drawable);
}
}
}
@Override
public void setBackgroundResource(@DrawableRes int resId) {
super.setBackgroundResource(resId);
if (mBackgroundTintHelper != null) {
mBackgroundTintHelper.onSetBackgroundResource(resId);
}
}
@Override
public void setTextAppearance(int resId) {
setTextAppearance(getContext(), resId);
}
@Override
public void setTextAppearance(Context context, int resId) {
super.setTextAppearance(context, resId);
if (mTextHelper != null) {
mTextHelper.onSetTextAppearance(context, resId);
}
}
@Override
public void setCompoundDrawablesRelativeWithIntrinsicBounds(
@DrawableRes int start, @DrawableRes int top, @DrawableRes int end, @DrawableRes int bottom) {
super.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom);
if (mTextHelper != null) {
mTextHelper.onSetCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom);
}
}
@Override
public void setCompoundDrawablesWithIntrinsicBounds(
@DrawableRes int left, @DrawableRes int top, @DrawableRes int right, @DrawableRes int bottom) {
super.setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom);
if (mTextHelper != null) {
mTextHelper.onSetCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom);
}
}
@Override
public void applySkin() {
if (mBackgroundTintHelper != null) {
mBackgroundTintHelper.applySkin();
}
if (mTextHelper != null) {
mTextHelper.applySkin();
}
applyDropDownBackgroundResource();
}
}