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:de.schildbach.wallet.elysium.service.BlockchainServiceImpl.java

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

    final ComponentName providerName = new ComponentName(this, WalletBalanceWidgetProvider.class);
    final int[] appWidgetIds;
    try {/*from  ww w .  j  a va 2  s. c o m*/
        appWidgetIds = appWidgetManager.getAppWidgetIds(providerName);
    } catch (RuntimeException e) {
        // Bug #6 - App server dead?
        Log.e("Elysium",
                "App server appears dead - Runtime Exception when running getAppWidgetIds.  Returning..");
        return;
    }

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

        WalletBalanceWidgetProvider.updateWidgets(this, appWidgetManager, appWidgetIds, balance);
    }
}

From source file:org.gaeproxy.GAEProxyService.java

public void handleCommand(Intent intent) {

    if (intent == null) {
        stopSelf();//from   ww w  . j  a va  2s  .c  o m
        return;
    }

    proxyType = settings.getString("proxyType", "GAE");
    sitekey = settings.getString("sitekey", "");
    try {
        port = Integer.valueOf(settings.getString("port", "1984"));
    } catch (NumberFormatException ex) {
        port = 1984;
    }

    isGlobalProxy = settings.getBoolean("isGlobalProxy", false);
    isGFWList = settings.getBoolean("isGFWList", false);
    isBypassApps = settings.getBoolean("isBypassApps", false);

    if (!parseProxyURL(settings.getString("proxy", "proxyofmax.appspot.com"))) {
        stopSelf();
        return;
    }

    if (!"GAE".equals(proxyType) && !"PaaS".equals(proxyType)) {
        proxyType = "GAE";
    }

    if ("fetch.py".equals(appPath))
        appPath = "2";

    Log.e(TAG, "Proxy: " + appId + " " + appPath);
    Log.e(TAG, "Local Port: " + port);

    new Thread(new Runnable() {
        @Override
        public void run() {

            handler.sendEmptyMessage(MSG_CONNECT_START);

            Log.d(TAG, "IPTABLES: " + Utils.getIptables());

            // Test for Redirect Support
            hasRedirectSupport = Utils.getHasRedirectSupport();

            if (handleConnection()) {
                // Connection and forward successful
                notifyAlert(getString(R.string.forward_success), getString(R.string.service_running));

                handler.sendEmptyMessageDelayed(MSG_CONNECT_SUCCESS, 500);

                // for widget, maybe exception here
                try {
                    RemoteViews views = new RemoteViews(getPackageName(), R.layout.gaeproxy_appwidget);
                    views.setImageViewResource(R.id.serviceToggle, R.drawable.on);
                    AppWidgetManager awm = AppWidgetManager.getInstance(GAEProxyService.this);
                    awm.updateAppWidget(
                            awm.getAppWidgetIds(
                                    new ComponentName(GAEProxyService.this, GAEProxyWidgetProvider.class)),
                            views);
                } catch (Exception ignore) {
                    // Nothing
                }
            } else {
                // Connection or forward unsuccessful
                notifyAlert(getString(R.string.forward_fail), getString(R.string.service_failed));

                stopSelf();
                handler.sendEmptyMessageDelayed(MSG_CONNECT_FAIL, 500);
            }

            handler.sendEmptyMessageDelayed(MSG_CONNECT_FINISH, 500);
        }
    }).start();
    markServiceStarted();
}

From source file:net.naonedbus.appwidget.HoraireWidgetProvider.java

/**
 * Grer le signal de rafraichissement.//from w  ww . j  a  v a  2  s  .c o  m
 */
@Override
public void onReceive(final Context context, final Intent intent) {
    final String action = intent.getAction();
    final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);

    if (DBG)
        Log.i(LOG_TAG, Integer.toHexString(hashCode()) + " - " + "onReceive " + action);

    final boolean updateWidget = ACTION_APPWIDGET_UPDATE.equals(action)
            || Intent.ACTION_USER_PRESENT.equals(action);

    if (updateWidget) {

        final int idExtra = intent.getIntExtra("id", -1);
        int[] ids;

        if (DBG)
            Log.i(LOG_TAG, Integer.toHexString(hashCode()) + " - "
                    + "Rception de l'ordre de rafraichissement des widgets.");

        if (idExtra == -1) {
            ids = appWidgetManager.getAppWidgetIds(new ComponentName(context, this.getClass()));
        } else {
            ids = new int[] { idExtra };
        }

        onUpdate(context, appWidgetManager, ids);

    } else if (HoraireWidgetProvider.ACTION_APPWIDGET_ON_CLICK.equals(action)) {

        final Arret arret = intent.getParcelableExtra("favori");
        if (arret != null) {
            final ParamIntent startIntent = new ParamIntent(context, HorairesActivity.class);
            startIntent.putExtra(HorairesActivity.PARAM_ARRET, arret);
            startIntent.putExtra(HorairesActivity.PARAM_FROM_WIDGET, true);
            startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            final TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
            stackBuilder.addParentStack(MainActivity.class);
            stackBuilder.addNextIntentWithParentStack(startIntent);

            stackBuilder.startActivities();
        }
    }

    super.onReceive(context, intent);
}

From source file:cc.mintcoin.wallet.service.BlockchainServiceImpl.java

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

    final ComponentName providerName = new ComponentName(this, WalletBalanceWidgetProvider.class);

    try {// w  ww . ja v a2s .  c  om
        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);
        }
    } catch (final RuntimeException x) // system server dead?
    {
        log.warn("cannot update app widgets", x);
    }
}

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

@Override
protected void onPostExecute(JSONObject jsonObject) {
    if (jsonObject != null) {
        try {//  w  w w.j a 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:piuk.blockchain.android.WalletApplication.java

public void notifyWidgets() {
    final Context context = getApplicationContext();

    // notify widgets
    final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    for (final AppWidgetProviderInfo providerInfo : appWidgetManager.getInstalledProviders()) {
        // limit to own widgets
        if (providerInfo.provider.getPackageName().equals(context.getPackageName())) {
            final Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS,
                    appWidgetManager.getAppWidgetIds(providerInfo.provider));
            context.sendBroadcast(intent);
        }/*from  w ww .  jav a 2  s  .  c o  m*/
    }
}

From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.java

public void onBackPressed() {
    if (widgetFirstTimeSetup) {
        finishWidgetSetup();/*from  w w  w . j a  v a2s  .  c  o  m*/
        return;
    }
    // check if sort has changed
    if (needsFeedUpdate || needsFeedViewUpdate || needsThemeUpdate) {
        if (mAppWidgetId != 0) {
            AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(SubredditSelectActivity.this);
            RemoteViews views = new RemoteViews(getPackageName(), R.layout.widget);
            views.setViewVisibility(R.id.srloader, View.VISIBLE);
            views.setViewVisibility(R.id.erroricon, View.INVISIBLE);
            // bypass the cached entrys only if the sorting preference has changed
            if (needsFeedUpdate) {
                global.setBypassCache(true);
            } else {
                global.setRefreshView();
            }
            if (needsThemeUpdate) {
                WidgetProvider.updateAppWidgets(SubredditSelectActivity.this, appWidgetManager,
                        new int[] { mAppWidgetId }, false);
            } else {
                appWidgetManager.partiallyUpdateAppWidget(mAppWidgetId, views);
            }
            appWidgetManager.notifyAppWidgetViewDataChanged(mAppWidgetId, R.id.listview);
        } else {
            Intent intent = new Intent();
            intent.putExtra("themeupdate", needsThemeUpdate);
            if (needsFeedUpdate) {
                setResult(2, intent); // reload feed and prefs
            } else {
                setResult(1, intent); // tells main activity to update feed prefs
            }
            if (needsThemeUpdate) {
                global.setRefreshView();
                AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(SubredditSelectActivity.this);
                int[] widgetIds = appWidgetManager
                        .getAppWidgetIds(new ComponentName(SubredditSelectActivity.this, WidgetProvider.class));
                WidgetProvider.updateAppWidgets(SubredditSelectActivity.this, appWidgetManager, widgetIds,
                        false);
                appWidgetManager.notifyAppWidgetViewDataChanged(widgetIds, R.id.listview);
            }
        }
    } else {
        setResult(0);
    }
    finish();
}

From source file:org.openintents.shopping.ui.ShoppingActivity.java

private void updateWidgets() {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
    int[] a = appWidgetManager
            .getAppWidgetIds(new ComponentName(this.getPackageName(), CheckItemsWidget.class.getName()));
    List<AppWidgetProviderInfo> b = appWidgetManager.getInstalledProviders();
    for (AppWidgetProviderInfo i : b) {
        if (i.provider.getPackageName().equals(this.getPackageName())) {
            a = appWidgetManager.getAppWidgetIds(i.provider);
            new CheckItemsWidget().onUpdate(this, appWidgetManager, a);
        }/*w  w  w .  j av a  2 s.  c  o m*/
    }
}