1 package ${packageName};
3 import android.appwidget.AppWidgetManager;
4 import android.appwidget.AppWidgetProvider;
5 import android.content.Context;
6 import android.widget.RemoteViews;
7 <#if applicationPackage??>import ${applicationPackage}.R;</#if>
10 * Implementation of App Widget functionality.
12 * App Widget Configuration implemented in {@link ${className}ConfigureActivity ${className}ConfigureActivity}
15 public class ${className} extends AppWidgetProvider {
18 public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
19 // There may be multiple widgets active, so update all of them
20 final int N = appWidgetIds.length;
21 for (int i=0; i<N; i++) {
22 updateAppWidget(context, appWidgetManager, appWidgetIds[i]);
28 public void onDeleted(Context context, int[] appWidgetIds) {
29 // When the user deletes the widget, delete the preference associated with it.
30 final int N = appWidgetIds.length;
31 for (int i=0; i<N; i++) {
32 ${className}ConfigureActivity.deleteTitlePref(context, appWidgetIds[i]);
38 public void onEnabled(Context context) {
39 // Enter relevant functionality for when the first widget is created
43 public void onDisabled(Context context) {
44 // Enter relevant functionality for when the last widget is disabled
47 static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
51 CharSequence widgetText = ${className}ConfigureActivity.loadTitlePref(context, appWidgetId);
53 CharSequence widgetText = context.getString(R.string.appwidget_text);
55 // Construct the RemoteViews object
56 RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.${class_name});
57 views.setTextViewText(R.id.appwidget_text, widgetText);
59 // Instruct the widget manager to update the widget
60 appWidgetManager.updateAppWidget(appWidgetId, views);