mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-01 00:06:47 +00:00
Merge remote-tracking branch 'aosp/android12L-release' into 12.1-dev
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.android.launcher3;
|
||||
|
||||
import static android.appwidget.AppWidgetHostView.getDefaultPaddingForWidget;
|
||||
|
||||
import static com.android.launcher3.CellLayout.SPRING_LOADED_PROGRESS;
|
||||
import static com.android.launcher3.LauncherAnimUtils.LAYOUT_HEIGHT;
|
||||
import static com.android.launcher3.LauncherAnimUtils.LAYOUT_WIDTH;
|
||||
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_WIDGET_RESIZE_COMPLETED;
|
||||
@@ -8,6 +10,8 @@ import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCH
|
||||
import static com.android.launcher3.views.BaseDragLayer.LAYOUT_X;
|
||||
import static com.android.launcher3.views.BaseDragLayer.LAYOUT_Y;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.AnimatorSet;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.PropertyValuesHolder;
|
||||
@@ -28,6 +32,7 @@ import androidx.annotation.Px;
|
||||
|
||||
import com.android.launcher3.accessibility.DragViewStateAnnouncer;
|
||||
import com.android.launcher3.dragndrop.DragLayer;
|
||||
import com.android.launcher3.keyboard.ViewGroupFocusHelper;
|
||||
import com.android.launcher3.logging.InstanceId;
|
||||
import com.android.launcher3.logging.InstanceIdSequence;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
@@ -51,12 +56,14 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
private static final String KEY_RECONFIGURABLE_WIDGET_EDUCATION_TIP_SEEN =
|
||||
"launcher.reconfigurable_widget_education_tip_seen";
|
||||
private static final Rect sTmpRect = new Rect();
|
||||
private static final Rect sTmpRect2 = new Rect();
|
||||
|
||||
private static final int HANDLE_COUNT = 4;
|
||||
private static final int INDEX_LEFT = 0;
|
||||
private static final int INDEX_TOP = 1;
|
||||
private static final int INDEX_RIGHT = 2;
|
||||
private static final int INDEX_BOTTOM = 3;
|
||||
private static final float MIN_OPACITY_FOR_CELL_LAYOUT_DURING_INVALID_RESIZE = 0.5f;
|
||||
|
||||
private final Launcher mLauncher;
|
||||
private final DragViewStateAnnouncer mStateAnnouncer;
|
||||
@@ -105,6 +112,16 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
|
||||
private final InstanceId logInstanceId = new InstanceIdSequence().newInstanceId();
|
||||
|
||||
private final ViewGroupFocusHelper mDragLayerRelativeCoordinateHelper;
|
||||
|
||||
/**
|
||||
* In the two panel UI, it is not possible to resize a widget to cross its host
|
||||
* {@link CellLayout}'s sibling. When this happens, we gradually reduce the opacity of the
|
||||
* sibling {@link CellLayout} from 1f to
|
||||
* {@link #MIN_OPACITY_FOR_CELL_LAYOUT_DURING_INVALID_RESIZE}.
|
||||
*/
|
||||
private final float mDragAcrossTwoPanelOpacityMargin;
|
||||
|
||||
private boolean mLeftBorderActive;
|
||||
private boolean mRightBorderActive;
|
||||
private boolean mTopBorderActive;
|
||||
@@ -151,6 +168,10 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
for (int i = 0; i < HANDLE_COUNT; i++) {
|
||||
mSystemGestureExclusionRects.add(new Rect());
|
||||
}
|
||||
|
||||
mDragAcrossTwoPanelOpacityMargin = mLauncher.getResources().getDimensionPixelSize(
|
||||
R.dimen.resize_frame_invalid_drag_across_two_panel_opacity_margin);
|
||||
mDragLayerRelativeCoordinateHelper = new ViewGroupFocusHelper(mLauncher.getDragLayer());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -203,7 +224,7 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
|
||||
dl.addView(frame);
|
||||
frame.mIsOpen = true;
|
||||
frame.snapToWidget(false);
|
||||
frame.post(() -> frame.snapToWidget(false));
|
||||
}
|
||||
|
||||
private void setupForWidget(LauncherAppWidgetHostView widgetView, CellLayout cellLayout,
|
||||
@@ -229,13 +250,15 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
// Only show resize handles for the directions in which resizing is possible.
|
||||
InvariantDeviceProfile idp = LauncherAppState.getIDP(cellLayout.getContext());
|
||||
mVerticalResizeActive = (info.resizeMode & AppWidgetProviderInfo.RESIZE_VERTICAL) != 0
|
||||
&& mMinVSpan < idp.numRows && mMaxVSpan > 1;
|
||||
&& mMinVSpan < idp.numRows && mMaxVSpan > 1
|
||||
&& mMinVSpan < mMaxVSpan;
|
||||
if (!mVerticalResizeActive) {
|
||||
mDragHandles[INDEX_TOP].setVisibility(GONE);
|
||||
mDragHandles[INDEX_BOTTOM].setVisibility(GONE);
|
||||
}
|
||||
mHorizontalResizeActive = (info.resizeMode & AppWidgetProviderInfo.RESIZE_HORIZONTAL) != 0
|
||||
&& mMinHSpan < idp.numColumns && mMaxHSpan > 1;
|
||||
&& mMinHSpan < idp.numColumns && mMaxHSpan > 1
|
||||
&& mMinHSpan < mMaxHSpan;
|
||||
if (!mHorizontalResizeActive) {
|
||||
mDragHandles[INDEX_LEFT].setVisibility(GONE);
|
||||
mDragHandles[INDEX_RIGHT].setVisibility(GONE);
|
||||
@@ -367,6 +390,37 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
lp.y = sTmpRect.top;
|
||||
}
|
||||
|
||||
// Handle invalid resize across CellLayouts in the two panel UI.
|
||||
if (mCellLayout.getParent() instanceof Workspace) {
|
||||
Workspace workspace = (Workspace) mCellLayout.getParent();
|
||||
CellLayout pairedCellLayout = workspace.getScreenPair(mCellLayout);
|
||||
if (pairedCellLayout != null) {
|
||||
Rect focusedCellLayoutBound = sTmpRect;
|
||||
mDragLayerRelativeCoordinateHelper.viewToRect(mCellLayout, focusedCellLayoutBound);
|
||||
Rect resizeFrameBound = sTmpRect2;
|
||||
findViewById(R.id.widget_resize_frame).getGlobalVisibleRect(resizeFrameBound);
|
||||
float progress = 1f;
|
||||
if (workspace.indexOfChild(pairedCellLayout) < workspace.indexOfChild(mCellLayout)
|
||||
&& mDeltaX < 0
|
||||
&& resizeFrameBound.left < focusedCellLayoutBound.left) {
|
||||
// Resize from right to left.
|
||||
progress = (mDragAcrossTwoPanelOpacityMargin + mDeltaX)
|
||||
/ mDragAcrossTwoPanelOpacityMargin;
|
||||
} else if (workspace.indexOfChild(pairedCellLayout)
|
||||
> workspace.indexOfChild(mCellLayout)
|
||||
&& mDeltaX > 0
|
||||
&& resizeFrameBound.right > focusedCellLayoutBound.right) {
|
||||
// Resize from left to right.
|
||||
progress = (mDragAcrossTwoPanelOpacityMargin - mDeltaX)
|
||||
/ mDragAcrossTwoPanelOpacityMargin;
|
||||
}
|
||||
float alpha = Math.max(MIN_OPACITY_FOR_CELL_LAYOUT_DURING_INVALID_RESIZE, progress);
|
||||
float springLoadedProgress = Math.min(1f, 1f - progress);
|
||||
updateInvalidResizeEffect(mCellLayout, pairedCellLayout, alpha,
|
||||
springLoadedProgress);
|
||||
}
|
||||
}
|
||||
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
@@ -379,8 +433,8 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
*/
|
||||
private void resizeWidgetIfNeeded(boolean onDismiss) {
|
||||
DeviceProfile dp = mLauncher.getDeviceProfile();
|
||||
float xThreshold = mCellLayout.getCellWidth() + dp.cellLayoutBorderSpacingPx;
|
||||
float yThreshold = mCellLayout.getCellHeight() + dp.cellLayoutBorderSpacingPx;
|
||||
float xThreshold = mCellLayout.getCellWidth() + dp.cellLayoutBorderSpacePx.x;
|
||||
float yThreshold = mCellLayout.getCellHeight() + dp.cellLayoutBorderSpacePx.y;
|
||||
|
||||
int hSpanInc = getSpanIncrement((mDeltaX + mDeltaXAddOn) / xThreshold - mRunningHInc);
|
||||
int vSpanInc = getSpanIncrement((mDeltaY + mDeltaYAddOn) / yThreshold - mRunningVInc);
|
||||
@@ -465,8 +519,8 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
|
||||
private void onTouchUp() {
|
||||
DeviceProfile dp = mLauncher.getDeviceProfile();
|
||||
int xThreshold = mCellLayout.getCellWidth() + dp.cellLayoutBorderSpacingPx;
|
||||
int yThreshold = mCellLayout.getCellHeight() + dp.cellLayoutBorderSpacingPx;
|
||||
int xThreshold = mCellLayout.getCellWidth() + dp.cellLayoutBorderSpacePx.x;
|
||||
int yThreshold = mCellLayout.getCellHeight() + dp.cellLayoutBorderSpacePx.y;
|
||||
|
||||
mDeltaXAddOn = mRunningHInc * xThreshold;
|
||||
mDeltaYAddOn = mRunningVInc * yThreshold;
|
||||
@@ -523,13 +577,24 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
}
|
||||
|
||||
final DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
|
||||
final CellLayout pairedCellLayout;
|
||||
if (mCellLayout.getParent() instanceof Workspace) {
|
||||
Workspace workspace = (Workspace) mCellLayout.getParent();
|
||||
pairedCellLayout = workspace.getScreenPair(mCellLayout);
|
||||
} else {
|
||||
pairedCellLayout = null;
|
||||
}
|
||||
if (!animate) {
|
||||
lp.width = newWidth;
|
||||
lp.height = newHeight;
|
||||
lp.x = newX;
|
||||
lp.y = newY;
|
||||
for (int i = 0; i < HANDLE_COUNT; i++) {
|
||||
mDragHandles[i].setAlpha(1.0f);
|
||||
mDragHandles[i].setAlpha(1f);
|
||||
}
|
||||
if (pairedCellLayout != null) {
|
||||
updateInvalidResizeEffect(mCellLayout, pairedCellLayout, /* alpha= */ 1f,
|
||||
/* springLoadedProgress= */ 0f);
|
||||
}
|
||||
requestLayout();
|
||||
} else {
|
||||
@@ -546,6 +611,10 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
set.play(mFirstFrameAnimatorHelper.addTo(
|
||||
ObjectAnimator.ofFloat(mDragHandles[i], ALPHA, 1f)));
|
||||
}
|
||||
if (pairedCellLayout != null) {
|
||||
updateInvalidResizeEffect(mCellLayout, pairedCellLayout, /* alpha= */ 1f,
|
||||
/* springLoadedProgress= */ 0f, /* animatorSet= */ set);
|
||||
}
|
||||
set.setDuration(SNAP_DURATION);
|
||||
set.start();
|
||||
}
|
||||
@@ -632,6 +701,52 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
}
|
||||
}
|
||||
|
||||
private void updateInvalidResizeEffect(CellLayout cellLayout, CellLayout pairedCellLayout,
|
||||
float alpha, float springLoadedProgress) {
|
||||
updateInvalidResizeEffect(cellLayout, pairedCellLayout, alpha,
|
||||
springLoadedProgress, /* animatorSet= */ null);
|
||||
}
|
||||
|
||||
private void updateInvalidResizeEffect(CellLayout cellLayout, CellLayout pairedCellLayout,
|
||||
float alpha, float springLoadedProgress, @Nullable AnimatorSet animatorSet) {
|
||||
int childCount = pairedCellLayout.getChildCount();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
View child = pairedCellLayout.getChildAt(i);
|
||||
if (animatorSet != null) {
|
||||
animatorSet.play(
|
||||
mFirstFrameAnimatorHelper.addTo(
|
||||
ObjectAnimator.ofFloat(child, ALPHA, alpha)));
|
||||
} else {
|
||||
child.setAlpha(alpha);
|
||||
}
|
||||
}
|
||||
if (animatorSet != null) {
|
||||
animatorSet.play(mFirstFrameAnimatorHelper.addTo(
|
||||
ObjectAnimator.ofFloat(cellLayout, SPRING_LOADED_PROGRESS,
|
||||
springLoadedProgress)));
|
||||
animatorSet.play(mFirstFrameAnimatorHelper.addTo(
|
||||
ObjectAnimator.ofFloat(pairedCellLayout, SPRING_LOADED_PROGRESS,
|
||||
springLoadedProgress)));
|
||||
} else {
|
||||
cellLayout.setSpringLoadedProgress(springLoadedProgress);
|
||||
pairedCellLayout.setSpringLoadedProgress(springLoadedProgress);
|
||||
}
|
||||
|
||||
boolean shouldShowCellLayoutBorder = springLoadedProgress > 0f;
|
||||
if (animatorSet != null) {
|
||||
animatorSet.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animator) {
|
||||
cellLayout.setIsDragOverlapping(shouldShowCellLayoutBorder);
|
||||
pairedCellLayout.setIsDragOverlapping(shouldShowCellLayoutBorder);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
cellLayout.setIsDragOverlapping(shouldShowCellLayoutBorder);
|
||||
pairedCellLayout.setIsDragOverlapping(shouldShowCellLayoutBorder);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isOfType(int type) {
|
||||
return (type & TYPE_WIDGET_RESIZE_FRAME) != 0;
|
||||
|
||||
Reference in New Issue
Block a user