Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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.launcher3; |
| 18 | |
Sunny Goyal | eaf7a95 | 2020-07-29 16:54:20 -0700 | [diff] [blame] | 19 | import static android.animation.ValueAnimator.areAnimatorsEnabled; |
Sunny Goyal | de75321 | 2018-05-15 13:55:57 -0700 | [diff] [blame] | 20 | import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED; |
| 21 | import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED; |
Tony Wickham | 9791bd1 | 2019-04-05 13:52:35 -0700 | [diff] [blame] | 22 | |
Sunny Goyal | de75321 | 2018-05-15 13:55:57 -0700 | [diff] [blame] | 23 | import static com.android.launcher3.compat.AccessibilityManagerCompat.isAccessibilityEnabled; |
| 24 | import static com.android.launcher3.compat.AccessibilityManagerCompat.sendCustomAccessibilityEvent; |
| 25 | |
Tony Wickham | 50e5165 | 2017-03-20 17:12:24 -0700 | [diff] [blame] | 26 | import android.annotation.SuppressLint; |
Fengjiang Li | b7860bd | 2023-03-15 10:50:50 -0700 | [diff] [blame] | 27 | import android.annotation.TargetApi; |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 28 | import android.content.Context; |
Fengjiang Li | b7860bd | 2023-03-15 10:50:50 -0700 | [diff] [blame] | 29 | import android.os.Build; |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 30 | import android.util.AttributeSet; |
Sunny Goyal | de75321 | 2018-05-15 13:55:57 -0700 | [diff] [blame] | 31 | import android.util.Pair; |
Tony Wickham | 50e5165 | 2017-03-20 17:12:24 -0700 | [diff] [blame] | 32 | import android.view.MotionEvent; |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 33 | import android.view.View; |
Pinyao Ting | 52d0252 | 2019-09-27 16:29:32 -0700 | [diff] [blame] | 34 | import android.view.accessibility.AccessibilityNodeInfo; |
Sunny Goyal | f3ac703 | 2020-03-13 13:01:33 -0700 | [diff] [blame] | 35 | import android.view.animation.Interpolator; |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 36 | import android.widget.LinearLayout; |
Fengjiang Li | b7860bd | 2023-03-15 10:50:50 -0700 | [diff] [blame] | 37 | import android.window.OnBackAnimationCallback; |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 38 | |
Tony Wickham | 9791bd1 | 2019-04-05 13:52:35 -0700 | [diff] [blame] | 39 | import androidx.annotation.IntDef; |
Tony Wickham | 9791bd1 | 2019-04-05 13:52:35 -0700 | [diff] [blame] | 40 | |
Sunny Goyal | f3ac703 | 2020-03-13 13:01:33 -0700 | [diff] [blame] | 41 | import com.android.launcher3.anim.PendingAnimation; |
Sunny Goyal | 3792096 | 2017-09-28 13:43:24 -0700 | [diff] [blame] | 42 | import com.android.launcher3.util.TouchController; |
Sunny Goyal | 87b5eb6 | 2018-07-03 15:53:39 -0700 | [diff] [blame] | 43 | import com.android.launcher3.views.ActivityContext; |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 44 | import com.android.launcher3.views.BaseDragLayer; |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 45 | |
| 46 | import java.lang.annotation.Retention; |
| 47 | import java.lang.annotation.RetentionPolicy; |
| 48 | |
| 49 | /** |
| 50 | * Base class for a View which shows a floating UI on top of the launcher UI. |
| 51 | */ |
Fengjiang Li | b7860bd | 2023-03-15 10:50:50 -0700 | [diff] [blame] | 52 | @TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) |
Fengjiang Li | 6bb8d79 | 2023-01-12 16:20:58 -0800 | [diff] [blame] | 53 | public abstract class AbstractFloatingView extends LinearLayout implements TouchController, |
Fengjiang Li | b7860bd | 2023-03-15 10:50:50 -0700 | [diff] [blame] | 54 | OnBackAnimationCallback { |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 55 | |
Tony Wickham | 50e5165 | 2017-03-20 17:12:24 -0700 | [diff] [blame] | 56 | @IntDef(flag = true, value = { |
| 57 | TYPE_FOLDER, |
Sunny Goyal | 10a1bd0 | 2017-10-09 14:56:21 -0700 | [diff] [blame] | 58 | TYPE_ACTION_POPUP, |
Sunny Goyal | 3792096 | 2017-09-28 13:43:24 -0700 | [diff] [blame] | 59 | TYPE_WIDGETS_BOTTOM_SHEET, |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 60 | TYPE_WIDGET_RESIZE_FRAME, |
Sunny Goyal | f8088ee | 2017-11-10 14:52:00 -0800 | [diff] [blame] | 61 | TYPE_WIDGETS_FULL_SHEET, |
Tony Wickham | 2fae2a0 | 2017-12-14 18:38:25 -0800 | [diff] [blame] | 62 | TYPE_ON_BOARD_POPUP, |
Vadim Tryshev | 17839d5 | 2018-05-23 14:45:56 -0700 | [diff] [blame] | 63 | TYPE_DISCOVERY_BOUNCE, |
Tony Wickham | 6a71a5b | 2018-08-21 11:40:23 -0700 | [diff] [blame] | 64 | TYPE_SNACKBAR, |
Jon Miranda | de0093d | 2019-04-16 20:53:24 -0700 | [diff] [blame] | 65 | TYPE_LISTENER, |
Jon Miranda | 517cec5 | 2020-05-19 14:04:59 -0700 | [diff] [blame] | 66 | TYPE_ALL_APPS_EDU, |
Sunny Goyal | 384b578 | 2021-02-09 22:50:02 -0800 | [diff] [blame] | 67 | TYPE_DRAG_DROP_POPUP, |
Sunny Goyal | 02424b2 | 2018-01-19 11:24:32 -0800 | [diff] [blame] | 68 | TYPE_TASK_MENU, |
Sunny Goyal | 30ac97d | 2020-06-24 23:47:46 -0700 | [diff] [blame] | 69 | TYPE_OPTIONS_POPUP, |
Alina Zaidi | d80cec6 | 2021-05-13 14:13:18 +0100 | [diff] [blame] | 70 | TYPE_ICON_SURFACE, |
Sunny Goyal | a992ac9 | 2023-01-10 17:50:32 -0800 | [diff] [blame] | 71 | TYPE_OPTIONS_POPUP_DIALOG, |
Alina Zaidi | f2c79de | 2021-05-27 14:55:21 +0100 | [diff] [blame] | 72 | TYPE_PIN_WIDGET_FROM_EXTERNAL_POPUP, |
Andy Wickham | 13f3ffe | 2021-07-30 16:00:20 -1000 | [diff] [blame] | 73 | TYPE_WIDGETS_EDUCATION_DIALOG, |
Brian Isganitis | 9e80fb3 | 2022-01-26 19:20:13 -0500 | [diff] [blame] | 74 | TYPE_TASKBAR_EDUCATION_DIALOG, |
Brian Isganitis | 7ef4fe4 | 2022-04-07 16:29:44 -0700 | [diff] [blame] | 75 | TYPE_TASKBAR_ALL_APPS, |
Sunny Goyal | a992ac9 | 2023-01-10 17:50:32 -0800 | [diff] [blame] | 76 | TYPE_ADD_TO_HOME_CONFIRMATION, |
Jagrut Desai | c6d625b | 2023-04-03 16:57:32 -0700 | [diff] [blame] | 77 | TYPE_TASKBAR_OVERLAY_PROXY, |
| 78 | TYPE_TASKBAR_PINNING_POPUP |
Tony Wickham | 50e5165 | 2017-03-20 17:12:24 -0700 | [diff] [blame] | 79 | }) |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 80 | @Retention(RetentionPolicy.SOURCE) |
| 81 | public @interface FloatingViewType {} |
| 82 | public static final int TYPE_FOLDER = 1 << 0; |
Sunny Goyal | 10a1bd0 | 2017-10-09 14:56:21 -0700 | [diff] [blame] | 83 | public static final int TYPE_ACTION_POPUP = 1 << 1; |
Tony Wickham | 343a77e | 2017-04-12 18:31:09 -0700 | [diff] [blame] | 84 | public static final int TYPE_WIDGETS_BOTTOM_SHEET = 1 << 2; |
Sunny Goyal | 3792096 | 2017-09-28 13:43:24 -0700 | [diff] [blame] | 85 | public static final int TYPE_WIDGET_RESIZE_FRAME = 1 << 3; |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 86 | public static final int TYPE_WIDGETS_FULL_SHEET = 1 << 4; |
Sunny Goyal | 02424b2 | 2018-01-19 11:24:32 -0800 | [diff] [blame] | 87 | public static final int TYPE_ON_BOARD_POPUP = 1 << 5; |
Vadim Tryshev | 17839d5 | 2018-05-23 14:45:56 -0700 | [diff] [blame] | 88 | public static final int TYPE_DISCOVERY_BOUNCE = 1 << 6; |
Tony Wickham | 6a71a5b | 2018-08-21 11:40:23 -0700 | [diff] [blame] | 89 | public static final int TYPE_SNACKBAR = 1 << 7; |
Jon Miranda | de0093d | 2019-04-16 20:53:24 -0700 | [diff] [blame] | 90 | public static final int TYPE_LISTENER = 1 << 8; |
Jon Miranda | 517cec5 | 2020-05-19 14:04:59 -0700 | [diff] [blame] | 91 | public static final int TYPE_ALL_APPS_EDU = 1 << 9; |
Sunny Goyal | a4647b6 | 2021-02-02 13:45:34 -0800 | [diff] [blame] | 92 | public static final int TYPE_DRAG_DROP_POPUP = 1 << 10; |
Sunny Goyal | 02424b2 | 2018-01-19 11:24:32 -0800 | [diff] [blame] | 93 | |
| 94 | // Popups related to quickstep UI |
Sunny Goyal | a4647b6 | 2021-02-02 13:45:34 -0800 | [diff] [blame] | 95 | public static final int TYPE_TASK_MENU = 1 << 11; |
| 96 | public static final int TYPE_OPTIONS_POPUP = 1 << 12; |
| 97 | public static final int TYPE_ICON_SURFACE = 1 << 13; |
Sunny Goyal | a992ac9 | 2023-01-10 17:50:32 -0800 | [diff] [blame] | 98 | public static final int TYPE_OPTIONS_POPUP_DIALOG = 1 << 14; |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 99 | |
Sunny Goyal | a992ac9 | 2023-01-10 17:50:32 -0800 | [diff] [blame] | 100 | public static final int TYPE_PIN_WIDGET_FROM_EXTERNAL_POPUP = 1 << 15; |
| 101 | public static final int TYPE_WIDGETS_EDUCATION_DIALOG = 1 << 16; |
| 102 | public static final int TYPE_TASKBAR_EDUCATION_DIALOG = 1 << 17; |
| 103 | public static final int TYPE_TASKBAR_ALL_APPS = 1 << 18; |
| 104 | public static final int TYPE_ADD_TO_HOME_CONFIRMATION = 1 << 19; |
| 105 | public static final int TYPE_TASKBAR_OVERLAY_PROXY = 1 << 20; |
Jagrut Desai | c6d625b | 2023-04-03 16:57:32 -0700 | [diff] [blame] | 106 | public static final int TYPE_TASKBAR_PINNING_POPUP = 1 << 21; |
Brian Isganitis | a2b3295 | 2023-11-30 13:27:28 -0500 | [diff] [blame] | 107 | public static final int TYPE_PIN_IME_POPUP = 1 << 22; |
Alina Zaidi | d80cec6 | 2021-05-13 14:13:18 +0100 | [diff] [blame] | 108 | |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 109 | public static final int TYPE_ALL = TYPE_FOLDER | TYPE_ACTION_POPUP |
Sunny Goyal | f8088ee | 2017-11-10 14:52:00 -0800 | [diff] [blame] | 110 | | TYPE_WIDGETS_BOTTOM_SHEET | TYPE_WIDGET_RESIZE_FRAME | TYPE_WIDGETS_FULL_SHEET |
Sunny Goyal | 462551b | 2019-02-18 14:42:47 -0800 | [diff] [blame] | 111 | | TYPE_ON_BOARD_POPUP | TYPE_DISCOVERY_BOUNCE | TYPE_TASK_MENU |
Sunny Goyal | 30ac97d | 2020-06-24 23:47:46 -0700 | [diff] [blame] | 112 | | TYPE_OPTIONS_POPUP | TYPE_SNACKBAR | TYPE_LISTENER | TYPE_ALL_APPS_EDU |
Alina Zaidi | f2c79de | 2021-05-27 14:55:21 +0100 | [diff] [blame] | 113 | | TYPE_ICON_SURFACE | TYPE_DRAG_DROP_POPUP | TYPE_PIN_WIDGET_FROM_EXTERNAL_POPUP |
Brian Isganitis | 7ef4fe4 | 2022-04-07 16:29:44 -0700 | [diff] [blame] | 114 | | TYPE_WIDGETS_EDUCATION_DIALOG | TYPE_TASKBAR_EDUCATION_DIALOG | TYPE_TASKBAR_ALL_APPS |
Brian Isganitis | 589c8d3 | 2022-11-17 20:08:05 +0000 | [diff] [blame] | 115 | | TYPE_OPTIONS_POPUP_DIALOG | TYPE_ADD_TO_HOME_CONFIRMATION |
Brian Isganitis | a2b3295 | 2023-11-30 13:27:28 -0500 | [diff] [blame] | 116 | | TYPE_TASKBAR_OVERLAY_PROXY | TYPE_TASKBAR_PINNING_POPUP | TYPE_PIN_IME_POPUP; |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 117 | |
Sunny Goyal | 7ede611 | 2017-12-05 15:11:21 -0800 | [diff] [blame] | 118 | // Type of popups which should be kept open during launcher rebind |
| 119 | public static final int TYPE_REBIND_SAFE = TYPE_WIDGETS_FULL_SHEET |
Jon Miranda | 517cec5 | 2020-05-19 14:04:59 -0700 | [diff] [blame] | 120 | | TYPE_WIDGETS_BOTTOM_SHEET | TYPE_ON_BOARD_POPUP | TYPE_DISCOVERY_BOUNCE |
Andy Wickham | 13f3ffe | 2021-07-30 16:00:20 -1000 | [diff] [blame] | 121 | | TYPE_ALL_APPS_EDU | TYPE_ICON_SURFACE | TYPE_WIDGETS_EDUCATION_DIALOG |
Brian Isganitis | 589c8d3 | 2022-11-17 20:08:05 +0000 | [diff] [blame] | 122 | | TYPE_TASKBAR_EDUCATION_DIALOG | TYPE_TASKBAR_ALL_APPS | TYPE_OPTIONS_POPUP_DIALOG |
Brian Isganitis | a2b3295 | 2023-11-30 13:27:28 -0500 | [diff] [blame] | 123 | | TYPE_TASKBAR_OVERLAY_PROXY | TYPE_PIN_IME_POPUP; |
Sunny Goyal | 7ede611 | 2017-12-05 15:11:21 -0800 | [diff] [blame] | 124 | |
Brian Isganitis | a2b3295 | 2023-11-30 13:27:28 -0500 | [diff] [blame] | 125 | /** Type of popups that should get exclusive accessibility focus. */ |
Jon Miranda | 517cec5 | 2020-05-19 14:04:59 -0700 | [diff] [blame] | 126 | public static final int TYPE_ACCESSIBLE = TYPE_ALL & ~TYPE_DISCOVERY_BOUNCE & ~TYPE_LISTENER |
Brian Isganitis | a2b3295 | 2023-11-30 13:27:28 -0500 | [diff] [blame] | 127 | & ~TYPE_ALL_APPS_EDU & ~TYPE_TASKBAR_ALL_APPS & ~TYPE_PIN_IME_POPUP; |
Tony Wickham | df1eb8b | 2018-04-12 17:26:18 -0700 | [diff] [blame] | 128 | |
Hyunyoung Song | f58cf5e | 2018-09-19 16:06:16 -0700 | [diff] [blame] | 129 | // These view all have particular operation associated with swipe down interaction. |
| 130 | public static final int TYPE_STATUS_BAR_SWIPE_DOWN_DISALLOW = TYPE_WIDGETS_BOTTOM_SHEET | |
| 131 | TYPE_WIDGETS_FULL_SHEET | TYPE_WIDGET_RESIZE_FRAME | TYPE_ON_BOARD_POPUP | |
Sunny Goyal | a4647b6 | 2021-02-02 13:45:34 -0800 | [diff] [blame] | 132 | TYPE_DISCOVERY_BOUNCE | TYPE_TASK_MENU | TYPE_DRAG_DROP_POPUP; |
Hyunyoung Song | f58cf5e | 2018-09-19 16:06:16 -0700 | [diff] [blame] | 133 | |
Brian Isganitis | e41faf5 | 2023-04-12 14:16:25 -0400 | [diff] [blame] | 134 | // Floating views that are exclusive to the taskbar overlay window. |
| 135 | public static final int TYPE_TASKBAR_OVERLAYS = |
| 136 | TYPE_TASKBAR_ALL_APPS | TYPE_TASKBAR_EDUCATION_DIALOG; |
| 137 | |
Brian Isganitis | 7eae1e6 | 2023-12-11 21:27:50 +0000 | [diff] [blame] | 138 | // Floating views that a TouchController should not try to intercept touches from. |
| 139 | public static final int TYPE_TOUCH_CONTROLLER_NO_INTERCEPT = TYPE_ALL & ~TYPE_DISCOVERY_BOUNCE |
| 140 | & ~TYPE_LISTENER & ~TYPE_TASKBAR_OVERLAYS; |
| 141 | |
Brian Isganitis | a2b3295 | 2023-11-30 13:27:28 -0500 | [diff] [blame] | 142 | public static final int TYPE_ALL_EXCEPT_ON_BOARD_POPUP = TYPE_ALL & ~TYPE_ON_BOARD_POPUP |
| 143 | & ~TYPE_PIN_IME_POPUP; |
Pat Manning | da69661 | 2023-02-17 15:06:58 +0000 | [diff] [blame] | 144 | |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 145 | protected boolean mIsOpen; |
| 146 | |
| 147 | public AbstractFloatingView(Context context, AttributeSet attrs) { |
| 148 | super(context, attrs); |
| 149 | } |
| 150 | |
| 151 | public AbstractFloatingView(Context context, AttributeSet attrs, int defStyleAttr) { |
| 152 | super(context, attrs, defStyleAttr); |
| 153 | } |
| 154 | |
Tony Wickham | 50e5165 | 2017-03-20 17:12:24 -0700 | [diff] [blame] | 155 | /** |
| 156 | * We need to handle touch events to prevent them from falling through to the workspace below. |
| 157 | */ |
| 158 | @SuppressLint("ClickableViewAccessibility") |
| 159 | @Override |
| 160 | public boolean onTouchEvent(MotionEvent ev) { |
| 161 | return true; |
| 162 | } |
| 163 | |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 164 | public final void close(boolean animate) { |
Sunny Goyal | eaf7a95 | 2020-07-29 16:54:20 -0700 | [diff] [blame] | 165 | animate &= areAnimatorsEnabled(); |
Hyunyoung Song | bd6fba9 | 2018-05-16 15:54:31 -0700 | [diff] [blame] | 166 | if (mIsOpen) { |
Hyunyoung Song | 6b670d6 | 2020-08-22 23:24:43 -0700 | [diff] [blame] | 167 | // Add to WW logging |
Hyunyoung Song | bd6fba9 | 2018-05-16 15:54:31 -0700 | [diff] [blame] | 168 | } |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 169 | handleClose(animate); |
Jon Miranda | 83337f9 | 2018-04-24 12:21:28 -0700 | [diff] [blame] | 170 | mIsOpen = false; |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | protected abstract void handleClose(boolean animate); |
| 174 | |
Tony Wickham | 9791bd1 | 2019-04-05 13:52:35 -0700 | [diff] [blame] | 175 | /** |
| 176 | * Creates a user-controlled animation to hint that the view will be closed if completed. |
| 177 | * @param distanceToMove The max distance that elements should move from their starting point. |
| 178 | */ |
Sunny Goyal | f3ac703 | 2020-03-13 13:01:33 -0700 | [diff] [blame] | 179 | public void addHintCloseAnim( |
| 180 | float distanceToMove, Interpolator interpolator, PendingAnimation target) { } |
Tony Wickham | 9791bd1 | 2019-04-05 13:52:35 -0700 | [diff] [blame] | 181 | |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 182 | public final boolean isOpen() { |
| 183 | return mIsOpen; |
| 184 | } |
| 185 | |
| 186 | protected abstract boolean isOfType(@FloatingViewType int type); |
| 187 | |
Fengjiang Li | 6bb8d79 | 2023-01-12 16:20:58 -0800 | [diff] [blame] | 188 | /** Return true if this view can consume back press. */ |
| 189 | public boolean canHandleBack() { |
Tony Wickham | 52c1b66 | 2018-05-21 13:13:58 -0700 | [diff] [blame] | 190 | return true; |
Sunny Goyal | 3792096 | 2017-09-28 13:43:24 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | @Override |
Fengjiang Li | 6bb8d79 | 2023-01-12 16:20:58 -0800 | [diff] [blame] | 194 | public void onBackInvoked() { |
| 195 | close(true); |
| 196 | } |
| 197 | |
| 198 | @Override |
Sunny Goyal | 3792096 | 2017-09-28 13:43:24 -0700 | [diff] [blame] | 199 | public boolean onControllerTouchEvent(MotionEvent ev) { |
| 200 | return false; |
| 201 | } |
| 202 | |
Sunny Goyal | de75321 | 2018-05-15 13:55:57 -0700 | [diff] [blame] | 203 | protected void announceAccessibilityChanges() { |
| 204 | Pair<View, String> targetInfo = getAccessibilityTarget(); |
| 205 | if (targetInfo == null || !isAccessibilityEnabled(getContext())) { |
| 206 | return; |
| 207 | } |
| 208 | sendCustomAccessibilityEvent( |
| 209 | targetInfo.first, TYPE_WINDOW_STATE_CHANGED, targetInfo.second); |
| 210 | |
| 211 | if (mIsOpen) { |
Andy Wickham | bc83edb | 2020-05-27 12:58:40 -0700 | [diff] [blame] | 212 | getAccessibilityInitialFocusView().performAccessibilityAction( |
| 213 | AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null); |
Sunny Goyal | de75321 | 2018-05-15 13:55:57 -0700 | [diff] [blame] | 214 | } |
Sunny Goyal | 87b5eb6 | 2018-07-03 15:53:39 -0700 | [diff] [blame] | 215 | ActivityContext.lookupContext(getContext()).getDragLayer() |
Sunny Goyal | de75321 | 2018-05-15 13:55:57 -0700 | [diff] [blame] | 216 | .sendAccessibilityEvent(TYPE_WINDOW_CONTENT_CHANGED); |
| 217 | } |
| 218 | |
| 219 | protected Pair<View, String> getAccessibilityTarget() { |
| 220 | return null; |
| 221 | } |
| 222 | |
Andy Wickham | bc83edb | 2020-05-27 12:58:40 -0700 | [diff] [blame] | 223 | /** Returns the View that Accessibility services should focus on first. */ |
| 224 | protected View getAccessibilityInitialFocusView() { |
| 225 | return this; |
| 226 | } |
| 227 | |
Samuel Fufa | 82bbdac | 2020-03-09 18:24:47 -0700 | [diff] [blame] | 228 | /** |
Tony Wickham | d5e116a | 2021-09-14 17:48:14 -0700 | [diff] [blame] | 229 | * Returns a view matching FloatingViewType and {@link #isOpen()} == true. |
Samuel Fufa | 82bbdac | 2020-03-09 18:24:47 -0700 | [diff] [blame] | 230 | */ |
| 231 | public static <T extends AbstractFloatingView> T getOpenView( |
Sunny Goyal | 87b5eb6 | 2018-07-03 15:53:39 -0700 | [diff] [blame] | 232 | ActivityContext activity, @FloatingViewType int type) { |
Tony Wickham | d5e116a | 2021-09-14 17:48:14 -0700 | [diff] [blame] | 233 | return getView(activity, type, true /* mustBeOpen */); |
| 234 | } |
| 235 | |
| 236 | /** |
Tony Wickham | f286f9c | 2022-04-20 14:43:39 -0700 | [diff] [blame] | 237 | * Returns whether there is at least one view of the given type where {@link #isOpen()} == true. |
| 238 | */ |
| 239 | public static boolean hasOpenView(ActivityContext activity, @FloatingViewType int type) { |
| 240 | return getOpenView(activity, type) != null; |
| 241 | } |
| 242 | |
| 243 | /** |
Tony Wickham | d5e116a | 2021-09-14 17:48:14 -0700 | [diff] [blame] | 244 | * Returns a view matching FloatingViewType, and {@link #isOpen()} may be false (if animating |
| 245 | * closed). |
| 246 | */ |
| 247 | public static <T extends AbstractFloatingView> T getAnyView( |
| 248 | ActivityContext activity, @FloatingViewType int type) { |
| 249 | return getView(activity, type, false /* mustBeOpen */); |
| 250 | } |
| 251 | |
| 252 | private static <T extends AbstractFloatingView> T getView( |
| 253 | ActivityContext activity, @FloatingViewType int type, boolean mustBeOpen) { |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 254 | BaseDragLayer dragLayer = activity.getDragLayer(); |
vadimt | 5a22ef7 | 2019-04-17 18:39:00 -0700 | [diff] [blame] | 255 | if (dragLayer == null) return null; |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 256 | // Iterate in reverse order. AbstractFloatingView is added later to the dragLayer, |
| 257 | // and will be one of the last views. |
| 258 | for (int i = dragLayer.getChildCount() - 1; i >= 0; i--) { |
| 259 | View child = dragLayer.getChildAt(i); |
| 260 | if (child instanceof AbstractFloatingView) { |
| 261 | AbstractFloatingView view = (AbstractFloatingView) child; |
Tony Wickham | d5e116a | 2021-09-14 17:48:14 -0700 | [diff] [blame] | 262 | if (view.isOfType(type) && (!mustBeOpen || view.isOpen())) { |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 263 | return (T) view; |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | return null; |
| 268 | } |
| 269 | |
Sunny Goyal | 87b5eb6 | 2018-07-03 15:53:39 -0700 | [diff] [blame] | 270 | public static void closeOpenContainer(ActivityContext activity, |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 271 | @FloatingViewType int type) { |
| 272 | AbstractFloatingView view = getOpenView(activity, type); |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 273 | if (view != null) { |
| 274 | view.close(true); |
| 275 | } |
| 276 | } |
| 277 | |
Sunny Goyal | 87b5eb6 | 2018-07-03 15:53:39 -0700 | [diff] [blame] | 278 | public static void closeOpenViews(ActivityContext activity, boolean animate, |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 279 | @FloatingViewType int type) { |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 280 | BaseDragLayer dragLayer = activity.getDragLayer(); |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 281 | // Iterate in reverse order. AbstractFloatingView is added later to the dragLayer, |
| 282 | // and will be one of the last views. |
| 283 | for (int i = dragLayer.getChildCount() - 1; i >= 0; i--) { |
| 284 | View child = dragLayer.getChildAt(i); |
| 285 | if (child instanceof AbstractFloatingView) { |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 286 | AbstractFloatingView abs = (AbstractFloatingView) child; |
| 287 | if (abs.isOfType(type)) { |
| 288 | abs.close(animate); |
| 289 | } |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | } |
| 293 | |
Sunny Goyal | 87b5eb6 | 2018-07-03 15:53:39 -0700 | [diff] [blame] | 294 | public static void closeAllOpenViews(ActivityContext activity, boolean animate) { |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 295 | closeOpenViews(activity, animate, TYPE_ALL); |
| 296 | activity.finishAutoCancelActionMode(); |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Sunny Goyal | 87b5eb6 | 2018-07-03 15:53:39 -0700 | [diff] [blame] | 299 | public static void closeAllOpenViews(ActivityContext activity) { |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 300 | closeAllOpenViews(activity, true); |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Tracy Zhou | d43e7c2 | 2018-10-16 14:49:55 -0700 | [diff] [blame] | 303 | public static void closeAllOpenViewsExcept(ActivityContext activity, boolean animate, |
| 304 | @FloatingViewType int type) { |
| 305 | closeOpenViews(activity, animate, TYPE_ALL & ~type); |
| 306 | activity.finishAutoCancelActionMode(); |
| 307 | } |
| 308 | |
| 309 | public static void closeAllOpenViewsExcept(ActivityContext activity, |
| 310 | @FloatingViewType int type) { |
| 311 | closeAllOpenViewsExcept(activity, true, type); |
| 312 | } |
| 313 | |
Sunny Goyal | 87b5eb6 | 2018-07-03 15:53:39 -0700 | [diff] [blame] | 314 | public static AbstractFloatingView getTopOpenView(ActivityContext activity) { |
Tony Wickham | df1eb8b | 2018-04-12 17:26:18 -0700 | [diff] [blame] | 315 | return getTopOpenViewWithType(activity, TYPE_ALL); |
| 316 | } |
| 317 | |
Sunny Goyal | 87b5eb6 | 2018-07-03 15:53:39 -0700 | [diff] [blame] | 318 | public static AbstractFloatingView getTopOpenViewWithType(ActivityContext activity, |
Tony Wickham | df1eb8b | 2018-04-12 17:26:18 -0700 | [diff] [blame] | 319 | @FloatingViewType int type) { |
| 320 | return getOpenView(activity, type); |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 321 | } |
vadimt | 34cc5f4 | 2020-06-04 13:38:17 -0700 | [diff] [blame] | 322 | |
| 323 | public boolean canInterceptEventsInSystemGestureRegion() { |
| 324 | return false; |
| 325 | } |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 326 | } |