Merge branch 'aosp-13' into 13-wip

This commit is contained in:
MrSluffy committed 2023-10-21 09:52:01 +08:00
commit 19bf26dd5a
1558 files changed
+103731 -36693

No files matched your search

@@ -15,7 +15,11 @@
*/
package com.android.launcher3.widget;
import static com.android.launcher3.anim.Interpolators.EMPHASIZED;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Rect;
import android.util.AttributeSet;
@@ -23,10 +27,13 @@ import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.WindowInsets;
import android.view.animation.Interpolator;
import android.widget.Toast;
import androidx.annotation.GuardedBy;
import androidx.annotation.Nullable;
import androidx.annotation.Px;
import androidx.core.view.ViewCompat;
import com.android.launcher3.DeviceProfile;
@@ -39,11 +46,13 @@ import com.android.launcher3.Utilities;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.popup.PopupDataProvider;
import com.android.launcher3.testing.TestLogging;
import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.touch.ItemLongClickListener;
import com.android.launcher3.util.SystemUiController;
import com.android.launcher3.util.Themes;
import com.android.launcher3.util.window.WindowManagerProxy;
import com.android.launcher3.views.AbstractSlideInView;
import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.views.ArrowTipView;
import app.lawnchair.theme.color.ColorTokens;
@@ -55,12 +64,7 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher>
implements OnClickListener, OnLongClickListener, DragSource,
PopupDataProvider.PopupDataChangeListener, Insettable {
/** The default number of cells that can fit horizontally in a widget sheet. */
protected static final int DEFAULT_MAX_HORIZONTAL_SPANS = 4;
/**
* The maximum scale, [0, 1], of the device screen width that the widgets picker can consume
* on large screen devices.
*/
protected static final float MAX_WIDTH_SCALE_FOR_LARGER_SCREEN = 0.89f;
public static final int DEFAULT_MAX_HORIZONTAL_SPANS = 4;
protected static final String KEY_WIDGETS_EDUCATION_TIP_SEEN =
"launcher.widgets_education_tip_seen";
@@ -69,12 +73,20 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher>
/* Touch handling related member variables. */
private Toast mWidgetInstructionToast;
private int mContentHorizontalMarginInPx;
@Px protected int mContentHorizontalMargin;
@Px protected int mWidgetCellHorizontalPadding;
protected int mNavBarScrimHeight;
private final Paint mNavBarScrimPaint;
public BaseWidgetSheet(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mContentHorizontalMarginInPx = getResources().getDimensionPixelSize(
mContentHorizontalMargin = getResources().getDimensionPixelSize(
R.dimen.widget_list_horizontal_margin);
mWidgetCellHorizontalPadding = getResources().getDimensionPixelSize(
R.dimen.widget_cell_horizontal_padding);
mNavBarScrimPaint = new Paint();
mNavBarScrimPaint.setColor(Themes.getAttrColor(context, R.attr.allAppsNavBarScrimColor));
}
protected int getScrimColor(Context context) {
@@ -84,6 +96,9 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher>
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
WindowInsets windowInsets = WindowManagerProxy.INSTANCE.get(getContext())
.normalizeWindowInsets(getContext(), getRootWindowInsets(), new Rect());
mNavBarScrimHeight = getNavBarScrimHeight(windowInsets);
mActivityContext.getPopupDataProvider().setChangeListener(this);
}
@@ -129,11 +144,35 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher>
@Override
public void setInsets(Rect insets) {
mInsets.set(insets);
int contentHorizontalMarginInPx = getResources().getDimensionPixelSize(
@Px int contentHorizontalMargin = getResources().getDimensionPixelSize(
R.dimen.widget_list_horizontal_margin);
if (contentHorizontalMarginInPx != mContentHorizontalMarginInPx) {
onContentHorizontalMarginChanged(contentHorizontalMarginInPx);
mContentHorizontalMarginInPx = contentHorizontalMarginInPx;
if (contentHorizontalMargin != mContentHorizontalMargin) {
onContentHorizontalMarginChanged(contentHorizontalMargin);
mContentHorizontalMargin = contentHorizontalMargin;
}
}
private int getNavBarScrimHeight(WindowInsets insets) {
if (Utilities.ATLEAST_Q) {
return insets.getTappableElementInsets().bottom;
} else {
return insets.getStableInsetBottom();
}
}
@Override
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
mNavBarScrimHeight = getNavBarScrimHeight(insets);
return super.onApplyWindowInsets(insets);
}
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
if (mNavBarScrimHeight > 0) {
canvas.drawRect(0, getHeight() - mNavBarScrimHeight, getWidth(), getHeight(),
mNavBarScrimPaint);
}
}
@@ -148,7 +187,10 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher>
protected void doMeasure(int widthMeasureSpec, int heightMeasureSpec) {
DeviceProfile deviceProfile = mActivityContext.getDeviceProfile();
int widthUsed;
if (mInsets.bottom > 0) {
if (deviceProfile.isTablet) {
int margin = deviceProfile.allAppsLeftRightMargin;
widthUsed = Math.max(2 * margin, 2 * (mInsets.left + mInsets.right));
} else if (mInsets.bottom > 0) {
widthUsed = mInsets.left + mInsets.right;
} else {
Rect padding = deviceProfile.workspacePadding;
@@ -156,33 +198,12 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher>
2 * (mInsets.left + mInsets.right));
}
if (deviceProfile.isTablet || deviceProfile.isTwoPanels) {
// In large screen devices, we restrict the width of the widgets picker to show part of
// the home screen. Let's ensure the minimum width used is at least the minimum width
// that isn't taken by the widgets picker.
int minUsedWidth = (int) (deviceProfile.availableWidthPx
* (1 - MAX_WIDTH_SCALE_FOR_LARGER_SCREEN));
widthUsed = Math.max(widthUsed, minUsedWidth);
}
int heightUsed = mInsets.top + deviceProfile.edgeMarginPx;
measureChildWithMargins(mContent, widthMeasureSpec,
widthUsed, heightMeasureSpec, heightUsed);
widthUsed, heightMeasureSpec, deviceProfile.bottomSheetTopPadding);
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),
MeasureSpec.getSize(heightMeasureSpec));
}
/** Returns the number of cells that can fit horizontally in a given {@code content}. */
protected int computeMaxHorizontalSpans(View content, int contentHorizontalPaddingPx) {
DeviceProfile deviceProfile = mActivityContext.getDeviceProfile();
int availableWidth = content.getMeasuredWidth() - contentHorizontalPaddingPx;
Point cellSize = deviceProfile.getCellSize();
if (cellSize.x > 0) {
return availableWidth / cellSize.x;
}
return DEFAULT_MAX_HORIZONTAL_SPANS;
}
private boolean beginDraggingWidget(WidgetCell v) {
if (TestProtocol.sDebugTracing) {
Log.d(TestProtocol.NO_DROP_TARGET, "2");
@@ -221,6 +242,12 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher>
return true;
}
@Override
protected Interpolator getIdleInterpolator() {
return mActivityContext.getDeviceProfile().isTablet
? EMPHASIZED : super.getIdleInterpolator();
}
//
// Drag related handling methods that implement {@link DragSource} interface.
//
@@ -307,6 +334,13 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher>
/** Returns {@code true} if tip has previously been shown on any of {@link BaseWidgetSheet}. */
protected boolean hasSeenEducationTip() {
return mActivityContext.getSharedPrefs().getBoolean(KEY_WIDGETS_EDUCATION_TIP_SEEN, false)
|| Utilities.IS_RUNNING_IN_TEST_HARNESS;
|| Utilities.isRunningInTestHarness();
}
@Override
protected void setTranslationShift(float translationShift) {
super.setTranslationShift(translationShift);
Launcher launcher = ActivityContext.lookupContext(getContext());
launcher.onWidgetsTransition(1 - translationShift);
}
}