List of usage examples for android.appwidget AppWidgetManager getInstance
public static AppWidgetManager getInstance(Context context)
From source file:org.isoron.uhabits.MainActivity.java
private static void updateWidgets(Context context, Class providerClass) { ComponentName provider = new ComponentName(context, providerClass); Intent intent = new Intent(context, providerClass); intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); int ids[] = AppWidgetManager.getInstance(context).getAppWidgetIds(provider); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids); context.sendBroadcast(intent);//from w w w .j a v a2 s .c o m }
From source file:org.cowboycoders.cyclisimo.widgets.TrackWidgetProvider.java
@Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); String action = intent.getAction(); if (context.getString(R.string.track_paused_broadcast_action).equals(action) || context.getString(R.string.track_resumed_broadcast_action).equals(action) || context.getString(R.string.track_started_broadcast_action).equals(action) || context.getString(R.string.track_stopped_broadcast_action).equals(action) || context.getString(R.string.track_update_broadcast_action).equals(action)) { long trackId = intent.getLongExtra(context.getString(R.string.track_id_broadcast_extra), -1L); AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); int[] appWidgetIds = appWidgetManager .getAppWidgetIds(new ComponentName(context, TrackWidgetProvider.class)); for (int appWidgetId : appWidgetIds) { RemoteViews remoteViews = getRemoteViews(context, trackId, HEIGHT_SIZE.get(appWidgetId, DEFAULT_SIZE)); appWidgetManager.updateAppWidget(appWidgetId, remoteViews); }//w ww .j a v a 2 s .co m } }
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); }//from w w w . j a v a 2 s . com // 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:com.google.android.apps.mytracks.widgets.TrackWidgetProvider.java
/** * Updates the widget.//from w ww .j ava 2s.co m * * @param context the context * @param trackId the track id */ private void update(Context context, long trackId) { // Get the preferences long recordingTrackId = PreferencesUtils.getLong(context, R.string.recording_track_id_key); boolean recordingTrackPaused = PreferencesUtils.getBoolean(context, R.string.recording_track_paused_key, PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT); boolean metricUnits = PreferencesUtils.getBoolean(context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT); // Get track and trip statistics MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context); if (trackId == -1L) { trackId = recordingTrackId; } if (trackId == -1L) { trackId = PreferencesUtils.getLong(context, R.string.selected_track_id_key); } Track track = trackId != -1L ? myTracksProviderUtils.getTrack(trackId) : myTracksProviderUtils.getLastTrack(); TripStatistics tripStatistics = track == null ? null : track.getTripStatistics(); RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.track_widget); boolean isRecording = recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT; updateStatisticsContainer(context, remoteViews, track); updateTotalDistance(context, remoteViews, tripStatistics, metricUnits); updateTotalTime(remoteViews, tripStatistics, isRecording, recordingTrackPaused); updateAverageSpeed(context, remoteViews, tripStatistics, metricUnits); updateMovingTime(context, remoteViews, tripStatistics); updateRecordButton(context, remoteViews, isRecording, recordingTrackPaused); updateRecordStatus(context, remoteViews, isRecording, recordingTrackPaused); updateStopButton(context, remoteViews, isRecording); AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); int[] appWidgetIds = appWidgetManager .getAppWidgetIds(new ComponentName(context, TrackWidgetProvider.class)); for (int appWidgetId : appWidgetIds) { appWidgetManager.updateAppWidget(appWidgetId, remoteViews); } }
From source file:com.lemontruck.thermo.MainActivity.java
private void closeActivity() { Context context = MainActivity.this; AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); ThermoWidget.remakeWidget(context, appWidgetManager, appWidgetId); Intent resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); setResult(RESULT_OK, resultValue);/* w w w .j av a 2 s . co m*/ finish(); }
From source file:com.teinproductions.tein.papyrosprogress.MainActivity.java
private void checkNotificationsAsked() { @SuppressWarnings("deprecation") final SharedPreferences oldSharedPref = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE); final SharedPreferences defaultSharedPref = PreferenceManager.getDefaultSharedPreferences(this); if (oldSharedPref.contains(Constants.NOTIFICATION_ASKED_PREFERENCE)) { // The old preferences have to be copied over to the new default shared preferences SharedPreferences.Editor editor = defaultSharedPref.edit(); editor.putBoolean(Constants.NOTIFICATION_PREFERENCE, oldSharedPref.getBoolean(Constants.NOTIFICATION_PREFERENCE, true)); editor.putInt(Constants.CACHED_BLOG_AMOUNT, oldSharedPref.getInt(Constants.CACHED_BLOG_AMOUNT, 0)); for (int id : AbstractProgressWidget.getAppWidgetLargeIds(this, AppWidgetManager.getInstance(this))) { editor.putInt(Constants.TEXT_SIZE_PREFERENCE + id, oldSharedPref.getInt(Constants.TEXT_SIZE_PREFERENCE + id, 24)); editor.putString(Constants.MILESTONE_WIDGET_PREFERENCE + id, oldSharedPref.getString(Constants.MILESTONE_WIDGET_PREFERENCE + id, "Version 0.1")); }//from w w w .ja va 2 s . c om for (int id : AbstractProgressWidget.getAppWidgetSmallIds(this, AppWidgetManager.getInstance(this))) { editor.putInt(Constants.TEXT_SIZE_PREFERENCE + id, oldSharedPref.getInt(Constants.TEXT_SIZE_PREFERENCE + id, 24)); editor.putString(Constants.MILESTONE_WIDGET_PREFERENCE + id, oldSharedPref.getString(Constants.MILESTONE_WIDGET_PREFERENCE + id, "Version 0.1")); } editor.apply(); // Clear the old shared preferences oldSharedPref.edit().clear().apply(); } else if (!defaultSharedPref.contains(Constants.NOTIFICATION_PREFERENCE)) { new AlertDialog.Builder(this).setTitle(getString(R.string.notifications)) .setMessage(getString(R.string.notification_dialog_message)) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { defaultSharedPref.edit().putBoolean(Constants.NOTIFICATION_PREFERENCE, true).apply(); AlarmUtils.setAlarm(MainActivity.this); invalidateOptionsMenu(); } }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { defaultSharedPref.edit().putBoolean(Constants.NOTIFICATION_PREFERENCE, false).apply(); AlarmUtils.reconsiderSettingAlarm(MainActivity.this); invalidateOptionsMenu(); } }).create().show(); } }
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 ww w . j av a2s .c om */ 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:com.mathi_amorim.emmanuel.metrictime.UpdateTimeService.java
private void updateWidget() { mCalendar.setTimeInMillis(System.currentTimeMillis()); MetricTime time = MetricTimeConverter.currentMetricTime(); String currentTime = String.format("%1$01d:%2$02d", time.hours, time.minutes); RemoteViews mRemoteViews = new RemoteViews(getPackageName(), R.layout.metric_time_widget); mRemoteViews.setTextViewText(R.id.widget1label, currentTime); Intent intent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); mRemoteViews.setOnClickPendingIntent(R.id.widget1label, pendingIntent); ComponentName mComponentName = new ComponentName(this, MetricTimeWidgetProvider.class); AppWidgetManager mAppWidgetManager = AppWidgetManager.getInstance(this); mAppWidgetManager.updateAppWidget(mComponentName, mRemoteViews); }
From source file:se.frikod.payday.DailyBudgetFragment.java
public void updateBudget() { try {//from ww w. ja v a 2 s .co m budget.update(); } catch (WrongAPIKeyException e) { activity.runSetup(); return; } catch (AccountNotFoundException e) { activity.runSetup(); return; } AppWidgetManager man = AppWidgetManager.getInstance(activity); int[] ids = man.getAppWidgetIds(new ComponentName(activity, PaydayWidget.class)); Intent updateIntent = new Intent(); updateIntent.setClass(activity, PaydayWidget.class); updateIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); updateIntent.putExtra(PaydayWidget.WIDGET_IDS_KEY, ids); activity.sendBroadcast(updateIntent); if (android.os.Build.VERSION.SDK_INT >= 11) { renderBudgetAnimated(); } else { renderBudget(budget.dailyBudget); } currentBudget = budget.dailyBudget; }
From source file:com.android.settings.aoip.WidgetsConfiguration.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); mContext = activity.getApplicationContext(); IntentFilter filter = new IntentFilter(ACTION_SEND_ID); mContext.registerReceiver(mWidgetIdReceiver, filter); mAppWidgetManager = AppWidgetManager.getInstance(mContext); }