am 9e05a5ea: Making launcher use new widget binding APIs

* commit '9e05a5ea951b4d5ffce324da8dd0656353306e6f':
  Making launcher use new widget binding APIs
This commit is contained in:
Adam Cohen
2012-09-20 06:07:54 -07:00
committed by Android Git Automerger
5 changed files with 71 additions and 8 deletions
@@ -64,6 +64,8 @@ public class AppWidgetResizeFrame extends FrameLayout {
final float DIMMED_HANDLE_ALPHA = 0f;
final float RESIZE_THRESHOLD = 0.66f;
private static Rect mTmpRect = new Rect();
public static final int LEFT = 0;
public static final int TOP = 1;
public static final int RIGHT = 2;
@@ -336,6 +338,16 @@ public class AppWidgetResizeFrame extends FrameLayout {
static void updateWidgetSizeRanges(AppWidgetHostView widgetView, Launcher launcher,
int spanX, int spanY) {
getWidgetSizeRanges(launcher, spanX, spanY, mTmpRect);
widgetView.updateAppWidgetSize(null, mTmpRect.left, mTmpRect.top,
mTmpRect.right, mTmpRect.bottom);
}
static Rect getWidgetSizeRanges(Launcher launcher, int spanX, int spanY, Rect rect) {
if (rect == null) {
rect = new Rect();
}
Rect landMetrics = Workspace.getCellLayoutMetrics(launcher, CellLayout.LANDSCAPE);
Rect portMetrics = Workspace.getCellLayoutMetrics(launcher, CellLayout.PORTRAIT);
final float density = launcher.getResources().getDisplayMetrics().density;
@@ -355,8 +367,8 @@ public class AppWidgetResizeFrame extends FrameLayout {
heightGap = portMetrics.bottom;
int portWidth = (int) ((spanX * cellWidth + (spanX - 1) * widthGap) / density);
int portHeight = (int) ((spanY * cellHeight + (spanY - 1) * heightGap) / density);
widgetView.updateAppWidgetSize(null, portWidth, landHeight, landWidth, portHeight);
rect.set(portWidth, landHeight, landWidth, portHeight);
return rect;
}
/**
@@ -43,6 +43,8 @@ import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Process;
import android.util.AttributeSet;
import android.util.Log;
@@ -309,6 +311,8 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
private ArrayList<Runnable> mDeferredPrepareLoadWidgetPreviewsTasks =
new ArrayList<Runnable>();
private Rect mTmpRect = new Rect();
// Used for drawing shortcut previews
BitmapCache mCachedShortcutPreviewBitmap = new BitmapCache();
PaintCache mCachedShortcutPreviewPaint = new PaintCache();
@@ -617,6 +621,19 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
mLauncher.getWorkspace().beginDragShared(v, this);
}
Bundle getDefaultOptionsForWidget(Launcher launcher, PendingAddWidgetInfo info) {
Bundle options = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
AppWidgetResizeFrame.getWidgetSizeRanges(mLauncher, info.spanX, info.spanY, mTmpRect);
options = new Bundle();
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, mTmpRect.left);
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, mTmpRect.top);
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, mTmpRect.right);
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, mTmpRect.bottom);
}
return options;
}
private void preloadWidget(final PendingAddWidgetInfo info) {
final AppWidgetProviderInfo pInfo = info.info;
if (pInfo.configure != null) {
@@ -628,9 +645,20 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
@Override
public void run() {
mWidgetLoadingId = mLauncher.getAppWidgetHost().allocateAppWidgetId();
if (AppWidgetManager.getInstance(mLauncher)
.bindAppWidgetIdIfAllowed(mWidgetLoadingId, info.componentName)) {
mWidgetCleanupState = WIDGET_BOUND;
Bundle options = getDefaultOptionsForWidget(mLauncher, info);
// Options will be null for platforms with JB or lower, so this serves as an
// SDK level check.
if (options == null) {
if (AppWidgetManager.getInstance(mLauncher).bindAppWidgetIdIfAllowed(
mWidgetLoadingId, info.componentName)) {
mWidgetCleanupState = WIDGET_BOUND;
}
} else {
if (AppWidgetManager.getInstance(mLauncher).bindAppWidgetIdIfAllowed(
mWidgetLoadingId, info.componentName, options)) {
mWidgetCleanupState = WIDGET_BOUND;
}
}
}
};
+4 -1
View File
@@ -55,6 +55,7 @@ import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
@@ -1190,7 +1191,9 @@ public final class Launcher extends Activity
launcherInfo.hostView.setTag(launcherInfo);
launcherInfo.hostView.setVisibility(View.VISIBLE);
launcherInfo.notifyWidgetSizeChanged(this);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
launcherInfo.notifyWidgetSizeChanged(this);
}
mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
@@ -19,6 +19,7 @@ package com.android.launcher2;
import android.appwidget.AppWidgetHostView;
import android.content.ComponentName;
import android.content.ContentValues;
import android.os.Build;
/**
* Represents a widget (either instantiated or about to be) in the Launcher.
@@ -72,7 +73,8 @@ class LauncherAppWidgetInfo extends ItemInfo {
* done so already (only really for default workspace widgets).
*/
void onBindAppWidget(Launcher launcher) {
if (!mHasNotifiedInitialWidgetSizeChanged) {
if (!mHasNotifiedInitialWidgetSizeChanged &&
Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
notifyWidgetSizeChanged(launcher);
}
}
+19 -1
View File
@@ -39,6 +39,7 @@ import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.Region.Op;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.IBinder;
import android.os.Parcelable;
import android.util.AttributeSet;
@@ -2228,7 +2229,12 @@ public class Workspace extends SmoothPagedView
mTargetCell, resultSpan, CellLayout.MODE_ON_DROP);
boolean foundCell = mTargetCell[0] >= 0 && mTargetCell[1] >= 0;
if (foundCell && (resultSpan[0] != item.spanX || resultSpan[1] != item.spanY)) {
// if the widget resizes on drop, or the sdk level is less than JBMR1, then we
// need to update the size.
if (foundCell && (cell instanceof AppWidgetHostView) &&
(resultSpan[0] != item.spanX || resultSpan[1] != item.spanY ||
Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)) {
resizeOnDrop = true;
item.spanX = resultSpan[0];
item.spanY = resultSpan[1];
@@ -3037,6 +3043,7 @@ public class Workspace extends SmoothPagedView
}
final ItemInfo item = (ItemInfo) d.dragInfo;
boolean updateWidgetSize = Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN;
if (findNearestVacantCell) {
int minSpanX = item.spanX;
int minSpanY = item.spanY;
@@ -3048,6 +3055,10 @@ public class Workspace extends SmoothPagedView
mTargetCell = cellLayout.createArea((int) mDragViewVisualCenter[0],
(int) mDragViewVisualCenter[1], minSpanX, minSpanY, info.spanX, info.spanY,
null, mTargetCell, resultSpan, CellLayout.MODE_ON_DROP_EXTERNAL);
if (resultSpan[0] != item.spanX || resultSpan[1] != item.spanY) {
updateWidgetSize = true;
}
item.spanX = resultSpan[0];
item.spanY = resultSpan[1];
}
@@ -3077,6 +3088,13 @@ public class Workspace extends SmoothPagedView
};
View finalView = pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET
? ((PendingAddWidgetInfo) pendingInfo).boundWidget : null;
if (finalView instanceof AppWidgetHostView && updateWidgetSize) {
AppWidgetHostView awhv = (AppWidgetHostView) finalView;
AppWidgetResizeFrame.updateWidgetSizeRanges(awhv, mLauncher, item.spanX,
item.spanY);
}
int animationStyle = ANIMATE_INTO_POSITION_AND_DISAPPEAR;
if (pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET &&
((PendingAddWidgetInfo) pendingInfo).info.configure != null) {