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.nogago.android.tracks.widgets.TrackWidgetProvider.java

/**
 * Updates the widget.// ww w . ja  va2  s  .com
 * 
 * @param action the action
 */
private void updateTrack(String action) {
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.track_widget);

    if (action != null) {
        updateButton(remoteViews, action);
    }
    updateView(remoteViews);

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    int[] appWidgetIds = appWidgetManager
            .getAppWidgetIds(new ComponentName(context, TrackWidgetProvider.class));
    for (int appWidgetId : appWidgetIds) {
        appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
    }
}

From source file:org.fairphone.peaceofmind.PeaceOfMindBroadCastReceiver.java

private void updateWidget(Context context) {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, WidgetProvider.class));
    if (appWidgetIds.length > 0) {
        new WidgetProvider().onUpdate(context, appWidgetManager, appWidgetIds);
    }//w ww .  java2 s.  c om
}

From source file:org.namelessrom.devicecontrol.widgets.RebootWidget.java

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] ids) {
    final ComponentName widget = new ComponentName(context, RebootWidget.class);

    final int[] allWidgetInstancesIds = appWidgetManager.getAppWidgetIds(widget);
    for (int widgetId : allWidgetInstancesIds) {
        final RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_reboot);

        final Intent intent = new Intent(context, RebootWidget.class);
        intent.setAction(SHOW_POPUP_DIALOG_REBOOT_ACTION);

        final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        remoteViews.setOnClickPendingIntent(R.id.widget_reboot_image, pendingIntent);

        appWidgetManager.updateAppWidget(widgetId, remoteViews);
    }/*from w  w  w  .  jav  a2 s .c o m*/

    super.onUpdate(context, appWidgetManager, ids);
}

From source file:de.micmun.android.workdaystarget.DaysLeftService.java

/**
 * Updates the days to target./*from  w  w w .  ja  v  a 2s. com*/
 */
private void updateDays() {
    AppWidgetManager appManager = AppWidgetManager.getInstance(this);
    ComponentName cName = new ComponentName(getApplicationContext(), DaysLeftProvider.class);
    int[] appIds = appManager.getAppWidgetIds(cName);

    DayCalculator dayCalc = new DayCalculator();
    if (!isOnline()) {
        try {
            Thread.sleep(60000);
        } catch (InterruptedException e) {
            Log.e(TAG, "Interrupted: " + e.getLocalizedMessage());
        }
    }

    for (int appId : appIds) {
        PrefManager pm = new PrefManager(this, appId);
        Calendar target = pm.getTarget();
        boolean[] chkDays = pm.getCheckedDays();
        int days = pm.getLastDiff();

        if (isOnline()) {
            try {
                days = dayCalc.getDaysLeft(target.getTime(), chkDays);
                Map<String, Object> saveMap = new HashMap<String, Object>();
                Long diff = Long.valueOf(days);
                saveMap.put(PrefManager.KEY_DIFF, diff);
                pm.save(saveMap);
            } catch (JSONException e) {
                Log.e(TAG, "ERROR holidays: " + e.getLocalizedMessage());
            }
        } else {
            Log.e(TAG, "No internet connection!");
        }
        RemoteViews rv = new RemoteViews(this.getPackageName(), R.layout.appwidget_layout);
        DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
        String targetStr = df.format(target.getTime());
        rv.setTextViewText(R.id.target, targetStr);
        String dayStr = String.format(Locale.getDefault(), "%d %s", days,
                getResources().getString(R.string.unit));
        rv.setTextViewText(R.id.dayCount, dayStr);

        // put widget id into intent
        Intent configIntent = new Intent(this, ConfigActivity.class);
        configIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        configIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        configIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appId);
        configIntent.setData(Uri.parse(configIntent.toUri(Intent.URI_INTENT_SCHEME)));
        PendingIntent pendIntent = PendingIntent.getActivity(this, 0, configIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        rv.setOnClickPendingIntent(R.id.widgetLayout, pendIntent);

        // update widget
        appManager.updateAppWidget(appId, rv);
    }
}

From source file:org.solovyev.android.calculator.widget.CalculatorWidget.java

public void updateWidget(@Nonnull Context context, boolean partially) {
    final AppWidgetManager manager = AppWidgetManager.getInstance(context);
    final int[] widgetIds = manager.getAppWidgetIds(new ComponentName(context, CalculatorWidget.class));
    updateWidget(context, manager, widgetIds, partially);
}

From source file:me.kartikarora.transfersh.activities.TransferActivity.java

public void updateWidgets() {
    Intent intent = new Intent(TransferActivity.this, FilesAppWidgetProvider.class);
    intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    AppWidgetManager widgetManager = AppWidgetManager.getInstance(getApplicationContext());
    int[] ids = widgetManager
            .getAppWidgetIds(new ComponentName(getApplicationContext(), FilesAppWidgetProvider.class));
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
    sendBroadcast(intent);//  www  .  j a  va 2  s .com
}

From source file:mmpud.project.daycountwidget.DayCountMainActivity.java

private void updateAdapter() {
    mAdapter.clear();/*  w w w  .j  a v a  2  s  .c  om*/
    // query from database
    if (mDbHelper == null) {
        mDbHelper = new DayCountDbHelper(this);
    }
    SQLiteDatabase db = mDbHelper.getReadableDatabase();

    // get all available day count widget ids
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
    ComponentName component = new ComponentName(this, DayCountWidgetProvider.class);
    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(component);
    for (int appWidgetId : appWidgetIds) {
        Cursor cursor = db.query(Contract.Widget.TABLE_NAME, null, Contract.Widget.WIDGET_ID + "=?",
                new String[] { String.valueOf(appWidgetId) }, null, null, null);
        long targetDateMillis;
        String title;
        String bodyStyle;
        int countBy;
        if (cursor.moveToFirst()) {
            targetDateMillis = cursor.getLong(cursor.getColumnIndexOrThrow(TARGET_DATE));
            title = cursor.getString(cursor.getColumnIndexOrThrow(EVENT_TITLE));
            bodyStyle = cursor.getString(cursor.getColumnIndexOrThrow(BODY_STYLE));
            countBy = cursor.getInt(cursor.getColumnIndexOrThrow(COUNT_BY));
        } else {
            targetDateMillis = LocalDate.now().atStartOfDay().atZone(ZoneOffset.UTC).toInstant().toEpochMilli();
            title = "";
            bodyStyle = String.valueOf(ContextCompat.getColor(this, R.color.body_black));
            countBy = COUNT_BY_DAY;
        }
        mAdapter.add(new DayCountWidget(appWidgetId, title, null, targetDateMillis, countBy, null, bodyStyle));
        cursor.close();
    }
    db.close();
}

From source file:com.google.android.apps.mytracks.widgets.TrackWidgetProvider.java

/**
 * Updates the widget.//from   ww  w.  j  a v a  2  s.  c o  m
 * 
 * @param context the context
 * @param trackId the track id
 */
private void update(Context context, long trackId) {
    // Get the preferences
    long recordingTrackId = PreferencesUtils.getLong(context, R.string.recording_track_id_key);
    boolean recordingTrackPaused = PreferencesUtils.getBoolean(context, R.string.recording_track_paused_key,
            PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
    boolean metricUnits = PreferencesUtils.getBoolean(context, R.string.metric_units_key,
            PreferencesUtils.METRIC_UNITS_DEFAULT);

    // Get track and trip statistics
    MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context);
    if (trackId == -1L) {
        trackId = recordingTrackId;
    }
    if (trackId == -1L) {
        trackId = PreferencesUtils.getLong(context, R.string.selected_track_id_key);
    }
    Track track = trackId != -1L ? myTracksProviderUtils.getTrack(trackId)
            : myTracksProviderUtils.getLastTrack();
    TripStatistics tripStatistics = track == null ? null : track.getTripStatistics();
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.track_widget);
    boolean isRecording = recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;

    updateStatisticsContainer(context, remoteViews, track);
    updateTotalDistance(context, remoteViews, tripStatistics, metricUnits);
    updateTotalTime(remoteViews, tripStatistics, isRecording, recordingTrackPaused);
    updateAverageSpeed(context, remoteViews, tripStatistics, metricUnits);
    updateMovingTime(context, remoteViews, tripStatistics);
    updateRecordButton(context, remoteViews, isRecording, recordingTrackPaused);
    updateRecordStatus(context, remoteViews, isRecording, recordingTrackPaused);
    updateStopButton(context, remoteViews, isRecording);

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    int[] appWidgetIds = appWidgetManager
            .getAppWidgetIds(new ComponentName(context, TrackWidgetProvider.class));
    for (int appWidgetId : appWidgetIds) {
        appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
    }
}

From source file:se.frikod.payday.DailyBudgetFragment.java

public void updateBudget() {

    try {/*from   w  w w.j  av  a2  s  . co  m*/
        budget.update();
    } catch (WrongAPIKeyException e) {
        activity.runSetup();
        return;
    } catch (AccountNotFoundException e) {
        activity.runSetup();
        return;
    }

    AppWidgetManager man = AppWidgetManager.getInstance(activity);
    int[] ids = man.getAppWidgetIds(new ComponentName(activity, PaydayWidget.class));

    Intent updateIntent = new Intent();
    updateIntent.setClass(activity, PaydayWidget.class);
    updateIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    updateIntent.putExtra(PaydayWidget.WIDGET_IDS_KEY, ids);
    activity.sendBroadcast(updateIntent);

    if (android.os.Build.VERSION.SDK_INT >= 11) {
        renderBudgetAnimated();
    } else {
        renderBudget(budget.dailyBudget);
    }
    currentBudget = budget.dailyBudget;

}

From source file:com.miz.service.TheTVDB.java

private void updateWidgets() {
    AppWidgetManager awm = AppWidgetManager.getInstance(this);
    awm.notifyAppWidgetViewDataChanged(/* w  w w  .  j av a2s . com*/
            awm.getAppWidgetIds(new ComponentName(this, ShowStackWidgetProvider.class)), R.id.stack_view); // Update stack view widget
    awm.notifyAppWidgetViewDataChanged(
            awm.getAppWidgetIds(new ComponentName(this, ShowCoverWidgetProvider.class)), R.id.widget_grid); // Update grid view widget
    awm.notifyAppWidgetViewDataChanged(
            awm.getAppWidgetIds(new ComponentName(this, ShowBackdropWidgetProvider.class)), R.id.widget_grid); // Update grid view widget
}