Files
lawnchair/src/com/android/launcher3/PendingAppWidgetHostView.java
Sunny Goyal ff57227711 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
2014-08-08 14:29:02 -07:00

79 lines
2.2 KiB
Java

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;
}
}