Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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.keyguard; |
| 18 | |
Aurimas Liutikas | d0cec56 | 2018-08-15 11:03:53 -0700 | [diff] [blame] | 19 | import static android.app.slice.Slice.HINT_LIST_ITEM; |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 20 | import static android.view.Display.DEFAULT_DISPLAY; |
| 21 | import static android.view.Display.INVALID_DISPLAY; |
Aurimas Liutikas | d0cec56 | 2018-08-15 11:03:53 -0700 | [diff] [blame] | 22 | |
Lucas Dupin | ad07944 | 2019-04-03 13:14:11 -0700 | [diff] [blame] | 23 | import static com.android.systemui.util.InjectionInflationController.VIEW_CONTEXT; |
| 24 | |
Lucas Dupin | c68ec48 | 2018-03-30 14:24:53 -0700 | [diff] [blame] | 25 | import android.animation.LayoutTransition; |
| 26 | import android.animation.ObjectAnimator; |
| 27 | import android.animation.PropertyValuesHolder; |
Lucas Dupin | f8e274c | 2018-02-22 17:01:55 -0800 | [diff] [blame] | 28 | import android.annotation.ColorInt; |
Fabian Kozynski | 648e555 | 2018-12-18 16:37:08 -0500 | [diff] [blame] | 29 | import android.annotation.StyleRes; |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 30 | import android.app.PendingIntent; |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 31 | import android.content.Context; |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 32 | import android.graphics.Color; |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 33 | import android.graphics.drawable.Drawable; |
Lucas Dupin | 2b61960 | 2019-10-15 10:49:56 -0700 | [diff] [blame] | 34 | import android.graphics.text.LineBreaker; |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 35 | import android.net.Uri; |
Lucas Dupin | a0d5119 | 2018-08-15 11:29:32 -0700 | [diff] [blame] | 36 | import android.os.Trace; |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 37 | import android.provider.Settings; |
Lucas Dupin | 2a3c3e3 | 2018-01-05 17:02:43 -0800 | [diff] [blame] | 38 | import android.text.TextUtils; |
| 39 | import android.text.TextUtils.TruncateAt; |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 40 | import android.util.AttributeSet; |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 41 | import android.util.Log; |
Robert Snoeberger | 78a79d2 | 2019-05-07 16:47:07 -0400 | [diff] [blame] | 42 | import android.util.TypedValue; |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 43 | import android.view.View; |
Lucas Dupin | c68ec48 | 2018-03-30 14:24:53 -0700 | [diff] [blame] | 44 | import android.view.animation.Animation; |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 45 | import android.widget.LinearLayout; |
Lucas Dupin | e570af6 | 2019-02-10 14:52:30 -0800 | [diff] [blame] | 46 | import android.widget.TextView; |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 47 | |
Lucas Dupin | ed00262 | 2018-10-25 18:12:15 -0700 | [diff] [blame] | 48 | import androidx.lifecycle.LiveData; |
| 49 | import androidx.lifecycle.Observer; |
Alan Viverette | e893588 | 2018-03-15 21:19:36 +0000 | [diff] [blame] | 50 | import androidx.slice.Slice; |
| 51 | import androidx.slice.SliceItem; |
Jason Monk | f852f56 | 2018-05-23 16:08:11 -0400 | [diff] [blame] | 52 | import androidx.slice.SliceViewManager; |
Alan Viverette | e893588 | 2018-03-15 21:19:36 +0000 | [diff] [blame] | 53 | import androidx.slice.core.SliceQuery; |
| 54 | import androidx.slice.widget.ListContent; |
| 55 | import androidx.slice.widget.RowContent; |
Aurimas Liutikas | d0cec56 | 2018-08-15 11:03:53 -0700 | [diff] [blame] | 56 | import androidx.slice.widget.SliceContent; |
Alan Viverette | e893588 | 2018-03-15 21:19:36 +0000 | [diff] [blame] | 57 | import androidx.slice.widget.SliceLiveData; |
Jason Monk | 2af1998 | 2017-11-07 19:38:27 -0500 | [diff] [blame] | 58 | |
Lucas Dupin | ed00262 | 2018-10-25 18:12:15 -0700 | [diff] [blame] | 59 | import com.android.internal.annotations.VisibleForTesting; |
| 60 | import com.android.internal.graphics.ColorUtils; |
| 61 | import com.android.settingslib.Utils; |
| 62 | import com.android.systemui.Dependency; |
| 63 | import com.android.systemui.Interpolators; |
Lucas Dupin | e570af6 | 2019-02-10 14:52:30 -0800 | [diff] [blame] | 64 | import com.android.systemui.R; |
Lucas Dupin | ed00262 | 2018-10-25 18:12:15 -0700 | [diff] [blame] | 65 | import com.android.systemui.keyguard.KeyguardSliceProvider; |
Lucas Dupin | ad07944 | 2019-04-03 13:14:11 -0700 | [diff] [blame] | 66 | import com.android.systemui.plugins.ActivityStarter; |
Lucas Dupin | ed00262 | 2018-10-25 18:12:15 -0700 | [diff] [blame] | 67 | import com.android.systemui.statusbar.policy.ConfigurationController; |
| 68 | import com.android.systemui.tuner.TunerService; |
| 69 | import com.android.systemui.util.wakelock.KeepAwakeAnimationListener; |
| 70 | |
Lucas Dupin | 4349952 | 2019-03-04 16:45:58 -0800 | [diff] [blame] | 71 | import java.io.FileDescriptor; |
| 72 | import java.io.PrintWriter; |
Lucas Dupin | ed00262 | 2018-10-25 18:12:15 -0700 | [diff] [blame] | 73 | import java.util.ArrayList; |
| 74 | import java.util.HashMap; |
| 75 | import java.util.List; |
| 76 | |
Lucas Dupin | ad07944 | 2019-04-03 13:14:11 -0700 | [diff] [blame] | 77 | import javax.inject.Inject; |
| 78 | import javax.inject.Named; |
| 79 | |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 80 | /** |
| 81 | * View visible under the clock on the lock screen and AoD. |
| 82 | */ |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 83 | public class KeyguardSliceView extends LinearLayout implements View.OnClickListener, |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 84 | Observer<Slice>, TunerService.Tunable, ConfigurationController.ConfigurationListener { |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 85 | |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 86 | private static final String TAG = "KeyguardSliceView"; |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 87 | public static final int DEFAULT_ANIM_DURATION = 550; |
| 88 | |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 89 | private final HashMap<View, PendingIntent> mClickActions; |
Lucas Dupin | ad07944 | 2019-04-03 13:14:11 -0700 | [diff] [blame] | 90 | private final ActivityStarter mActivityStarter; |
| 91 | private final ConfigurationController mConfigurationController; |
Robert Snoeberger | dc8fee7 | 2019-07-19 16:35:35 -0400 | [diff] [blame] | 92 | private final LayoutTransition mLayoutTransition; |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 93 | private Uri mKeyguardSliceUri; |
Lucas Dupin | e570af6 | 2019-02-10 14:52:30 -0800 | [diff] [blame] | 94 | @VisibleForTesting |
| 95 | TextView mTitle; |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 96 | private Row mRow; |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 97 | private int mTextColor; |
| 98 | private float mDarkAmount = 0; |
| 99 | |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 100 | private LiveData<Slice> mLiveData; |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 101 | private int mDisplayId = INVALID_DISPLAY; |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 102 | private int mIconSize; |
Robert Snoeberger | 78a79d2 | 2019-05-07 16:47:07 -0400 | [diff] [blame] | 103 | private int mIconSizeWithHeader; |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 104 | /** |
Lucas Dupin | 3978e6e | 2018-05-22 18:08:35 -0700 | [diff] [blame] | 105 | * Runnable called whenever the view contents change. |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 106 | */ |
Lucas Dupin | 3978e6e | 2018-05-22 18:08:35 -0700 | [diff] [blame] | 107 | private Runnable mContentChangeListener; |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 108 | private Slice mSlice; |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 109 | private boolean mHasHeader; |
Lucas Dupin | e570af6 | 2019-02-10 14:52:30 -0800 | [diff] [blame] | 110 | private final int mRowWithHeaderPadding; |
| 111 | private final int mRowPadding; |
Robert Snoeberger | 78a79d2 | 2019-05-07 16:47:07 -0400 | [diff] [blame] | 112 | private float mRowTextSize; |
| 113 | private float mRowWithHeaderTextSize; |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 114 | |
Lucas Dupin | ad07944 | 2019-04-03 13:14:11 -0700 | [diff] [blame] | 115 | @Inject |
| 116 | public KeyguardSliceView(@Named(VIEW_CONTEXT) Context context, AttributeSet attrs, |
| 117 | ActivityStarter activityStarter, ConfigurationController configurationController) { |
| 118 | super(context, attrs); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 119 | |
| 120 | TunerService tunerService = Dependency.get(TunerService.class); |
| 121 | tunerService.addTunable(this, Settings.Secure.KEYGUARD_SLICE_URI); |
| 122 | |
| 123 | mClickActions = new HashMap<>(); |
Lucas Dupin | e570af6 | 2019-02-10 14:52:30 -0800 | [diff] [blame] | 124 | mRowPadding = context.getResources().getDimensionPixelSize(R.dimen.subtitle_clock_padding); |
| 125 | mRowWithHeaderPadding = context.getResources() |
| 126 | .getDimensionPixelSize(R.dimen.header_subtitle_padding); |
Lucas Dupin | ad07944 | 2019-04-03 13:14:11 -0700 | [diff] [blame] | 127 | mActivityStarter = activityStarter; |
| 128 | mConfigurationController = configurationController; |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 129 | |
Robert Snoeberger | dc8fee7 | 2019-07-19 16:35:35 -0400 | [diff] [blame] | 130 | mLayoutTransition = new LayoutTransition(); |
| 131 | mLayoutTransition.setStagger(LayoutTransition.CHANGE_APPEARING, DEFAULT_ANIM_DURATION / 2); |
| 132 | mLayoutTransition.setDuration(LayoutTransition.APPEARING, DEFAULT_ANIM_DURATION); |
| 133 | mLayoutTransition.setDuration(LayoutTransition.DISAPPEARING, DEFAULT_ANIM_DURATION / 2); |
| 134 | mLayoutTransition.disableTransitionType(LayoutTransition.CHANGE_APPEARING); |
| 135 | mLayoutTransition.disableTransitionType(LayoutTransition.CHANGE_DISAPPEARING); |
| 136 | mLayoutTransition.setInterpolator(LayoutTransition.APPEARING, |
| 137 | Interpolators.FAST_OUT_SLOW_IN); |
| 138 | mLayoutTransition.setInterpolator(LayoutTransition.DISAPPEARING, Interpolators.ALPHA_OUT); |
| 139 | mLayoutTransition.setAnimateParentHierarchy(false); |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Andy Wickham | a72a8f8 | 2020-01-16 13:57:14 -0800 | [diff] [blame] | 142 | // Temporary workaround to allow KeyguardStatusView to inflate a copy for Universal Smartspace. |
| 143 | // Eventually the existing copy will be reparented instead, and we won't need this. |
| 144 | public KeyguardSliceView(Context context, AttributeSet attributeSet) { |
| 145 | this(context, attributeSet, Dependency.get(ActivityStarter.class), |
| 146 | Dependency.get(ConfigurationController.class)); |
| 147 | } |
| 148 | |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 149 | @Override |
| 150 | protected void onFinishInflate() { |
| 151 | super.onFinishInflate(); |
Lucas Dupin | e570af6 | 2019-02-10 14:52:30 -0800 | [diff] [blame] | 152 | mTitle = findViewById(R.id.title); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 153 | mRow = findViewById(R.id.row); |
Jason Chang | b4e879d | 2018-04-11 11:17:58 +0800 | [diff] [blame] | 154 | mTextColor = Utils.getColorAttrDefaultColor(mContext, R.attr.wallpaperTextColor); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 155 | mIconSize = (int) mContext.getResources().getDimension(R.dimen.widget_icon_size); |
Robert Snoeberger | 78a79d2 | 2019-05-07 16:47:07 -0400 | [diff] [blame] | 156 | mIconSizeWithHeader = (int) mContext.getResources().getDimension(R.dimen.header_icon_size); |
| 157 | mRowTextSize = mContext.getResources().getDimensionPixelSize( |
| 158 | R.dimen.widget_label_font_size); |
| 159 | mRowWithHeaderTextSize = mContext.getResources().getDimensionPixelSize( |
| 160 | R.dimen.header_row_font_size); |
Lucas Dupin | ad07944 | 2019-04-03 13:14:11 -0700 | [diff] [blame] | 161 | mTitle.setOnClickListener(this); |
Lucas Dupin | 2b61960 | 2019-10-15 10:49:56 -0700 | [diff] [blame] | 162 | mTitle.setBreakStrategy(LineBreaker.BREAK_STRATEGY_BALANCED); |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | @Override |
| 166 | protected void onAttachedToWindow() { |
| 167 | super.onAttachedToWindow(); |
| 168 | |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 169 | mDisplayId = getDisplay().getDisplayId(); |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 170 | // Make sure we always have the most current slice |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 171 | mLiveData.observeForever(this); |
Lucas Dupin | ad07944 | 2019-04-03 13:14:11 -0700 | [diff] [blame] | 172 | mConfigurationController.addCallback(this); |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | @Override |
| 176 | protected void onDetachedFromWindow() { |
| 177 | super.onDetachedFromWindow(); |
| 178 | |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 179 | // TODO(b/117344873) Remove below work around after this issue be fixed. |
| 180 | if (mDisplayId == DEFAULT_DISPLAY) { |
| 181 | mLiveData.removeObserver(this); |
| 182 | } |
Lucas Dupin | ad07944 | 2019-04-03 13:14:11 -0700 | [diff] [blame] | 183 | mConfigurationController.removeCallback(this); |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Robert Snoeberger | dc8fee7 | 2019-07-19 16:35:35 -0400 | [diff] [blame] | 186 | @Override |
| 187 | public void onVisibilityAggregated(boolean isVisible) { |
| 188 | super.onVisibilityAggregated(isVisible); |
| 189 | setLayoutTransition(isVisible ? mLayoutTransition : null); |
| 190 | } |
| 191 | |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 192 | /** |
| 193 | * Returns whether the current visible slice has a title/header. |
| 194 | */ |
| 195 | public boolean hasHeader() { |
| 196 | return mHasHeader; |
| 197 | } |
| 198 | |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 199 | private void showSlice() { |
Lucas Dupin | a0d5119 | 2018-08-15 11:29:32 -0700 | [diff] [blame] | 200 | Trace.beginSection("KeyguardSliceView#showSlice"); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 201 | if (mSlice == null) { |
Lucas Dupin | e570af6 | 2019-02-10 14:52:30 -0800 | [diff] [blame] | 202 | mTitle.setVisibility(GONE); |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 203 | mRow.setVisibility(GONE); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 204 | mHasHeader = false; |
Lucas Dupin | 3978e6e | 2018-05-22 18:08:35 -0700 | [diff] [blame] | 205 | if (mContentChangeListener != null) { |
| 206 | mContentChangeListener.run(); |
| 207 | } |
Lucas Dupin | 4349952 | 2019-03-04 16:45:58 -0800 | [diff] [blame] | 208 | Trace.endSection(); |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 209 | return; |
| 210 | } |
Lucas Dupin | ad07944 | 2019-04-03 13:14:11 -0700 | [diff] [blame] | 211 | mClickActions.clear(); |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 212 | |
Aurimas Liutikas | d0cec56 | 2018-08-15 11:03:53 -0700 | [diff] [blame] | 213 | ListContent lc = new ListContent(getContext(), mSlice); |
| 214 | SliceContent headerContent = lc.getHeader(); |
Lucas Dupin | e570af6 | 2019-02-10 14:52:30 -0800 | [diff] [blame] | 215 | mHasHeader = headerContent != null && !headerContent.getSliceItem().hasHint(HINT_LIST_ITEM); |
Lucas Dupin | ed00262 | 2018-10-25 18:12:15 -0700 | [diff] [blame] | 216 | List<SliceContent> subItems = new ArrayList<>(); |
Mady Mellor | 78f04ef | 2018-05-23 15:04:47 -0700 | [diff] [blame] | 217 | for (int i = 0; i < lc.getRowItems().size(); i++) { |
Aurimas Liutikas | d0cec56 | 2018-08-15 11:03:53 -0700 | [diff] [blame] | 218 | SliceContent subItem = lc.getRowItems().get(i); |
| 219 | String itemUri = subItem.getSliceItem().getSlice().getUri().toString(); |
Mady Mellor | 78f04ef | 2018-05-23 15:04:47 -0700 | [diff] [blame] | 220 | // Filter out the action row |
| 221 | if (!KeyguardSliceProvider.KEYGUARD_ACTION_URI.equals(itemUri)) { |
| 222 | subItems.add(subItem); |
| 223 | } |
| 224 | } |
Lucas Dupin | e570af6 | 2019-02-10 14:52:30 -0800 | [diff] [blame] | 225 | if (!mHasHeader) { |
| 226 | mTitle.setVisibility(GONE); |
| 227 | } else { |
| 228 | mTitle.setVisibility(VISIBLE); |
| 229 | |
| 230 | RowContent header = lc.getHeader(); |
| 231 | SliceItem mainTitle = header.getTitleItem(); |
| 232 | CharSequence title = mainTitle != null ? mainTitle.getText() : null; |
| 233 | mTitle.setText(title); |
Lucas Dupin | ad07944 | 2019-04-03 13:14:11 -0700 | [diff] [blame] | 234 | if (header.getPrimaryAction() != null |
| 235 | && header.getPrimaryAction().getAction() != null) { |
| 236 | mClickActions.put(mTitle, header.getPrimaryAction().getAction()); |
| 237 | } |
Lucas Dupin | e570af6 | 2019-02-10 14:52:30 -0800 | [diff] [blame] | 238 | } |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 239 | |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 240 | final int subItemsCount = subItems.size(); |
Lucas Dupin | a2a7a40 | 2018-01-12 17:45:51 -0800 | [diff] [blame] | 241 | final int blendedColor = getTextColor(); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 242 | final int startIndex = mHasHeader ? 1 : 0; // First item is header; skip it |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 243 | mRow.setVisibility(subItemsCount > 0 ? VISIBLE : GONE); |
Lucas Dupin | e570af6 | 2019-02-10 14:52:30 -0800 | [diff] [blame] | 244 | LinearLayout.LayoutParams layoutParams = (LayoutParams) mRow.getLayoutParams(); |
| 245 | layoutParams.topMargin = mHasHeader ? mRowWithHeaderPadding : mRowPadding; |
| 246 | mRow.setLayoutParams(layoutParams); |
| 247 | |
Mady Mellor | 90e9fce | 2018-01-22 17:30:40 -0800 | [diff] [blame] | 248 | for (int i = startIndex; i < subItemsCount; i++) { |
Aurimas Liutikas | d0cec56 | 2018-08-15 11:03:53 -0700 | [diff] [blame] | 249 | RowContent rc = (RowContent) subItems.get(i); |
| 250 | SliceItem item = rc.getSliceItem(); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 251 | final Uri itemTag = item.getSlice().getUri(); |
| 252 | // Try to reuse the view if already exists in the layout |
Lucas Dupin | 2a6c1fa | 2020-02-07 11:29:19 -0800 | [diff] [blame] | 253 | KeyguardSliceTextView button = mRow.findViewWithTag(itemTag); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 254 | if (button == null) { |
Lucas Dupin | 2a6c1fa | 2020-02-07 11:29:19 -0800 | [diff] [blame] | 255 | button = new KeyguardSliceTextView(mContext); |
Lucas Dupin | a2a7a40 | 2018-01-12 17:45:51 -0800 | [diff] [blame] | 256 | button.setTextColor(blendedColor); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 257 | button.setTag(itemTag); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 258 | final int viewIndex = i - (mHasHeader ? 1 : 0); |
Lucas Dupin | c68ec48 | 2018-03-30 14:24:53 -0700 | [diff] [blame] | 259 | mRow.addView(button, viewIndex); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 260 | } |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 261 | |
Mady Mellor | 90e9fce | 2018-01-22 17:30:40 -0800 | [diff] [blame] | 262 | PendingIntent pendingIntent = null; |
Alan Viverette | 8593528 | 2018-02-27 22:10:18 +0000 | [diff] [blame] | 263 | if (rc.getPrimaryAction() != null) { |
| 264 | pendingIntent = rc.getPrimaryAction().getAction(); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 265 | } |
| 266 | mClickActions.put(button, pendingIntent); |
| 267 | |
Lucas Dupin | 1f7374a | 2018-02-26 18:08:33 -0800 | [diff] [blame] | 268 | final SliceItem titleItem = rc.getTitleItem(); |
| 269 | button.setText(titleItem == null ? null : titleItem.getText()); |
Lucas Dupin | 1d5e910 | 2018-05-21 17:58:05 -0700 | [diff] [blame] | 270 | button.setContentDescription(rc.getContentDescription()); |
Robert Snoeberger | 78a79d2 | 2019-05-07 16:47:07 -0400 | [diff] [blame] | 271 | button.setTextSize(TypedValue.COMPLEX_UNIT_PX, |
| 272 | mHasHeader ? mRowWithHeaderTextSize : mRowTextSize); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 273 | |
| 274 | Drawable iconDrawable = null; |
| 275 | SliceItem icon = SliceQuery.find(item.getSlice(), |
| 276 | android.app.slice.SliceItem.FORMAT_IMAGE); |
| 277 | if (icon != null) { |
Robert Snoeberger | 78a79d2 | 2019-05-07 16:47:07 -0400 | [diff] [blame] | 278 | final int iconSize = mHasHeader ? mIconSizeWithHeader : mIconSize; |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 279 | iconDrawable = icon.getIcon().loadDrawable(mContext); |
Lucas Dupin | 2955bf1 | 2018-12-26 10:15:51 -0800 | [diff] [blame] | 280 | if (iconDrawable != null) { |
| 281 | final int width = (int) (iconDrawable.getIntrinsicWidth() |
Robert Snoeberger | 78a79d2 | 2019-05-07 16:47:07 -0400 | [diff] [blame] | 282 | / (float) iconDrawable.getIntrinsicHeight() * iconSize); |
| 283 | iconDrawable.setBounds(0, 0, Math.max(width, 1), iconSize); |
Lucas Dupin | 2955bf1 | 2018-12-26 10:15:51 -0800 | [diff] [blame] | 284 | } |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 285 | } |
Lucas Dupin | acb0eed | 2018-03-03 14:05:04 -0800 | [diff] [blame] | 286 | button.setCompoundDrawables(iconDrawable, null, null, null); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 287 | button.setOnClickListener(this); |
Lucas Dupin | 2c0d52e | 2018-03-14 12:39:00 -0700 | [diff] [blame] | 288 | button.setClickable(pendingIntent != null); |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 291 | // Removing old views |
| 292 | for (int i = 0; i < mRow.getChildCount(); i++) { |
| 293 | View child = mRow.getChildAt(i); |
| 294 | if (!mClickActions.containsKey(child)) { |
| 295 | mRow.removeView(child); |
| 296 | i--; |
| 297 | } |
| 298 | } |
| 299 | |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 300 | if (mContentChangeListener != null) { |
Lucas Dupin | 3978e6e | 2018-05-22 18:08:35 -0700 | [diff] [blame] | 301 | mContentChangeListener.run(); |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 302 | } |
Lucas Dupin | a0d5119 | 2018-08-15 11:29:32 -0700 | [diff] [blame] | 303 | Trace.endSection(); |
Lucas Dupin | 2c5fce6 | 2018-03-05 19:06:00 -0800 | [diff] [blame] | 304 | } |
| 305 | |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 306 | public void setDarkAmount(float darkAmount) { |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 307 | mDarkAmount = darkAmount; |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 308 | mRow.setDarkAmount(darkAmount); |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 309 | updateTextColors(); |
| 310 | } |
| 311 | |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 312 | private void updateTextColors() { |
Lucas Dupin | a2a7a40 | 2018-01-12 17:45:51 -0800 | [diff] [blame] | 313 | final int blendedColor = getTextColor(); |
Lucas Dupin | e570af6 | 2019-02-10 14:52:30 -0800 | [diff] [blame] | 314 | mTitle.setTextColor(blendedColor); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 315 | int childCount = mRow.getChildCount(); |
| 316 | for (int i = 0; i < childCount; i++) { |
| 317 | View v = mRow.getChildAt(i); |
Lucas Dupin | 2a6c1fa | 2020-02-07 11:29:19 -0800 | [diff] [blame] | 318 | if (v instanceof TextView) { |
| 319 | ((TextView) v).setTextColor(blendedColor); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 320 | } |
| 321 | } |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 324 | @Override |
| 325 | public void onClick(View v) { |
| 326 | final PendingIntent action = mClickActions.get(v); |
| 327 | if (action != null) { |
Lucas Dupin | ad07944 | 2019-04-03 13:14:11 -0700 | [diff] [blame] | 328 | mActivityStarter.startPendingIntentDismissingKeyguard(action); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 332 | /** |
Lucas Dupin | 3978e6e | 2018-05-22 18:08:35 -0700 | [diff] [blame] | 333 | * Runnable that gets invoked every time the title or the row visibility changes. |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 334 | * @param contentChangeListener The listener. |
| 335 | */ |
Lucas Dupin | 3978e6e | 2018-05-22 18:08:35 -0700 | [diff] [blame] | 336 | public void setContentChangeListener(Runnable contentChangeListener) { |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 337 | mContentChangeListener = contentChangeListener; |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 338 | } |
| 339 | |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 340 | /** |
| 341 | * LiveData observer lifecycle. |
| 342 | * @param slice the new slice content. |
| 343 | */ |
| 344 | @Override |
| 345 | public void onChanged(Slice slice) { |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 346 | mSlice = slice; |
| 347 | showSlice(); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | @Override |
| 351 | public void onTuningChanged(String key, String newValue) { |
| 352 | setupUri(newValue); |
| 353 | } |
| 354 | |
Lucas Dupin | e570af6 | 2019-02-10 14:52:30 -0800 | [diff] [blame] | 355 | /** |
| 356 | * Sets the slice provider Uri. |
| 357 | */ |
| 358 | public void setupUri(String uriString) { |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 359 | if (uriString == null) { |
| 360 | uriString = KeyguardSliceProvider.KEYGUARD_SLICE_URI; |
| 361 | } |
| 362 | |
| 363 | boolean wasObserving = false; |
| 364 | if (mLiveData != null && mLiveData.hasActiveObservers()) { |
| 365 | wasObserving = true; |
| 366 | mLiveData.removeObserver(this); |
| 367 | } |
| 368 | |
| 369 | mKeyguardSliceUri = Uri.parse(uriString); |
| 370 | mLiveData = SliceLiveData.fromUri(mContext, mKeyguardSliceUri); |
| 371 | |
| 372 | if (wasObserving) { |
| 373 | mLiveData.observeForever(this); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | |
Lucas Dupin | f8e274c | 2018-02-22 17:01:55 -0800 | [diff] [blame] | 377 | @VisibleForTesting |
| 378 | int getTextColor() { |
Lucas Dupin | a2a7a40 | 2018-01-12 17:45:51 -0800 | [diff] [blame] | 379 | return ColorUtils.blendARGB(mTextColor, Color.WHITE, mDarkAmount); |
| 380 | } |
| 381 | |
Lucas Dupin | f8e274c | 2018-02-22 17:01:55 -0800 | [diff] [blame] | 382 | @VisibleForTesting |
| 383 | void setTextColor(@ColorInt int textColor) { |
| 384 | mTextColor = textColor; |
| 385 | updateTextColors(); |
| 386 | } |
| 387 | |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 388 | @Override |
| 389 | public void onDensityOrFontScaleChanged() { |
| 390 | mIconSize = mContext.getResources().getDimensionPixelSize(R.dimen.widget_icon_size); |
Robert Snoeberger | 78a79d2 | 2019-05-07 16:47:07 -0400 | [diff] [blame] | 391 | mIconSizeWithHeader = (int) mContext.getResources().getDimension(R.dimen.header_icon_size); |
| 392 | mRowTextSize = mContext.getResources().getDimensionPixelSize( |
| 393 | R.dimen.widget_label_font_size); |
| 394 | mRowWithHeaderTextSize = mContext.getResources().getDimensionPixelSize( |
| 395 | R.dimen.header_row_font_size); |
Lucas Dupin | 2c5fce6 | 2018-03-05 19:06:00 -0800 | [diff] [blame] | 396 | } |
| 397 | |
Lucas Dupin | 9fedb89 | 2018-05-04 17:42:33 -0700 | [diff] [blame] | 398 | public void refresh() { |
Lucas Dupin | a0d5119 | 2018-08-15 11:29:32 -0700 | [diff] [blame] | 399 | Slice slice; |
| 400 | Trace.beginSection("KeyguardSliceView#refresh"); |
| 401 | // We can optimize performance and avoid binder calls when we know that we're bound |
| 402 | // to a Slice on the same process. |
| 403 | if (KeyguardSliceProvider.KEYGUARD_SLICE_URI.equals(mKeyguardSliceUri.toString())) { |
| 404 | KeyguardSliceProvider instance = KeyguardSliceProvider.getAttachedInstance(); |
| 405 | if (instance != null) { |
| 406 | slice = instance.onBindSlice(mKeyguardSliceUri); |
| 407 | } else { |
| 408 | Log.w(TAG, "Keyguard slice not bound yet?"); |
| 409 | slice = null; |
| 410 | } |
| 411 | } else { |
| 412 | slice = SliceViewManager.getInstance(getContext()).bindSlice(mKeyguardSliceUri); |
| 413 | } |
Lucas Dupin | 9fedb89 | 2018-05-04 17:42:33 -0700 | [diff] [blame] | 414 | onChanged(slice); |
Lucas Dupin | a0d5119 | 2018-08-15 11:29:32 -0700 | [diff] [blame] | 415 | Trace.endSection(); |
Lucas Dupin | 9fedb89 | 2018-05-04 17:42:33 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Lucas Dupin | 4349952 | 2019-03-04 16:45:58 -0800 | [diff] [blame] | 418 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 419 | pw.println("KeyguardSliceView:"); |
| 420 | pw.println(" mClickActions: " + mClickActions); |
| 421 | pw.println(" mTitle: " + (mTitle == null ? "null" : mTitle.getVisibility() == VISIBLE)); |
| 422 | pw.println(" mRow: " + (mRow == null ? "null" : mRow.getVisibility() == VISIBLE)); |
| 423 | pw.println(" mTextColor: " + Integer.toHexString(mTextColor)); |
| 424 | pw.println(" mDarkAmount: " + mDarkAmount); |
| 425 | pw.println(" mSlice: " + mSlice); |
| 426 | pw.println(" mHasHeader: " + mHasHeader); |
| 427 | } |
| 428 | |
Lucas Dupin | 4603fe2 | 2018-03-08 16:51:16 -0800 | [diff] [blame] | 429 | public static class Row extends LinearLayout { |
| 430 | |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 431 | /** |
| 432 | * This view is visible in AOD, which means that the device will sleep if we |
| 433 | * don't hold a wake lock. We want to enter doze only after all views have reached |
| 434 | * their desired positions. |
| 435 | */ |
| 436 | private final Animation.AnimationListener mKeepAwakeListener; |
Robert Snoeberger | dc8fee7 | 2019-07-19 16:35:35 -0400 | [diff] [blame] | 437 | private LayoutTransition mLayoutTransition; |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 438 | private float mDarkAmount; |
Lucas Dupin | c68ec48 | 2018-03-30 14:24:53 -0700 | [diff] [blame] | 439 | |
Lucas Dupin | 4603fe2 | 2018-03-08 16:51:16 -0800 | [diff] [blame] | 440 | public Row(Context context) { |
Lucas Dupin | c68ec48 | 2018-03-30 14:24:53 -0700 | [diff] [blame] | 441 | this(context, null); |
Lucas Dupin | 4603fe2 | 2018-03-08 16:51:16 -0800 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | public Row(Context context, AttributeSet attrs) { |
Lucas Dupin | c68ec48 | 2018-03-30 14:24:53 -0700 | [diff] [blame] | 445 | this(context, attrs, 0); |
Lucas Dupin | 4603fe2 | 2018-03-08 16:51:16 -0800 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | public Row(Context context, AttributeSet attrs, int defStyleAttr) { |
Lucas Dupin | c68ec48 | 2018-03-30 14:24:53 -0700 | [diff] [blame] | 449 | this(context, attrs, defStyleAttr, 0); |
Lucas Dupin | 4603fe2 | 2018-03-08 16:51:16 -0800 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | public Row(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 453 | super(context, attrs, defStyleAttr, defStyleRes); |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 454 | mKeepAwakeListener = new KeepAwakeAnimationListener(mContext); |
Lucas Dupin | c68ec48 | 2018-03-30 14:24:53 -0700 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | @Override |
| 458 | protected void onFinishInflate() { |
Robert Snoeberger | dc8fee7 | 2019-07-19 16:35:35 -0400 | [diff] [blame] | 459 | mLayoutTransition = new LayoutTransition(); |
| 460 | mLayoutTransition.setDuration(DEFAULT_ANIM_DURATION); |
Lucas Dupin | c68ec48 | 2018-03-30 14:24:53 -0700 | [diff] [blame] | 461 | |
| 462 | PropertyValuesHolder left = PropertyValuesHolder.ofInt("left", 0, 1); |
| 463 | PropertyValuesHolder right = PropertyValuesHolder.ofInt("right", 0, 1); |
| 464 | ObjectAnimator changeAnimator = ObjectAnimator.ofPropertyValuesHolder((Object) null, |
| 465 | left, right); |
Robert Snoeberger | dc8fee7 | 2019-07-19 16:35:35 -0400 | [diff] [blame] | 466 | mLayoutTransition.setAnimator(LayoutTransition.CHANGE_APPEARING, changeAnimator); |
| 467 | mLayoutTransition.setAnimator(LayoutTransition.CHANGE_DISAPPEARING, changeAnimator); |
| 468 | mLayoutTransition.setInterpolator(LayoutTransition.CHANGE_APPEARING, |
Lucas Dupin | c68ec48 | 2018-03-30 14:24:53 -0700 | [diff] [blame] | 469 | Interpolators.ACCELERATE_DECELERATE); |
Robert Snoeberger | dc8fee7 | 2019-07-19 16:35:35 -0400 | [diff] [blame] | 470 | mLayoutTransition.setInterpolator(LayoutTransition.CHANGE_DISAPPEARING, |
Lucas Dupin | c68ec48 | 2018-03-30 14:24:53 -0700 | [diff] [blame] | 471 | Interpolators.ACCELERATE_DECELERATE); |
Robert Snoeberger | dc8fee7 | 2019-07-19 16:35:35 -0400 | [diff] [blame] | 472 | mLayoutTransition.setStartDelay(LayoutTransition.CHANGE_APPEARING, |
| 473 | DEFAULT_ANIM_DURATION); |
| 474 | mLayoutTransition.setStartDelay(LayoutTransition.CHANGE_DISAPPEARING, |
| 475 | DEFAULT_ANIM_DURATION); |
Lucas Dupin | c68ec48 | 2018-03-30 14:24:53 -0700 | [diff] [blame] | 476 | |
| 477 | ObjectAnimator appearAnimator = ObjectAnimator.ofFloat(null, "alpha", 0f, 1f); |
Robert Snoeberger | dc8fee7 | 2019-07-19 16:35:35 -0400 | [diff] [blame] | 478 | mLayoutTransition.setAnimator(LayoutTransition.APPEARING, appearAnimator); |
| 479 | mLayoutTransition.setInterpolator(LayoutTransition.APPEARING, Interpolators.ALPHA_IN); |
Lucas Dupin | c68ec48 | 2018-03-30 14:24:53 -0700 | [diff] [blame] | 480 | |
| 481 | ObjectAnimator disappearAnimator = ObjectAnimator.ofFloat(null, "alpha", 1f, 0f); |
Robert Snoeberger | dc8fee7 | 2019-07-19 16:35:35 -0400 | [diff] [blame] | 482 | mLayoutTransition.setInterpolator(LayoutTransition.DISAPPEARING, |
| 483 | Interpolators.ALPHA_OUT); |
| 484 | mLayoutTransition.setDuration(LayoutTransition.DISAPPEARING, DEFAULT_ANIM_DURATION / 4); |
| 485 | mLayoutTransition.setAnimator(LayoutTransition.DISAPPEARING, disappearAnimator); |
Lucas Dupin | c68ec48 | 2018-03-30 14:24:53 -0700 | [diff] [blame] | 486 | |
Robert Snoeberger | dc8fee7 | 2019-07-19 16:35:35 -0400 | [diff] [blame] | 487 | mLayoutTransition.setAnimateParentHierarchy(false); |
| 488 | } |
| 489 | |
| 490 | @Override |
| 491 | public void onVisibilityAggregated(boolean isVisible) { |
| 492 | super.onVisibilityAggregated(isVisible); |
| 493 | setLayoutTransition(isVisible ? mLayoutTransition : null); |
Lucas Dupin | 4603fe2 | 2018-03-08 16:51:16 -0800 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | @Override |
| 497 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 498 | int width = MeasureSpec.getSize(widthMeasureSpec); |
Lucas Dupin | 8b77a3b | 2018-05-01 13:23:03 -0700 | [diff] [blame] | 499 | int childCount = getChildCount(); |
| 500 | for (int i = 0; i < childCount; i++) { |
Lucas Dupin | 4603fe2 | 2018-03-08 16:51:16 -0800 | [diff] [blame] | 501 | View child = getChildAt(i); |
Lucas Dupin | 2a6c1fa | 2020-02-07 11:29:19 -0800 | [diff] [blame] | 502 | if (child instanceof KeyguardSliceTextView) { |
| 503 | ((KeyguardSliceTextView) child).setMaxWidth(width / childCount); |
Lucas Dupin | 4603fe2 | 2018-03-08 16:51:16 -0800 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 507 | } |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 508 | |
| 509 | public void setDarkAmount(float darkAmount) { |
| 510 | boolean isAwake = darkAmount != 0; |
| 511 | boolean wasAwake = mDarkAmount != 0; |
| 512 | if (isAwake == wasAwake) { |
| 513 | return; |
| 514 | } |
| 515 | mDarkAmount = darkAmount; |
| 516 | setLayoutAnimationListener(isAwake ? null : mKeepAwakeListener); |
| 517 | } |
| 518 | |
| 519 | @Override |
| 520 | public boolean hasOverlappingRendering() { |
| 521 | return false; |
| 522 | } |
Lucas Dupin | 4603fe2 | 2018-03-08 16:51:16 -0800 | [diff] [blame] | 523 | } |
| 524 | |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 525 | /** |
| 526 | * Representation of an item that appears under the clock on main keyguard message. |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 527 | */ |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 528 | @VisibleForTesting |
Lucas Dupin | 2a6c1fa | 2020-02-07 11:29:19 -0800 | [diff] [blame] | 529 | static class KeyguardSliceTextView extends TextView implements |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 530 | ConfigurationController.ConfigurationListener { |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 531 | |
Fabian Kozynski | 648e555 | 2018-12-18 16:37:08 -0500 | [diff] [blame] | 532 | @StyleRes |
| 533 | private static int sStyleId = R.style.TextAppearance_Keyguard_Secondary; |
| 534 | |
Lucas Dupin | 2a6c1fa | 2020-02-07 11:29:19 -0800 | [diff] [blame] | 535 | KeyguardSliceTextView(Context context) { |
Fabian Kozynski | 648e555 | 2018-12-18 16:37:08 -0500 | [diff] [blame] | 536 | super(context, null /* attrs */, 0 /* styleAttr */, sStyleId); |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 537 | onDensityOrFontScaleChanged(); |
| 538 | setEllipsize(TruncateAt.END); |
| 539 | } |
| 540 | |
| 541 | @Override |
| 542 | protected void onAttachedToWindow() { |
| 543 | super.onAttachedToWindow(); |
| 544 | Dependency.get(ConfigurationController.class).addCallback(this); |
| 545 | } |
| 546 | |
| 547 | @Override |
| 548 | protected void onDetachedFromWindow() { |
| 549 | super.onDetachedFromWindow(); |
| 550 | Dependency.get(ConfigurationController.class).removeCallback(this); |
| 551 | } |
| 552 | |
| 553 | @Override |
| 554 | public void onDensityOrFontScaleChanged() { |
Lucas Dupin | 8b77a3b | 2018-05-01 13:23:03 -0700 | [diff] [blame] | 555 | updatePadding(); |
| 556 | } |
| 557 | |
| 558 | @Override |
Fabian Kozynski | 648e555 | 2018-12-18 16:37:08 -0500 | [diff] [blame] | 559 | public void onOverlayChanged() { |
| 560 | setTextAppearance(sStyleId); |
| 561 | } |
| 562 | |
| 563 | @Override |
Lucas Dupin | 8b77a3b | 2018-05-01 13:23:03 -0700 | [diff] [blame] | 564 | public void setText(CharSequence text, BufferType type) { |
| 565 | super.setText(text, type); |
| 566 | updatePadding(); |
| 567 | } |
| 568 | |
| 569 | private void updatePadding() { |
| 570 | boolean hasText = !TextUtils.isEmpty(getText()); |
| 571 | int horizontalPadding = (int) getContext().getResources() |
| 572 | .getDimension(R.dimen.widget_horizontal_padding) / 2; |
| 573 | setPadding(horizontalPadding, 0, horizontalPadding * (hasText ? 1 : -1), 0); |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 574 | setCompoundDrawablePadding((int) mContext.getResources() |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 575 | .getDimension(R.dimen.widget_icon_padding)); |
| 576 | } |
Lucas Dupin | acb0eed | 2018-03-03 14:05:04 -0800 | [diff] [blame] | 577 | |
| 578 | @Override |
| 579 | public void setTextColor(int color) { |
| 580 | super.setTextColor(color); |
| 581 | updateDrawableColors(); |
| 582 | } |
| 583 | |
| 584 | @Override |
| 585 | public void setCompoundDrawables(Drawable left, Drawable top, Drawable right, |
| 586 | Drawable bottom) { |
| 587 | super.setCompoundDrawables(left, top, right, bottom); |
| 588 | updateDrawableColors(); |
Lucas Dupin | 8b77a3b | 2018-05-01 13:23:03 -0700 | [diff] [blame] | 589 | updatePadding(); |
Lucas Dupin | acb0eed | 2018-03-03 14:05:04 -0800 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | private void updateDrawableColors() { |
| 593 | final int color = getCurrentTextColor(); |
| 594 | for (Drawable drawable : getCompoundDrawables()) { |
| 595 | if (drawable != null) { |
| 596 | drawable.setTint(color); |
| 597 | } |
| 598 | } |
| 599 | } |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 600 | } |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 601 | } |