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