2014-10-23 17:28:30 -07:00
|
|
|
package com.android.launcher3;
|
|
|
|
|
|
2020-05-20 20:34:04 -07:00
|
|
|
import static com.android.launcher3.config.FeatureFlags.SEPARATE_RECENTS_ACTIVITY;
|
2018-04-19 12:34:43 -07:00
|
|
|
|
2015-11-23 11:47:50 -08:00
|
|
|
import android.annotation.TargetApi;
|
2014-10-23 17:28:30 -07:00
|
|
|
import android.content.Context;
|
|
|
|
|
import android.graphics.Rect;
|
2019-04-23 11:28:54 -07:00
|
|
|
import android.os.Build;
|
2014-10-23 17:28:30 -07:00
|
|
|
import android.util.AttributeSet;
|
2016-02-09 11:28:52 -08:00
|
|
|
import android.view.ViewDebug;
|
2019-06-12 08:44:09 -07:00
|
|
|
import android.view.WindowInsets;
|
2014-10-23 17:28:30 -07:00
|
|
|
|
2019-04-23 11:28:54 -07:00
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
2014-10-23 17:28:30 -07:00
|
|
|
public class LauncherRootView extends InsettableFrameLayout {
|
2015-06-23 10:53:59 -07:00
|
|
|
|
2019-06-12 08:44:09 -07:00
|
|
|
private final Rect mTempRect = new Rect();
|
|
|
|
|
|
2018-01-08 14:19:34 -08:00
|
|
|
private final Launcher mLauncher;
|
|
|
|
|
|
2019-04-23 11:28:54 -07:00
|
|
|
@ViewDebug.ExportedProperty(category = "launcher")
|
|
|
|
|
private static final List<Rect> SYSTEM_GESTURE_EXCLUSION_RECT =
|
|
|
|
|
Collections.singletonList(new Rect());
|
|
|
|
|
|
2018-03-14 17:51:49 -07:00
|
|
|
private WindowStateListener mWindowStateListener;
|
2019-04-23 11:28:54 -07:00
|
|
|
@ViewDebug.ExportedProperty(category = "launcher")
|
|
|
|
|
private boolean mDisallowBackGesture;
|
2019-09-05 11:47:12 -07:00
|
|
|
@ViewDebug.ExportedProperty(category = "launcher")
|
|
|
|
|
private boolean mForceHideBackArrow;
|
2015-11-23 11:47:50 -08:00
|
|
|
|
2014-10-23 17:28:30 -07:00
|
|
|
public LauncherRootView(Context context, AttributeSet attrs) {
|
|
|
|
|
super(context, attrs);
|
2018-01-08 14:19:34 -08:00
|
|
|
mLauncher = Launcher.getLauncher(context);
|
2014-10-23 17:28:30 -07:00
|
|
|
}
|
|
|
|
|
|
2019-06-12 08:44:09 -07:00
|
|
|
private void handleSystemWindowInsets(Rect insets) {
|
2018-01-08 14:19:34 -08:00
|
|
|
// Update device profile before notifying th children.
|
2020-04-03 17:10:11 -07:00
|
|
|
mLauncher.getDeviceProfile().updateInsets(insets);
|
2018-01-18 14:02:47 -08:00
|
|
|
boolean resetState = !insets.equals(mInsets);
|
2017-08-18 00:35:52 -07:00
|
|
|
setInsets(insets);
|
2015-11-23 11:47:50 -08:00
|
|
|
|
2018-01-18 14:02:47 -08:00
|
|
|
if (resetState) {
|
2018-04-19 12:34:43 -07:00
|
|
|
mLauncher.getStateManager().reapplyState(true /* cancelCurrentAnimation */);
|
2018-01-18 14:02:47 -08:00
|
|
|
}
|
2019-06-12 08:44:09 -07:00
|
|
|
}
|
2015-06-23 10:53:59 -07:00
|
|
|
|
2019-06-12 08:44:09 -07:00
|
|
|
@Override
|
|
|
|
|
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
|
|
|
|
|
mTempRect.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(),
|
|
|
|
|
insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
|
|
|
|
|
handleSystemWindowInsets(mTempRect);
|
2020-06-02 02:31:31 -07:00
|
|
|
return insets;
|
2014-10-23 17:28:30 -07:00
|
|
|
}
|
2015-06-23 10:53:59 -07:00
|
|
|
|
2018-01-18 11:35:10 -08:00
|
|
|
@Override
|
|
|
|
|
public void setInsets(Rect insets) {
|
2018-01-31 15:18:11 -08:00
|
|
|
// If the insets haven't changed, this is a no-op. Avoid unnecessary layout caused by
|
|
|
|
|
// modifying child layout params.
|
|
|
|
|
if (!insets.equals(mInsets)) {
|
|
|
|
|
super.setInsets(insets);
|
|
|
|
|
}
|
2018-01-18 11:35:10 -08:00
|
|
|
}
|
|
|
|
|
|
2018-01-08 14:19:34 -08:00
|
|
|
public void dispatchInsets() {
|
2020-04-03 17:10:11 -07:00
|
|
|
mLauncher.getDeviceProfile().updateInsets(mInsets);
|
2018-01-31 15:18:11 -08:00
|
|
|
super.setInsets(mInsets);
|
2018-01-08 14:19:34 -08:00
|
|
|
}
|
|
|
|
|
|
2018-03-14 17:51:49 -07:00
|
|
|
public void setWindowStateListener(WindowStateListener listener) {
|
|
|
|
|
mWindowStateListener = listener;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onWindowFocusChanged(boolean hasWindowFocus) {
|
|
|
|
|
super.onWindowFocusChanged(hasWindowFocus);
|
|
|
|
|
if (mWindowStateListener != null) {
|
|
|
|
|
mWindowStateListener.onWindowFocusChanged(hasWindowFocus);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onWindowVisibilityChanged(int visibility) {
|
|
|
|
|
super.onWindowVisibilityChanged(visibility);
|
|
|
|
|
if (mWindowStateListener != null) {
|
|
|
|
|
mWindowStateListener.onWindowVisibilityChanged(visibility);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-23 11:28:54 -07:00
|
|
|
@Override
|
|
|
|
|
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
|
|
|
|
super.onLayout(changed, l, t, r, b);
|
|
|
|
|
SYSTEM_GESTURE_EXCLUSION_RECT.get(0).set(l, t, r, b);
|
|
|
|
|
setDisallowBackGesture(mDisallowBackGesture);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-05 11:47:12 -07:00
|
|
|
@TargetApi(Build.VERSION_CODES.Q)
|
|
|
|
|
public void setForceHideBackArrow(boolean forceHideBackArrow) {
|
|
|
|
|
this.mForceHideBackArrow = forceHideBackArrow;
|
|
|
|
|
setDisallowBackGesture(mDisallowBackGesture);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-23 11:28:54 -07:00
|
|
|
@TargetApi(Build.VERSION_CODES.Q)
|
|
|
|
|
public void setDisallowBackGesture(boolean disallowBackGesture) {
|
2020-05-20 20:34:04 -07:00
|
|
|
if (!Utilities.ATLEAST_Q || SEPARATE_RECENTS_ACTIVITY.get()) {
|
2019-04-23 11:28:54 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mDisallowBackGesture = disallowBackGesture;
|
2019-09-05 11:47:12 -07:00
|
|
|
setSystemGestureExclusionRects((mForceHideBackArrow || mDisallowBackGesture)
|
2019-04-23 11:28:54 -07:00
|
|
|
? SYSTEM_GESTURE_EXCLUSION_RECT
|
|
|
|
|
: Collections.emptyList());
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-14 17:51:49 -07:00
|
|
|
public interface WindowStateListener {
|
|
|
|
|
|
|
|
|
|
void onWindowFocusChanged(boolean hasFocus);
|
|
|
|
|
|
|
|
|
|
void onWindowVisibilityChanged(int visibility);
|
|
|
|
|
}
|
2014-10-23 17:28:30 -07:00
|
|
|
}
|