Example usage for android.os Bundle putStringArray

List of usage examples for android.os Bundle putStringArray

Introduction

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

Prototype

public void putStringArray(@Nullable String key, @Nullable String[] value) 

Source Link

Document

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

Usage

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);
        }//from   w  w w.j av  a 2s .  c  o  m
    }
    return bundle;
}

From source file:com.google.plus.samples.photohunt.PlusClientFragment.java

/**
 * Attach a {@link PlusClient} managing fragment to you activity.
 *
 * @param activity The activity to attach the fragment to.
 * @param scopes The scopes to request permission for.
 * @param visibleActivities An array of visible activities to request.
 * @return The fragment managing a {@link PlusClient}.
 *//*from   w  ww. ja  v a  2 s.  com*/
public static PlusClientFragment getPlusClientFragment(FragmentActivity activity, String[] scopes,
        String[] visibleActivities) {
    if (!(activity instanceof OnSignInListener)) {
        throw new IllegalArgumentException(
                "The activity must implement OnSignedInListener to receive callbacks.");
    }

    // Check if the fragment is already attached.
    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    Fragment fragment = fragmentManager.findFragmentByTag(TAG_PLUS_CLIENT);
    if (fragment instanceof PlusClientFragment) {
        // The fragment is attached.  If it has the right visible activities, return it.
        if (Arrays.equals(visibleActivities, fragment.getArguments().getStringArray(ARG_VISIBLE_ACTIVITIES))) {
            return (PlusClientFragment) fragment;
        }
    }

    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    // If a fragment was already attached, remove it to clean up.
    if (fragment != null) {
        fragmentTransaction.remove(fragment);
    }

    // Create a new fragment and attach it to the fragment manager.
    Bundle arguments = new Bundle();
    arguments.putStringArray(ARG_VISIBLE_ACTIVITIES, visibleActivities);
    arguments.putStringArray(ARG_SCOPES, scopes);
    PlusClientFragment signInFragment = new PlusClientFragment();
    signInFragment.setArguments(arguments);
    fragmentTransaction.add(signInFragment, TAG_PLUS_CLIENT);
    fragmentTransaction.commit();
    return signInFragment;
}

From source file:gr.scify.newsum.ui.PlusClientFragment.java

/**
 * Attach a {@link PlusClient} managing fragment to you activity.
 *
 * @param activity The activity to attach the fragment to.
 * @param visibleActivities An array of visible activities to request.
 * @return The fragment managing a {@link PlusClient}.
 *///w w w.j  a  va2  s.com
public static PlusClientFragment getPlusClientFragment(FragmentActivity activity, String[] visibleActivities) {
    if (!(activity instanceof OnSignedInListener)) {
        throw new IllegalArgumentException(
                "The activity must implement OnSignedInListener to receive callbacks.");
    }

    // Check if the fragment is already attached.
    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    Fragment fragment = fragmentManager.findFragmentByTag(TAG_PLUS_CLIENT);
    if (fragment instanceof PlusClientFragment) {
        // The fragment is attached.  If it has the right visible activities, return it.
        if (Arrays.equals(visibleActivities, fragment.getArguments().getStringArray(ARG_VISIBLE_ACTIVITIES))) {
            return (PlusClientFragment) fragment;
        }
    }

    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    // If a fragment was already attached, remove it to clean up.
    if (fragment != null) {
        fragmentTransaction.remove(fragment);
    }

    // Create a new fragment and attach it to the fragment manager.
    Bundle arguments = new Bundle();
    arguments.putStringArray(ARG_VISIBLE_ACTIVITIES, visibleActivities);
    PlusClientFragment signInFragment = new PlusClientFragment();
    signInFragment.setArguments(arguments);
    fragmentTransaction.add(signInFragment, TAG_PLUS_CLIENT);
    fragmentTransaction.commit();
    return signInFragment;
}

From source file:com.sprunck.openit.activity.PlusClientFragment.java

/**
 * Attach a {@link com.google.android.gms.plus.PlusClient} managing fragment to you activity.
 *
 * @param activity The activity to attach the fragment to.
 * @param scopes   The scopes to request permission for.
 * @param actions  An array of actions to request.
 * @return The fragment managing a {@link com.google.android.gms.plus.PlusClient}.
 *///from   w  w w.jav a2  s.co  m
public static PlusClientFragment getPlusClientFragment(FragmentActivity activity, String[] scopes,
        String[] actions) {
    if (!(activity instanceof OnSignInListener)) {
        throw new IllegalArgumentException(
                "The activity must implement OnSignedInListener to receive callbacks.");
    }

    // Check if the fragment is already attached.
    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    Fragment fragment = fragmentManager.findFragmentByTag(TAG_PLUS_CLIENT);
    if (fragment instanceof PlusClientFragment) {
        // The fragment is attached.  If it has the right visible activities, return it.
        if (Arrays.equals(actions, fragment.getArguments().getStringArray(ARG_ACTIONS))) {
            return (PlusClientFragment) fragment;
        }
    }

    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    // If a fragment was already attached, remove it to clean up.
    if (fragment != null) {
        fragmentTransaction.remove(fragment);
    }

    // Create a new fragment and attach it to the fragment manager.
    Bundle arguments = new Bundle();
    arguments.putStringArray(ARG_ACTIONS, actions);
    arguments.putStringArray(ARG_SCOPES, scopes);
    PlusClientFragment signInFragment = new PlusClientFragment();
    signInFragment.setArguments(arguments);
    fragmentTransaction.add(signInFragment, TAG_PLUS_CLIENT);
    fragmentTransaction.commit();
    return signInFragment;
}

From source file:donations.DonationsFragment.java

/**
 * Instantiate DonationsFragment.//from   w  ww.  ja va2 s .c om
 *
 * @param debug               You can use BuildConfig.DEBUG to propagate the debug flag from your app to the Donations library
 * @param googleEnabled       Enabled Google Play donations
 * @param googlePubkey        Your Google Play public key
 * @param googleCatalog       Possible item names that can be purchased from Google Play
 * @param googleCatalogValues Values for the names
 * @param paypalEnabled       Enable PayPal donations
 * @param paypalUser          Your PayPal email address
 * @param paypalCurrencyCode  Currency code like EUR. See here for other codes:
 *                            https://developer.paypal.com/webapps/developer/docs/classic/api/currency_codes/#id09A6G0U0GYK
 * @param paypalItemName      Display item name on PayPal, like "Donation for NTPSync"
 * @param flattrEnabled       Enable Flattr donations
 * @param flattrProjectUrl    The project URL used on Flattr
 * @param flattrUrl           The Flattr URL to your thing. NOTE: Enter without http://
 * @return DonationsFragment
 */
public static DonationsFragment newInstance(boolean debug, boolean googleEnabled, String googlePubkey,
        String[] googleCatalog, String[] googleCatalogValues, boolean paypalEnabled, String paypalUser,
        String paypalCurrencyCode, String paypalItemName, boolean flattrEnabled, String flattrProjectUrl,
        String flattrUrl) {
    DonationsFragment donationsFragment = new DonationsFragment();
    Bundle args = new Bundle();

    args.putBoolean(ARG_DEBUG, debug);

    args.putBoolean(ARG_GOOGLE_ENABLED, googleEnabled);
    args.putString(ARG_GOOGLE_PUBKEY, googlePubkey);
    args.putStringArray(ARG_GOOGLE_CATALOG, googleCatalog);
    args.putStringArray(ARG_GOOGLE_CATALOG_VALUES, googleCatalogValues);

    args.putBoolean(ARG_PAYPAL_ENABLED, paypalEnabled);
    args.putString(ARG_PAYPAL_USER, paypalUser);
    args.putString(ARG_PAYPAL_CURRENCY_CODE, paypalCurrencyCode);
    args.putString(ARG_PAYPAL_ITEM_NAME, paypalItemName);

    args.putBoolean(ARG_FLATTR_ENABLED, flattrEnabled);
    args.putString(ARG_FLATTR_PROJECT_URL, flattrProjectUrl);
    args.putString(ARG_FLATTR_URL, flattrUrl);

    donationsFragment.setArguments(args);
    return donationsFragment;
}

From source file:com.ultramegasoft.flavordex2.dialog.FileSelectorDialog.java

/**
 * @param fm               The FragmentManager to use
 * @param target           The Fragment to send results to
 * @param requestCode      The request code
 * @param rootPath         The initial starting path
 * @param allowDirectories Whether to allow directories to be selected
 * @param nameFilter       Filter out files that do not contain any of these string
 * @param path             The current path
 *///w  w  w.j  av a 2 s .c  o  m
private static void showDialog(@NonNull FragmentManager fm, @Nullable Fragment target, int requestCode,
        @Nullable String rootPath, boolean allowDirectories, @Nullable String[] nameFilter,
        @Nullable String path) {
    final DialogFragment fragment = new FileSelectorDialog();
    fragment.setTargetFragment(target, requestCode);

    final Bundle args = new Bundle();
    args.putString(ARG_ROOT_PATH, rootPath);
    args.putString(ARG_PATH, path);
    args.putBoolean(ARG_ALLOW_DIRECTORIES, allowDirectories);
    args.putStringArray(ARG_NAME_FILTER, nameFilter);
    fragment.setArguments(args);

    fragment.show(fm, TAG);
}

From source file:jahirfiquitiva.iconshowcase.fragments.DonationsFragment.java

/**
 * Instantiate DonationsFragment.//from   ww  w .jav  a  2 s. com
 *
 * @param debug               You can use BuildConfig.DEBUG to propagate the debug flag from your app to the Donations library
 * @param googleEnabled       Enabled Google Play donations
 * @param googlePubkey        Your Google Play public key
 * @param googleCatalog       Possible item names that can be purchased from Google Play
 * @param googleCatalogValues Values for the names
 * @param paypalEnabled       Enable PayPal donations
 * @param paypalUser          Your PayPal email address
 * @param paypalCurrencyCode  Currency code like EUR. See here for other codes:
 *                            https://developer.paypal.com/webapps/developer/docs/classic/api/currency_codes/#id09A6G0U0GYK
 * @param paypalItemName      Display item name on PayPal, like "Donation for NTPSync"
 * @param flattrEnabled       Enable Flattr donations
 * @param flattrProjectUrl    The project URL used on Flattr
 * @param flattrUrl           The Flattr URL to your thing. NOTE: Enter without http://
 * @param bitcoinEnabled      Enable bitcoin donations
 * @param bitcoinAddress      The address to receive bitcoin
 *
 * @return DonationsFragment
 */
public static DonationsFragment newInstance(boolean debug, boolean googleEnabled, String googlePubkey,
        String[] googleCatalog, String[] googleCatalogValues, boolean paypalEnabled, String paypalUser,
        String paypalCurrencyCode, String paypalItemName, boolean flattrEnabled, String flattrProjectUrl,
        String flattrUrl, boolean bitcoinEnabled, String bitcoinAddress) {
    DonationsFragment donationsFragment = new DonationsFragment();
    Bundle args = new Bundle();

    args.putBoolean(ARG_DEBUG, debug);

    args.putBoolean(ARG_GOOGLE_ENABLED, googleEnabled);
    args.putString(ARG_GOOGLE_PUBKEY, googlePubkey);
    args.putStringArray(ARG_GOOGLE_CATALOG, googleCatalog);
    args.putStringArray(ARG_GOOGLE_CATALOG_VALUES, googleCatalogValues);

    args.putBoolean(ARG_PAYPAL_ENABLED, paypalEnabled);
    args.putString(ARG_PAYPAL_USER, paypalUser);
    args.putString(ARG_PAYPAL_CURRENCY_CODE, paypalCurrencyCode);
    args.putString(ARG_PAYPAL_ITEM_NAME, paypalItemName);

    args.putBoolean(ARG_FLATTR_ENABLED, flattrEnabled);
    args.putString(ARG_FLATTR_PROJECT_URL, flattrProjectUrl);
    args.putString(ARG_FLATTR_URL, flattrUrl);

    args.putBoolean(ARG_BITCOIN_ENABLED, bitcoinEnabled);
    args.putString(ARG_BITCOIN_ADDRESS, bitcoinAddress);

    donationsFragment.setArguments(args);
    return donationsFragment;
}

From source file:io.flutter.embedding.engine.android.FlutterFragment.java

/**
 * Creates a {@link Bundle} of arguments that can be used to configure a {@link FlutterFragment}.
 * This method is exposed so that developers can create subclasses of {@link FlutterFragment}.
 * Subclasses should declare static factories that use this method to create arguments that will
 * be understood by the base class, and then the subclass can add any additional arguments it
 * wants to this {@link Bundle}. Example:
 * <pre>{@code/* w ww. j  a  v a  2 s  . co m*/
 * public static MyFlutterFragment newInstance(String myNewArg) {
 *   // Create an instance of our subclass Fragment.
 *   MyFlutterFragment myFrag = new MyFlutterFragment();
 *
 *   // Create the Bundle or args that FlutterFragment understands.
 *   Bundle args = FlutterFragment.createArgsBundle(...);
 *
 *   // Add our new args to the bundle.
 *   args.putString(ARG_MY_NEW_ARG, myNewArg);
 *
 *   // Give the args to our subclass Fragment.
 *   myFrag.setArguments(args);
 *
 *   // Return the newly created subclass Fragment.
 *   return myFrag;
 * }
 * }</pre>
 *
 * @param dartEntrypoint the name of the initial Dart method to invoke, defaults to "main"
 * @param initialRoute the first route that a Flutter app will render in this {@link FlutterFragment}, defaults to "/"
 * @param appBundlePath the path to the app bundle which contains the Dart app to execute
 * @param flutterShellArgs any special configuration arguments for the Flutter engine
 *
 * @return Bundle of arguments that configure a {@link FlutterFragment}
 */
protected static Bundle createArgsBundle(@Nullable String dartEntrypoint, @Nullable String initialRoute,
        @Nullable String appBundlePath, @Nullable FlutterShellArgs flutterShellArgs) {
    Bundle args = new Bundle();
    args.putString(ARG_INITIAL_ROUTE, initialRoute);
    args.putString(ARG_APP_BUNDLE_PATH, appBundlePath);
    args.putString(ARG_DART_ENTRYPOINT, dartEntrypoint);
    // TODO(mattcarroll): determine if we should have an explicit FlutterTestFragment instead of conflating.
    if (null != flutterShellArgs) {
        args.putStringArray(ARG_FLUTTER_INITIALIZATION_ARGS, flutterShellArgs.toArray());
    }
    return args;
}

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 w  w w  .j a  v a2s  .  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.lol.reddit.fragments.CommentListingFragment.java

public static CommentListingFragment newInstance(final List<RedditURLParser.RedditURL> urls, final UUID session,
        final CacheRequest.DownloadType downloadType) {

    final CommentListingFragment f = new CommentListingFragment();

    final Bundle bundle = new Bundle(3);

    final String[] urlStrings = new String[urls.size()];
    {//  w w w  .  j  a va2 s.  c  om
        int i = 0;
        for (final RedditURLParser.RedditURL url : urls) {
            urlStrings[i++] = url.toString();
        }
    }

    bundle.putStringArray("urls", urlStrings);
    if (session != null)
        bundle.putString("session", session.toString());
    bundle.putString("downloadType", downloadType.name());

    f.setArguments(bundle);

    return f;
}