List of usage examples for android.os Bundle putInt
public void putInt(@Nullable String key, int value)
From source file:edu.csh.coursebrowser.SectionInfoActivity.java
@Override public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { // When the given tab is selected, show the tab contents in the // container view. Fragment fragment = new DummySectionFragment(); Bundle args = new Bundle(); args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, tab.getPosition() + 1); fragment.setArguments(args);//from w ww .jav a 2s. c o m getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment).commit(); }
From source file:io.github.importre.android.chromeadb.ChromeAdbService.java
private void moveCursor(String coords) { try {/*w w w.ja v a2 s . com*/ final String[] points = coords.split(","); for (int i = 0; i < points.length; i += 2) { int x = Integer.parseInt(points[i]); int y = Integer.parseInt(points[i + 1]); Message msg = mHandler.obtainMessage(); Bundle data = new Bundle(); data.putInt("x", x); data.putInt("y", y); msg.setData(data); mHandler.sendMessage(msg); } } catch (Exception e) { } }
From source file:com.irccloud.android.fragment.AcceptListFragment.java
@Override public void onSaveInstanceState(Bundle state) { state.putInt("cid", cid); state.putString("event", event.toString()); }
From source file:com.facebook.internal.BundleJSONConverterTests.java
@SmallTest public void testSimpleValues() throws JSONException { ArrayList<String> arrayList = new ArrayList<String>(); arrayList.add("1st"); arrayList.add("2nd"); arrayList.add("third"); Bundle innerBundle1 = new Bundle(); innerBundle1.putInt("inner", 1); Bundle innerBundle2 = new Bundle(); innerBundle2.putString("inner", "2"); innerBundle2.putStringArray("deep list", new String[] { "7", "8" }); innerBundle1.putBundle("nested bundle", innerBundle2); Bundle b = new Bundle(); b.putBoolean("boolValue", true); b.putInt("intValue", 7); b.putLong("longValue", 5000000000l); b.putDouble("doubleValue", 3.14); b.putString("stringValue", "hello world"); b.putStringArray("stringArrayValue", new String[] { "first", "second" }); b.putStringArrayList("stringArrayListValue", arrayList); b.putBundle("nested", innerBundle1); JSONObject json = BundleJSONConverter.convertToJSON(b); assertNotNull(json);//from www .j a va 2 s.com assertEquals(true, json.getBoolean("boolValue")); assertEquals(7, json.getInt("intValue")); assertEquals(5000000000l, json.getLong("longValue")); assertEquals(3.14, json.getDouble("doubleValue")); assertEquals("hello world", json.getString("stringValue")); JSONArray jsonArray = json.getJSONArray("stringArrayValue"); assertEquals(2, jsonArray.length()); assertEquals("first", jsonArray.getString(0)); assertEquals("second", jsonArray.getString(1)); jsonArray = json.getJSONArray("stringArrayListValue"); assertEquals(3, jsonArray.length()); assertEquals("1st", jsonArray.getString(0)); assertEquals("2nd", jsonArray.getString(1)); assertEquals("third", jsonArray.getString(2)); JSONObject innerJson = json.getJSONObject("nested"); assertEquals(1, innerJson.getInt("inner")); innerJson = innerJson.getJSONObject("nested bundle"); assertEquals("2", innerJson.getString("inner")); jsonArray = innerJson.getJSONArray("deep list"); assertEquals(2, jsonArray.length()); assertEquals("7", jsonArray.getString(0)); assertEquals("8", jsonArray.getString(1)); Bundle finalBundle = BundleJSONConverter.convertToBundle(json); assertNotNull(finalBundle); assertEquals(true, finalBundle.getBoolean("boolValue")); assertEquals(7, finalBundle.getInt("intValue")); assertEquals(5000000000l, finalBundle.getLong("longValue")); assertEquals(3.14, finalBundle.getDouble("doubleValue")); assertEquals("hello world", finalBundle.getString("stringValue")); List<String> stringList = finalBundle.getStringArrayList("stringArrayValue"); assertEquals(2, stringList.size()); assertEquals("first", stringList.get(0)); assertEquals("second", stringList.get(1)); stringList = finalBundle.getStringArrayList("stringArrayListValue"); assertEquals(3, stringList.size()); assertEquals("1st", stringList.get(0)); assertEquals("2nd", stringList.get(1)); assertEquals("third", stringList.get(2)); Bundle finalInnerBundle = finalBundle.getBundle("nested"); assertEquals(1, finalInnerBundle.getInt("inner")); finalBundle = finalInnerBundle.getBundle("nested bundle"); assertEquals("2", finalBundle.getString("inner")); stringList = finalBundle.getStringArrayList("deep list"); assertEquals(2, stringList.size()); assertEquals("7", stringList.get(0)); assertEquals("8", stringList.get(1)); }
From source file:de.damdi.fitness.activity.settings.sync.WgerImageDownloader.java
/** * /*www . j a va 2 s . com*/ * @param urlToDownload * the url * @return the name of the downloaded image. This name can be different from * the original name if there's already a file with the same name. */ private String downloadImageToSyncedImagesFolder(String urlToDownload) { try { URL url = new URL(urlToDownload); URLConnection connection = url.openConnection(); connection.connect(); // this will be useful so that you can show a typical 0-100% // progress bar int fileLength = connection.getContentLength(); // download the file InputStream input = new BufferedInputStream(url.openStream()); // create output folder String outputFolder = mContext.getFilesDir().toString() + "/" + IDataProvider.SYNCED_IMAGES_FOLDER; (new File(outputFolder)).mkdir(); String imageName = new File(urlToDownload).getName(); String outputPath = outputFolder + "/" + imageName; // skip files that already exist if ((new File(outputPath)).exists()) { Log.e(TAG, "already such a file: " + outputPath); Log.e(TAG, "Will SKIP this file."); return imageName; } OutputStream output = new FileOutputStream(outputPath); byte data[] = new byte[1024]; long total = 0; int count; while ((count = input.read(data)) != -1) { total += count; // publishing the progress.... Bundle resultData = new Bundle(); resultData.putInt("progress", (int) (total * 100 / fileLength)); // receiver.send(UPDATE_PROGRESS, resultData); output.write(data, 0, count); } output.flush(); output.close(); input.close(); return imageName; } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:com.commonsware.cwac.colormixer.ColorMixer.java
@Override public Parcelable onSaveInstanceState() { Bundle state = new Bundle(); state.putParcelable(SUPERSTATE, super.onSaveInstanceState()); state.putInt(COLOR, getColor()); return (state); }
From source file:com.facebook.internal.BundleJSONConverterTest.java
@Test public void testSimpleValues() throws JSONException { ArrayList<String> arrayList = new ArrayList<String>(); arrayList.add("1st"); arrayList.add("2nd"); arrayList.add("third"); Bundle innerBundle1 = new Bundle(); innerBundle1.putInt("inner", 1); Bundle innerBundle2 = new Bundle(); innerBundle2.putString("inner", "2"); innerBundle2.putStringArray("deep list", new String[] { "7", "8" }); innerBundle1.putBundle("nested bundle", innerBundle2); Bundle b = new Bundle(); b.putBoolean("boolValue", true); b.putInt("intValue", 7); b.putLong("longValue", 5000000000l); b.putDouble("doubleValue", 3.14); b.putString("stringValue", "hello world"); b.putStringArray("stringArrayValue", new String[] { "first", "second" }); b.putStringArrayList("stringArrayListValue", arrayList); b.putBundle("nested", innerBundle1); JSONObject json = BundleJSONConverter.convertToJSON(b); assertNotNull(json);//from www . j a v a 2 s .c o m assertEquals(true, json.getBoolean("boolValue")); assertEquals(7, json.getInt("intValue")); assertEquals(5000000000l, json.getLong("longValue")); assertEquals(3.14, json.getDouble("doubleValue"), TestUtils.DOUBLE_EQUALS_DELTA); assertEquals("hello world", json.getString("stringValue")); JSONArray jsonArray = json.getJSONArray("stringArrayValue"); assertEquals(2, jsonArray.length()); assertEquals("first", jsonArray.getString(0)); assertEquals("second", jsonArray.getString(1)); jsonArray = json.getJSONArray("stringArrayListValue"); assertEquals(3, jsonArray.length()); assertEquals("1st", jsonArray.getString(0)); assertEquals("2nd", jsonArray.getString(1)); assertEquals("third", jsonArray.getString(2)); JSONObject innerJson = json.getJSONObject("nested"); assertEquals(1, innerJson.getInt("inner")); innerJson = innerJson.getJSONObject("nested bundle"); assertEquals("2", innerJson.getString("inner")); jsonArray = innerJson.getJSONArray("deep list"); assertEquals(2, jsonArray.length()); assertEquals("7", jsonArray.getString(0)); assertEquals("8", jsonArray.getString(1)); Bundle finalBundle = BundleJSONConverter.convertToBundle(json); assertNotNull(finalBundle); assertEquals(true, finalBundle.getBoolean("boolValue")); assertEquals(7, finalBundle.getInt("intValue")); assertEquals(5000000000l, finalBundle.getLong("longValue")); assertEquals(3.14, finalBundle.getDouble("doubleValue"), TestUtils.DOUBLE_EQUALS_DELTA); assertEquals("hello world", finalBundle.getString("stringValue")); List<String> stringList = finalBundle.getStringArrayList("stringArrayValue"); assertEquals(2, stringList.size()); assertEquals("first", stringList.get(0)); assertEquals("second", stringList.get(1)); stringList = finalBundle.getStringArrayList("stringArrayListValue"); assertEquals(3, stringList.size()); assertEquals("1st", stringList.get(0)); assertEquals("2nd", stringList.get(1)); assertEquals("third", stringList.get(2)); Bundle finalInnerBundle = finalBundle.getBundle("nested"); assertEquals(1, finalInnerBundle.getInt("inner")); finalBundle = finalInnerBundle.getBundle("nested bundle"); assertEquals("2", finalBundle.getString("inner")); stringList = finalBundle.getStringArrayList("deep list"); assertEquals(2, stringList.size()); assertEquals("7", stringList.get(0)); assertEquals("8", stringList.get(1)); }
From source file:eu.masconsult.bgbanking.accounts.AccountAuthenticator.java
@Override public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException { Log.v(TAG, "getAuthToken(account: " + account + ", authTokenType: " + authTokenType + ")"); Bank bank = Bank.fromAccountType(context, account.type); if (bank == null) { throw new IllegalArgumentException("unsupported account type " + account.type); }//w w w . ja v a 2 s.c om if (!Constants.getAuthorityType(context).equals(authTokenType)) { throw new IllegalArgumentException("unsupported authTOkenType " + authTokenType); } final Intent intent = new Intent(context, LoginActivity.class); intent.putExtra(KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); intent.putExtra(KEY_ACCOUNT_NAME, account.name); intent.putExtra(KEY_ACCOUNT_TYPE, account.type); String password = accountManager.getPassword(account); try { String authToken = bank.getClient().authenticate(account.name, password); Log.v(TAG, "obtained auth token " + authToken); if (authToken == null) { throw new AuthenticationException("no authToken"); } // store the new auth token and return it accountManager.setAuthToken(account, authTokenType, authToken); intent.putExtra(KEY_AUTHTOKEN, authToken); return intent.getExtras(); } catch (ParseException e) { Log.w(TAG, "ParseException", e); Bundle bundle = new Bundle(); bundle.putInt(KEY_ERROR_CODE, 1); bundle.putString(KEY_ERROR_MESSAGE, e.getMessage()); return bundle; } catch (IOException e) { Log.w(TAG, "IOException", e); throw new NetworkErrorException(e); } catch (CaptchaException e) { Log.w(TAG, "CaptchaException", e); // We need human to verify captcha final Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); intent.putExtra(KEY_CAPTCHA_URI, e.getCaptchaUri()); return bundle; } catch (AuthenticationException e) { Log.w(TAG, "AuthenticationException", e); // we need new credentials final Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); return bundle; } }
From source file:de.kirchnerei.bicycle.battery.BatteryListFragment.java
private void doBatteryItemActionClick(int action, BatteryItem item) { Bundle args = new Bundle(); args.putInt(BatteryDefine.PARAM_BATTERY_ID, item.getId()); switch (action) { case R.id.action_detail: getMiddlewareHandler().onAction(R.string.fragment_battery_detail, args); break;//from w w w. ja v a2s.c o m case R.id.action_edit: getMiddlewareHandler().onAction(R.string.fragment_battery_edit, args); break; case R.id.action_delete: Logger.debug("Not implemented yet"); break; } }
From source file:edu.csh.coursebrowser.SectionInfoActivity.java
@Override public void onSaveInstanceState(Bundle outState) { // Serialize the current tab position. outState.putInt(STATE_SELECTED_NAVIGATION_ITEM, getActionBar().getSelectedNavigationIndex()); }