John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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.qs; |
| 18 | |
| 19 | import android.content.Context; |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 20 | import android.content.res.Configuration; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 21 | import android.content.res.Resources; |
| 22 | import android.content.res.TypedArray; |
| 23 | import android.graphics.Typeface; |
| 24 | import android.graphics.drawable.Drawable; |
John Spurlock | 4bf3198 | 2014-05-21 13:04:22 -0400 | [diff] [blame] | 25 | import android.graphics.drawable.RippleDrawable; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 26 | import android.os.Handler; |
| 27 | import android.os.Looper; |
| 28 | import android.os.Message; |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 29 | import android.util.MathUtils; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 30 | import android.util.TypedValue; |
| 31 | import android.view.Gravity; |
| 32 | import android.view.View; |
| 33 | import android.view.ViewGroup; |
John Spurlock | 83e2848 | 2014-05-18 17:20:05 -0400 | [diff] [blame] | 34 | import android.widget.ImageView; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 35 | import android.widget.ImageView.ScaleType; |
| 36 | import android.widget.TextView; |
| 37 | |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 38 | import com.android.systemui.FontSizeUtils; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 39 | import com.android.systemui.R; |
| 40 | import com.android.systemui.qs.QSTile.State; |
| 41 | |
| 42 | /** View that represents a standard quick settings tile. **/ |
| 43 | public class QSTileView extends ViewGroup { |
| 44 | private static final Typeface CONDENSED = Typeface.create("sans-serif-condensed", |
| 45 | Typeface.NORMAL); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 46 | |
| 47 | protected final Context mContext; |
| 48 | private final View mIcon; |
| 49 | private final View mDivider; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 50 | private final H mHandler = new H(); |
John Spurlock | 4bf3198 | 2014-05-21 13:04:22 -0400 | [diff] [blame] | 51 | private final int mIconSizePx; |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 52 | private final int mTileSpacingPx; |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 53 | private int mTilePaddingTopPx; |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 54 | private final int mTilePaddingBelowIconPx; |
John Spurlock | 39076ed | 2014-06-30 20:47:20 -0400 | [diff] [blame] | 55 | private final int mDualTileVerticalPaddingPx; |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 56 | private final View mTopBackgroundView; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 57 | |
John Spurlock | d47a3f3 | 2014-05-18 19:14:14 -0400 | [diff] [blame] | 58 | private TextView mLabel; |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 59 | private QSDualTileLabel mDualLabel; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 60 | private boolean mDual; |
| 61 | private OnClickListener mClickPrimary; |
| 62 | private OnClickListener mClickSecondary; |
John Spurlock | 4bf3198 | 2014-05-21 13:04:22 -0400 | [diff] [blame] | 63 | private RippleDrawable mRipple; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 64 | |
| 65 | public QSTileView(Context context) { |
| 66 | super(context); |
| 67 | |
| 68 | mContext = context; |
| 69 | final Resources res = context.getResources(); |
John Spurlock | 4bf3198 | 2014-05-21 13:04:22 -0400 | [diff] [blame] | 70 | mIconSizePx = res.getDimensionPixelSize(R.dimen.qs_tile_icon_size); |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 71 | mTileSpacingPx = res.getDimensionPixelSize(R.dimen.qs_tile_spacing); |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 72 | mTilePaddingBelowIconPx = res.getDimensionPixelSize(R.dimen.qs_tile_padding_below_icon); |
John Spurlock | 39076ed | 2014-06-30 20:47:20 -0400 | [diff] [blame] | 73 | mDualTileVerticalPaddingPx = |
| 74 | res.getDimensionPixelSize(R.dimen.qs_dual_tile_padding_vertical); |
John Spurlock | d47a3f3 | 2014-05-18 19:14:14 -0400 | [diff] [blame] | 75 | recreateLabel(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 76 | setClipChildren(false); |
| 77 | |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 78 | mTopBackgroundView = new View(context); |
| 79 | addView(mTopBackgroundView); |
| 80 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 81 | mIcon = createIcon(); |
| 82 | addView(mIcon); |
| 83 | |
| 84 | mDivider = new View(mContext); |
John Spurlock | 4bf3198 | 2014-05-21 13:04:22 -0400 | [diff] [blame] | 85 | mDivider.setBackgroundColor(res.getColor(R.color.qs_tile_divider)); |
| 86 | final int dh = res.getDimensionPixelSize(R.dimen.qs_tile_divider_height); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 87 | mDivider.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, dh)); |
| 88 | addView(mDivider); |
| 89 | |
| 90 | setClickable(true); |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 91 | |
| 92 | updateTopPadding(); |
| 93 | } |
| 94 | |
| 95 | private void updateTopPadding() { |
| 96 | Resources res = getResources(); |
| 97 | int padding = res.getDimensionPixelSize(R.dimen.qs_tile_padding_top); |
| 98 | int largePadding = res.getDimensionPixelSize(R.dimen.qs_tile_padding_top_large_text); |
| 99 | float largeFactor = (MathUtils.constrain(getResources().getConfiguration().fontScale, |
| 100 | 1.0f, FontSizeUtils.LARGE_TEXT_SCALE) - 1f) / (FontSizeUtils.LARGE_TEXT_SCALE - 1f); |
| 101 | mTilePaddingTopPx = Math.round((1 - largeFactor) * padding + largeFactor * largePadding); |
| 102 | requestLayout(); |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | protected void onConfigurationChanged(Configuration newConfig) { |
| 107 | super.onConfigurationChanged(newConfig); |
| 108 | updateTopPadding(); |
| 109 | FontSizeUtils.updateFontSize(mLabel, R.dimen.qs_tile_text_size); |
| 110 | if (mDualLabel != null) { |
| 111 | mDualLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, |
| 112 | getResources().getDimensionPixelSize(R.dimen.qs_tile_text_size)); |
| 113 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 114 | } |
| 115 | |
John Spurlock | d47a3f3 | 2014-05-18 19:14:14 -0400 | [diff] [blame] | 116 | private void recreateLabel() { |
| 117 | CharSequence labelText = null; |
Selim Cinek | e5557a9 | 2014-08-15 19:59:23 +0200 | [diff] [blame] | 118 | CharSequence labelDescription = null; |
John Spurlock | d47a3f3 | 2014-05-18 19:14:14 -0400 | [diff] [blame] | 119 | if (mLabel != null) { |
| 120 | labelText = mLabel.getText(); |
| 121 | removeView(mLabel); |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 122 | mLabel = null; |
| 123 | } |
| 124 | if (mDualLabel != null) { |
| 125 | labelText = mDualLabel.getText(); |
Selim Cinek | e5557a9 | 2014-08-15 19:59:23 +0200 | [diff] [blame] | 126 | labelDescription = mLabel.getContentDescription(); |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 127 | removeView(mDualLabel); |
| 128 | mDualLabel = null; |
John Spurlock | d47a3f3 | 2014-05-18 19:14:14 -0400 | [diff] [blame] | 129 | } |
| 130 | final Resources res = mContext.getResources(); |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 131 | if (mDual) { |
John Spurlock | 39076ed | 2014-06-30 20:47:20 -0400 | [diff] [blame] | 132 | mDualLabel = new QSDualTileLabel(mContext); |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 133 | mDualLabel.setId(android.R.id.title); |
John Spurlock | 39076ed | 2014-06-30 20:47:20 -0400 | [diff] [blame] | 134 | mDualLabel.setBackgroundResource(R.drawable.btn_borderless_rect); |
Jason Monk | 5d32507 | 2014-10-27 11:38:47 -0400 | [diff] [blame^] | 135 | mDualLabel.setFirstLineCaret(res.getDrawable(R.drawable.qs_dual_tile_caret)); |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 136 | mDualLabel.setTextColor(res.getColor(R.color.qs_tile_text)); |
John Spurlock | 39076ed | 2014-06-30 20:47:20 -0400 | [diff] [blame] | 137 | mDualLabel.setPadding(0, mDualTileVerticalPaddingPx, 0, mDualTileVerticalPaddingPx); |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 138 | mDualLabel.setTypeface(CONDENSED); |
| 139 | mDualLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, |
| 140 | res.getDimensionPixelSize(R.dimen.qs_tile_text_size)); |
| 141 | mDualLabel.setClickable(true); |
| 142 | mDualLabel.setOnClickListener(mClickSecondary); |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 143 | mDualLabel.setFocusable(true); |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 144 | if (labelText != null) { |
| 145 | mDualLabel.setText(labelText); |
| 146 | } |
Selim Cinek | e5557a9 | 2014-08-15 19:59:23 +0200 | [diff] [blame] | 147 | if (labelDescription != null) { |
| 148 | mDualLabel.setContentDescription(labelDescription); |
| 149 | } |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 150 | addView(mDualLabel); |
| 151 | } else { |
| 152 | mLabel = new TextView(mContext); |
| 153 | mLabel.setId(android.R.id.title); |
| 154 | mLabel.setTextColor(res.getColor(R.color.qs_tile_text)); |
| 155 | mLabel.setGravity(Gravity.CENTER_HORIZONTAL); |
| 156 | mLabel.setMinLines(2); |
| 157 | mLabel.setPadding(0, 0, 0, 0); |
| 158 | mLabel.setTypeface(CONDENSED); |
| 159 | mLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, |
| 160 | res.getDimensionPixelSize(R.dimen.qs_tile_text_size)); |
| 161 | mLabel.setClickable(false); |
| 162 | if (labelText != null) { |
| 163 | mLabel.setText(labelText); |
| 164 | } |
| 165 | addView(mLabel); |
John Spurlock | d47a3f3 | 2014-05-18 19:14:14 -0400 | [diff] [blame] | 166 | } |
John Spurlock | d47a3f3 | 2014-05-18 19:14:14 -0400 | [diff] [blame] | 167 | } |
| 168 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 169 | public void setDual(boolean dual) { |
John Spurlock | d47a3f3 | 2014-05-18 19:14:14 -0400 | [diff] [blame] | 170 | final boolean changed = dual != mDual; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 171 | mDual = dual; |
John Spurlock | d47a3f3 | 2014-05-18 19:14:14 -0400 | [diff] [blame] | 172 | if (changed) { |
| 173 | recreateLabel(); |
| 174 | } |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 175 | Drawable tileBackground = getTileBackground(); |
| 176 | if (tileBackground instanceof RippleDrawable) { |
| 177 | setRipple((RippleDrawable) tileBackground); |
| 178 | } |
| 179 | if (dual) { |
| 180 | mTopBackgroundView.setOnClickListener(mClickPrimary); |
| 181 | setOnClickListener(null); |
| 182 | setClickable(false); |
| 183 | setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO); |
| 184 | mTopBackgroundView.setBackground(tileBackground); |
| 185 | } else { |
| 186 | mTopBackgroundView.setOnClickListener(null); |
| 187 | mTopBackgroundView.setClickable(false); |
| 188 | setOnClickListener(mClickPrimary); |
| 189 | setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); |
| 190 | setBackground(tileBackground); |
| 191 | } |
| 192 | mTopBackgroundView.setFocusable(dual); |
| 193 | setFocusable(!dual); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 194 | mDivider.setVisibility(dual ? VISIBLE : GONE); |
| 195 | postInvalidate(); |
| 196 | } |
| 197 | |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 198 | private void setRipple(RippleDrawable tileBackground) { |
| 199 | mRipple = tileBackground; |
| 200 | if (getWidth() != 0) { |
| 201 | updateRippleSize(getWidth(), getHeight()); |
| 202 | } |
| 203 | } |
| 204 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 205 | public void init(OnClickListener clickPrimary, OnClickListener clickSecondary) { |
| 206 | mClickPrimary = clickPrimary; |
| 207 | mClickSecondary = clickSecondary; |
| 208 | } |
| 209 | |
| 210 | protected View createIcon() { |
John Spurlock | 83e2848 | 2014-05-18 17:20:05 -0400 | [diff] [blame] | 211 | final ImageView icon = new ImageView(mContext); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 212 | icon.setId(android.R.id.icon); |
| 213 | icon.setScaleType(ScaleType.CENTER_INSIDE); |
| 214 | return icon; |
| 215 | } |
| 216 | |
John Spurlock | 4bf3198 | 2014-05-21 13:04:22 -0400 | [diff] [blame] | 217 | private Drawable getTileBackground() { |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 218 | final int[] attrs = new int[] { android.R.attr.selectableItemBackgroundBorderless }; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 219 | final TypedArray ta = mContext.obtainStyledAttributes(attrs); |
| 220 | final Drawable d = ta.getDrawable(0); |
| 221 | ta.recycle(); |
| 222 | return d; |
| 223 | } |
| 224 | |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 225 | private View labelView() { |
| 226 | return mDual ? mDualLabel : mLabel; |
| 227 | } |
| 228 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 229 | @Override |
| 230 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 231 | final int w = MeasureSpec.getSize(widthMeasureSpec); |
| 232 | final int h = MeasureSpec.getSize(heightMeasureSpec); |
John Spurlock | 4bf3198 | 2014-05-21 13:04:22 -0400 | [diff] [blame] | 233 | final int iconSpec = exactly(mIconSizePx); |
Jorim Jaggi | c737b9b | 2014-09-08 23:57:20 +0200 | [diff] [blame] | 234 | mIcon.measure(MeasureSpec.makeMeasureSpec(w, MeasureSpec.AT_MOST), iconSpec); |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 235 | labelView().measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(h, MeasureSpec.AT_MOST)); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 236 | if (mDual) { |
| 237 | mDivider.measure(widthMeasureSpec, exactly(mDivider.getLayoutParams().height)); |
| 238 | } |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 239 | int heightSpec = exactly( |
| 240 | mIconSizePx + mTilePaddingBelowIconPx + mTilePaddingTopPx); |
| 241 | mTopBackgroundView.measure(widthMeasureSpec, heightSpec); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 242 | setMeasuredDimension(w, h); |
| 243 | } |
| 244 | |
| 245 | private static int exactly(int size) { |
| 246 | return MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY); |
| 247 | } |
| 248 | |
| 249 | @Override |
| 250 | protected void onLayout(boolean changed, int l, int t, int r, int b) { |
| 251 | final int w = getMeasuredWidth(); |
John Spurlock | 529aa73 | 2014-07-10 22:49:16 -0400 | [diff] [blame] | 252 | final int h = getMeasuredHeight(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 253 | |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 254 | layout(mTopBackgroundView, 0, mTileSpacingPx); |
| 255 | |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 256 | int top = 0; |
| 257 | top += mTileSpacingPx; |
| 258 | top += mTilePaddingTopPx; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 259 | final int iconLeft = (w - mIcon.getMeasuredWidth()) / 2; |
| 260 | layout(mIcon, iconLeft, top); |
John Spurlock | 4bf3198 | 2014-05-21 13:04:22 -0400 | [diff] [blame] | 261 | if (mRipple != null) { |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 262 | updateRippleSize(w, h); |
| 263 | |
John Spurlock | 4bf3198 | 2014-05-21 13:04:22 -0400 | [diff] [blame] | 264 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 265 | top = mIcon.getBottom(); |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 266 | top += mTilePaddingBelowIconPx; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 267 | if (mDual) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 268 | layout(mDivider, 0, top); |
| 269 | top = mDivider.getBottom(); |
| 270 | } |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 271 | layout(labelView(), 0, top); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 272 | } |
| 273 | |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 274 | private void updateRippleSize(int width, int height) { |
| 275 | // center the touch feedback on the center of the icon, and dial it down a bit |
| 276 | final int cx = width / 2; |
| 277 | final int cy = mDual ? mIcon.getTop() + mIcon.getHeight() / 2 : height / 2; |
| 278 | final int rad = (int)(mIcon.getHeight() * 1.25f); |
| 279 | mRipple.setHotspotBounds(cx - rad, cy - rad, cx + rad, cy + rad); |
| 280 | } |
| 281 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 282 | private static void layout(View child, int left, int top) { |
| 283 | child.layout(left, top, left + child.getMeasuredWidth(), top + child.getMeasuredHeight()); |
| 284 | } |
| 285 | |
| 286 | protected void handleStateChanged(QSTile.State state) { |
John Spurlock | 83e2848 | 2014-05-18 17:20:05 -0400 | [diff] [blame] | 287 | if (mIcon instanceof ImageView) { |
| 288 | ImageView iv = (ImageView) mIcon; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 289 | if (state.icon != null) { |
John Spurlock | 83e2848 | 2014-05-18 17:20:05 -0400 | [diff] [blame] | 290 | iv.setImageDrawable(state.icon); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 291 | } else if (state.iconId > 0) { |
John Spurlock | 83e2848 | 2014-05-18 17:20:05 -0400 | [diff] [blame] | 292 | iv.setImageResource(state.iconId); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 293 | } |
Selim Cinek | 06d3bca | 2014-08-26 17:29:20 +0200 | [diff] [blame] | 294 | Drawable drawable = iv.getDrawable(); |
| 295 | if (state.autoMirrorDrawable && drawable != null) { |
| 296 | drawable.setAutoMirrored(true); |
| 297 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 298 | } |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 299 | if (mDual) { |
| 300 | mDualLabel.setText(state.label); |
Selim Cinek | e5557a9 | 2014-08-15 19:59:23 +0200 | [diff] [blame] | 301 | mDualLabel.setContentDescription(state.dualLabelContentDescription); |
Jason Monk | ec81d38 | 2014-09-18 16:11:09 -0400 | [diff] [blame] | 302 | mTopBackgroundView.setContentDescription(state.contentDescription); |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 303 | } else { |
| 304 | mLabel.setText(state.label); |
Jason Monk | ec81d38 | 2014-09-18 16:11:09 -0400 | [diff] [blame] | 305 | setContentDescription(state.contentDescription); |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 306 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | public void onStateChanged(QSTile.State state) { |
| 310 | mHandler.obtainMessage(H.STATE_CHANGED, state).sendToTarget(); |
| 311 | } |
| 312 | |
| 313 | private class H extends Handler { |
| 314 | private static final int STATE_CHANGED = 1; |
| 315 | public H() { |
| 316 | super(Looper.getMainLooper()); |
| 317 | } |
| 318 | @Override |
| 319 | public void handleMessage(Message msg) { |
| 320 | if (msg.what == STATE_CHANGED) { |
| 321 | handleStateChanged((State) msg.obj); |
| 322 | } |
| 323 | } |
| 324 | } |
Selim Cinek | ece4a83 | 2014-08-22 15:35:53 +0000 | [diff] [blame] | 325 | } |