List of usage examples for android.os Bundle putStringArrayList
@Override public void putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value)
From source file:me.henrytao.smoothappbarlayoutdemo.activity.BaseActivity.java
private void requestItemsForPurchase(final AsyncCallback<List<PurchaseItem>> callback) { if (mPurchaseItems != null && mPurchaseItems.size() > 0) { if (callback != null) { callback.onSuccess(mPurchaseItems); }/*from w w w.j a va2s . co m*/ return; } new AsyncTask<IInAppBillingService, Void, AsyncResult<List<PurchaseItem>>>() { @Override protected AsyncResult<List<PurchaseItem>> doInBackground(IInAppBillingService... params) { List<PurchaseItem> result = new ArrayList<>(); Throwable exception = null; IInAppBillingService billingService = params[0]; if (billingService == null) { exception = new Exception("Unknow"); } else { ArrayList<String> skuList = new ArrayList<>(Arrays.asList(DONATE_ITEMS)); Bundle querySkus = new Bundle(); querySkus.putStringArrayList("ITEM_ID_LIST", skuList); try { Bundle skuDetails = billingService.getSkuDetails(3, getPackageName(), "inapp", querySkus); int response = skuDetails.getInt("RESPONSE_CODE"); if (response == 0) { ArrayList<String> responseList = skuDetails.getStringArrayList("DETAILS_LIST"); PurchaseItem purchaseItem; for (String item : responseList) { purchaseItem = new PurchaseItem(new JSONObject(item)); if (purchaseItem.isValid()) { result.add(purchaseItem); } } } } catch (RemoteException e) { e.printStackTrace(); exception = e; } catch (JSONException e) { e.printStackTrace(); exception = e; } } return new AsyncResult<>(result, exception); } @Override protected void onPostExecute(AsyncResult<List<PurchaseItem>> result) { if (!isFinishing() && callback != null) { Throwable error = result.getError(); if (error == null && (result.getResult() == null || result.getResult().size() == 0)) { error = new Exception("Unknow"); } if (error != null) { callback.onError(error); } else { mPurchaseItems = result.getResult(); Collections.sort(mPurchaseItems, new Comparator<PurchaseItem>() { @Override public int compare(PurchaseItem lhs, PurchaseItem rhs) { return (int) ((lhs.getPriceAmountMicros() - rhs.getPriceAmountMicros()) / 1000); } }); callback.onSuccess(mPurchaseItems); } } } }.execute(mBillingService); }
From source file:com.kaliturin.blacklist.fragments.SMSSendFragment.java
@Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); ArrayList<String> numbers = new ArrayList<>(number2NameMap.keySet()); ArrayList<String> names = new ArrayList<>(number2NameMap.values()); outState.putStringArrayList(CONTACT_NUMBERS, numbers); outState.putStringArrayList(CONTACT_NAMES, names); }
From source file:br.fapema.morholt.android.wizardpager.wizard.basic.FixedFragmentStatePagerAdapter.java
@Override public Parcelable saveState() { Bundle state = null; if (mSavedState.size() > 0) { state = new Bundle(); Fragment.SavedState[] fss = new Fragment.SavedState[mSavedState.size()]; mSavedState.toArray(fss);/* w w w. j a va2s . c o m*/ state.putParcelableArray("states", fss); state.putStringArrayList("tags", mSavedFragmentTags); } for (int i = 0; i < mFragments.size(); i++) { Fragment f = mFragments.get(i); if (f != null) { if (state == null) { state = new Bundle(); } String key = "f" + i; mFragmentManager.putFragment(state, key, f); } } return state; }
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);// w ww. ja v a 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:com.google.android.apps.forscience.whistlepunk.metadata.TriggerListFragment.java
@Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); saveTriggerOrder();/*ww w . j a va 2s . co m*/ outState.putStringArrayList(KEY_TRIGGER_ORDER, mTriggerOrder); }
From source file:com.odo.kcl.mobileminer.activities.MainActivity.java
@Override public void onSaveInstanceState(Bundle savedInstanceState) { super.onSaveInstanceState(savedInstanceState); savedInstanceState.putBoolean("miningButtonState", this.miningButtonState); savedInstanceState.putString("cellText", this.cellButton.getText().toString()); savedInstanceState.putStringArrayList("processHeader", (ArrayList<String>) this.processHeader); for (String key : this.processHeader) { savedInstanceState.putStringArrayList(key, (ArrayList<String>) this.socketChild.get(key)); }/*www. jav a2 s.com*/ }
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);/* w w w .j a va2 s.c om*/ 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:activities.GatewayActivity.java
@Override public void WATCHiTSwitchClicked(boolean on) { if (on) {/*from w w w. jav a2s .c om*/ if (sApp.currentActiveSpace == null) { showToast(getString(R.string.register_event_first)); configFragment.updateWATCHiTView(false); return; } if (!btAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivity(enableBtIntent); sApp.isWATChiTOn = false; return; } else { sApp.service.start(); //sApp.isWATChiTOn = true; Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices(); arrayAdapter = new ArrayList<String>(); devices = new ArrayList<BluetoothDevice>(); if (pairedDevices.size() > 0) { for (BluetoothDevice device : pairedDevices) { arrayAdapter.add("Name: " + device.getName() + "\n" + getString(R.string.adress) + " :" + device.getAddress()); devices.add(device); //sApp.arrayAdapter.add() } sApp.bluetoothDevices = devices; } Bundle b = new Bundle(); b.putStringArrayList("adapter", arrayAdapter); ChooseBlueToothDeviceDialog dialog = new ChooseBlueToothDeviceDialog(); dialog.setArguments(b); dialog.show(getSupportFragmentManager(), "pairedbluetoothdevices"); } } if (!on) { if (sApp.service.isRunning()) sApp.service.stop(); showToast(getString(R.string.toast_stopped_watchit_service)); sApp.isWATChiTOn = false; } configFragment.updateWATCHiTView(sApp.isWATChiTOn); }
From source file:com.nokia.example.pepperfarm.iap.Payment.java
/** * Fetches the prices asynchronously/* w w w. j a v a2 s.co m*/ */ public void fetchPrices() { if (!isBillingAvailable()) return; for (Product p : Content.ITEMS) { if (p.getPrice() != "") { Log.i("fetchPrices", "Prices already available. Not fetching."); return; } } AsyncTask<Void, String, Void> pricesTask = new AsyncTask<Void, String, Void>() { @Override protected Void doInBackground(Void... params) { ArrayList<String> productIdArray = new ArrayList<String>(Content.ITEM_MAP.keySet()); Bundle productBundle = new Bundle(); productBundle.putStringArrayList("ITEM_ID_LIST", productIdArray); try { Bundle priceInfo = npay.getProductDetails(API_VERSION, activity.getPackageName(), ITEM_TYPE_INAPP, productBundle); if (priceInfo.getInt("RESPONSE_CODE", RESULT_ERR) == RESULT_OK) { ArrayList<String> productDetailsList = priceInfo.getStringArrayList("DETAILS_LIST"); for (String productDetails : productDetailsList) { parseProductDetails(productDetails); } } else { Log.e("fetchPrices", "PRICE - priceInfo was not ok: Result was: " + priceInfo.getInt("RESPONSE_CODE", -100)); } } catch (JSONException e) { Log.e("fetchPrices", "PRODUCT DETAILS PARSING EXCEPTION: " + e.getMessage(), e); } catch (RemoteException e) { Log.e("fetchPrices", "PRICE EXCEPTION: " + e.getMessage(), e); } return null; } private void parseProductDetails(String productDetails) throws JSONException { ProductDetails details = new ProductDetails(productDetails); Log.i("fetchPrices", productDetails); Product p = Content.ITEM_MAP.get(details.getProductId()); if (p != null) { p.setPrice(details.getPriceFormatted()); Log.i("fetchPrices", "PRICE RECEIVED - " + details.getPrice() + " " + details.getCurrency()); } else { Log.i("fetchPrices", "Unable to set price for product " + details.getProductId() + ". Product not found."); } } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); if (ProductListFragment.purchaseListAdapter != null) { ProductListFragment.purchaseListAdapter.notifyDataSetChanged(); } if (MainScreenPepperListFragment.reference.adapter != null) { MainScreenPepperListFragment.reference.adapter.notifyDataSetChanged(); } } }; pricesTask.execute(); }
From source file:us.cboyd.android.dicom.DcmBrowser.java
public void onFileSelected(int position, ArrayList<String> fileList, File currDir) { // The user selected a DICOM file from the DcmListFragment position -= 1;/*from ww w. j a v a 2 s .c o m*/ if ((position < 0) || (position > fileList.size())) { // TODO: Error return; } if (mFragmented && mListFragment.isVisible()) { // If we're in the one-pane layout and need to swap fragments // Enable the Home/Up button to allow the user to go back to ActionBar actionBar = getActionBar(); actionBar.setHomeButtonEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); // Create fragment and give it an argument for the selected article Bundle args = new Bundle(); args.putInt(DcmVar.POSITION, position); args.putStringArrayList(DcmVar.FILELIST, fileList); args.putString(DcmVar.CURRDIR, currDir.getPath()); mInfoFragment.setArguments(args); FragmentTransaction transaction = getFragmentManager().beginTransaction(); // Replace whatever is in the fragment_container view with this fragment, // and add the transaction to the back stack so the user can navigate back transaction.replace(R.id.fragment_container, mInfoFragment); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); transaction.addToBackStack(null).commit(); // set up the drawer's list view with items and click listener mDrawerList.setAdapter(mListFragment.getListAdapter()); } else { // If we're in the two-pane layout or already displaying the DcmInfoFragment // Call a method in the DcmInfoFragment to update its content mInfoFragment.updateDicomInfo(position, fileList, currDir.getPath()); } setTitle(fileList.get(position)); }