Example usage for android.appwidget AppWidgetManager getInstance

List of usage examples for android.appwidget AppWidgetManager getInstance

Introduction

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

Prototype

public static AppWidgetManager getInstance(Context context) 

Source Link

Document

Get the AppWidgetManager instance to use for the supplied android.content.Context Context object.

Usage

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

/**
 * Updates frequent contacts widget//from w ww.j  ava  2s. c  om
 */
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.darshancomputing.BatteryIndicatorPro.BatteryInfoService.java

@Override
public void onCreate() {
    res = getResources();//from   ww w .j a v a 2s. c om
    str = new Str(res);
    log_db = new LogDatabase(this);

    info = new BatteryInfo();

    messenger = new Messenger(new MessageHandler());
    clientMessengers = new java.util.HashSet<Messenger>();

    predictor = new Predictor(this);
    bl = BatteryLevel.getInstance(this, BatteryLevel.SIZE_NOTIFICATION);
    cwbg = new CircleWidgetBackground(this);

    alarms = new AlarmDatabase(this);

    mNotificationManager = NotificationManagerCompat.from(this);
    mainNotificationB = new NotificationCompat.Builder(this);

    alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    loadSettingsFiles();
    sdkVersioning();

    currentHack = CurrentHack.getInstance(this);
    currentHack.setPreferFS(settings.getBoolean(SettingsActivity.KEY_CURRENT_HACK_PREFER_FS,
            res.getBoolean(R.bool.default_prefer_fs_current_hack)));

    Intent currentInfoIntent = new Intent(this, BatteryInfoActivity.class).putExtra(EXTRA_CURRENT_INFO, true);
    currentInfoPendingIntent = PendingIntent.getActivity(this, RC_MAIN, currentInfoIntent, 0);

    Intent updatePredictorIntent = new Intent(this, BatteryInfoService.class);
    updatePredictorIntent.putExtra(EXTRA_UPDATE_PREDICTOR, true);
    updatePredictorPendingIntent = PendingIntent.getService(this, 0, updatePredictorIntent, 0);

    Intent alarmsIntent = new Intent(this, BatteryInfoActivity.class).putExtra(EXTRA_EDIT_ALARMS, true);
    alarmsPendingIntent = PendingIntent.getActivity(this, RC_ALARMS, alarmsIntent, 0);

    widgetManager = AppWidgetManager.getInstance(this);

    Class[] appWidgetProviders = { BatteryInfoAppWidgetProvider.class, /* Circle widget! */
            FullAppWidgetProvider.class };

    for (int i = 0; i < appWidgetProviders.length; i++) {
        int[] ids = widgetManager.getAppWidgetIds(new ComponentName(this, appWidgetProviders[i]));

        for (int j = 0; j < ids.length; j++) {
            widgetIds.add(ids[j]);
        }
    }

    Intent bc_intent = registerReceiver(mBatteryInfoReceiver, batteryChanged);
    info.load(bc_intent, sp_service);
}

From source file:com.shanet.relayremote.Main.java

private void setRelayStates(ArrayList<BasicNameValuePair> states) {
    if (states == null)
        return;/* ww  w  .  j  av  a  2 s.  co m*/

    // The server these states correspond to is the first entry
    String server = states.get(0).getValue();

    Relay relay;
    ArrayList<Bundle> widgets = database.selectAllWidgets();

    relay_loop: for (int i = 0; i < relays.size(); i++) {
        relay = relays.get(i);

        // If the current relay belongs to the server the states belong to, find it's state by matching pins
        if (relay.getServer().equals(server)) {
            for (int j = 1; j < states.size(); j++) {
                if (relay.getPin() == Integer.valueOf(states.get(j).getName())) {
                    if (states.get(j).getValue().charAt(0) == Constants.CMD_ON) {
                        relay.turnOn();
                    } else {
                        relay.turnOff();
                    }

                    // Check if any widgets are assigned to this relay, and if so, update them
                    for (Bundle widget : widgets) {
                        if (widget.getInt("type") == Constants.WIDGET_RELAY
                                && widget.getInt("id") == relay.getRid()) {
                            // Update the indicator image
                            RemoteViews views = new RemoteViews(this.getPackageName(), R.layout.widget);
                            views.setImageViewResource(R.id.widgetIndicator,
                                    (states.get(i).getValue().charAt(0) == Constants.CMD_ON)
                                            ? R.drawable.widget_on
                                            : R.drawable.widget_off);
                            AppWidgetManager.getInstance(this).updateAppWidget(widget.getInt("wid"), views);

                            // Set the state of the widget in the widget class
                            Widget.setState(widget.getInt("wid"),
                                    (states.get(i).getValue().charAt(0) == Constants.CMD_ON) ? Widget.STATE_ON
                                            : Widget.STATE_OFF);
                        }
                    }

                    // Done with this relay; move to the next one
                    continue relay_loop;
                }
            }
        }
    }
}

From source file:org.gnucash.android.ui.widget.WidgetConfigurationActivity.java

/**
 * Updates all widgets belonging to the application
 * @param context Application context//from w  w  w. j a  va2 s.  c  o  m
 */
public static void updateAllWidgets(Context context) {
    Log.i("WidgetConfiguration", "Updating all widgets");
    AppWidgetManager widgetManager = AppWidgetManager.getInstance(context);
    ComponentName componentName = new ComponentName(context, TransactionAppWidgetProvider.class);
    int[] appWidgetIds = widgetManager.getAppWidgetIds(componentName);

    SharedPreferences defaultSharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    for (int widgetId : appWidgetIds) {
        long accountId = defaultSharedPrefs.getLong(UxArgument.SELECTED_ACCOUNT_ID + widgetId, -1);

        if (accountId <= 0)
            continue;
        updateWidget(context, widgetId, accountId);
    }
}

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 . j av  a2s  .  co m*/
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:com.google.android.apps.dashclock.DashClockService.java

/**
 * Updates a widget's UI./*from   w ww  .j a v a2s  . co  m*/
 */
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.ferid.app.cleaner.MainActivity.java

/**
 * Update cleaner widget/* w w w.  j  ava2s .  c o m*/
 */
private void updateCleanerWidget() {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    ComponentName thisAppWidget = new ComponentName(context.getPackageName(), this.getClass().getName());
    Intent updateWidget = new Intent(context, CleanerWidget.class);
    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisAppWidget);
    updateWidget.setAction(CleanerWidget.APP_TO_WID);
    updateWidget.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
    context.sendBroadcast(updateWidget);
}

From source file:de.eidottermihi.rpicheck.widget.OverclockingWidget.java

@Override
public void onEnabled(Context context) {
    ComponentName thisAppWidget = new ComponentName(context.getPackageName(),
            OverclockingWidget.class.getName());
    int[] appWidgetIds = AppWidgetManager.getInstance(context).getAppWidgetIds(thisAppWidget);

    for (int appWidgetId : appWidgetIds) {
        // Restoring scheduled alarm after reboot for every widget
        OverclockingWidgetConfigureActivity.settingScheduledAlarm(context, appWidgetId);
    }/*from  w w  w  . j ava 2 s . c  o  m*/
}

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

@SuppressLint("NewApi")
public void updateWidget() {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

        AppWidgetManager appManager = AppWidgetManager.getInstance(this);
        ComponentName name = new ComponentName(this, WidgetProvider.class);
        appManager.notifyAppWidgetViewDataChanged(appManager.getAppWidgetIds(name), R.id.words);
    }//from   www .j  av a  2s. c o  m
}

From source file:de.hackerspacebremen.push.PushIntentService.java

private void updateAppWidget(Context context, SpaceData data) {
    SharedPreferences dataPersistence = getSharedPreferences(Constants.SPACE_DATA_PERSISTENCE,
            Context.MODE_PRIVATE);
    Editor editor = dataPersistence.edit();
    editor.putBoolean(Constants.SPACE_OPEN_DATA_KEY, data.isSpaceOpen());
    editor.commit();/*  w  w  w.  j a va  2 s.  c  om*/

    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.appwidget);
    remoteViews.setViewVisibility(R.id.indicatorImage, View.VISIBLE);
    remoteViews.setViewVisibility(R.id.errorText, View.GONE);

    if (data.isSpaceOpen()) {
        remoteViews.setImageViewResource(R.id.indicatorImage, R.drawable.banner);
    } else {
        remoteViews.setImageViewResource(R.id.indicatorImage, R.drawable.banner_blur);
    }

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    ComponentName componentName = new ComponentName(context, HackerspaceWidgetProvider.class);
    appWidgetManager.updateAppWidget(componentName, remoteViews);
}