Fix widget update to properly refresh.

Bug: 5413224
Change-Id: Id66c7dc8aac8b5e24c7d5c5b1633c9c3ab981b15
This commit is contained in:
Ben Komalo 2011-10-14 14:33:27 -07:00
parent 1f6769facc
commit 561004883d
3 changed files with 44 additions and 24 deletions

View File

@ -16,11 +16,6 @@
package com.android.email.provider; package com.android.email.provider;
import com.android.email.Email;
import com.android.email.widget.EmailWidget;
import com.android.email.widget.WidgetManager;
import com.android.emailcommon.Logging;
import android.app.Service; import android.app.Service;
import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider; import android.appwidget.AppWidgetProvider;
@ -29,6 +24,11 @@ import android.content.Intent;
import android.util.Log; import android.util.Log;
import android.widget.RemoteViewsService; import android.widget.RemoteViewsService;
import com.android.email.Email;
import com.android.email.widget.EmailWidget;
import com.android.email.widget.WidgetManager;
import com.android.emailcommon.Logging;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.PrintWriter; import java.io.PrintWriter;
@ -56,7 +56,7 @@ public class WidgetProvider extends AppWidgetProvider {
Log.d(EmailWidget.TAG, "onUpdate"); Log.d(EmailWidget.TAG, "onUpdate");
} }
super.onUpdate(context, appWidgetManager, appWidgetIds); super.onUpdate(context, appWidgetManager, appWidgetIds);
WidgetManager.getInstance().createWidgets(context, appWidgetIds); WidgetManager.getInstance().updateWidgets(context, appWidgetIds);
} }
@Override @Override

View File

@ -16,19 +16,6 @@
package com.android.email.widget; package com.android.email.widget;
import com.android.email.Email;
import com.android.email.R;
import com.android.email.ResourceHelper;
import com.android.email.activity.MessageCompose;
import com.android.email.activity.UiUtilities;
import com.android.email.activity.Welcome;
import com.android.email.provider.WidgetProvider.WidgetService;
import com.android.emailcommon.Logging;
import com.android.emailcommon.provider.Account;
import com.android.emailcommon.provider.EmailContent.Message;
import com.android.emailcommon.provider.Mailbox;
import com.android.emailcommon.utility.EmailAsyncTask;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetManager;
import android.content.Context; import android.content.Context;
@ -53,6 +40,19 @@ import android.view.View;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import android.widget.RemoteViewsService; import android.widget.RemoteViewsService;
import com.android.email.Email;
import com.android.email.R;
import com.android.email.ResourceHelper;
import com.android.email.activity.MessageCompose;
import com.android.email.activity.UiUtilities;
import com.android.email.activity.Welcome;
import com.android.email.provider.WidgetProvider.WidgetService;
import com.android.emailcommon.Logging;
import com.android.emailcommon.provider.Account;
import com.android.emailcommon.provider.EmailContent.Message;
import com.android.emailcommon.provider.Mailbox;
import com.android.emailcommon.utility.EmailAsyncTask;
import java.util.List; import java.util.List;
/** /**
@ -171,6 +171,14 @@ public class EmailWidget implements RemoteViewsService.RemoteViewsFactory,
mLoader.load(mAccountId, mailboxId); mLoader.load(mAccountId, mailboxId);
} }
/**
* Resets the data in the widget and forces a reload.
*/
public void reset() {
mLoader.reset();
start();
}
private boolean isCursorValid() { private boolean isCursorValid() {
return mCursor != null && !mCursor.isClosed(); return mCursor != null && !mCursor.isClosed();
} }

View File

@ -16,15 +16,15 @@
package com.android.email.widget; package com.android.email.widget;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import com.android.email.Email; import com.android.email.Email;
import com.android.emailcommon.Logging; import com.android.emailcommon.Logging;
import com.android.emailcommon.provider.Account; import com.android.emailcommon.provider.Account;
import com.android.emailcommon.provider.Mailbox; import com.android.emailcommon.provider.Mailbox;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.Map; import java.util.Map;
@ -69,6 +69,18 @@ public class WidgetManager {
} }
} }
public synchronized void updateWidgets(Context context, int[] widgetIds) {
for (int widgetId : widgetIds) {
// Find the widget in the map
final EmailWidget widget = WidgetManager.getInstance().get(widgetId);
if (widget != null) {
widget.reset();
} else {
getOrCreateWidget(context, widgetId);
}
}
}
public synchronized EmailWidget getOrCreateWidget(Context context, int widgetId) { public synchronized EmailWidget getOrCreateWidget(Context context, int widgetId) {
EmailWidget widget = WidgetManager.getInstance().get(widgetId); EmailWidget widget = WidgetManager.getInstance().get(widgetId);
if (widget == null) { if (widget == null) {
@ -76,7 +88,7 @@ public class WidgetManager {
Log.d(EmailWidget.TAG, "Create email widget; ID: " + widgetId); Log.d(EmailWidget.TAG, "Create email widget; ID: " + widgetId);
} }
widget = new EmailWidget(context, widgetId); widget = new EmailWidget(context, widgetId);
WidgetManager.getInstance().put(widgetId, widget); put(widgetId, widget);
widget.start(); widget.start();
} }
return widget; return widget;