Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 1 | /* |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 2 | * Copyright (C) 2017 The Android Open Source Project |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 3 | * |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 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 |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 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. |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 13 | */ |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 14 | package com.android.systemui.qs.tileimpl; |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 15 | |
Jason Monk | cb2307c | 2018-01-15 14:19:45 -0500 | [diff] [blame] | 16 | import static com.android.systemui.qs.tileimpl.QSIconViewImpl.QS_ANIM_LENGTH; |
| 17 | |
Jason Monk | cb2307c | 2018-01-15 14:19:45 -0500 | [diff] [blame] | 18 | import android.animation.ValueAnimator; |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 19 | import android.content.Context; |
Jason Monk | cb2307c | 2018-01-15 14:19:45 -0500 | [diff] [blame] | 20 | import android.content.res.ColorStateList; |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 21 | import android.content.res.TypedArray; |
Fabian Kozynski | 1ab7ede | 2018-12-13 15:05:31 -0500 | [diff] [blame] | 22 | import android.graphics.Color; |
Fabian Kozynski | 487e459 | 2018-12-06 14:05:11 -0500 | [diff] [blame] | 23 | import android.graphics.Path; |
| 24 | import android.graphics.drawable.AdaptiveIconDrawable; |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 25 | import android.graphics.drawable.Drawable; |
| 26 | import android.graphics.drawable.RippleDrawable; |
Fabian Kozynski | 487e459 | 2018-12-06 14:05:11 -0500 | [diff] [blame] | 27 | import android.graphics.drawable.ShapeDrawable; |
| 28 | import android.graphics.drawable.shapes.PathShape; |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 29 | import android.os.Handler; |
| 30 | import android.os.Looper; |
| 31 | import android.os.Message; |
Jason Monk | e2f05d2 | 2017-03-23 10:45:37 -0400 | [diff] [blame] | 32 | import android.service.quicksettings.Tile; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 33 | import android.text.TextUtils; |
Jason Monk | cb2307c | 2018-01-15 14:19:45 -0500 | [diff] [blame] | 34 | import android.util.Log; |
Fabian Kozynski | 487e459 | 2018-12-06 14:05:11 -0500 | [diff] [blame] | 35 | import android.util.PathParser; |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 36 | import android.view.Gravity; |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 37 | import android.view.View; |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 38 | import android.view.ViewGroup; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 39 | import android.view.accessibility.AccessibilityEvent; |
| 40 | import android.view.accessibility.AccessibilityNodeInfo; |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 41 | import android.widget.FrameLayout; |
Jason Monk | cb2307c | 2018-01-15 14:19:45 -0500 | [diff] [blame] | 42 | import android.widget.ImageView; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 43 | import android.widget.Switch; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 44 | |
Jason Monk | cb2307c | 2018-01-15 14:19:45 -0500 | [diff] [blame] | 45 | import com.android.settingslib.Utils; |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 46 | import com.android.systemui.R; |
Jason Monk | cb2307c | 2018-01-15 14:19:45 -0500 | [diff] [blame] | 47 | import com.android.systemui.plugins.qs.QSIconView; |
| 48 | import com.android.systemui.plugins.qs.QSTile; |
Jason Monk | 90950d9 | 2017-06-20 13:16:05 -0400 | [diff] [blame] | 49 | import com.android.systemui.plugins.qs.QSTile.BooleanState; |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 50 | |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 51 | public class QSTileBaseView extends com.android.systemui.plugins.qs.QSTileView { |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 52 | |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 53 | private static final String TAG = "QSTileBaseView"; |
Fabian Kozynski | 487e459 | 2018-12-06 14:05:11 -0500 | [diff] [blame] | 54 | private static final int ICON_MASK_ID = com.android.internal.R.string.config_icon_mask; |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 55 | private final H mHandler = new H(); |
Amin Shaikh | 32d786f | 2018-08-01 17:08:26 -0400 | [diff] [blame] | 56 | private final int[] mLocInScreen = new int[2]; |
Jason Monk | f13413e | 2017-02-15 15:49:32 -0500 | [diff] [blame] | 57 | private final FrameLayout mIconFrame; |
Jiaquan He | 074ae46 | 2016-05-13 08:56:19 -0700 | [diff] [blame] | 58 | protected QSIconView mIcon; |
| 59 | protected RippleDrawable mRipple; |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 60 | private Drawable mTileBackground; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 61 | private String mAccessibilityClass; |
| 62 | private boolean mTileState; |
| 63 | private boolean mCollapsedView; |
Jason Monk | 90950d9 | 2017-06-20 13:16:05 -0400 | [diff] [blame] | 64 | private boolean mClicked; |
shawnlin | 2e7d4e4 | 2019-04-08 17:52:15 +0800 | [diff] [blame] | 65 | private boolean mShowRippleEffect = true; |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 66 | |
Jason Monk | cb2307c | 2018-01-15 14:19:45 -0500 | [diff] [blame] | 67 | private final ImageView mBg; |
| 68 | private final int mColorActive; |
| 69 | private final int mColorInactive; |
| 70 | private final int mColorDisabled; |
| 71 | private int mCircleColor; |
Fabian Kozynski | 487e459 | 2018-12-06 14:05:11 -0500 | [diff] [blame] | 72 | private int mBgSize; |
Jason Monk | cb2307c | 2018-01-15 14:19:45 -0500 | [diff] [blame] | 73 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 74 | public QSTileBaseView(Context context, QSIconView icon) { |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 75 | this(context, icon, false); |
| 76 | } |
| 77 | |
| 78 | public QSTileBaseView(Context context, QSIconView icon, boolean collapsedView) { |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 79 | super(context); |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 80 | // Default to Quick Tile padding, and QSTileView will specify its own padding. |
| 81 | int padding = context.getResources().getDimensionPixelSize(R.dimen.qs_quick_tile_padding); |
Jason Monk | f13413e | 2017-02-15 15:49:32 -0500 | [diff] [blame] | 82 | mIconFrame = new FrameLayout(context); |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 83 | int size = context.getResources().getDimensionPixelSize(R.dimen.qs_quick_tile_size); |
Jason Monk | f13413e | 2017-02-15 15:49:32 -0500 | [diff] [blame] | 84 | addView(mIconFrame, new LayoutParams(size, size)); |
Jason Monk | cb2307c | 2018-01-15 14:19:45 -0500 | [diff] [blame] | 85 | mBg = new ImageView(getContext()); |
Fabian Kozynski | 487e459 | 2018-12-06 14:05:11 -0500 | [diff] [blame] | 86 | Path path = new Path(PathParser.createPathFromPathData( |
| 87 | context.getResources().getString(ICON_MASK_ID))); |
| 88 | float pathSize = AdaptiveIconDrawable.MASK_SIZE; |
| 89 | PathShape p = new PathShape(path, pathSize, pathSize); |
| 90 | ShapeDrawable d = new ShapeDrawable(p); |
Fabian Kozynski | 1ab7ede | 2018-12-13 15:05:31 -0500 | [diff] [blame] | 91 | d.setTintList(ColorStateList.valueOf(Color.TRANSPARENT)); |
Fabian Kozynski | 487e459 | 2018-12-06 14:05:11 -0500 | [diff] [blame] | 92 | int bgSize = context.getResources().getDimensionPixelSize(R.dimen.qs_tile_background_size); |
| 93 | d.setIntrinsicHeight(bgSize); |
| 94 | d.setIntrinsicWidth(bgSize); |
Fabian Kozynski | 487e459 | 2018-12-06 14:05:11 -0500 | [diff] [blame] | 95 | mBg.setImageDrawable(d); |
Fabian Kozynski | bca09b7 | 2019-04-04 15:57:42 -0400 | [diff] [blame] | 96 | FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(bgSize, bgSize, Gravity.CENTER); |
| 97 | mIconFrame.addView(mBg, lp); |
| 98 | mBg.setLayoutParams(lp); |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 99 | mIcon = icon; |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 100 | FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( |
Fabian Kozynski | bca09b7 | 2019-04-04 15:57:42 -0400 | [diff] [blame] | 101 | ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, |
| 102 | Gravity.CENTER); |
Jason Monk | f13413e | 2017-02-15 15:49:32 -0500 | [diff] [blame] | 103 | mIconFrame.addView(mIcon, params); |
Rohan Shah | 28191fc | 2018-01-16 14:28:55 -0800 | [diff] [blame] | 104 | mIconFrame.setClipChildren(false); |
| 105 | mIconFrame.setClipToPadding(false); |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 106 | |
| 107 | mTileBackground = newTileBackground(); |
| 108 | if (mTileBackground instanceof RippleDrawable) { |
| 109 | setRipple((RippleDrawable) mTileBackground); |
| 110 | } |
| 111 | setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); |
| 112 | setBackground(mTileBackground); |
| 113 | |
Jason Chang | b4e879d | 2018-04-11 11:17:58 +0800 | [diff] [blame] | 114 | mColorActive = Utils.getColorAttrDefaultColor(context, android.R.attr.colorAccent); |
Jason Monk | cb2307c | 2018-01-15 14:19:45 -0500 | [diff] [blame] | 115 | mColorDisabled = Utils.getDisabled(context, |
Jason Chang | b4e879d | 2018-04-11 11:17:58 +0800 | [diff] [blame] | 116 | Utils.getColorAttrDefaultColor(context, android.R.attr.textColorTertiary)); |
| 117 | mColorInactive = Utils.getColorAttrDefaultColor(context, android.R.attr.textColorSecondary); |
Jason Monk | cb2307c | 2018-01-15 14:19:45 -0500 | [diff] [blame] | 118 | |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 119 | setPadding(0, 0, 0, 0); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 120 | setClipChildren(false); |
| 121 | setClipToPadding(false); |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 122 | mCollapsedView = collapsedView; |
Min Yun | f07f170 | 2016-06-27 13:55:15 -0700 | [diff] [blame] | 123 | setFocusable(true); |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 124 | } |
| 125 | |
Fabian Kozynski | 487e459 | 2018-12-06 14:05:11 -0500 | [diff] [blame] | 126 | public View getBgCircle() { |
Jason Monk | cb2307c | 2018-01-15 14:19:45 -0500 | [diff] [blame] | 127 | return mBg; |
| 128 | } |
| 129 | |
Jiaquan He | 074ae46 | 2016-05-13 08:56:19 -0700 | [diff] [blame] | 130 | protected Drawable newTileBackground() { |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 131 | final int[] attrs = new int[]{android.R.attr.selectableItemBackgroundBorderless}; |
| 132 | final TypedArray ta = getContext().obtainStyledAttributes(attrs); |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 133 | final Drawable d = ta.getDrawable(0); |
| 134 | ta.recycle(); |
| 135 | return d; |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 136 | } |
| 137 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 138 | private void setRipple(RippleDrawable tileBackground) { |
| 139 | mRipple = tileBackground; |
| 140 | if (getWidth() != 0) { |
Amin Shaikh | 3033099 | 2018-03-26 17:50:42 -0400 | [diff] [blame] | 141 | updateRippleSize(); |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | |
Amin Shaikh | 3033099 | 2018-03-26 17:50:42 -0400 | [diff] [blame] | 145 | private void updateRippleSize() { |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 146 | // center the touch feedback on the center of the icon, and dial it down a bit |
Amin Shaikh | 3033099 | 2018-03-26 17:50:42 -0400 | [diff] [blame] | 147 | final int cx = mIconFrame.getMeasuredWidth() / 2 + mIconFrame.getLeft(); |
| 148 | final int cy = mIconFrame.getMeasuredHeight() / 2 + mIconFrame.getTop(); |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 149 | final int rad = (int) (mIcon.getHeight() * .85f); |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 150 | mRipple.setHotspotBounds(cx - rad, cy - rad, cx + rad, cy + rad); |
| 151 | } |
| 152 | |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 153 | @Override |
| 154 | public void init(QSTile tile) { |
| 155 | init(v -> tile.click(), v -> tile.secondaryClick(), view -> { |
| 156 | tile.longClick(); |
| 157 | return true; |
| 158 | }); |
| 159 | } |
| 160 | |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 161 | public void init(OnClickListener click, OnClickListener secondaryClick, |
| 162 | OnLongClickListener longClick) { |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 163 | setOnClickListener(click); |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 164 | setOnLongClickListener(longClick); |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | @Override |
| 168 | protected void onLayout(boolean changed, int l, int t, int r, int b) { |
| 169 | super.onLayout(changed, l, t, r, b); |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 170 | if (mRipple != null) { |
Amin Shaikh | 3033099 | 2018-03-26 17:50:42 -0400 | [diff] [blame] | 171 | updateRippleSize(); |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | |
Jorim Jaggi | c308117 | 2016-04-08 23:56:37 -0700 | [diff] [blame] | 175 | @Override |
| 176 | public boolean hasOverlappingRendering() { |
| 177 | // Avoid layers for this layout - we don't need them. |
| 178 | return false; |
| 179 | } |
| 180 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 181 | /** |
| 182 | * Update the accessibility order for this view. |
| 183 | * |
| 184 | * @param previousView the view which should be before this one |
| 185 | * @return the last view in this view which is accessible |
| 186 | */ |
| 187 | public View updateAccessibilityOrder(View previousView) { |
| 188 | setAccessibilityTraversalAfter(previousView.getId()); |
| 189 | return this; |
| 190 | } |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 191 | |
| 192 | public void onStateChanged(QSTile.State state) { |
| 193 | mHandler.obtainMessage(H.STATE_CHANGED, state).sendToTarget(); |
| 194 | } |
| 195 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 196 | protected void handleStateChanged(QSTile.State state) { |
Jason Monk | cb2307c | 2018-01-15 14:19:45 -0500 | [diff] [blame] | 197 | int circleColor = getCircleColor(state.state); |
Amin Shaikh | 32d786f | 2018-08-01 17:08:26 -0400 | [diff] [blame] | 198 | boolean allowAnimations = animationsEnabled(); |
Jason Monk | cb2307c | 2018-01-15 14:19:45 -0500 | [diff] [blame] | 199 | if (circleColor != mCircleColor) { |
Amin Shaikh | 32d786f | 2018-08-01 17:08:26 -0400 | [diff] [blame] | 200 | if (allowAnimations) { |
Jason Monk | cb2307c | 2018-01-15 14:19:45 -0500 | [diff] [blame] | 201 | ValueAnimator animator = ValueAnimator.ofArgb(mCircleColor, circleColor) |
| 202 | .setDuration(QS_ANIM_LENGTH); |
| 203 | animator.addUpdateListener(animation -> mBg.setImageTintList(ColorStateList.valueOf( |
| 204 | (Integer) animation.getAnimatedValue()))); |
| 205 | animator.start(); |
| 206 | } else { |
| 207 | QSIconViewImpl.setTint(mBg, circleColor); |
| 208 | } |
| 209 | mCircleColor = circleColor; |
| 210 | } |
| 211 | |
shawnlin | 2e7d4e4 | 2019-04-08 17:52:15 +0800 | [diff] [blame] | 212 | mShowRippleEffect = state.showRippleEffect; |
Jason Monk | e2f05d2 | 2017-03-23 10:45:37 -0400 | [diff] [blame] | 213 | setClickable(state.state != Tile.STATE_UNAVAILABLE); |
Fabian Kozynski | 58d9b86 | 2018-10-29 12:27:42 -0400 | [diff] [blame] | 214 | setLongClickable(state.handlesLongClick); |
Amin Shaikh | 32d786f | 2018-08-01 17:08:26 -0400 | [diff] [blame] | 215 | mIcon.setIcon(state, allowAnimations); |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 216 | setContentDescription(state.contentDescription); |
Rohan Shah | 185f661 | 2018-03-29 17:35:00 -0700 | [diff] [blame] | 217 | |
Fabian Kozynski | a0cbcf9 | 2018-11-29 09:53:57 -0500 | [diff] [blame] | 218 | mAccessibilityClass = |
| 219 | state.state == Tile.STATE_UNAVAILABLE ? null : state.expandedAccessibilityClassName; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 220 | if (state instanceof QSTile.BooleanState) { |
Jason Monk | 90950d9 | 2017-06-20 13:16:05 -0400 | [diff] [blame] | 221 | boolean newState = ((BooleanState) state).value; |
| 222 | if (mTileState != newState) { |
| 223 | mClicked = false; |
| 224 | mTileState = newState; |
| 225 | } |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 226 | } |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 227 | } |
| 228 | |
Amin Shaikh | 32d786f | 2018-08-01 17:08:26 -0400 | [diff] [blame] | 229 | /* The view should not be animated if it's not on screen and no part of it is visible. |
| 230 | */ |
Amin Shaikh | 5df1a75 | 2018-04-03 13:39:53 -0400 | [diff] [blame] | 231 | protected boolean animationsEnabled() { |
Amin Shaikh | 32d786f | 2018-08-01 17:08:26 -0400 | [diff] [blame] | 232 | if (!isShown()) { |
| 233 | return false; |
| 234 | } |
| 235 | if (getAlpha() != 1f) { |
| 236 | return false; |
| 237 | } |
| 238 | getLocationOnScreen(mLocInScreen); |
| 239 | return mLocInScreen[1] >= -getHeight(); |
Amin Shaikh | 5df1a75 | 2018-04-03 13:39:53 -0400 | [diff] [blame] | 240 | } |
| 241 | |
Jason Monk | cb2307c | 2018-01-15 14:19:45 -0500 | [diff] [blame] | 242 | private int getCircleColor(int state) { |
| 243 | switch (state) { |
| 244 | case Tile.STATE_ACTIVE: |
| 245 | return mColorActive; |
| 246 | case Tile.STATE_INACTIVE: |
| 247 | case Tile.STATE_UNAVAILABLE: |
| 248 | return mColorDisabled; |
| 249 | default: |
| 250 | Log.e(TAG, "Invalid state " + state); |
| 251 | return 0; |
| 252 | } |
| 253 | } |
| 254 | |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 255 | @Override |
Jason Monk | e2f05d2 | 2017-03-23 10:45:37 -0400 | [diff] [blame] | 256 | public void setClickable(boolean clickable) { |
| 257 | super.setClickable(clickable); |
shawnlin | 2e7d4e4 | 2019-04-08 17:52:15 +0800 | [diff] [blame] | 258 | setBackground(clickable && mShowRippleEffect ? mRipple : null); |
Jason Monk | e2f05d2 | 2017-03-23 10:45:37 -0400 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | @Override |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 262 | public int getDetailY() { |
| 263 | return getTop() + getHeight() / 2; |
| 264 | } |
| 265 | |
Jason Monk | 1aec93f | 2016-03-01 09:39:30 -0500 | [diff] [blame] | 266 | public QSIconView getIcon() { |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 267 | return mIcon; |
| 268 | } |
| 269 | |
Rohan Shah | a840199 | 2018-01-25 18:22:44 -0800 | [diff] [blame] | 270 | public View getIconWithBackground() { |
| 271 | return mIconFrame; |
| 272 | } |
| 273 | |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 274 | @Override |
Jason Monk | 90950d9 | 2017-06-20 13:16:05 -0400 | [diff] [blame] | 275 | public boolean performClick() { |
| 276 | mClicked = true; |
| 277 | return super.performClick(); |
| 278 | } |
| 279 | |
| 280 | @Override |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 281 | public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 282 | super.onInitializeAccessibilityEvent(event); |
| 283 | if (!TextUtils.isEmpty(mAccessibilityClass)) { |
| 284 | event.setClassName(mAccessibilityClass); |
| 285 | if (Switch.class.getName().equals(mAccessibilityClass)) { |
Jason Monk | 90950d9 | 2017-06-20 13:16:05 -0400 | [diff] [blame] | 286 | boolean b = mClicked ? !mTileState : mTileState; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 287 | String label = getResources() |
Jason Monk | 90950d9 | 2017-06-20 13:16:05 -0400 | [diff] [blame] | 288 | .getString(b ? R.string.switch_bar_on : R.string.switch_bar_off); |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 289 | event.setContentDescription(label); |
Jason Monk | 90950d9 | 2017-06-20 13:16:05 -0400 | [diff] [blame] | 290 | event.setChecked(b); |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 291 | } |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | @Override |
| 296 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
| 297 | super.onInitializeAccessibilityNodeInfo(info); |
Amin Shaikh | bb2c6c9 | 2018-06-12 18:25:43 -0400 | [diff] [blame] | 298 | // Clear selected state so it is not announce by talkback. |
| 299 | info.setSelected(false); |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 300 | if (!TextUtils.isEmpty(mAccessibilityClass)) { |
| 301 | info.setClassName(mAccessibilityClass); |
| 302 | if (Switch.class.getName().equals(mAccessibilityClass)) { |
Jason Monk | 90950d9 | 2017-06-20 13:16:05 -0400 | [diff] [blame] | 303 | boolean b = mClicked ? !mTileState : mTileState; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 304 | String label = getResources() |
Jason Monk | 90950d9 | 2017-06-20 13:16:05 -0400 | [diff] [blame] | 305 | .getString(b ? R.string.switch_bar_on : R.string.switch_bar_off); |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 306 | info.setText(label); |
Jason Monk | 90950d9 | 2017-06-20 13:16:05 -0400 | [diff] [blame] | 307 | info.setChecked(b); |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 308 | info.setCheckable(true); |
Fabian Kozynski | 58d9b86 | 2018-10-29 12:27:42 -0400 | [diff] [blame] | 309 | if (isLongClickable()) { |
| 310 | info.addAction( |
| 311 | new AccessibilityNodeInfo.AccessibilityAction( |
| 312 | AccessibilityNodeInfo.AccessibilityAction |
| 313 | .ACTION_LONG_CLICK.getId(), |
| 314 | getResources().getString( |
| 315 | R.string.accessibility_long_click_tile))); |
| 316 | } |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | } |
| 320 | |
Fabian Kozynski | 00d494d | 2019-04-04 09:53:50 -0400 | [diff] [blame^] | 321 | @Override |
| 322 | public String toString() { |
| 323 | final StringBuilder sb = new StringBuilder(getClass().getSimpleName()).append('['); |
| 324 | sb.append("locInScreen=(" + mLocInScreen[0] + ", " + mLocInScreen[1] + ")"); |
| 325 | sb.append(", iconView=" + mIcon.toString()); |
| 326 | sb.append(", tileState=" + mTileState); |
| 327 | sb.append("]"); |
| 328 | return sb.toString(); |
| 329 | } |
| 330 | |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 331 | private class H extends Handler { |
| 332 | private static final int STATE_CHANGED = 1; |
Fabian Kozynski | 487e459 | 2018-12-06 14:05:11 -0500 | [diff] [blame] | 333 | |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 334 | public H() { |
| 335 | super(Looper.getMainLooper()); |
| 336 | } |
| 337 | |
| 338 | @Override |
| 339 | public void handleMessage(Message msg) { |
| 340 | if (msg.what == STATE_CHANGED) { |
| 341 | handleStateChanged((QSTile.State) msg.obj); |
| 342 | } |
| 343 | } |
| 344 | } |
Fabian Kozynski | 487e459 | 2018-12-06 14:05:11 -0500 | [diff] [blame] | 345 | } |