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