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.grarak.kerneladiutor.fragments.tools.ProfileFragment.java

private void load(List<RecyclerViewItem> items) {
    mProfiles = new Profiles(getActivity());
    List<Profiles.ProfileItem> profileItems = mProfiles.getAllProfiles();
    if (mTaskerMode && profileItems.size() == 0) {
        Snackbar.make(getRootView(), R.string.no_profiles, Snackbar.LENGTH_LONG).show();
        return;//from w  w w .j a v a2 s  .  c o  m
    }
    for (int i = 0; i < profileItems.size(); i++) {
        final int position = i;
        final CardView cardView = new CardView(getActivity());
        cardView.setOnMenuListener(new CardView.OnMenuListener() {
            @Override
            public void onMenuReady(final CardView cardView, PopupMenu popupMenu) {
                Menu menu = popupMenu.getMenu();
                menu.add(Menu.NONE, 0, Menu.NONE, getString(R.string.append));
                menu.add(Menu.NONE, 1, Menu.NONE, getString(R.string.edit));
                menu.add(Menu.NONE, 2, Menu.NONE, getString(R.string.details));
                final MenuItem onBoot = menu.add(Menu.NONE, 3, Menu.NONE, getString(R.string.on_boot))
                        .setCheckable(true);
                onBoot.setChecked(mProfiles.getAllProfiles().get(position).isOnBootEnabled());
                menu.add(Menu.NONE, 4, Menu.NONE, getString(R.string.export));
                menu.add(Menu.NONE, 5, Menu.NONE, getString(R.string.delete));

                popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        List<Profiles.ProfileItem> items = mProfiles.getAllProfiles();
                        switch (item.getItemId()) {
                        case 0:
                            if (Utils.DONATED) {
                                Intent intent = new Intent(getActivity(), ProfileActivity.class);
                                intent.putExtra(ProfileActivity.POSITION_INTENT, position);
                                startActivityForResult(intent, 2);
                            } else {
                                mDonateDialog = ViewUtils.dialogDonate(getActivity());
                                mDonateDialog.show();
                            }
                            break;
                        case 1:
                            if (Utils.DONATED) {
                                Intent intent = new Intent(getActivity(), ProfileEditActivity.class);
                                intent.putExtra(ProfileEditActivity.POSITION_INTENT, position);
                                startActivityForResult(intent, 3);
                            } else {
                                mDonateDialog = ViewUtils.dialogDonate(getActivity());
                                mDonateDialog.show();
                            }
                            break;
                        case 2:
                            if (items.get(position).getName() != null) {
                                List<Profiles.ProfileItem.CommandItem> commands = items.get(position)
                                        .getCommands();
                                if (commands.size() > 0) {
                                    setForegroundText(items.get(position).getName().toUpperCase());
                                    mDetailsFragment.setText(commands);
                                    showForeground();
                                } else {
                                    Utils.toast(R.string.profile_empty, getActivity());
                                }
                            }
                            break;
                        case 3:
                            onBoot.setChecked(!onBoot.isChecked());
                            items.get(position).enableOnBoot(onBoot.isChecked());
                            mProfiles.commit();
                            break;
                        case 4:
                            mExportProfile = items.get(position);
                            requestPermission(0, Manifest.permission.WRITE_EXTERNAL_STORAGE);
                            break;
                        case 5:
                            mDeleteDialog = ViewUtils.dialogBuilder(getString(R.string.sure_question),
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                        }
                                    }, new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            mProfiles.delete(position);
                                            mProfiles.commit();
                                            reload();
                                        }
                                    }, new DialogInterface.OnDismissListener() {
                                        @Override
                                        public void onDismiss(DialogInterface dialogInterface) {
                                            mDeleteDialog = null;
                                        }
                                    }, getActivity());
                            mDeleteDialog.show();
                            break;
                        }
                        return false;
                    }
                });
            }
        });

        final DescriptionView descriptionView = new DescriptionView();
        descriptionView.setSummary(profileItems.get(i).getName());
        descriptionView.setOnItemClickListener(new RecyclerViewItem.OnItemClickListener() {
            @Override
            public void onClick(RecyclerViewItem item) {
                if (mTaskerMode) {
                    mSelectDialog = ViewUtils.dialogBuilder(
                            getString(R.string.select_question, descriptionView.getSummary()),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                }
                            }, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    ((ProfileTaskerActivity) getActivity()).finish(
                                            descriptionView.getSummary().toString(),
                                            mProfiles.getAllProfiles().get(position).getCommands());
                                }
                            }, new DialogInterface.OnDismissListener() {
                                @Override
                                public void onDismiss(DialogInterface dialogInterface) {
                                    mSelectDialog = null;
                                }
                            }, getActivity());
                    mSelectDialog.show();
                } else {
                    mApplyDialog = ViewUtils.dialogBuilder(
                            getString(R.string.apply_question, descriptionView.getSummary()),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                }
                            }, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    for (Profiles.ProfileItem.CommandItem command : mProfiles.getAllProfiles()
                                            .get(position).getCommands()) {
                                        CPUFreq.ApplyCpu applyCpu;
                                        if (command.getCommand().startsWith("#")
                                                && ((applyCpu = new CPUFreq.ApplyCpu(
                                                        command.getCommand().substring(1)))
                                                                .toString() != null)) {
                                            for (String applyCpuCommand : Service.getApplyCpu(applyCpu,
                                                    RootUtils.getSU())) {
                                                Control.runSetting(applyCpuCommand, null, null, null);
                                            }
                                        } else {
                                            Control.runSetting(command.getCommand(), null, null, null);
                                        }
                                    }
                                }
                            }, new DialogInterface.OnDismissListener() {
                                @Override
                                public void onDismiss(DialogInterface dialogInterface) {
                                    mApplyDialog = null;
                                }
                            }, getActivity());
                    try {
                        mApplyDialog.show();
                    } catch (NullPointerException ignored) {
                    }
                }
            }
        });

        if (mTaskerMode) {
            items.add(descriptionView);
        } else {
            cardView.addItem(descriptionView);
            items.add(cardView);
        }
    }

    if (!mTaskerMode) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getActivity());
        int appWidgetIds[] = appWidgetManager.getAppWidgetIds(new ComponentName(getActivity(), Widget.class));
        appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.profile_list);
        Tile.publishProfileTile(profileItems, getActivity());
    }
}

From source file:com.roymam.android.nilsplus.ui.NiLSActivity.java

private boolean isWidgetPlaced() {
    AppWidgetManager widgetManager = AppWidgetManager.getInstance(this);
    ComponentName widgetComponent = new ComponentName(this, NotificationsWidgetProvider.class);
    int[] widgetIds = widgetManager.getAppWidgetIds(widgetComponent);
    return (widgetIds.length > 0);
}

From source file:com.andryr.musicplayer.PlaybackService.java

private void refreshAppWidgets() {

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
    int appWidgetIds[] = appWidgetManager.getAppWidgetIds(new ComponentName(this, PlaybackWidget.class));
    PlaybackWidget.updateAppWidget(this, appWidgetIds);
}

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

@Override
public void onReceive(Context context, Intent intent) {
    mComtext = context;/*  w w  w .  ja  v a 2  s  .  c  o m*/
    String action = intent.getAction();
    Log.i("sai", "onReceive: " + action);

    super.onReceive(context, intent);

    if (ACTION_ON_QUARTER_HOUR.equals(action) || Intent.ACTION_DATE_CHANGED.equals(action)
            || Intent.ACTION_TIMEZONE_CHANGED.equals(action) || Intent.ACTION_TIME_CHANGED.equals(action)
            || Intent.ACTION_LOCALE_CHANGED.equals(action)) {
        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);
                float ratio = WidgetUtils.getScaleRatio(context, null, appWidgetId);
                // SPRD for bug421127 add am/pm for widget
                WidgetUtils.setTimeFormat(widget,
                        (int) context.getResources().getDimension(R.dimen.widget_label_font_size),
                        R.id.the_clock);
                WidgetUtils.setClockSize(context, widget, ratio);
                //refreshAlarm(context, widget);
                appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget);
            }
        }
        if (!ACTION_ON_QUARTER_HOUR.equals(action)) {
            cancelAlarmOnQuarterHour(context);
        }
        startAlarmOnQuarterHour(context);
    }
    // cg sai.pan begin
    else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
        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);
                refreshBtStatus(context, widget);
                appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget);
            }
        }
    } else if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
        int wifiStatus = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0);
        Log.e("sai", "wifiStatus" + wifiStatus);
        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 (WifiManager.WIFI_STATE_ENABLED == wifiStatus
                        || WifiManager.WIFI_STATE_ENABLING == wifiStatus) {
                    widget.setImageViewResource(R.id.wifi, R.drawable.status_wifi_on);
                } else {
                    widget.setImageViewResource(R.id.wifi, R.drawable.status_wifi_off);
                }
                appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget);
            }
        }
    } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
        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);
                refreshWifiStatus(context, widget);
            }
        }
    } else if ("android.net.conn.CONNECTIVITY_CHANGE".equals(action)) {
        if (isNetworkConnected(context)) {
            Log.e("sai", "isNetworkConnected true");
            requestLocation(context);
        } else {
            Log.e("sai", "isNetworkConnected false");
        }
    }
}

From source file:com.feathercoin.wallet.feathercoin.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  . java 2 s.co  m*/
        appWidgetIds = appWidgetManager.getAppWidgetIds(providerName);
    } catch (RuntimeException e) {
        // Bug #6 - App server dead?
        Log.e("Feathercoin",
                "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:de.schildbach.wallet.digitalcoin.service.BlockchainServiceImpl.java

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

    final ComponentName providerName = new ComponentName(this, WalletBalanceWidgetProvider.class);
    final int[] appWidgetIds;
    try {/*ww w . ja  v a 2s . co m*/
        appWidgetIds = appWidgetManager.getAppWidgetIds(providerName);
    } catch (RuntimeException e) {
        // Bug #6 - App server dead?
        Log.e("digitalcoin",
                "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:de.schildbach.wallet.worldcoin.service.BlockchainServiceImpl.java

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

    final ComponentName providerName = new ComponentName(this, WalletBalanceWidgetProvider.class);
    final int[] appWidgetIds;
    try {/*  w  w w .  jav a2  s  .c o m*/
        appWidgetIds = appWidgetManager.getAppWidgetIds(providerName);
    } catch (RuntimeException e) {
        // Bug #6 - App server dead?
        Log.e("worldcoin",
                "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:de.schildbach.wallet.goldcoin.service.BlockchainServiceImpl.java

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

    final ComponentName providerName = new ComponentName(this, WalletBalanceWidgetProvider.class);
    final int[] appWidgetIds;
    try {/*  w w w  . j a  v  a  2s  . c  o  m*/
        appWidgetIds = appWidgetManager.getAppWidgetIds(providerName);
    } catch (RuntimeException e) {
        // Bug #6 - App server dead?
        Log.e("Litecoin",
                "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

/** Called when the activity is closed. */
@Override//from w w w  . j ava 2s  .c  o m
public void onDestroy() {

    EasyTracker.getTracker().trackEvent("service", "stop", getVersionName(), 0L);

    if (mShutdownReceiver != null) {
        unregisterReceiver(mShutdownReceiver);
        mShutdownReceiver = null;
    }

    statusLock = true;

    stopForegroundCompat(1);

    notifyAlert(getString(R.string.forward_stop), getString(R.string.service_stopped),
            Notification.FLAG_AUTO_CANCEL);

    try {
        if (dnsServer != null)
            dnsServer.close();
    } catch (Exception e) {
        Log.e(TAG, "DNS Server close unexpected");
    }

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

            // Make sure the connection is closed, important here
            onDisconnect();
        }
    }.start();

    // for widget, maybe exception here
    try {
        RemoteViews views = new RemoteViews(getPackageName(), R.layout.gaeproxy_appwidget);
        views.setImageViewResource(R.id.serviceToggle, R.drawable.off);
        AppWidgetManager awm = AppWidgetManager.getInstance(this);
        awm.updateAppWidget(awm.getAppWidgetIds(new ComponentName(this, GAEProxyWidgetProvider.class)), views);
    } catch (Exception ignore) {
        // Nothing
    }

    Editor ed = settings.edit();
    ed.putBoolean("isRunning", false);
    ed.putBoolean("isConnecting", false);
    ed.commit();

    try {
        notificationManager.cancel(0);
    } catch (Exception ignore) {
        // Nothing
    }

    try {
        ProxySettings.resetProxy(this);
    } catch (Exception ignore) {
        // Nothing
    }

    super.onDestroy();

    statusLock = false;

    markServiceStopped();
}

From source file:de.schildbach.wallet.marscoin.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  w ww.  jav a2s  .  c o  m
        appWidgetIds = appWidgetManager.getAppWidgetIds(providerName);
    } catch (RuntimeException e) {
        // Bug #6 - App server dead?
        Log.e("marscoin",
                "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);
    }
}