Example usage for android.os Bundle keySet

List of usage examples for android.os Bundle keySet

Introduction

In this page you can find the example usage for android.os Bundle keySet.

Prototype

public Set<String> keySet() 

Source Link

Document

Returns a Set containing the Strings used as keys in this Bundle.

Usage

From source file:Main.java

public static String encodeUrl(Bundle parameters) {
    if (parameters == null) {
        return "";
    }//from ww w  .j  av  a 2 s. c o m

    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (String key : parameters.keySet()) {
        if (first)
            first = false;
        else
            sb.append("&");
        sb.append(key + "=" + parameters.getString(key));
    }
    return sb.toString();
}

From source file:com.kakao.http.HttpRequestTask.java

/**
 * String/Boolean/Number ?.//from  w ww .  j av  a2s  . c  o  m
 */
public static void addQueryParams(BoundRequestBuilder requestBuilder, Bundle parameters) {
    if (parameters == null)
        return;
    Set<String> keys = parameters.keySet();
    for (String key : keys) {
        Object value = parameters.get(key);
        String valueStr = null;

        if (value == null) {
            value = "";
        }

        if (isSupportedParameterType(value)) {
            valueStr = parameterToString(value);
        } else {
            throw new IllegalArgumentException(String.format("Unsupported parameter type for GET request: %s",
                    value.getClass().getSimpleName()));
        }

        requestBuilder.addQueryParameter(key, valueStr);
    }
}

From source file:com.facebook.TestUtils.java

public static void assertEqualContents(final Bundle a, final Bundle b) {
    for (String key : a.keySet()) {
        if (!b.containsKey(key)) {
            Assert.fail("bundle does not include key " + key);
        }/* ww w.ja va2  s . com*/
        Assert.assertEquals(a.get(key), b.get(key));
    }
    for (String key : b.keySet()) {
        if (!a.containsKey(key)) {
            Assert.fail("bundle does not include key " + key);
        }
    }
}

From source file:com.kakao.http.HttpRequestTask.java

/**
 * String/Boolean/Number ? value ? ?? Map/Set ?.
 *///  w  w w.j a va 2 s . c om
public static void addParams(final BoundRequestBuilder requestBuilder, final Bundle parameters) {
    if (parameters == null)
        return;

    Set<String> keys = parameters.keySet();
    for (String key : keys) {
        Object value = parameters.get(key);
        String valueStr = null;

        if (value == null) {
            value = "";
        }

        if (isSupportedParameterType(value)) {
            valueStr = parameterToString(value);
        } else if (value instanceof Map || value instanceof Set) {
            try {
                valueStr = objectMapper.writeValueAsString(value);
            } catch (JsonProcessingException e) {
                throw new IllegalArgumentException(
                        String.format("Unsupported parameter type : %s", value.getClass().getSimpleName()));
            }
        } else {
            throw new IllegalArgumentException(
                    String.format("Unsupported parameter type : %s", value.getClass().getSimpleName()));
        }

        requestBuilder.addParameter(key, valueStr);
    }
}

From source file:com.evollu.react.fcm.BundleJSONConverter.java

public static JSONObject convertToJSON(Bundle bundle) throws JSONException {
    JSONObject json = new JSONObject();

    for (String key : bundle.keySet()) {
        Object value = bundle.get(key);
        if (value == null) {
            // Null is not supported.
            continue;
        }/*from   w w  w  .j  a  va 2s.  c o m*/

        // Special case List<String> as getClass would not work, since List is an interface
        if (value instanceof List<?>) {
            JSONArray jsonArray = new JSONArray();
            @SuppressWarnings("unchecked")
            List<String> listValue = (List<String>) value;
            for (String stringValue : listValue) {
                jsonArray.put(stringValue);
            }
            json.put(key, jsonArray);
            continue;
        }

        // Special case Bundle as it's one way, on the return it will be JSONObject
        if (value instanceof Bundle) {
            json.put(key, convertToJSON((Bundle) value));
            continue;
        }

        Setter setter = SETTERS.get(value.getClass());
        if (setter == null) {
            throw new IllegalArgumentException("Unsupported type: " + value.getClass());
        }
        setter.setOnJSON(json, key, value);
    }

    return json;
}

From source file:Main.java

public static void registerNewSourceSinkConnection(int counter, Bundle bundle) {
    Log.i("PEP", "in registerNewSourceSinkConnection(int counter, Bundle bundle)" + counter + " "
            + bundle.toString());//w ww.j  a v  a  2 s . c o  m
    int taintInfoKeyCounter = 0;

    if (bundle != null) {
        for (String intentKey : bundle.keySet()) {
            if (intentKey.startsWith(keyBaseName)) {
                String possibleNumber = intentKey.substring(keyBaseName.length());
                if (possibleNumber.length() > 0 && TextUtils.isDigitsOnly(possibleNumber)) {
                    int currentCounter = Integer.parseInt(possibleNumber);
                    if (taintInfoKeyCounter < currentCounter)
                        taintInfoKeyCounter = currentCounter;
                }
            }
        }

        if (taintInfoKeyCounter == 0) {
            Log.i("PEP", "bundle:" + bundle.toString());
            if (bundle.containsKey(keyBaseName)) {
                String taintSourceCats = bundle.getString(keyBaseName);
                String[] allCats = taintSourceCats.split(",");
                sourceSinkConnection.put(counter, new HashSet<String>(Arrays.asList(allCats)));
            }
        } else {
            if (bundle.containsKey(keyBaseName + taintInfoKeyCounter)) {
                String taintSourceCats = bundle.getString(keyBaseName + taintInfoKeyCounter);
                String[] allCats = taintSourceCats.split(",");
                sourceSinkConnection.put(counter, new HashSet<String>(Arrays.asList(allCats)));
            }
        }
    }
}

From source file:com.partypoker.poker.engagement.utils.EngagementBundleToJSON.java

/**
 * Recursive function to write a value to JSON.
 * @param json the JSON serializer./*from  w ww .  ja  v  a2  s .c  om*/
 * @param value the value to write in JSON.
 */
private static void convert(JSONStringer json, Object value) throws JSONException {
    /* Handle null */
    if (value == null)
        json.value(null);

    /* The function is recursive if it encounters a bundle */
    else if (value instanceof Bundle) {
        /* Cast bundle */
        Bundle bundle = (Bundle) value;

        /* Open object */
        json.object();

        /* Traverse bundle */
        for (String key : bundle.keySet()) {
            /* Write key */
            json.key(key);

            /* Recursive call to write the value */
            convert(json, bundle.get(key));
        }

        /* End object */
        json.endObject();
    }

    /* Handle array, write it as a JSON array */
    else if (value.getClass().isArray()) {
        /* Open array */
        json.array();

        /* Recursive call on each value */
        int length = Array.getLength(value);
        for (int i = 0; i < length; i++)
            convert(json, Array.get(value, i));

        /* Close array */
        json.endArray();
    }

    /* Handle ArrayList, write it as a JSON array */
    else if (value instanceof ArrayList<?>) {
        /* Open array */
        json.array();

        /* Recursive call on each value */
        ArrayList<?> arrayList = (ArrayList<?>) value;
        for (Object val : arrayList)
            convert(json, val);

        /* Close array */
        json.endArray();
    }

    /* Format throwable values with the stack trace */
    else if (value instanceof Throwable) {
        Throwable t = (Throwable) value;
        StringWriter text = new StringWriter();
        t.printStackTrace(new PrintWriter(text));
        json.value(text.toString());
    }

    /* Other values are handled directly by JSONStringer (numerical, boolean and String) */
    else
        json.value(value);
}

From source file:jp.mixi.android.sdk.util.UrlUtils.java

/**
 * Bundle???/*from   w ww.  java2  s.  co m*/
 * 
 * @param params ?Bundle
 * @return ???String
 */
public static String encodeUrlForBundle(Bundle params) {
    if (params == null) {
        return "";
    }

    StringBuilder builder = new StringBuilder();
    boolean first = true;
    for (String key : params.keySet()) {
        if (first) {
            first = false;
        } else {
            builder.append(PARAM_SEPARATOR);
        }
        try {
            builder.append(URLEncoder.encode(key, HTTP.UTF_8) + EQUAL
                    + URLEncoder.encode(params.getString(key), HTTP.UTF_8));
        } catch (UnsupportedEncodingException e) {
            Log.e(TAG, e.getLocalizedMessage(), e);
        }
    }
    return builder.toString();
}

From source file:bolts.MeasurementEvent.java

/**
 *  Broadcast Bolts measurement event.//from  www  .jav  a 2s . com
 *  Bolts raises events to the application with this method by sending
 *  {@link #MEASUREMENT_EVENT_NOTIFICATION_NAME} broadcast.
 *
 *  @param context the context of activity or application who is going to send the event. required.
 *  @param name the event name that is going to be sent. required.
 *  @param intent the intent that carries the logging data in its extra bundle and data url. optional.
 *  @param extraLoggingData other logging data to be sent in events argument. optional.
 *
 */
static void sendBroadcastEvent(Context context, String name, Intent intent,
        Map<String, String> extraLoggingData) {
    Bundle logData = new Bundle();
    if (intent != null) {
        Bundle applinkData = AppLinks.getAppLinkData(intent);
        if (applinkData != null) {
            logData = getApplinkLogData(context, name, applinkData, intent);
        } else {
            Uri intentUri = intent.getData();
            if (intentUri != null) {
                logData.putString("intentData", intentUri.toString());
            }
            Bundle intentExtras = intent.getExtras();
            if (intentExtras != null) {
                for (String key : intentExtras.keySet()) {
                    Object o = intentExtras.get(key);
                    String logValue = objectToJSONString(o);
                    logData.putString(key, logValue);
                }
            }
        }
    }

    if (extraLoggingData != null) {
        for (String key : extraLoggingData.keySet()) {
            logData.putString(key, extraLoggingData.get(key));
        }
    }
    MeasurementEvent event = new MeasurementEvent(context, name, logData);
    event.sendBroadcast();
}

From source file:com.appdynamics.demo.gasp.service.RESTIntentService.java

private static List<BasicNameValuePair> paramsToList(Bundle params) {
    ArrayList<BasicNameValuePair> formList = new ArrayList<BasicNameValuePair>(params.size());

    for (String key : params.keySet()) {
        Object value = params.get(key);

        if (value != null)
            formList.add(new BasicNameValuePair(key, value.toString()));
    }/* w  w w  . j  ava  2 s  .  c o m*/

    return formList;
}