Example usage for android.os Bundle putBundle

List of usage examples for android.os Bundle putBundle

Introduction

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

Prototype

public void putBundle(@Nullable String key, @Nullable Bundle value) 

Source Link

Document

Inserts a Bundle value into the mapping of this Bundle, replacing any existing value for the given key.

Usage

From source file:com.facebook.internal.DialogPresenter.java

public static void setupAppCallForWebDialog(AppCall appCall, String actionName, Bundle parameters) {
    Validate.hasFacebookActivity(FacebookSdk.getApplicationContext());
    Validate.hasInternetPermissions(FacebookSdk.getApplicationContext());

    Bundle intentParameters = new Bundle();
    intentParameters.putString(NativeProtocol.WEB_DIALOG_ACTION, actionName);
    intentParameters.putBundle(NativeProtocol.WEB_DIALOG_PARAMS, parameters);

    Intent webDialogIntent = new Intent();
    NativeProtocol.setupProtocolRequestIntent(webDialogIntent, appCall.getCallId().toString(), actionName,
            NativeProtocol.getLatestKnownVersion(), intentParameters);
    webDialogIntent.setClass(FacebookSdk.getApplicationContext(), FacebookActivity.class);
    webDialogIntent.setAction(FacebookDialogFragment.TAG);

    appCall.setRequestIntent(webDialogIntent);
}

From source file:ca.rmen.android.networkmonitor.app.dialog.DialogFragmentFactory.java

/**
 * Show a visible dialog fragment with the given title and message, and an ok and cancel button. If the given activity implements
 *         {@link DialogButtonListener}, the actionId and extras parameter will be provided in
 *         the {@link DialogButtonListener#onOkClicked(int, Bundle)} callback on the activity, when the user clicks on the ok button.
 *//*from ww w. j  a v a 2 s .c  o  m*/
public static void showConfirmDialog(FragmentActivity activity, String title, String message, int actionId,
        Bundle extras) {
    Log.v(TAG, "showConfirmDialog: title = " + title + ", message = " + message + ", actionId = " + actionId
            + ", extras = " + extras);
    ConfirmDialogFragment result = new ConfirmDialogFragment();
    Bundle arguments = new Bundle(4);
    arguments.putString(EXTRA_TITLE, title);
    arguments.putString(EXTRA_MESSAGE, message);
    arguments.putInt(EXTRA_ACTION_ID, actionId);
    if (extras != null)
        arguments.putBundle(EXTRA_EXTRAS, extras);
    result.setArguments(arguments);
    result.show(activity.getSupportFragmentManager(), ConfirmDialogFragment.class.getSimpleName());
}

From source file:org.getlantern.firetweet.util.CustomTabUtils.java

public static List<SupportTabSpec> getHomeTabs(final Context context) {
    if (context == null)
        return Collections.emptyList();
    final ContentResolver resolver = context.getContentResolver();
    final Cursor cur = resolver.query(Tabs.CONTENT_URI, Tabs.COLUMNS, null, null, Tabs.DEFAULT_SORT_ORDER);
    if (cur == null)
        return Collections.emptyList();
    final ArrayList<SupportTabSpec> tabs = new ArrayList<>();
    cur.moveToFirst();/*  w w w.j  a  v  a 2s  .co m*/
    final int idxName = cur.getColumnIndex(Tabs.NAME), idxIcon = cur.getColumnIndex(Tabs.ICON),
            idxType = cur.getColumnIndex(Tabs.TYPE), idxArguments = cur.getColumnIndex(Tabs.ARGUMENTS),
            idxExtras = cur.getColumnIndex(Tabs.EXTRAS), idxPosition = cur.getColumnIndex(Tabs.POSITION);
    while (!cur.isAfterLast()) {
        final String type = cur.getString(idxType);
        final int position = cur.getInt(idxPosition);
        final String iconType = cur.getString(idxIcon);
        final String name = cur.getString(idxName);
        final Bundle args = ParseUtils.jsonToBundle(cur.getString(idxArguments));
        final String tag = getTagByType(type);
        args.putInt(EXTRA_TAB_POSITION, position);
        args.putBundle(EXTRA_EXTRAS, ParseUtils.jsonToBundle(cur.getString(idxExtras)));
        final CustomTabConfiguration conf = getTabConfiguration(type);
        final Class<? extends Fragment> cls = conf != null ? conf.getFragmentClass() : InvalidTabFragment.class;
        tabs.add(new SupportTabSpec(name != null ? name : getTabTypeName(context, type),
                getTabIconObject(iconType), type, cls, args, position, tag));
        cur.moveToNext();
    }
    cur.close();
    Collections.sort(tabs);
    return tabs;
}

From source file:de.vanita5.twittnuker.util.CustomTabUtils.java

public static SupportTabSpec getAddedTabAt(final Context context, final int position) {
    if (context == null || position < 0)
        return null;
    final ContentResolver resolver = context.getContentResolver();
    final Cursor cur = resolver.query(Tabs.CONTENT_URI, Tabs.COLUMNS, Tabs.POSITION + " = " + position, null,
            Tabs.DEFAULT_SORT_ORDER);/*from  w  ww. ja  v a  2s .  c o m*/
    final int idxName = cur.getColumnIndex(Tabs.NAME), idxIcon = cur.getColumnIndex(Tabs.ICON),
            idxType = cur.getColumnIndex(Tabs.TYPE), idxArguments = cur.getColumnIndex(Tabs.ARGUMENTS),
            idxExtras = cur.getColumnIndex(Tabs.EXTRAS);
    try {
        if (cur.getCount() == 0)
            return null;
        cur.moveToFirst();
        final String type = cur.getString(idxType);
        final CustomTabConfiguration conf = getTabConfiguration(type);
        if (conf == null)
            return null;
        final String icon_type = cur.getString(idxIcon);
        final String name = cur.getString(idxName);
        final Bundle args = ParseUtils.jsonToBundle(cur.getString(idxArguments));
        args.putInt(EXTRA_TAB_POSITION, position);
        args.putBundle(EXTRA_EXTRAS, ParseUtils.jsonToBundle(cur.getString(idxExtras)));
        final Class<? extends Fragment> fragment = conf.getFragmentClass();
        return new SupportTabSpec(name != null ? name : getTabTypeName(context, type),
                getTabIconObject(icon_type), type, fragment, args, position);
    } finally {
        cur.close();
    }
}

From source file:de.vanita5.twittnuker.util.CustomTabUtils.java

public static List<SupportTabSpec> getHomeTabs(final Context context) {
    if (context == null)
        return Collections.emptyList();
    final ContentResolver resolver = context.getContentResolver();
    final Cursor cur = resolver.query(Tabs.CONTENT_URI, Tabs.COLUMNS, null, null, Tabs.DEFAULT_SORT_ORDER);
    if (cur == null)
        return Collections.emptyList();
    final ArrayList<SupportTabSpec> tabs = new ArrayList<SupportTabSpec>();
    cur.moveToFirst();/*  w  w w .j ava  2  s.  co m*/
    final int idxName = cur.getColumnIndex(Tabs.NAME), idxIcon = cur.getColumnIndex(Tabs.ICON),
            idxType = cur.getColumnIndex(Tabs.TYPE), idxArguments = cur.getColumnIndex(Tabs.ARGUMENTS),
            idxExtras = cur.getColumnIndex(Tabs.EXTRAS), idxPosition = cur.getColumnIndex(Tabs.POSITION);
    while (!cur.isAfterLast()) {
        final String type = cur.getString(idxType);
        final int position = cur.getInt(idxPosition);
        final String iconType = cur.getString(idxIcon);
        final String name = cur.getString(idxName);
        final Bundle args = ParseUtils.jsonToBundle(cur.getString(idxArguments));
        args.putInt(EXTRA_TAB_POSITION, position);
        args.putBundle(EXTRA_EXTRAS, ParseUtils.jsonToBundle(cur.getString(idxExtras)));
        final CustomTabConfiguration conf = getTabConfiguration(type);
        final Class<? extends Fragment> cls = conf != null ? conf.getFragmentClass() : InvalidTabFragment.class;
        tabs.add(new SupportTabSpec(name != null ? name : getTabTypeName(context, type),
                getTabIconObject(iconType), type, cls, args, position));
        cur.moveToNext();
    }
    cur.close();
    Collections.sort(tabs);
    return tabs;
}

From source file:ca.rmen.android.scrumchatter.dialog.DialogFragmentFactory.java

/**
 * @param inputValidatorClass will be called with each text event on the edit text, to validate the user's input.
 *///www .  j  a  va2  s. co  m
public static void showInputDialog(FragmentActivity activity, String title, String inputHint,
        String prefilledText, Class<?> inputValidatorClass, int actionId, Bundle extras) {
    Log.v(TAG, "showInputDialog: title = " + title + ", prefilledText =  " + prefilledText + ", actionId = "
            + actionId + ", extras = " + extras);
    Bundle arguments = new Bundle(6);
    arguments.putString(EXTRA_TITLE, title);
    arguments.putString(EXTRA_INPUT_HINT, inputHint);
    arguments.putInt(EXTRA_ACTION_ID, actionId);
    arguments.putString(EXTRA_ENTERED_TEXT, prefilledText);
    if (inputValidatorClass != null)
        arguments.putSerializable(EXTRA_INPUT_VALIDATOR_CLASS, inputValidatorClass);
    arguments.putBundle(EXTRA_EXTRAS, extras);
    InputDialogFragment result = new InputDialogFragment();
    result.setArguments(arguments);
    result.show(activity.getSupportFragmentManager(), InputDialogFragment.class.getSimpleName());
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static Bundle addMapToBundle(HashMap<String, ?> map, Bundle bundle) {
    for (String key : map.keySet()) {
        Object value = map.get(key);
        if (value instanceof String) {
            bundle.putString(key, (String) value);
        } else if (value instanceof Integer) {
            bundle.putInt(key, (Integer) value);
        } else if (value instanceof Double) {
            bundle.putDouble(key, ((Double) value));
        } else if (value instanceof Boolean) {
            bundle.putBoolean(key, (Boolean) value);
        } else if (value instanceof HashMap) {
            bundle.putBundle(key, addMapToBundle((HashMap<String, Object>) value, new Bundle()));
        } else if (value instanceof ArrayList) {
            putArray(key, (ArrayList) value, bundle);
        }/*from   ww  w. j  a v  a 2s.  c o  m*/
    }
    return bundle;
}

From source file:com.facebook.AppLinkData.java

private static Bundle toBundle(JSONObject node) throws JSONException {
    Bundle bundle = new Bundle();
    @SuppressWarnings("unchecked")
    Iterator<String> fields = node.keys();
    while (fields.hasNext()) {
        String key = fields.next();
        Object value;/*from   www  .ja  va  2s . c  o  m*/
        value = node.get(key);

        if (value instanceof JSONObject) {
            bundle.putBundle(key, toBundle((JSONObject) value));
        } else if (value instanceof JSONArray) {
            JSONArray valueArr = (JSONArray) value;
            if (valueArr.length() == 0) {
                bundle.putStringArray(key, new String[0]);
            } else {
                Object firstNode = valueArr.get(0);
                if (firstNode instanceof JSONObject) {
                    Bundle[] bundles = new Bundle[valueArr.length()];
                    for (int i = 0; i < valueArr.length(); i++) {
                        bundles[i] = toBundle(valueArr.getJSONObject(i));
                    }
                    bundle.putParcelableArray(key, bundles);
                } else if (firstNode instanceof JSONArray) {
                    // we don't support nested arrays
                    throw new FacebookException("Nested arrays are not supported.");
                } else { // just use the string value
                    String[] arrValues = new String[valueArr.length()];
                    for (int i = 0; i < valueArr.length(); i++) {
                        arrValues[i] = valueArr.get(i).toString();
                    }
                    bundle.putStringArray(key, arrValues);
                }
            }
        } else {
            bundle.putString(key, value.toString());
        }
    }
    return bundle;
}

From source file:org.opendatakit.common.android.utilities.AndroidUtils.java

public static Bundle convertToBundle(JSONObject valueMap, final MacroStringExpander expander)
        throws JSONException {
    Bundle b = new Bundle();
    @SuppressWarnings("unchecked")
    Iterator<String> cur = valueMap.keys();
    while (cur.hasNext()) {
        String key = cur.next();//from  ww w.j  a  v  a  2 s  .c  om
        if (!valueMap.isNull(key)) {
            Object o = valueMap.get(key);
            if (o instanceof JSONObject) {
                Bundle be = convertToBundle((JSONObject) o, expander);
                b.putBundle(key, be);
            } else if (o instanceof JSONArray) {
                JSONArray a = (JSONArray) o;
                // only non-empty arrays are written into the Bundle
                // first non-null element defines data type
                // for the array
                Object oe = null;
                for (int j = 0; j < a.length(); ++j) {
                    if (!a.isNull(j)) {
                        oe = a.get(j);
                        break;
                    }
                }
                if (oe != null) {
                    if (oe instanceof JSONObject) {
                        Bundle[] va = new Bundle[a.length()];
                        for (int j = 0; j < a.length(); ++j) {
                            if (a.isNull(j)) {
                                va[j] = null;
                            } else {
                                va[j] = convertToBundle((JSONObject) a.getJSONObject(j), expander);
                            }
                        }
                        b.putParcelableArray(key, va);
                    } else if (oe instanceof JSONArray) {
                        throw new JSONException("Unable to convert nested arrays");
                    } else if (oe instanceof String) {
                        String[] va = new String[a.length()];
                        for (int j = 0; j < a.length(); ++j) {
                            if (a.isNull(j)) {
                                va[j] = null;
                            } else {
                                va[j] = a.getString(j);
                            }
                        }
                        b.putStringArray(key, va);
                    } else if (oe instanceof Boolean) {
                        boolean[] va = new boolean[a.length()];
                        for (int j = 0; j < a.length(); ++j) {
                            if (a.isNull(j)) {
                                va[j] = false;
                            } else {
                                va[j] = a.getBoolean(j);
                            }
                        }
                        b.putBooleanArray(key, va);
                    } else if (oe instanceof Integer) {
                        int[] va = new int[a.length()];
                        for (int j = 0; j < a.length(); ++j) {
                            if (a.isNull(j)) {
                                va[j] = 0;
                            } else {
                                va[j] = a.getInt(j);
                            }
                        }
                        b.putIntArray(key, va);
                    } else if (oe instanceof Long) {
                        long[] va = new long[a.length()];
                        for (int j = 0; j < a.length(); ++j) {
                            if (a.isNull(j)) {
                                va[j] = 0;
                            } else {
                                va[j] = a.getLong(j);
                            }
                        }
                        b.putLongArray(key, va);
                    } else if (oe instanceof Double) {
                        double[] va = new double[a.length()];
                        for (int j = 0; j < a.length(); ++j) {
                            if (a.isNull(j)) {
                                va[j] = Double.NaN;
                            } else {
                                va[j] = a.getDouble(j);
                            }
                        }
                        b.putDoubleArray(key, va);
                    }
                }
            } else if (o instanceof String) {
                String v = valueMap.getString(key);
                if (expander != null) {
                    v = expander.expandString(v);
                }
                b.putString(key, v);
            } else if (o instanceof Boolean) {
                b.putBoolean(key, valueMap.getBoolean(key));
            } else if (o instanceof Integer) {
                b.putInt(key, valueMap.getInt(key));
            } else if (o instanceof Long) {
                b.putLong(key, valueMap.getLong(key));
            } else if (o instanceof Double) {
                b.putDouble(key, valueMap.getDouble(key));
            }
        }
    }
    return b;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
public static Bundle persistableBundleToBundle(PersistableBundle persistableBundle) {
    Set<String> keySet = persistableBundle.keySet();
    Bundle bundle = new Bundle();
    for (String key : keySet) {
        Object value = persistableBundle.get(key);
        if (value instanceof Boolean) {
            bundle.putBoolean(key, (boolean) value);
        } else if (value instanceof Integer) {
            bundle.putInt(key, (int) value);
        } else if (value instanceof String) {
            bundle.putString(key, (String) value);
        } else if (value instanceof String[]) {
            bundle.putStringArray(key, (String[]) value);
        } else if (value instanceof PersistableBundle) {
            Bundle innerBundle = persistableBundleToBundle((PersistableBundle) value);
            bundle.putBundle(key, innerBundle);
        }//w  w w  . ja  v a  2  s  .  c o m
    }
    return bundle;
}