List of usage examples for android.os Bundle putDoubleArray
public void putDoubleArray(@Nullable String key, @Nullable double[] value)
From source file:nuclei.task.TaskScheduler.java
private void onSchedulePreL(Context context) { Task.Builder builder;/* w w w .j a va2 s . c om*/ switch (mBuilder.mTaskType) { case TASK_ONE_OFF: OneoffTask.Builder oneOffBuilder = new OneoffTask.Builder(); builder = oneOffBuilder; if (mBuilder.mWindowStartDelaySecondsSet || mBuilder.mWindowEndDelaySecondsSet) oneOffBuilder.setExecutionWindow(mBuilder.mWindowStartDelaySeconds, mBuilder.mWindowEndDelaySeconds); break; case TASK_PERIODIC: builder = new PeriodicTask.Builder().setFlex(mBuilder.mFlexInSeconds) .setPeriod(mBuilder.mPeriodInSeconds); break; default: throw new IllegalArgumentException(); } ArrayMap<String, Object> map = new ArrayMap<>(); mBuilder.mTask.serialize(map); Bundle extras = new Bundle(); for (Map.Entry<String, Object> entry : map.entrySet()) { Object v = entry.getValue(); if (v == null) continue; if (v instanceof Integer) extras.putInt(entry.getKey(), (int) v); else if (v instanceof Double) extras.putDouble(entry.getKey(), (double) v); else if (v instanceof Long) extras.putLong(entry.getKey(), (long) v); else if (v instanceof String) extras.putString(entry.getKey(), (String) v); else if (v instanceof String[]) extras.putStringArray(entry.getKey(), (String[]) v); else if (v instanceof boolean[]) extras.putBooleanArray(entry.getKey(), (boolean[]) v); else if (v instanceof double[]) extras.putDoubleArray(entry.getKey(), (double[]) v); else if (v instanceof long[]) extras.putLongArray(entry.getKey(), (long[]) v); else if (v instanceof int[]) extras.putIntArray(entry.getKey(), (int[]) v); else if (v instanceof Parcelable) extras.putParcelable(entry.getKey(), (Parcelable) v); else if (v instanceof Serializable) extras.putSerializable(entry.getKey(), (Serializable) v); else throw new IllegalArgumentException("Invalid Type: " + entry.getKey()); } extras.putString(TASK_NAME, mBuilder.mTask.getClass().getName()); builder.setExtras(extras).setPersisted(mBuilder.mPersisted).setRequiresCharging(mBuilder.mRequiresCharging) .setService(TaskGcmService.class).setTag(mBuilder.mTask.getTaskTag()) .setUpdateCurrent(mBuilder.mUpdateCurrent); switch (mBuilder.mNetworkState) { case NETWORK_STATE_ANY: builder.setRequiredNetwork(Task.NETWORK_STATE_ANY); break; case NETWORK_STATE_CONNECTED: builder.setRequiredNetwork(Task.NETWORK_STATE_CONNECTED); break; case NETWORK_STATE_UNMETERED: builder.setRequiredNetwork(Task.NETWORK_STATE_UNMETERED); break; } GcmNetworkManager.getInstance(context).schedule(builder.build()); }
From source file:ru.moscow.tuzlukov.sergey.weatherlog.MainActivity.java
@Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); List<Long> baseLongList = new ArrayList<>(temperatureMap.keySet()); List<Double> baseDoubleList = new ArrayList<>(temperatureMap.values()); long[] timeArray = new long[baseLongList.size()]; double[] tempArray = new double[baseDoubleList.size()]; for (int i = 0; i < temperatureMap.size(); i++) { timeArray[i] = baseLongList.get(i); tempArray[i] = baseDoubleList.get(i); }/* w ww. j a va 2 s . co m*/ outState.putLong(SAVED_CURRENT_TIME, currentTime); outState.putLong(SAVED_CURRENT_TIME_MINUS_12, currentTimeMinus12h); outState.putLong(SAVED_CURRENT_TIME_MINUS_24, currentTimeMinus24h); outState.putLongArray(SAVED_TIME_ARRAY, timeArray); outState.putDoubleArray(SAVED_TEMP_ARRAY, tempArray); outState.putBoolean(SAVED_CURRENT_GAINED, currentIsGained); outState.putBoolean(SAVED_HISTORY_GAINED, historyIsGained); outState.putBoolean(SAVED_LOADER_VISIBILITY, llLoader.getVisibility() == View.VISIBLE); outState.putString(SAVED_DIALOG_APPID, registerDialog.getEtAppId().getText().toString()); outState.putBoolean(SAVED_DIALOG_VISIBILITY, registerDialog.isVisible()); }
From source file:net.alexjf.tmm.fragments.ImmedTransactionStatsFragment.java
private void updateCurrentTransactionSet() { if (adapter == null || catPercentageAdapter == null) { return;// w w w. j a va 2 s .c om } if (adapter.getCount() == 0 && catPercentageAdapter.getCount() == 0) { return; } if (categoryStatsTask != null) { return; } Utils.preventOrientationChanges(getActivity()); String strLoading = getActivity().getResources().getString(R.string.analyzing_stats); categoryStatsTask = new AsyncTaskWithProgressDialog<ImmediateTransactionAdapter>(getActivity(), TASK_CATEGORYSTATS, strLoading) { // TODO: Make this more efficient by already getting all the // data from the database @Override protected Bundle doInBackground(ImmediateTransactionAdapter... args) { List<ImmediateTransaction> currentTransactionSet = new LinkedList<ImmediateTransaction>(); Utils.fromAdapterToList(adapter, currentTransactionSet); currentFilter.applyInPlace(currentTransactionSet); Map<Category, Double> perCategoryValues = new HashMap<Category, Double>(); double totalValue = 0; CurrencyUnit currency = null; for (ImmediateTransaction transaction : currentTransactionSet) { try { transaction.load(); Category cat = transaction.getCategory(); cat.load(); Money transactionValue = transaction.getValue(); if (currency == null) { currency = transactionValue.getCurrencyUnit(); } double transactionValueDouble = transactionValue.abs().getAmount().doubleValue(); Double existingValue = perCategoryValues.get(cat); totalValue += transactionValueDouble; if (existingValue != null) { transactionValueDouble += existingValue; } perCategoryValues.put(cat, transactionValueDouble); } catch (DatabaseException e) { setThrowable(e); return null; } } Bundle bundle = new Bundle(); int size = perCategoryValues.size(); Category[] categories = new Category[size]; double[] values = new double[size]; List<Entry<Category, Double>> catValues = new ArrayList<Entry<Category, Double>>( perCategoryValues.entrySet()); Collections.sort(catValues, new Comparator<Entry<Category, Double>>() { @Override public int compare(Map.Entry<Category, Double> arg0, Map.Entry<Category, Double> arg1) { return arg0.getValue().compareTo(arg1.getValue()); } ; }); int i = 0; for (Entry<Category, Double> catValue : catValues) { categories[i] = catValue.getKey(); values[i] = catValue.getValue(); i++; } if (currency != null) { bundle.putString(KEY_CURRENCY, currency.getCurrencyCode()); } bundle.putParcelableArray(KEY_CATEGORIES, categories); bundle.putDoubleArray(KEY_VALUES, values); bundle.putDouble(KEY_TOTALVALUE, totalValue); return bundle; } ; }; categoryStatsTask.setResultListener(this); categoryStatsTask.execute(adapter); }
From source file:com.googlecode.android_scripting.facade.AndroidFacade.java
private static void putNestedJSONObject(JSONObject jsonObject, Bundle bundle) throws JSONException { JSONArray names = jsonObject.names(); for (int i = 0; i < names.length(); i++) { String name = names.getString(i); Object data = jsonObject.get(name); if (data == null) { continue; }// w w w. j a v a2 s. c om if (data instanceof Integer) { bundle.putInt(name, ((Integer) data).intValue()); } if (data instanceof Float) { bundle.putFloat(name, ((Float) data).floatValue()); } if (data instanceof Double) { bundle.putDouble(name, ((Double) data).doubleValue()); } if (data instanceof Long) { bundle.putLong(name, ((Long) data).longValue()); } if (data instanceof String) { bundle.putString(name, (String) data); } if (data instanceof Boolean) { bundle.putBoolean(name, ((Boolean) data).booleanValue()); } // Nested JSONObject if (data instanceof JSONObject) { Bundle nestedBundle = new Bundle(); bundle.putBundle(name, nestedBundle); putNestedJSONObject((JSONObject) data, nestedBundle); } // Nested JSONArray. Doesn't support mixed types in single array if (data instanceof JSONArray) { // Empty array. No way to tell what type of data to pass on, so skipping if (((JSONArray) data).length() == 0) { Log.e("Empty array not supported in nested JSONObject, skipping"); continue; } // Integer if (((JSONArray) data).get(0) instanceof Integer) { int[] integerArrayData = new int[((JSONArray) data).length()]; for (int j = 0; j < ((JSONArray) data).length(); ++j) { integerArrayData[j] = ((JSONArray) data).getInt(j); } bundle.putIntArray(name, integerArrayData); } // Double if (((JSONArray) data).get(0) instanceof Double) { double[] doubleArrayData = new double[((JSONArray) data).length()]; for (int j = 0; j < ((JSONArray) data).length(); ++j) { doubleArrayData[j] = ((JSONArray) data).getDouble(j); } bundle.putDoubleArray(name, doubleArrayData); } // Long if (((JSONArray) data).get(0) instanceof Long) { long[] longArrayData = new long[((JSONArray) data).length()]; for (int j = 0; j < ((JSONArray) data).length(); ++j) { longArrayData[j] = ((JSONArray) data).getLong(j); } bundle.putLongArray(name, longArrayData); } // String if (((JSONArray) data).get(0) instanceof String) { String[] stringArrayData = new String[((JSONArray) data).length()]; for (int j = 0; j < ((JSONArray) data).length(); ++j) { stringArrayData[j] = ((JSONArray) data).getString(j); } bundle.putStringArray(name, stringArrayData); } // Boolean if (((JSONArray) data).get(0) instanceof Boolean) { boolean[] booleanArrayData = new boolean[((JSONArray) data).length()]; for (int j = 0; j < ((JSONArray) data).length(); ++j) { booleanArrayData[j] = ((JSONArray) data).getBoolean(j); } bundle.putBooleanArray(name, booleanArrayData); } } } }
From source file:com.androzic.MapActivity.java
@Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); Log.e(TAG, "onSaveInstanceState()"); outState.putParcelable("lastKnownLocation", lastKnownLocation); outState.putLong("lastRenderTime", lastRenderTime); outState.putLong("lastMagnetic", lastMagnetic); outState.putLong("lastDim", lastDim); outState.putBoolean("lastGeoid", lastGeoid); outState.putInt("waypointSelected", waypointSelected); outState.putInt("routeSelected", routeSelected); outState.putLong("mapObjectSelected", mapObjectSelected); if (application.distanceOverlay != null) { outState.putDoubleArray("distAncor", application.distanceOverlay.getAncor()); }/*from www.jav a2 s.c om*/ }
From source file:org.opendatakit.common.android.utilities.AndroidUtils.java
public static Bundle convertToBundle(JSONObject valueMap, final MacroStringExpander expander) throws JSONException { Bundle b = new Bundle(); @SuppressWarnings("unchecked") Iterator<String> cur = valueMap.keys(); while (cur.hasNext()) { String key = cur.next();//from w w w .ja v a2 s . c o m if (!valueMap.isNull(key)) { Object o = valueMap.get(key); if (o instanceof JSONObject) { Bundle be = convertToBundle((JSONObject) o, expander); b.putBundle(key, be); } else if (o instanceof JSONArray) { JSONArray a = (JSONArray) o; // only non-empty arrays are written into the Bundle // first non-null element defines data type // for the array Object oe = null; for (int j = 0; j < a.length(); ++j) { if (!a.isNull(j)) { oe = a.get(j); break; } } if (oe != null) { if (oe instanceof JSONObject) { Bundle[] va = new Bundle[a.length()]; for (int j = 0; j < a.length(); ++j) { if (a.isNull(j)) { va[j] = null; } else { va[j] = convertToBundle((JSONObject) a.getJSONObject(j), expander); } } b.putParcelableArray(key, va); } else if (oe instanceof JSONArray) { throw new JSONException("Unable to convert nested arrays"); } else if (oe instanceof String) { String[] va = new String[a.length()]; for (int j = 0; j < a.length(); ++j) { if (a.isNull(j)) { va[j] = null; } else { va[j] = a.getString(j); } } b.putStringArray(key, va); } else if (oe instanceof Boolean) { boolean[] va = new boolean[a.length()]; for (int j = 0; j < a.length(); ++j) { if (a.isNull(j)) { va[j] = false; } else { va[j] = a.getBoolean(j); } } b.putBooleanArray(key, va); } else if (oe instanceof Integer) { int[] va = new int[a.length()]; for (int j = 0; j < a.length(); ++j) { if (a.isNull(j)) { va[j] = 0; } else { va[j] = a.getInt(j); } } b.putIntArray(key, va); } else if (oe instanceof Long) { long[] va = new long[a.length()]; for (int j = 0; j < a.length(); ++j) { if (a.isNull(j)) { va[j] = 0; } else { va[j] = a.getLong(j); } } b.putLongArray(key, va); } else if (oe instanceof Double) { double[] va = new double[a.length()]; for (int j = 0; j < a.length(); ++j) { if (a.isNull(j)) { va[j] = Double.NaN; } else { va[j] = a.getDouble(j); } } b.putDoubleArray(key, va); } } } else if (o instanceof String) { String v = valueMap.getString(key); if (expander != null) { v = expander.expandString(v); } b.putString(key, v); } else if (o instanceof Boolean) { b.putBoolean(key, valueMap.getBoolean(key)); } else if (o instanceof Integer) { b.putInt(key, valueMap.getInt(key)); } else if (o instanceof Long) { b.putLong(key, valueMap.getLong(key)); } else if (o instanceof Double) { b.putDouble(key, valueMap.getDouble(key)); } } } return b; }
From source file:com.facebook.SharedPreferencesTokenCache.java
private void deserializeKey(String key, Bundle bundle) throws JSONException { String jsonString = cache.getString(key, "{}"); JSONObject json = new JSONObject(jsonString); String valueType = json.getString(JSON_VALUE_TYPE); if (valueType.equals(TYPE_BOOLEAN)) { bundle.putBoolean(key, json.getBoolean(JSON_VALUE)); } else if (valueType.equals(TYPE_BOOLEAN_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); boolean[] array = new boolean[jsonArray.length()]; for (int i = 0; i < array.length; i++) { array[i] = jsonArray.getBoolean(i); }/* w ww . j a va 2 s.c o m*/ bundle.putBooleanArray(key, array); } else if (valueType.equals(TYPE_BYTE)) { bundle.putByte(key, (byte) json.getInt(JSON_VALUE)); } else if (valueType.equals(TYPE_BYTE_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); byte[] array = new byte[jsonArray.length()]; for (int i = 0; i < array.length; i++) { array[i] = (byte) jsonArray.getInt(i); } bundle.putByteArray(key, array); } else if (valueType.equals(TYPE_SHORT)) { bundle.putShort(key, (short) json.getInt(JSON_VALUE)); } else if (valueType.equals(TYPE_SHORT_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); short[] array = new short[jsonArray.length()]; for (int i = 0; i < array.length; i++) { array[i] = (short) jsonArray.getInt(i); } bundle.putShortArray(key, array); } else if (valueType.equals(TYPE_INTEGER)) { bundle.putInt(key, json.getInt(JSON_VALUE)); } else if (valueType.equals(TYPE_INTEGER_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); int[] array = new int[jsonArray.length()]; for (int i = 0; i < array.length; i++) { array[i] = jsonArray.getInt(i); } bundle.putIntArray(key, array); } else if (valueType.equals(TYPE_LONG)) { bundle.putLong(key, json.getLong(JSON_VALUE)); } else if (valueType.equals(TYPE_LONG_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); long[] array = new long[jsonArray.length()]; for (int i = 0; i < array.length; i++) { array[i] = jsonArray.getLong(i); } bundle.putLongArray(key, array); } else if (valueType.equals(TYPE_FLOAT)) { bundle.putFloat(key, (float) json.getDouble(JSON_VALUE)); } else if (valueType.equals(TYPE_FLOAT_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); float[] array = new float[jsonArray.length()]; for (int i = 0; i < array.length; i++) { array[i] = (float) jsonArray.getDouble(i); } bundle.putFloatArray(key, array); } else if (valueType.equals(TYPE_DOUBLE)) { bundle.putDouble(key, json.getDouble(JSON_VALUE)); } else if (valueType.equals(TYPE_DOUBLE_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); double[] array = new double[jsonArray.length()]; for (int i = 0; i < array.length; i++) { array[i] = jsonArray.getDouble(i); } bundle.putDoubleArray(key, array); } else if (valueType.equals(TYPE_CHAR)) { String charString = json.getString(JSON_VALUE); if (charString != null && charString.length() == 1) { bundle.putChar(key, charString.charAt(0)); } } else if (valueType.equals(TYPE_CHAR_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); char[] array = new char[jsonArray.length()]; for (int i = 0; i < array.length; i++) { String charString = jsonArray.getString(i); if (charString != null && charString.length() == 1) { array[i] = charString.charAt(0); } } bundle.putCharArray(key, array); } else if (valueType.equals(TYPE_STRING)) { bundle.putString(key, json.getString(JSON_VALUE)); } else if (valueType.equals(TYPE_STRING_LIST)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); int numStrings = jsonArray.length(); ArrayList<String> stringList = new ArrayList<String>(numStrings); for (int i = 0; i < numStrings; i++) { Object jsonStringValue = jsonArray.get(i); stringList.add(i, jsonStringValue == JSONObject.NULL ? null : (String) jsonStringValue); } bundle.putStringArrayList(key, stringList); } }
From source file:com.facebook.LegacyTokenHelper.java
private void deserializeKey(String key, Bundle bundle) throws JSONException { String jsonString = cache.getString(key, "{}"); JSONObject json = new JSONObject(jsonString); String valueType = json.getString(JSON_VALUE_TYPE); if (valueType.equals(TYPE_BOOLEAN)) { bundle.putBoolean(key, json.getBoolean(JSON_VALUE)); } else if (valueType.equals(TYPE_BOOLEAN_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); boolean[] array = new boolean[jsonArray.length()]; for (int i = 0; i < array.length; i++) { array[i] = jsonArray.getBoolean(i); }/*from ww w .ja v a 2 s . c o m*/ bundle.putBooleanArray(key, array); } else if (valueType.equals(TYPE_BYTE)) { bundle.putByte(key, (byte) json.getInt(JSON_VALUE)); } else if (valueType.equals(TYPE_BYTE_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); byte[] array = new byte[jsonArray.length()]; for (int i = 0; i < array.length; i++) { array[i] = (byte) jsonArray.getInt(i); } bundle.putByteArray(key, array); } else if (valueType.equals(TYPE_SHORT)) { bundle.putShort(key, (short) json.getInt(JSON_VALUE)); } else if (valueType.equals(TYPE_SHORT_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); short[] array = new short[jsonArray.length()]; for (int i = 0; i < array.length; i++) { array[i] = (short) jsonArray.getInt(i); } bundle.putShortArray(key, array); } else if (valueType.equals(TYPE_INTEGER)) { bundle.putInt(key, json.getInt(JSON_VALUE)); } else if (valueType.equals(TYPE_INTEGER_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); int[] array = new int[jsonArray.length()]; for (int i = 0; i < array.length; i++) { array[i] = jsonArray.getInt(i); } bundle.putIntArray(key, array); } else if (valueType.equals(TYPE_LONG)) { bundle.putLong(key, json.getLong(JSON_VALUE)); } else if (valueType.equals(TYPE_LONG_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); long[] array = new long[jsonArray.length()]; for (int i = 0; i < array.length; i++) { array[i] = jsonArray.getLong(i); } bundle.putLongArray(key, array); } else if (valueType.equals(TYPE_FLOAT)) { bundle.putFloat(key, (float) json.getDouble(JSON_VALUE)); } else if (valueType.equals(TYPE_FLOAT_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); float[] array = new float[jsonArray.length()]; for (int i = 0; i < array.length; i++) { array[i] = (float) jsonArray.getDouble(i); } bundle.putFloatArray(key, array); } else if (valueType.equals(TYPE_DOUBLE)) { bundle.putDouble(key, json.getDouble(JSON_VALUE)); } else if (valueType.equals(TYPE_DOUBLE_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); double[] array = new double[jsonArray.length()]; for (int i = 0; i < array.length; i++) { array[i] = jsonArray.getDouble(i); } bundle.putDoubleArray(key, array); } else if (valueType.equals(TYPE_CHAR)) { String charString = json.getString(JSON_VALUE); if (charString != null && charString.length() == 1) { bundle.putChar(key, charString.charAt(0)); } } else if (valueType.equals(TYPE_CHAR_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); char[] array = new char[jsonArray.length()]; for (int i = 0; i < array.length; i++) { String charString = jsonArray.getString(i); if (charString != null && charString.length() == 1) { array[i] = charString.charAt(0); } } bundle.putCharArray(key, array); } else if (valueType.equals(TYPE_STRING)) { bundle.putString(key, json.getString(JSON_VALUE)); } else if (valueType.equals(TYPE_STRING_LIST)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); int numStrings = jsonArray.length(); ArrayList<String> stringList = new ArrayList<String>(numStrings); for (int i = 0; i < numStrings; i++) { Object jsonStringValue = jsonArray.get(i); stringList.add(i, jsonStringValue == JSONObject.NULL ? null : (String) jsonStringValue); } bundle.putStringArrayList(key, stringList); } else if (valueType.equals(TYPE_ENUM)) { try { String enumType = json.getString(JSON_VALUE_ENUM_TYPE); @SuppressWarnings({ "unchecked", "rawtypes" }) Class<? extends Enum> enumClass = (Class<? extends Enum>) Class.forName(enumType); @SuppressWarnings("unchecked") Enum<?> enumValue = Enum.valueOf(enumClass, json.getString(JSON_VALUE)); bundle.putSerializable(key, enumValue); } catch (ClassNotFoundException e) { } catch (IllegalArgumentException e) { } } }