Move to Android N-MR1 SDK.
[android_tools.git] / sdk / sources / android-25 / android / support / v7 / widget / AppCompatMultiAutoCompleteTextView.java
blobc850f110799e84c419c213255c5cc7e6ff68ce9d
1 /*
2 * Copyright (C) 2014 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package android.support.v7.widget;
19 import android.content.Context;
20 import android.content.res.ColorStateList;
21 import android.graphics.PorterDuff;
22 import android.graphics.drawable.Drawable;
23 import android.support.annotation.DrawableRes;
24 import android.support.annotation.Nullable;
25 import android.support.annotation.RestrictTo;
26 import android.support.v4.view.TintableBackgroundView;
27 import android.support.v7.appcompat.R;
28 import android.support.v7.content.res.AppCompatResources;
29 import android.util.AttributeSet;
30 import android.widget.MultiAutoCompleteTextView;
32 import static android.support.annotation.RestrictTo.Scope.GROUP_ID;
34 /**
35 * A {@link MultiAutoCompleteTextView} which supports compatible features on older version of the
36 * platform, including:
37 * <ul>
38 * <li>Supports {@link R.attr#textAllCaps} style attribute which works back to
39 * {@link android.os.Build.VERSION_CODES#GINGERBREAD Gingerbread}.</li>
40 * <li>Allows dynamic tint of it background via the background tint methods in
41 * {@link android.support.v4.view.ViewCompat}.</li>
42 * <li>Allows setting of the background tint using {@link R.attr#backgroundTint} and
43 * {@link R.attr#backgroundTintMode}.</li>
44 * </ul>
46 * <p>This will automatically be used when you use {@link MultiAutoCompleteTextView} in your layouts.
47 * You should only need to manually use this class when writing custom views.</p>
49 public class AppCompatMultiAutoCompleteTextView extends MultiAutoCompleteTextView
50 implements TintableBackgroundView {
52 private static final int[] TINT_ATTRS = {
53 android.R.attr.popupBackground
56 private AppCompatBackgroundHelper mBackgroundTintHelper;
57 private AppCompatTextHelper mTextHelper;
59 public AppCompatMultiAutoCompleteTextView(Context context) {
60 this(context, null);
63 public AppCompatMultiAutoCompleteTextView(Context context, AttributeSet attrs) {
64 this(context, attrs, R.attr.autoCompleteTextViewStyle);
67 public AppCompatMultiAutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr) {
68 super(TintContextWrapper.wrap(context), attrs, defStyleAttr);
70 TintTypedArray a = TintTypedArray.obtainStyledAttributes(getContext(), attrs,
71 TINT_ATTRS, defStyleAttr, 0);
72 if (a.hasValue(0)) {
73 setDropDownBackgroundDrawable(a.getDrawable(0));
75 a.recycle();
77 mBackgroundTintHelper = new AppCompatBackgroundHelper(this);
78 mBackgroundTintHelper.loadFromAttributes(attrs, defStyleAttr);
80 mTextHelper = AppCompatTextHelper.create(this);
81 mTextHelper.loadFromAttributes(attrs, defStyleAttr);
82 mTextHelper.applyCompoundDrawablesTints();
85 @Override
86 public void setDropDownBackgroundResource(@DrawableRes int resId) {
87 setDropDownBackgroundDrawable(AppCompatResources.getDrawable(getContext(), resId));
90 @Override
91 public void setBackgroundResource(@DrawableRes int resId) {
92 super.setBackgroundResource(resId);
93 if (mBackgroundTintHelper != null) {
94 mBackgroundTintHelper.onSetBackgroundResource(resId);
98 @Override
99 public void setBackgroundDrawable(Drawable background) {
100 super.setBackgroundDrawable(background);
101 if (mBackgroundTintHelper != null) {
102 mBackgroundTintHelper.onSetBackgroundDrawable(background);
107 * This should be accessed via
108 * {@link android.support.v4.view.ViewCompat#setBackgroundTintList(android.view.View, ColorStateList)}
110 * @hide
112 @RestrictTo(GROUP_ID)
113 @Override
114 public void setSupportBackgroundTintList(@Nullable ColorStateList tint) {
115 if (mBackgroundTintHelper != null) {
116 mBackgroundTintHelper.setSupportBackgroundTintList(tint);
121 * This should be accessed via
122 * {@link android.support.v4.view.ViewCompat#getBackgroundTintList(android.view.View)}
124 * @hide
126 @RestrictTo(GROUP_ID)
127 @Override
128 @Nullable
129 public ColorStateList getSupportBackgroundTintList() {
130 return mBackgroundTintHelper != null
131 ? mBackgroundTintHelper.getSupportBackgroundTintList() : null;
135 * This should be accessed via
136 * {@link android.support.v4.view.ViewCompat#setBackgroundTintMode(android.view.View, PorterDuff.Mode)}
138 * @hide
140 @RestrictTo(GROUP_ID)
141 @Override
142 public void setSupportBackgroundTintMode(@Nullable PorterDuff.Mode tintMode) {
143 if (mBackgroundTintHelper != null) {
144 mBackgroundTintHelper.setSupportBackgroundTintMode(tintMode);
149 * This should be accessed via
150 * {@link android.support.v4.view.ViewCompat#getBackgroundTintMode(android.view.View)}
152 * @hide
154 @RestrictTo(GROUP_ID)
155 @Override
156 @Nullable
157 public PorterDuff.Mode getSupportBackgroundTintMode() {
158 return mBackgroundTintHelper != null
159 ? mBackgroundTintHelper.getSupportBackgroundTintMode() : null;
162 @Override
163 protected void drawableStateChanged() {
164 super.drawableStateChanged();
165 if (mBackgroundTintHelper != null) {
166 mBackgroundTintHelper.applySupportBackgroundTint();
168 if (mTextHelper != null) {
169 mTextHelper.applyCompoundDrawablesTints();
173 @Override
174 public void setTextAppearance(Context context, int resId) {
175 super.setTextAppearance(context, resId);
176 if (mTextHelper != null) {
177 mTextHelper.onSetTextAppearance(context, resId);