1e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk/* 2e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk * Copyright (C) 2017 The Android Open Source Project 3e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk * 4e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk * except in compliance with the License. You may obtain a copy of the License at 6e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk * 7e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk * http://www.apache.org/licenses/LICENSE-2.0 8e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk * 9e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk * Unless required by applicable law or agreed to in writing, software distributed under the 10e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk * KIND, either express or implied. See the License for the specific language governing 12e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk * permissions and limitations under the License. 13e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk */ 14e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk 15e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monkpackage com.android.systemui.qs; 16e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk 17e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monkimport android.content.Context; 1801df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monkimport android.graphics.drawable.Drawable; 19e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monkimport android.widget.ImageView; 20e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk 21e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monkimport com.android.settingslib.Utils; 22e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monkimport com.android.systemui.R; 2301df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monkimport com.android.systemui.plugins.qs.QSTile.Icon; 24e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monkimport com.android.systemui.plugins.qs.QSTile.State; 2501df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monkimport com.android.systemui.statusbar.phone.SignalDrawable; 2601df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk 2701df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monkimport java.util.Objects; 28e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk 29e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk// Exists to provide easy way to add sim icon to cell tile 30e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk// TODO Find a better way to handle this and remove it. 31e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monkpublic class CellTileView extends SignalTileView { 32e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk 3301df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk private final SignalDrawable mSignalDrawable; 34e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk 35e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk public CellTileView(Context context) { 36e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk super(context); 3701df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk mSignalDrawable = new SignalDrawable(mContext); 38fe6228f26a83f13b27901383f4be7735792fe172Evan Laird mSignalDrawable.setDarkIntensity(isDark(mContext)); 3901df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk mSignalDrawable.setIntrinsicSize(context.getResources().getDimensionPixelSize( 4001df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk R.dimen.qs_tile_icon_size)); 4101df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk } 4201df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk 4301df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk protected void updateIcon(ImageView iv, State state) { 4401df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk if (!Objects.equals(state.icon, iv.getTag(R.id.qs_icon_tag))) { 4501df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk mSignalDrawable.setLevel(((SignalIcon) state.icon).getState()); 4601df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk iv.setImageDrawable(mSignalDrawable); 4701df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk iv.setTag(R.id.qs_icon_tag, state.icon); 4801df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk } 49e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk } 50e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk 51fe6228f26a83f13b27901383f4be7735792fe172Evan Laird private static int isDark(Context context) { 52fe6228f26a83f13b27901383f4be7735792fe172Evan Laird return Utils.getColorAttr(context, android.R.attr.colorForeground) == 0xff000000 ? 1 : 0; 53fe6228f26a83f13b27901383f4be7735792fe172Evan Laird } 54fe6228f26a83f13b27901383f4be7735792fe172Evan Laird 5501df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk public static class SignalIcon extends Icon { 5601df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk 5701df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk private final int mState; 5801df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk 5901df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk public SignalIcon(int state) { 6001df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk mState = state; 6101df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk } 6201df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk 6301df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk public int getState() { 6401df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk return mState; 6501df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk } 6601df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk 6701df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk @Override 6801df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk public Drawable getDrawable(Context context) { 69fe6228f26a83f13b27901383f4be7735792fe172Evan Laird //TODO: Not the optimal solution to create this drawable 70fe6228f26a83f13b27901383f4be7735792fe172Evan Laird SignalDrawable d = new SignalDrawable(context); 71fe6228f26a83f13b27901383f4be7735792fe172Evan Laird d.setDarkIntensity(isDark(context)); 72fe6228f26a83f13b27901383f4be7735792fe172Evan Laird d.setLevel(getState()); 73fe6228f26a83f13b27901383f4be7735792fe172Evan Laird return d; 7401df36f37fc470d3fd8c120b09cc4e7943cfacfbJason Monk } 75e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk } 76e5b770e47d44a40d412c7d42010b2cf67920d9e3Jason Monk} 77