Java Code Examples for android.os.Bundle#putCharSequenceArray()

The following examples show how to use android.os.Bundle#putCharSequenceArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ListDialogFragment.java    From android-styled-dialogs with Apache License 2.0 6 votes vote down vote up
@Override
protected Bundle prepareArguments() {
    Bundle args = new Bundle();
    args.putCharSequence(ARG_TITLE, title);
    args.putCharSequence(ARG_POSITIVE_BUTTON, confirmButtonText);
    args.putCharSequence(ARG_NEGATIVE_BUTTON, cancelButtonText);

    args.putCharSequenceArray(ARG_ITEMS, items);

    SparseBooleanArrayParcelable sparseArray = new SparseBooleanArrayParcelable();
    for (int index = 0; checkedItems != null && index < checkedItems.length; index++) {
        sparseArray.put(checkedItems[index], true);
    }
    args.putParcelable(ARG_CHECKED_ITEMS, sparseArray);
    args.putInt(ARG_MODE, mode);


    return args;
}
 
Example 2
Source File: GenericSelectDialog.java    From Kore with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new instance of the dialog, providing arguments.
 * @param listener Listener for selection
 * @param token Token to be returned on the callback, to differentiate different calls
 * @param title Title of the dialog
 * @param items String array of the options to show in the dialog
 * @param selectedItem Index of the selected item
 * @return New dialog
 */
public static GenericSelectDialog newInstance(GenericSelectDialogListener listener,
                                              int token, String title, CharSequence[] items, int selectedItem) {
    GenericSelectDialog dialog = new GenericSelectDialog();
    // TODO: This isn't going to survive destroys, but it's the easiast way to communicate
    dialog.mListener = listener;

    Bundle args = new Bundle();
    args.putInt(TOKEN_KEY, token);
    args.putString(TITLE_KEY, title);
    args.putCharSequenceArray(ARRAY_ITEMS, items);
    args.putInt(SELECTED_ITEM_KEY, selectedItem);
    dialog.setArguments(args);

    return dialog;
}
 
Example 3
Source File: ListDialogDecorator.java    From AndroidMaterialDialog with Apache License 2.0 6 votes vote down vote up
@Override
public final void onSaveInstanceState(@NonNull final Bundle outState) {
    outState.putParcelable(ITEM_COLOR_EXTRA, getItemColor());
    outState.putIntArray(ICON_RESOURCE_IDS_EXTRA, iconResourceIds);

    if (items != null) {
        outState.putCharSequenceArray(ITEMS_EXTRA, items);
        outState.putBooleanArray(ENABLED_ITEMS_EXTRA, getEnabledItems());
    } else if (singleChoiceItems != null) {
        outState.putCharSequenceArray(SINGLE_CHOICE_ITEMS_EXTRA, singleChoiceItems);
        outState.putBooleanArray(CHECKED_ITEMS_EXTRA, getCheckedItems());
        outState.putBooleanArray(ENABLED_ITEMS_EXTRA, getEnabledItems());
    } else if (multiChoiceItems != null) {
        outState.putCharSequenceArray(MULTI_CHOICE_ITEMS_EXTRA, multiChoiceItems);
        outState.putBooleanArray(CHECKED_ITEMS_EXTRA, getCheckedItems());
        outState.putBooleanArray(ENABLED_ITEMS_EXTRA, getEnabledItems());
    }
}
 
Example 4
Source File: OHCompactAlertDialogFragment.java    From oneHookLibraryAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * @param tag                    tag of this dialog. can be used to identify the dialog
 * @param title                  title res id
 * @param text                   message res id
 * @param button1                button 1 text res id (on the right)
 * @param button2                button 2 text res id (on the left)
 * @param selectableItems
 * @param selectableItemsRes
 * @param selectableItemIconsRes
 * @param object                 additional serialized  object
 * @param cancelable             is dialog is cancelable when tapped outside
 * @return a new alert dialog fragment
 */
private static OHCompactAlertDialogFragment newInstance(final String tag, final String title,
                                                        final String text, final String button1, final String button2,
                                                        final CharSequence[] selectableItems,
                                                        final int[] selectableItemsRes,
                                                        final int[] selectableItemIconsRes,
                                                        final Object object, final boolean cancelable) {
    final OHCompactAlertDialogFragment frag = new OHCompactAlertDialogFragment();
    frag.setCancelable(true);
    final Bundle args = new Bundle();
    args.putString(ARG_TAG, tag);
    args.putString(ARG_TITLE, title);
    args.putString(ARG_BUTTON1, button1);
    args.putString(ARG_BUTTON2, button2);
    args.putString(ARG_TEXT, text);
    args.putCharSequenceArray(ARG_SELECTABLE_ITEMS, selectableItems);
    args.putIntArray(ARG_SELECTABLE_ITEM_ICONS_RES, selectableItemIconsRes);
    args.putIntArray(ARG_SELECTABLE_ITEMS_RES, selectableItemsRes);
    if (object != null) {
        if (object instanceof Parcelable) {
            args.putParcelable(ARG_OBJECT_P, (Parcelable) object);
        } else if (object instanceof Serializable) {
            args.putSerializable(ARG_OBJECT_S, (Serializable) object);
        } else {
            throw new RuntimeException("Attached object can only be parcelable or serializable");
        }
    }
    args.putBoolean(ARG_CANCELLABLE, cancelable);
    frag.setArguments(args);
    return frag;
}
 
Example 5
Source File: GesturesPreference.java    From HgLauncher with GNU General Public License v3.0 5 votes vote down vote up
@Override public boolean onPreferenceChange(Preference preference, Object newValue) {
    ListPreference list = (ListPreference) preference;
    String value = (String) newValue;

    // Workaround due to the use of setSummary in onCreate.
    switch (value) {
        case "handler":
            list.setSummary(R.string.gesture_action_handler);
            break;
        case "widget":
            list.setSummary(R.string.gesture_action_widget);
            break;
        case "status":
            list.setSummary(R.string.gesture_action_status);
            break;
        case "list":
            list.setSummary(R.string.gesture_action_list);
            break;
        case "app":
            // Create the Bundle to pass to AppSelectionPreferenceDialog.
            Bundle appListBundle = new Bundle();
            appListBundle.putString("key", list.getKey());
            appListBundle.putCharSequenceArray("entries", appListEntries);
            appListBundle.putCharSequenceArray("entryValues", appListEntryValues);

            // Call and create AppSelectionPreferenceDialog.
            AppSelectionPreferenceDialog appList = new AppSelectionPreferenceDialog();
            appList.setTargetFragment(GesturesPreference.this, APPLICATION_DIALOG_CODE);
            appList.setArguments(appListBundle);
            appList.show(requireFragmentManager(), "AppSelectionDialog");
            break;
        case "none":
        default:
            list.setSummary(R.string.gesture_action_default);
            break;
    }
    return true;
}
 
Example 6
Source File: TabDialogFragment.java    From AndroidTabbedDialog with Apache License 2.0 5 votes vote down vote up
@Override
protected Bundle prepareArguments() {
    Bundle args = new Bundle();
    args.putCharSequence(TabDialogFragment.ARG_MESSAGE, mMessage);
    args.putCharSequence(TabDialogFragment.ARG_TITLE, mTitle);
    args.putCharSequence(TabDialogFragment.ARG_SUB_TITLE, mSubTitle);
    args.putCharSequence(TabDialogFragment.ARG_POSITIVE_BUTTON, mPositiveButtonText);
    args.putCharSequence(TabDialogFragment.ARG_NEGATIVE_BUTTON, mNegativeButtonText);
    args.putCharSequence(TabDialogFragment.ARG_NEUTRAL_BUTTON, mNeutralButtonText);

    args.putCharSequenceArray(TabDialogFragment.ARG_TAB_BUTTON, mTabButtonText);

    return args;
}
 
Example 7
Source File: ViewAdditionalFiltersDialogFragment.java    From SpotifyAdBlocker with MIT License 5 votes vote down vote up
public static ViewAdditionalFiltersDialogFragment newInstance(CharSequence[] additionalFilters) {

        Bundle args = new Bundle();
        args.putCharSequenceArray("additionalFilters", additionalFilters);
        ViewAdditionalFiltersDialogFragment fragment = new ViewAdditionalFiltersDialogFragment();
        fragment.setArguments(args);
        return fragment;
    }
 
Example 8
Source File: GesturesPreference.java    From HgLauncher with GNU General Public License v3.0 5 votes vote down vote up
@Override public boolean onPreferenceChange(Preference preference, Object newValue) {
    ListPreference list = (ListPreference) preference;
    String value = (String) newValue;

    // Workaround due to the use of setSummary in onCreate.
    switch (value) {
        case "handler":
            list.setSummary(R.string.gesture_action_handler);
            break;
        case "widget":
            list.setSummary(R.string.gesture_action_widget);
            break;
        case "status":
            list.setSummary(R.string.gesture_action_status);
            break;
        case "list":
            list.setSummary(R.string.gesture_action_list);
            break;
        case "app":
            // Create the Bundle to pass to AppSelectionPreferenceDialog.
            Bundle appListBundle = new Bundle();
            appListBundle.putString("key", list.getKey());
            appListBundle.putCharSequenceArray("entries", appListEntries);
            appListBundle.putCharSequenceArray("entryValues", appListEntryValues);

            // Call and create AppSelectionPreferenceDialog.
            AppSelectionPreferenceDialog appList = new AppSelectionPreferenceDialog();
            appList.setTargetFragment(GesturesPreference.this, APPLICATION_DIALOG_CODE);
            appList.setArguments(appListBundle);
            appList.show(requireFragmentManager(), "AppSelectionDialog");
            break;
        case "none":
        default:
            list.setSummary(R.string.gesture_action_default);
            break;
    }
    return true;
}
 
Example 9
Source File: MultiSelectListPreferenceDialogFragment.java    From MaterialPreference with Apache License 2.0 5 votes vote down vote up
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putStringArrayList(SAVE_STATE_VALUES, new ArrayList<>(mNewValues));
    outState.putBoolean(SAVE_STATE_CHANGED, mPreferenceChanged);
    outState.putCharSequenceArray(SAVE_STATE_ENTRIES, mEntries);
    outState.putCharSequenceArray(SAVE_STATE_ENTRY_VALUES, mEntryValues);
}
 
Example 10
Source File: ForegroundManager.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
public ItemChoiceDialogFragment(int pendingDataIndex, boolean[] selected, CharSequence[] items,
		String descriptionText, Bitmap descriptionImage, boolean multiple) {
	Bundle args = new Bundle();
	fillArguments(args, pendingDataIndex);
	args.putBooleanArray(EXTRA_SELECTED, selected);
	args.putCharSequenceArray(EXTRA_ITEMS, items);
	args.putString(EXTRA_DESCRIPTION_TEXT, descriptionText);
	args.putParcelable(EXTRA_DESCRIPTION_IMAGE, descriptionImage);
	args.putBoolean(EXTRA_MULTIPLE, multiple);
	setArguments(args);
}
 
Example 11
Source File: RemoteInputCompatJellybean.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
static Bundle toBundle(RemoteInputCompatBase.RemoteInput remoteInput) {
    Bundle data = new Bundle();
    data.putString(KEY_RESULT_KEY, remoteInput.getResultKey());
    data.putCharSequence(KEY_LABEL, remoteInput.getLabel());
    data.putCharSequenceArray(KEY_CHOICES, remoteInput.getChoices());
    data.putBoolean(KEY_ALLOW_FREE_FORM_INPUT, remoteInput.getAllowFreeFormInput());
    data.putBundle(KEY_EXTRAS, remoteInput.getExtras());
    return data;
}
 
Example 12
Source File: InstanceStateManager.java    From AndroidCommons with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private static void setBundleValue(@NonNull Field field, @NonNull Object obj,
        @NonNull Bundle bundle, @NonNull String key, boolean isGson)
        throws IllegalAccessException {

    if (isGson) {
        bundle.putString(key, GsonHelper.toJson(field.get(obj)));
        return;
    }

    Class<?> type = field.getType();
    Type[] genericTypes = null;
    if (field.getGenericType() instanceof ParameterizedType) {
        genericTypes = ((ParameterizedType) field.getGenericType()).getActualTypeArguments();
    }

    if (type.equals(Boolean.TYPE)) {
        bundle.putBoolean(key, field.getBoolean(obj));

    } else if (type.equals(boolean[].class)) {
        bundle.putBooleanArray(key, (boolean[]) field.get(obj));

    } else if (type.equals(Bundle.class)) {
        bundle.putBundle(key, (Bundle) field.get(obj));

    } else if (type.equals(Byte.TYPE)) {
        bundle.putByte(key, field.getByte(obj));

    } else if (type.equals(byte[].class)) {
        bundle.putByteArray(key, (byte[]) field.get(obj));

    } else if (type.equals(Character.TYPE)) {
        bundle.putChar(key, field.getChar(obj));

    } else if (type.equals(char[].class)) {
        bundle.putCharArray(key, (char[]) field.get(obj));

    } else if (type.equals(CharSequence.class)) {
        bundle.putCharSequence(key, (CharSequence) field.get(obj));

    } else if (type.equals(CharSequence[].class)) {
        bundle.putCharSequenceArray(key, (CharSequence[]) field.get(obj));

    } else if (type.equals(Double.TYPE)) {
        bundle.putDouble(key, field.getDouble(obj));

    } else if (type.equals(double[].class)) {
        bundle.putDoubleArray(key, (double[]) field.get(obj));

    } else if (type.equals(Float.TYPE)) {
        bundle.putFloat(key, field.getFloat(obj));

    } else if (type.equals(float[].class)) {
        bundle.putFloatArray(key, (float[]) field.get(obj));

    } else if (type.equals(Integer.TYPE)) {
        bundle.putInt(key, field.getInt(obj));

    } else if (type.equals(int[].class)) {
        bundle.putIntArray(key, (int[]) field.get(obj));

    } else if (type.equals(Long.TYPE)) {
        bundle.putLong(key, field.getLong(obj));

    } else if (type.equals(long[].class)) {
        bundle.putLongArray(key, (long[]) field.get(obj));

    } else if (type.equals(Short.TYPE)) {
        bundle.putShort(key, field.getShort(obj));

    } else if (type.equals(short[].class)) {
        bundle.putShortArray(key, (short[]) field.get(obj));

    } else if (type.equals(String.class)) {
        bundle.putString(key, (String) field.get(obj));

    } else if (type.equals(String[].class)) {
        bundle.putStringArray(key, (String[]) field.get(obj));

    } else if (Parcelable.class.isAssignableFrom(type)) {
        bundle.putParcelable(key, (Parcelable) field.get(obj));

    } else if (type.equals(ArrayList.class)
            && genericTypes != null
            && genericTypes[0] instanceof Class
            && Parcelable.class.isAssignableFrom((Class<?>) genericTypes[0])) {
        bundle.putParcelableArrayList(key, (ArrayList<? extends Parcelable>) field.get(obj));

    } else if (type.isArray() && Parcelable.class.isAssignableFrom(type.getComponentType())) {
        bundle.putParcelableArray(key, (Parcelable[]) field.get(obj));

    } else if (Serializable.class.isAssignableFrom(type)) {
        bundle.putSerializable(key, (Serializable) field.get(obj));

    } else {
        throw new RuntimeException("Unsupported field type: " + field.getName()
                + ", " + type.getName());
    }
}
 
Example 13
Source File: DialogModule.java    From react-native-GPay with MIT License 4 votes vote down vote up
@ReactMethod
public void showAlert(
    ReadableMap options,
    Callback errorCallback,
    final Callback actionCallback) {
  final FragmentManagerHelper fragmentManagerHelper = getFragmentManagerHelper();
  if (fragmentManagerHelper == null) {
    errorCallback.invoke("Tried to show an alert while not attached to an Activity");
    return;
  }

  final Bundle args = new Bundle();
  if (options.hasKey(KEY_TITLE)) {
    args.putString(AlertFragment.ARG_TITLE, options.getString(KEY_TITLE));
  }
  if (options.hasKey(KEY_MESSAGE)) {
    args.putString(AlertFragment.ARG_MESSAGE, options.getString(KEY_MESSAGE));
  }
  if (options.hasKey(KEY_BUTTON_POSITIVE)) {
    args.putString(AlertFragment.ARG_BUTTON_POSITIVE, options.getString(KEY_BUTTON_POSITIVE));
  }
  if (options.hasKey(KEY_BUTTON_NEGATIVE)) {
    args.putString(AlertFragment.ARG_BUTTON_NEGATIVE, options.getString(KEY_BUTTON_NEGATIVE));
  }
  if (options.hasKey(KEY_BUTTON_NEUTRAL)) {
    args.putString(AlertFragment.ARG_BUTTON_NEUTRAL, options.getString(KEY_BUTTON_NEUTRAL));
  }
  if (options.hasKey(KEY_ITEMS)) {
    ReadableArray items = options.getArray(KEY_ITEMS);
    CharSequence[] itemsArray = new CharSequence[items.size()];
    for (int i = 0; i < items.size(); i ++) {
      itemsArray[i] = items.getString(i);
    }
    args.putCharSequenceArray(AlertFragment.ARG_ITEMS, itemsArray);
  }
  if (options.hasKey(KEY_CANCELABLE)) {
    args.putBoolean(KEY_CANCELABLE, options.getBoolean(KEY_CANCELABLE));
  }

  UiThreadUtil.runOnUiThread(new Runnable() {
    @Override
    public void run() {
      fragmentManagerHelper.showNewAlert(mIsInForeground, args, actionCallback);
    }
  });

}
 
Example 14
Source File: SimpleAlertDialog.java    From SimpleAlertDialog-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Creates the arguments of the {@code SimpleAlertDialog} as a {@code Bundle}.<br/>
 * In most cases, you don't have to call this method directly.
 *
 * @return Created arguments bundle
 */
@TargetApi(Build.VERSION_CODES.FROYO)
public Bundle createArguments() {
    Bundle args = new Bundle();
    if (mThemeResId > 0) {
        args.putInt(SimpleAlertDialog.ARG_THEME_RES_ID, mThemeResId);
    }
    if (mTitle != null) {
        args.putCharSequence(SimpleAlertDialog.ARG_TITLE, mTitle);
    } else if (mTitleResId > 0) {
        args.putInt(SimpleAlertDialog.ARG_TITLE_RES_ID, mTitleResId);
    }
    if (mIcon > 0) {
        args.putInt(SimpleAlertDialog.ARG_ICON, mIcon);
    }
    if (mMessage != null) {
        args.putCharSequence(SimpleAlertDialog.ARG_MESSAGE, mMessage);
    } else if (mMessageResId > 0) {
        args.putInt(SimpleAlertDialog.ARG_MESSAGE_RES_ID, mMessageResId);
    }
    if (mPositiveButton != null) {
        args.putCharSequence(SimpleAlertDialog.ARG_POSITIVE_BUTTON, mPositiveButton);
    } else if (mPositiveButtonResId > 0) {
        args.putInt(SimpleAlertDialog.ARG_POSITIVE_BUTTON_RES_ID, mPositiveButtonResId);
    }
    if (mNeutralButton != null) {
        args.putCharSequence(SimpleAlertDialog.ARG_NEUTRAL_BUTTON, mNeutralButton);
    } else if (mNeutralButtonResId > 0) {
        args.putInt(SimpleAlertDialog.ARG_NEUTRAL_BUTTON_RES_ID, mNeutralButtonResId);
    }
    if (mNegativeButton != null) {
        args.putCharSequence(SimpleAlertDialog.ARG_NEGATIVE_BUTTON, mNegativeButton);
    } else if (mNegativeButtonResId > 0) {
        args.putInt(SimpleAlertDialog.ARG_NEGATIVE_BUTTON_RES_ID, mNegativeButtonResId);
    }
    if (mItems != null && Build.VERSION_CODES.ECLAIR <= Build.VERSION.SDK_INT) {
        args.putCharSequenceArray(SimpleAlertDialog.ARG_ITEMS, mItems);
    } else if (mItemsResId > 0) {
        args.putInt(SimpleAlertDialog.ARG_ITEMS_RES_ID, mItemsResId);
    }
    if (mIcons != null) {
        args.putIntArray(SimpleAlertDialog.ARG_ICONS, mIcons);
    }
    args.putBoolean(SimpleAlertDialog.ARG_CANCELABLE, mCancelable);
    args.putBoolean(SimpleAlertDialog.ARG_CANCELED_ON_TOUCH_OUTSIDE,
            mCanceledOnTouchOutside);
    if (mSingleChoiceCheckedItem >= 0) {
        args.putInt(SimpleAlertDialog.ARG_SINGLE_CHOICE_CHECKED_ITEM,
                mSingleChoiceCheckedItem);
    }
    if (mEditTextInitialText != null || 0 < mEditTextInputType) {
        args.putCharSequence(SimpleAlertDialog.ARG_EDIT_TEXT_INITIAL_TEXT, mEditTextInitialText);
        args.putInt(SimpleAlertDialog.ARG_EDIT_TEXT_INPUT_TYPE, mEditTextInputType);
    }
    args.putBoolean(SimpleAlertDialog.ARG_USE_VIEW, mUseView);
    args.putBoolean(SimpleAlertDialog.ARG_USE_ADAPTER, mUseAdapter);
    args.putInt(SimpleAlertDialog.ARG_REQUEST_CODE, mRequestCode);
    return args;
}
 
Example 15
Source File: RNPromptModule.java    From react-native-prompt-android with MIT License 4 votes vote down vote up
@ReactMethod
public void promptWithArgs(ReadableMap options, final Callback callback) {
    final FragmentManagerHelper fragmentManagerHelper = getFragmentManagerHelper();
    if (fragmentManagerHelper == null) {
        FLog.w(RNPromptModule.class, "Tried to show an alert while not attached to an Activity");
        return;
    }

    final Bundle args = new Bundle();
    if (options.hasKey(KEY_TITLE)) {
        args.putString(RNPromptFragment.ARG_TITLE, options.getString(KEY_TITLE));
    }
    if (options.hasKey(KEY_MESSAGE)) {
        String message = options.getString(KEY_MESSAGE);
        if (!message.isEmpty()) {
            args.putString(RNPromptFragment.ARG_MESSAGE, options.getString(KEY_MESSAGE));
        }
    }
    if (options.hasKey(KEY_BUTTON_POSITIVE)) {
        args.putString(RNPromptFragment.ARG_BUTTON_POSITIVE, options.getString(KEY_BUTTON_POSITIVE));
    }
    if (options.hasKey(KEY_BUTTON_NEGATIVE)) {
        args.putString(RNPromptFragment.ARG_BUTTON_NEGATIVE, options.getString(KEY_BUTTON_NEGATIVE));
    }
    if (options.hasKey(KEY_BUTTON_NEUTRAL)) {
        args.putString(RNPromptFragment.ARG_BUTTON_NEUTRAL, options.getString(KEY_BUTTON_NEUTRAL));
    }
    if (options.hasKey(KEY_ITEMS)) {
        ReadableArray items = options.getArray(KEY_ITEMS);
        CharSequence[] itemsArray = new CharSequence[items.size()];
        for (int i = 0; i < items.size(); i++) {
            itemsArray[i] = items.getString(i);
        }
        args.putCharSequenceArray(RNPromptFragment.ARG_ITEMS, itemsArray);
    }
    if (options.hasKey(KEY_CANCELABLE)) {
        args.putBoolean(KEY_CANCELABLE, options.getBoolean(KEY_CANCELABLE));
    }
    if (options.hasKey(KEY_TYPE)) {
        args.putString(KEY_TYPE, options.getString(KEY_TYPE));
    }
    if (options.hasKey(KEY_STYLE)) {
        args.putString(KEY_STYLE, options.getString(KEY_STYLE));
    }
    if (options.hasKey(KEY_DEFAULT_VALUE)) {
        args.putString(KEY_DEFAULT_VALUE, options.getString(KEY_DEFAULT_VALUE));
    }
    if (options.hasKey(KEY_PLACEHOLDER)) {
        args.putString(KEY_PLACEHOLDER, options.getString(KEY_PLACEHOLDER));
    }
    fragmentManagerHelper.showNewAlert(mIsInForeground, args, callback);
}
 
Example 16
Source File: MeepoUtils.java    From Meepo with Apache License 2.0 4 votes vote down vote up
public static void putValueToBundle(
        @NonNull Bundle bundle, @NonNull String key, @NonNull Object value) {
    if (value instanceof String) {
        bundle.putString(key, (String) value);
    } else if (value instanceof Integer) {
        bundle.putInt(key, (int) value);
    } else if (value instanceof Boolean) {
        bundle.putBoolean(key, (boolean) value);
    } else if (value instanceof Long) {
        bundle.putLong(key, (long) value);
    } else if (value instanceof Short) {
        bundle.putShort(key, (short) value);
    } else if (value instanceof Double) {
        bundle.putDouble(key, (double) value);
    } else if (value instanceof Float) {
        bundle.putFloat(key, (float) value);
    } else if (value instanceof Character) {
        bundle.putChar(key, (char) value);
    } else if (value instanceof Byte) {
        bundle.putByte(key, (byte) value);
    } else if (value instanceof CharSequence) {
        bundle.putCharSequence(key, (CharSequence) value);
    } else if (value instanceof Bundle) {
        bundle.putBundle(key, (Bundle) value);
    } else if (value instanceof Parcelable) {
        bundle.putParcelable(key, (Parcelable) value);
    } else if (value instanceof String[]) {
        bundle.putStringArray(key, (String[]) value);
    } else if (value instanceof int[]) {
        bundle.putIntArray(key, (int[]) value);
    } else if (value instanceof boolean[]) {
        bundle.putBooleanArray(key, (boolean[]) value);
    } else if (value instanceof long[]) {
        bundle.putLongArray(key, (long[]) value);
    } else if (value instanceof short[]) {
        bundle.putShortArray(key, (short[]) value);
    } else if (value instanceof double[]) {
        bundle.putDoubleArray(key, (double[]) value);
    } else if (value instanceof float[]) {
        bundle.putFloatArray(key, (float[]) value);
    } else if (value instanceof char[]) {
        bundle.putCharArray(key, (char[]) value);
    } else if (value instanceof byte[]) {
        bundle.putByteArray(key, (byte[]) value);
    } else if (value instanceof CharSequence[]) {
        bundle.putCharSequenceArray(key, (CharSequence[]) value);
    } else if (value instanceof Parcelable[]) {
        bundle.putParcelableArray(key, (Parcelable[]) value);
    } else if (value instanceof ArrayList) {
        bundle.putIntegerArrayList(key, (ArrayList<Integer>) value);
    } else if (value instanceof SparseArray) {
        bundle.putSparseParcelableArray(key, (SparseArray<? extends Parcelable>) value);
    } else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            if (value instanceof IBinder) {
                bundle.putBinder(key, (IBinder) value);
                return;
            }
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            if (value instanceof Size) {
                bundle.putSize(key, (Size) value);
                return;
            } else if (value instanceof SizeF) {
                bundle.putSizeF(key, (SizeF) value);
                return;
            }
        }
        if (value instanceof Serializable) {
            bundle.putSerializable(key, (Serializable) value);
            return;
        }

        throw new RuntimeException(String.format(Locale.getDefault(),
                "Arguments extra %s has wrong type %s.", key, value.getClass().getName()));
    }
}
 
Example 17
Source File: InjectionHelper.java    From android-state with Eclipse Public License 1.0 4 votes vote down vote up
public void putCharSequenceArray(Bundle state, String key, CharSequence[] x) {
    state.putCharSequenceArray(key + mBaseKey, x);
}
 
Example 18
Source File: CharSequenceArrayCoder.java    From lyra with Apache License 2.0 2 votes vote down vote up
/**
 * Write a field's value into the saved state {@link Bundle}.
 *
 * @param state      {@link Bundle} used to save the state
 * @param key        key retrieved from {@code fieldDeclaringClass#fieldName}
 * @param fieldValue value of field
 */
@Override
public void serialize(@NonNull Bundle state, @NonNull String key, @NonNull CharSequence[] fieldValue) {
    state.putCharSequenceArray(key, fieldValue);
}