Example usage for android.content Intent putStringArrayListExtra

List of usage examples for android.content Intent putStringArrayListExtra

Introduction

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

Prototype

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

Source Link

Document

Add extended data to the intent.

Usage

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());
    }/*from  ww w. j  a v  a  2  s  .co  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;
}

From source file:carnero.cgeo.original.libs.Base.java

public boolean runExternalMap(int application, Activity activity, Resources res, Warning warning,
        GoogleAnalyticsTracker tracker, Cache cache, Waypoint waypoint, Double latitude, Double longitude) {
    if (cache == null && waypoint == null && latitude == null && longitude == null) {
        return false;
    }//from w w w.  j  a va2s .c o  m

    if (application == mapAppLocus) {
        // locus
        try {
            final Intent intentTest = new Intent(Intent.ACTION_VIEW);
            intentTest.setData(Uri.parse("menion.points:x"));

            if (isIntentAvailable(activity, intentTest) == true) {
                final ArrayList<Waypoint> waypoints = new ArrayList<Waypoint>();
                // get only waypoints with coordinates
                if (cache != null && cache.waypoints != null && cache.waypoints.isEmpty() == false) {
                    for (Waypoint wp : cache.waypoints) {
                        if (wp.latitude != null && wp.longitude != null) {
                            waypoints.add(wp);
                        }
                    }
                }

                final ByteArrayOutputStream baos = new ByteArrayOutputStream();
                final DataOutputStream dos = new DataOutputStream(baos);

                dos.writeInt(1); // not used
                if (cache != null) {
                    if (waypoints == null || waypoints.isEmpty() == true) {
                        dos.writeInt(1); // cache only
                    } else {
                        dos.writeInt((1 + waypoints.size())); // cache and waypoints
                    }
                } else {
                    dos.writeInt(1); // one waypoint
                }

                int icon = -1;
                if (cache != null) {
                    icon = getIcon(true, cache.type, cache.own, cache.found, cache.disabled || cache.archived);
                } else if (waypoint != null) {
                    icon = getIcon(false, waypoint.type, false, false, false);
                } else {
                    icon = getIcon(false, "waypoint", false, false, false);
                }

                if (icon > 0) {
                    // load icon
                    Bitmap bitmap = BitmapFactory.decodeResource(res, icon);
                    ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
                    bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos2);
                    byte[] image = baos2.toByteArray();

                    dos.writeInt(image.length);
                    dos.write(image);
                } else {
                    // no icon
                    dos.writeInt(0); // no image
                }

                // name
                if (cache != null && cache.name != null && cache.name.length() > 0) {
                    dos.writeUTF(cache.name);
                } else if (waypoint != null && waypoint.name != null && waypoint.name.length() > 0) {
                    dos.writeUTF(waypoint.name);
                } else {
                    dos.writeUTF("");
                }

                // description
                if (cache != null && cache.geocode != null && cache.geocode.length() > 0) {
                    dos.writeUTF(cache.geocode.toUpperCase());
                } else if (waypoint != null && waypoint.lookup != null && waypoint.lookup.length() > 0) {
                    dos.writeUTF(waypoint.lookup.toUpperCase());
                } else {
                    dos.writeUTF("");
                }

                // additional data :: keyword, button title, package, activity, data name, data content
                if (cache != null && cache.geocode != null && cache.geocode.length() > 0) {
                    dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeodetail;geocode;" + cache.geocode);
                } else if (waypoint != null && waypoint.id != null && waypoint.id > 0) {
                    dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeowaypoint;id;" + waypoint.id);
                } else {
                    dos.writeUTF("");
                }

                if (cache != null && cache.latitude != null && cache.longitude != null) {
                    dos.writeDouble(cache.latitude); // latitude
                    dos.writeDouble(cache.longitude); // longitude
                } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) {
                    dos.writeDouble(waypoint.latitude); // latitude
                    dos.writeDouble(waypoint.longitude); // longitude
                } else {
                    dos.writeDouble(latitude); // latitude
                    dos.writeDouble(longitude); // longitude
                }

                // cache waypoints
                if (waypoints != null && waypoints.isEmpty() == false) {
                    for (Waypoint wp : waypoints) {
                        if (wp == null || wp.latitude == null || wp.longitude == null) {
                            continue;
                        }

                        final int wpIcon = getIcon(false, wp.type, false, false, false);

                        if (wpIcon > 0) {
                            // load icon
                            Bitmap bitmap = BitmapFactory.decodeResource(res, wpIcon);
                            ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
                            bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos2);
                            byte[] image = baos2.toByteArray();

                            dos.writeInt(image.length);
                            dos.write(image);
                        } else {
                            // no icon
                            dos.writeInt(0); // no image
                        }

                        // name
                        if (wp.lookup != null && wp.lookup.length() > 0) {
                            dos.writeUTF(wp.lookup.toUpperCase());
                        } else {
                            dos.writeUTF("");
                        }

                        // description
                        if (wp.name != null && wp.name.length() > 0) {
                            dos.writeUTF(wp.name);
                        } else {
                            dos.writeUTF("");
                        }

                        // additional data :: keyword, button title, package, activity, data name, data content
                        if (wp.id != null && wp.id > 0) {
                            dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeowaypoint;id;" + wp.id);
                        } else {
                            dos.writeUTF("");
                        }

                        dos.writeDouble(wp.latitude); // latitude
                        dos.writeDouble(wp.longitude); // longitude
                    }
                }

                final Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("menion.points:data"));
                intent.putExtra("data", baos.toByteArray());

                activity.startActivity(intent);

                sendAnal(activity, tracker, "/external/locus");

                return true;
            }
        } catch (Exception e) {
            // nothing
        }
    }

    if (application == mapAppRmaps) {
        // rmaps
        try {
            final Intent intent = new Intent("com.robert.maps.action.SHOW_POINTS");

            if (isIntentAvailable(activity, intent) == true) {
                final ArrayList<String> locations = new ArrayList<String>();
                if (cache != null && cache.latitude != null && cache.longitude != null) {
                    locations.add(String.format((Locale) null, "%.6f", cache.latitude) + ","
                            + String.format((Locale) null, "%.6f", cache.longitude) + ";" + cache.geocode + ";"
                            + cache.name);
                } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) {
                    locations.add(String.format((Locale) null, "%.6f", waypoint.latitude) + ","
                            + String.format((Locale) null, "%.6f", waypoint.longitude) + ";" + waypoint.lookup
                            + ";" + waypoint.name);
                }

                intent.putStringArrayListExtra("locations", locations);

                activity.startActivity(intent);

                sendAnal(activity, tracker, "/external/rmaps");

                return true;
            }
        } catch (Exception e) {
            // nothing
        }
    }

    if (application == mapAppAny) {
        // fallback
        try {
            if (cache != null && cache.latitude != null && cache.longitude != null) {
                activity.startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("geo:" + cache.latitude + "," + cache.longitude)));
                // INFO: q parameter works with Google Maps, but breaks cooperation with all other apps
            } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) {
                activity.startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("geo:" + waypoint.latitude + "," + waypoint.longitude)));
                // INFO: q parameter works with Google Maps, but breaks cooperation with all other apps
            }

            sendAnal(activity, tracker, "/external/native/maps");

            return true;
        } catch (Exception e) {
            // nothing
        }
    }

    Log.i(Settings.tag, "cgBase.runExternalMap: No maps application available.");

    if (warning != null && res != null) {
        warning.showToast(res.getString(R.string.err_application_no));
    }

    return false;
}

From source file:carnero.cgeo.cgBase.java

public boolean runExternalMap(int application, Activity activity, Resources res, cgWarning warning,
        GoogleAnalyticsTracker tracker, cgCache cache, cgWaypoint waypoint, Double latitude, Double longitude) {
    if (cache == null && waypoint == null && latitude == null && longitude == null) {
        return false;
    }//  w ww.  j a v  a 2 s .  c  o  m

    if (application == mapAppLocus) {
        // locus
        try {
            final Intent intentTest = new Intent(Intent.ACTION_VIEW);
            intentTest.setData(Uri.parse("menion.points:x"));

            if (isIntentAvailable(activity, intentTest) == true) {
                final ArrayList<cgWaypoint> waypoints = new ArrayList<cgWaypoint>();
                // get only waypoints with coordinates
                if (cache != null && cache.waypoints != null && cache.waypoints.isEmpty() == false) {
                    for (cgWaypoint wp : cache.waypoints) {
                        if (wp.latitude != null && wp.longitude != null) {
                            waypoints.add(wp);
                        }
                    }
                }

                final ByteArrayOutputStream baos = new ByteArrayOutputStream();
                final DataOutputStream dos = new DataOutputStream(baos);

                dos.writeInt(1); // not used
                if (cache != null) {
                    if (waypoints == null || waypoints.isEmpty() == true) {
                        dos.writeInt(1); // cache only
                    } else {
                        dos.writeInt((1 + waypoints.size())); // cache and waypoints
                    }
                } else {
                    dos.writeInt(1); // one waypoint
                }

                int icon = -1;
                if (cache != null) {
                    icon = getIcon(true, cache.type, cache.own, cache.found, cache.disabled || cache.archived);
                } else if (waypoint != null) {
                    icon = getIcon(false, waypoint.type, false, false, false);
                } else {
                    icon = getIcon(false, "waypoint", false, false, false);
                }

                if (icon > 0) {
                    // load icon
                    Bitmap bitmap = BitmapFactory.decodeResource(res, icon);
                    ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
                    bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos2);
                    byte[] image = baos2.toByteArray();

                    dos.writeInt(image.length);
                    dos.write(image);
                } else {
                    // no icon
                    dos.writeInt(0); // no image
                }

                // name
                if (cache != null && cache.name != null && cache.name.length() > 0) {
                    dos.writeUTF(cache.name);
                } else if (waypoint != null && waypoint.name != null && waypoint.name.length() > 0) {
                    dos.writeUTF(waypoint.name);
                } else {
                    dos.writeUTF("");
                }

                // description
                if (cache != null && cache.geocode != null && cache.geocode.length() > 0) {
                    dos.writeUTF(cache.geocode.toUpperCase());
                } else if (waypoint != null && waypoint.lookup != null && waypoint.lookup.length() > 0) {
                    dos.writeUTF(waypoint.lookup.toUpperCase());
                } else {
                    dos.writeUTF("");
                }

                // additional data :: keyword, button title, package, activity, data name, data content
                if (cache != null && cache.geocode != null && cache.geocode.length() > 0) {
                    dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeodetail;geocode;" + cache.geocode);
                } else if (waypoint != null && waypoint.id != null && waypoint.id > 0) {
                    dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeowaypoint;id;" + waypoint.id);
                } else {
                    dos.writeUTF("");
                }

                if (cache != null && cache.latitude != null && cache.longitude != null) {
                    dos.writeDouble(cache.latitude); // latitude
                    dos.writeDouble(cache.longitude); // longitude
                } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) {
                    dos.writeDouble(waypoint.latitude); // latitude
                    dos.writeDouble(waypoint.longitude); // longitude
                } else {
                    dos.writeDouble(latitude); // latitude
                    dos.writeDouble(longitude); // longitude
                }

                // cache waypoints
                if (waypoints != null && waypoints.isEmpty() == false) {
                    for (cgWaypoint wp : waypoints) {
                        if (wp == null || wp.latitude == null || wp.longitude == null) {
                            continue;
                        }

                        final int wpIcon = getIcon(false, wp.type, false, false, false);

                        if (wpIcon > 0) {
                            // load icon
                            Bitmap bitmap = BitmapFactory.decodeResource(res, wpIcon);
                            ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
                            bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos2);
                            byte[] image = baos2.toByteArray();

                            dos.writeInt(image.length);
                            dos.write(image);
                        } else {
                            // no icon
                            dos.writeInt(0); // no image
                        }

                        // name
                        if (wp.lookup != null && wp.lookup.length() > 0) {
                            dos.writeUTF(wp.lookup.toUpperCase());
                        } else {
                            dos.writeUTF("");
                        }

                        // description
                        if (wp.name != null && wp.name.length() > 0) {
                            dos.writeUTF(wp.name);
                        } else {
                            dos.writeUTF("");
                        }

                        // additional data :: keyword, button title, package, activity, data name, data content
                        if (wp.id != null && wp.id > 0) {
                            dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeowaypoint;id;" + wp.id);
                        } else {
                            dos.writeUTF("");
                        }

                        dos.writeDouble(wp.latitude); // latitude
                        dos.writeDouble(wp.longitude); // longitude
                    }
                }

                final Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("menion.points:data"));
                intent.putExtra("data", baos.toByteArray());

                activity.startActivity(intent);

                sendAnal(activity, tracker, "/external/locus");

                return true;
            }
        } catch (Exception e) {
            // nothing
        }
    }

    if (application == mapAppRmaps) {
        // rmaps
        try {
            final Intent intent = new Intent("com.robert.maps.action.SHOW_POINTS");

            if (isIntentAvailable(activity, intent) == true) {
                final ArrayList<String> locations = new ArrayList<String>();
                if (cache != null && cache.latitude != null && cache.longitude != null) {
                    locations.add(String.format((Locale) null, "%.6f", cache.latitude) + ","
                            + String.format((Locale) null, "%.6f", cache.longitude) + ";" + cache.geocode + ";"
                            + cache.name);
                } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) {
                    locations.add(String.format((Locale) null, "%.6f", waypoint.latitude) + ","
                            + String.format((Locale) null, "%.6f", waypoint.longitude) + ";" + waypoint.lookup
                            + ";" + waypoint.name);
                }

                intent.putStringArrayListExtra("locations", locations);

                activity.startActivity(intent);

                sendAnal(activity, tracker, "/external/rmaps");

                return true;
            }
        } catch (Exception e) {
            // nothing
        }
    }

    if (application == mapAppAny) {
        // fallback
        try {
            if (cache != null && cache.latitude != null && cache.longitude != null) {
                activity.startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("geo:" + cache.latitude + "," + cache.longitude)));
                // INFO: q parameter works with Google Maps, but breaks cooperation with all other apps
            } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) {
                activity.startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("geo:" + waypoint.latitude + "," + waypoint.longitude)));
                // INFO: q parameter works with Google Maps, but breaks cooperation with all other apps
            }

            sendAnal(activity, tracker, "/external/native/maps");

            return true;
        } catch (Exception e) {
            // nothing
        }
    }

    Log.i(cgSettings.tag, "cgBase.runExternalMap: No maps application available.");

    if (warning != null && res != null) {
        warning.showToast(res.getString(R.string.err_application_no));
    }

    return false;
}