Example usage for android.appwidget AppWidgetManager ACTION_APPWIDGET_UPDATE

List of usage examples for android.appwidget AppWidgetManager ACTION_APPWIDGET_UPDATE

Introduction

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

Prototype

String ACTION_APPWIDGET_UPDATE

To view the source code for android.appwidget AppWidgetManager ACTION_APPWIDGET_UPDATE.

Click Source Link

Document

Sent when it is time to update your AppWidget.

Usage

From source file:com.dpcsoftware.mn.App.java

public void setFlag(int tableId) {
    switch (tableId) {
    case 1://from   w  ww. j  av  a 2 s . c om
        mnUpdateList = true;

        //Update widgets if anyone is being used
        AppWidgetManager wManager = AppWidgetManager.getInstance(this);
        ComponentName cWidgetProvider = new ComponentName(this, Widget1.class);
        int wIds[] = wManager.getAppWidgetIds(cWidgetProvider);
        if (wIds.length != 0) {
            Intent updateIntent = new Intent(this, Widget1.class);
            updateIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
            updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, wIds);
            try {
                PendingIntent.getBroadcast(this, 0, updateIntent, PendingIntent.FLAG_UPDATE_CURRENT).send();
            } catch (PendingIntent.CanceledException e) {
                e.printStackTrace();
            }
        }
        break;
    case 2:
        mnUpdateList = true;
        break;
    case 3:
        mnUpdateMenu = true;
        break;
    }
}

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

@Override
public void onReceive(Context aContext, Intent intent) {
    super.onReceive(aContext, intent);
    initialize(aContext);//from www.  j  av a 2 s . c  o m

    selectedTrackId = intent.getLongExtra(context.getString(R.string.track_id_broadcast_extra),
            selectedTrackId);
    String action = intent.getAction();

    if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)
            || AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)
            || trackStartedBroadcastAction.equals(action) || trackStoppedBroadcastAction.equals(action)) {
        updateTrack(action);
    }
}

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);//ww w.  j  ava  2 s  .c  om
}

From source file:net.niyonkuru.koodroid.appwidget.WidgetConfigureActivity.java

@Override
public void onPause() {
    super.onPause();

    mAlertDialog.dismiss(); // avoid leaking window

    String action = getIntent().getAction();
    if (mResultCode == RESULT_CANCELED
            && (action != null && action.equals(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE))) {
        /* avoid phantom widgets */
        AppWidgetHost host = new AppWidgetHost(this, 1);
        host.deleteAppWidgetId(mAppWidgetId);
    } else {//  ww w.  j  a v  a  2s.co  m
        Intent intent = IntentUtils.createWidgetIntent(this, AppWidgetManager.ACTION_APPWIDGET_UPDATE);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { mAppWidgetId });

        sendBroadcast(intent);
    }
}

From source file:com.QuarkLabs.BTCeClient.UpdateWidgetsTask.java

@Override
protected void onPostExecute(JSONObject jsonObject) {
    if (jsonObject != null) {
        try {/*from w w w  . ja v  a  2  s.  c  o m*/
            Context context = mContext.get();
            if (context == null) {
                return;
            }
            AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
            for (int x : mMap.keySet()) {
                RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_layout);
                double price = jsonObject.getJSONObject(mMap.get(x).replace("/", "_").toLowerCase(Locale.US))
                        .getDouble("last");
                String priceString;
                if (price > 1) {
                    priceString = (new DecimalFormat("#.##")).format(price);
                } else {
                    priceString = String.valueOf(price);
                }
                views.setTextViewText(R.id.widgetCurrencyValue, priceString);
                views.setTextViewText(R.id.widgetPair, mMap.get(x));
                String color = jsonObject.getJSONObject(mMap.get(x).replace("/", "_").toLowerCase(Locale.US))
                        .getString("color");
                int colorValue = color.equals("green") ? Color.GREEN : Color.RED;
                views.setTextColor(R.id.widgetCurrencyValue, colorValue);
                Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                Bundle bundle = new Bundle();
                bundle.putIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS,
                        appWidgetManager.getAppWidgetIds(new ComponentName(context, WidgetProvider.class)));
                intent.putExtras(bundle);
                PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent,
                        PendingIntent.FLAG_UPDATE_CURRENT);
                views.setOnClickPendingIntent(R.id.widgetContainer, pi);
                SimpleDateFormat df = new SimpleDateFormat("EEE HH:mm", Locale.US);
                Calendar calendar = Calendar.getInstance();
                views.setTextViewText(R.id.widgetDate, df.format(calendar.getTime()));
                appWidgetManager.updateAppWidget(x, views);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

From source file:se.frikod.payday.DailyBudgetFragment.java

public void updateBudget() {

    try {/*from  w  w  w  . j  a  va  2s  .com*/
        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.sudhirkhanger.andpress.ui.MainActivity.java

private void updateWidgets() {
    ComponentName name = new ComponentName(this, AndPressWidgetProvider.class);
    int[] ids = AppWidgetManager.getInstance(this).getAppWidgetIds(name);

    Intent intent = new Intent(this, AndPressWidgetProvider.class);
    intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
    sendBroadcast(intent);//from   w  w w.ja  v a2 s  .  c o  m
}

From source file:com.gelakinetic.inboxwidget.InboxCheckerAppWidgetConfigure.java

/**
 * @param context A context to build the intent with
 * @return An Intent which will call onUpdate for all Inbox Widgets
 */// w  w w  .  java 2  s  .  c  om
private static Intent getUpdateWidgetIntent(Context context) {
    /* Get an intent for the InboxCheckerAppWidgetProvider class */
    Intent intent = new Intent(context.getApplicationContext(), InboxCheckerAppWidgetProvider.class);
    /* Tell it to update widgets */
    intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);

    /* Get a list of IDs for all the widgets */
    AppWidgetManager widgetManager = AppWidgetManager.getInstance(context);
    int[] ids = widgetManager.getAppWidgetIds(new ComponentName(context, InboxCheckerAppWidgetProvider.class));

    /* Tell the intent which widgets to update */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        widgetManager.notifyAppWidgetViewDataChanged(ids, android.R.id.list);
    }
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);

    /* Return the intent */
    return intent;
}

From source file:org.solovyev.android.calculator.widget.CalculatorWidget.java

@Override
public void onReceive(@Nonnull Context context, @Nonnull Intent intent) {
    cast(context).getComponent().inject(this);

    super.onReceive(context, intent);

    final String action = intent.getAction();
    if (TextUtils.isEmpty(action)) {
        return;//from   w  w  w  . j av  a  2  s .  c o  m
    }
    switch (action) {
    case ACTION_EDITOR_STATE_CHANGED:
    case ACTION_DISPLAY_STATE_CHANGED:
        updateWidget(context, true);
        break;
    case ACTION_CONFIGURATION_CHANGED:
    case ACTION_THEME_CHANGED:
    case ACTION_INIT:
    case AppWidgetManager.ACTION_APPWIDGET_UPDATE:
    case AppWidgetManager.ACTION_APPWIDGET_OPTIONS_CHANGED:
        updateWidget(context, false);
        break;
    }
}

From source file:net.olejon.mdapp.MyTools.java

public void updateWidget() {
    ComponentName componentName = new ComponentName(mContext, Widget.class);

    int[] appWidgetIds = AppWidgetManager.getInstance(mContext).getAppWidgetIds(componentName);

    Intent intent = new Intent(mContext, Widget.class);
    intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);

    mContext.sendBroadcast(intent);/*w w  w .j  a  va 2  s.  c o m*/
}