Example usage for android.appwidget AppWidgetManager updateAppWidget

List of usage examples for android.appwidget AppWidgetManager updateAppWidget

Introduction

In this page you can find the example usage for android.appwidget AppWidgetManager updateAppWidget.

Prototype

public void updateAppWidget(ComponentName provider, RemoteViews views) 

Source Link

Document

Set the RemoteViews to use for all AppWidget instances for the supplied AppWidget provider.

Usage

From source file:name.gumartinm.weather.information.widget.WidgetIntentService.java

private void updateWidget(final RemoteViews remoteView, final int appWidgetId) {

    final AppWidgetManager manager = AppWidgetManager.getInstance(this.getApplicationContext());
    manager.updateAppWidget(appWidgetId, remoteView);
}

From source file:com.android.gallery3d.gadget.WidgetConfigure.java

private void updateWidgetAndFinish(WidgetDatabaseHelper.Entry entry) {
    AppWidgetManager manager = AppWidgetManager.getInstance(this);
    RemoteViews views = PhotoAppWidgetProvider.buildWidget(this, mAppWidgetId, entry);
    manager.updateAppWidget(mAppWidgetId, views);
    setResult(RESULT_OK, new Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId));
    finish();/*from  www  .ja  v  a  2 s .  c  o  m*/
}

From source file:de.hackerspacebremen.push.PushIntentService.java

private void updateAppWidget(Context context, SpaceData data) {
    SharedPreferences dataPersistence = getSharedPreferences(Constants.SPACE_DATA_PERSISTENCE,
            Context.MODE_PRIVATE);
    Editor editor = dataPersistence.edit();
    editor.putBoolean(Constants.SPACE_OPEN_DATA_KEY, data.isSpaceOpen());
    editor.commit();/*from   w ww .j  av a2 s . c o m*/

    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.appwidget);
    remoteViews.setViewVisibility(R.id.indicatorImage, View.VISIBLE);
    remoteViews.setViewVisibility(R.id.errorText, View.GONE);

    if (data.isSpaceOpen()) {
        remoteViews.setImageViewResource(R.id.indicatorImage, R.drawable.banner);
    } else {
        remoteViews.setImageViewResource(R.id.indicatorImage, R.drawable.banner_blur);
    }

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    ComponentName componentName = new ComponentName(context, HackerspaceWidgetProvider.class);
    appWidgetManager.updateAppWidget(componentName, remoteViews);
}

From source file:me.sandrin.xkcdwidget.XKCDAppWidgetProvider.java

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    title = "";/*from   ww w . j a v  a  2  s . c  o  m*/
    altText = "";
    image = null;

    updateComicInfo();

    for (int appWidgetId : appWidgetIds) {
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.app_widget_layout);
        updateRemoteViews(context, views);
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}

From source file:com.ratusapparatus.tapsaff.TapsAff.java

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);

    ComponentName thisWidget = new ComponentName(context, TapsAff.class);
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
    views.setTextViewText(R.id.main, "ehh...");
    appWidgetManager.updateAppWidget(thisWidget, views);

    RetreiveFeedTask task = new RetreiveFeedTask();
    task.context = context;//from www  .j a va 2 s  .  c  o m
    task.appWidgetManager = appWidgetManager;
    task.execute("http://www.taps-aff.co.uk/taps.json");

}

From source file:com.nogago.android.tracks.widgets.TrackWidgetProvider.java

/**
 * Updates the widget./*from  w  w w  .  j  a  v a 2  s .  c  o  m*/
 * 
 * @param action the action
 */
private void updateTrack(String action) {
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.track_widget);

    if (action != null) {
        updateButton(remoteViews, action);
    }
    updateView(remoteViews);

    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:de.hackerspacebremen.fragments.StatusFragment.java

private void updateAppWidget(SpaceData data) {
    SharedPreferences dataPersistence = getActivity().getSharedPreferences(Constants.SPACE_DATA_PERSISTENCE,
            Context.MODE_PRIVATE);
    Editor editor = dataPersistence.edit();
    editor.putBoolean(Constants.SPACE_OPEN_DATA_KEY, data.isSpaceOpen());
    editor.commit();//from   w w  w  .  ja  va 2  s  .c om

    RemoteViews remoteViews = new RemoteViews(getActivity().getPackageName(), R.layout.appwidget);
    remoteViews.setViewVisibility(R.id.indicatorImage, View.VISIBLE);
    remoteViews.setViewVisibility(R.id.errorText, View.GONE);

    if (data.isSpaceOpen()) {
        remoteViews.setImageViewResource(R.id.indicatorImage, R.drawable.banner);
    } else {
        remoteViews.setImageViewResource(R.id.indicatorImage, R.drawable.banner_blur);
    }

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getActivity());
    ComponentName componentName = new ComponentName(getActivity(), HackerspaceWidgetProvider.class);
    appWidgetManager.updateAppWidget(componentName, remoteViews);
}

From source file:HomescreenWidgetProvider.java

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);
    for (int count = 0; count < appWidgetIds.length; count++) {
        RemoteViews appWidgetLayout = new RemoteViews(context.getPackageName(), R.layout.widget);
        Intent intent = new Intent(context, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
        appWidgetLayout.setOnClickPendingIntent(R.id.analogClock, pendingIntent);
        appWidgetManager.updateAppWidget(appWidgetIds[count], appWidgetLayout);
    }/*from w  ww.  j ava 2s.c om*/
}

From source file:com.google.android.apps.mytracks.widgets.TrackWidgetProvider.java

/**
 * Updates the widget./*from  w w  w  .  j av  a  2s  .  c o 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.meiste.greg.ptw.WidgetProvider.java

@Override
public void onUpdate(final Context context, final AppWidgetManager appWidgetManager, final int[] appWidgetIds) {
    Util.log("WidgetProvider.onUpdate: num=" + appWidgetIds.length);

    final RemoteViews rViews = new RemoteViews(context.getPackageName(), R.layout.widget_loading);
    appWidgetManager.updateAppWidget(appWidgetIds, rViews);

    new UpdateWidgetThread(context).start();

    /* Set alarm to update widget when device is awake. */
    setAlarm(context);//  w  ww .  j a  v  a 2  s  .  c  o m
}