Example usage for android.appwidget AppWidgetManager getAppWidgetIds

List of usage examples for android.appwidget AppWidgetManager getAppWidgetIds

Introduction

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

Prototype

public int[] getAppWidgetIds(ComponentName provider) 

Source Link

Document

Get the list of appWidgetIds that have been bound to the given AppWidget provider.

Usage

From source file:com.ferid.app.frequentcontacts.MainActivity.java

/**
 * Updates frequent contacts widget//  w  w w .j a v  a2 s .  c  o m
 */
private void updateFrequentContactsWidget() {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    ComponentName thisAppWidget = new ComponentName(context.getPackageName(), this.getClass().getName());
    Intent updateWidget = new Intent(context, FrequentContactsWidget.class);
    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisAppWidget);
    updateWidget.setAction(FrequentContactsWidget.APP_TO_WID);
    updateWidget.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
    context.sendBroadcast(updateWidget);
}

From source file:com.ferid.app.notetake.MainActivity.java

/**
 * Updates note widget//ww  w  .j  a  v  a  2s . c o  m
 */
private void updateNoteWidget() {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    ComponentName thisAppWidget = new ComponentName(context.getPackageName(), this.getClass().getName());
    Intent updateWidget = new Intent(context, NoteWidget.class);
    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisAppWidget);
    updateWidget.setAction(NoteWidget.APP_TO_WID);
    updateWidget.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
    context.sendBroadcast(updateWidget);
}

From source file:org.zoumbox.mh_dla_notifier.Receiver.java

protected void checkForWidgetsUpdate(Context context, Troll troll) {

    try {//from  w  w w.  j a  v  a 2s. co  m
        AppWidgetManager widgetManager = AppWidgetManager.getInstance(context);

        ComponentName componentName = new ComponentName(context, HomeScreenWidget.class);
        int[] appWidgetIds = widgetManager.getAppWidgetIds(componentName);

        if (appWidgetIds != null && appWidgetIds.length > 0) {

            // FIXME AThimel 14/02/14 Remove ASAP
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);

            String dlaText = Trolls.getWidgetDlaTextFunction(context).apply(troll);
            Bitmap blason = MhDlaNotifierUtils.loadBlasonForWidget(troll.getBlason(), context.getCacheDir());

            for (int appWidgetId : appWidgetIds) {

                RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.home_screen_widget);
                views.setTextViewText(R.id.widgetDla, dlaText);

                if (blason == null) {
                    views.setImageViewResource(R.id.widgetImage, R.drawable.trarnoll_square_transparent_128);
                } else {
                    views.setImageViewBitmap(R.id.widgetImage, blason);
                }

                // Tell the AppWidgetManager to perform an update on the current app widget
                widgetManager.updateAppWidget(appWidgetId, views);
            }
        }

    } catch (Exception eee) {
        Log.e(TAG, "Unable to update widget(s)", eee);
    }

}

From source file:de.hero.vertretungsplan.HtmlWork.java

@SuppressLint("NewApi")
private void updateWidget(boolean before) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.widget);
        AppWidgetManager appManager = AppWidgetManager.getInstance(context);
        ComponentName name = new ComponentName(context, WidgetProvider.class);
        if (before) {
            widget.setImageViewResource(R.id.aktButton, R.drawable.ic_action_aktualisieren_pressed);
        } else {//from  w  w  w .  j av a 2  s .  c  o m
            widget.setImageViewResource(R.id.aktButton, R.drawable.aktualisieren_drawable);
            if (dataChanged) {
                appManager.notifyAppWidgetViewDataChanged(appManager.getAppWidgetIds(name), R.id.words);
            }
        }
        appManager.partiallyUpdateAppWidget(appManager.getAppWidgetIds(name), widget);
    }
}

From source file:com.google.android.apps.dashclock.DashClockService.java

/**
 * Updates a widget's UI./*w ww  .ja va2  s. c om*/
 */
private void handleUpdateWidgets(Intent intent) {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);

    // Either update all app widgets, or only those which were requested.
    int appWidgetIds[];
    if (intent.hasExtra(EXTRA_APPWIDGET_ID)) {
        appWidgetIds = new int[] { intent.getIntExtra(EXTRA_APPWIDGET_ID, -1) };
    } else {
        appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(this, WidgetProvider.class));
    }

    StringBuilder sb = new StringBuilder();
    for (int appWidgetId : appWidgetIds) {
        sb.append(appWidgetId).append(" ");
    }
    LOGD(TAG, "Rendering widgets with appWidgetId(s): " + sb);

    WidgetRenderer.renderWidgets(this, appWidgetIds);
}

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

@Override
public void onReceive(Context context, Intent intent) {
    final String action = intent.getAction();

    if (action.equals(REFRESH_ACTION)) {
        Log.d(TAG, "Widget Refresh button pressed");

        Intent i = new Intent(Constants.INTENT_START_SYNC_WITH_REMOTE);
        context.sendBroadcast(i);/* ww w.  ja  va  2 s.  co m*/
        Bundle extras = intent.getExtras();

        if (extras != null) {
            int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID);
            AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
            RemoteViews rv = buildLayout(context, appWidgetId, true);
            appWidgetManager.partiallyUpdateAppWidget(appWidgetId, rv);
        }
    } else if (action.equals(Constants.INTENT_WIDGET_UPDATE)) {
        Log.d(TAG, "Update widget intent received ");

        int[] appWidgetIds = null;
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        Bundle extras = intent.getExtras();

        if (extras != null) {
            appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
        }

        if (appWidgetIds == null) {
            appWidgetIds = appWidgetManager
                    .getAppWidgetIds(new ComponentName(context, ListWidgetProvider.class.getName()));
        }

        if (appWidgetIds != null && appWidgetIds.length > 0) {
            this.onUpdate(context, appWidgetManager, appWidgetIds);
        }
    }

    super.onReceive(context, intent);
}

From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java

private void refreshCityOrWeather(Context context, String what, int which) {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    if (appWidgetManager != null) {
        int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context));
        for (int appWidgetId : appWidgetIds) {
            RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);
            if (1 == which) {
                widget.setTextViewText(R.id.city, what);
            } else if (2 == which) {
                if (what.equals("")) {
                    //widget.setTextViewText(R.id.temperature, context.getString(R.string.weather_network_error));
                } else if (what.contains(",")) {
                    String weather = what.split(",")[0];
                    String temperature = what.split(",")[1];
                    String image = what.split(",")[2];
                    widget.setTextViewText(R.id.temperature, temperature);
                    widget.setImageViewResource(R.id.weather, getWeatherImageId(image));
                }// w  w  w.  j  a v a2s . c o  m
            }
            appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget);
        }
    }
}

From source file:fr.shywim.antoinedaniel.ui.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case SETTINGS_REQUEST_CODE:
        AppWidgetManager man = AppWidgetManager.getInstance(this);
        if (man != null) {
            int[] ids = man.getAppWidgetIds(new ComponentName(mAppContext, HomeScreenWidgetProvider.class));
            Intent updateIntent = new Intent();
            updateIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
            updateIntent.putExtra(HomeScreenWidgetProvider.WIDGET_IDS_KEY, ids);
            this.sendBroadcast(updateIntent);
        }//from   w w w.j  a va 2s . com

        if (resultCode == RESULT_CONNECT_GOOGLE_CODE) {
            mTaskFragment.connectPlayServices(findViewById(VIEW_ID_POPUPS));
        }
        break;

    case PURCHASE_REQUEST_CODE:
        if (resultCode == RESULT_OK) {
            String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
            try {
                JSONObject jo = new JSONObject(purchaseData);
                String sku = jo.getString("productId");
                if (sku.equals(utils.SKU_DONATE)) {
                    PrefUtils.setUserDonated(this, true);
                    Toast.makeText(this, R.string.toast_purchase_thanks, Toast.LENGTH_LONG).show();
                    mAdView.destroy();
                    LinearLayout adLayout = (LinearLayout) findViewById(R.id.adLayout);
                    adLayout.setVisibility(View.GONE);
                }
            } catch (JSONException e) {
                Toast.makeText(mContext, R.string.error, Toast.LENGTH_SHORT).show();
            }
        }
        break;

    case BlindGameActivity.REQUEST_CODE:
        /*if (resultCode == RESULT_OK){
           selectItem(DrawerPosition.GAMES, data.getExtras());
        } else selectItem(DrawerPosition.GAMES, null);*/
        break;

    case 1001:
        if (resultCode == RESULT_OK) {
            mTaskFragment.connectPlayServices(findViewById(VIEW_ID_POPUPS));
        } else {
            PrefUtils.setRefusedGoogle(this, true);
        }
        break;
    }
}

From source file:de.schildbach.wallet.service.BlockchainServiceImpl.java

public void notifyWidgets() {
    final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);

    final ComponentName providerName = new ComponentName(this, WalletBalanceWidgetProvider.class);
    final int[] appWidgetIds = appWidgetManager.getAppWidgetIds(providerName);

    if (appWidgetIds.length > 0) {
        final Wallet wallet = application.getWallet();
        final BigInteger balance = wallet.getBalance(BalanceType.ESTIMATED);

        WalletBalanceWidgetProvider.updateWidgets(this, appWidgetManager, appWidgetIds, balance);
    }// ww  w .ja v  a2  s  .c om
}

From source file:org.kiwix.kiwixmobile.KiwixMobileActivity.java

public static void updateWidgets(Context context) {
    Intent intent = new Intent(context.getApplicationContext(), KiwixSearchWidget.class);
    intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    // Use an array and EXTRA_APPWIDGET_IDS instead of AppWidgetManager.EXTRA_APPWIDGET_ID,
    // since it seems the onUpdate() is only fired on that:
    AppWidgetManager widgetManager = AppWidgetManager.getInstance(context);
    int[] ids = widgetManager.getAppWidgetIds(new ComponentName(context, KiwixSearchWidget.class));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        widgetManager.notifyAppWidgetViewDataChanged(ids, android.R.id.list);

        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
        context.sendBroadcast(intent);/*from   www  . ja  v  a 2 s.  c o m*/
    }
}