@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { Log.d(TAG, "onUpdate"); // For each widget that needs an update, get the text that we should display: // - Create a RemoteViews object for it // - Set the text in the RemoteViews object // - Tell the AppWidgetManager to show that views object for the widget. final int N = appWidgetIds.length; for (int i=0; i<N; i++) { int appWidgetId = appWidgetIds[i]; String titlePrefix = ExampleAppWidgetConfigure.loadTitlePref(context, appWidgetId); updateAppWidget(context, appWidgetManager, appWidgetId, titlePrefix); } }
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { Log.d(TAG, "onUpdate"); // For each widget that needs an update, get the text that we should display: // - Create a RemoteViews object for it // - Set the text in the RemoteViews object // - Tell the AppWidgetManager to show that views object for the widget. final int N = appWidgetIds.length; for (int i=0; i<N; i++) { int appWidgetId = appWidgetIds[i]; String titlePrefix = ExampleAppWidgetConfigure.loadTitlePref(context, appWidgetId); updateAppWidget(context, appWidgetManager, appWidgetId, titlePrefix); } }
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId, String titlePrefix) { Log.d(TAG, "updateAppWidget appWidgetId=" + appWidgetId + " titlePrefix=" + titlePrefix); // Getting the string this way allows the string to be localized. The format // string is filled in using java.util.Formatter-style format strings. CharSequence text = context.getString(R.string.appwidget_text_format, ExampleAppWidgetConfigure.loadTitlePref(context, appWidgetId), "0x" + Long.toHexString(SystemClock.elapsedRealtime())); // Construct the RemoteViews object. It takes the package name (in our case, it's our // package, but it needs this because on the other side it's the widget host inflating // the layout from our package). RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider); views.setTextViewText(R.id.appwidget_text, text); // Tell the widget manager appWidgetManager.updateAppWidget(appWidgetId, views); } }
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId, String titlePrefix) { Log.d(TAG, "updateAppWidget appWidgetId=" + appWidgetId + " titlePrefix=" + titlePrefix); // Getting the string this way allows the string to be localized. The format // string is filled in using java.util.Formatter-style format strings. CharSequence text = context.getString(R.string.appwidget_text_format, ExampleAppWidgetConfigure.loadTitlePref(context, appWidgetId), "0x" + Long.toHexString(SystemClock.elapsedRealtime())); // Construct the RemoteViews object. It takes the package name (in our case, it's our // package, but it needs this because on the other side it's the widget host inflating // the layout from our package). RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider); views.setTextViewText(R.id.appwidget_text, text); // Tell the widget manager appWidgetManager.updateAppWidget(appWidgetId, views); } }
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); // Set the result to CANCELED. This will cause the widget host to cancel // out of the widget placement if they press the back button. setResult(RESULT_CANCELED); // Set the view layout resource to use. setContentView(R.layout.appwidget_configure); // Find the EditText mAppWidgetPrefix = (EditText)findViewById(R.id.appwidget_prefix); // Bind the action for the save button. findViewById(R.id.save_button).setOnClickListener(mOnClickListener); // Find the widget id from the intent. Intent intent = getIntent(); Bundle extras = intent.getExtras(); if (extras != null) { mAppWidgetId = extras.getInt( AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); } // If they gave us an intent without the widget id, just bail. if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { finish(); } mAppWidgetPrefix.setText(loadTitlePref(ExampleAppWidgetConfigure.this, mAppWidgetId)); }
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); // Set the result to CANCELED. This will cause the widget host to cancel // out of the widget placement if they press the back button. setResult(RESULT_CANCELED); // Set the view layout resource to use. setContentView(R.layout.appwidget_configure); // Find the EditText mAppWidgetPrefix = (EditText)findViewById(R.id.appwidget_prefix); // Bind the action for the save button. findViewById(R.id.save_button).setOnClickListener(mOnClickListener); // Find the widget id from the intent. Intent intent = getIntent(); Bundle extras = intent.getExtras(); if (extras != null) { mAppWidgetId = extras.getInt( AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); } // If they gave us an intent without the widget id, just bail. if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { finish(); } mAppWidgetPrefix.setText(loadTitlePref(ExampleAppWidgetConfigure.this, mAppWidgetId)); }