Java Code Examples for android.os.Bundle#putCharSequenceArray()
The following examples show how to use
android.os.Bundle#putCharSequenceArray() .
These examples are extracted from open source projects.
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 Project: Kore File: GenericSelectDialog.java License: Apache License 2.0 | 6 votes |
/** * 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 2
Source Project: AndroidMaterialDialog File: ListDialogDecorator.java License: Apache License 2.0 | 6 votes |
@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 3
Source Project: android-styled-dialogs File: ListDialogFragment.java License: Apache License 2.0 | 6 votes |
@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 4
Source Project: HgLauncher File: GesturesPreference.java License: GNU General Public License v3.0 | 5 votes |
@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 5
Source Project: AndroidTabbedDialog File: TabDialogFragment.java License: Apache License 2.0 | 5 votes |
@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 6
Source Project: SpotifyAdBlocker File: ViewAdditionalFiltersDialogFragment.java License: MIT License | 5 votes |
public static ViewAdditionalFiltersDialogFragment newInstance(CharSequence[] additionalFilters) { Bundle args = new Bundle(); args.putCharSequenceArray("additionalFilters", additionalFilters); ViewAdditionalFiltersDialogFragment fragment = new ViewAdditionalFiltersDialogFragment(); fragment.setArguments(args); return fragment; }
Example 7
Source Project: HgLauncher File: GesturesPreference.java License: GNU General Public License v3.0 | 5 votes |
@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 8
Source Project: MaterialPreference File: MultiSelectListPreferenceDialogFragment.java License: Apache License 2.0 | 5 votes |
@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 9
Source Project: Dashchan File: ForegroundManager.java License: Apache License 2.0 | 5 votes |
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 10
Source Project: adt-leanback-support File: RemoteInputCompatJellybean.java License: Apache License 2.0 | 5 votes |
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 11
Source Project: oneHookLibraryAndroid File: OHCompactAlertDialogFragment.java License: Apache License 2.0 | 5 votes |
/** * @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 12
Source Project: react-native-GPay File: DialogModule.java License: MIT License | 4 votes |
@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 13
Source Project: android-state File: InjectionHelper.java License: Eclipse Public License 1.0 | 4 votes |
public void putCharSequenceArray(Bundle state, String key, CharSequence[] x) { state.putCharSequenceArray(key + mBaseKey, x); }
Example 14
Source Project: Meepo File: MeepoUtils.java License: Apache License 2.0 | 4 votes |
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 15
Source Project: react-native-prompt-android File: RNPromptModule.java License: MIT License | 4 votes |
@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 Project: SimpleAlertDialog-for-Android File: SimpleAlertDialog.java License: Apache License 2.0 | 4 votes |
/** * 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 17
Source Project: AndroidCommons File: InstanceStateManager.java License: Apache License 2.0 | 4 votes |
@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 18
Source Project: lyra File: CharSequenceArrayCoder.java License: Apache License 2.0 | 2 votes |
/** * 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); }