Roll NDK to pick std::deque patch.
[android_tools.git] / sdk / tools / templates / other / AppWidget / root / src / app_package / AppWidget.java.ftl
blob60a1e08fa17494afff14ccd53325797b740f1211
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>
9 /**
10  * Implementation of App Widget functionality.
11 <#if configurable>
12  * App Widget Configuration implemented in {@link ${className}ConfigureActivity ${className}ConfigureActivity}
13 </#if>
14  */
15 public class ${className} extends AppWidgetProvider {
17     @Override
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]);
23         }
24     }
26 <#if configurable>
27     @Override
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]);
33         }
34     }
35 </#if>
37     @Override
38     public void onEnabled(Context context) {
39         // Enter relevant functionality for when the first widget is created
40     }
42     @Override
43     public void onDisabled(Context context) {
44         // Enter relevant functionality for when the last widget is disabled
45     }
47     static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
48             int appWidgetId) {
50 <#if configurable>
51         CharSequence widgetText = ${className}ConfigureActivity.loadTitlePref(context, appWidgetId);
52 <#else>
53         CharSequence widgetText = context.getString(R.string.appwidget_text);
54 </#if>
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);
61     }