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