Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 17 | package com.android.launcher3; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 18 | |
Liran Binyamin | a833af3 | 2023-08-02 16:30:27 -0400 | [diff] [blame] | 19 | import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_X; |
| 20 | import static com.android.launcher3.util.MultiTranslateDelegate.INDEX_BUBBLE_ADJUSTMENT_ANIM; |
| 21 | |
| 22 | import android.animation.AnimatorSet; |
| 23 | import android.animation.ObjectAnimator; |
| 24 | import android.animation.ValueAnimator; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 25 | import android.content.Context; |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 26 | import android.graphics.Rect; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 27 | import android.util.AttributeSet; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 28 | import android.view.Gravity; |
Sunny Goyal | c373e1c | 2021-03-09 17:27:53 -0800 | [diff] [blame] | 29 | import android.view.LayoutInflater; |
Sunny Goyal | d158097 | 2019-04-09 11:52:49 -0700 | [diff] [blame] | 30 | import android.view.MotionEvent; |
Tony Wickham | 39938cb | 2021-02-26 09:15:31 -0800 | [diff] [blame] | 31 | import android.view.View; |
Sunny Goyal | 4ffec48 | 2016-02-09 11:28:52 -0800 | [diff] [blame] | 32 | import android.view.ViewDebug; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 33 | import android.view.ViewGroup; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 34 | import android.widget.FrameLayout; |
| 35 | |
maxwen | f069c2b | 2022-11-15 22:10:05 +0100 | [diff] [blame] | 36 | import com.android.launcher3.Utilities; |
micky387 | 7362a64 | 2024-12-09 10:26:15 -0500 | [diff] [blame] | 37 | |
Liran Binyamin | 69f4974 | 2024-03-04 09:39:53 -0500 | [diff] [blame] | 38 | import androidx.annotation.IntDef; |
mpodolian | dfb4821 | 2024-09-13 17:43:11 -0700 | [diff] [blame] | 39 | import androidx.annotation.Nullable; |
Liran Binyamin | 69f4974 | 2024-03-04 09:39:53 -0500 | [diff] [blame] | 40 | |
mpodolian | 2fd9827 | 2024-12-04 16:23:00 -0800 | [diff] [blame] | 41 | import com.android.launcher3.celllayout.CellLayoutLayoutParams; |
Liran Binyamin | a833af3 | 2023-08-02 16:30:27 -0400 | [diff] [blame] | 42 | import com.android.launcher3.util.HorizontalInsettableView; |
mpodolian | dfb4821 | 2024-09-13 17:43:11 -0700 | [diff] [blame] | 43 | import com.android.launcher3.util.MultiPropertyFactory; |
Liran Binyamin | 69f4974 | 2024-03-04 09:39:53 -0500 | [diff] [blame] | 44 | import com.android.launcher3.util.MultiPropertyFactory.MultiProperty; |
Liran Binyamin | a833af3 | 2023-08-02 16:30:27 -0400 | [diff] [blame] | 45 | import com.android.launcher3.util.MultiTranslateDelegate; |
Liran Binyamin | 69f4974 | 2024-03-04 09:39:53 -0500 | [diff] [blame] | 46 | import com.android.launcher3.util.MultiValueAlpha; |
Liran Binyamin | a833af3 | 2023-08-02 16:30:27 -0400 | [diff] [blame] | 47 | import com.android.launcher3.views.ActivityContext; |
| 48 | |
Liran Binyamin | 69f4974 | 2024-03-04 09:39:53 -0500 | [diff] [blame] | 49 | import java.io.PrintWriter; |
| 50 | import java.lang.annotation.Retention; |
| 51 | import java.lang.annotation.RetentionPolicy; |
| 52 | |
Hyunyoung Song | 95786e0 | 2020-09-15 00:34:10 -0700 | [diff] [blame] | 53 | /** |
| 54 | * View class that represents the bottom row of the home screen. |
| 55 | */ |
| 56 | public class Hotseat extends CellLayout implements Insettable { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 57 | |
Liran Binyamin | 69f4974 | 2024-03-04 09:39:53 -0500 | [diff] [blame] | 58 | public static final int ALPHA_CHANNEL_TASKBAR_ALIGNMENT = 0; |
| 59 | public static final int ALPHA_CHANNEL_PREVIEW_RENDERER = 1; |
| 60 | public static final int ALPHA_CHANNEL_TASKBAR_STASH = 2; |
| 61 | public static final int ALPHA_CHANNEL_CHANNELS_COUNT = 3; |
| 62 | |
| 63 | @Retention(RetentionPolicy.RUNTIME) |
| 64 | @IntDef({ALPHA_CHANNEL_TASKBAR_ALIGNMENT, ALPHA_CHANNEL_PREVIEW_RENDERER, |
| 65 | ALPHA_CHANNEL_TASKBAR_STASH}) |
| 66 | public @interface HotseatQsbAlphaId { |
| 67 | } |
| 68 | |
mpodolian | dfb4821 | 2024-09-13 17:43:11 -0700 | [diff] [blame] | 69 | public static final int ICONS_TRANSLATION_X_NAV_BAR_ALIGNMENT = 0; |
| 70 | public static final int ICONS_TRANSLATION_X_CHANNELS_COUNT = 1; |
| 71 | |
| 72 | @Retention(RetentionPolicy.RUNTIME) |
| 73 | @IntDef({ICONS_TRANSLATION_X_NAV_BAR_ALIGNMENT}) |
| 74 | public @interface IconsTranslationX { |
| 75 | } |
| 76 | |
Sunny Goyal | c373e1c | 2021-03-09 17:27:53 -0800 | [diff] [blame] | 77 | // Ratio of empty space, qsb should take up to appear visually centered. |
| 78 | public static final float QSB_CENTER_FACTOR = .325f; |
Liran Binyamin | a833af3 | 2023-08-02 16:30:27 -0400 | [diff] [blame] | 79 | private static final int BUBBLE_BAR_ADJUSTMENT_ANIMATION_DURATION_MS = 250; |
Sunny Goyal | c373e1c | 2021-03-09 17:27:53 -0800 | [diff] [blame] | 80 | |
Sunny Goyal | 4ffec48 | 2016-02-09 11:28:52 -0800 | [diff] [blame] | 81 | @ViewDebug.ExportedProperty(category = "launcher") |
Sunny Goyal | 12069e6 | 2018-01-16 14:17:20 -0800 | [diff] [blame] | 82 | private boolean mHasVerticalHotseat; |
Shikha Malhotra | f78da1b | 2022-04-11 10:23:18 +0000 | [diff] [blame] | 83 | private Workspace<?> mWorkspace; |
Adam Cohen | b66675a | 2020-05-15 16:16:17 -0700 | [diff] [blame] | 84 | private boolean mSendTouchToWorkspace; |
Liran Binyamin | 69f4974 | 2024-03-04 09:39:53 -0500 | [diff] [blame] | 85 | private final MultiValueAlpha mIconsAlphaChannels; |
| 86 | private final MultiValueAlpha mQsbAlphaChannels; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 87 | |
mpodolian | dfb4821 | 2024-09-13 17:43:11 -0700 | [diff] [blame] | 88 | private @Nullable MultiProperty mQsbTranslationX; |
| 89 | |
| 90 | private final MultiPropertyFactory mIconsTranslationXFactory; |
| 91 | |
Sunny Goyal | c373e1c | 2021-03-09 17:27:53 -0800 | [diff] [blame] | 92 | private final View mQsb; |
Tony Wickham | ae72b46 | 2021-03-10 16:18:40 -0800 | [diff] [blame] | 93 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 94 | public Hotseat(Context context) { |
| 95 | this(context, null); |
| 96 | } |
| 97 | |
| 98 | public Hotseat(Context context, AttributeSet attrs) { |
| 99 | this(context, attrs, 0); |
| 100 | } |
| 101 | |
| 102 | public Hotseat(Context context, AttributeSet attrs, int defStyle) { |
| 103 | super(context, attrs, defStyle); |
Sunny Goyal | c373e1c | 2021-03-09 17:27:53 -0800 | [diff] [blame] | 104 | |
maxwen | f069c2b | 2022-11-15 22:10:05 +0100 | [diff] [blame] | 105 | if (Utilities.showHotseatQsbWidget(context)) { |
| 106 | mQsb = LayoutInflater.from(context).inflate(R.layout.search_container_hotseat, this, false); |
| 107 | } else { |
| 108 | mQsb = LayoutInflater.from(context).inflate(R.layout.search_container_hotseat_empty, this, false); |
| 109 | } |
Sunny Goyal | c373e1c | 2021-03-09 17:27:53 -0800 | [diff] [blame] | 110 | addView(mQsb); |
Liran Binyamin | 69f4974 | 2024-03-04 09:39:53 -0500 | [diff] [blame] | 111 | mIconsAlphaChannels = new MultiValueAlpha(getShortcutsAndWidgets(), |
| 112 | ALPHA_CHANNEL_CHANNELS_COUNT); |
mpodolian | dfb4821 | 2024-09-13 17:43:11 -0700 | [diff] [blame] | 113 | if (mQsb instanceof Reorderable qsbReorderable) { |
| 114 | mQsbTranslationX = qsbReorderable.getTranslateDelegate() |
| 115 | .getTranslationX(MultiTranslateDelegate.INDEX_NAV_BAR_ANIM); |
| 116 | } |
| 117 | mIconsTranslationXFactory = new MultiPropertyFactory<>(getShortcutsAndWidgets(), |
| 118 | VIEW_TRANSLATE_X, ICONS_TRANSLATION_X_CHANNELS_COUNT, Float::sum); |
Liran Binyamin | 69f4974 | 2024-03-04 09:39:53 -0500 | [diff] [blame] | 119 | mQsbAlphaChannels = new MultiValueAlpha(mQsb, ALPHA_CHANNEL_CHANNELS_COUNT); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 120 | } |
| 121 | |
mpodolian | dfb4821 | 2024-09-13 17:43:11 -0700 | [diff] [blame] | 122 | /** Provides translation X for hotseat icons for the channel. */ |
| 123 | public MultiProperty getIconsTranslationX(@IconsTranslationX int channelId) { |
| 124 | return mIconsTranslationXFactory.get(channelId); |
| 125 | } |
| 126 | |
| 127 | /** Provides translation X for hotseat Qsb. */ |
| 128 | @Nullable |
| 129 | public MultiProperty getQsbTranslationX() { |
| 130 | return mQsbTranslationX; |
| 131 | } |
| 132 | |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 133 | /** |
| 134 | * Returns orientation specific cell X given invariant order in the hotseat |
| 135 | */ |
| 136 | public int getCellXFromOrder(int rank) { |
Sunny Goyal | 4f3e938 | 2015-06-05 00:13:25 -0700 | [diff] [blame] | 137 | return mHasVerticalHotseat ? 0 : rank; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 138 | } |
Hyunyoung Song | 31178b8 | 2015-02-24 14:12:51 -0800 | [diff] [blame] | 139 | |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 140 | /** |
| 141 | * Returns orientation specific cell Y given invariant order in the hotseat |
| 142 | */ |
| 143 | public int getCellYFromOrder(int rank) { |
Sunny Goyal | 876e462 | 2018-11-02 13:50:40 -0700 | [diff] [blame] | 144 | return mHasVerticalHotseat ? (getCountY() - (rank + 1)) : 0; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Sihua Ma | a44f4ac | 2024-06-03 18:35:39 +0000 | [diff] [blame] | 147 | boolean isHasVerticalHotseat() { |
| 148 | return mHasVerticalHotseat; |
| 149 | } |
| 150 | |
Sunny Goyal | ab770a1 | 2018-11-14 15:17:26 -0800 | [diff] [blame] | 151 | public void resetLayout(boolean hasVerticalHotseat) { |
Liran Binyamin | a833af3 | 2023-08-02 16:30:27 -0400 | [diff] [blame] | 152 | ActivityContext activityContext = ActivityContext.lookupContext(getContext()); |
| 153 | boolean bubbleBarEnabled = activityContext.isBubbleBarEnabled(); |
| 154 | boolean hasBubbles = activityContext.hasBubbles(); |
Sunny Goyal | 876e462 | 2018-11-02 13:50:40 -0700 | [diff] [blame] | 155 | removeAllViewsInLayout(); |
Sunny Goyal | 11e9649 | 2018-03-23 17:06:00 -0700 | [diff] [blame] | 156 | mHasVerticalHotseat = hasVerticalHotseat; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 157 | DeviceProfile dp = mActivity.getDeviceProfile(); |
Liran Binyamin | a833af3 | 2023-08-02 16:30:27 -0400 | [diff] [blame] | 158 | |
| 159 | if (bubbleBarEnabled) { |
mpodolian | 51e2bb3 | 2024-10-08 14:15:49 -0700 | [diff] [blame] | 160 | if (dp.shouldAdjustHotseatForBubbleBar(getContext(), hasBubbles)) { |
| 161 | getShortcutsAndWidgets().setTranslationProvider( |
| 162 | cellX -> dp.getHotseatAdjustedTranslation(getContext(), cellX)); |
Liran Binyamin | a833af3 | 2023-08-02 16:30:27 -0400 | [diff] [blame] | 163 | if (mQsb instanceof HorizontalInsettableView) { |
| 164 | HorizontalInsettableView insettableQsb = (HorizontalInsettableView) mQsb; |
| 165 | final float insetFraction = (float) dp.iconSizePx / dp.hotseatQsbWidth; |
| 166 | // post this to the looper so that QSB has a chance to redraw itself, e.g. |
| 167 | // after device rotation |
| 168 | mQsb.post(() -> insettableQsb.setHorizontalInsets(insetFraction)); |
| 169 | } |
| 170 | } else { |
| 171 | getShortcutsAndWidgets().setTranslationProvider(null); |
| 172 | if (mQsb instanceof HorizontalInsettableView) { |
| 173 | ((HorizontalInsettableView) mQsb).setHorizontalInsets(0); |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | |
Thales Lima | 8cd020b | 2022-03-15 20:15:14 +0000 | [diff] [blame] | 178 | resetCellSize(dp); |
Sunny Goyal | 11e9649 | 2018-03-23 17:06:00 -0700 | [diff] [blame] | 179 | if (hasVerticalHotseat) { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 180 | setGridSize(1, dp.numShownHotseatIcons); |
Sunny Goyal | 11e9649 | 2018-03-23 17:06:00 -0700 | [diff] [blame] | 181 | } else { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 182 | setGridSize(dp.numShownHotseatIcons, 1); |
Sunny Goyal | 11e9649 | 2018-03-23 17:06:00 -0700 | [diff] [blame] | 183 | } |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 184 | } |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 185 | |
Liran Binyamin | a833af3 | 2023-08-02 16:30:27 -0400 | [diff] [blame] | 186 | /** |
| 187 | * Adjust the hotseat icons for the bubble bar. |
| 188 | * |
| 189 | * <p>When the bubble bar becomes visible, if needed, this method animates the hotseat icons |
| 190 | * to reduce the spacing between them and make room for the bubble bar. The QSB width is |
| 191 | * animated as well to align with the hotseat icons. |
| 192 | * |
| 193 | * <p>When the bubble bar goes away, any adjustments that were previously made are reversed. |
| 194 | */ |
| 195 | public void adjustForBubbleBar(boolean isBubbleBarVisible) { |
| 196 | DeviceProfile dp = mActivity.getDeviceProfile(); |
mpodolian | 28907bc | 2024-11-25 11:40:35 -0800 | [diff] [blame] | 197 | boolean shouldAdjust = isBubbleBarVisible |
| 198 | && dp.shouldAdjustHotseatOrQsbForBubbleBar(getContext()); |
| 199 | boolean shouldAdjustHotseat = shouldAdjust |
| 200 | && dp.shouldAlignBubbleBarWithHotseat(); |
Liran Binyamin | a833af3 | 2023-08-02 16:30:27 -0400 | [diff] [blame] | 201 | ShortcutAndWidgetContainer icons = getShortcutsAndWidgets(); |
Liran Binyamin | a833af3 | 2023-08-02 16:30:27 -0400 | [diff] [blame] | 202 | // update the translation provider for future layout passes of hotseat icons. |
mpodolian | b563271 | 2024-11-13 15:17:59 -0800 | [diff] [blame] | 203 | if (shouldAdjustHotseat) { |
mpodolian | 51e2bb3 | 2024-10-08 14:15:49 -0700 | [diff] [blame] | 204 | icons.setTranslationProvider( |
| 205 | cellX -> dp.getHotseatAdjustedTranslation(getContext(), cellX)); |
Liran Binyamin | a833af3 | 2023-08-02 16:30:27 -0400 | [diff] [blame] | 206 | } else { |
| 207 | icons.setTranslationProvider(null); |
| 208 | } |
mpodolian | 5bf8bff | 2024-11-06 16:11:35 -0800 | [diff] [blame] | 209 | AnimatorSet animatorSet = new AnimatorSet(); |
Liran Binyamin | a833af3 | 2023-08-02 16:30:27 -0400 | [diff] [blame] | 210 | for (int i = 0; i < icons.getChildCount(); i++) { |
| 211 | View child = icons.getChildAt(i); |
mpodolian | 2fd9827 | 2024-12-04 16:23:00 -0800 | [diff] [blame] | 212 | if (child.getLayoutParams() instanceof CellLayoutLayoutParams lp) { |
| 213 | float tx = shouldAdjustHotseat |
| 214 | ? dp.getHotseatAdjustedTranslation(getContext(), lp.getCellX()) : 0; |
| 215 | if (child instanceof Reorderable) { |
| 216 | MultiTranslateDelegate mtd = ((Reorderable) child).getTranslateDelegate(); |
| 217 | animatorSet.play( |
| 218 | mtd.getTranslationX(INDEX_BUBBLE_ADJUSTMENT_ANIM).animateToValue(tx)); |
| 219 | } else { |
| 220 | animatorSet.play(ObjectAnimator.ofFloat(child, VIEW_TRANSLATE_X, tx)); |
| 221 | } |
Liran Binyamin | a833af3 | 2023-08-02 16:30:27 -0400 | [diff] [blame] | 222 | } |
| 223 | } |
mpodolian | 28907bc | 2024-11-25 11:40:35 -0800 | [diff] [blame] | 224 | //TODO(b/381109832) refactor & simplify adjustment logic |
| 225 | boolean shouldAdjustQsb = |
| 226 | shouldAdjustHotseat || (shouldAdjust && dp.shouldAlignBubbleBarWithQSB()); |
Liran Binyamin | 2a47a4a | 2024-07-24 12:25:09 -0400 | [diff] [blame] | 227 | if (mQsb instanceof HorizontalInsettableView horizontalInsettableQsb) { |
| 228 | final float currentInsetFraction = horizontalInsettableQsb.getHorizontalInsets(); |
mpodolian | 28907bc | 2024-11-25 11:40:35 -0800 | [diff] [blame] | 229 | final float targetInsetFraction = shouldAdjustQsb |
mpodolian | b563271 | 2024-11-13 15:17:59 -0800 | [diff] [blame] | 230 | ? (float) dp.iconSizePx / dp.hotseatQsbWidth : 0; |
Liran Binyamin | 2a47a4a | 2024-07-24 12:25:09 -0400 | [diff] [blame] | 231 | ValueAnimator qsbAnimator = |
| 232 | ValueAnimator.ofFloat(currentInsetFraction, targetInsetFraction); |
Liran Binyamin | a833af3 | 2023-08-02 16:30:27 -0400 | [diff] [blame] | 233 | qsbAnimator.addUpdateListener(animation -> { |
Liran Binyamin | 2a47a4a | 2024-07-24 12:25:09 -0400 | [diff] [blame] | 234 | float insetFraction = (float) animation.getAnimatedValue(); |
Liran Binyamin | a833af3 | 2023-08-02 16:30:27 -0400 | [diff] [blame] | 235 | horizontalInsettableQsb.setHorizontalInsets(insetFraction); |
| 236 | }); |
| 237 | animatorSet.play(qsbAnimator); |
| 238 | } |
| 239 | animatorSet.setDuration(BUBBLE_BAR_ADJUSTMENT_ANIMATION_DURATION_MS).start(); |
| 240 | } |
| 241 | |
Adam Cohen | a5f4e48 | 2013-10-11 12:10:28 -0700 | [diff] [blame] | 242 | @Override |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 243 | public void setInsets(Rect insets) { |
| 244 | FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams(); |
Sunny Goyal | c4d3201 | 2020-04-03 17:10:11 -0700 | [diff] [blame] | 245 | DeviceProfile grid = mActivity.getDeviceProfile(); |
Sunny Goyal | 12069e6 | 2018-01-16 14:17:20 -0800 | [diff] [blame] | 246 | |
Sunny Goyal | 11e9649 | 2018-03-23 17:06:00 -0700 | [diff] [blame] | 247 | if (grid.isVerticalBarLayout()) { |
Sunny Goyal | c373e1c | 2021-03-09 17:27:53 -0800 | [diff] [blame] | 248 | mQsb.setVisibility(View.GONE); |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 249 | lp.height = ViewGroup.LayoutParams.MATCH_PARENT; |
Sunny Goyal | 7e2e67f | 2018-01-26 13:40:08 -0800 | [diff] [blame] | 250 | if (grid.isSeascape()) { |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 251 | lp.gravity = Gravity.LEFT; |
Tony Wickham | 1eeffbe | 2018-06-12 15:01:15 -0700 | [diff] [blame] | 252 | lp.width = grid.hotseatBarSizePx + insets.left; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 253 | } else { |
| 254 | lp.gravity = Gravity.RIGHT; |
Tony Wickham | 1eeffbe | 2018-06-12 15:01:15 -0700 | [diff] [blame] | 255 | lp.width = grid.hotseatBarSizePx + insets.right; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 256 | } |
| 257 | } else { |
Sunny Goyal | c373e1c | 2021-03-09 17:27:53 -0800 | [diff] [blame] | 258 | mQsb.setVisibility(View.VISIBLE); |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 259 | lp.gravity = Gravity.BOTTOM; |
| 260 | lp.width = ViewGroup.LayoutParams.MATCH_PARENT; |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 261 | lp.height = grid.hotseatBarSizePx; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 262 | } |
Sunny Goyal | c373e1c | 2021-03-09 17:27:53 -0800 | [diff] [blame] | 263 | |
Sunny Goyal | 57b2279 | 2021-05-25 14:35:01 -0700 | [diff] [blame] | 264 | Rect padding = grid.getHotseatLayoutPadding(getContext()); |
| 265 | setPadding(padding.left, padding.top, padding.right, padding.bottom); |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 266 | setLayoutParams(lp); |
| 267 | InsettableFrameLayout.dispatchInsets(this, insets); |
| 268 | } |
Sunny Goyal | d158097 | 2019-04-09 11:52:49 -0700 | [diff] [blame] | 269 | |
Shikha Malhotra | f78da1b | 2022-04-11 10:23:18 +0000 | [diff] [blame] | 270 | public void setWorkspace(Workspace<?> w) { |
Adam Cohen | b66675a | 2020-05-15 16:16:17 -0700 | [diff] [blame] | 271 | mWorkspace = w; |
Sebastian Franco | 2986e0b | 2024-01-25 10:23:39 -0800 | [diff] [blame] | 272 | setCellLayoutContainer(w); |
Adam Cohen | b66675a | 2020-05-15 16:16:17 -0700 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | @Override |
| 276 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 277 | // We allow horizontal workspace scrolling from within the Hotseat. We do this by delegating |
| 278 | // touch intercept the Workspace, and if it intercepts, delegating touch to the Workspace |
| 279 | // for the remainder of the this input stream. |
| 280 | int yThreshold = getMeasuredHeight() - getPaddingBottom(); |
| 281 | if (mWorkspace != null && ev.getY() <= yThreshold) { |
| 282 | mSendTouchToWorkspace = mWorkspace.onInterceptTouchEvent(ev); |
| 283 | return mSendTouchToWorkspace; |
| 284 | } |
| 285 | return false; |
| 286 | } |
| 287 | |
Sunny Goyal | d158097 | 2019-04-09 11:52:49 -0700 | [diff] [blame] | 288 | @Override |
| 289 | public boolean onTouchEvent(MotionEvent event) { |
Adam Cohen | b66675a | 2020-05-15 16:16:17 -0700 | [diff] [blame] | 290 | // See comment in #onInterceptTouchEvent |
| 291 | if (mSendTouchToWorkspace) { |
| 292 | final int action = event.getAction(); |
| 293 | switch (action & MotionEvent.ACTION_MASK) { |
| 294 | case MotionEvent.ACTION_UP: |
| 295 | case MotionEvent.ACTION_CANCEL: |
| 296 | mSendTouchToWorkspace = false; |
| 297 | } |
| 298 | return mWorkspace.onTouchEvent(event); |
| 299 | } |
Alex Chau | 21698c5 | 2021-09-24 14:36:15 +0100 | [diff] [blame] | 300 | // Always let touch follow through to Workspace. |
| 301 | return false; |
Sunny Goyal | d158097 | 2019-04-09 11:52:49 -0700 | [diff] [blame] | 302 | } |
Schneider Victor-tulias | 3cf264f | 2020-09-22 12:58:38 -0700 | [diff] [blame] | 303 | |
| 304 | @Override |
Sunny Goyal | c373e1c | 2021-03-09 17:27:53 -0800 | [diff] [blame] | 305 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 306 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 307 | |
Alex Chau | 206ede9 | 2022-08-01 17:46:12 +0100 | [diff] [blame] | 308 | DeviceProfile dp = mActivity.getDeviceProfile(); |
maxwen | f069c2b | 2022-11-15 22:10:05 +0100 | [diff] [blame] | 309 | int hotseatQsbWidth = dp.isQsbInline ? dp.hotseatQsbWidth : dp.getHostseatQsbWidth(); |
| 310 | mQsb.measure(MeasureSpec.makeMeasureSpec(hotseatQsbWidth, MeasureSpec.EXACTLY), |
Alex Chau | 206ede9 | 2022-08-01 17:46:12 +0100 | [diff] [blame] | 311 | MeasureSpec.makeMeasureSpec(dp.hotseatQsbHeight, MeasureSpec.EXACTLY)); |
Sunny Goyal | c373e1c | 2021-03-09 17:27:53 -0800 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | @Override |
| 315 | protected void onLayout(boolean changed, int l, int t, int r, int b) { |
| 316 | super.onLayout(changed, l, t, r, b); |
| 317 | |
Alex Chau | 206ede9 | 2022-08-01 17:46:12 +0100 | [diff] [blame] | 318 | int qsbMeasuredWidth = mQsb.getMeasuredWidth(); |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 319 | int left; |
Alex Chau | 206ede9 | 2022-08-01 17:46:12 +0100 | [diff] [blame] | 320 | DeviceProfile dp = mActivity.getDeviceProfile(); |
| 321 | if (dp.isQsbInline) { |
| 322 | int qsbSpace = dp.hotseatBorderSpace; |
Thales Lima | 612230d | 2022-03-31 18:04:37 +0100 | [diff] [blame] | 323 | left = Utilities.isRtl(getResources()) ? r - getPaddingRight() + qsbSpace |
Alex Chau | 206ede9 | 2022-08-01 17:46:12 +0100 | [diff] [blame] | 324 | : l + getPaddingLeft() - qsbMeasuredWidth - qsbSpace; |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 325 | } else { |
Alex Chau | 206ede9 | 2022-08-01 17:46:12 +0100 | [diff] [blame] | 326 | left = (r - l - qsbMeasuredWidth) / 2; |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 327 | } |
Alex Chau | 206ede9 | 2022-08-01 17:46:12 +0100 | [diff] [blame] | 328 | int right = left + qsbMeasuredWidth; |
Sunny Goyal | c373e1c | 2021-03-09 17:27:53 -0800 | [diff] [blame] | 329 | |
Alex Chau | 206ede9 | 2022-08-01 17:46:12 +0100 | [diff] [blame] | 330 | int bottom = b - t - dp.getQsbOffsetY(); |
| 331 | int top = bottom - dp.hotseatQsbHeight; |
Sunny Goyal | c373e1c | 2021-03-09 17:27:53 -0800 | [diff] [blame] | 332 | mQsb.layout(left, top, right, bottom); |
| 333 | } |
| 334 | |
Tony Wickham | 39938cb | 2021-02-26 09:15:31 -0800 | [diff] [blame] | 335 | /** |
Liran Binyamin | 69f4974 | 2024-03-04 09:39:53 -0500 | [diff] [blame] | 336 | * Sets the alpha value of the specified alpha channel of just our ShortcutAndWidgetContainer. |
Tony Wickham | 9ce3b25 | 2021-03-22 14:43:58 -0700 | [diff] [blame] | 337 | */ |
Liran Binyamin | 69f4974 | 2024-03-04 09:39:53 -0500 | [diff] [blame] | 338 | public void setIconsAlpha(float alpha, @HotseatQsbAlphaId int channelId) { |
| 339 | getIconsAlpha(channelId).setValue(alpha); |
Tony Wickham | ae72b46 | 2021-03-10 16:18:40 -0800 | [diff] [blame] | 340 | } |
Sunny Goyal | c373e1c | 2021-03-09 17:27:53 -0800 | [diff] [blame] | 341 | |
Alex Chau | c1d2644 | 2022-06-09 15:09:26 +0100 | [diff] [blame] | 342 | /** |
| 343 | * Sets the alpha value of just our QSB. |
| 344 | */ |
Liran Binyamin | 69f4974 | 2024-03-04 09:39:53 -0500 | [diff] [blame] | 345 | public void setQsbAlpha(float alpha, @HotseatQsbAlphaId int channelId) { |
| 346 | getQsbAlpha(channelId).setValue(alpha); |
Alex Chau | c1d2644 | 2022-06-09 15:09:26 +0100 | [diff] [blame] | 347 | } |
| 348 | |
Liran Binyamin | 69f4974 | 2024-03-04 09:39:53 -0500 | [diff] [blame] | 349 | /** Returns the alpha channel for ShortcutAndWidgetContainer */ |
| 350 | public MultiProperty getIconsAlpha(@HotseatQsbAlphaId int channelId) { |
| 351 | return mIconsAlphaChannels.get(channelId); |
| 352 | } |
| 353 | |
| 354 | /** Returns the alpha channel for Qsb */ |
| 355 | public MultiProperty getQsbAlpha(@HotseatQsbAlphaId int channelId) { |
| 356 | return mQsbAlphaChannels.get(channelId); |
Tracy Zhou | ae88197 | 2021-09-30 10:14:34 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Sunny Goyal | c373e1c | 2021-03-09 17:27:53 -0800 | [diff] [blame] | 359 | /** |
| 360 | * Returns the QSB inside hotseat |
| 361 | */ |
| 362 | public View getQsb() { |
| 363 | return mQsb; |
| 364 | } |
Tony Wickham | 9ce3b25 | 2021-03-22 14:43:58 -0700 | [diff] [blame] | 365 | |
Liran Binyamin | 69f4974 | 2024-03-04 09:39:53 -0500 | [diff] [blame] | 366 | /** Dumps the Hotseat internal state */ |
| 367 | public void dump(String prefix, PrintWriter writer) { |
| 368 | writer.println(prefix + "Hotseat:"); |
| 369 | mIconsAlphaChannels.dump( |
| 370 | prefix + "\t", |
| 371 | writer, |
| 372 | "mIconsAlphaChannels", |
| 373 | "ALPHA_CHANNEL_TASKBAR_ALIGNMENT", |
| 374 | "ALPHA_CHANNEL_PREVIEW_RENDERER", |
| 375 | "ALPHA_CHANNEL_TASKBAR_STASH"); |
| 376 | mQsbAlphaChannels.dump( |
| 377 | prefix + "\t", |
| 378 | writer, |
| 379 | "mQsbAlphaChannels", |
| 380 | "ALPHA_CHANNEL_TASKBAR_ALIGNMENT", |
| 381 | "ALPHA_CHANNEL_PREVIEW_RENDERER", |
| 382 | "ALPHA_CHANNEL_TASKBAR_STASH" |
| 383 | ); |
| 384 | } |
| 385 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 386 | } |