1/* 2 * Copyright (C) 2014 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.internal.widget; 18 19import android.content.Context; 20import android.util.AttributeSet; 21import android.widget.CheckBox; 22 23/** 24 * An tint aware {@link android.widget.CheckBox}. 25 * 26 * @hide 27 */ 28public class TintCheckBox extends CheckBox { 29 30 private static final int[] TINT_ATTRS = { 31 android.R.attr.button 32 }; 33 34 private final TintManager mTintManager; 35 36 public TintCheckBox(Context context) { 37 this(context, null); 38 } 39 40 public TintCheckBox(Context context, AttributeSet attrs) { 41 this(context, attrs, android.R.attr.checkboxStyle); 42 } 43 44 public TintCheckBox(Context context, AttributeSet attrs, int defStyleAttr) { 45 super(context, attrs, defStyleAttr); 46 47 TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, TINT_ATTRS, 48 defStyleAttr, 0); 49 setButtonDrawable(a.getDrawable(0)); 50 a.recycle(); 51 52 mTintManager = a.getTintManager(); 53 } 54 55 @Override 56 public void setButtonDrawable(int resid) { 57 setButtonDrawable(mTintManager.getDrawable(resid)); 58 } 59} 60