diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2014-07-23 13:58:07 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2014-08-08 14:29:02 -0700 |
commit | ff572277112ec3d6a6a8c1be274d6fa1019e3648 (patch) | |
tree | 85212d0b7f7b217beb80892917ea88a7ac180947 /src/com/android/launcher3/PendingAppWidgetHostView.java | |
parent | 6075170b838bfe7a040bbff25c2c22859b7d6ee5 (diff) | |
download | android_packages_apps_Trebuchet-ff572277112ec3d6a6a8c1be274d6fa1019e3648.tar.gz android_packages_apps_Trebuchet-ff572277112ec3d6a6a8c1be274d6fa1019e3648.tar.bz2 android_packages_apps_Trebuchet-ff572277112ec3d6a6a8c1be274d6fa1019e3648.zip |
Adding support to restore widgets even for jelly beans.
> Show 'widget-not-ready' until the widget app is installed
> Once the app is installed, bind a new widget id (not required on L if
id-remap was received).
**Remove the widget if bind failed
> If the widget has no configuration screen, show the widget, otherwise
show 'setup-widget'.
> Clicking 'setup-widget' shows the config screen, and updates the
widget on RESULT_OK.
issue: 10779035
Change-Id: I2f8b06d09dd6acbc498cdd93edc59c26e5ce17af
Diffstat (limited to 'src/com/android/launcher3/PendingAppWidgetHostView.java')
-rw-r--r-- | src/com/android/launcher3/PendingAppWidgetHostView.java | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/com/android/launcher3/PendingAppWidgetHostView.java b/src/com/android/launcher3/PendingAppWidgetHostView.java new file mode 100644 index 000000000..048e9f8c3 --- /dev/null +++ b/src/com/android/launcher3/PendingAppWidgetHostView.java @@ -0,0 +1,78 @@ +package com.android.launcher3; + +import android.content.Context; +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 TextView mDefaultView; + private OnClickListener mClickListener; + + public PendingAppWidgetHostView(Context context, int restoreStatus) { + super(context); + mRestoreStatus = restoreStatus; + } + + @Override + public void updateAppWidgetSize(Bundle newOptions, int minWidth, int minHeight, int maxWidth, + int maxHeight) { + // No-op + } + + @Override + protected View getDefaultView() { + if (mDefaultView == null) { + mDefaultView = (TextView) mInflater.inflate(R.layout.appwidget_not_ready, this, false); + mDefaultView.setOnClickListener(this); + applyState(); + } + return mDefaultView; + } + + @Override + public void setOnClickListener(OnClickListener l) { + mClickListener = l; + } + + public void setStatus(int status) { + if (mRestoreStatus != status) { + mRestoreStatus = status; + applyState(); + } + } + + @Override + public boolean isReinflateRequired() { + // Re inflate is required if the the widget is restored. + return mRestoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED; + } + + private void applyState() { + if (mDefaultView != null) { + if (isReadyForClickSetup()) { + mDefaultView.setText(R.string.gadget_setup_text); + } else { + mDefaultView.setText(R.string.gadget_pending_text); + } + } + } + + @Override + public void onClick(View v) { + // AppWidgetHostView blocks all click events on the root view. Instead handle click events + // on the content and pass it along. + if (mClickListener != null) { + mClickListener.onClick(this); + } + } + + public boolean isReadyForClickSetup() { + return (mRestoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0 + && (mRestoreStatus & LauncherAppWidgetInfo.FLAG_UI_NOT_READY) != 0; + } +} |