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.support.annotation.RequiresApi; 23import android.support.v7.appcompat.R; 24import android.util.AttributeSet; 25import android.widget.TextView; 26 27@RequiresApi(17) 28class AppCompatTextHelperV17 extends AppCompatTextHelper { 29 private TintInfo mDrawableStartTint; 30 private TintInfo mDrawableEndTint; 31 32 AppCompatTextHelperV17(TextView view) { 33 super(view); 34 } 35 36 @Override 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, R.styleable.AppCompatTextHelper, 44 defStyleAttr, 0); 45 if (a.hasValue(R.styleable.AppCompatTextHelper_android_drawableStart)) { 46 mDrawableStartTint = createTintInfo(context, drawableManager, 47 a.getResourceId(R.styleable.AppCompatTextHelper_android_drawableStart, 0)); 48 } 49 if (a.hasValue(R.styleable.AppCompatTextHelper_android_drawableEnd)) { 50 mDrawableEndTint = createTintInfo(context, drawableManager, 51 a.getResourceId(R.styleable.AppCompatTextHelper_android_drawableEnd, 0)); 52 } 53 a.recycle(); 54 } 55 56 @Override 57 void applyCompoundDrawablesTints() { 58 super.applyCompoundDrawablesTints(); 59 60 if (mDrawableStartTint != null || mDrawableEndTint != null) { 61 final Drawable[] compoundDrawables = mView.getCompoundDrawablesRelative(); 62 applyCompoundDrawableTint(compoundDrawables[0], mDrawableStartTint); 63 applyCompoundDrawableTint(compoundDrawables[2], mDrawableEndTint); 64 } 65 } 66} 67