Merge "Correct Launcher3 for new sizes in App Widgets." into sc-dev
This commit is contained in:
commit
bcadf1457c
5 files changed
+27
-57
No files matched your search
@@ -12,12 +12,11 @@ import android.animation.PropertyValuesHolder;
|
||||
import android.appwidget.AppWidgetHostView;
|
||||
import android.appwidget.AppWidgetProviderInfo;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.SizeF;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
@@ -368,7 +367,7 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
|
||||
public static void updateWidgetSizeRanges(AppWidgetHostView widgetView, Launcher launcher,
|
||||
int spanX, int spanY) {
|
||||
List<PointF> sizes = getWidgetSizes(launcher, spanX, spanY);
|
||||
List<SizeF> sizes = getWidgetSizes(launcher, spanX, spanY);
|
||||
if (ATLEAST_S) {
|
||||
widgetView.updateAppWidgetSize(new Bundle(), sizes);
|
||||
} else {
|
||||
@@ -378,43 +377,25 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
}
|
||||
}
|
||||
|
||||
private static PointF getWidgetSize(Context context, Point cellSize, int spanX, int spanY,
|
||||
private static SizeF getWidgetSize(Context context, Point cellSize, int spanX, int spanY,
|
||||
int borderSpacing) {
|
||||
final float density = context.getResources().getDisplayMetrics().density;
|
||||
final float hBorderSpacing = (spanX - 1) * borderSpacing;
|
||||
final float vBorderSpacing = (spanY - 1) * borderSpacing;
|
||||
|
||||
PointF widgetSize = new PointF();
|
||||
widgetSize.x = ((spanX * cellSize.x) + hBorderSpacing) / density;
|
||||
widgetSize.y = ((spanY * cellSize.y) + vBorderSpacing) / density;
|
||||
return widgetSize;
|
||||
}
|
||||
|
||||
/** Returns the actual widget size given its span. */
|
||||
public static PointF getWidgetSize(Context context, int spanX, int spanY) {
|
||||
final Point[] cellSize = CELL_SIZE.get(context);
|
||||
final int[] borderSpacing = BORDER_SPACING_SIZE.get(context);
|
||||
if (isLandscape(context)) {
|
||||
return getWidgetSize(context, cellSize[0], spanX, spanY, borderSpacing[0]);
|
||||
}
|
||||
return getWidgetSize(context, cellSize[1], spanX, spanY, borderSpacing[1]);
|
||||
}
|
||||
|
||||
/** Returns true if the screen is in landscape mode. */
|
||||
private static boolean isLandscape(Context context) {
|
||||
return context.getResources().getConfiguration().orientation
|
||||
== Configuration.ORIENTATION_LANDSCAPE;
|
||||
return new SizeF(((spanX * cellSize.x) + hBorderSpacing) / density,
|
||||
((spanY * cellSize.y) + vBorderSpacing) / density);
|
||||
}
|
||||
|
||||
/** Returns the list of sizes for a widget of given span, in dp. */
|
||||
public static ArrayList<PointF> getWidgetSizes(Context context, int spanX, int spanY) {
|
||||
public static ArrayList<SizeF> getWidgetSizes(Context context, int spanX, int spanY) {
|
||||
final Point[] cellSize = CELL_SIZE.get(context);
|
||||
final int[] borderSpacing = BORDER_SPACING_SIZE.get(context);
|
||||
|
||||
PointF landSize = getWidgetSize(context, cellSize[0], spanX, spanY, borderSpacing[0]);
|
||||
PointF portSize = getWidgetSize(context, cellSize[1], spanX, spanY, borderSpacing[1]);
|
||||
SizeF landSize = getWidgetSize(context, cellSize[0], spanX, spanY, borderSpacing[0]);
|
||||
SizeF portSize = getWidgetSize(context, cellSize[1], spanX, spanY, borderSpacing[1]);
|
||||
|
||||
ArrayList<PointF> sizes = new ArrayList<>(2);
|
||||
ArrayList<SizeF> sizes = new ArrayList<>(2);
|
||||
sizes.add(landSize);
|
||||
sizes.add(portSize);
|
||||
return sizes;
|
||||
@@ -430,17 +411,18 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
* the right (resp. bottom) for the max. The returned rectangle is set with 0s if the list is
|
||||
* empty.
|
||||
*/
|
||||
public static Rect getMinMaxSizes(List<PointF> sizes, @Nullable Rect outRect) {
|
||||
public static Rect getMinMaxSizes(List<SizeF> sizes, @Nullable Rect outRect) {
|
||||
if (outRect == null) {
|
||||
outRect = new Rect();
|
||||
}
|
||||
if (sizes.isEmpty()) {
|
||||
outRect.set(0, 0, 0, 0);
|
||||
} else {
|
||||
PointF first = sizes.get(0);
|
||||
outRect.set((int) first.x, (int) first.y, (int) first.x, (int) first.y);
|
||||
SizeF first = sizes.get(0);
|
||||
outRect.set((int) first.getWidth(), (int) first.getHeight(), (int) first.getWidth(),
|
||||
(int) first.getHeight());
|
||||
for (int i = 1; i < sizes.size(); i++) {
|
||||
outRect.union((int) sizes.get(i).x, (int) sizes.get(i).y);
|
||||
outRect.union((int) sizes.get(i).getWidth(), (int) sizes.get(i).getHeight());
|
||||
}
|
||||
}
|
||||
return outRect;
|
||||
|
||||
@@ -32,11 +32,11 @@ import android.appwidget.AppWidgetProviderInfo;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.SizeF;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -299,7 +299,7 @@ public class QsbContainerView extends FrameLayout {
|
||||
InvariantDeviceProfile idp = LauncherAppState.getIDP(getContext());
|
||||
|
||||
Bundle opts = new Bundle();
|
||||
ArrayList<PointF> sizes = AppWidgetResizeFrame
|
||||
ArrayList<SizeF> sizes = AppWidgetResizeFrame
|
||||
.getWidgetSizes(getContext(), idp.numColumns, 1);
|
||||
Rect size = AppWidgetResizeFrame.getMinMaxSizes(sizes, null /* outRect */);
|
||||
opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, size.left);
|
||||
|
||||
@@ -16,12 +16,9 @@
|
||||
|
||||
package com.android.launcher3.widget;
|
||||
|
||||
import static com.android.launcher3.Utilities.ATLEAST_S;
|
||||
|
||||
import android.appwidget.AppWidgetProviderInfo;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.PointF;
|
||||
import android.os.Handler;
|
||||
import android.os.SystemClock;
|
||||
import android.util.SparseBooleanArray;
|
||||
@@ -218,16 +215,6 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView
|
||||
mIsScrollable = checkScrollableRecursively(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
|
||||
if (ATLEAST_S) {
|
||||
float density = getContext().getResources().getDisplayMetrics().density;
|
||||
setCurrentSize(new PointF(w / density, h / density));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
|
||||
super.onInitializeAccessibilityNodeInfo(info);
|
||||
|
||||
@@ -22,7 +22,6 @@ import static com.android.launcher3.graphics.PreloadIconDrawable.newPendingIcon;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
@@ -30,6 +29,7 @@ import android.os.Bundle;
|
||||
import android.text.Layout;
|
||||
import android.text.StaticLayout;
|
||||
import android.text.TextPaint;
|
||||
import android.util.SizeF;
|
||||
import android.util.TypedValue;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.View;
|
||||
@@ -112,7 +112,7 @@ public class PendingAppWidgetHostView extends LauncherAppWidgetHostView
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAppWidgetSize(Bundle newOptions, List<PointF> sizes) {
|
||||
public void updateAppWidgetSize(Bundle newOptions, List<SizeF> sizes) {
|
||||
// No-op
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@ package com.android.launcher3.widget;
|
||||
import android.appwidget.AppWidgetHostView;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.Context;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.util.SizeF;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.launcher3.AppWidgetResizeFrame;
|
||||
@@ -19,6 +19,7 @@ import com.android.launcher3.dragndrop.DragOptions;
|
||||
import com.android.launcher3.util.Thunk;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class WidgetHostViewLoader implements DragController.DragListener {
|
||||
private static final String TAG = "WidgetHostViewLoader";
|
||||
@@ -154,7 +155,7 @@ public class WidgetHostViewLoader implements DragController.DragListener {
|
||||
}
|
||||
|
||||
public static Bundle getDefaultOptionsForWidget(Context context, PendingAddWidgetInfo info) {
|
||||
ArrayList<PointF> sizes = AppWidgetResizeFrame
|
||||
ArrayList<SizeF> sizes = AppWidgetResizeFrame
|
||||
.getWidgetSizes(context, info.spanX, info.spanY);
|
||||
|
||||
Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context,
|
||||
@@ -163,19 +164,19 @@ public class WidgetHostViewLoader implements DragController.DragListener {
|
||||
float xPaddingDips = (padding.left + padding.right) / density;
|
||||
float yPaddingDips = (padding.top + padding.bottom) / density;
|
||||
|
||||
for (PointF size : sizes) {
|
||||
size.x = Math.max(0.f, size.x - xPaddingDips);
|
||||
size.y = Math.max(0.f, size.y - yPaddingDips);
|
||||
}
|
||||
ArrayList<SizeF> paddedSizes = sizes.stream().map(
|
||||
size -> new SizeF(Math.max(0.f, size.getWidth() - xPaddingDips),
|
||||
Math.max(0.f, size.getHeight() - yPaddingDips))).collect(
|
||||
Collectors.toCollection(ArrayList::new));
|
||||
|
||||
Rect rect = AppWidgetResizeFrame.getMinMaxSizes(sizes, null /* outRect */);
|
||||
Rect rect = AppWidgetResizeFrame.getMinMaxSizes(paddedSizes, null /* outRect */);
|
||||
|
||||
Bundle options = new Bundle();
|
||||
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, rect.left);
|
||||
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, rect.top);
|
||||
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, rect.right);
|
||||
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, rect.bottom);
|
||||
options.putParcelableArrayList(AppWidgetManager.OPTION_APPWIDGET_SIZES, sizes);
|
||||
options.putParcelableArrayList(AppWidgetManager.OPTION_APPWIDGET_SIZES, paddedSizes);
|
||||
return options;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user