Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar; |
| 18 | |
Beverly | 1be62f4 | 2018-12-19 17:17:48 -0500 | [diff] [blame] | 19 | import static com.android.systemui.plugins.DarkIconDispatcher.getTint; |
| 20 | import static com.android.systemui.plugins.DarkIconDispatcher.isInArea; |
Evan Laird | 97ae20c | 2018-05-10 13:13:27 -0400 | [diff] [blame] | 21 | import static com.android.systemui.statusbar.StatusBarIconView.STATE_DOT; |
| 22 | import static com.android.systemui.statusbar.StatusBarIconView.STATE_HIDDEN; |
| 23 | import static com.android.systemui.statusbar.StatusBarIconView.STATE_ICON; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 24 | |
| 25 | import android.content.Context; |
| 26 | import android.content.res.ColorStateList; |
| 27 | import android.graphics.Color; |
| 28 | import android.graphics.Rect; |
| 29 | import android.util.AttributeSet; |
Evan Laird | 97ae20c | 2018-05-10 13:13:27 -0400 | [diff] [blame] | 30 | import android.view.Gravity; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 31 | import android.view.LayoutInflater; |
| 32 | import android.view.View; |
Evan Laird | 97ae20c | 2018-05-10 13:13:27 -0400 | [diff] [blame] | 33 | import android.widget.FrameLayout; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 34 | import android.widget.ImageView; |
Evan Laird | 97ae20c | 2018-05-10 13:13:27 -0400 | [diff] [blame] | 35 | import android.widget.LinearLayout; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 36 | |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 37 | import com.android.internal.annotations.VisibleForTesting; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 38 | import com.android.settingslib.graph.SignalDrawable; |
Fabian Kozynski | f86df99 | 2019-04-22 14:23:47 -0400 | [diff] [blame] | 39 | import com.android.systemui.DualToneHandler; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 40 | import com.android.systemui.R; |
Beverly | 1be62f4 | 2018-12-19 17:17:48 -0500 | [diff] [blame] | 41 | import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 42 | import com.android.systemui.statusbar.phone.StatusBarSignalPolicy.MobileIconState; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 43 | |
Evan Laird | 97ae20c | 2018-05-10 13:13:27 -0400 | [diff] [blame] | 44 | public class StatusBarMobileView extends FrameLayout implements DarkReceiver, |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 45 | StatusIconDisplayable { |
| 46 | private static final String TAG = "StatusBarMobileView"; |
| 47 | |
Evan Laird | 97ae20c | 2018-05-10 13:13:27 -0400 | [diff] [blame] | 48 | /// Used to show etc dots |
| 49 | private StatusBarIconView mDotView; |
| 50 | /// The main icon view |
| 51 | private LinearLayout mMobileGroup; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 52 | private String mSlot; |
| 53 | private MobileIconState mState; |
| 54 | private SignalDrawable mMobileDrawable; |
| 55 | private View mInoutContainer; |
| 56 | private ImageView mIn; |
| 57 | private ImageView mOut; |
| 58 | private ImageView mMobile, mMobileType, mMobileRoaming; |
| 59 | private View mMobileRoamingSpace; |
Evan Laird | 97ae20c | 2018-05-10 13:13:27 -0400 | [diff] [blame] | 60 | private int mVisibleState = -1; |
Fabian Kozynski | f86df99 | 2019-04-22 14:23:47 -0400 | [diff] [blame] | 61 | private DualToneHandler mDualToneHandler; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 62 | |
Evan Laird | 97ae20c | 2018-05-10 13:13:27 -0400 | [diff] [blame] | 63 | public static StatusBarMobileView fromContext(Context context, String slot) { |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 64 | LayoutInflater inflater = LayoutInflater.from(context); |
Evan Laird | 97ae20c | 2018-05-10 13:13:27 -0400 | [diff] [blame] | 65 | StatusBarMobileView v = (StatusBarMobileView) |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 66 | inflater.inflate(R.layout.status_bar_mobile_signal_group, null); |
Evan Laird | 97ae20c | 2018-05-10 13:13:27 -0400 | [diff] [blame] | 67 | |
| 68 | v.setSlot(slot); |
| 69 | v.init(); |
| 70 | v.setVisibleState(STATE_ICON); |
| 71 | return v; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | public StatusBarMobileView(Context context) { |
| 75 | super(context); |
| 76 | } |
| 77 | |
| 78 | public StatusBarMobileView(Context context, AttributeSet attrs) { |
| 79 | super(context, attrs); |
| 80 | } |
| 81 | |
| 82 | public StatusBarMobileView(Context context, AttributeSet attrs, int defStyleAttr) { |
| 83 | super(context, attrs, defStyleAttr); |
| 84 | } |
| 85 | |
| 86 | public StatusBarMobileView(Context context, AttributeSet attrs, int defStyleAttr, |
| 87 | int defStyleRes) { |
| 88 | super(context, attrs, defStyleAttr, defStyleRes); |
| 89 | } |
| 90 | |
Evan Laird | c139727 | 2018-05-21 20:12:34 -0400 | [diff] [blame] | 91 | @Override |
| 92 | public void getDrawingRect(Rect outRect) { |
| 93 | super.getDrawingRect(outRect); |
| 94 | float translationX = getTranslationX(); |
| 95 | float translationY = getTranslationY(); |
| 96 | outRect.left += translationX; |
| 97 | outRect.right += translationX; |
| 98 | outRect.top += translationY; |
| 99 | outRect.bottom += translationY; |
| 100 | } |
| 101 | |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 102 | private void init() { |
Fabian Kozynski | f86df99 | 2019-04-22 14:23:47 -0400 | [diff] [blame] | 103 | mDualToneHandler = new DualToneHandler(getContext()); |
Evan Laird | 97ae20c | 2018-05-10 13:13:27 -0400 | [diff] [blame] | 104 | mMobileGroup = findViewById(R.id.mobile_group); |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 105 | mMobile = findViewById(R.id.mobile_signal); |
| 106 | mMobileType = findViewById(R.id.mobile_type); |
| 107 | mMobileRoaming = findViewById(R.id.mobile_roaming); |
| 108 | mMobileRoamingSpace = findViewById(R.id.mobile_roaming_space); |
| 109 | mIn = findViewById(R.id.mobile_in); |
| 110 | mOut = findViewById(R.id.mobile_out); |
| 111 | mInoutContainer = findViewById(R.id.inout_container); |
| 112 | |
| 113 | mMobileDrawable = new SignalDrawable(getContext()); |
| 114 | mMobile.setImageDrawable(mMobileDrawable); |
Evan Laird | 97ae20c | 2018-05-10 13:13:27 -0400 | [diff] [blame] | 115 | |
| 116 | initDotView(); |
| 117 | } |
| 118 | |
| 119 | private void initDotView() { |
| 120 | mDotView = new StatusBarIconView(mContext, mSlot, null); |
| 121 | mDotView.setVisibleState(STATE_DOT); |
| 122 | |
| 123 | int width = mContext.getResources().getDimensionPixelSize(R.dimen.status_bar_icon_size); |
| 124 | LayoutParams lp = new LayoutParams(width, width); |
| 125 | lp.gravity = Gravity.CENTER_VERTICAL | Gravity.START; |
| 126 | addView(mDotView, lp); |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | public void applyMobileState(MobileIconState state) { |
Evan Laird | f303d95 | 2018-06-21 14:07:10 -0400 | [diff] [blame] | 130 | boolean requestLayout = false; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 131 | if (state == null) { |
Evan Laird | f303d95 | 2018-06-21 14:07:10 -0400 | [diff] [blame] | 132 | requestLayout = getVisibility() != View.GONE; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 133 | setVisibility(View.GONE); |
| 134 | mState = null; |
Evan Laird | f303d95 | 2018-06-21 14:07:10 -0400 | [diff] [blame] | 135 | } else if (mState == null) { |
| 136 | requestLayout = true; |
Evan Laird | 56fb9f8 | 2018-04-24 21:11:15 -0400 | [diff] [blame] | 137 | mState = state.copy(); |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 138 | initViewState(); |
Evan Laird | f303d95 | 2018-06-21 14:07:10 -0400 | [diff] [blame] | 139 | } else if (!mState.equals(state)) { |
| 140 | requestLayout = updateState(state.copy()); |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 141 | } |
| 142 | |
Evan Laird | f303d95 | 2018-06-21 14:07:10 -0400 | [diff] [blame] | 143 | if (requestLayout) { |
| 144 | requestLayout(); |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | |
| 148 | private void initViewState() { |
| 149 | setContentDescription(mState.contentDescription); |
| 150 | if (!mState.visible) { |
Evan Laird | 97ae20c | 2018-05-10 13:13:27 -0400 | [diff] [blame] | 151 | mMobileGroup.setVisibility(View.GONE); |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 152 | } else { |
Evan Laird | 97ae20c | 2018-05-10 13:13:27 -0400 | [diff] [blame] | 153 | mMobileGroup.setVisibility(View.VISIBLE); |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 154 | } |
| 155 | mMobileDrawable.setLevel(mState.strengthId); |
| 156 | if (mState.typeId > 0) { |
| 157 | mMobileType.setContentDescription(mState.typeContentDescription); |
| 158 | mMobileType.setImageResource(mState.typeId); |
| 159 | mMobileType.setVisibility(View.VISIBLE); |
| 160 | } else { |
| 161 | mMobileType.setVisibility(View.GONE); |
| 162 | } |
| 163 | |
| 164 | mMobileRoaming.setVisibility(mState.roaming ? View.VISIBLE : View.GONE); |
| 165 | mMobileRoamingSpace.setVisibility(mState.roaming ? View.VISIBLE : View.GONE); |
| 166 | mIn.setVisibility(mState.activityIn ? View.VISIBLE : View.GONE); |
Evan Laird | f303d95 | 2018-06-21 14:07:10 -0400 | [diff] [blame] | 167 | mOut.setVisibility(mState.activityOut ? View.VISIBLE : View.GONE); |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 168 | mInoutContainer.setVisibility((mState.activityIn || mState.activityOut) |
| 169 | ? View.VISIBLE : View.GONE); |
| 170 | } |
| 171 | |
Evan Laird | f303d95 | 2018-06-21 14:07:10 -0400 | [diff] [blame] | 172 | private boolean updateState(MobileIconState state) { |
| 173 | boolean needsLayout = false; |
| 174 | |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 175 | setContentDescription(state.contentDescription); |
| 176 | if (mState.visible != state.visible) { |
Evan Laird | 97ae20c | 2018-05-10 13:13:27 -0400 | [diff] [blame] | 177 | mMobileGroup.setVisibility(state.visible ? View.VISIBLE : View.GONE); |
Evan Laird | f303d95 | 2018-06-21 14:07:10 -0400 | [diff] [blame] | 178 | needsLayout = true; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 179 | } |
| 180 | if (mState.strengthId != state.strengthId) { |
| 181 | mMobileDrawable.setLevel(state.strengthId); |
| 182 | } |
Evan Laird | 6dedbe6 | 2018-04-05 16:22:36 -0400 | [diff] [blame] | 183 | if (mState.typeId != state.typeId) { |
Evan Laird | f303d95 | 2018-06-21 14:07:10 -0400 | [diff] [blame] | 184 | needsLayout |= state.typeId == 0 || mState.typeId == 0; |
Evan Laird | 6dedbe6 | 2018-04-05 16:22:36 -0400 | [diff] [blame] | 185 | if (state.typeId != 0) { |
| 186 | mMobileType.setContentDescription(state.typeContentDescription); |
| 187 | mMobileType.setImageResource(state.typeId); |
| 188 | mMobileType.setVisibility(View.VISIBLE); |
| 189 | } else { |
| 190 | mMobileType.setVisibility(View.GONE); |
| 191 | } |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | mMobileRoaming.setVisibility(state.roaming ? View.VISIBLE : View.GONE); |
| 195 | mMobileRoamingSpace.setVisibility(state.roaming ? View.VISIBLE : View.GONE); |
| 196 | mIn.setVisibility(state.activityIn ? View.VISIBLE : View.GONE); |
Evan Laird | f303d95 | 2018-06-21 14:07:10 -0400 | [diff] [blame] | 197 | mOut.setVisibility(state.activityOut ? View.VISIBLE : View.GONE); |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 198 | mInoutContainer.setVisibility((state.activityIn || state.activityOut) |
| 199 | ? View.VISIBLE : View.GONE); |
| 200 | |
Evan Laird | f303d95 | 2018-06-21 14:07:10 -0400 | [diff] [blame] | 201 | needsLayout |= state.roaming != mState.roaming |
| 202 | || state.activityIn != mState.activityIn |
| 203 | || state.activityOut != mState.activityOut; |
| 204 | |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 205 | mState = state; |
Evan Laird | f303d95 | 2018-06-21 14:07:10 -0400 | [diff] [blame] | 206 | return needsLayout; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | @Override |
| 210 | public void onDarkChanged(Rect area, float darkIntensity, int tint) { |
Evan Laird | dbeefe3 | 2018-04-03 16:52:41 -0400 | [diff] [blame] | 211 | if (!isInArea(area, this)) { |
| 212 | return; |
| 213 | } |
Amin Shaikh | 0ad7e51 | 2019-04-29 07:36:34 -0400 | [diff] [blame] | 214 | mMobileDrawable.setTintList( |
Fabian Kozynski | 8957ede | 2019-05-22 12:16:10 -0400 | [diff] [blame] | 215 | ColorStateList.valueOf(mDualToneHandler.getSingleColor(darkIntensity))); |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 216 | ColorStateList color = ColorStateList.valueOf(getTint(area, this, tint)); |
| 217 | mIn.setImageTintList(color); |
| 218 | mOut.setImageTintList(color); |
| 219 | mMobileType.setImageTintList(color); |
| 220 | mMobileRoaming.setImageTintList(color); |
Evan Laird | 97ae20c | 2018-05-10 13:13:27 -0400 | [diff] [blame] | 221 | mDotView.setDecorColor(tint); |
| 222 | mDotView.setIconColor(tint, false); |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | @Override |
| 226 | public String getSlot() { |
| 227 | return mSlot; |
| 228 | } |
| 229 | |
| 230 | public void setSlot(String slot) { |
| 231 | mSlot = slot; |
| 232 | } |
| 233 | |
| 234 | @Override |
| 235 | public void setStaticDrawableColor(int color) { |
| 236 | ColorStateList list = ColorStateList.valueOf(color); |
| 237 | float intensity = color == Color.WHITE ? 0 : 1; |
Fabian Kozynski | f86df99 | 2019-04-22 14:23:47 -0400 | [diff] [blame] | 238 | // We want the ability to change the theme from the one set by SignalDrawable in certain |
| 239 | // surfaces. In this way, we can pass a theme to the view. |
Amin Shaikh | 0ad7e51 | 2019-04-29 07:36:34 -0400 | [diff] [blame] | 240 | mMobileDrawable.setTintList( |
Fabian Kozynski | 8957ede | 2019-05-22 12:16:10 -0400 | [diff] [blame] | 241 | ColorStateList.valueOf(mDualToneHandler.getSingleColor(intensity))); |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 242 | mIn.setImageTintList(list); |
| 243 | mOut.setImageTintList(list); |
| 244 | mMobileType.setImageTintList(list); |
| 245 | mMobileRoaming.setImageTintList(list); |
Evan Laird | 97ae20c | 2018-05-10 13:13:27 -0400 | [diff] [blame] | 246 | mDotView.setDecorColor(color); |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | @Override |
Evan Laird | 20b87bf | 2018-04-12 09:54:11 -0400 | [diff] [blame] | 250 | public void setDecorColor(int color) { |
Evan Laird | 97ae20c | 2018-05-10 13:13:27 -0400 | [diff] [blame] | 251 | mDotView.setDecorColor(color); |
Evan Laird | 20b87bf | 2018-04-12 09:54:11 -0400 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | @Override |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 255 | public boolean isIconVisible() { |
| 256 | return mState.visible; |
| 257 | } |
| 258 | |
Evan Laird | 20b87bf | 2018-04-12 09:54:11 -0400 | [diff] [blame] | 259 | @Override |
Evan Laird | 620ea2c | 2018-06-21 11:18:19 -0400 | [diff] [blame] | 260 | public void setVisibleState(int state, boolean animate) { |
Evan Laird | 97ae20c | 2018-05-10 13:13:27 -0400 | [diff] [blame] | 261 | if (state == mVisibleState) { |
| 262 | return; |
| 263 | } |
| 264 | |
| 265 | mVisibleState = state; |
| 266 | switch (state) { |
| 267 | case STATE_ICON: |
| 268 | mMobileGroup.setVisibility(View.VISIBLE); |
| 269 | mDotView.setVisibility(View.GONE); |
| 270 | break; |
| 271 | case STATE_DOT: |
| 272 | mMobileGroup.setVisibility(View.INVISIBLE); |
| 273 | mDotView.setVisibility(View.VISIBLE); |
| 274 | break; |
| 275 | case STATE_HIDDEN: |
| 276 | default: |
Evan Laird | 7804778 | 2018-06-04 17:54:42 -0400 | [diff] [blame] | 277 | mMobileGroup.setVisibility(View.INVISIBLE); |
| 278 | mDotView.setVisibility(View.INVISIBLE); |
Evan Laird | 97ae20c | 2018-05-10 13:13:27 -0400 | [diff] [blame] | 279 | break; |
| 280 | } |
Evan Laird | 20b87bf | 2018-04-12 09:54:11 -0400 | [diff] [blame] | 281 | } |
| 282 | |
Evan Laird | 150701d4 | 2018-05-04 16:14:00 -0400 | [diff] [blame] | 283 | @Override |
| 284 | public int getVisibleState() { |
Evan Laird | 97ae20c | 2018-05-10 13:13:27 -0400 | [diff] [blame] | 285 | return mVisibleState; |
Evan Laird | 150701d4 | 2018-05-04 16:14:00 -0400 | [diff] [blame] | 286 | } |
| 287 | |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 288 | @VisibleForTesting |
| 289 | public MobileIconState getState() { |
| 290 | return mState; |
| 291 | } |
| 292 | |
| 293 | @Override |
| 294 | public String toString() { |
| 295 | return "StatusBarMobileView(slot=" + mSlot + " state=" + mState + ")"; |
| 296 | } |
| 297 | } |