Java Code Examples for android.os.Bundle.putDoubleArray()

The following are Jave code examples for showing how to use putDoubleArray() of the android.os.Bundle class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: JobSchedulerCompat   File: PersistableBundleTest.java   View Source Code Vote up 6 votes
@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);
}
 
Example 2
Project: astrobee_android   File: RobotCommands.java   View Source Code Vote up 6 votes
/**
 * 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;
}
 
Example 3
Project: JobSchedulerCompat   File: PersistableBundle.java   View Source Code Vote up 5 votes
@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;
}
 
Example 4
Project: kognitivo   File: Utility.java   View Source Code Vote up 5 votes
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;
}
 
Example 5
Project: ucar-weex-core   File: ArgumentsUtil.java   View Source Code Vote up 5 votes
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);
        }

    }
}
 
Example 6
Project: GitHub   File: Injector.java   View Source Code Vote up 4 votes
public void putDoubleArray(Bundle state, String key, double[] x) {
    state.putDoubleArray(key + baseKey, x);
}
 
Example 7
Project: android-state   File: InjectionHelper.java   View Source Code Vote up 4 votes
public void putDoubleArray(Bundle state, String key, double[] x) {
    state.putDoubleArray(key + mBaseKey, x);
}
 
Example 8
Project: MagicBox   File: DoubleArrayWriter.java   View Source Code Vote up 4 votes
@Override
public void write(Bundle bundle, Object to, StateField field) throws IllegalAccessException {
    Field propertyField = field.getField();
    propertyField.setAccessible(true);
    bundle.putDoubleArray(field.getBundleKey(), (double[]) propertyField.get(to));
}
 
Example 9
Project: IPCInvoker   File: ParameterHelper.java   View Source Code Vote up 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 10
Project: EnchantedFortress   File: GameFragment.java   View Source Code Vote up 4 votes
@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putDoubleArray(SaveLoad.SaveKey, SaveLoad.get().serialize(this.game));
}
 
Example 11
Project: MRouter   File: MainActivity.java   View Source Code Vote up 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
Project: TrainAppTFG   File: BluetoothLeService.java   View Source Code Vote up 2 votes
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    super.onCharacteristicChanged(gatt, characteristic);
    Log.d("BLUETOOTH", "onCharacteristicChanged");

    if(characteristic.getUuid().equals(UUID_MOVEMENT_DATA)){
        byte[] valores = characteristic.getValue();

        double acc_x = (valores[7] << 8) +  valores[6];
        double acc_y = (valores[9] << 8) +  valores[8];
        double acc_z = (valores[11] << 8) +  valores[10];


        double acc_scaledX = (sensorMpu9250AccConvert(acc_x) * GRAVITIY) * (-1);
        double acc_scaledY =  sensorMpu9250AccConvert(acc_y) * GRAVITIY;
        double acc_scaledZ = (sensorMpu9250AccConvert(acc_z) * GRAVITIY) * (-1);

        Log.d("ACELEROMETRO", "Value: " + acc_scaledX + " : " + acc_scaledY + " : " + acc_scaledZ);

        double gyro_x = (valores[1] << 8) +  valores[0];
        double gyro_y = (valores[3] << 8) +  valores[2];
        double gyro_z = (valores[5] << 8) +  valores[4];


        double gyro_scaledX = (sensorMpu9250GyroConvert(gyro_x)) * (Math.PI/180) * (-1);
        double gyro_scaledY = (sensorMpu9250GyroConvert(gyro_y)) * (Math.PI/180);
        double gyro_scaledZ = (sensorMpu9250GyroConvert(gyro_z)) * (Math.PI/180) * (-1);

        Log.d("GIROSCOPIO  ", "Value: " + gyro_scaledX + " : " + gyro_scaledY + " : " + gyro_scaledZ);

        double[] datosAcelGyro = {acc_scaledX, acc_scaledY, acc_scaledZ, gyro_scaledX, gyro_scaledY, gyro_scaledZ};

        Bundle bundle = new Bundle();
        bundle.putDoubleArray("datos", datosAcelGyro);

        //TODO crear constantes para los codigos de envio
        resultReceiverEnvioDatos.send(100, bundle);



    }
}
 
Example 13
Project: Lyra   File: DoubleArrayCoder.java   View Source Code Vote up 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 double[] fieldValue) {
    state.putDoubleArray(key, fieldValue);
}