@Override public void onDeleted(Context context, int[] appWidgetIds) { Log.d(TAG, "onDeleted"); // When the user deletes the widget, delete the preference associated with it. final int N = appWidgetIds.length; for (int i=0; i<N; i++) { ExampleAppWidgetConfigure.deleteTitlePref(context, appWidgetIds[i]); } }
@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)); }
public void onClick(View v) { final Context context = ExampleAppWidgetConfigure.this; // When the button is clicked, save the string in our prefs and return that they // clicked OK. String titlePrefix = mAppWidgetPrefix.getText().toString(); saveTitlePref(context, mAppWidgetId, titlePrefix); // Push widget update to surface with newly set prefix AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); ExampleAppWidgetProvider.updateAppWidget(context, appWidgetManager, mAppWidgetId, titlePrefix); // Make sure we pass back the original appWidgetId Intent resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); setResult(RESULT_OK, resultValue); finish(); } };
@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 onReceive(Context context, Intent intent) { Log.d("ExmampleBroadcastReceiver", "intent=" + intent); // For our example, we'll also update all of the widgets when the timezone // changes, or the user or network sets the time. String action = intent.getAction(); if (action.equals(Intent.ACTION_TIMEZONE_CHANGED) || action.equals(Intent.ACTION_TIME_CHANGED)) { AppWidgetManager gm = AppWidgetManager.getInstance(context); ArrayList<Integer> appWidgetIds = new ArrayList<Integer>(); ArrayList<String> texts = new ArrayList<String>(); ExampleAppWidgetConfigure.loadAllTitlePrefs(context, appWidgetIds, texts); final int N = appWidgetIds.size(); for (int i=0; i<N; i++) { ExampleAppWidgetProvider.updateAppWidget(context, gm, appWidgetIds.get(i), texts.get(i)); } } }
public void onClick(View v) { final Context context = ExampleAppWidgetConfigure.this; // When the button is clicked, save the string in our prefs and return that they // clicked OK. String titlePrefix = mAppWidgetPrefix.getText().toString(); saveTitlePref(context, mAppWidgetId, titlePrefix); // Push widget update to surface with newly set prefix AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); ExampleAppWidgetProvider.updateAppWidget(context, appWidgetManager, mAppWidgetId, titlePrefix); // Make sure we pass back the original appWidgetId Intent resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); setResult(RESULT_OK, resultValue); finish(); } };
@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 onReceive(Context context, Intent intent) { Log.d("ExmampleBroadcastReceiver", "intent=" + intent); // For our example, we'll also update all of the widgets when the timezone // changes, or the user or network sets the time. String action = intent.getAction(); if (action.equals(Intent.ACTION_TIMEZONE_CHANGED) || action.equals(Intent.ACTION_TIME_CHANGED)) { AppWidgetManager gm = AppWidgetManager.getInstance(context); ArrayList<Integer> appWidgetIds = new ArrayList<>(); ArrayList<String> texts = new ArrayList<>(); ExampleAppWidgetConfigure.loadAllTitlePrefs(context, appWidgetIds, texts); final int N = appWidgetIds.size(); for (int i=0; i<N; i++) { ExampleAppWidgetProvider.updateAppWidget(context, gm, appWidgetIds.get(i), texts.get(i)); } } }
@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)); }
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 onDeleted(Context context, int[] appWidgetIds) { Log.d(TAG, "onDeleted"); // When the user deletes the widget, delete the preference associated with it. final int N = appWidgetIds.length; for (int i=0; i<N; i++) { ExampleAppWidgetConfigure.deleteTitlePref(context, appWidgetIds[i]); } }
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); } }