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:cc.mintcoin.wallet.service.BlockchainServiceImpl.java

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

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

    try {/*from w ww.j  a  v  a2s  . c  o  m*/
        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: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  . co m
    }
}

From source file:mp.teardrop.PlaybackService.java

/**
 * Check if there are any instances of each widget.
 *//*from   www .  j  a v  a  2  s.c  o  m*/
private void initWidgets() {
    AppWidgetManager manager = AppWidgetManager.getInstance(this);
    OneCellWidget.checkEnabled(this, manager);
    FourSquareWidget.checkEnabled(this, manager);
    FourLongWidget.checkEnabled(this, manager);
    FourWhiteWidget.checkEnabled(this, manager);
    WidgetD.checkEnabled(this, manager);
    WidgetE.checkEnabled(this, manager);
}

From source file:mp.teardrop.PlaybackService.java

/**
 * Update the widgets with the current song and state.
 *///  w  ww . j  av a 2s  . co  m
private void updateWidgets() {
    AppWidgetManager manager = AppWidgetManager.getInstance(this);
    Song song = mCurrentSong;
    int state = mState;
    OneCellWidget.updateWidget(this, manager, song, state);
    FourLongWidget.updateWidget(this, manager, song, state);
    FourSquareWidget.updateWidget(this, manager, song, state);
    FourWhiteWidget.updateWidget(this, manager, song, state);
    WidgetD.updateWidget(this, manager, song, state);
    WidgetE.updateWidget(this, manager, song, state);
}

From source file:com.piusvelte.sonet.core.StatusDialog.java

private String[] getAllWidgets() {
    mAppWidgetIds = new int[0];
    // validate appwidgetids with appwidgetmanager
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
    mAppWidgetIds = Sonet.getWidgets(getApplicationContext(), appWidgetManager);

    // older versions had a null widget, remove them
    this.getContentResolver().delete(Widgets.getContentUri(StatusDialog.this), Widgets.WIDGET + "=?",
            new String[] { "" });
    this.getContentResolver().delete(Widget_accounts.getContentUri(StatusDialog.this),
            Widget_accounts.WIDGET + "=?", new String[] { "" });

    String[] widgetsOptions = new String[mAppWidgetIds.length];
    for (int i = 0; i < mAppWidgetIds.length; i++) {
        AppWidgetProviderInfo info = appWidgetManager.getAppWidgetInfo(mAppWidgetIds[i]);
        String providerName = info.provider.getClassName();
        widgetsOptions[i] = Integer.toString(mAppWidgetIds[i]) + " (" + providerName + ")";
    }/*from  w w  w  .  ja  v a  2 s  .  c om*/
    return widgetsOptions;
}

From source file:com.shafiq.myfeedle.core.StatusDialog.java

private String[] getAllWidgets() {
    mAppWidgetIds = new int[0];
    // validate appwidgetids with appwidgetmanager
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
    mAppWidgetIds = Myfeedle.getWidgets(getApplicationContext(), appWidgetManager);

    // older versions had a null widget, remove them
    this.getContentResolver().delete(Widgets.getContentUri(StatusDialog.this), Widgets.WIDGET + "=?",
            new String[] { "" });
    this.getContentResolver().delete(Widget_accounts.getContentUri(StatusDialog.this),
            Widget_accounts.WIDGET + "=?", new String[] { "" });

    String[] widgetsOptions = new String[mAppWidgetIds.length];
    for (int i = 0; i < mAppWidgetIds.length; i++) {
        AppWidgetProviderInfo info = appWidgetManager.getAppWidgetInfo(mAppWidgetIds[i]);
        String providerName = info.provider.getClassName();
        widgetsOptions[i] = Integer.toString(mAppWidgetIds[i]) + " (" + providerName + ")";
    }/*from   w ww .  j av a 2 s. co m*/
    return widgetsOptions;
}

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   w ww .  j  a v  a  2 s .c om*/
    }
}

From source file:de.azapps.mirakel.main_activity.MainActivity.java

@SuppressLint("NewApi")
@Override//w  ww.jav a 2 s  . c  om
protected void onPause() {
    if (getTasksFragment() != null) {
        getTasksFragment().clearFocus();
    }
    final Intent intent = new Intent(this, MainWidgetProvider.class);
    intent.setAction("android.appwidget.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:
    final Context context = getApplicationContext();
    final ComponentName name = new ComponentName(context, MainWidgetProvider.class);
    final int widgets[] = AppWidgetManager.getInstance(context).getAppWidgetIds(name);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgets);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        for (final int id : widgets) {
            AppWidgetManager.getInstance(this).notifyAppWidgetViewDataChanged(id, R.id.widget_tasks_list);
        }
    }
    sendBroadcast(intent);
    TaskDialogHelpers.stopRecording();
    super.onPause();
}

From source file:com.aniruddhc.acemusic.player.Services.AudioPlaybackService.java

/**
 * Updates all open homescreen/lockscreen widgets.
 *///from  w  ww .j  av  a  2 s  . c o m
public void updateWidgets() {
    try {
        //Fire a broadcast message to the widget(s) to update them.
        Intent smallWidgetIntent = new Intent(mContext, SmallWidgetProvider.class);
        smallWidgetIntent.setAction("android.appwidget.action.APPWIDGET_UPDATE");
        int smallWidgetIds[] = AppWidgetManager.getInstance(mContext)
                .getAppWidgetIds(new ComponentName(mContext, SmallWidgetProvider.class));
        smallWidgetIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, smallWidgetIds);
        mContext.sendBroadcast(smallWidgetIntent);

        Intent largeWidgetIntent = new Intent(mContext, LargeWidgetProvider.class);
        largeWidgetIntent.setAction("android.appwidget.action.APPWIDGET_UPDATE");
        int largeWidgetIds[] = AppWidgetManager.getInstance(mContext)
                .getAppWidgetIds(new ComponentName(mContext, LargeWidgetProvider.class));
        largeWidgetIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, largeWidgetIds);
        mContext.sendBroadcast(largeWidgetIntent);

        Intent blurredWidgetIntent = new Intent(mContext, BlurredWidgetProvider.class);
        blurredWidgetIntent.setAction("android.appwidget.action.APPWIDGET_UPDATE");
        int blurredWidgetIds[] = AppWidgetManager.getInstance(mContext)
                .getAppWidgetIds(new ComponentName(mContext, BlurredWidgetProvider.class));
        blurredWidgetIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, blurredWidgetIds);
        mContext.sendBroadcast(blurredWidgetIntent);

        Intent albumArtWidgetIntent = new Intent(mContext, AlbumArtWidgetProvider.class);
        albumArtWidgetIntent.setAction("android.appwidget.action.APPWIDGET_UPDATE");
        int albumArtWidgetIds[] = AppWidgetManager.getInstance(mContext)
                .getAppWidgetIds(new ComponentName(mContext, AlbumArtWidgetProvider.class));
        albumArtWidgetIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, albumArtWidgetIds);
        mContext.sendBroadcast(albumArtWidgetIntent);

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.homeworkreminder.Main.java

public static void updateAppWidget() {
    Intent intent = new Intent(context, Widget.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:
    int ids[] = AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName(context, Widget.class));
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
    context.sendBroadcast(intent);/*  ww  w . j  a v a 2 s. c  o  m*/
}