mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-02 17:06:49 +00:00
Launcher changes for go/widget-size-specification
Makes sure the launcher: 1 - Send the list of actual sizes the widget in all situations. 2 - Gives the current size to the framework on inflation. Also needed to guard the new border changes introduced in http://ag/13532637 with the corresponding flag. Change-Id: I2a33e9501b921f2fc393684e8ce91ee077626bf7 Test: By hand using a local widget. Bug: 179025145
This commit is contained in:
@@ -3,6 +3,7 @@ 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;
|
||||
@@ -18,6 +19,8 @@ import com.android.launcher3.dragndrop.DragLayer;
|
||||
import com.android.launcher3.dragndrop.DragOptions;
|
||||
import com.android.launcher3.util.Thunk;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class WidgetHostViewLoader implements DragController.DragListener {
|
||||
private static final String TAG = "WidgetHostViewLoader";
|
||||
private static final boolean LOGD = false;
|
||||
@@ -152,24 +155,28 @@ public class WidgetHostViewLoader implements DragController.DragListener {
|
||||
}
|
||||
|
||||
public static Bundle getDefaultOptionsForWidget(Context context, PendingAddWidgetInfo info) {
|
||||
Rect rect = new Rect();
|
||||
AppWidgetResizeFrame.getWidgetSizeRanges(context, info.spanX, info.spanY, rect);
|
||||
ArrayList<PointF> sizes = AppWidgetResizeFrame
|
||||
.getWidgetSizes(context, info.spanX, info.spanY);
|
||||
|
||||
Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context,
|
||||
info.componentName, null);
|
||||
|
||||
float density = context.getResources().getDisplayMetrics().density;
|
||||
int xPaddingDips = (int) ((padding.left + padding.right) / density);
|
||||
int yPaddingDips = (int) ((padding.top + padding.bottom) / density);
|
||||
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);
|
||||
}
|
||||
|
||||
Rect rect = AppWidgetResizeFrame.getMinMaxSizes(sizes, null /* outRect */);
|
||||
|
||||
Bundle options = new Bundle();
|
||||
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH,
|
||||
rect.left - xPaddingDips);
|
||||
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT,
|
||||
rect.top - yPaddingDips);
|
||||
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH,
|
||||
rect.right - xPaddingDips);
|
||||
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT,
|
||||
rect.bottom - yPaddingDips);
|
||||
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);
|
||||
return options;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user