Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 1 | package com.android.launcher3; |
| 2 | |
Sunny Goyal | a314d5a | 2020-05-20 20:34:04 -0700 | [diff] [blame] | 3 | import static com.android.launcher3.config.FeatureFlags.SEPARATE_RECENTS_ACTIVITY; |
Sunny Goyal | ed2d2bc | 2018-04-19 12:34:43 -0700 | [diff] [blame] | 4 | |
Sunny Goyal | 9326461 | 2015-11-23 11:47:50 -0800 | [diff] [blame] | 5 | import android.annotation.TargetApi; |
Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 6 | import android.content.Context; |
| 7 | import android.graphics.Rect; |
Tony Wickham | 12e8a34 | 2019-04-23 11:28:54 -0700 | [diff] [blame] | 8 | import android.os.Build; |
Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 9 | import android.util.AttributeSet; |
Sunny Goyal | 4ffec48 | 2016-02-09 11:28:52 -0800 | [diff] [blame] | 10 | import android.view.ViewDebug; |
Sunny Goyal | 022b182 | 2019-06-12 08:44:09 -0700 | [diff] [blame] | 11 | import android.view.WindowInsets; |
Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 12 | |
Sunny Goyal | 9d89f75 | 2020-06-19 11:09:24 -0700 | [diff] [blame] | 13 | import com.android.launcher3.statemanager.StatefulActivity; |
| 14 | |
Tony Wickham | 12e8a34 | 2019-04-23 11:28:54 -0700 | [diff] [blame] | 15 | import java.util.Collections; |
| 16 | import java.util.List; |
| 17 | |
Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 18 | public class LauncherRootView extends InsettableFrameLayout { |
Sunny Goyal | 0abb36f | 2015-06-23 10:53:59 -0700 | [diff] [blame] | 19 | |
Sunny Goyal | 022b182 | 2019-06-12 08:44:09 -0700 | [diff] [blame] | 20 | private final Rect mTempRect = new Rect(); |
| 21 | |
Sunny Goyal | 9d89f75 | 2020-06-19 11:09:24 -0700 | [diff] [blame] | 22 | private final StatefulActivity mActivity; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 23 | |
Sunny Goyal | 745df7c | 2019-04-03 15:25:00 -0700 | [diff] [blame] | 24 | @ViewDebug.ExportedProperty(category = "launcher") |
Tony Wickham | 12e8a34 | 2019-04-23 11:28:54 -0700 | [diff] [blame] | 25 | private static final List<Rect> SYSTEM_GESTURE_EXCLUSION_RECT = |
| 26 | Collections.singletonList(new Rect()); |
| 27 | |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 28 | private WindowStateListener mWindowStateListener; |
Tony Wickham | 12e8a34 | 2019-04-23 11:28:54 -0700 | [diff] [blame] | 29 | @ViewDebug.ExportedProperty(category = "launcher") |
| 30 | private boolean mDisallowBackGesture; |
Vinit Nayak | 9a84621 | 2019-09-05 11:47:12 -0700 | [diff] [blame] | 31 | @ViewDebug.ExportedProperty(category = "launcher") |
| 32 | private boolean mForceHideBackArrow; |
Sunny Goyal | 9326461 | 2015-11-23 11:47:50 -0800 | [diff] [blame] | 33 | |
Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 34 | public LauncherRootView(Context context, AttributeSet attrs) { |
| 35 | super(context, attrs); |
Sunny Goyal | 9d89f75 | 2020-06-19 11:09:24 -0700 | [diff] [blame] | 36 | mActivity = StatefulActivity.fromContext(context); |
Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Sunny Goyal | 022b182 | 2019-06-12 08:44:09 -0700 | [diff] [blame] | 39 | private void handleSystemWindowInsets(Rect insets) { |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 40 | // Update device profile before notifying th children. |
Sunny Goyal | 9d89f75 | 2020-06-19 11:09:24 -0700 | [diff] [blame] | 41 | mActivity.getDeviceProfile().updateInsets(insets); |
Sunny Goyal | ce8809a | 2018-01-18 14:02:47 -0800 | [diff] [blame] | 42 | boolean resetState = !insets.equals(mInsets); |
Sunny Goyal | 906c6b2 | 2017-08-18 00:35:52 -0700 | [diff] [blame] | 43 | setInsets(insets); |
| 44 | |
Sunny Goyal | ce8809a | 2018-01-18 14:02:47 -0800 | [diff] [blame] | 45 | if (resetState) { |
Sunny Goyal | 9d89f75 | 2020-06-19 11:09:24 -0700 | [diff] [blame] | 46 | mActivity.getStateManager().reapplyState(true /* cancelCurrentAnimation */); |
Sunny Goyal | ce8809a | 2018-01-18 14:02:47 -0800 | [diff] [blame] | 47 | } |
Sunny Goyal | 022b182 | 2019-06-12 08:44:09 -0700 | [diff] [blame] | 48 | } |
Sunny Goyal | 0abb36f | 2015-06-23 10:53:59 -0700 | [diff] [blame] | 49 | |
Sunny Goyal | 022b182 | 2019-06-12 08:44:09 -0700 | [diff] [blame] | 50 | @Override |
| 51 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
| 52 | mTempRect.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), |
| 53 | insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom()); |
| 54 | handleSystemWindowInsets(mTempRect); |
Sunny Goyal | 786940a | 2020-06-02 02:31:31 -0700 | [diff] [blame] | 55 | return insets; |
Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 56 | } |
Sunny Goyal | 0abb36f | 2015-06-23 10:53:59 -0700 | [diff] [blame] | 57 | |
Jon Miranda | de43a71 | 2018-01-18 11:35:10 -0800 | [diff] [blame] | 58 | @Override |
| 59 | public void setInsets(Rect insets) { |
Sunny Goyal | f8d56fc | 2018-01-31 15:18:11 -0800 | [diff] [blame] | 60 | // If the insets haven't changed, this is a no-op. Avoid unnecessary layout caused by |
| 61 | // modifying child layout params. |
| 62 | if (!insets.equals(mInsets)) { |
| 63 | super.setInsets(insets); |
| 64 | } |
Jon Miranda | de43a71 | 2018-01-18 11:35:10 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 67 | public void dispatchInsets() { |
Sunny Goyal | 9d89f75 | 2020-06-19 11:09:24 -0700 | [diff] [blame] | 68 | mActivity.getDeviceProfile().updateInsets(mInsets); |
Sunny Goyal | f8d56fc | 2018-01-31 15:18:11 -0800 | [diff] [blame] | 69 | super.setInsets(mInsets); |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 70 | } |
| 71 | |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 72 | public void setWindowStateListener(WindowStateListener listener) { |
| 73 | mWindowStateListener = listener; |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 78 | super.onWindowFocusChanged(hasWindowFocus); |
| 79 | if (mWindowStateListener != null) { |
| 80 | mWindowStateListener.onWindowFocusChanged(hasWindowFocus); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | protected void onWindowVisibilityChanged(int visibility) { |
| 86 | super.onWindowVisibilityChanged(visibility); |
| 87 | if (mWindowStateListener != null) { |
| 88 | mWindowStateListener.onWindowVisibilityChanged(visibility); |
| 89 | } |
| 90 | } |
| 91 | |
Sunny Goyal | 745df7c | 2019-04-03 15:25:00 -0700 | [diff] [blame] | 92 | @Override |
Tony Wickham | 12e8a34 | 2019-04-23 11:28:54 -0700 | [diff] [blame] | 93 | protected void onLayout(boolean changed, int l, int t, int r, int b) { |
| 94 | super.onLayout(changed, l, t, r, b); |
| 95 | SYSTEM_GESTURE_EXCLUSION_RECT.get(0).set(l, t, r, b); |
| 96 | setDisallowBackGesture(mDisallowBackGesture); |
| 97 | } |
| 98 | |
| 99 | @TargetApi(Build.VERSION_CODES.Q) |
Vinit Nayak | 9a84621 | 2019-09-05 11:47:12 -0700 | [diff] [blame] | 100 | public void setForceHideBackArrow(boolean forceHideBackArrow) { |
| 101 | this.mForceHideBackArrow = forceHideBackArrow; |
| 102 | setDisallowBackGesture(mDisallowBackGesture); |
| 103 | } |
| 104 | |
| 105 | @TargetApi(Build.VERSION_CODES.Q) |
Tony Wickham | 12e8a34 | 2019-04-23 11:28:54 -0700 | [diff] [blame] | 106 | public void setDisallowBackGesture(boolean disallowBackGesture) { |
Sunny Goyal | a314d5a | 2020-05-20 20:34:04 -0700 | [diff] [blame] | 107 | if (!Utilities.ATLEAST_Q || SEPARATE_RECENTS_ACTIVITY.get()) { |
Tony Wickham | 12e8a34 | 2019-04-23 11:28:54 -0700 | [diff] [blame] | 108 | return; |
| 109 | } |
| 110 | mDisallowBackGesture = disallowBackGesture; |
Vinit Nayak | 9a84621 | 2019-09-05 11:47:12 -0700 | [diff] [blame] | 111 | setSystemGestureExclusionRects((mForceHideBackArrow || mDisallowBackGesture) |
Tony Wickham | 12e8a34 | 2019-04-23 11:28:54 -0700 | [diff] [blame] | 112 | ? SYSTEM_GESTURE_EXCLUSION_RECT |
| 113 | : Collections.emptyList()); |
| 114 | } |
| 115 | |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 116 | public interface WindowStateListener { |
| 117 | |
| 118 | void onWindowFocusChanged(boolean hasFocus); |
| 119 | |
| 120 | void onWindowVisibilityChanged(int visibility); |
| 121 | } |
Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 122 | } |