1/* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 15package com.android.systemui.qs; 16 17import android.content.Context; 18import android.graphics.drawable.Drawable; 19import android.widget.ImageView; 20 21import com.android.settingslib.Utils; 22import com.android.systemui.R; 23import com.android.systemui.plugins.qs.QSTile.Icon; 24import com.android.systemui.plugins.qs.QSTile.State; 25import com.android.systemui.statusbar.phone.SignalDrawable; 26 27import java.util.Objects; 28 29// Exists to provide easy way to add sim icon to cell tile 30// TODO Find a better way to handle this and remove it. 31public class CellTileView extends SignalTileView { 32 33 private final SignalDrawable mSignalDrawable; 34 35 public CellTileView(Context context) { 36 super(context); 37 mSignalDrawable = new SignalDrawable(mContext); 38 mSignalDrawable.setDarkIntensity(isDark(mContext)); 39 mSignalDrawable.setIntrinsicSize(context.getResources().getDimensionPixelSize( 40 R.dimen.qs_tile_icon_size)); 41 } 42 43 protected void updateIcon(ImageView iv, State state) { 44 if (!Objects.equals(state.icon, iv.getTag(R.id.qs_icon_tag))) { 45 mSignalDrawable.setLevel(((SignalIcon) state.icon).getState()); 46 iv.setImageDrawable(mSignalDrawable); 47 iv.setTag(R.id.qs_icon_tag, state.icon); 48 } 49 } 50 51 private static int isDark(Context context) { 52 return Utils.getColorAttr(context, android.R.attr.colorForeground) == 0xff000000 ? 1 : 0; 53 } 54 55 public static class SignalIcon extends Icon { 56 57 private final int mState; 58 59 public SignalIcon(int state) { 60 mState = state; 61 } 62 63 public int getState() { 64 return mState; 65 } 66 67 @Override 68 public Drawable getDrawable(Context context) { 69 //TODO: Not the optimal solution to create this drawable 70 SignalDrawable d = new SignalDrawable(context); 71 d.setDarkIntensity(isDark(context)); 72 d.setLevel(getState()); 73 return d; 74 } 75 } 76} 77