summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/PendingAppWidgetHostView.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2014-08-27 14:04:33 -0700
committerSunny Goyal <sunnygoyal@google.com>2014-08-27 14:07:05 -0700
commite7b8cd9e4f8d38d0445f3a032fafd44332f70878 (patch)
treebb9107583e21133d9912b49b83af2e69052a21a7 /src/com/android/launcher3/PendingAppWidgetHostView.java
parent424418bb50ccf5d9270650b70cc51f423da51a65 (diff)
downloadandroid_packages_apps_Trebuchet-e7b8cd9e4f8d38d0445f3a032fafd44332f70878.tar.gz
android_packages_apps_Trebuchet-e7b8cd9e4f8d38d0445f3a032fafd44332f70878.tar.bz2
android_packages_apps_Trebuchet-e7b8cd9e4f8d38d0445f3a032fafd44332f70878.zip
Improving restored widget behavior
> Clicking a broken widget install shows a dialog similar to an app icon > Clicking remove on the dialog removed all components for the corresponding package > Widget pending view shows 'Setup' text instead of icon, if there is enough space Change-Id: I82ec0a1ee9542c1e3b860e6e00798a80450dce3c
Diffstat (limited to 'src/com/android/launcher3/PendingAppWidgetHostView.java')
-rw-r--r--src/com/android/launcher3/PendingAppWidgetHostView.java82
1 files changed, 66 insertions, 16 deletions
diff --git a/src/com/android/launcher3/PendingAppWidgetHostView.java b/src/com/android/launcher3/PendingAppWidgetHostView.java
index 04014366c..d23a33033 100644
--- a/src/com/android/launcher3/PendingAppWidgetHostView.java
+++ b/src/com/android/launcher3/PendingAppWidgetHostView.java
@@ -24,6 +24,10 @@ import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
+import android.text.Layout;
+import android.text.StaticLayout;
+import android.text.TextPaint;
+import android.util.TypedValue;
import android.view.View;
import android.view.View.OnClickListener;
@@ -46,12 +50,19 @@ public class PendingAppWidgetHostView extends LauncherAppWidgetHostView implemen
private boolean mDrawableSizeChanged;
+ private final TextPaint mPaint;
+ private Layout mSetupTextLayout;
+
public PendingAppWidgetHostView(Context context, LauncherAppWidgetInfo info) {
super(context);
mInfo = info;
mStartState = info.restoreStatus;
mIconLookupIntent = new Intent().setComponent(info.providerName);
+ mPaint = new TextPaint();
+ mPaint.setColor(0xFFFFFFFF);
+ mPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX,
+ getDeviceProfile().iconTextSizePx, getResources().getDisplayMetrics()));
setBackgroundResource(R.drawable.quantum_panel_dark);
setWillNotDraw(false);
}
@@ -127,7 +138,7 @@ public class PendingAppWidgetHostView extends LauncherAppWidgetHostView implemen
public void applyState() {
if (mDrawable != null) {
- mDrawable.setLevel(mInfo.installProgress);
+ mDrawable.setLevel(Math.max(mInfo.installProgress, 0));
}
}
@@ -165,27 +176,66 @@ public class PendingAppWidgetHostView extends LauncherAppWidgetHostView implemen
mDrawable.draw(canvas);
} else if ((mCenterDrawable != null) && (mTopCornerDrawable != null)) {
if (mDrawableSizeChanged) {
- int iconSize = getResources().getDimensionPixelSize(R.dimen.app_icon_size);
+ DeviceProfile grid = getDeviceProfile();
+ int iconSize = grid.iconSizePx;
int paddingTop = getPaddingTop();
+ int paddingBottom = getPaddingBottom();
int paddingLeft = getPaddingLeft();
-
- int size = Math.min(iconSize, Math.min(
- getWidth() - paddingLeft - getPaddingRight(),
- getHeight() - paddingTop - getPaddingBottom()));
- mRect.set(0, 0, size, size);
- mRect.offsetTo((getWidth() - mRect.width()) / 2, (getHeight() - mRect.height()) / 2);
- mCenterDrawable.setBounds(mRect);
-
- size = Math.min(size / 2,
- Math.max(mRect.top - paddingTop, mRect.left - paddingLeft));
- mTopCornerDrawable.setBounds(paddingLeft, paddingTop,
- paddingLeft + size, paddingTop + size);
+ int paddingRight = getPaddingRight();
+
+ int availableWidth = getWidth() - paddingLeft - paddingRight;
+ int availableHeight = getHeight() - paddingTop - paddingBottom;
+
+ // Recreate the setup text.
+ mSetupTextLayout = new StaticLayout(
+ getResources().getText(R.string.gadget_setup_text), mPaint, availableWidth,
+ Layout.Alignment.ALIGN_CENTER, 1, 0, true);
+ if (mSetupTextLayout.getLineCount() == 1) {
+ // The text fits in a single line. No need to draw the setup icon.
+ int size = Math.min(iconSize, Math.min(availableWidth,
+ availableHeight - mSetupTextLayout.getHeight()));
+ mRect.set(0, 0, size, size);
+ mRect.offsetTo((getWidth() - mRect.width()) / 2,
+ (getHeight() - mRect.height() - mSetupTextLayout.getHeight()
+ - grid.iconDrawablePaddingPx) / 2);
+
+ mTopCornerDrawable.setBounds(mRect);
+
+ // Update left and top to indicate the position where the text will be drawn.
+ mRect.left = paddingLeft;
+ mRect.top = mRect.bottom + grid.iconDrawablePaddingPx;
+ } else {
+ // The text can't be drawn in a single line. Draw a setup icon instead.
+ mSetupTextLayout = null;
+ int size = Math.min(iconSize, Math.min(
+ getWidth() - paddingLeft - paddingRight,
+ getHeight() - paddingTop - paddingBottom));
+ mRect.set(0, 0, size, size);
+ mRect.offsetTo((getWidth() - mRect.width()) / 2, (getHeight() - mRect.height()) / 2);
+ mCenterDrawable.setBounds(mRect);
+
+ size = Math.min(size / 2,
+ Math.max(mRect.top - paddingTop, mRect.left - paddingLeft));
+ mTopCornerDrawable.setBounds(paddingLeft, paddingTop,
+ paddingLeft + size, paddingTop + size);
+ }
mDrawableSizeChanged = false;
}
- mCenterDrawable.draw(canvas);
- mTopCornerDrawable.draw(canvas);
+ if (mSetupTextLayout == null) {
+ mCenterDrawable.draw(canvas);
+ mTopCornerDrawable.draw(canvas);
+ } else {
+ canvas.save();
+ canvas.translate(mRect.left, mRect.top);
+ mSetupTextLayout.draw(canvas);
+ canvas.restore();
+ mTopCornerDrawable.draw(canvas);
+ }
}
}
+ private DeviceProfile getDeviceProfile() {
+ return LauncherAppState.getInstance().getDynamicGrid().getDeviceProfile();
+ }
}