mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-27 15:26:58 +00:00
Allowing Launcher to draw behind cutouts
> Launcher uses realSize, availableSize and insets to calculate various layout values. Without drawing behind cutouts, these values are not consistent (insets + availableSize != realSize) leading to jumps in layouts. > Removing fake black bars in low-ram devices to avoid inconsistent insets. > Fixing various layouts not taking lert/right insets into account. Bug: 156268804 Change-Id: I8441db8a468b08a65b57b932050b5b4b37313966
This commit is contained in:
34
res/values-v30/styles.xml
Normal file
34
res/values-v30/styles.xml
Normal file
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<!-- Launcher theme -->
|
||||
<style name="BaseLauncherTheme" parent="@android:style/Theme.DeviceDefault.DayNight">
|
||||
<item name="android:colorBackgroundCacheHint">@null</item>
|
||||
<item name="android:colorEdgeEffect">#FF757575</item>
|
||||
<item name="android:windowActionBar">false</item>
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<item name="android:windowShowWallpaper">true</item>
|
||||
<item name="folderTextColor">?attr/workspaceTextColor</item>
|
||||
<item name="android:windowLayoutInDisplayCutoutMode">always</item>
|
||||
<item name="android:enforceStatusBarContrast">false</item>
|
||||
<item name="android:enforceNavigationBarContrast">false</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -538,7 +538,6 @@ public class DeviceProfile {
|
||||
mInsets.right + hotseatBarSidePaddingStartPx, mInsets.bottom);
|
||||
}
|
||||
} else {
|
||||
|
||||
// We want the edges of the hotseat to line up with the edges of the workspace, but the
|
||||
// icons in the hotseat are a different size, and so don't line up perfectly. To account
|
||||
// for this, we pad the left and right of the hotseat with half of the difference of a
|
||||
@@ -547,9 +546,11 @@ public class DeviceProfile {
|
||||
float hotseatCellWidth = (float) widthPx / inv.numHotseatIcons;
|
||||
int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
|
||||
mHotseatPadding.set(
|
||||
hotseatAdjustment + workspacePadding.left + cellLayoutPaddingLeftRightPx,
|
||||
hotseatAdjustment + workspacePadding.left + cellLayoutPaddingLeftRightPx
|
||||
+ mInsets.left,
|
||||
hotseatBarTopPaddingPx,
|
||||
hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx,
|
||||
hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx
|
||||
+ mInsets.right,
|
||||
hotseatBarBottomPaddingPx + mInsets.bottom + cellLayoutBottomPaddingPx);
|
||||
}
|
||||
return mHotseatPadding;
|
||||
|
||||
@@ -91,7 +91,6 @@ public class Hotseat extends CellLayout implements LogContainerProvider, Insetta
|
||||
public void setInsets(Rect insets) {
|
||||
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
|
||||
DeviceProfile grid = mActivity.getDeviceProfile();
|
||||
insets = grid.getInsets();
|
||||
|
||||
if (grid.isVerticalBarLayout()) {
|
||||
lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
|
||||
@@ -1,19 +1,12 @@
|
||||
package com.android.launcher3;
|
||||
|
||||
import static com.android.launcher3.config.FeatureFlags.SEPARATE_RECENTS_ACTIVITY;
|
||||
import static com.android.launcher3.util.SystemUiController.FLAG_DARK_NAV;
|
||||
import static com.android.launcher3.util.SystemUiController.UI_STATE_ROOT_VIEW;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewDebug;
|
||||
import android.view.WindowInsets;
|
||||
|
||||
@@ -26,16 +19,10 @@ public class LauncherRootView extends InsettableFrameLayout {
|
||||
|
||||
private final Launcher mLauncher;
|
||||
|
||||
private final Paint mOpaquePaint;
|
||||
|
||||
@ViewDebug.ExportedProperty(category = "launcher")
|
||||
private final Rect mConsumedInsets = new Rect();
|
||||
|
||||
@ViewDebug.ExportedProperty(category = "launcher")
|
||||
private static final List<Rect> SYSTEM_GESTURE_EXCLUSION_RECT =
|
||||
Collections.singletonList(new Rect());
|
||||
|
||||
private View mAlignedView;
|
||||
private WindowStateListener mWindowStateListener;
|
||||
@ViewDebug.ExportedProperty(category = "launcher")
|
||||
private boolean mDisallowBackGesture;
|
||||
@@ -44,55 +31,15 @@ public class LauncherRootView extends InsettableFrameLayout {
|
||||
|
||||
public LauncherRootView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
mOpaquePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
mOpaquePaint.setColor(Color.BLACK);
|
||||
mOpaquePaint.setStyle(Paint.Style.FILL);
|
||||
|
||||
mLauncher = Launcher.getLauncher(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
if (getChildCount() > 0) {
|
||||
// LauncherRootView contains only one child, which should be aligned
|
||||
// based on the horizontal insets.
|
||||
mAlignedView = getChildAt(0);
|
||||
}
|
||||
super.onFinishInflate();
|
||||
}
|
||||
|
||||
private void handleSystemWindowInsets(Rect insets) {
|
||||
mConsumedInsets.setEmpty();
|
||||
boolean drawInsetBar = false;
|
||||
if ((insets.right > 0 || insets.left > 0)
|
||||
&& getContext().getSystemService(ActivityManager.class).isLowRamDevice()) {
|
||||
mConsumedInsets.left = insets.left;
|
||||
mConsumedInsets.right = insets.right;
|
||||
insets.set(0, insets.top, 0, insets.bottom);
|
||||
drawInsetBar = true;
|
||||
}
|
||||
|
||||
mLauncher.getSystemUiController().updateUiState(
|
||||
UI_STATE_ROOT_VIEW, drawInsetBar ? FLAG_DARK_NAV : 0);
|
||||
|
||||
// Update device profile before notifying th children.
|
||||
mLauncher.getDeviceProfile().updateInsets(insets);
|
||||
boolean resetState = !insets.equals(mInsets);
|
||||
setInsets(insets);
|
||||
|
||||
if (mAlignedView != null) {
|
||||
// Apply margins on aligned view to handle consumed insets.
|
||||
MarginLayoutParams lp = (MarginLayoutParams) mAlignedView.getLayoutParams();
|
||||
if (lp.leftMargin != mConsumedInsets.left || lp.rightMargin != mConsumedInsets.right ||
|
||||
lp.bottomMargin != mConsumedInsets.bottom) {
|
||||
lp.leftMargin = mConsumedInsets.left;
|
||||
lp.rightMargin = mConsumedInsets.right;
|
||||
lp.topMargin = mConsumedInsets.top;
|
||||
lp.bottomMargin = mConsumedInsets.bottom;
|
||||
mAlignedView.setLayoutParams(lp);
|
||||
}
|
||||
}
|
||||
if (resetState) {
|
||||
mLauncher.getStateManager().reapplyState(true /* cancelCurrentAnimation */);
|
||||
}
|
||||
@@ -103,12 +50,7 @@ public class LauncherRootView extends InsettableFrameLayout {
|
||||
mTempRect.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(),
|
||||
insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
|
||||
handleSystemWindowInsets(mTempRect);
|
||||
if (Utilities.ATLEAST_Q) {
|
||||
return insets.inset(mConsumedInsets.left, mConsumedInsets.top,
|
||||
mConsumedInsets.right, mConsumedInsets.bottom);
|
||||
} else {
|
||||
return insets.replaceSystemWindowInsets(mTempRect);
|
||||
}
|
||||
return insets;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -125,24 +67,6 @@ public class LauncherRootView extends InsettableFrameLayout {
|
||||
super.setInsets(mInsets);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispatchDraw(Canvas canvas) {
|
||||
super.dispatchDraw(canvas);
|
||||
|
||||
// If the right inset is opaque, draw a black rectangle to ensure that is stays opaque.
|
||||
if (mConsumedInsets.right > 0) {
|
||||
int width = getWidth();
|
||||
canvas.drawRect(width - mConsumedInsets.right, 0, width, getHeight(), mOpaquePaint);
|
||||
}
|
||||
if (mConsumedInsets.left > 0) {
|
||||
canvas.drawRect(0, 0, mConsumedInsets.left, getHeight(), mOpaquePaint);
|
||||
}
|
||||
if (mConsumedInsets.bottom > 0) {
|
||||
int height = getHeight();
|
||||
canvas.drawRect(0, height - mConsumedInsets.bottom, getWidth(), height, mOpaquePaint);
|
||||
}
|
||||
}
|
||||
|
||||
public void setWindowStateListener(WindowStateListener listener) {
|
||||
mWindowStateListener = listener;
|
||||
}
|
||||
|
||||
@@ -349,15 +349,15 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
|
||||
}
|
||||
|
||||
ViewGroup.MarginLayoutParams mlp = (MarginLayoutParams) getLayoutParams();
|
||||
mlp.leftMargin = insets.left;
|
||||
mlp.rightMargin = insets.right;
|
||||
setLayoutParams(mlp);
|
||||
|
||||
if (grid.isVerticalBarLayout()) {
|
||||
mlp.leftMargin = insets.left;
|
||||
mlp.rightMargin = insets.right;
|
||||
setPadding(grid.workspacePadding.left, 0, grid.workspacePadding.right, 0);
|
||||
} else {
|
||||
mlp.leftMargin = mlp.rightMargin = 0;
|
||||
setPadding(0, 0, 0, 0);
|
||||
}
|
||||
setLayoutParams(mlp);
|
||||
|
||||
InsettableFrameLayout.dispatchInsets(this, insets);
|
||||
}
|
||||
|
||||
@@ -293,8 +293,8 @@ public abstract class ArrowPopup<T extends BaseDraggingActivity> extends Abstrac
|
||||
// gravity to CENTER_HORIZONTAL, but continue below to update y.
|
||||
} else {
|
||||
boolean canBeLeftAligned = x + width + insets.left
|
||||
< dragLayer.getRight() - insets.right;
|
||||
boolean canBeRightAligned = x > dragLayer.getLeft() + insets.left;
|
||||
< dragLayer.getWidth() - insets.right;
|
||||
boolean canBeRightAligned = x > insets.left;
|
||||
boolean alignmentStillValid = mIsLeftAligned && canBeLeftAligned
|
||||
|| !mIsLeftAligned && canBeRightAligned;
|
||||
if (!alignmentStillValid) {
|
||||
@@ -367,8 +367,10 @@ public abstract class ArrowPopup<T extends BaseDraggingActivity> extends Abstrac
|
||||
super.onLayout(changed, l, t, r, b);
|
||||
|
||||
// enforce contained is within screen
|
||||
ViewGroup dragLayer = getPopupContainer();
|
||||
if (getTranslationX() + l < 0 || getTranslationX() + r > dragLayer.getWidth()) {
|
||||
BaseDragLayer dragLayer = getPopupContainer();
|
||||
Rect insets = dragLayer.getInsets();
|
||||
if (getTranslationX() + l < insets.left
|
||||
|| getTranslationX() + r > dragLayer.getWidth() - insets.right) {
|
||||
// If we are still off screen, center horizontally too.
|
||||
mGravity |= Gravity.CENTER_HORIZONTAL;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.launcher3.util;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
|
||||
@@ -33,8 +32,7 @@ public class SystemUiController {
|
||||
public static final int UI_STATE_BASE_WINDOW = 0;
|
||||
public static final int UI_STATE_ALL_APPS = 1;
|
||||
public static final int UI_STATE_WIDGET_BOTTOM_SHEET = 2;
|
||||
public static final int UI_STATE_ROOT_VIEW = 3;
|
||||
public static final int UI_STATE_OVERVIEW = 4;
|
||||
public static final int UI_STATE_OVERVIEW = 3;
|
||||
|
||||
public static final int FLAG_LIGHT_NAV = 1 << 0;
|
||||
public static final int FLAG_DARK_NAV = 1 << 1;
|
||||
@@ -42,7 +40,7 @@ public class SystemUiController {
|
||||
public static final int FLAG_DARK_STATUS = 1 << 3;
|
||||
|
||||
private final Window mWindow;
|
||||
private final int[] mStates = new int[5];
|
||||
private final int[] mStates = new int[4];
|
||||
|
||||
public SystemUiController(Window window) {
|
||||
mWindow = window;
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.animation.PropertyValuesHolder;
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
@@ -39,10 +38,8 @@ import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
import com.android.launcher3.LauncherAppWidgetHost.ProviderChangedListener;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.anim.PendingAnimation;
|
||||
import com.android.launcher3.compat.AccessibilityManagerCompat;
|
||||
import com.android.launcher3.testing.TestProtocol;
|
||||
import com.android.launcher3.views.RecyclerViewFastScroller;
|
||||
import com.android.launcher3.views.TopRoundedCornerView;
|
||||
|
||||
@@ -135,7 +132,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int widthUsed;
|
||||
if (mInsets.bottom > 0) {
|
||||
widthUsed = 0;
|
||||
widthUsed = mInsets.left + mInsets.right;
|
||||
} else {
|
||||
Rect padding = mLauncher.getDeviceProfile().workspacePadding;
|
||||
widthUsed = Math.max(padding.left + padding.right,
|
||||
@@ -156,7 +153,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet
|
||||
|
||||
// Content is laid out as center bottom aligned
|
||||
int contentWidth = mContent.getMeasuredWidth();
|
||||
int contentLeft = (width - contentWidth) / 2;
|
||||
int contentLeft = (width - contentWidth - mInsets.left - mInsets.right) / 2 + mInsets.left;
|
||||
mContent.layout(contentLeft, height - mContent.getMeasuredHeight(),
|
||||
contentLeft + contentWidth, height);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user