1f2819e0eada8af3835141857b5d499bca90774a6Jason Monk/* 2f2819e0eada8af3835141857b5d499bca90774a6Jason Monk * Copyright (C) 2015 The Android Open Source Project 3f2819e0eada8af3835141857b5d499bca90774a6Jason Monk * 4f2819e0eada8af3835141857b5d499bca90774a6Jason Monk * Licensed under the Apache License, Version 2.0 (the "License"); 5f2819e0eada8af3835141857b5d499bca90774a6Jason Monk * you may not use this file except in compliance with the License. 6f2819e0eada8af3835141857b5d499bca90774a6Jason Monk * You may obtain a copy of the License at 7f2819e0eada8af3835141857b5d499bca90774a6Jason Monk * 8f2819e0eada8af3835141857b5d499bca90774a6Jason Monk * http://www.apache.org/licenses/LICENSE-2.0 9f2819e0eada8af3835141857b5d499bca90774a6Jason Monk * 10f2819e0eada8af3835141857b5d499bca90774a6Jason Monk * Unless required by applicable law or agreed to in writing, software 11f2819e0eada8af3835141857b5d499bca90774a6Jason Monk * distributed under the License is distributed on an "AS IS" BASIS, 12f2819e0eada8af3835141857b5d499bca90774a6Jason Monk * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13f2819e0eada8af3835141857b5d499bca90774a6Jason Monk * See the License for the specific language governing permissions and 14f2819e0eada8af3835141857b5d499bca90774a6Jason Monk * limitations under the License. 15f2819e0eada8af3835141857b5d499bca90774a6Jason Monk */ 16f2819e0eada8af3835141857b5d499bca90774a6Jason Monkpackage com.android.settings; 17f2819e0eada8af3835141857b5d499bca90774a6Jason Monk 18f2819e0eada8af3835141857b5d499bca90774a6Jason Monkimport android.content.Context; 19f2819e0eada8af3835141857b5d499bca90774a6Jason Monkimport android.content.res.ColorStateList; 2039b467482d1bf256a111c757e9b7621c6f523271Jason Monkimport android.support.v7.preference.Preference; 2139b467482d1bf256a111c757e9b7621c6f523271Jason Monkimport android.support.v7.preference.PreferenceViewHolder; 22f2819e0eada8af3835141857b5d499bca90774a6Jason Monkimport android.util.AttributeSet; 23f2819e0eada8af3835141857b5d499bca90774a6Jason Monkimport android.widget.ImageView; 24f2819e0eada8af3835141857b5d499bca90774a6Jason Monk 25f2819e0eada8af3835141857b5d499bca90774a6Jason Monkpublic class TintablePreference extends Preference { 26f2819e0eada8af3835141857b5d499bca90774a6Jason Monk 27f2819e0eada8af3835141857b5d499bca90774a6Jason Monk private int mTintColor; 28f2819e0eada8af3835141857b5d499bca90774a6Jason Monk 29f2819e0eada8af3835141857b5d499bca90774a6Jason Monk public TintablePreference(Context context, AttributeSet attrs) { 30f2819e0eada8af3835141857b5d499bca90774a6Jason Monk super(context, attrs); 31f2819e0eada8af3835141857b5d499bca90774a6Jason Monk } 32f2819e0eada8af3835141857b5d499bca90774a6Jason Monk 33f2819e0eada8af3835141857b5d499bca90774a6Jason Monk public void setTint(int color) { 34f2819e0eada8af3835141857b5d499bca90774a6Jason Monk mTintColor = color; 35f2819e0eada8af3835141857b5d499bca90774a6Jason Monk notifyChanged(); 36f2819e0eada8af3835141857b5d499bca90774a6Jason Monk } 37f2819e0eada8af3835141857b5d499bca90774a6Jason Monk 38f2819e0eada8af3835141857b5d499bca90774a6Jason Monk @Override 3939b467482d1bf256a111c757e9b7621c6f523271Jason Monk public void onBindViewHolder(PreferenceViewHolder view) { 4039b467482d1bf256a111c757e9b7621c6f523271Jason Monk super.onBindViewHolder(view); 41f2819e0eada8af3835141857b5d499bca90774a6Jason Monk 42f2819e0eada8af3835141857b5d499bca90774a6Jason Monk if (mTintColor != 0) { 436880ec09cd95359d42007d3c76ac4b9905743de7Jason Monk ((ImageView) view.findViewById(android.R.id.icon)).setImageTintList( 44f2819e0eada8af3835141857b5d499bca90774a6Jason Monk ColorStateList.valueOf(mTintColor)); 459cc88e5e5e901f5dbf3a9aec5d7cbdb4294968a9Jason Monk } else { 469cc88e5e5e901f5dbf3a9aec5d7cbdb4294968a9Jason Monk ((ImageView) view.findViewById(android.R.id.icon)).setImageTintList(null); 47f2819e0eada8af3835141857b5d499bca90774a6Jason Monk } 48f2819e0eada8af3835141857b5d499bca90774a6Jason Monk } 49f2819e0eada8af3835141857b5d499bca90774a6Jason Monk} 50