android.os.Bundle#putDoubleArray ( )源码实例Demo

下面列出了android.os.Bundle#putDoubleArray ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Test
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void testBundleConstructor() {
    Bundle platformBundle = new Bundle();
    platformBundle.putString("string", "string");
    platformBundle.putInt("int", 0);
    platformBundle.putLong("long", 0);
    platformBundle.putDouble("double", 0);
    platformBundle.putStringArray("string_array", new String[]{"one", "two", "three"});
    platformBundle.putIntArray("int_array", new int[]{1, 2, 3});
    platformBundle.putLongArray("long_array", new long[]{1, 2, 3});
    platformBundle.putDoubleArray("double_array", new double[]{1, 2, 3});

    PersistableBundle bundle = new PersistableBundle(platformBundle);
    assertEquals(platformBundle.getString("string"), bundle.getString("string"));
    assertEquals(platformBundle.getInt("int"), bundle.getInt("int"));
    assertEquals(platformBundle.getLong("long"), bundle.getLong("long"));
    assertEquals(platformBundle.getDouble("double"), bundle.getDouble("double"), 0.01);
    assertArrayEquals(platformBundle.getStringArray("string_array"), bundle.getStringArray("string_array"));
    assertArrayEquals(platformBundle.getIntArray("int_array"), bundle.getIntArray("int_array"));
    assertArrayEquals(platformBundle.getLongArray("long_array"), bundle.getLongArray("long_array"));
    assertArrayEquals(platformBundle.getDoubleArray("double_array"), bundle.getDoubleArray("double_array"), 0.01);
}
 
源代码2 项目: astrobee_android   文件: RobotCommands.java
/**
 * Creates a bundle with the data for the move command
 * @param x coordinates on the x axis
 * @param y coordinates on the y axis
 * @param z coordinates on the z axis
 * @param phi roll attitude angle
 * @param theta pitch attitude angle
 * @param gamma yaw attitude angle
 * @return bundle of move command data
 */
public Bundle moveTo(double x, double y, double z, double phi, double theta, double gamma){
    //For now only passing the xyz position. Keeping tolerances and quaternions unchanged.
    Bundle bundle = new Bundle();
    String cmd = CMD_NAME_SIMPLE_MOVE6DOF;
    int numArgs = 6;
    double [] pos = new double[3];
    double [] att = new double[3];
    pos[0] = x;
    pos[1] = y;
    pos[2] = z;
    att[0] = phi;
    att[1] = theta;
    att[2] = gamma;
    bundle.putString("cmd", cmd);
    bundle.putInt("numArgs", numArgs);
    bundle.putDoubleArray("pos", pos);
    bundle.putDoubleArray("att", att);

    return bundle;
}
 
源代码3 项目: astrobee_android   文件: RobotCommands.java
/**
 * Creates a bundle with the data for the move command
 * @param x coordinates on the x axis
 * @param y coordinates on the y axis
 * @param z coordinates on the z axis
 * @param phi roll attitude angle
 * @param theta pitch attitude angle
 * @param gamma yaw attitude angle
 * @return bundle of move command data
 */
public Bundle moveTo(double x, double y, double z, double phi, double theta, double gamma){
    //For now only passing the xyz position. Keeping tolerances and quaternions unchanged.
    Bundle bundle = new Bundle();
    String cmd = CMD_NAME_SIMPLE_MOVE6DOF;
    int numArgs = 6;
    double [] pos = new double[3];
    double [] att = new double[3];
    pos[0] = x;
    pos[1] = y;
    pos[2] = z;
    att[0] = phi;
    att[1] = theta;
    att[2] = gamma;
    bundle.putString("cmd", cmd);
    bundle.putInt("numArgs", numArgs);
    bundle.putDoubleArray("pos", pos);
    bundle.putDoubleArray("att", att);

    return bundle;
}
 
源代码4 项目: JobSchedulerCompat   文件: PersistableBundle.java
@NonNull
public Bundle toBundle() {
    Bundle bundle = new Bundle(map.size());
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();
        if (value == null) {
            bundle.putString(key, null);
        } else if (value instanceof String) {
            bundle.putString(key, (String) value);
        } else if (value instanceof Integer) {
            bundle.putInt(key, (Integer) value);
        } else if (value instanceof Long) {
            bundle.putLong(key, (Long) value);
        } else if (value instanceof Double) {
            bundle.putDouble(key, (Double) value);
        } else if (value instanceof Boolean) {
            bundle.putBoolean(key, (Boolean) value);
        } else if (value instanceof String[]) {
            bundle.putStringArray(key, (String[]) value);
        } else if (value instanceof int[]) {
            bundle.putIntArray(key, (int[]) value);
        } else if (value instanceof long[]) {
            bundle.putLongArray(key, (long[]) 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 PersistableBundle) {
            bundle.putBundle(key, ((PersistableBundle) value).toBundle());
        }
    }
    return bundle;
}
 
源代码5 项目: kognitivo   文件: Utility.java
public static boolean putJSONValueInBundle(Bundle bundle, String key, Object value) {
    if (value == null) {
        bundle.remove(key);
    } else if (value instanceof Boolean) {
        bundle.putBoolean(key, (boolean) value);
    } else if (value instanceof boolean[]) {
        bundle.putBooleanArray(key, (boolean[]) value);
    } else if (value instanceof Double) {
        bundle.putDouble(key, (double) value);
    } else if (value instanceof double[]) {
        bundle.putDoubleArray(key, (double[]) value);
    } else if (value instanceof Integer) {
        bundle.putInt(key, (int) value);
    } else if (value instanceof int[]) {
        bundle.putIntArray(key, (int[]) value);
    } else if (value instanceof Long) {
        bundle.putLong(key, (long) value);
    } else if (value instanceof long[]) {
        bundle.putLongArray(key, (long[]) value);
    } else if (value instanceof String) {
        bundle.putString(key, (String) value);
    } else if (value instanceof JSONArray) {
        bundle.putString(key, ((JSONArray) value).toString());
    } else if (value instanceof JSONObject) {
        bundle.putString(key, ((JSONObject) value).toString());
    } else {
        return false;
    }
    return true;
}
 
源代码6 项目: ucar-weex-core   文件: ArgumentsUtil.java
public static void fromArrayToBundle(Bundle bundle, String key, Object array) {
    if (bundle != null && !TextUtils.isEmpty(key) && array != null) {
        if (array instanceof String[]) {
            bundle.putStringArray(key, (String[]) ((String[]) array));
        } else if (array instanceof byte[]) {
            bundle.putByteArray(key, (byte[]) ((byte[]) array));
        } else if (array instanceof short[]) {
            bundle.putShortArray(key, (short[]) ((short[]) array));
        } else if (array instanceof int[]) {
            bundle.putIntArray(key, (int[]) ((int[]) array));
        } else if (array instanceof long[]) {
            bundle.putLongArray(key, (long[]) ((long[]) array));
        } else if (array instanceof float[]) {
            bundle.putFloatArray(key, (float[]) ((float[]) array));
        } else if (array instanceof double[]) {
            bundle.putDoubleArray(key, (double[]) ((double[]) array));
        } else if (array instanceof boolean[]) {
            bundle.putBooleanArray(key, (boolean[]) ((boolean[]) array));
        } else if (array instanceof char[]) {
            bundle.putCharArray(key, (char[]) ((char[]) array));
        } else {
            if (!(array instanceof JSONArray)) {
                throw new IllegalArgumentException("Unknown array type " + array.getClass());
            }

            ArrayList arraylist = new ArrayList();
            JSONArray jsonArray = (JSONArray) array;
            Iterator it = jsonArray.iterator();

            while (it.hasNext()) {
                JSONObject object = (JSONObject) it.next();
                arraylist.add(fromJsonToBundle(object));
            }

            bundle.putParcelableArrayList(key, arraylist);
        }

    }
}
 
源代码7 项目: AnimCubeAndroid   文件: AnimCube.java
/**
 * <p>
 * Saves the cube current state to a bundle, in order for it to be recovered after a configuration change or after the app is resumed from background.
 * </p>
 * <p>
 * If needed, the saved state can be read from the bundle by reading the values stored at keys defined in {@link CubeState}.
 * </p>
 *
 * @return a {@link Bundle} containing the cube's current state
 * @see #restoreState(Bundle)
 */
public Bundle saveState() {
    Bundle b = new Bundle();
    int[][] cubeDeepCopy = new int[6][9];
    synchronized (animThreadLock) {
        CubeUtils.deepCopy2DArray(cube, cubeDeepCopy);
        for (int i = 0; i < cubeDeepCopy.length; i++) {
            b.putIntArray(CubeState.KEY_CUBE + i, cubeDeepCopy[i]);
        }
        for (int i = 0; i < initialCube.length; i++) {
            b.putIntArray(CubeState.KEY_INITIAL_CUBE + i, initialCube[i]);
        }
        b.putIntArray(CubeState.KEY_MOVE, move);
        b.putBoolean(CubeState.KEY_IS_ANIMATING, animating);
        b.putInt(CubeState.KEY_ANIMATION_MODE, animationMode);
        b.putDoubleArray(CubeState.KEY_EYE, eye);
        b.putDoubleArray(CubeState.KEY_EYE_X, eyeX);
        b.putDoubleArray(CubeState.KEY_EYE_Y, eyeY);
        b.putDouble(CubeState.KEY_ORIGINAL_ANGLE, originalAngle);
        if (moveDir == -1) {
            b.putInt(CubeState.KEY_MOVE_POS, movePos == move.length ? move.length : movePos + 1);
        } else {
            b.putInt(CubeState.KEY_MOVE_POS, movePos);
        }
        b.putBoolean(CubeState.KEY_EDITABLE, editable);
        b.putInt(CubeState.KEY_BACKFACES_DISTANCE, backFacesDistance);
        b.putInt(CubeState.KEY_SINGLE_ROTATION_SPEED, speed);
        b.putInt(CubeState.KEY_DOUBLE_ROTATION_SPEED, doubleSpeed);
        b.putBoolean(CubeState.KEY_IS_DEBUGGABLE, isDebuggable);
    }
    return b;
}
 
源代码8 项目: AnimCubeAndroid   文件: AnimCubeDebug.java
/**
 * <p>
 * Saves the cube current state to a bundle, in order for it to be recovered after a configuration change or after the app is resumed from background.
 * </p>
 * <p>
 * If needed, the saved state can be read from the bundle by reading the values stored at keys defined in {@link CubeState}.
 * </p>
 *
 * @return a {@link Bundle} containing the cube's current state
 * @see #restoreState(Bundle)
 */
public Bundle saveState() {
    Bundle b = new Bundle();
    int[][] cubeDeepCopy = new int[6][9];
    synchronized (animThreadLock) {
        CubeUtils.deepCopy2DArray(cube, cubeDeepCopy);
        for (int i = 0; i < cubeDeepCopy.length; i++) {
            b.putIntArray(CubeState.KEY_CUBE + i, cubeDeepCopy[i]);
        }
        for (int i = 0; i < initialCube.length; i++) {
            b.putIntArray(CubeState.KEY_INITIAL_CUBE + i, initialCube[i]);
        }
        b.putIntArray(CubeState.KEY_MOVE, move);
        b.putBoolean(CubeState.KEY_IS_ANIMATING, animating);
        b.putInt(CubeState.KEY_ANIMATION_MODE, animationMode);
        b.putDoubleArray(CubeState.KEY_EYE, eye);
        b.putDoubleArray(CubeState.KEY_EYE_X, eyeX);
        b.putDoubleArray(CubeState.KEY_EYE_Y, eyeY);
        b.putDouble(CubeState.KEY_ORIGINAL_ANGLE, originalAngle);
        if (moveDir == -1) {
            b.putInt(CubeState.KEY_MOVE_POS, movePos == move.length ? move.length : movePos + 1);
        } else {
            b.putInt(CubeState.KEY_MOVE_POS, movePos);
        }
        b.putBoolean(CubeState.KEY_EDITABLE, editable);
        b.putInt(CubeState.KEY_BACKFACES_DISTANCE, backFacesDistance);
        b.putInt(CubeState.KEY_SINGLE_ROTATION_SPEED, speed);
        b.putInt(CubeState.KEY_DOUBLE_ROTATION_SPEED, doubleSpeed);
        b.putBoolean(CubeState.KEY_IS_DEBUGGABLE, isDebuggable);
    }
    return b;
}
 
private static void putDoubleArray(String key, Bundle bundle) {
    int length = random.nextInt(50);
    double[] array = new double[length];
    for (int i = 0; i < length; i++) {
        array[i] = random.nextDouble();
    }
    bundle.putDoubleArray(key, array);
}
 
源代码10 项目: android-state   文件: InjectionHelper.java
public void putDoubleArray(Bundle state, String key, double[] x) {
    state.putDoubleArray(key + mBaseKey, x);
}
 
源代码11 项目: IPCInvoker   文件: ParameterHelper.java
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));
        }
    }
 
源代码12 项目: Meepo   文件: MeepoUtils.java
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()));
    }
}
 
源代码13 项目: MRouter   文件: MainActivity.java
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;
}
 
源代码14 项目: AndroidCommons   文件: InstanceStateManager.java
@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());
    }
}
 
源代码15 项目: Androzic   文件: MapView.java
@Override
protected Parcelable onSaveInstanceState()
{
	Bundle bundle = new Bundle();
	bundle.putParcelable("instanceState", super.onSaveInstanceState());

	bundle.putInt("vectorType", vectorType);
	bundle.putInt("vectorMultiplier", vectorMultiplier);
	bundle.putBoolean("autoFollow", isFollowing);
	bundle.putBoolean("strictUnfollow", strictUnfollow);
	bundle.putBoolean("loadBestMap", loadBestMap);
	bundle.putInt("bestMapInterval", bestMapInterval);

	bundle.putBoolean("isFixed", isFixed);
	bundle.putBoolean("isMoving", isMoving);
	bundle.putLong("lastBestMap", lastBestMap);

	bundle.putInt("penX", penX);
	bundle.putInt("penY", penY);
	bundle.putInt("penOX", penOX);
	bundle.putInt("penOY", penOY);
	bundle.putIntArray("lookAheadXY", currentViewport.lookAheadXY);
	bundle.putInt("lookAhead", lookAhead);
	bundle.putFloat("lookAheadC", lookAheadC);
	bundle.putFloat("lookAheadS", lookAheadS);
	bundle.putFloat("lookAheadSS", lookAheadSS);
	bundle.putInt("lookAheadPst", lookAheadPst);
	bundle.putFloat("lookAheadB", lookAheadB);
	bundle.putFloat("smoothB", smoothB);
	bundle.putFloat("smoothBS", smoothBS);

	bundle.putDoubleArray("mapCenter", currentViewport.mapCenter);
	bundle.putDoubleArray("currentLocation", currentViewport.location);
	bundle.putIntArray("mapCenterXY", currentViewport.mapCenterXY);
	bundle.putIntArray("currentLocationXY", currentViewport.locationXY);
	bundle.putFloat("mapHeading", currentViewport.mapHeading);
	bundle.putFloat("bearing", currentViewport.bearing);
	bundle.putFloat("speed", currentViewport.speed);
	bundle.putDouble("mpp", mpp);
	bundle.putInt("vectorLength", vectorLength);
	bundle.putInt("proximity", proximity);

	return bundle;
}
 
源代码16 项目: AndroidApp   文件: MyElectricMainFragment.java
@Override
public void onSaveInstanceState(Bundle outState) {

    outState.putInt("power_graph_length", powerChart.getChartLength());
    outState.putDouble("power_now", powerNowWatts);
    outState.putDouble("power_today", powerTodaykWh);

    outState.putInt("power_feed_id", myElectricSettings.getPowerFeedId());
    outState.putInt("use_feed_id", myElectricSettings.getUseFeedId());


    outState.putParcelable("settings", myElectricSettings);
    outState.putIntArray("chart2_colors", dailyUsageBarChart.getBarColours());

    double[] values = new double[powerChart.getValues().size()];

    for (int i = 0; i < powerChart.getValues().size(); i++)
        values[i] = powerChart.getValues().get(i);

    outState.putStringArrayList("chart1_labels", powerChart.getLabels());
    outState.putDoubleArray("chart1_values", values);

    values = new double[dailyUsageBarChart.getValues().size()];

    for (int i = 0; i < dailyUsageBarChart.getValues().size(); i++)
        values[i] = dailyUsageBarChart.getValues().get(i);

    outState.putStringArrayList("chart2_labels", dailyUsageBarChart.getLabels());
    outState.putDoubleArray("chart2_values", values);

    super.onSaveInstanceState(outState);
}
 
源代码17 项目: lyra   文件: DoubleArrayCoder.java
/**
 * 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 double[] fieldValue) {
    state.putDoubleArray(key, fieldValue);
}