• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
15 package com.android.systemui.qs;
16 
17 import android.content.Context;
18 import android.graphics.drawable.Drawable;
19 import android.widget.ImageView;
20 
21 import com.android.settingslib.Utils;
22 import com.android.systemui.R;
23 import com.android.systemui.plugins.qs.QSTile.Icon;
24 import com.android.systemui.plugins.qs.QSTile.State;
25 import com.android.systemui.statusbar.phone.SignalDrawable;
26 
27 import 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.
31 public class CellTileView extends SignalTileView {
32 
33     private final SignalDrawable mSignalDrawable;
34 
CellTileView(Context context)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 
updateIcon(ImageView iv, State state)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 
isDark(Context context)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 
SignalIcon(int state)59         public SignalIcon(int state) {
60             mState = state;
61         }
62 
getState()63         public int getState() {
64             return mState;
65         }
66 
67         @Override
getDrawable(Context context)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