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