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.service.quicksettings.Tile; 20import android.widget.ImageView; 21 22import com.android.settingslib.graph.SignalDrawable; 23import com.android.settingslib.Utils; 24import com.android.systemui.R; 25import com.android.systemui.plugins.qs.QSTile.Icon; 26import com.android.systemui.plugins.qs.QSTile.State; 27import com.android.systemui.qs.tileimpl.QSTileImpl; 28 29import 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. 33public class CellTileView extends SignalTileView { 34 35 private final SignalDrawable mSignalDrawable; 36 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 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 61 public SignalIcon(int state) { 62 mState = state; 63 } 64 65 public int getState() { 66 return mState; 67 } 68 69 @Override 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