Tightening up the widget resize frame to account for widget padding

-> This wasn't possible before as we weren't enforcing the padding,
   but now that we are we can make the resizing look better

Change-Id: I7b74eee052beaee0cc12f4cec0505af9c214d012
This commit is contained in:
Adam Cohen
2011-06-13 17:13:42 -07:00
parent 61fa4197c4
commit 37b59ff9aa

View File

@@ -7,6 +7,7 @@ import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.appwidget.AppWidgetProviderInfo;
import android.content.Context;
import android.content.res.Resources;
import android.view.Gravity;
import android.widget.FrameLayout;
import android.widget.ImageView;
@@ -30,6 +31,11 @@ public class AppWidgetResizeFrame extends FrameLayout {
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;
@@ -103,6 +109,12 @@ public class AppWidgetResizeFrame extends FrameLayout {
Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
addView(mBottomHandle, lp);
Resources r = context.getResources();
mWidgetPaddingLeft = r.getDimensionPixelSize(R.dimen.app_widget_padding_left);
mWidgetPaddingTop = r.getDimensionPixelSize(R.dimen.app_widget_padding_top);
mWidgetPaddingRight = r.getDimensionPixelSize(R.dimen.app_widget_padding_right);
mWidgetPaddingBottom = r.getDimensionPixelSize(R.dimen.app_widget_padding_bottom);
if (mResizeMode == AppWidgetProviderInfo.RESIZE_HORIZONTAL) {
mTopHandle.setVisibility(GONE);
mBottomHandle.setVisibility(GONE);
@@ -294,10 +306,13 @@ public class AppWidgetResizeFrame extends FrameLayout {
int xOffset = mCellLayout.getLeft() + mCellLayout.getLeftPadding() - mWorkspace.getScrollX();
int yOffset = mCellLayout.getTop() + mCellLayout.getTopPadding() - mWorkspace.getScrollY();
int newWidth = mWidgetView.getWidth() + 2 * mBackgroundPadding;
int newHeight = mWidgetView.getHeight() + 2 * mBackgroundPadding;
int newX = mWidgetView.getLeft() - mBackgroundPadding + xOffset;
int newY = mWidgetView.getTop() - mBackgroundPadding + yOffset;
int newWidth = mWidgetView.getWidth() + 2 * mBackgroundPadding - mWidgetPaddingLeft -
mWidgetPaddingRight;
int newHeight = mWidgetView.getHeight() + 2 * mBackgroundPadding - mWidgetPaddingTop -
mWidgetPaddingBottom;
int newX = mWidgetView.getLeft() - mBackgroundPadding + xOffset + mWidgetPaddingLeft;
int newY = mWidgetView.getTop() - mBackgroundPadding + yOffset + mWidgetPaddingTop;
// We need to make sure the frame stays within the bounds of the CellLayout
if (newY < 0) {