summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/PendingAppWidgetHostView.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2014-08-11 17:05:23 -0700
committerSunny Goyal <sunnygoyal@google.com>2014-08-12 16:00:03 -0700
commit0fc1be164e982433e619bcbb16aa67e28ff681ef (patch)
treeb72e41365906b7619407950d41375afb6eed5dc3 /src/com/android/launcher3/PendingAppWidgetHostView.java
parent0fe505bf82a265e51c556d7204976651cde7f55c (diff)
downloadandroid_packages_apps_Trebuchet-0fc1be164e982433e619bcbb16aa67e28ff681ef.tar.gz
android_packages_apps_Trebuchet-0fc1be164e982433e619bcbb16aa67e28ff681ef.tar.bz2
android_packages_apps_Trebuchet-0fc1be164e982433e619bcbb16aa67e28ff681ef.zip
Updating the ui for widget restore flow
> Pending widget show a PreloadIconDrawable to indicate installation progress > Only the concerned widgets are reinflated on package install and not the whole workspace. > Adding support for storing default package icon in IconCache issue: 10779035 issue: 16737660 Change-Id: Id787ae4a5ef72d6e01aeb5a1bae5ab8840037679
Diffstat (limited to 'src/com/android/launcher3/PendingAppWidgetHostView.java')
-rw-r--r--src/com/android/launcher3/PendingAppWidgetHostView.java153
1 files changed, 133 insertions, 20 deletions
diff --git a/src/com/android/launcher3/PendingAppWidgetHostView.java b/src/com/android/launcher3/PendingAppWidgetHostView.java
index 048e9f8c3..04014366c 100644
--- a/src/com/android/launcher3/PendingAppWidgetHostView.java
+++ b/src/com/android/launcher3/PendingAppWidgetHostView.java
@@ -1,21 +1,59 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package com.android.launcher3;
import android.content.Context;
+import android.content.Intent;
+import android.content.res.Resources.Theme;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Rect;
+import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
-import android.widget.TextView;
public class PendingAppWidgetHostView extends LauncherAppWidgetHostView implements OnClickListener {
- int mRestoreStatus;
+ private static Theme sPreloaderTheme;
- private TextView mDefaultView;
+ private final Rect mRect = new Rect();
+ private View mDefaultView;
private OnClickListener mClickListener;
+ private final LauncherAppWidgetInfo mInfo;
+ private final int mStartState;
+ private final Intent mIconLookupIntent;
+
+ private Bitmap mIcon;
+ private PreloadIconDrawable mDrawable;
+
+ private Drawable mCenterDrawable;
+ private Drawable mTopCornerDrawable;
+
+ private boolean mDrawableSizeChanged;
- public PendingAppWidgetHostView(Context context, int restoreStatus) {
+ public PendingAppWidgetHostView(Context context, LauncherAppWidgetInfo info) {
super(context);
- mRestoreStatus = restoreStatus;
+ mInfo = info;
+ mStartState = info.restoreStatus;
+ mIconLookupIntent = new Intent().setComponent(info.providerName);
+
+ setBackgroundResource(R.drawable.quantum_panel_dark);
+ setWillNotDraw(false);
}
@Override
@@ -27,7 +65,7 @@ public class PendingAppWidgetHostView extends LauncherAppWidgetHostView implemen
@Override
protected View getDefaultView() {
if (mDefaultView == null) {
- mDefaultView = (TextView) mInflater.inflate(R.layout.appwidget_not_ready, this, false);
+ mDefaultView = mInflater.inflate(R.layout.appwidget_not_ready, this, false);
mDefaultView.setOnClickListener(this);
applyState();
}
@@ -39,26 +77,57 @@ public class PendingAppWidgetHostView extends LauncherAppWidgetHostView implemen
mClickListener = l;
}
- public void setStatus(int status) {
- if (mRestoreStatus != status) {
- mRestoreStatus = status;
- applyState();
- }
+ @Override
+ public boolean isReinflateRequired() {
+ // Re inflate is required any time the widget restore status changes
+ return mStartState != mInfo.restoreStatus;
}
@Override
- public boolean isReinflateRequired() {
- // Re inflate is required if the the widget is restored.
- return mRestoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED;
+ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+ super.onSizeChanged(w, h, oldw, oldh);
+ mDrawableSizeChanged = true;
}
- private void applyState() {
- if (mDefaultView != null) {
+ public void updateIcon(IconCache cache) {
+ Bitmap icon = cache.getIcon(mIconLookupIntent, mInfo.user);
+ if (mIcon == icon) {
+ return;
+ }
+ mIcon = icon;
+ if (mDrawable != null) {
+ mDrawable.setCallback(null);
+ mDrawable = null;
+ }
+ if (mIcon != null) {
+ // The view displays two modes, one with a setup icon and another with a preload icon
+ // in the center.
if (isReadyForClickSetup()) {
- mDefaultView.setText(R.string.gadget_setup_text);
+ mCenterDrawable = getResources().getDrawable(R.drawable.ic_setting);
+ mTopCornerDrawable = new FastBitmapDrawable(mIcon);
} else {
- mDefaultView.setText(R.string.gadget_pending_text);
+ if (sPreloaderTheme == null) {
+ sPreloaderTheme = getResources().newTheme();
+ sPreloaderTheme.applyStyle(R.style.PreloadIcon, true);
+ }
+
+ FastBitmapDrawable drawable = Utilities.createIconDrawable(mIcon);
+ mDrawable = new PreloadIconDrawable(drawable, sPreloaderTheme);
+ mDrawable.setCallback(this);
+ applyState();
}
+ mDrawableSizeChanged = true;
+ }
+ }
+
+ @Override
+ protected boolean verifyDrawable(Drawable who) {
+ return (who == mDrawable) || super.verifyDrawable(who);
+ }
+
+ public void applyState() {
+ if (mDrawable != null) {
+ mDrawable.setLevel(mInfo.installProgress);
}
}
@@ -72,7 +141,51 @@ public class PendingAppWidgetHostView extends LauncherAppWidgetHostView implemen
}
public boolean isReadyForClickSetup() {
- return (mRestoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0
- && (mRestoreStatus & LauncherAppWidgetInfo.FLAG_UI_NOT_READY) != 0;
+ return (mInfo.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0
+ && (mInfo.restoreStatus & LauncherAppWidgetInfo.FLAG_UI_NOT_READY) != 0;
}
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ if (mDrawable != null) {
+ if (mDrawableSizeChanged) {
+ int maxSize = LauncherAppState.getInstance().getDynamicGrid()
+ .getDeviceProfile().iconSizePx + 2 * mDrawable.getOutset();
+ int size = Math.min(maxSize, Math.min(
+ getWidth() - getPaddingLeft() - getPaddingRight(),
+ getHeight() - getPaddingTop() - getPaddingBottom()));
+
+ mRect.set(0, 0, size, size);
+ mRect.inset(mDrawable.getOutset(), mDrawable.getOutset());
+ mRect.offsetTo((getWidth() - mRect.width()) / 2, (getHeight() - mRect.height()) / 2);
+ mDrawable.setBounds(mRect);
+ mDrawableSizeChanged = false;
+ }
+
+ mDrawable.draw(canvas);
+ } else if ((mCenterDrawable != null) && (mTopCornerDrawable != null)) {
+ if (mDrawableSizeChanged) {
+ int iconSize = getResources().getDimensionPixelSize(R.dimen.app_icon_size);
+ int paddingTop = getPaddingTop();
+ 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);
+ mDrawableSizeChanged = false;
+ }
+
+ mCenterDrawable.draw(canvas);
+ mTopCornerDrawable.draw(canvas);
+ }
+ }
+
}