Merge "Update drag and drop visualizations" into sc-dev am: 6adae06ed2
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/13663247 Change-Id: I01a466c52051edc7b3b1e36615dacf3f62d02137
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:alpha="0.4"
|
||||
android:color="?android:attr/colorAccent"/>
|
||||
</selector>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:alpha="0.3"
|
||||
android:color="?android:attr/colorAccent"/>
|
||||
</selector>
|
||||
@@ -23,13 +23,16 @@
|
||||
<shape android:shape="rectangle" >
|
||||
<stroke
|
||||
android:width="@dimen/spring_loaded_panel_border"
|
||||
android:color="@color/spring_loaded_highlighted_panel_border_color" />
|
||||
<solid android:color="@color/spring_loaded_panel_color" />
|
||||
android:color="?android:attr/colorAccent" />
|
||||
<solid android:color="@color/cell_layout_bg_color_active"/>
|
||||
<corners android:radius="@dimen/bg_round_rect_radius"></corners>
|
||||
|
||||
</shape>
|
||||
</item>
|
||||
<item>
|
||||
<shape android:shape="rectangle" >
|
||||
<solid android:color="@color/spring_loaded_panel_color" />
|
||||
<solid android:color="@color/cell_layout_bg_color_inactive"/>
|
||||
<corners android:radius="@dimen/bg_round_rect_radius"></corners>
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
<attr name="folderTextColor" format="color" />
|
||||
<attr name="folderHintColor" format="color" />
|
||||
<attr name="workProfileOverlayTextColor" format="color" />
|
||||
<attr name="gridColor" format="color" />
|
||||
|
||||
<!-- BubbleTextView specific attributes. -->
|
||||
<declare-styleable name="BubbleTextView">
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
<integer name="config_dragOutlineFadeTime">900</integer>
|
||||
|
||||
<!-- The alpha value at which to show the most recent drop visualization outline. -->
|
||||
<integer name="config_dragOutlineMaxAlpha">128</integer>
|
||||
<integer name="config_dragOutlineMaxAlpha">255</integer>
|
||||
|
||||
<!-- Parameters controlling the animation for when an item is dropped on the home screen,
|
||||
and it animates from its old position to the new one. -->
|
||||
|
||||
@@ -169,7 +169,7 @@
|
||||
|
||||
<dimen name="drag_flingToDeleteMinVelocity">-1500dp</dimen>
|
||||
|
||||
<dimen name="spring_loaded_panel_border">1dp</dimen>
|
||||
<dimen name="spring_loaded_panel_border">2dp</dimen>
|
||||
<dimen name="keyboard_drag_stroke_width">4dp</dimen>
|
||||
|
||||
<!-- Folders -->
|
||||
@@ -291,4 +291,8 @@
|
||||
<dimen name="task_thumbnail_icon_size_grid">0dp</dimen>
|
||||
<dimen name="overview_task_margin">0dp</dimen>
|
||||
|
||||
<!-- Workspace grid visualization parameters -->
|
||||
<dimen name="grid_visualization_rounding_radius">28dp</dimen>
|
||||
<dimen name="grid_visualization_cell_spacing">6dp</dimen>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
<item name="workProfileOverlayTextColor">#FF212121</item>
|
||||
<item name="eduHalfSheetBGColor">?android:attr/colorAccent</item>
|
||||
<item name="disabledIconAlpha">.54</item>
|
||||
<item name="gridColor">?android:attr/colorAccent</item>
|
||||
|
||||
<item name="android:windowTranslucentStatus">false</item>
|
||||
<item name="android:windowTranslucentNavigation">false</item>
|
||||
|
||||
@@ -30,18 +30,19 @@ import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Parcelable;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.FloatProperty;
|
||||
import android.util.Log;
|
||||
import android.util.Property;
|
||||
import android.util.SparseArray;
|
||||
@@ -53,6 +54,7 @@ import android.view.accessibility.AccessibilityEvent;
|
||||
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.graphics.ColorUtils;
|
||||
import androidx.core.view.ViewCompat;
|
||||
|
||||
import com.android.launcher3.LauncherSettings.Favorites;
|
||||
@@ -60,9 +62,7 @@ import com.android.launcher3.accessibility.DragAndDropAccessibilityDelegate;
|
||||
import com.android.launcher3.anim.Interpolators;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.dragndrop.AppWidgetHostViewDrawable;
|
||||
import com.android.launcher3.dragndrop.DraggableView;
|
||||
import com.android.launcher3.folder.PreviewBackground;
|
||||
import com.android.launcher3.graphics.DragPreviewProvider;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.util.CellAndSpan;
|
||||
import com.android.launcher3.util.GridOccupancy;
|
||||
@@ -106,11 +106,6 @@ public class CellLayout extends ViewGroup {
|
||||
@Thunk final int[] mTempLocation = new int[2];
|
||||
final PointF mTmpPointF = new PointF();
|
||||
|
||||
// Used to visualize / debug the Grid of the CellLayout
|
||||
private static final boolean VISUALIZE_GRID = false;
|
||||
private Rect mVisualizeGridRect = new Rect();
|
||||
private Paint mVisualizeGridPaint = new Paint();
|
||||
|
||||
private GridOccupancy mOccupied;
|
||||
private GridOccupancy mTmpOccupied;
|
||||
|
||||
@@ -132,7 +127,7 @@ public class CellLayout extends ViewGroup {
|
||||
|
||||
// These arrays are used to implement the drag visualization on x-large screens.
|
||||
// They are used as circular arrays, indexed by mDragOutlineCurrent.
|
||||
@Thunk final Rect[] mDragOutlines = new Rect[4];
|
||||
@Thunk final CellLayout.LayoutParams[] mDragOutlines = new CellLayout.LayoutParams[4];
|
||||
@Thunk final float[] mDragOutlineAlphas = new float[mDragOutlines.length];
|
||||
private final InterruptibleInOutAnimator[] mDragOutlineAnims =
|
||||
new InterruptibleInOutAnimator[mDragOutlines.length];
|
||||
@@ -146,8 +141,21 @@ public class CellLayout extends ViewGroup {
|
||||
|
||||
private boolean mItemPlacementDirty = false;
|
||||
|
||||
// Used to visualize the grid and drop locations
|
||||
private boolean mVisualizeCells = false;
|
||||
private boolean mVisualizeDropLocation = true;
|
||||
private RectF mVisualizeGridRect = new RectF();
|
||||
private Paint mVisualizeGridPaint = new Paint();
|
||||
private int mGridVisualizationPadding;
|
||||
private int mGridVisualizationRoundingRadius;
|
||||
private float mGridAlpha = 0f;
|
||||
private int mGridColor = 0;
|
||||
private float mSpringLoadedProgress = 0f;
|
||||
private float mScrollProgress = 0f;
|
||||
|
||||
// When a drag operation is in progress, holds the nearest cell to the touch point
|
||||
private final int[] mDragCell = new int[2];
|
||||
private final int[] mDragCellSpan = new int[2];
|
||||
|
||||
private boolean mDragging = false;
|
||||
|
||||
@@ -191,6 +199,20 @@ public class CellLayout extends ViewGroup {
|
||||
// Related to accessible drag and drop
|
||||
DragAndDropAccessibilityDelegate mTouchHelper;
|
||||
|
||||
|
||||
public static final FloatProperty<CellLayout> SPRING_LOADED_PROGRESS =
|
||||
new FloatProperty<CellLayout>("spring_loaded_progress") {
|
||||
@Override
|
||||
public Float get(CellLayout cl) {
|
||||
return cl.getSpringLoadedProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(CellLayout cl, float progress) {
|
||||
cl.setSpringLoadedProgress(progress);
|
||||
}
|
||||
};
|
||||
|
||||
public CellLayout(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
@@ -231,19 +253,26 @@ public class CellLayout extends ViewGroup {
|
||||
mFolderLeaveBehind.mDelegateCellY = -1;
|
||||
|
||||
setAlwaysDrawnWithCacheEnabled(false);
|
||||
final Resources res = getResources();
|
||||
|
||||
mBackground = res.getDrawable(R.drawable.bg_celllayout);
|
||||
Resources res = getResources();
|
||||
|
||||
mBackground = getContext().getDrawable(R.drawable.bg_celllayout);
|
||||
mBackground.setCallback(this);
|
||||
mBackground.setAlpha(0);
|
||||
|
||||
mGridColor = Themes.getAttrColor(getContext(), R.attr.gridColor);
|
||||
mGridVisualizationPadding =
|
||||
res.getDimensionPixelSize(R.dimen.grid_visualization_cell_spacing);
|
||||
mGridVisualizationRoundingRadius =
|
||||
res.getDimensionPixelSize(R.dimen.grid_visualization_rounding_radius);
|
||||
mReorderPreviewAnimationMagnitude = (REORDER_PREVIEW_MAGNITUDE * deviceProfile.iconSizePx);
|
||||
|
||||
// Initialize the data structures used for the drag visualization.
|
||||
mEaseOutInterpolator = Interpolators.DEACCEL_2_5; // Quint ease out
|
||||
mDragCell[0] = mDragCell[1] = -1;
|
||||
mDragCellSpan[0] = mDragCellSpan[1] = -1;
|
||||
for (int i = 0; i < mDragOutlines.length; i++) {
|
||||
mDragOutlines[i] = new Rect(-1, -1, -1, -1);
|
||||
mDragOutlines[i] = new CellLayout.LayoutParams(0, 0, 0, 0);
|
||||
}
|
||||
mDragOutlinePaint.setColor(Themes.getAttrColor(context, R.attr.workspaceTextColor));
|
||||
|
||||
@@ -264,34 +293,14 @@ public class CellLayout extends ViewGroup {
|
||||
final int thisIndex = i;
|
||||
anim.getAnimator().addUpdateListener(new AnimatorUpdateListener() {
|
||||
public void onAnimationUpdate(ValueAnimator animation) {
|
||||
final Bitmap outline = (Bitmap)anim.getTag();
|
||||
|
||||
// If an animation is started and then stopped very quickly, we can still
|
||||
// get spurious updates we've cleared the tag. Guard against this.
|
||||
if (outline == null) {
|
||||
if (LOGD) {
|
||||
Object val = animation.getAnimatedValue();
|
||||
Log.d(TAG, "anim " + thisIndex + " update: " + val +
|
||||
", isStopped " + anim.isStopped());
|
||||
}
|
||||
// Try to prevent it from continuing to run
|
||||
animation.cancel();
|
||||
} else {
|
||||
mDragOutlineAlphas[thisIndex] = (Float) animation.getAnimatedValue();
|
||||
CellLayout.this.invalidate(mDragOutlines[thisIndex]);
|
||||
}
|
||||
mDragOutlineAlphas[thisIndex] = (Float) animation.getAnimatedValue();
|
||||
CellLayout.this.invalidate();
|
||||
}
|
||||
});
|
||||
// The animation holds a reference to the drag outline bitmap as long is it's
|
||||
// running. This way the bitmap can be GCed when the animations are complete.
|
||||
anim.getAnimator().addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
if ((Float) ((ValueAnimator) animation).getAnimatedValue() == 0f) {
|
||||
anim.setTag(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
mDragOutlineAnims[i] = anim;
|
||||
}
|
||||
|
||||
@@ -430,16 +439,6 @@ public class CellLayout extends ViewGroup {
|
||||
mBackground.draw(canvas);
|
||||
}
|
||||
|
||||
final Paint paint = mDragOutlinePaint;
|
||||
for (int i = 0; i < mDragOutlines.length; i++) {
|
||||
final float alpha = mDragOutlineAlphas[i];
|
||||
if (alpha > 0) {
|
||||
final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag();
|
||||
paint.setAlpha((int)(alpha + .5f));
|
||||
canvas.drawBitmap(b, null, mDragOutlines[i], paint);
|
||||
}
|
||||
}
|
||||
|
||||
if (DEBUG_VISUALIZE_OCCUPIED) {
|
||||
int[] pt = new int[2];
|
||||
ColorDrawable cd = new ColorDrawable(Color.RED);
|
||||
@@ -475,34 +474,109 @@ public class CellLayout extends ViewGroup {
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
if (VISUALIZE_GRID) {
|
||||
if (mVisualizeCells || mVisualizeDropLocation) {
|
||||
visualizeGrid(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates the progress of the Workspace entering the SpringLoaded state; allows the
|
||||
* CellLayout to update various visuals for this state.
|
||||
*
|
||||
* @param progress
|
||||
*/
|
||||
public void setSpringLoadedProgress(float progress) {
|
||||
if (Float.compare(progress, mSpringLoadedProgress) != 0) {
|
||||
mSpringLoadedProgress = progress;
|
||||
updateBgAlpha();
|
||||
setGridAlpha(progress);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See setSpringLoadedProgress
|
||||
* @return progress
|
||||
*/
|
||||
public float getSpringLoadedProgress() {
|
||||
return mSpringLoadedProgress;
|
||||
}
|
||||
|
||||
private void updateBgAlpha() {
|
||||
mBackground.setAlpha((int) (mSpringLoadedProgress * mScrollProgress * 255));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the progress of this page's scroll
|
||||
*
|
||||
* @param progress 0 if the screen is centered, +/-1 if it is to the right / left respectively
|
||||
*/
|
||||
public void setScrollProgress(float progress) {
|
||||
if (Float.compare(Math.abs(progress), mScrollProgress) != 0) {
|
||||
mScrollProgress = Math.abs(progress);
|
||||
updateBgAlpha();
|
||||
}
|
||||
}
|
||||
|
||||
private void setGridAlpha(float gridAlpha) {
|
||||
if (Float.compare(gridAlpha, mGridAlpha) != 0) {
|
||||
mGridAlpha = gridAlpha;
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
protected void visualizeGrid(Canvas canvas) {
|
||||
mVisualizeGridRect.set(0, 0, mCellWidth, mCellHeight);
|
||||
mVisualizeGridPaint.setStrokeWidth(4);
|
||||
mVisualizeGridRect.set(mGridVisualizationPadding, mGridVisualizationPadding,
|
||||
mCellWidth - mGridVisualizationPadding,
|
||||
mCellHeight - mGridVisualizationPadding);
|
||||
|
||||
for (int i = 0; i < mCountX; i++) {
|
||||
for (int j = 0; j < mCountY; j++) {
|
||||
canvas.save();
|
||||
mVisualizeGridPaint.setStrokeWidth(8);
|
||||
int paintAlpha = (int) (120 * mGridAlpha);
|
||||
mVisualizeGridPaint.setColor(ColorUtils.setAlphaComponent(mGridColor, paintAlpha));
|
||||
|
||||
int transX = i * mCellWidth + (i * mBorderSpacing);
|
||||
int transY = j * mCellHeight + (j * mBorderSpacing);
|
||||
if (mVisualizeCells) {
|
||||
for (int i = 0; i < mCountX; i++) {
|
||||
for (int j = 0; j < mCountY; j++) {
|
||||
int transX = i * mCellWidth + (i * mBorderSpacing) + getPaddingLeft()
|
||||
+ mGridVisualizationPadding;
|
||||
int transY = j * mCellHeight + (j * mBorderSpacing) + getPaddingTop()
|
||||
+ mGridVisualizationPadding;
|
||||
|
||||
canvas.translate(getPaddingLeft() + transX, getPaddingTop() + transY);
|
||||
mVisualizeGridRect.offsetTo(transX, transY);
|
||||
mVisualizeGridPaint.setStyle(Paint.Style.FILL);
|
||||
canvas.drawRoundRect(mVisualizeGridRect, mGridVisualizationRoundingRadius,
|
||||
mGridVisualizationRoundingRadius, mVisualizeGridPaint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mVisualizeGridPaint.setStyle(Paint.Style.FILL);
|
||||
mVisualizeGridPaint.setColor(Color.argb(80, 255, 100, 100));
|
||||
if (mVisualizeDropLocation) {
|
||||
for (int i = 0; i < mDragOutlines.length; i++) {
|
||||
final float alpha = mDragOutlineAlphas[i];
|
||||
if (alpha <= 0) continue;
|
||||
|
||||
canvas.drawRect(mVisualizeGridRect, mVisualizeGridPaint);
|
||||
mVisualizeGridPaint.setAlpha(255);
|
||||
int x = mDragOutlines[i].cellX;
|
||||
int y = mDragOutlines[i].cellY;
|
||||
int spanX = mDragOutlines[i].cellHSpan;
|
||||
int spanY = mDragOutlines[i].cellVSpan;
|
||||
|
||||
mVisualizeGridRect.set(mGridVisualizationPadding, mGridVisualizationPadding,
|
||||
mCellWidth * spanX - mGridVisualizationPadding,
|
||||
mCellHeight * spanY - mGridVisualizationPadding);
|
||||
|
||||
int transX = x * mCellWidth + (x * mBorderSpacing)
|
||||
+ getPaddingLeft() + mGridVisualizationPadding;
|
||||
int transY = y * mCellHeight + (y * mBorderSpacing)
|
||||
+ getPaddingTop() + mGridVisualizationPadding;
|
||||
|
||||
mVisualizeGridRect.offsetTo(transX, transY);
|
||||
|
||||
mVisualizeGridPaint.setStyle(Paint.Style.STROKE);
|
||||
mVisualizeGridPaint.setColor(Color.argb(255, 255, 100, 100));
|
||||
mVisualizeGridPaint.setColor(Color.argb((int) (alpha),
|
||||
Color.red(mGridColor), Color.green(mGridColor), Color.blue(mGridColor)));
|
||||
|
||||
canvas.drawRect(mVisualizeGridRect, mVisualizeGridPaint);
|
||||
canvas.restore();
|
||||
canvas.drawRoundRect(mVisualizeGridRect, mGridVisualizationRoundingRadius,
|
||||
mGridVisualizationRoundingRadius, mVisualizeGridPaint);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -846,10 +920,6 @@ public class CellLayout extends ViewGroup {
|
||||
- ((mCountX - 1) * mBorderSpacing);
|
||||
}
|
||||
|
||||
public Drawable getScrimBackground() {
|
||||
return mBackground;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean verifyDrawable(Drawable who) {
|
||||
return super.verifyDrawable(who) || (who == mBackground);
|
||||
@@ -959,61 +1029,32 @@ public class CellLayout extends ViewGroup {
|
||||
return false;
|
||||
}
|
||||
|
||||
void visualizeDropLocation(DraggableView v, DragPreviewProvider outlineProvider, int cellX, int
|
||||
cellY, int spanX, int spanY, boolean resize, DropTarget.DragObject dragObject) {
|
||||
final int oldDragCellX = mDragCell[0];
|
||||
final int oldDragCellY = mDragCell[1];
|
||||
|
||||
if (cellX != oldDragCellX || cellY != oldDragCellY) {
|
||||
void visualizeDropLocation(int cellX, int cellY, int spanX, int spanY,
|
||||
DropTarget.DragObject dragObject) {
|
||||
if (mDragCell[0] != cellX || mDragCell[1] != cellY || mDragCellSpan[0] != spanX
|
||||
|| mDragCellSpan[1] != spanY) {
|
||||
mDragCell[0] = cellX;
|
||||
mDragCell[1] = cellY;
|
||||
|
||||
applyColorExtraction(dragObject, mDragCell, spanX, spanY);
|
||||
|
||||
if (outlineProvider == null || outlineProvider.generatedDragOutline == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap dragOutline = outlineProvider.generatedDragOutline;
|
||||
mDragCellSpan[0] = spanX;
|
||||
mDragCellSpan[1] = spanY;
|
||||
|
||||
final int oldIndex = mDragOutlineCurrent;
|
||||
mDragOutlineAnims[oldIndex].animateOut();
|
||||
mDragOutlineCurrent = (oldIndex + 1) % mDragOutlines.length;
|
||||
Rect r = mDragOutlines[mDragOutlineCurrent];
|
||||
|
||||
cellToRect(cellX, cellY, spanX, spanY, r);
|
||||
int left = r.left;
|
||||
int top = r.top;
|
||||
LayoutParams cell = mDragOutlines[mDragOutlineCurrent];
|
||||
cell.cellX = cellX;
|
||||
cell.cellY = cellY;
|
||||
cell.cellHSpan = spanX;
|
||||
cell.cellVSpan = spanY;
|
||||
|
||||
int width = dragOutline.getWidth();
|
||||
int height = dragOutline.getHeight();
|
||||
|
||||
if (resize) {
|
||||
width = r.width();
|
||||
height = r.height();
|
||||
}
|
||||
|
||||
// Center horizontaly
|
||||
left += (r.width() - dragOutline.getWidth()) / 2;
|
||||
|
||||
if (v != null && v.getViewType() == DraggableView.DRAGGABLE_WIDGET) {
|
||||
// Center vertically
|
||||
top += (r.height() - dragOutline.getHeight()) / 2;
|
||||
} else if (v != null && v.getViewType() == DraggableView.DRAGGABLE_ICON) {
|
||||
int cHeight = getShortcutsAndWidgets().getCellContentHeight();
|
||||
int cellPaddingY = (int) Math.max(0, ((mCellHeight - cHeight) / 2f));
|
||||
top += cellPaddingY;
|
||||
}
|
||||
|
||||
r.set(left, top, left + width, top + height);
|
||||
|
||||
Utilities.scaleRectAboutCenter(r, mChildScale);
|
||||
mDragOutlineAnims[mDragOutlineCurrent].setTag(dragOutline);
|
||||
mDragOutlineAnims[mDragOutlineCurrent].animateIn();
|
||||
invalidate();
|
||||
|
||||
if (dragObject.stateAnnouncer != null) {
|
||||
dragObject.stateAnnouncer.announce(getItemMoveDescription(cellX, cellY));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2504,6 +2545,7 @@ public class CellLayout extends ViewGroup {
|
||||
|
||||
// Invalidate the drag data
|
||||
mDragCell[0] = mDragCell[1] = -1;
|
||||
mDragCellSpan[0] = mDragCellSpan[1] = -1;
|
||||
mDragOutlineAnims[mDragOutlineCurrent].animateOut();
|
||||
mDragOutlineCurrent = (mDragOutlineCurrent + 1) % mDragOutlineAnims.length;
|
||||
revertTempState();
|
||||
|
||||
@@ -81,7 +81,6 @@ import com.android.launcher3.folder.FolderIcon;
|
||||
import com.android.launcher3.folder.PreviewBackground;
|
||||
import com.android.launcher3.graphics.DragPreviewProvider;
|
||||
import com.android.launcher3.graphics.PreloadIconDrawable;
|
||||
import com.android.launcher3.graphics.WorkspaceDragScrim;
|
||||
import com.android.launcher3.icons.BitmapRenderer;
|
||||
import com.android.launcher3.icons.FastBitmapDrawable;
|
||||
import com.android.launcher3.logger.LauncherAtom;
|
||||
@@ -204,8 +203,6 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
|
||||
|
||||
private DragPreviewProvider mOutlineProvider = null;
|
||||
|
||||
private WorkspaceDragScrim mWorkspaceDragScrim;
|
||||
|
||||
private boolean mWorkspaceFadeInAdjacentScreens;
|
||||
|
||||
final WallpaperOffsetInterpolator mWallpaperOffset;
|
||||
@@ -634,6 +631,8 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
|
||||
addView(newScreen, insertIndex);
|
||||
mStateTransitionAnimation.applyChildState(
|
||||
mLauncher.getStateManager().getState(), newScreen, insertIndex);
|
||||
|
||||
updatePageScrollValues();
|
||||
return newScreen;
|
||||
}
|
||||
|
||||
@@ -1007,6 +1006,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
|
||||
}
|
||||
|
||||
updatePageAlphaValues();
|
||||
updatePageScrollValues();
|
||||
enableHwLayersOnVisiblePages();
|
||||
}
|
||||
|
||||
@@ -1212,19 +1212,6 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
|
||||
}
|
||||
}
|
||||
|
||||
public void setWorkspaceDragScrim(WorkspaceDragScrim workspaceDragScrim) {
|
||||
mWorkspaceDragScrim = workspaceDragScrim;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
// The workspace scrim may need to be re-rendered based on the workspace scroll
|
||||
if (mWorkspaceDragScrim != null) {
|
||||
mWorkspaceDragScrim.invalidate();
|
||||
}
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void computeScroll() {
|
||||
super.computeScroll();
|
||||
@@ -1266,6 +1253,17 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePageScrollValues() {
|
||||
int screenCenter = getScrollX() + getMeasuredWidth() / 2;
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
CellLayout child = (CellLayout) getChildAt(i);
|
||||
if (child != null) {
|
||||
float scrollProgress = getScrollProgress(screenCenter, child, i);
|
||||
child.setScrollProgress(scrollProgress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
mWallpaperOffset.setWindowToken(getWindowToken());
|
||||
@@ -2254,8 +2252,8 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
|
||||
item.spanY, child, mTargetCell);
|
||||
|
||||
if (!nearestDropOccupied) {
|
||||
mDragTargetLayout.visualizeDropLocation(d.originalView, mOutlineProvider,
|
||||
mTargetCell[0], mTargetCell[1], item.spanX, item.spanY, false, d);
|
||||
mDragTargetLayout.visualizeDropLocation(mTargetCell[0], mTargetCell[1],
|
||||
item.spanX, item.spanY, d);
|
||||
} else if ((mDragMode == DRAG_MODE_NONE || mDragMode == DRAG_MODE_REORDER)
|
||||
&& !mReorderAlarm.alarmPending() && (mLastReorderX != reorderX ||
|
||||
mLastReorderY != reorderY)) {
|
||||
@@ -2445,8 +2443,8 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
|
||||
}
|
||||
|
||||
boolean resize = resultSpan[0] != spanX || resultSpan[1] != spanY;
|
||||
mDragTargetLayout.visualizeDropLocation(dragObject.originalView, mOutlineProvider,
|
||||
mTargetCell[0], mTargetCell[1], resultSpan[0], resultSpan[1], resize, dragObject);
|
||||
mDragTargetLayout.visualizeDropLocation(mTargetCell[0], mTargetCell[1],
|
||||
resultSpan[0], resultSpan[1], dragObject);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,13 +18,11 @@ package com.android.launcher3;
|
||||
|
||||
import static androidx.dynamicanimation.animation.DynamicAnimation.MIN_VISIBLE_CHANGE_SCALE;
|
||||
|
||||
import static com.android.launcher3.LauncherAnimUtils.DRAWABLE_ALPHA;
|
||||
import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
|
||||
import static com.android.launcher3.LauncherAnimUtils.VIEW_ALPHA;
|
||||
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_X;
|
||||
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_Y;
|
||||
import static com.android.launcher3.LauncherState.FLAG_HAS_SYS_UI_SCRIM;
|
||||
import static com.android.launcher3.LauncherState.FLAG_WORKSPACE_HAS_BACKGROUNDS;
|
||||
import static com.android.launcher3.LauncherState.HINT_STATE;
|
||||
import static com.android.launcher3.LauncherState.HOTSEAT_ICONS;
|
||||
import static com.android.launcher3.LauncherState.NORMAL;
|
||||
@@ -51,8 +49,9 @@ import com.android.launcher3.LauncherState.ScaleAndTranslation;
|
||||
import com.android.launcher3.anim.PendingAnimation;
|
||||
import com.android.launcher3.anim.PropertySetter;
|
||||
import com.android.launcher3.anim.SpringAnimationBuilder;
|
||||
import com.android.launcher3.graphics.Scrim;
|
||||
import com.android.launcher3.graphics.SysUiScrim;
|
||||
import com.android.launcher3.graphics.WorkspaceDragScrim;
|
||||
import com.android.launcher3.states.SpringLoadedState;
|
||||
import com.android.launcher3.states.StateAnimationConfig;
|
||||
import com.android.launcher3.util.DynamicResource;
|
||||
import com.android.systemui.plugins.ResourceProvider;
|
||||
@@ -171,7 +170,7 @@ public class WorkspaceStateTransitionAnimation {
|
||||
|
||||
public void setScrim(PropertySetter propertySetter, LauncherState state,
|
||||
StateAnimationConfig config) {
|
||||
WorkspaceDragScrim workspaceDragScrim = mLauncher.getDragLayer().getWorkspaceDragScrim();
|
||||
Scrim workspaceDragScrim = mLauncher.getDragLayer().getWorkspaceDragScrim();
|
||||
propertySetter.setFloat(workspaceDragScrim, SCRIM_PROGRESS,
|
||||
state.getWorkspaceBackgroundAlpha(mLauncher), LINEAR);
|
||||
|
||||
@@ -193,11 +192,10 @@ public class WorkspaceStateTransitionAnimation {
|
||||
PageAlphaProvider pageAlphaProvider, PropertySetter propertySetter,
|
||||
StateAnimationConfig config) {
|
||||
float pageAlpha = pageAlphaProvider.getPageAlpha(childIndex);
|
||||
int drawableAlpha = state.hasFlag(FLAG_WORKSPACE_HAS_BACKGROUNDS)
|
||||
? Math.round(pageAlpha * 255) : 0;
|
||||
float springLoadedProgress = (state instanceof SpringLoadedState) ? 1.0f : 0f;
|
||||
|
||||
propertySetter.setInt(cl.getScrimBackground(),
|
||||
DRAWABLE_ALPHA, drawableAlpha, ZOOM_OUT);
|
||||
propertySetter.setFloat(cl,
|
||||
CellLayout.SPRING_LOADED_PROGRESS, springLoadedProgress, ZOOM_OUT);
|
||||
Interpolator fadeInterpolator = config.getInterpolator(ANIM_WORKSPACE_FADE,
|
||||
pageAlphaProvider.interpolator);
|
||||
propertySetter.setFloat(cl.getShortcutsAndWidgets(), VIEW_ALPHA,
|
||||
|
||||
@@ -46,8 +46,8 @@ import com.android.launcher3.R;
|
||||
import com.android.launcher3.ShortcutAndWidgetContainer;
|
||||
import com.android.launcher3.Workspace;
|
||||
import com.android.launcher3.folder.Folder;
|
||||
import com.android.launcher3.graphics.Scrim;
|
||||
import com.android.launcher3.graphics.SysUiScrim;
|
||||
import com.android.launcher3.graphics.WorkspaceDragScrim;
|
||||
import com.android.launcher3.keyboard.ViewGroupFocusHelper;
|
||||
import com.android.launcher3.util.Thunk;
|
||||
import com.android.launcher3.views.BaseDragLayer;
|
||||
@@ -83,7 +83,7 @@ public class DragLayer extends BaseDragLayer<Launcher> {
|
||||
|
||||
// Related to adjacent page hints
|
||||
private final ViewGroupFocusHelper mFocusIndicatorHelper;
|
||||
private WorkspaceDragScrim mWorkspaceDragScrim;
|
||||
private Scrim mWorkspaceDragScrim;
|
||||
private SysUiScrim mSysUiScrim;
|
||||
private LauncherRootView mRootView;
|
||||
|
||||
@@ -106,9 +106,7 @@ public class DragLayer extends BaseDragLayer<Launcher> {
|
||||
public void setup(DragController dragController, Workspace workspace) {
|
||||
mDragController = dragController;
|
||||
recreateControllers();
|
||||
|
||||
mWorkspaceDragScrim = new WorkspaceDragScrim((this));
|
||||
mWorkspaceDragScrim.setWorkspace(workspace);
|
||||
mWorkspaceDragScrim = new Scrim(this);
|
||||
|
||||
// We delegate drawing of the workspace scrim to LauncherRootView (one level up), so as
|
||||
// to avoid artifacts when translating the entire drag layer in the -1 transition.
|
||||
@@ -540,7 +538,7 @@ public class DragLayer extends BaseDragLayer<Launcher> {
|
||||
mSysUiScrim.onInsetsChanged(insets, mAllowSysuiScrims);
|
||||
}
|
||||
|
||||
public WorkspaceDragScrim getWorkspaceDragScrim() {
|
||||
public Scrim getWorkspaceDragScrim() {
|
||||
return mWorkspaceDragScrim;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.
|
||||
*/
|
||||
|
||||
package com.android.launcher3.graphics;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Region;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.launcher3.CellLayout;
|
||||
import com.android.launcher3.Workspace;
|
||||
|
||||
/**
|
||||
* Scrim drawn during SpringLoaded State (ie. Drag and Drop). Darkens the workspace except for
|
||||
* the focused CellLayout.
|
||||
*/
|
||||
public class WorkspaceDragScrim extends Scrim {
|
||||
|
||||
private final Rect mHighlightRect = new Rect();
|
||||
|
||||
private Workspace mWorkspace;
|
||||
|
||||
public WorkspaceDragScrim(View view) {
|
||||
super(view);
|
||||
onExtractedColorsChanged(mWallpaperColorInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the workspace that this scrim is acting on
|
||||
* @param workspace
|
||||
*/
|
||||
public void setWorkspace(Workspace workspace) {
|
||||
mWorkspace = workspace;
|
||||
mWorkspace.setWorkspaceDragScrim(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cut out the focused paged of the Workspace and then draw the scrim
|
||||
* @param canvas
|
||||
*/
|
||||
public void draw(Canvas canvas) {
|
||||
// Draw the background below children.
|
||||
if (mScrimAlpha > 0) {
|
||||
// Update the scroll position first to ensure scrim cutout is in the right place.
|
||||
mWorkspace.computeScrollWithoutInvalidation();
|
||||
CellLayout currCellLayout = mWorkspace.getCurrentDragOverlappingLayout();
|
||||
canvas.save();
|
||||
if (currCellLayout != null && currCellLayout != mLauncher.getHotseat()) {
|
||||
// Cut a hole in the darkening scrim on the page that should be highlighted, if any.
|
||||
mLauncher.getDragLayer()
|
||||
.getDescendantRectRelativeToSelf(currCellLayout, mHighlightRect);
|
||||
canvas.clipRect(mHighlightRect, Region.Op.DIFFERENCE);
|
||||
}
|
||||
|
||||
super.draw(canvas);
|
||||
canvas.restore();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user