• 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.service.quicksettings.Tile;
20 import android.widget.ImageView;
21 
22 import com.android.settingslib.graph.SignalDrawable;
23 import com.android.settingslib.Utils;
24 import com.android.systemui.R;
25 import com.android.systemui.plugins.qs.QSTile.Icon;
26 import com.android.systemui.plugins.qs.QSTile.State;
27 import com.android.systemui.qs.tileimpl.QSTileImpl;
28 
29 import java.util.Objects;
30 
31 // Exists to provide easy way to add sim icon to cell tile
32 // TODO Find a better way to handle this and remove it.
33 public class CellTileView extends SignalTileView {
34 
35     private final SignalDrawable mSignalDrawable;
36 
CellTileView(Context context)37     public CellTileView(Context context) {
38         super(context);
39         mSignalDrawable = new SignalDrawable(mContext);
40         mSignalDrawable.setColors(QSTileImpl.getColorForState(context, Tile.STATE_UNAVAILABLE),
41                 QSTileImpl.getColorForState(context, Tile.STATE_ACTIVE));
42         mSignalDrawable.setIntrinsicSize(context.getResources().getDimensionPixelSize(
43                 R.dimen.qs_tile_icon_size));
44     }
45 
updateIcon(ImageView iv, State state)46     protected void updateIcon(ImageView iv, State state) {
47         if (!(state.icon instanceof SignalIcon)) {
48             super.updateIcon(iv, state);
49             return;
50         } else if (!Objects.equals(state.icon, iv.getTag(R.id.qs_icon_tag))) {
51             mSignalDrawable.setLevel(((SignalIcon) state.icon).getState());
52             iv.setImageDrawable(mSignalDrawable);
53             iv.setTag(R.id.qs_icon_tag, state.icon);
54         }
55     }
56 
57     public static class SignalIcon extends Icon {
58 
59         private final int mState;
60 
SignalIcon(int state)61         public SignalIcon(int state) {
62             mState = state;
63         }
64 
getState()65         public int getState() {
66             return mState;
67         }
68 
69         @Override
getDrawable(Context context)70         public Drawable getDrawable(Context context) {
71             //TODO: Not the optimal solution to create this drawable
72             SignalDrawable d = new SignalDrawable(context);
73             d.setColors(QSTileImpl.getColorForState(context, Tile.STATE_UNAVAILABLE),
74                     QSTileImpl.getColorForState(context, Tile.STATE_ACTIVE));
75             d.setLevel(getState());
76             return d;
77         }
78     }
79 }
80