Java Code Examples for android.os.bundle#putByte()
The following examples show how to use
android.os.bundle#putByte() .
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: AbstractSpec.java From DeviceConnect-Android with MIT License | 6 votes |
/** * Number の値を Bundle に格納します. * * @param bundle Number の値を格納する Bundle * @param key キー * @param number 格納する値 */ protected void copyNumber(Bundle bundle, String key, Number number) { if (number instanceof Byte) { bundle.putByte(key, number.byteValue()); } else if (number instanceof Short) { bundle.putShort(key, number.shortValue()); } else if (number instanceof Integer) { bundle.putInt(key, number.intValue()); } else if (number instanceof Long) { bundle.putLong(key, number.longValue()); } else if (number instanceof Float) { bundle.putFloat(key, number.floatValue()); } else if (number instanceof Double) { bundle.putDouble(key, number.doubleValue()); } }
Example 2
Source File: KVUtils.java From letv with Apache License 2.0 | 6 votes |
public static Bundle put(Bundle to, Bundle from, String key) { if (!(to == null || from == null || TextUtils.empty(key) || !from.containsKey(key))) { Object value = from.get(key); if (value instanceof Boolean) { to.putBoolean(key, ((Boolean) value).booleanValue()); } else if (value instanceof Byte) { to.putByte(key, ((Byte) value).byteValue()); } else if (value instanceof Character) { to.putChar(key, ((Character) value).charValue()); } else if (value instanceof Short) { to.putShort(key, ((Short) value).shortValue()); } else if (value instanceof Integer) { to.putInt(key, ((Integer) value).intValue()); } else if (value instanceof Long) { to.putLong(key, ((Long) value).longValue()); } else if (value instanceof Float) { to.putFloat(key, ((Float) value).floatValue()); } else if (value instanceof Double) { to.putDouble(key, ((Double) value).doubleValue()); } else if (value instanceof String) { to.putString(key, (String) value); } } return to; }
Example 3
Source File: KVUtils.java From letv with Apache License 2.0 | 6 votes |
public static Bundle put(Bundle to, Intent from, String key) { if (!(to == null || from == null || TextUtils.empty(key) || !from.hasExtra(key))) { Object value = from.getExtras().get(key); if (value instanceof Boolean) { to.putBoolean(key, ((Boolean) value).booleanValue()); } else if (value instanceof Byte) { to.putByte(key, ((Byte) value).byteValue()); } else if (value instanceof Character) { to.putChar(key, ((Character) value).charValue()); } else if (value instanceof Short) { to.putShort(key, ((Short) value).shortValue()); } else if (value instanceof Integer) { to.putInt(key, ((Integer) value).intValue()); } else if (value instanceof Long) { to.putLong(key, ((Long) value).longValue()); } else if (value instanceof Float) { to.putFloat(key, ((Float) value).floatValue()); } else if (value instanceof Double) { to.putDouble(key, ((Double) value).doubleValue()); } else if (value instanceof String) { to.putString(key, (String) value); } } return to; }
Example 4
Source File: AbstractSpec.java From DeviceConnect-Android with MIT License | 5 votes |
/** * ベンダー拡張を Bundle に格納します. * * @param bundle ベンダー拡張を格納するBundle */ @SuppressWarnings("unchecked") protected void copyVendorExtensions(Bundle bundle) { if (mVendorExtensions != null && !mVendorExtensions.isEmpty()) { for (String key : mVendorExtensions.keySet()) { Object object = mVendorExtensions.get(key); if (object instanceof Integer) { bundle.putInt(key, (Integer) object); } else if (object instanceof int[]) { bundle.putIntArray(key, (int[]) object); } else if (object instanceof Long) { bundle.putLong(key, (Long) object); } else if (object instanceof long[]) { bundle.putLongArray(key, (long[]) object); } else if (object instanceof Short) { bundle.putShort(key, (Short) object); } else if (object instanceof short[]) { bundle.putShortArray(key, (short[]) object); } else if (object instanceof Byte) { bundle.putByte(key, (Byte) object); } else if (object instanceof byte[]) { bundle.putByteArray(key, (byte[]) object); } else if (object instanceof Boolean) { bundle.putBoolean(key, (Boolean) object); } else if (object instanceof String) { bundle.putString(key, (String) object); } else if (object instanceof String[]) { bundle.putStringArray(key, (String[]) object); } else if (object instanceof Bundle) { bundle.putParcelable(key, (Bundle) object); } else if (object instanceof ArrayList) { bundle.putParcelableArrayList(key, (ArrayList) object); } } } }
Example 5
Source File: OpenAPIParser.java From DeviceConnect-Android with MIT License | 5 votes |
@SuppressWarnings("unchecked") public static Bundle parseJSONObject(JSONObject jsonObject) throws JSONException { Bundle bundle = new Bundle(); for (Iterator<String> it = jsonObject.keys(); it.hasNext();) { String key = it.next(); Object object = jsonObject.get(key); if (object != null) { if (object instanceof Integer) { bundle.putInt(key, (Integer) object); } else if (object instanceof int[]) { bundle.putIntArray(key, (int[]) object); } else if (object instanceof Long) { bundle.putLong(key, (Long) object); } else if (object instanceof long[]) { bundle.putLongArray(key, (long[]) object); } else if (object instanceof Short) { bundle.putShort(key, (Short) object); } else if (object instanceof short[]) { bundle.putShortArray(key, (short[]) object); } else if (object instanceof Byte) { bundle.putByte(key, (Byte) object); } else if (object instanceof byte[]) { bundle.putByteArray(key, (byte[]) object); } else if (object instanceof Boolean) { bundle.putBoolean(key, (Boolean) object); } else if (object instanceof String) { bundle.putString(key, (String) object); } else if (object instanceof String[]) { bundle.putStringArray(key, (String[]) object); } else if (object instanceof JSONObject) { bundle.putParcelable(key, parseJSONObject((JSONObject) object)); } else if (object instanceof JSONArray) { bundle.putParcelableArrayList(key, parseJSONArray((JSONArray) object)); } } } return bundle; }
Example 6
Source File: ModuleLoaderTest.java From mobile-messaging-sdk-android with Apache License 2.0 | 5 votes |
@Test public void shouldCreateInstancesBasedOnMetadata() throws Exception { // Given Bundle givenMetadata = new Bundle(); givenMetadata.putString(AClass.class.getName(), BaseClass.class.getName()); givenMetadata.putString("something", "something else"); givenMetadata.putString(BClass.class.getName(), BaseClass.class.getName()); givenMetadata.putByte("something1", (byte) 0); givenMetadata.putString(CClass.class.getName(), BaseClass.class.getName()); givenMetadata.putFloat("something2", 1f); givenMetadata.putLong("something3", 2L); givenMetadata.putInt("something4", 3); givenMetadata.putStringArray("something5", new String[]{"a", "b"}); givenMetadataWillBe(givenMetadata); ModuleLoader givenModuleLoader = new ModuleLoader(mockedContext); // When Map<String, BaseClass> actualModuleMap = givenModuleLoader.loadModulesFromManifest(BaseClass.class); // Then assertEquals(3, actualModuleMap.size()); assertTrue(actualModuleMap.get(AClass.class.getName()) instanceof AClass); assertTrue(actualModuleMap.get(BClass.class.getName()) instanceof BClass); assertTrue(actualModuleMap.get(CClass.class.getName()) instanceof CClass); }
Example 7
Source File: DlQueueFragment.java From aMuleRemote with GNU General Public License v3.0 | 5 votes |
@Override public void onSaveInstanceState (Bundle outState) { super.onSaveInstanceState(outState); outState.putByte(BUNDLE_SORT_BY, mSortBy); outState.putInt(BUNDLE_SELECTED_ITEM, getSelectedItemPosition()); outState.putLong(BUNDLE_CATEGORY_FILTER, mCatId); }
Example 8
Source File: Mapping.java From ActivityRouter with Apache License 2.0 | 5 votes |
private void put(Bundle bundle, String name, String value) { int type = extraTypes.getType(name); name = extraTypes.transfer(name); if (type == ExtraTypes.STRING) { type = extraTypes.getType(name); } switch (type) { case ExtraTypes.INT: bundle.putInt(name, Integer.parseInt(value)); break; case ExtraTypes.LONG: bundle.putLong(name, Long.parseLong(value)); break; case ExtraTypes.BOOL: bundle.putBoolean(name, Boolean.parseBoolean(value)); break; case ExtraTypes.SHORT: bundle.putShort(name, Short.parseShort(value)); break; case ExtraTypes.FLOAT: bundle.putFloat(name, Float.parseFloat(value)); break; case ExtraTypes.DOUBLE: bundle.putDouble(name, Double.parseDouble(value)); break; case ExtraTypes.BYTE: bundle.putByte(name, Byte.parseByte(value)); break; case ExtraTypes.CHAR: bundle.putChar(name, value.charAt(0)); break; default: bundle.putString(name, value); break; } }
Example 9
Source File: InstanceStateManager.java From AndroidCommons with 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 10
Source File: DataMap.java From android_external_GmsLib with Apache License 2.0 | 4 votes |
public Bundle toBundle() { Bundle bundle = new Bundle(); for (String key : data.keySet()) { switch (types.get(key)) { case Asset: bundle.putParcelable(key, (Asset) data.get(key)); break; case Boolean: bundle.putBoolean(key, (Boolean) data.get(key)); break; case Byte: bundle.putByte(key, (Byte) data.get(key)); break; case ByteArray: bundle.putByteArray(key, (byte[]) data.get(key)); break; case DataMap: bundle.putBundle(key, ((DataMap) data.get(key)).toBundle()); break; case DataMapArrayList: ArrayList<Bundle> bundles = new ArrayList<Bundle>(); for (DataMap dataMap : ((ArrayList<DataMap>) data.get(key))) { bundles.add(dataMap.toBundle()); } bundle.putParcelableArrayList(key, bundles); break; case Double: bundle.putDouble(key, (Double) data.get(key)); break; case Float: bundle.putFloat(key, (Float) data.get(key)); break; case FloatArray: bundle.putFloatArray(key, (float[]) data.get(key)); break; case Integer: bundle.putInt(key, (Integer) data.get(key)); break; case IntegerArrayList: bundle.putIntegerArrayList(key, (ArrayList<Integer>) data.get(key)); break; case Long: bundle.putLong(key, (Long) data.get(key)); break; case LongArray: bundle.putLongArray(key, (long[]) data.get(key)); break; case String: bundle.putString(key, (String) data.get(key)); break; case StringArray: bundle.putStringArray(key, (String[]) data.get(key)); break; case StringArrayList: bundle.putStringArrayList(key, (ArrayList<String>) data.get(key)); break; } } return bundle; }
Example 11
Source File: MainActivity.java From MRouter with Apache License 2.0 | 4 votes |
public Bundle assembleBundle() { User user = new User(); user.setAge(90); user.setGender(1); user.setName("kitty"); Address address = new Address(); address.setCity("HangZhou"); address.setProvince("ZheJiang"); Bundle extras = new Bundle(); extras.putString("extra", "from extras"); ArrayList<String> stringList = new ArrayList<>(); stringList.add("Java"); stringList.add("C#"); stringList.add("Kotlin"); ArrayList<String> stringArrayList = new ArrayList<>(); stringArrayList.add("American"); stringArrayList.add("China"); stringArrayList.add("England"); ArrayList<Integer> intArrayList = new ArrayList<>(); intArrayList.add(100); intArrayList.add(101); intArrayList.add(102); ArrayList<Integer> intList = new ArrayList<>(); intList.add(10011); intList.add(10111); intList.add(10211); ArrayList<Address> addressList = new ArrayList<>(); addressList.add(new Address("JiangXi", "ShangRao", null)); addressList.add(new Address("ZheJiang", "NingBo", null)); Address[] addressArray = new Address[]{ new Address("Beijing", "Beijing", null), new Address("Shanghai", "Shanghai", null), new Address("Guangzhou", "Guangzhou", null) }; Bundle bundle = new Bundle(); bundle.putSerializable("user", user); bundle.putParcelable("address", address); bundle.putParcelableArrayList("addressList", addressList); bundle.putParcelableArray("addressArray", addressArray); bundle.putString("param", "chiclaim"); bundle.putStringArray("stringArray", new String[]{"a", "b", "c"}); bundle.putStringArrayList("stringArrayList", stringList); bundle.putStringArrayList("stringList", stringArrayList); bundle.putByte("byte", (byte) 2); bundle.putByteArray("byteArray", new byte[]{1, 2, 3, 4, 5}); bundle.putInt("age", 33); bundle.putIntArray("intArray", new int[]{10, 11, 12, 13}); bundle.putIntegerArrayList("intList", intList); bundle.putIntegerArrayList("intArrayList", intArrayList); bundle.putChar("chara", 'c'); bundle.putCharArray("charArray", "chiclaim".toCharArray()); bundle.putShort("short", (short) 1000000); bundle.putShortArray("shortArray", new short[]{(short) 10.9, (short) 11.9}); bundle.putDouble("double", 1200000); bundle.putDoubleArray("doubleArray", new double[]{1232, 9999, 8789, 3.1415926}); bundle.putLong("long", 999999999); bundle.putLongArray("longArray", new long[]{1000, 2000, 3000}); bundle.putFloat("float", 333); bundle.putFloatArray("floatArray", new float[]{12.9f, 234.9f}); bundle.putBoolean("boolean", true); bundle.putBooleanArray("booleanArray", new boolean[]{true, false, true}); return bundle; }
Example 12
Source File: Utils.java From MCPELauncher with Apache License 2.0 | 4 votes |
private static void rebootIntoInstrumentation(Activity activity, Intent targetIntent) { boolean launchViaAlarm = Build.VERSION.SDK_INT >= 29; // Android 10 requires alarm if (launchViaAlarm) { setupAlarm(activity, targetIntent); } String abiOverride = getOverriddenNativeAbi(); Bundle bundle = new Bundle(); if (launchViaAlarm) { bundle.putByte("skipLaunch", (byte)1); } else { bundle.putParcelable("launchIntent", targetIntent); } ComponentName componentName = new ComponentName(activity, RelaunchInstrumentation.class); try { Object iActivityManager = null; try { Method ActivityManager_getService = ActivityManager.class.getMethod("getService"); iActivityManager = ActivityManager_getService.invoke(null); } catch (NoSuchMethodException nme) { System.err.println(nme); // Android 7.1 and below Method ActivityManagerNative_getDefault = Class.forName("android.app.ActivityManagerNative").getMethod("getDefault"); iActivityManager = ActivityManagerNative_getDefault.invoke(null); } Method IActivityManager_startInstrumentation = iActivityManager.getClass().getMethod("startInstrumentation", ComponentName.class, String.class, Integer.TYPE, Bundle.class, Class.forName("android.app.IInstrumentationWatcher"), Class.forName("android.app.IUiAutomationConnection"), Integer.TYPE, String.class); IActivityManager_startInstrumentation.invoke(iActivityManager, /* className= */ componentName, /* profileFile= */ null, /* flags= */ 0, /* arguments= */ bundle, /* watcher= */ null, /* connection= */ null, /* userId= */ 0, /* abiOverride= */ abiOverride); // this call will force-close the process momentarily. while (true) { Thread.sleep(10000); } } catch (Exception e) { throw new RuntimeException(e); } }
Example 13
Source File: AddressDetailActivity.java From bcm-android with GNU General Public License v3.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); address = getIntent().getStringExtra("ADDRESS"); type = getIntent().getByteExtra("TYPE", SCANNED_WALLET); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setDisplayHomeAsUpEnabled(true); title = (TextView) findViewById(R.id.toolbar_title); String walletname = AddressNameConverter.getInstance(this).get(address); title.setText(type == OWN_WALLET ? (walletname == null ? "Unnamed Wallet" : walletname) : "Address"); coord = (CoordinatorLayout) findViewById(R.id.main_content); appbar = (AppBarLayout) findViewById(R.id.appbar); fragments = new Fragment[3]; fragments[0] = new FragmentDetailShare(); fragments[1] = new FragmentDetailOverview(); fragments[2] = new FragmentTransactions(); Bundle bundle = new Bundle(); bundle.putString("ADDRESS", address); bundle.putDouble("BALANCE", getIntent().getDoubleExtra("BALANCE", 0)); bundle.putByte("TYPE", type); fragments[0].setArguments(bundle); fragments[1].setArguments(bundle); fragments[2].setArguments(bundle); mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); mViewPager = (ViewPager) findViewById(R.id.container); mViewPager.setAdapter(mSectionsPagerAdapter); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(mViewPager); tabLayout.setupWithViewPager(mViewPager); tabLayout.getTabAt(0).setIcon(R.drawable.ic_action_share); tabLayout.getTabAt(1).setIcon(R.drawable.ic_wallet); tabLayout.getTabAt(2).setIcon(R.drawable.ic_transactions); mViewPager.setCurrentItem(1); mViewPager.setOffscreenPageLimit(3); }
Example 14
Source File: AddressDetailActivity.java From Lunary-Ethereum-Wallet with GNU General Public License v3.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); address = getIntent().getStringExtra("ADDRESS"); type = getIntent().getByteExtra("TYPE", SCANNED_WALLET); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setDisplayHomeAsUpEnabled(true); title = (TextView) findViewById(R.id.toolbar_title); String walletname = AddressNameConverter.getInstance(this).get(address); title.setText(type == OWN_WALLET ? (walletname == null ? "Unnamed Wallet" : walletname) : "Address"); coord = (CoordinatorLayout) findViewById(R.id.main_content); appbar = (AppBarLayout) findViewById(R.id.appbar); fragments = new Fragment[3]; fragments[0] = new FragmentDetailShare(); fragments[1] = new FragmentDetailOverview(); fragments[2] = new FragmentTransactions(); Bundle bundle = new Bundle(); bundle.putString("ADDRESS", address); bundle.putDouble("BALANCE", getIntent().getDoubleExtra("BALANCE", 0)); bundle.putByte("TYPE", type); fragments[0].setArguments(bundle); fragments[1].setArguments(bundle); fragments[2].setArguments(bundle); mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); mViewPager = (ViewPager) findViewById(R.id.container); mViewPager.setAdapter(mSectionsPagerAdapter); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(mViewPager); tabLayout.setupWithViewPager(mViewPager); tabLayout.getTabAt(0).setIcon(R.drawable.ic_action_share); tabLayout.getTabAt(1).setIcon(R.drawable.ic_wallet); tabLayout.getTabAt(2).setIcon(R.drawable.ic_transactions); mViewPager.setCurrentItem(1); mViewPager.setOffscreenPageLimit(3); }
Example 15
Source File: MeepoUtils.java From Meepo with 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 16
Source File: ParameterHelper.java From IPCInvoker with Apache License 2.0 | 4 votes |
public static void put(Bundle bundle, String key, Object value) { if (value instanceof Integer) { bundle.putInt(key, (Integer) value); } else if (value instanceof Float) { bundle.putFloat(key, (Float) value); } else if (value instanceof Character) { bundle.putChar(key, (Character) value); } else if (value instanceof CharSequence) { bundle.putCharSequence(key, (CharSequence) 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 Byte) { bundle.putByte(key, (Byte) value); } else if (value instanceof Boolean) { bundle.putBoolean(key, (Boolean) value); } else if (value instanceof Double) { bundle.putDouble(key, (Double) value); } else if (value instanceof Parcelable) { bundle.putParcelable(key, (Parcelable) value); } else if (value instanceof Bundle) { bundle.putBundle(key, (Bundle) value); } else if (value instanceof int[]) { bundle.putIntArray(key, (int[]) value); } else if (value instanceof byte[]) { bundle.putByteArray(key, (byte[]) value); } else if (value instanceof float[]) { bundle.putFloatArray(key, (float[]) value); } else if (value instanceof double[]) { bundle.putDoubleArray(key, (double[]) 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 Parcelable[]) { bundle.putParcelableArray(key, (Parcelable[]) value); } else if (value instanceof short[]) { bundle.putShortArray(key, (short[]) value); } else if (value instanceof String[]) { bundle.putStringArray(key, (String[]) value); } else { // bundle.putString(key, String.valueOf(value)); } }
Example 17
Source File: ArgumentsUtil.java From ucar-weex-core with Apache License 2.0 | 4 votes |
public static Bundle fromJsonToBundle(JSONObject jsonObject) { Bundle budle = new Bundle(); if (jsonObject == null) { return budle; } else { Iterator iterator = jsonObject.keySet().iterator(); while (iterator.hasNext()) { String key = (String) iterator.next(); Object value = jsonObject.get(key); if (value != null) { if (value instanceof String) { budle.putString(key, (String) value); } else if (value instanceof Byte) { budle.putByte(key, ((Byte) value).byteValue()); } else if (value instanceof Short) { budle.putShort(key, ((Short) value).shortValue()); } else if (value instanceof Integer) { budle.putInt(key, ((Integer) value).intValue()); } else if (value instanceof Long) { budle.putLong(key, ((Long) value).longValue()); } else if (value instanceof Float) { budle.putFloat(key, ((Float) value).floatValue()); } else if (value instanceof Double) { budle.putDouble(key, ((Double) value).doubleValue()); } else if (value instanceof Boolean) { budle.putBoolean(key, ((Boolean) value).booleanValue()); } else if (value instanceof Character) { budle.putChar(key, ((Character) value).charValue()); } else if (value instanceof JSONObject) { budle.putBundle(key, fromJsonToBundle((JSONObject) value)); } else { if (!value.getClass().isArray()) { throw new IllegalArgumentException("Could not convert " + value.getClass()); } fromArrayToBundle(budle, key, value); } } } return budle; } }
Example 18
Source File: InjectionHelper.java From android-state with Eclipse Public License 1.0 | 4 votes |
public void putBoxedByte(Bundle state, String key, Byte x) { if (x != null) { state.putByte(key + mBaseKey, x); } }
Example 19
Source File: InjectionHelper.java From android-state with Eclipse Public License 1.0 | 4 votes |
public void putByte(Bundle state, String key, byte x) { state.putByte(key + mBaseKey, x); }
Example 20
Source File: ByteCoder.java From lyra with 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 Byte fieldValue) { state.putByte(key, fieldValue); }