List of usage examples for android.os Bundle putInt
public void putInt(@Nullable String key, int value)
From source file:com.oakesville.mythling.MediaActivity.java
protected void showItemInDetailPane(int position, boolean grabFocus) { ItemDetailFragment detailFragment = new ItemDetailFragment(); Bundle arguments = new Bundle(); arguments.putInt(SEL_ITEM_INDEX, position); arguments.putBoolean(GRAB_FOCUS, grabFocus); detailFragment.setArguments(arguments); // FIXME: Issue #69 getFragmentManager().beginTransaction().replace(R.id.detail_container, detailFragment, DETAIL_FRAGMENT) .commit();/*w w w.j ava2 s . c o m*/ }
From source file:com.gimranov.zandy.app.data.Item.java
/** * Makes ArrayList<Bundle> from the present item's tags Primarily for use * with TagActivity, but who knows?//from ww w. j ava 2 s .co m */ public ArrayList<Bundle> tagsToBundleArray() { JSONObject itemContent = this.content; /* * Here we walk through the data and make Bundles to send to the * ArrayAdapter. There should be no real risk of JSON exceptions, since * the JSON was checked when initialized in the Item object. * * Each Bundle has three keys: "itemKey", "tag", and "type" */ ArrayList<Bundle> rows = new ArrayList<Bundle>(); Bundle b = new Bundle(); if (!itemContent.has("tags")) { return rows; } try { JSONArray tags = itemContent.getJSONArray("tags"); Log.d(TAG, tags.toString()); for (int i = 0; i < tags.length(); i++) { b = new Bundle(); // Type is not always specified, but we try to get it // and fall back to 0 when missing. Log.d(TAG, tags.getJSONObject(i).toString()); if (tags.getJSONObject(i).has("type")) b.putInt("type", tags.getJSONObject(i).optInt("type", 0)); b.putString("tag", tags.getJSONObject(i).optString("tag")); b.putString("itemKey", this.key); rows.add(b); } } catch (JSONException e) { Log.e(TAG, "JSON exception caught in tag bundler: ", e); } return rows; }
From source file:com.vegnab.vegnab.MainVNActivity.java
public void goToVisitHeaderScreen(long visitID) { // swap VisitHeaderFragment in place of existing fragment if (LDebug.ON) Log.d(LOG_TAG, "About to go to VisitHeader"); Bundle args = new Bundle(); // visitID = 0 means new visit, not assigned or created yet args.putLong(VisitHeaderFragment.ARG_VISIT_ID, visitID); args.putInt(VisitHeaderFragment.ARG_SUBPLOT, 0); // start with dummy value, subplot 0 VisitHeaderFragment visHdrFrag = VisitHeaderFragment.newInstance(args); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); // put the present fragment on the backstack so the user can navigate back to it // the tag is for the fragment now being added, not the one replaced transaction.replace(R.id.fragment_container, visHdrFrag, Tags.VISIT_HEADER); transaction.addToBackStack(null);/*w w w . j a va 2s .co m*/ transaction.commit(); }
From source file:com.oakesville.mythling.MediaActivity.java
protected void showSubListPane(String path, int selIdx, boolean grabFocus) { ItemListFragment listFragment = new ItemListFragment(); Bundle arguments = new Bundle(); arguments.putString(PATH, path);/*from w w w.j a v a 2s .c o m*/ arguments.putInt(SEL_ITEM_INDEX, selIdx); arguments.putBoolean(GRAB_FOCUS, grabFocus); listFragment.setArguments(arguments); getFragmentManager().beginTransaction().replace(R.id.detail_container, listFragment, LIST_FRAGMENT) .commit(); }
From source file:com.oakesville.mythling.MediaActivity.java
@Override public void onSaveInstanceState(Bundle savedInstanceState) { super.onSaveInstanceState(savedInstanceState); savedInstanceState.putInt(SEL_ITEM_INDEX, selItemIndex); savedInstanceState.putInt(CURRENT_TOP, currentTop); savedInstanceState.putInt(TOP_OFFSET, topOffset); }
From source file:com.facebook.internal.FacebookWebFallbackDialog.java
@Override protected Bundle parseResponseUri(String url) { Uri responseUri = Uri.parse(url);//from w ww .j a v a 2 s . com Bundle queryParams = Utility.parseUrlQueryString(responseUri.getQuery()); // Convert Bridge args to the format that the Native dialog code understands. String bridgeArgsJSONString = queryParams.getString(ServerProtocol.FALLBACK_DIALOG_PARAM_BRIDGE_ARGS); queryParams.remove(ServerProtocol.FALLBACK_DIALOG_PARAM_BRIDGE_ARGS); if (!Utility.isNullOrEmpty(bridgeArgsJSONString)) { Bundle bridgeArgs; try { JSONObject bridgeArgsJSON = new JSONObject(bridgeArgsJSONString); bridgeArgs = BundleJSONConverter.convertToBundle(bridgeArgsJSON); queryParams.putBundle(NativeProtocol.EXTRA_PROTOCOL_BRIDGE_ARGS, bridgeArgs); } catch (JSONException je) { Utility.logd(TAG, "Unable to parse bridge_args JSON", je); } } // Convert Method results to the format that the Native dialog code understands. String methodResultsJSONString = queryParams.getString(ServerProtocol.FALLBACK_DIALOG_PARAM_METHOD_RESULTS); queryParams.remove(ServerProtocol.FALLBACK_DIALOG_PARAM_METHOD_RESULTS); if (!Utility.isNullOrEmpty(methodResultsJSONString)) { methodResultsJSONString = Utility.isNullOrEmpty(methodResultsJSONString) ? "{}" : methodResultsJSONString; Bundle methodResults; try { JSONObject methodArgsJSON = new JSONObject(methodResultsJSONString); methodResults = BundleJSONConverter.convertToBundle(methodArgsJSON); queryParams.putBundle(NativeProtocol.EXTRA_PROTOCOL_METHOD_RESULTS, methodResults); } catch (JSONException je) { Utility.logd(TAG, "Unable to parse bridge_args JSON", je); } } // The web host does not send a numeric version back. Put the latest known version in there so NativeProtocol // can continue parsing the response. queryParams.remove(ServerProtocol.FALLBACK_DIALOG_PARAM_VERSION); queryParams.putInt(NativeProtocol.EXTRA_PROTOCOL_VERSION, NativeProtocol.getLatestKnownVersion()); return queryParams; }
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 w w w .j av a2 s.co 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) { } } }
From source file:net.homelinux.penecoptero.android.citybikes.donation.app.MainActivity.java
private void fillData(boolean all) { if (mNDBAdapter != null && mNDBAdapter.isConfigured()) { Bundle data = new Bundle(); if (!all) { GeoPoint center = locator.getCurrentGeoPoint(); if (center == null) { //Do something.. int nid = settings.getInt("network_id", -1); //Log.i("CityBikes","Current network is id: "+Integer.toString(nid)); if (nid != -1) { try { mNDBAdapter.load(); JSONObject network = mNDBAdapter.getNetworks(nid); //Log.i("CityBikes",network.toString()); double lat = Integer.parseInt(network.getString("lat")) / 1E6; double lng = Integer.parseInt(network.getString("lng")) / 1E6; Location fallback = new Location("fallback"); fallback.setLatitude(lat); fallback.setLongitude(lng); locator.setFallbackLocation(fallback); locator.unlockCenter(); center = locator.getCurrentGeoPoint(); } catch (Exception e) { //Log.i("CityBikes","We re fucked, that network aint existin"); e.printStackTrace(); }//from ww w. j a v a 2 s . c o m } else { //Log.i("CityBikes","We re fucked, why re we here?"); } } data.putInt(StationsDBAdapter.CENTER_LAT_KEY, center.getLatitudeE6()); data.putInt(StationsDBAdapter.CENTER_LNG_KEY, center.getLongitudeE6()); data.putInt(StationsDBAdapter.RADIUS_KEY, hOverlay.getRadius()); } progressDialog = new ProgressDialog(this); progressDialog.setTitle(""); progressDialog.setMessage(getString(R.string.loading)); progressDialog.show(); try { mDbHelper.sync(all, data); } catch (Exception e) { ////Log.i("openBicing", "Error Updating?"); e.printStackTrace(); progressDialog.dismiss(); } ; } else { //Log.i("CityBikes","First time!!! :D"); try { mNDBAdapter.update(); AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_map); alertDialog.setTitle(R.string.bike_network_alert_title); alertDialog.setMessage(getString(R.string.bike_network_alert_text)); alertDialog.setButton(getString(R.string.automatic), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.automatic), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showAutoNetworkDialog(0); } }); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.manual), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showBikeNetworks(); } }); alertDialog.show(); } catch (Exception e) { e.printStackTrace(); Toast toast = Toast.makeText(getApplicationContext(), getString(R.string.network_error), Toast.LENGTH_LONG); toast.show(); } } }
From source file:net.homelinux.penecoptero.android.citybikes.app.MainActivity.java
private void fillData(boolean all) { if (mNDBAdapter != null && mNDBAdapter.isConfigured()) { Bundle data = new Bundle(); if (!all) { GeoPoint center = locator.getCurrentGeoPoint(); if (center == null) { //Do something.. int nid = settings.getInt("network_id", -1); //Log.i("CityBikes","Current network is id: "+Integer.toString(nid)); if (nid != -1) { try { mNDBAdapter.load(); JSONObject network = mNDBAdapter.getNetworks(nid); //Log.i("CityBikes",network.toString()); double lat = Integer.parseInt(network.getString("lat")) / 1E6; double lng = Integer.parseInt(network.getString("lng")) / 1E6; Location fallback = new Location("fallback"); fallback.setLatitude(lat); fallback.setLongitude(lng); locator.setFallbackLocation(fallback); locator.unlockCenter(); center = locator.getCurrentGeoPoint(); } catch (Exception e) { //Log.i("CityBikes","We re fucked, that network aint existin"); e.printStackTrace(); }/*from w ww .j a v a2 s.co m*/ } else { //Log.i("CityBikes","We re fucked, why re we here?"); } } data.putInt(StationsDBAdapter.CENTER_LAT_KEY, center.getLatitudeE6()); data.putInt(StationsDBAdapter.CENTER_LNG_KEY, center.getLongitudeE6()); data.putInt(StationsDBAdapter.RADIUS_KEY, hOverlay.getRadius()); } progressDialog = new ProgressDialog(this); progressDialog.setTitle(""); progressDialog.setMessage(getString(R.string.loading)); progressDialog.show(); try { mDbHelper.sync(all, data); } catch (Exception e) { ////Log.i("openBicing", "Error Updating?"); e.printStackTrace(); progressDialog.dismiss(); } ; } else { //Log.i("CityBikes","First time!!! :D"); try { mNDBAdapter.update(); AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_map); alertDialog.setTitle(R.string.bike_network_alert_title); alertDialog.setMessage(getString(R.string.bike_network_alert_text)); alertDialog.setButton(getString(R.string.automatic), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.automatic), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showAutoNetworkDialog(0); } }); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.manual), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showBikeNetworks(); } }); alertDialog.show(); } catch (Exception e) { e.printStackTrace(); Toast toast = Toast.makeText(getApplicationContext(), getString(R.string.network_error), Toast.LENGTH_LONG); toast.show(); } } infoLayer.update(); }