Merge "Fix widget update to properly refresh."

This commit is contained in:
Ben Komalo 2011-10-17 10:30:51 -07:00 committed by Android (Google) Code Review
commit 30b49a0098
3 changed files with 44 additions and 24 deletions

View File

@ -16,11 +16,6 @@
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.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
@ -29,6 +24,11 @@ import android.content.Intent;
import android.util.Log;
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.PrintWriter;
@ -56,7 +56,7 @@ public class WidgetProvider extends AppWidgetProvider {
Log.d(EmailWidget.TAG, "onUpdate");
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
WidgetManager.getInstance().createWidgets(context, appWidgetIds);
WidgetManager.getInstance().updateWidgets(context, appWidgetIds);
}
@Override

View File

@ -16,19 +16,6 @@
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.appwidget.AppWidgetManager;
import android.content.Context;
@ -53,6 +40,19 @@ import android.view.View;
import android.widget.RemoteViews;
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;
/**
@ -171,6 +171,14 @@ public class EmailWidget implements RemoteViewsService.RemoteViewsFactory,
mLoader.load(mAccountId, mailboxId);
}
/**
* Resets the data in the widget and forces a reload.
*/
public void reset() {
mLoader.reset();
start();
}
private boolean isCursorValid() {
return mCursor != null && !mCursor.isClosed();
}

View File

@ -16,15 +16,15 @@
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.emailcommon.Logging;
import com.android.emailcommon.provider.Account;
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.PrintWriter;
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) {
EmailWidget widget = WidgetManager.getInstance().get(widgetId);
if (widget == null) {
@ -76,7 +88,7 @@ public class WidgetManager {
Log.d(EmailWidget.TAG, "Create email widget; ID: " + widgetId);
}
widget = new EmailWidget(context, widgetId);
WidgetManager.getInstance().put(widgetId, widget);
put(widgetId, widget);
widget.start();
}
return widget;