1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
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
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17package android.support.v7.widget;
18
19import android.content.Context;
20import android.content.res.TypedArray;
21import android.graphics.drawable.Drawable;
22import android.util.AttributeSet;
23import android.widget.TextView;
24
25class AppCompatTextHelperV17 extends AppCompatTextHelper {
26
27    private static final int[] VIEW_ATTRS_v17 = {
28            android.R.attr.drawableStart, android.R.attr.drawableEnd };
29
30    private TintInfo mDrawableStartTint;
31    private TintInfo mDrawableEndTint;
32
33    AppCompatTextHelperV17(TextView view) {
34        super(view);
35    }
36
37    void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {
38        super.loadFromAttributes(attrs, defStyleAttr);
39
40        final Context context = mView.getContext();
41        final AppCompatDrawableManager drawableManager = AppCompatDrawableManager.get();
42
43        TypedArray a = context.obtainStyledAttributes(attrs, VIEW_ATTRS_v17, defStyleAttr, 0);
44        if (a.hasValue(0)) {
45            mDrawableStartTint = createTintInfo(context, drawableManager, a.getResourceId(0, 0));
46        }
47        if (a.hasValue(1)) {
48            mDrawableEndTint = createTintInfo(context, drawableManager, a.getResourceId(1, 0));
49        }
50        a.recycle();
51    }
52
53    @Override
54    void applyCompoundDrawablesTints() {
55        super.applyCompoundDrawablesTints();
56
57        if (mDrawableStartTint != null || mDrawableEndTint != null) {
58            final Drawable[] compoundDrawables = mView.getCompoundDrawablesRelative();
59            applyCompoundDrawableTint(compoundDrawables[0], mDrawableStartTint);
60            applyCompoundDrawableTint(compoundDrawables[2], mDrawableEndTint);
61        }
62    }
63}
64