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:org.openbitcoinwidget.WidgetProvider.java

public static void updateAppWidgetWithWaitMessage(Context context, AppWidgetManager appWidgetManager,
        int appWidgetId) {
    appWidgetManager.updateAppWidget(appWidgetId,
            new RemoteViews(context.getPackageName(), R.layout.appwidget_loading));
}

From source file:org.cowboycoders.cyclisimo.widgets.TrackWidgetProvider.java

/**
 * Updates an app widget./*from   w w  w . j ava 2  s . c om*/
 * 
 * @param context the context
 * @param appWidgetManager the app widget manager
 * @param appWidgetId the app widget id
 */
public static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
    RemoteViews remoteViews = getRemoteViews(context, -1L, HEIGHT_SIZE.get(appWidgetId, DEFAULT_SIZE));
    appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
}

From source file:st.brothas.mtgoxwidget.MtGoxWidgetProvider.java

static void updateAppWidget(final Context context, AppWidgetManager appWidgetManager, int appWidgetId) {

    WidgetPreferences preferences = MtGoxPreferencesActivity.getWidgetPreferences(context, appWidgetId);

    if (preferences == null) {
        // Don't do anything unless the rate service has been chosen.
        // Show a "please remove this widget and add a new one"
        appWidgetManager.updateAppWidget(appWidgetId,
                new RemoteViews(context.getPackageName(), R.layout.appwidget_replace_me));
        return;//from w ww.j a va  2 s .  c  o m
    }

    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider);
    Intent clickIntent = new Intent(context, GraphPopupActivity.class);
    clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    clickIntent.setAction("dummyAction"); // Needed to get the extra variables included in the call
    // Note: the appWidgetId needs to be sent in the pendingIntent as request code, otherwise only ONE
    //       cached intent will be used for all widget instances!
    PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, clickIntent, 0);
    views.setOnClickPendingIntent(R.id.appwidget_box, pendingIntent);
    views.setTextViewText(R.id.appwidget_service_name, preferences.getRateService().getName());

    MtGoxDataOpenHelper dbHelper = new MtGoxDataOpenHelper(context);
    MtGoxTickerData prevData = dbHelper.getLastTickerData(preferences);

    MtGoxTickerData newData;
    JSONObject latestQuoteJSON = getLatestQuoteJSON(preferences);
    if (latestQuoteJSON != null) {
        newData = preferences.getRateService().parseJSON(latestQuoteJSON);
        newData.setCurrencyConversion(preferences.getCurrencyConversion());
        storeLastValueIfNotNull(dbHelper, newData);
        updateViews(views, prevData, newData, preferences);
    } else if (prevData != null) {
        newData = prevData;
        updateViews(views, prevData, newData, preferences);
    } else {
        updateViewsWithError(views, preferences);
    }
    appWidgetManager.updateAppWidget(appWidgetId, views);
}

From source file:org.openbitcoinwidget.WidgetProvider.java

private static void updateAppWidget(final Context context, AppWidgetManager appWidgetManager, int appWidgetId) {

    WidgetPreferences preferences = PreferencesActivity.getWidgetPreferences(context, appWidgetId);

    if (preferences == null) {
        // Don't do anything unless the rate service has been chosen.
        // Show a "please remove this widget and add a new one"
        appWidgetManager.updateAppWidget(appWidgetId,
                new RemoteViews(context.getPackageName(), R.layout.appwidget_replace_me));
        return;//from w w  w .  j ava  2  s.  c om
    }

    boolean isOnLockScreen = isWidgetShownOnLockScreen(appWidgetManager, appWidgetId);

    RemoteViews views;
    if (isOnLockScreen) {
        views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider_lock_screen);
    } else {
        views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider);
    }

    Intent clickIntent = new Intent(context, GraphPopupActivity.class);
    clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    clickIntent.setAction("dummyAction"); // Needed to get the extra variables included in the call
    // Note: the appWidgetId needs to be sent in the pendingIntent as request code, otherwise only ONE
    //      cached intent will be used for all widget instances!
    PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, clickIntent, 0);
    views.setOnClickPendingIntent(R.id.appwidget_box, pendingIntent);
    views.setTextViewText(R.id.appwidget_service_name, preferences.getRateService().getName());

    DataOpenHelper dbHelper = new DataOpenHelper(context);
    TickerData prevData = dbHelper.getLastTickerData(preferences);

    TickerData newData;
    String latestQuote = getLatestQuote(preferences);
    if (latestQuote != null && !latestQuote.equals("")) {
        newData = preferences.getRateService().parseJSON(latestQuote);
        newData.setCurrencyConversion(preferences.getCurrencyConversion());
        storeLastValueIfNotNull(dbHelper, newData);
        updateViews(views, prevData, newData, preferences);
    } else if (prevData != null) {
        newData = prevData;
        updateViews(views, prevData, newData, preferences);
    } else {
        updateViewsWithError(views, preferences);
    }
    appWidgetManager.updateAppWidget(appWidgetId, views);
}

From source file:br.com.bioscada.apps.biotracks.widgets.TrackWidgetProvider.java

/**
 * Updates an app widget.//from  w ww .  j  ava 2s .  c o m
 * 
 * @param context the context
 * @param appWidgetManager the app widget manager
 * @param appWidgetId the app widget id
 * @param trackId the track id. -1L to not specify one
 */
public static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId,
        long trackId) {
    int size = ApiAdapterFactory.getApiAdapter().getAppWidgetSize(appWidgetManager, appWidgetId);
    RemoteViews remoteViews = getRemoteViews(context, trackId, size);
    appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
}

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:org.gnucash.android.ui.widget.WidgetConfigurationActivity.java

/**
 * Updates the widget with id <code>appWidgetId</code> with information from the 
 * account with record ID <code>accountId</code>
  * If the account has been deleted, then a notice is posted in the widget
  * @param appWidgetId ID of the widget to be updated
  * @param accountId Database ID of the account tied to the widget
 */// w  ww. j  a va 2s.  c  o m
public static void updateWidget(Context context, int appWidgetId, long accountId) {
    Log.i("WidgetConfiguration", "Updating widget: " + appWidgetId);
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);

    AccountsDbAdapter accountsDbAdapter = new AccountsDbAdapter(context);
    Account account = accountsDbAdapter.getAccount(accountId);

    if (account == null) {
        Log.i("WidgetConfiguration", "Account not found, resetting widget " + appWidgetId);
        //if account has been deleted, let the user know
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_4x1);
        views.setTextViewText(R.id.account_name, context.getString(R.string.toast_account_deleted));
        views.setTextViewText(R.id.transactions_summary, "");
        //set it to simply open the app
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                new Intent(context, AccountsActivity.class), 0);
        views.setOnClickPendingIntent(R.id.widget_layout, pendingIntent);
        views.setOnClickPendingIntent(R.id.btn_new_transaction, pendingIntent);
        appWidgetManager.updateAppWidget(appWidgetId, views);
        Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
        editor.remove(UxArgument.SELECTED_ACCOUNT_ID + appWidgetId);
        editor.commit();
        return;
    }

    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_4x1);
    views.setTextViewText(R.id.account_name, account.getName());
    Money accountBalance = accountsDbAdapter.getAccountBalance(accountId);

    views.setTextViewText(R.id.transactions_summary, accountBalance.formattedString(Locale.getDefault()));
    int color = account.getBalance().isNegative() ? R.color.debit_red : R.color.credit_green;
    views.setTextColor(R.id.transactions_summary, context.getResources().getColor(color));

    Intent accountViewIntent = new Intent(context, TransactionsActivity.class);
    accountViewIntent.setAction(Intent.ACTION_VIEW);
    accountViewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    accountViewIntent.putExtra(UxArgument.SELECTED_ACCOUNT_ID, accountId);
    PendingIntent accountPendingIntent = PendingIntent.getActivity(context, appWidgetId, accountViewIntent, 0);
    views.setOnClickPendingIntent(R.id.widget_layout, accountPendingIntent);

    Intent newTransactionIntent = new Intent(context, TransactionsActivity.class);
    newTransactionIntent.setAction(Intent.ACTION_INSERT_OR_EDIT);
    newTransactionIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    newTransactionIntent.putExtra(UxArgument.SELECTED_ACCOUNT_ID, accountId);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, newTransactionIntent, 0);
    views.setOnClickPendingIntent(R.id.btn_new_transaction, pendingIntent);

    appWidgetManager.updateAppWidget(appWidgetId, views);
}

From source file:net.sourceforge.servestream.service.AppWidgetOneProvider.java

private void pushUpdate(Context context, int[] appWidgetIds, RemoteViews views) {
    // Update specific list of appWidgetIds if given, otherwise default to all
    final AppWidgetManager gm = AppWidgetManager.getInstance(context);
    if (appWidgetIds != null) {
        gm.updateAppWidget(appWidgetIds, views);
    } else {//from   w ww.  ja v a  2  s . co m
        gm.updateAppWidget(new ComponentName(context, this.getClass()), views);
    }
}

From source file:com.battlelancer.seriesguide.appwidget.ListWidgetProvider.java

@Override
public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId,
        Bundle newOptions) {//www  .ja v  a 2s  . c o m
    RemoteViews rv = buildRemoteViews(context, appWidgetManager, appWidgetId);

    appWidgetManager.updateAppWidget(appWidgetId, rv);
}

From source file:com.todotxt.todotxttouch.widget.ListWidgetProvider.java

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    for (int i = 0; i < appWidgetIds.length; ++i) {
        RemoteViews layout = buildLayout(context, appWidgetIds[i], false);
        appWidgetManager.updateAppWidget(appWidgetIds[i], layout);
    }/* w w  w  .j a v  a  2  s. c o  m*/

    appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.widget_list);
    super.onUpdate(context, appWidgetManager, appWidgetIds);
}