Fix bug where very large widgets get cropped out am: cb36de9e9f am: 2563c27666
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/21381954 Change-Id: Ie31ccc8b4b09f66cb7963ab9bf405696cf4b8509 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.launcher3.widget;
|
package com.android.launcher3.widget;
|
||||||
|
|
||||||
|
import static android.view.View.MeasureSpec.getSize;
|
||||||
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 android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||||
@@ -118,6 +119,8 @@ public class WidgetCell extends LinearLayout {
|
|||||||
private TextView mWidgetName;
|
private TextView mWidgetName;
|
||||||
private TextView mWidgetDims;
|
private TextView mWidgetDims;
|
||||||
private TextView mWidgetDescription;
|
private TextView mWidgetDescription;
|
||||||
|
private Consumer<Bitmap> mCallback;
|
||||||
|
private @Nullable Bitmap mCachedPreview;
|
||||||
|
|
||||||
protected WidgetItem mItem;
|
protected WidgetItem mItem;
|
||||||
|
|
||||||
@@ -429,6 +432,8 @@ public class WidgetCell extends LinearLayout {
|
|||||||
*/
|
*/
|
||||||
private void ensurePreviewWithCallback(Consumer<Bitmap> callback,
|
private void ensurePreviewWithCallback(Consumer<Bitmap> callback,
|
||||||
@Nullable Bitmap cachedPreview) {
|
@Nullable Bitmap cachedPreview) {
|
||||||
|
mCallback = callback;
|
||||||
|
mCachedPreview = cachedPreview;
|
||||||
if (mAppWidgetHostViewPreview != null) {
|
if (mAppWidgetHostViewPreview != null) {
|
||||||
int containerWidth = (int) (mTargetPreviewWidth * mPreviewContainerScale);
|
int containerWidth = (int) (mTargetPreviewWidth * mPreviewContainerScale);
|
||||||
int containerHeight = (int) (mTargetPreviewHeight * mPreviewContainerScale);
|
int containerHeight = (int) (mTargetPreviewHeight * mPreviewContainerScale);
|
||||||
@@ -469,6 +474,7 @@ public class WidgetCell extends LinearLayout {
|
|||||||
INDEX_WIDGET_CENTERING,
|
INDEX_WIDGET_CENTERING,
|
||||||
-(params.width - (params.width * mPreviewContainerScale)) / 2.0f,
|
-(params.width - (params.width * mPreviewContainerScale)) / 2.0f,
|
||||||
-(params.height - (params.height * mPreviewContainerScale)) / 2.0f);
|
-(params.height - (params.height * mPreviewContainerScale)) / 2.0f);
|
||||||
|
mWidgetImageContainer.removeAllViews();
|
||||||
mWidgetImageContainer.addView(mAppWidgetHostViewPreview, /* index= */ 0);
|
mWidgetImageContainer.addView(mAppWidgetHostViewPreview, /* index= */ 0);
|
||||||
mWidgetImage.setVisibility(View.GONE);
|
mWidgetImage.setVisibility(View.GONE);
|
||||||
applyPreview(null);
|
applyPreview(null);
|
||||||
@@ -579,4 +585,19 @@ public class WidgetCell extends LinearLayout {
|
|||||||
(mTargetPreviewHeight - verticalPadding) * mPreviewContainerScale
|
(mTargetPreviewHeight - verticalPadding) * mPreviewContainerScale
|
||||||
/ appWidgetContentHeight);
|
/ appWidgetContentHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
int padding = getPaddingLeft() + getPaddingRight();
|
||||||
|
int allowedWidth = getSize(widthMeasureSpec) - padding;
|
||||||
|
|
||||||
|
// Here we prevent having clipped widgets when they're too large as the preview width is
|
||||||
|
// larger than the max allowed width. We then re-do the preview with the new preview width
|
||||||
|
if (allowedWidth > 0 && mCachedPreview == null && allowedWidth < mTargetPreviewWidth) {
|
||||||
|
mTargetPreviewWidth = allowedWidth;
|
||||||
|
ensurePreviewWithCallback(mCallback, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user