Updating widget resize frame assets.

> Using a shadow as background and a frame as foreground.
> The handle has baked in shadow which gets wrapped by the
frame shadow

Change-Id: Ib0e305ea735304236b3319e4fde22fb442f5dc0f
This commit is contained in:
Sunny Goyal
2015-05-18 20:52:57 -07:00
parent e49c105de5
commit ba776d57f4
37 changed files with 56 additions and 62 deletions

View File

@@ -15,24 +15,36 @@ import android.widget.FrameLayout;
import android.widget.ImageView;
public class AppWidgetResizeFrame extends FrameLayout {
private LauncherAppWidgetHostView mWidgetView;
private CellLayout mCellLayout;
private DragLayer mDragLayer;
private ImageView mLeftHandle;
private ImageView mRightHandle;
private ImageView mTopHandle;
private ImageView mBottomHandle;
private static final int SNAP_DURATION = 150;
private static final float DIMMED_HANDLE_ALPHA = 0f;
private static final float RESIZE_THRESHOLD = 0.66f;
private static Rect sTmpRect = new Rect();
private final Launcher mLauncher;
private final LauncherAppWidgetHostView mWidgetView;
private final CellLayout mCellLayout;
private final DragLayer mDragLayer;
private final ImageView mLeftHandle;
private final ImageView mRightHandle;
private final ImageView mTopHandle;
private final ImageView mBottomHandle;
private final Rect mWidgetPadding;
private final int mBackgroundPadding;
private final int mTouchTargetWidth;
private final int[] mDirectionVector = new int[2];
private final int[] mLastDirectionVector = new int[2];
private final int[] mTmpPt = new int[2];
private boolean mLeftBorderActive;
private boolean mRightBorderActive;
private boolean mTopBorderActive;
private boolean mBottomBorderActive;
private int mWidgetPaddingLeft;
private int mWidgetPaddingRight;
private int mWidgetPaddingTop;
private int mWidgetPaddingBottom;
private int mBaselineWidth;
private int mBaselineHeight;
private int mBaselineX;
@@ -48,30 +60,9 @@ public class AppWidgetResizeFrame extends FrameLayout {
private int mDeltaXAddOn;
private int mDeltaYAddOn;
private int mBackgroundPadding;
private int mTouchTargetWidth;
private int mTopTouchRegionAdjustment = 0;
private int mBottomTouchRegionAdjustment = 0;
int[] mDirectionVector = new int[2];
int[] mLastDirectionVector = new int[2];
int[] mTmpPt = new int[2];
final int SNAP_DURATION = 150;
final int BACKGROUND_PADDING = 24;
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;
public static final int BOTTOM = 3;
private Launcher mLauncher;
public AppWidgetResizeFrame(Context context,
LauncherAppWidgetHostView widgetView, CellLayout cellLayout, DragLayer dragLayer) {
@@ -87,49 +78,49 @@ public class AppWidgetResizeFrame extends FrameLayout {
mMinHSpan = info.minSpanX;
mMinVSpan = info.minSpanY;
setBackgroundResource(R.drawable.widget_resize_frame_holo);
setBackgroundResource(R.drawable.widget_resize_shadow);
setForeground(getResources().getDrawable(R.drawable.widget_resize_frame));
setPadding(0, 0, 0, 0);
final int handleMargin = getResources().getDimensionPixelSize(R.dimen.widget_handle_margin);
LayoutParams lp;
mLeftHandle = new ImageView(context);
mLeftHandle.setImageResource(R.drawable.widget_resize_handle_left);
lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
mLeftHandle.setImageResource(R.drawable.ic_widget_resize_handle);
lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
Gravity.LEFT | Gravity.CENTER_VERTICAL);
lp.leftMargin = handleMargin;
addView(mLeftHandle, lp);
mRightHandle = new ImageView(context);
mRightHandle.setImageResource(R.drawable.widget_resize_handle_right);
lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
mRightHandle.setImageResource(R.drawable.ic_widget_resize_handle);
lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
Gravity.RIGHT | Gravity.CENTER_VERTICAL);
lp.rightMargin = handleMargin;
addView(mRightHandle, lp);
mTopHandle = new ImageView(context);
mTopHandle.setImageResource(R.drawable.widget_resize_handle_top);
lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
mTopHandle.setImageResource(R.drawable.ic_widget_resize_handle);
lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
Gravity.CENTER_HORIZONTAL | Gravity.TOP);
lp.topMargin = handleMargin;
addView(mTopHandle, lp);
mBottomHandle = new ImageView(context);
mBottomHandle.setImageResource(R.drawable.widget_resize_handle_bottom);
lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
mBottomHandle.setImageResource(R.drawable.ic_widget_resize_handle);
lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
lp.bottomMargin = handleMargin;
addView(mBottomHandle, lp);
Rect p = new Rect(0, 0, 0, 0);
if (!info.isCustomWidget) {
p = AppWidgetHostView.getDefaultPaddingForWidget(context,
mWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context,
widgetView.getAppWidgetInfo().provider, null);
} else {
Resources r = context.getResources();
int padding = r.getDimensionPixelSize(R.dimen.default_widget_padding);
p.set(padding, padding, padding, padding);
mWidgetPadding = new Rect(padding, padding, padding, padding);
}
mWidgetPaddingLeft = p.left;
mWidgetPaddingTop = p.top;
mWidgetPaddingRight = p.right;
mWidgetPaddingBottom = p.bottom;
if (mResizeMode == AppWidgetProviderInfo.RESIZE_HORIZONTAL) {
mTopHandle.setVisibility(GONE);
mBottomHandle.setVisibility(GONE);
@@ -138,8 +129,8 @@ public class AppWidgetResizeFrame extends FrameLayout {
mRightHandle.setVisibility(GONE);
}
final float density = mLauncher.getResources().getDisplayMetrics().density;
mBackgroundPadding = (int) Math.ceil(density * BACKGROUND_PADDING);
mBackgroundPadding = getResources()
.getDimensionPixelSize(R.dimen.resize_frame_background_padding);
mTouchTargetWidth = 2 * mBackgroundPadding;
// When we create the resize frame, we first mark all cells as unoccupied. The appropriate
@@ -344,9 +335,9 @@ 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);
getWidgetSizeRanges(launcher, spanX, spanY, sTmpRect);
widgetView.updateAppWidgetSize(null, sTmpRect.left, sTmpRect.top,
sTmpRect.right, sTmpRect.bottom);
}
public static Rect getWidgetSizeRanges(Launcher launcher, int spanX, int spanY, Rect rect) {
@@ -404,19 +395,19 @@ public class AppWidgetResizeFrame extends FrameLayout {
public void snapToWidget(boolean animate) {
final DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
int newWidth = mWidgetView.getWidth() + 2 * mBackgroundPadding - mWidgetPaddingLeft -
mWidgetPaddingRight;
int newHeight = mWidgetView.getHeight() + 2 * mBackgroundPadding - mWidgetPaddingTop -
mWidgetPaddingBottom;
int newWidth = mWidgetView.getWidth() + 2 * mBackgroundPadding
- mWidgetPadding.left - mWidgetPadding.right;
int newHeight = mWidgetView.getHeight() + 2 * mBackgroundPadding
- mWidgetPadding.top - mWidgetPadding.bottom;
mTmpPt[0] = mWidgetView.getLeft();
mTmpPt[1] = mWidgetView.getTop();
mDragLayer.getDescendantCoordRelativeToSelf(mCellLayout.getShortcutsAndWidgets(), mTmpPt);
int newX = mTmpPt[0] - mBackgroundPadding + mWidgetPaddingLeft;
int newY = mTmpPt[1] - mBackgroundPadding + mWidgetPaddingTop;
int newX = mTmpPt[0] - mBackgroundPadding + mWidgetPadding.left;
int newY = mTmpPt[1] - mBackgroundPadding + mWidgetPadding.top;
// We need to make sure the frame's touchable regions lie fully within the bounds of the
// We need to make sure the frame's touchable regions lie fully within the bounds of the
// DragLayer. We allow the actual handles to be clipped, but we shift the touch regions
// down accordingly to provide a proper touch target.
if (newY < 0) {