Example usage for android.appwidget AppWidgetManager ACTION_APPWIDGET_UPDATE

List of usage examples for android.appwidget AppWidgetManager ACTION_APPWIDGET_UPDATE

Introduction

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

Prototype

String ACTION_APPWIDGET_UPDATE

To view the source code for android.appwidget AppWidgetManager ACTION_APPWIDGET_UPDATE.

Click Source Link

Document

Sent when it is time to update your AppWidget.

Usage

From source file:eu.power_switch.widget.provider.ReceiverWidgetProvider.java

/**
 * Forces an Update of all Receiver Widgets
 *
 * @param context any suitable context//w w  w  .  jav a 2  s .c  om
 */
public static void forceWidgetUpdate(Context context) {
    // update receiver widgets
    Intent intent = new Intent(context, ReceiverWidgetProvider.class);
    intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    int ids[] = AppWidgetManager.getInstance(context.getApplicationContext())
            .getAppWidgetIds(new ComponentName(context.getApplicationContext(), ReceiverWidgetProvider.class));
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
    context.sendBroadcast(intent);
}

From source file:ch.fixme.status.Widget.java

public void onReceive(Context ctxt, Intent intent) {
    String action = intent.getAction();
    if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
        // Remove widget alarm
        int widgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                AppWidgetManager.INVALID_APPWIDGET_ID);
        PendingIntent pi = PendingIntent.getService(ctxt, widgetId, getIntent(ctxt, widgetId), 0);
        AlarmManager am = (AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE);
        am.cancel(pi);//from   w ww.  j  a  v a  2 s. com

        // remove preference
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctxt);
        Editor edit = prefs.edit();
        edit.remove(Main.PREF_API_URL_WIDGET + widgetId);
        edit.remove(Main.PREF_INIT_WIDGET + widgetId);
        edit.remove(Main.PREF_LAST_WIDGET + widgetId);
        edit.remove(Main.PREF_FORCE_WIDGET + widgetId);
        edit.commit();

        // Log.i(Main.TAG, "Remove widget alarm for id=" + widgetId);
    } else if (intent.hasExtra(WIDGET_IDS) && AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) {
        int[] ids = intent.getExtras().getIntArray(WIDGET_IDS);
        onUpdate(ctxt, AppWidgetManager.getInstance(ctxt), ids);
    } else
        super.onReceive(ctxt, intent);
}

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

@Override
public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);
    String action = intent.getAction();
    if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)
            || AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)
            || context.getString(R.string.track_paused_broadcast_action).equals(action)
            || context.getString(R.string.track_resumed_broadcast_action).equals(action)
            || context.getString(R.string.track_started_broadcast_action).equals(action)
            || context.getString(R.string.track_stopped_broadcast_action).equals(action)
            || context.getString(R.string.track_update_broadcast_action).equals(action)) {
        long trackId = intent.getLongExtra(context.getString(R.string.track_id_broadcast_extra), -1L);
        update(context, trackId);/*from  w  ww  .ja  v  a2s  .c  o  m*/
    }
}

From source file:ru.yandex.subtitles.ui.appwidget.AbstractAppWidget.java

@Override
public void onReceive(@NonNull final Context context, @NonNull final Intent intent) {
    super.onReceive(context, intent);

    final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    final ComponentName componentName = new ComponentName(context, getClass());
    final int[] widgetIds = appWidgetManager.getAppWidgetIds(componentName);

    final String action = intent.getAction();
    if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)
            || ACTION_APPWIDGET_DATASET_CHANGED.equals(action)) {
        notifyAppWidgetsViewDataChanged(appWidgetManager, widgetIds);

    } else if (getStartConversationAction().equals(action)) {
        startConversation(context, intent);

    }//from ww  w  .  j a v a  2 s  .com
}

From source file:de.baumann.browser.helper.Activity_intent.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    onNewIntent(getIntent());// w  w  w. ja  va  2  s  . co m
    android.content.Intent intent = getIntent();

    Uri data = intent.getData();

    String domain;
    if (Uri.parse(data.toString()).getHost().length() == 0) {
        domain = getString(R.string.app_domain);
    } else {
        domain = Uri.parse(data.toString()).getHost();
    }

    if (domain.contains("www.")) {
        domain = domain.replace("www.", "").toUpperCase();
    }

    String domain2 = domain.substring(0, 1).toUpperCase() + domain.substring(1);

    PreferenceManager.setDefaultValues(this, R.xml.user_settings, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_search, false);
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    sharedPref.edit().putString("add_readLater_link", data.toString()).apply();
    sharedPref.edit().putString("add_readLater_domain", domain2).apply();

    Random rand = new Random();
    int n = rand.nextInt(100000);

    android.content.Intent iMain = new android.content.Intent();
    iMain.setData(data);
    iMain.setAction(Intent.ACTION_VIEW);
    iMain.setClassName(Activity_intent.this, "de.baumann.browser.Browser_left");

    android.content.Intent iAction = new android.content.Intent(this, Browser_left.class);
    iAction.setAction("readLater");

    android.content.Intent iAction_2 = new android.content.Intent(this, Activity_intent_add.class);
    iAction_2.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);

    PendingIntent piMain = PendingIntent.getActivity(this, n, iMain, 0);
    PendingIntent piAction = PendingIntent.getActivity(this, n, iAction, 0);
    PendingIntent piAction_2 = PendingIntent.getActivity(this, n, iAction_2, 0);

    NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.format_list_bulleted,
            getString(R.string.readLater_action), piAction).build();
    NotificationCompat.Action action_2 = new NotificationCompat.Action.Builder(R.drawable.format_list_bulleted,
            getString(R.string.readLater_action2), piAction_2).build();

    android.support.v4.app.NotificationCompat.Builder builderSummary = new android.support.v4.app.NotificationCompat.Builder(
            Activity_intent.this).setAutoCancel(true).setSmallIcon(R.drawable.earth)
                    .setColor(ContextCompat.getColor(Activity_intent.this, R.color.colorPrimary))
                    .setGroup("Browser").setGroupSummary(true).setContentIntent(piMain);

    Notification notification = new android.support.v4.app.NotificationCompat.Builder(Activity_intent.this)
            .setColor(ContextCompat.getColor(Activity_intent.this, R.color.colorPrimary))
            .setSmallIcon(R.drawable.earth).setContentTitle(getString(R.string.readLater_title))
            .setContentText(data.toString()).setContentIntent(piMain).setAutoCancel(true).setGroup("Browser")
            .addAction(action).addAction(action_2)
            .setStyle(new android.support.v4.app.NotificationCompat.BigTextStyle().bigText(data.toString()))
            .setPriority(Notification.PRIORITY_MAX).setVibrate(new long[0]).build();

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(n, notification);
    notificationManager.notify(0, builderSummary.build());

    finish();
}

From source file:com.openerp.services.ExpenseSyncService.java

/**
 * Perform sync.//w  w w  .j  ava  2  s . c o m
 *
 * @param context    the context
 * @param account    the account
 * @param extras     the extras
 * @param authority  the authority
 * @param provider   the provider
 * @param syncResult the sync result
 */
public void performSync(Context context, Account account, Bundle extras, String authority,
        ContentProviderClient provider, SyncResult syncResult) {

    Log.d(TAG, "ExpenseSyncService->performSync()");
    Intent intent = new Intent();
    Intent updateWidgetIntent = new Intent();
    updateWidgetIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    intent.setAction(SyncFinishReceiver.SYNC_FINISH);
    OEUser user = OpenERPAccountManager.getAccountDetail(context, account.name);
    try {
        ExpenseDBHelper expense_db = new ExpenseDBHelper(context);
        expense_db.setAccountUser(user);
        OEHelper oe = expense_db.getOEInstance();
        if (oe == null) {
            return;
        }
        int user_id = user.getUser_id();

        // Updating User Context for OE-JSON-RPC
        JSONObject newContext = new JSONObject();
        //newContext.put("default_model", "res.users");
        //newContext.put("default_res_id", user_id);

        OEArguments arguments = new OEArguments();
        // Param 1 : domain
        //OEDomain domain = new OEDomain();
        //arguments.add(domain);
        // Param 2 : context
        arguments.add(oe.updateContext(newContext));

        //???
        List<Integer> ids = expense_db.ids();
        if (oe.syncWithMethod("get_waiting_audit_expenses", arguments, true)) {
            int affected_rows = oe.getAffectedRows();
            Log.d(TAG, "ExpenseSyncService[arguments]:" + arguments.toString());
            Log.d(TAG, "ExpenseSyncService->affected_rows:" + affected_rows);
            List<Integer> affected_ids = oe.getAffectedIds();
            boolean notification = true;
            ActivityManager am = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
            List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
            ComponentName componentInfo = taskInfo.get(0).topActivity;
            if (componentInfo.getPackageName().equalsIgnoreCase("com.openerp")) {
                notification = false;
            }
            if (notification && affected_rows > 0) {
                OENotificationHelper mNotification = new OENotificationHelper();
                Intent mainActiivty = new Intent(context, MainActivity.class);
                mainActiivty.setAction("EXPENSES");
                mNotification.setResultIntent(mainActiivty, context);

                String notify_title = context.getResources().getString(R.string.expenses_sync_notify_title);
                notify_title = String.format(notify_title, affected_rows);

                String notify_body = context.getResources().getString(R.string.expenses_sync_notify_body);
                notify_body = String.format(notify_body, affected_rows);

                mNotification.showNotification(context, notify_title, notify_body, authority,
                        R.drawable.ic_oe_notification);
            }
            intent.putIntegerArrayListExtra("new_ids", (ArrayList<Integer>) affected_ids);
        }
        //?expense?
        List<Integer> updated_ids = updateOldExpenses(expense_db, oe, user, ids);

    } catch (Exception e) {
        e.printStackTrace();
    }
    if (user.getAndroidName().equals(account.name)) {
        context.sendBroadcast(intent);
        //context.sendBroadcast(updateWidgetIntent);
    }
}

From source file:de.Maxr1998.xposed.maxlock.ui.MasterSwitchShortcutActivity.java

public void fireIntentAndFinish() {
    Intent intent = new Intent(this, MasterSwitchWidget.class);
    intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    int[] ids = AppWidgetManager.getInstance(getApplication())
            .getAppWidgetIds(new ComponentName(getApplication(), MasterSwitchWidget.class));
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
    sendBroadcast(intent);//w w w .j a  va 2 s. c o m
    finish();
}

From source file:com.dpcsoftware.mn.Widget1Config.java

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.item1:
        //Save Widget Preferences
        SharedPreferences.Editor pEditor = wPrefs.edit();
        int idSelected = ((RadioGroup) findViewById(R.id.radioGroup1)).getCheckedRadioButtonId();
        boolean byMonth = false;
        if (idSelected == R.id.radio0)
            byMonth = true;//from  w w w .j  a  v a 2 s . c  o  m
        pEditor.putBoolean(wId + "_BYMONTH", byMonth);
        pEditor.putLong(wId + "_GROUPID", sp.getSelectedItemId());
        pEditor.commit();

        //Update widget
        Intent updateIntent = new Intent(this, Widget1.class);
        updateIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
        updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { wId });
        try {
            PendingIntent.getBroadcast(this, 0, updateIntent, PendingIntent.FLAG_UPDATE_CURRENT).send();
        } catch (PendingIntent.CanceledException e) {
            e.printStackTrace();
        }

        setResult(RESULT_OK, resultIntent);
        finish();
        break;
    }
    return true;
}

From source file:com.openerp.services.VoucherSyncService.java

/**
 * Perform sync.//from   www. jav a 2 s.c  o  m
 *
 * @param context    the context
 * @param account    the account
 * @param extras     the extras
 * @param authority  the authority
 * @param provider   the provider
 * @param syncResult the sync result
 */
public void performSync(Context context, Account account, Bundle extras, String authority,
        ContentProviderClient provider, SyncResult syncResult) {

    Log.d(TAG, "VoucherSyncService->performSync()");
    Intent intent = new Intent();
    Intent updateWidgetIntent = new Intent();
    updateWidgetIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    intent.setAction(SyncFinishReceiver.SYNC_FINISH);
    OEUser user = OpenERPAccountManager.getAccountDetail(context, account.name);
    try {
        VoucherDB voucherDb = new VoucherDB(context);
        voucherDb.setAccountUser(user);
        OEHelper oe = voucherDb.getOEInstance();
        if (oe == null) {
            return;
        }
        int user_id = user.getUser_id();

        // Updating User Context for OE-JSON-RPC
        JSONObject newContext = new JSONObject();
        //newContext.put("default_model", "res.users");
        //newContext.put("default_res_id", user_id);

        OEArguments arguments = new OEArguments();
        // Param 1 : domain
        OEDomain domain = new OEDomain();
        //type = payment
        arguments.add(domain);
        // Param 2 : context
        arguments.add(oe.updateContext(newContext));

        //???
        List<Integer> ids = voucherDb.ids();
        if (oe.syncWithMethod("get_waiting_audit_vouchers", arguments, true)) {
            int affected_rows = oe.getAffectedRows();
            Log.d(TAG, "VoucherSyncService[arguments]:" + arguments.toString());
            Log.d(TAG, "VoucherSyncService->affected_rows:" + affected_rows);
            List<Integer> affected_ids = oe.getAffectedIds();
            boolean notification = true;
            ActivityManager am = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
            List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
            ComponentName componentInfo = taskInfo.get(0).topActivity;
            if (componentInfo.getPackageName().equalsIgnoreCase("com.openerp")) {
                notification = false;
            }
            if (notification && affected_rows > 0) {
                OENotificationHelper mNotification = new OENotificationHelper();
                Intent mainActiivty = new Intent(context, MainActivity.class);
                mainActiivty.setAction("VOUCHERS");
                mNotification.setResultIntent(mainActiivty, context);

                String notify_title = context.getResources().getString(R.string.vouchers_sync_notify_title);
                notify_title = String.format(notify_title, affected_rows);

                String notify_body = context.getResources().getString(R.string.vouchers_sync_notify_body);
                notify_body = String.format(notify_body, affected_rows);

                mNotification.showNotification(context, notify_title, notify_body, authority,
                        R.drawable.ic_oe_notification);
            }
            intent.putIntegerArrayListExtra("new_ids", (ArrayList<Integer>) affected_ids);
        }
        //?expense?
        List<Integer> updated_ids = updateOldVouchers(voucherDb, oe, user, ids);

    } catch (Exception e) {
        e.printStackTrace();
    }
    if (user.getAndroidName().equals(account.name)) {
        context.sendBroadcast(intent);
        //context.sendBroadcast(updateWidgetIntent);
    }
}

From source file:com.openerp.services.MessageSyncService.java

/**
 * Perform sync.//from  w  ww. j  av  a  2  s.c  o m
 *
 * @param context    the context
 * @param account    the account
 * @param extras     the extras
 * @param authority  the authority
 * @param provider   the provider
 * @param syncResult the sync result
 */
public void performSync(Context context, Account account, Bundle extras, String authority,
        ContentProviderClient provider, SyncResult syncResult) {
    Intent intent = new Intent();
    Intent updateWidgetIntent = new Intent();
    updateWidgetIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    updateWidgetIntent.putExtra(MessageWidget.ACTION_MESSAGE_WIDGET_UPDATE, true);
    intent.setAction(SyncFinishReceiver.SYNC_FINISH);
    OEUser user = OpenERPAccountManager.getAccountDetail(context, account.name);
    try {
        MessageDB msgDb = new MessageDB(context);
        msgDb.setAccountUser(user);
        OEHelper oe = msgDb.getOEInstance();
        if (oe == null) {
            return;
        }
        int user_id = user.getUser_id();

        // Updating User Context for OE-JSON-RPC
        JSONObject newContext = new JSONObject();
        newContext.put("default_model", "res.users");
        newContext.put("default_res_id", user_id);

        OEArguments arguments = new OEArguments();
        // Param 1 : ids
        arguments.addNull();
        // Param 2 : domain
        OEDomain domain = new OEDomain();

        // Data limit.
        PreferenceManager mPref = new PreferenceManager(context);
        int data_limit = mPref.getInt("sync_data_limit", 60);
        domain.add("create_date", ">=", OEDate.getDateBefore(data_limit));

        if (!extras.containsKey("group_ids")) {
            // Last id
            JSONArray msgIds = new JSONArray();
            for (OEDataRow row : msgDb.select()) {
                msgIds.put(row.getInt("id"));
            }
            domain.add("id", "not in", msgIds);

            domain.add("|");
            // Argument for check partner_ids.user_id is current user
            domain.add("partner_ids.user_ids", "in", new JSONArray().put(user_id));

            domain.add("|");
            // Argument for check notification_ids.partner_ids.user_id
            // is
            // current user
            domain.add("notification_ids.partner_id.user_ids", "in", new JSONArray().put(user_id));

            // Argument for check author id is current user
            domain.add("author_id.user_ids", "in", new JSONArray().put(user_id));

        } else {
            JSONArray group_ids = new JSONArray(extras.getString("group_ids"));

            // Argument for group model check
            domain.add("model", "=", "mail.group");

            // Argument for group model res id
            domain.add("res_id", "in", group_ids);
        }

        arguments.add(domain.getArray());
        // Param 3 : message_unload_ids
        arguments.add(new JSONArray());
        // Param 4 : thread_level
        arguments.add(true);
        // Param 5 : context
        arguments.add(oe.updateContext(newContext));
        // Param 6 : parent_id
        arguments.addNull();
        // Param 7 : limit
        arguments.add(50);
        List<Integer> ids = msgDb.ids();
        if (oe.syncWithMethod("message_read", arguments)) {
            int affected_rows = oe.getAffectedRows();
            List<Integer> affected_ids = oe.getAffectedIds();
            boolean notification = true;
            ActivityManager am = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
            List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
            ComponentName componentInfo = taskInfo.get(0).topActivity;
            if (componentInfo.getPackageName().equalsIgnoreCase("com.openerp")) {
                notification = false;
            }
            if (notification && affected_rows > 0) {
                OENotificationHelper mNotification = new OENotificationHelper();
                Intent mainActiivty = new Intent(context, MainActivity.class);
                mNotification.setResultIntent(mainActiivty, context);

                String notify_title = context.getResources().getString(R.string.messages_sync_notify_title);
                notify_title = String.format(notify_title, affected_rows);

                String notify_body = context.getResources().getString(R.string.messages_sync_notify_body);
                notify_body = String.format(notify_body, affected_rows);

                mNotification.showNotification(context, notify_title, notify_body, authority,
                        R.drawable.ic_oe_notification);
            }
            intent.putIntegerArrayListExtra("new_ids", (ArrayList<Integer>) affected_ids);
        }
        List<Integer> updated_ids = updateOldMessages(msgDb, oe, user, ids);
        intent.putIntegerArrayListExtra("updated_ids", (ArrayList<Integer>) updated_ids);
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (user.getAndroidName().equals(account.name)) {
        context.sendBroadcast(intent);
        context.sendBroadcast(updateWidgetIntent);
    }
}