Merge "Fix scaling on widget previews that have width / height set to wrap_content" into sc-v2-dev am: b971baefe1
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/15346899 Change-Id: I44db843f7c9248c078342ac927a2663427f4b3ee
This commit is contained in:
commit
841fc730ef
4 files changed
+52
-12
No files matched your search
@@ -192,15 +192,15 @@ public class AddItemActivity extends BaseActivity
|
|||||||
float appWidgetHostViewScale = mWidgetCell.getAppWidgetHostViewScale();
|
float appWidgetHostViewScale = mWidgetCell.getAppWidgetHostViewScale();
|
||||||
int xOffset =
|
int xOffset =
|
||||||
appWidgetHostView.getLeft() - (int) (mLastTouchPos.x * appWidgetHostViewScale);
|
appWidgetHostView.getLeft() - (int) (mLastTouchPos.x * appWidgetHostViewScale);
|
||||||
int yOffset = appWidgetHostView.getTop()
|
int yOffset =
|
||||||
- (int) (mLastTouchPos.y * mWidgetCell.getAppWidgetHostViewScale());
|
appWidgetHostView.getTop() - (int) (mLastTouchPos.y * appWidgetHostViewScale);
|
||||||
bounds.offset(xOffset, yOffset);
|
bounds.offset(xOffset, yOffset);
|
||||||
listener = new PinItemDragListener(
|
listener = new PinItemDragListener(
|
||||||
mRequest,
|
mRequest,
|
||||||
bounds,
|
bounds,
|
||||||
appWidgetHostView.getMeasuredWidth(),
|
appWidgetHostView.getMeasuredWidth(),
|
||||||
appWidgetHostView.getMeasuredWidth(),
|
appWidgetHostView.getMeasuredWidth(),
|
||||||
appWidgetHostView.getScaleX());
|
appWidgetHostViewScale);
|
||||||
} else {
|
} else {
|
||||||
bounds = img.getBitmapBounds();
|
bounds = img.getBitmapBounds();
|
||||||
bounds.offset(img.getLeft() - (int) mLastTouchPos.x,
|
bounds.offset(img.getLeft() - (int) mLastTouchPos.x,
|
||||||
|
|||||||
@@ -188,11 +188,11 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher>
|
|||||||
dragHelper.startDrag(image.getBitmapBounds(), image.getDrawable().getIntrinsicWidth(),
|
dragHelper.startDrag(image.getBitmapBounds(), image.getDrawable().getIntrinsicWidth(),
|
||||||
image.getWidth(), new Point(loc[0], loc[1]), this, new DragOptions());
|
image.getWidth(), new Point(loc[0], loc[1]), this, new DragOptions());
|
||||||
} else {
|
} else {
|
||||||
View preview = v.getAppWidgetHostViewPreview();
|
NavigableAppWidgetHostView preview = v.getAppWidgetHostViewPreview();
|
||||||
int[] loc = new int[2];
|
int[] loc = new int[2];
|
||||||
getPopupContainer().getLocationInDragLayer(preview, loc);
|
getPopupContainer().getLocationInDragLayer(preview, loc);
|
||||||
|
Rect r = new Rect();
|
||||||
Rect r = new Rect(0, 0, preview.getWidth(), preview.getHeight());
|
preview.getWorkspaceVisualDragBounds(r);
|
||||||
dragHelper.startDrag(r, preview.getMeasuredWidth(), preview.getMeasuredWidth(),
|
dragHelper.startDrag(r, preview.getMeasuredWidth(), preview.getMeasuredWidth(),
|
||||||
new Point(loc[0], loc[1]), this, new DragOptions());
|
new Point(loc[0], loc[1]), this, new DragOptions());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,10 +84,8 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView
|
|||||||
private boolean mIsScrollable;
|
private boolean mIsScrollable;
|
||||||
private boolean mIsAttachedToWindow;
|
private boolean mIsAttachedToWindow;
|
||||||
private boolean mIsAutoAdvanceRegistered;
|
private boolean mIsAutoAdvanceRegistered;
|
||||||
private boolean mIsInDragMode = false;
|
|
||||||
private Runnable mAutoAdvanceRunnable;
|
private Runnable mAutoAdvanceRunnable;
|
||||||
private RectF mLastLocationRegistered = null;
|
private RectF mLastLocationRegistered = null;
|
||||||
@Nullable private AppWidgetHostViewDragListener mDragListener;
|
|
||||||
|
|
||||||
// Used to store the widget sizes in drag layer coordinates.
|
// Used to store the widget sizes in drag layer coordinates.
|
||||||
private final Rect mCurrentWidgetSize = new Rect();
|
private final Rect mCurrentWidgetSize = new Rect();
|
||||||
@@ -102,6 +100,14 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView
|
|||||||
private @Nullable SparseIntArray mDeferredColorChange = null;
|
private @Nullable SparseIntArray mDeferredColorChange = null;
|
||||||
private boolean mEnableColorExtraction = true;
|
private boolean mEnableColorExtraction = true;
|
||||||
|
|
||||||
|
// The following member variables are only used during drag-n-drop.
|
||||||
|
private boolean mIsInDragMode = false;
|
||||||
|
@Nullable private AppWidgetHostViewDragListener mDragListener;
|
||||||
|
/** The drag content width which is only set when the drag content scale is not 1f. */
|
||||||
|
private int mDragContentWidth = 0;
|
||||||
|
/** The drag content height which is only set when the drag content scale is not 1f. */
|
||||||
|
private int mDragContentHeight = 0;
|
||||||
|
|
||||||
public LauncherAppWidgetHostView(Context context) {
|
public LauncherAppWidgetHostView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
mLauncher = Launcher.getLauncher(context);
|
mLauncher = Launcher.getLauncher(context);
|
||||||
@@ -310,10 +316,28 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView
|
|||||||
updateColorExtraction();
|
updateColorExtraction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||||
|
if (mIsInDragMode && mDragContentWidth > 0 && mDragContentHeight > 0
|
||||||
|
&& getChildCount() == 1) {
|
||||||
|
measureChild(getChildAt(0), MeasureSpec.getSize(mDragContentWidth),
|
||||||
|
MeasureSpec.getSize(mDragContentHeight));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Starts the drag mode. */
|
/** Starts the drag mode. */
|
||||||
public void startDrag(AppWidgetHostViewDragListener dragListener) {
|
public void startDrag(AppWidgetHostViewDragListener dragListener) {
|
||||||
mIsInDragMode = true;
|
mIsInDragMode = true;
|
||||||
mDragListener = dragListener;
|
mDragListener = dragListener;
|
||||||
|
// In the case of dragging a scaled preview from widgets picker, we should reuse the
|
||||||
|
// previously measured dimension from WidgetCell#measureAndComputeWidgetPreviewScale, which
|
||||||
|
// measures the dimension of a widget preview without its parent's bound before scaling
|
||||||
|
// down.
|
||||||
|
if ((getScaleX() != 1f || getScaleY() != 1f) && getChildCount() == 1) {
|
||||||
|
mDragContentWidth = getChildAt(0).getMeasuredWidth();
|
||||||
|
mDragContentHeight = getChildAt(0).getMeasuredHeight();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Handles a drag event occurred on a workspace page, {@code pageId}. */
|
/** Handles a drag event occurred on a workspace page, {@code pageId}. */
|
||||||
@@ -326,6 +350,8 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView
|
|||||||
public void endDrag() {
|
public void endDrag() {
|
||||||
mIsInDragMode = false;
|
mIsInDragMode = false;
|
||||||
mDragListener = null;
|
mDragListener = null;
|
||||||
|
mDragContentWidth = 0;
|
||||||
|
mDragContentHeight = 0;
|
||||||
mWidgetSizeAtDrag.setEmpty();
|
mWidgetSizeAtDrag.setEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package com.android.launcher3.widget;
|
|||||||
|
|
||||||
import static android.view.View.MeasureSpec.makeMeasureSpec;
|
import static android.view.View.MeasureSpec.makeMeasureSpec;
|
||||||
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
||||||
|
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||||
|
|
||||||
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_TRAY;
|
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_TRAY;
|
||||||
import static com.android.launcher3.Utilities.ATLEAST_S;
|
import static com.android.launcher3.Utilities.ATLEAST_S;
|
||||||
@@ -372,7 +373,7 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
|
|||||||
if (shouldScale) {
|
if (shouldScale) {
|
||||||
setNoClip(mWidgetImageContainer);
|
setNoClip(mWidgetImageContainer);
|
||||||
setNoClip(mAppWidgetHostViewPreview);
|
setNoClip(mAppWidgetHostViewPreview);
|
||||||
mAppWidgetHostViewScale = computeWidgetPreviewScale();
|
mAppWidgetHostViewScale = measureAndComputeWidgetPreviewScale();
|
||||||
mAppWidgetHostViewPreview.setScaleToFit(mAppWidgetHostViewScale);
|
mAppWidgetHostViewPreview.setScaleToFit(mAppWidgetHostViewScale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -473,7 +474,7 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
|
|||||||
view.setClipToPadding(false);
|
view.setClipToPadding(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private float computeWidgetPreviewScale() {
|
private float measureAndComputeWidgetPreviewScale() {
|
||||||
if (mAppWidgetHostViewPreview.getChildCount() != 1) {
|
if (mAppWidgetHostViewPreview.getChildCount() != 1) {
|
||||||
return 1f;
|
return 1f;
|
||||||
}
|
}
|
||||||
@@ -482,12 +483,25 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
|
|||||||
mAppWidgetHostViewPreview.measure(
|
mAppWidgetHostViewPreview.measure(
|
||||||
makeMeasureSpec(MAX_MEASURE_SPEC_DIMENSION, MeasureSpec.UNSPECIFIED),
|
makeMeasureSpec(MAX_MEASURE_SPEC_DIMENSION, MeasureSpec.UNSPECIFIED),
|
||||||
makeMeasureSpec(MAX_MEASURE_SPEC_DIMENSION, MeasureSpec.UNSPECIFIED));
|
makeMeasureSpec(MAX_MEASURE_SPEC_DIMENSION, MeasureSpec.UNSPECIFIED));
|
||||||
int appWidgetContentWidth = mAppWidgetHostViewPreview.getChildAt(0).getMeasuredWidth();
|
View widgetContent = mAppWidgetHostViewPreview.getChildAt(0);
|
||||||
int appWidgetContentHeight = mAppWidgetHostViewPreview.getChildAt(0).getMeasuredHeight();
|
int appWidgetContentWidth = widgetContent.getMeasuredWidth();
|
||||||
|
int appWidgetContentHeight = widgetContent.getMeasuredHeight();
|
||||||
if (appWidgetContentWidth == 0 || appWidgetContentHeight == 0) {
|
if (appWidgetContentWidth == 0 || appWidgetContentHeight == 0) {
|
||||||
return 1f;
|
return 1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the width / height of the widget content is set to wrap content, overrides the width /
|
||||||
|
// height with the measured dimension. This avoids incorrect measurement after scaling.
|
||||||
|
FrameLayout.LayoutParams layoutParam =
|
||||||
|
(FrameLayout.LayoutParams) widgetContent.getLayoutParams();
|
||||||
|
if (layoutParam.width == WRAP_CONTENT) {
|
||||||
|
layoutParam.width = widgetContent.getMeasuredWidth();
|
||||||
|
}
|
||||||
|
if (layoutParam.height == WRAP_CONTENT) {
|
||||||
|
layoutParam.height = widgetContent.getMeasuredHeight();
|
||||||
|
}
|
||||||
|
widgetContent.setLayoutParams(layoutParam);
|
||||||
|
|
||||||
int horizontalPadding = mAppWidgetHostViewPreview.getPaddingStart()
|
int horizontalPadding = mAppWidgetHostViewPreview.getPaddingStart()
|
||||||
+ mAppWidgetHostViewPreview.getPaddingEnd();
|
+ mAppWidgetHostViewPreview.getPaddingEnd();
|
||||||
int verticalPadding = mAppWidgetHostViewPreview.getPaddingTop()
|
int verticalPadding = mAppWidgetHostViewPreview.getPaddingTop()
|
||||||
|
|||||||
Reference in new issue
Block a user