1 /* 2 * Copyright (C) 2016 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 package com.android.systemui.qs.external; 17 18 import android.content.Context; 19 import android.content.res.ColorStateList; 20 import android.service.quicksettings.Tile; 21 import android.support.annotation.VisibleForTesting; 22 import com.android.systemui.R; 23 24 public class TileColorPicker { 25 @VisibleForTesting static final int[] DISABLE_STATE_SET = {-android.R.attr.state_enabled}; 26 @VisibleForTesting static final int[] ENABLE_STATE_SET = {android.R.attr.state_enabled, 27 android.R.attr.state_activated}; 28 @VisibleForTesting static final int[] INACTIVE_STATE_SET = {-android.R.attr.state_activated}; 29 private static TileColorPicker sInstance; 30 31 private ColorStateList mColorStateList; 32 33 private TileColorPicker(Context context) { 34 mColorStateList = context.getResources(). 35 getColorStateList(R.color.tint_color_selector, context.getTheme()); 36 } 37 38 public static TileColorPicker getInstance(Context context) { 39 if (sInstance == null) { 40 sInstance = new TileColorPicker(context); 41 } 42 return sInstance; 43 } 44 45 public int getColor(int state) { 46 final int defaultColor = 0; 47 48 switch (state) { 49 case Tile.STATE_UNAVAILABLE: 50 return mColorStateList.getColorForState(DISABLE_STATE_SET, defaultColor); 51 case Tile.STATE_INACTIVE: 52 return mColorStateList.getColorForState(INACTIVE_STATE_SET, defaultColor); 53 case Tile.STATE_ACTIVE: 54 return mColorStateList.getColorForState(ENABLE_STATE_SET, defaultColor); 55 default: 56 return mColorStateList.getColorForState(ENABLE_STATE_SET, defaultColor); 57 } 58 } 59 60 } 61