blob: 6951ff280429394f83bab599b1eb13fc569260d3 [file] [log] [blame]
Adam Cohena6d04922014-10-23 17:28:30 -07001package com.android.launcher3;
2
Sunny Goyala314d5a2020-05-20 20:34:04 -07003import static com.android.launcher3.config.FeatureFlags.SEPARATE_RECENTS_ACTIVITY;
Sunny Goyaled2d2bc2018-04-19 12:34:43 -07004
Sunny Goyal93264612015-11-23 11:47:50 -08005import android.annotation.TargetApi;
Adam Cohena6d04922014-10-23 17:28:30 -07006import android.content.Context;
7import android.graphics.Rect;
Tony Wickham12e8a342019-04-23 11:28:54 -07008import android.os.Build;
Adam Cohena6d04922014-10-23 17:28:30 -07009import android.util.AttributeSet;
Sunny Goyal4ffec482016-02-09 11:28:52 -080010import android.view.ViewDebug;
Sunny Goyal022b1822019-06-12 08:44:09 -070011import android.view.WindowInsets;
Adam Cohena6d04922014-10-23 17:28:30 -070012
Tony Wickham12e8a342019-04-23 11:28:54 -070013import java.util.Collections;
14import java.util.List;
15
Adam Cohena6d04922014-10-23 17:28:30 -070016public class LauncherRootView extends InsettableFrameLayout {
Sunny Goyal0abb36f2015-06-23 10:53:59 -070017
Sunny Goyal022b1822019-06-12 08:44:09 -070018 private final Rect mTempRect = new Rect();
19
Sunny Goyal07b69292018-01-08 14:19:34 -080020 private final Launcher mLauncher;
21
Sunny Goyal745df7c2019-04-03 15:25:00 -070022 @ViewDebug.ExportedProperty(category = "launcher")
Tony Wickham12e8a342019-04-23 11:28:54 -070023 private static final List<Rect> SYSTEM_GESTURE_EXCLUSION_RECT =
24 Collections.singletonList(new Rect());
25
Sunny Goyal7185dd62018-03-14 17:51:49 -070026 private WindowStateListener mWindowStateListener;
Tony Wickham12e8a342019-04-23 11:28:54 -070027 @ViewDebug.ExportedProperty(category = "launcher")
28 private boolean mDisallowBackGesture;
Vinit Nayak9a846212019-09-05 11:47:12 -070029 @ViewDebug.ExportedProperty(category = "launcher")
30 private boolean mForceHideBackArrow;
Sunny Goyal93264612015-11-23 11:47:50 -080031
Adam Cohena6d04922014-10-23 17:28:30 -070032 public LauncherRootView(Context context, AttributeSet attrs) {
33 super(context, attrs);
Sunny Goyal07b69292018-01-08 14:19:34 -080034 mLauncher = Launcher.getLauncher(context);
Adam Cohena6d04922014-10-23 17:28:30 -070035 }
36
Sunny Goyal022b1822019-06-12 08:44:09 -070037 private void handleSystemWindowInsets(Rect insets) {
Sunny Goyal07b69292018-01-08 14:19:34 -080038 // Update device profile before notifying th children.
Sunny Goyalc4d32012020-04-03 17:10:11 -070039 mLauncher.getDeviceProfile().updateInsets(insets);
Sunny Goyalce8809a2018-01-18 14:02:47 -080040 boolean resetState = !insets.equals(mInsets);
Sunny Goyal906c6b22017-08-18 00:35:52 -070041 setInsets(insets);
42
Sunny Goyalce8809a2018-01-18 14:02:47 -080043 if (resetState) {
Sunny Goyaled2d2bc2018-04-19 12:34:43 -070044 mLauncher.getStateManager().reapplyState(true /* cancelCurrentAnimation */);
Sunny Goyalce8809a2018-01-18 14:02:47 -080045 }
Sunny Goyal022b1822019-06-12 08:44:09 -070046 }
Sunny Goyal0abb36f2015-06-23 10:53:59 -070047
Sunny Goyal022b1822019-06-12 08:44:09 -070048 @Override
49 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
50 mTempRect.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(),
51 insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
52 handleSystemWindowInsets(mTempRect);
Sunny Goyal786940a2020-06-02 02:31:31 -070053 return insets;
Adam Cohena6d04922014-10-23 17:28:30 -070054 }
Sunny Goyal0abb36f2015-06-23 10:53:59 -070055
Jon Mirandade43a712018-01-18 11:35:10 -080056 @Override
57 public void setInsets(Rect insets) {
Sunny Goyalf8d56fc2018-01-31 15:18:11 -080058 // 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 Mirandade43a712018-01-18 11:35:10 -080063 }
64
Sunny Goyal07b69292018-01-08 14:19:34 -080065 public void dispatchInsets() {
Sunny Goyalc4d32012020-04-03 17:10:11 -070066 mLauncher.getDeviceProfile().updateInsets(mInsets);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -080067 super.setInsets(mInsets);
Sunny Goyal07b69292018-01-08 14:19:34 -080068 }
69
Sunny Goyal7185dd62018-03-14 17:51:49 -070070 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 Goyal745df7c2019-04-03 15:25:00 -070090 @Override
Tony Wickham12e8a342019-04-23 11:28:54 -070091 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 Nayak9a846212019-09-05 11:47:12 -070098 public void setForceHideBackArrow(boolean forceHideBackArrow) {
99 this.mForceHideBackArrow = forceHideBackArrow;
100 setDisallowBackGesture(mDisallowBackGesture);
101 }
102
103 @TargetApi(Build.VERSION_CODES.Q)
Tony Wickham12e8a342019-04-23 11:28:54 -0700104 public void setDisallowBackGesture(boolean disallowBackGesture) {
Sunny Goyala314d5a2020-05-20 20:34:04 -0700105 if (!Utilities.ATLEAST_Q || SEPARATE_RECENTS_ACTIVITY.get()) {
Tony Wickham12e8a342019-04-23 11:28:54 -0700106 return;
107 }
108 mDisallowBackGesture = disallowBackGesture;
Vinit Nayak9a846212019-09-05 11:47:12 -0700109 setSystemGestureExclusionRects((mForceHideBackArrow || mDisallowBackGesture)
Tony Wickham12e8a342019-04-23 11:28:54 -0700110 ? SYSTEM_GESTURE_EXCLUSION_RECT
111 : Collections.emptyList());
112 }
113
Sunny Goyal7185dd62018-03-14 17:51:49 -0700114 public interface WindowStateListener {
115
116 void onWindowFocusChanged(boolean hasFocus);
117
118 void onWindowVisibilityChanged(int visibility);
119 }
Adam Cohena6d04922014-10-23 17:28:30 -0700120}