List of usage examples for android.appwidget AppWidgetManager getAppWidgetIds
public int[] getAppWidgetIds(ComponentName provider)
From source file:com.concentriclivers.mms.com.android.mms.widget.MmsWidgetProvider.java
@Override public void onReceive(Context context, Intent intent) { // if (Log.isLoggable(LogTag.WIDGET, Log.VERBOSE)) { Log.v(TAG, "onReceive intent: " + intent); // }//from w ww .j a v a 2s . com String action = intent.getAction(); // The base class AppWidgetProvider's onReceive handles the normal widget intents. Here // we're looking for an intent sent by the messaging app when it knows a message has // been sent or received (or a conversation has been read) and is telling the widget it // needs to update. if (ACTION_NOTIFY_DATASET_CHANGED.equals(action)) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); int[] appWidgetIds = appWidgetManager .getAppWidgetIds(new ComponentName(context, MmsWidgetProvider.class)); if (appWidgetIds.length > 0) { appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds[0], R.id.conversation_list); } } else { super.onReceive(context, intent); } }
From source file:dk.cafeanalog.AnalogWidget.java
private void handleIsOpen(final Context mContext, final OpeningStatus openingStatus) { final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext); final int[] appWidgetIds = appWidgetManager .getAppWidgetIds(new ComponentName(mContext, AnalogWidget.class)); final RemoteViews views = new RemoteViews(mContext.getPackageName(), R.layout.analog_widget); views.setTextViewText(R.id.appwidget_text, mContext.getText(R.string.refreshing_analog)); views.setTextColor(R.id.appwidget_text, ContextCompat.getColor(mContext, android.R.color.primary_text_dark)); // Instruct the widget manager to update the widget for (int appWidgetId : appWidgetIds) { appWidgetManager.updateAppWidget(appWidgetId, views); }//from ww w.j a va 2s.co m CharSequence widgetText; if (openingStatus.open) { widgetText = mContext.getString(R.string.widget_open_analog); views.setTextColor(R.id.appwidget_text, ContextCompat.getColor(mContext, R.color.openColor)); } else { widgetText = mContext.getString(R.string.widget_closed_analog); views.setTextColor(R.id.appwidget_text, ContextCompat.getColor(mContext, R.color.closedColor)); } views.setTextViewText(R.id.appwidget_text, widgetText); views.setOnClickPendingIntent(R.id.appwidget_text, getPendingSelfIntent(mContext)); // Instruct the widget manager to update the widget for (int appWidgetId : appWidgetIds) { appWidgetManager.updateAppWidget(appWidgetId, views); } }
From source file:com.fbartnitzek.tasteemall.widget.StatsWidgetIntentService.java
@Override protected void onHandleIntent(Intent intent) { // Log.v(LOG_TAG, "onHandleIntent, hashCode=" + this.hashCode() + ", " + "intent = [" + intent + "]"); // get all widget ids AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this); int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(this, StatsWidgetProvider.class)); // query all entities int numLocations = queryAndGetCount(DatabaseContract.LocationEntry.CONTENT_URI, QueryColumns.Widget.LocationQuery.COLUMNS); int numProducers = queryAndGetCount(DatabaseContract.ProducerEntry.CONTENT_URI, QueryColumns.Widget.ProviderQuery.COLUMNS); int numDrinks = queryAndGetCount(DatabaseContract.DrinkEntry.CONTENT_URI, QueryColumns.Widget.DrinkQuery.COLUMNS); int numUsers = queryAndGetCount(DatabaseContract.UserEntry.CONTENT_URI, QueryColumns.Widget.UserQuery.COLUMNS); int numReviews = queryAndGetCount(DatabaseContract.ReviewEntry.CONTENT_URI, QueryColumns.Widget.ReviewQuery.COLUMNS); // TODO: results are getting "cached" or something like that ... // maybe that helps: http://stackoverflow.com/questions/9497270/widget-with-content-provider-impossible-to-use-readpermission Log.v(LOG_TAG,/*from w w w.jav a 2 s . c om*/ "onHandleIntent, producer=" + numProducers + ", drinks=" + numDrinks + ", reviews=" + numReviews); for (int appWidgetId : appWidgetIds) { // dynamically adapt widget width ... later RemoteViews views = new RemoteViews(getPackageName(), R.layout.info_widget); // fill stats views.setTextViewText(R.id.stats_locations, getString(R.string.widget_statistics_locations, numLocations)); views.setTextViewText(R.id.stats_producers, getString(R.string.widget_statistics_producers, numProducers)); views.setTextViewText(R.id.stats_drinks, getString(R.string.widget_statistics_drinks, numDrinks)); views.setTextViewText(R.id.stats_users, getString(R.string.widget_statistics_users, numUsers)); views.setTextViewText(R.id.stats_reviews, getString(R.string.widget_statistics_reviews, numReviews)); // seems to be impossible to get contentDescription for whole widget... // views.setContentDescription(R.id.widget_layout, // getString(R.string.a11y_widget_statistics_all, numProducers, numDrinks, numReviews)); views.setContentDescription(R.id.stats_reviews, getString(R.string.a11y_widget_statistics_all, numProducers, numDrinks, numReviews)); // set on click listener for add and search on every update (kind of useless...) // add button - create backStack for add Intent addIntent = new Intent(this, AddReviewActivity.class); PendingIntent addPendingIntent = TaskStackBuilder.create(this).addNextIntentWithParentStack(addIntent) .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.widget_add_button, addPendingIntent); // search button PendingIntent searchPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); views.setOnClickPendingIntent(R.id.widget_search_button, searchPendingIntent); // update each StatsWidget appWidgetManager.updateAppWidget(appWidgetId, views); } }
From source file:com.ravi.apps.android.newsbytes.widget.NewsWidgetProvider.java
@Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); // Get the intent action. String action = intent.getAction(); Log.d(LOG_TAG, context.getString(R.string.log_on_receive) + action); // If the widget was enabled, start the sync adapter for immediate sync. if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)) { // Initialize the sync adapter and trigger an immediate sync. NewsSyncAdapter.initializeSyncAdapter(context); NewsSyncAdapter.syncImmediately(context); }// w ww. java 2 s . c om // If the underlying data has been updated, notify the widgets to refresh their views if (context.getString(R.string.action_data_updated).equals(action)) { // Get the app widget manager. AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); // Get app widget ids from the app widget manager. int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, getClass())); // Notify the app widget manager that the underlying widget data has changed. appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.widget_list_view); } }
From source file:net.sourceforge.servestream.service.AppWidgetOneProvider.java
/** * Check against {@link AppWidgetManager} if there are any instances of this widget. *//* w w w. j a v a2 s . com*/ private boolean hasInstances(Context context) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, this.getClass())); return (appWidgetIds.length > 0); }
From source file:com.battlelancer.seriesguide.appwidget.ListWidgetProvider.java
@Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); // check if we received our update alarm if (UPDATE.equals(intent.getAction())) { // trigger refresh of list widgets AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); int[] appWidgetIds = appWidgetManager .getAppWidgetIds(new ComponentName(context, ListWidgetProvider.class)); appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.list_view); }//from www. j a v a2 s . c o m }
From source file:com.miz.functions.TheMovieDb.java
private void updateWidgets() { AppWidgetManager awm = AppWidgetManager.getInstance(context); awm.notifyAppWidgetViewDataChanged(/*w w w .ja v a2 s .co m*/ awm.getAppWidgetIds(new ComponentName(context, MovieStackWidgetProvider.class)), R.id.stack_view); // Update stack view widget awm.notifyAppWidgetViewDataChanged( awm.getAppWidgetIds(new ComponentName(context, MovieCoverWidgetProvider.class)), R.id.widget_grid); // Update grid view widget awm.notifyAppWidgetViewDataChanged( awm.getAppWidgetIds(new ComponentName(context, MovieBackdropWidgetProvider.class)), R.id.widget_grid); // Update grid view widget }
From source file:dk.cafeanalog.AnalogWidget.java
private void handleError(Context mContext) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext); RemoteViews views = new RemoteViews(mContext.getPackageName(), R.layout.analog_widget); int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(mContext, AnalogWidget.class)); views.setTextViewText(R.id.appwidget_text, "Error"); views.setOnClickPendingIntent(R.id.appwidget_text, getPendingSelfIntent(mContext)); // Instruct the widget manager to update the widget for (int appWidgetId : appWidgetIds) { appWidgetManager.updateAppWidget(appWidgetId, views); }/*from ww w . j ava 2 s . c o m*/ }
From source file:org.flerda.android.honeypad.NoteEditFragment.java
/** * Persists the details of the current note. This will either create a new * note, or update an existing note./*from w w w .jav a 2s . c o m*/ */ private void saveNote() { ContentValues values = new ContentValues(2); values.put(NotesProvider.KEY_TITLE, mTitleText.getText().toString()); values.put(NotesProvider.KEY_BODY, mBodyText.getText().toString()); final boolean updating = mCurrentNote != null; if (updating) { getActivity().getContentResolver().update(mCurrentNote, values, null, null); } else { Uri newNote = getActivity().getContentResolver().insert(NotesProvider.CONTENT_URI, values); if (newNote != null) { mCurrentNote = newNote; } } // show a toast confirmation Toast.makeText(getActivity(), updating ? R.string.note_updated : R.string.note_saved, Toast.LENGTH_SHORT) .show(); if (mIsV11) { // update widget AppWidgetManager awm = AppWidgetManager.getInstance(getActivity()); awm.notifyAppWidgetViewDataChanged( awm.getAppWidgetIds(new ComponentName(getActivity(), WidgetProvider.class)), R.id.stack_view); } Toast.makeText(getActivity(), "Note Saved", Toast.LENGTH_SHORT).show(); Bundle b = getArguments(); if (null != b && b.containsKey(ARGUMENT_POP_ON_SAVE)) { getFragmentManager().popBackStack(); } }
From source file:ru.yandex.subtitles.ui.appwidget.AbstractAppWidget.java
@Override public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { super.onReceive(context, intent); final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); final ComponentName componentName = new ComponentName(context, getClass()); final int[] widgetIds = appWidgetManager.getAppWidgetIds(componentName); final String action = intent.getAction(); if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action) || ACTION_APPWIDGET_DATASET_CHANGED.equals(action)) { notifyAppWidgetsViewDataChanged(appWidgetManager, widgetIds); } else if (getStartConversationAction().equals(action)) { startConversation(context, intent); }//from w w w.j a va 2 s. c o m }