Example usage for android.content Intent putIntegerArrayListExtra

List of usage examples for android.content Intent putIntegerArrayListExtra

Introduction

In this page you can find the example usage for android.content Intent putIntegerArrayListExtra.

Prototype

public @NonNull Intent putIntegerArrayListExtra(String name, ArrayList<Integer> value) 

Source Link

Document

Add extended data to the intent.

Usage

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

/**
 * Perform sync.//  w  ww .  j a  v 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 ww w  . java 2s  .  c om*/
 *
 * @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);
    }
}

From source file:com.hanuor.sapphire.utils.intentation.IntentationPrime.java

public Intent jsonToINTENT(String JSONString) throws JSONException {

    JSONObject jsonObject = new JSONObject(JSONString.toString());
    String toArray = jsonObject.get("intentExtras").toString();
    String contextName = jsonObject.get("context").toString();
    String className = jsonObject.get("className").toString();
    Log.d("Insass", className.toString());

    Intent setIntent = new Intent();
    setIntent.setClassName(contextName, className);
    HashMap<String, String> extrasHash = new HashMap<String, String>();
    JSONObject issueObj = new JSONObject(toArray);
    for (int i = 0; i < issueObj.length(); i++) {
        extrasHash.put(issueObj.names().getString(i), issueObj.get(issueObj.names().getString(i)).toString());
    }/* ww w.  ja va  2s .  c o m*/
    Iterator it = extrasHash.entrySet().iterator();
    while (it.hasNext()) {
        //add conditions  and checks here

        Map.Entry pair = (Map.Entry) it.next();
        String currentKey = (String) pair.getKey();
        Log.d("HAHA", "" + currentKey);
        String[] getValuethroughSplit = pair.getValue().toString().split(LibraryDatabase.JSONSEPERATOR);
        String dataType = getValuethroughSplit[0];
        String value = (String) getValuethroughSplit[2];
        Log.d("Insamareen", getValuethroughSplit.length + " " + dataType + " " + value.toString());
        switch (dataType) {
        case "String":
            setIntent.putExtra(currentKey, (String) value);
            break;
        case "String[]":
            String comp1 = value.substring(1, value.length() - 1);
            String[] comp2 = comp1.split(",");
            setIntent.putExtra(currentKey, comp2);
            break;
        case "Integer":
            setIntent.putExtra(currentKey, Integer.parseInt(value));
            break;
        case "Double":

            setIntent.putExtra(currentKey, Double.parseDouble(value));

            break;
        case "double[]":
            String compDouble1 = value.substring(1, value.length() - 1);
            String[] compDoub2 = compDouble1.split(",");
            double[] db = new double[compDoub2.length];
            for (int i = 0; i < compDoub2.length; i++) {
                db[i] = Double.parseDouble(compDoub2[i]);
            }
            setIntent.putExtra(currentKey, db);
            break;
        case "int[]":
            String compInt1 = value.substring(1, value.length() - 1);
            String[] compInt2 = compInt1.split(",");
            int[] intVal = new int[compInt2.length];
            for (int i = 0; i < compInt2.length; i++) {
                intVal[i] = Integer.parseInt(compInt2[i]);
            }
            Log.d("Hankey", intVal.toString());
            setIntent.putExtra(currentKey, intVal);

            break;
        case "Boolean":
            setIntent.putExtra(currentKey, Boolean.valueOf(value));

            break;
        case "boolean[]":
            String compB1 = value.substring(1, value.length() - 1);
            String[] compB2 = compB1.split(",");
            boolean[] BVal = new boolean[compB2.length];
            for (int i = 0; i < compB2.length; i++) {
                BVal[i] = Boolean.parseBoolean(compB2[i]);
            }
            setIntent.putExtra(currentKey, value);

            break;
        case "Char":
            setIntent.putExtra(currentKey, value);

            break;
        case "char[]":

            String ch1 = value.substring(1, value.length() - 1);
            String[] ch2 = ch1.split(",");
            String newS = null;
            for (int i = 0; i < ch2.length; i++) {
                newS = newS + ch2[i];
            }
            setIntent.putExtra(currentKey, newS.toCharArray());

            break;
        case "CharSequence":
            setIntent.putExtra(currentKey, (CharSequence) value);

            break;
        case "Charsequence[]":
            setIntent.putExtra(currentKey, value.toString());

            break;
        case "Byte":
            setIntent.putExtra(currentKey, Byte.valueOf(value));

            break;
        case "byte[]":
            String by = value.substring(1, value.length() - 1);
            String[] by2 = by.split(",");
            byte[] by3 = new byte[by2.length];
            for (int i = 0; i < by2.length; i++) {
                by3[i] = Byte.parseByte(by2[i]);
            }
            setIntent.putExtra(currentKey, by3);

            break;
        case "Float":
            setIntent.putExtra(currentKey, Float.valueOf(value));

            break;
        case "float[]":
            String fl = value.substring(1, value.length() - 1);
            String[] fl2 = fl.split(",");
            float[] fl3 = new float[fl2.length];
            for (int i = 0; i < fl2.length; i++) {
                fl3[i] = Float.parseFloat(fl2[i]);
            }
            setIntent.putExtra(currentKey, fl3);

            break;
        case "Short":
            setIntent.putExtra(currentKey, Short.valueOf(value));

            break;
        case "short[]":
            String sh = value.substring(1, value.length() - 1);
            String[] sh2 = sh.split(",");
            short[] sh3 = new short[sh2.length];
            for (int i = 0; i < sh2.length; i++) {
                sh3[i] = Short.parseShort(sh2[i]);
            }
            setIntent.putExtra(currentKey, sh3);

            break;
        case "Long":
            setIntent.putExtra(currentKey, Long.valueOf(value));

            break;
        case "long[]":
            String ll = value.substring(1, value.length() - 1);
            String[] ll2 = ll.split(",");
            long[] ll3 = new long[ll2.length];
            for (int i = 0; i < ll2.length; i++) {
                ll3[i] = Long.parseLong(ll2[i]);
            }
            setIntent.putExtra(currentKey, ll3);

            break;

        case "ArrayListString":
            Log.d("Hankey", currentKey + " ");
            String arrL = value.substring(1, value.length() - 1);
            String[] arrl2 = arrL.split(",");
            ArrayList<String> arrStr = new ArrayList<String>();
            for (int i = 0; i < arrl2.length; i++) {
                arrStr.add(arrl2[i]);
            }
            setIntent.putStringArrayListExtra(currentKey, arrStr);

            break;
        case "ArrayListInteger":
            String arL = value.substring(1, value.length() - 1);
            String[] arl2 = arL.split(",");
            ArrayList<Integer> arrInt = new ArrayList<Integer>();
            for (int i = 0; i < arl2.length; i++) {
                arrInt.add(Integer.parseInt(arl2[i]));
            }

            setIntent.putIntegerArrayListExtra(currentKey, arrInt);

            break;
        default:
            // whatever
        }
    }
    return setIntent;
}