List of usage examples for android.os Bundle getStringArrayList
@Override
@Nullable
public ArrayList<String> getStringArrayList(@Nullable String key)
From source file:com.nextgis.mobile.InputPointActivity.java
@Override protected void onRestoreInstanceState(Bundle outState) { super.onRestoreInstanceState(outState); m_sCat = outState.getString("cat"); m_sSubCat = outState.getString("subcat"); m_fAzimuth = outState.getFloat("az"); m_fDist = outState.getFloat("dist"); m_sNote = outState.getString("note"); image_lst = outState.getStringArrayList("photos"); double[] adfAz = outState.getDoubleArray("photos_az"); for (int i = 0; i < adfAz.length; i++) { image_rotation.add(adfAz[i]);// ww w . j a va 2s .co m } }
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 .jav a 2s . com 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:com.ct.speech.HintReceiver.java
/** * Fire an intent to start the speech recognition activity. * // w w w . java2 s . c o m * @param args * Argument array with the following string args: [req * code][number of matches][prompt string] Google speech * recognizer */ private void startSpeechRecognitionActivity(JSONArray args) { // int reqCode = 42; // Hitchhiker? // global now int maxMatches = 2; String prompt = ""; String language = ""; try { if (args.length() > 0) { // Request code - passed back to the caller on a successful // operation String temp = args.getString(0); reqCode = Integer.parseInt(temp); } if (args.length() > 1) { // Maximum number of matches, 0 means the recognizer decides String temp = args.getString(1); maxMatches = Integer.parseInt(temp); } if (args.length() > 2) { // Optional text prompt prompt = args.getString(2); } if (args.length() > 3) { // Optional language specified language = args.getString(3); } } catch (Exception e) { Log.e(TAG, String.format("startSpeechRecognitionActivity exception: %s", e.toString())); } final Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra("calling_package", "com.ct.BasicAppFrame"); // If specific language if (!language.equals("")) { intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language); } if (maxMatches > 0) intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxMatches); if (!(prompt.length() == 0)) intent.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt); // ctx.startActivityForResult(this, intent, reqCode); //removed to try // using recognizer directly try { this.ctx.runOnUiThread(new Runnable() { public void run() { final SpeechRecognizer recognizer = SpeechRecognizer.createSpeechRecognizer((Context) ctx); RecognitionListener listener = new RecognitionListener() { @Override public void onResults(Bundle results) { //closeRecordedFile(); sendBackResults(results); ArrayList<String> voiceResults = results .getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION); if (voiceResults == null) { Log.e(TAG, "No voice results"); } else { // Log.d(TAG, "Printing matches: "); for (@SuppressWarnings("unused") String match : voiceResults) { // Log.d(TAG, match); } } recognizer.destroy(); } @Override public void onReadyForSpeech(Bundle params) { // Log.d(TAG, "Ready for speech"); } @Override public void onError(int error) { Log.d(TAG, "Error listening for speech: " + error); if (error == SpeechRecognizer.ERROR_NO_MATCH) { sendBackResults(NO_MATCH); } else if (error == SpeechRecognizer.ERROR_SPEECH_TIMEOUT) { sendBackResults(NO_INPUT); } else { speechFailure("unknown error"); } recognizer.destroy(); } @Override public void onBeginningOfSpeech() { // Log.d(TAG, "Speech starting"); setStartOfSpeech(); } @Override //doesn't fire in Android after Ice Cream Sandwich public void onBufferReceived(byte[] buffer) { } @Override public void onEndOfSpeech() { setEndOfSpeech(); } @Override public void onEvent(int eventType, Bundle params) { // TODO Auto-generated method stub } @Override public void onPartialResults(Bundle partialResults) { // TODO Auto-generated method stub } @Override public void onRmsChanged(float rmsdB) { // TODO Auto-generated method stub } }; recognizer.setRecognitionListener(listener); Log.d(TAG, "starting speech recognition activity"); recognizer.startListening(intent); } }); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.anjlab.android.iab.v3.BillingProcessor.java
private SkuDetails getSkuDetails(String productId, String purchaseType) { if (billingService != null) { try {/*from ww w. ja v a 2s . c o m*/ ArrayList<String> skuList = new ArrayList<String>(); skuList.add(productId); Bundle products = new Bundle(); products.putStringArrayList(Constants.PRODUCTS_LIST, skuList); Bundle skuDetails = billingService.getSkuDetails(Constants.GOOGLE_API_VERSION, contextPackageName, purchaseType, products); int response = skuDetails.getInt(Constants.RESPONSE_CODE); if (response == Constants.BILLING_RESPONSE_RESULT_OK) { for (String responseLine : skuDetails.getStringArrayList(Constants.DETAILS_LIST)) { JSONObject object = new JSONObject(responseLine); String responseProductId = object.getString(Constants.RESPONSE_PRODUCT_ID); if (productId.equals(responseProductId)) return new SkuDetails(object); } } else { if (eventHandler != null) eventHandler.onBillingError(response, null); Log.e(LOG_TAG, String.format("Failed to retrieve info for %s: error %d", productId, response)); } } catch (Exception e) { Log.e(LOG_TAG, String.format("Failed to call getSkuDetails %s", e.toString())); } } return null; }
From source file:me.henrytao.bootstrapandroidlibrarydemo.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 ava 2 s .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(mDonateItems)); 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.krayzk9s.imgurholo.ui.AlbumsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); boolean newData = false; if (savedInstanceState == null && urls == null) { urls = new ArrayList<String>(); ids = new ArrayList<String>(); newData = true;/* ww w . j a va 2 s . co m*/ } else if (savedInstanceState != null) { urls = savedInstanceState.getStringArrayList("urls"); ids = savedInstanceState.getStringArrayList("ids"); } View view = inflater.inflate(R.layout.image_layout, container, false); errorText = (TextView) view.findViewById(R.id.error); mPullToRefreshLayout = (PullToRefreshLayout) view.findViewById(R.id.ptr_layout); ActionBarPullToRefresh.from(getActivity()) // Mark All Children as pullable .allChildrenArePullable() // Set the OnRefreshListener .listener(this) // Finally commit the setup to our PullToRefreshLayout .setup(mPullToRefreshLayout); ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) errorText.getLayoutParams(); mlp.setMargins(0, 0, 0, 0); view.setPadding(0, getActivity().getActionBar().getHeight(), 0, 0); noImageView = (TextView) view.findViewById(R.id.no_images); GridView gridview = (GridView) view.findViewById(R.id.grid_layout); ImgurHoloActivity activity = (ImgurHoloActivity) getActivity(); SharedPreferences settings = activity.getApiCall().settings; gridview.setColumnWidth(Utils.dpToPx( Integer.parseInt(settings.getString(getString(R.string.icon_size), getString(R.string.onetwenty))), getActivity())); imageAdapter = new ImageAdapter(view.getContext()); gridview.setAdapter(imageAdapter); gridview.setOnItemClickListener(new GridItemClickListener()); if (newData) { getImages(); } gridview.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int i) { } @Override public void onScroll(AbsListView absListView, int firstVisibleItem, int i2, int i3) { if (lastInView == -1) lastInView = firstVisibleItem; else if (lastInView > firstVisibleItem) { getActivity().getActionBar().show(); lastInView = firstVisibleItem; } else if (lastInView < firstVisibleItem) { getActivity().getActionBar().hide(); lastInView = firstVisibleItem; } } }); return view; }
From source file:br.com.thinkti.android.filechooserfrag.fragFileChooser.java
public void init() { if (_main == null || _Intent == null || _chooserView == null || _blnInitialized) { return;// w ww .ja v a2s . c o m } try { Bundle extras = _Intent.getExtras(); if (extras != null) { unicode = extras.getBoolean("blnUniCode", true); DefaultDir = extras.getString("DefaultDir"); if (extras.getStringArrayList("filterFileExtension") != null) { extensions = extras.getStringArrayList("filterFileExtension"); fileFilter = new FileFilter() { @Override public boolean accept(File pathname) { return ((pathname.isDirectory()) || ExtensionsMatch(pathname)); } }; } } setCurrentDir((DefaultDir)); _blnInitialized = true; } catch (Exception ex) { Toast.makeText(_main, _main.getString(R.string.Error) + ex.getMessage(), Toast.LENGTH_LONG).show(); } }
From source file:com.gamethrive.TrackGooglePurchase.java
private void QueryBoughtItems() { if (isWaitingForPurchasesRequest) return;//from w w w .j av a2s . com new Thread(new Runnable() { public void run() { isWaitingForPurchasesRequest = true; try { if (getPurchasesMethod == null) getPurchasesMethod = IInAppBillingServiceClass.getMethod("getPurchases", int.class, String.class, String.class, String.class); Bundle ownedItems = (Bundle) getPurchasesMethod.invoke(mIInAppBillingService, 3, appContext.getPackageName(), "inapp", null); if (ownedItems.getInt("RESPONSE_CODE") == 0) { ArrayList<String> skusToAdd = new ArrayList<String>(); ArrayList<String> newPurchaseTokens = new ArrayList<String>(); ArrayList<String> ownedSkus = ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST"); ArrayList<String> purchaseDataList = ownedItems .getStringArrayList("INAPP_PURCHASE_DATA_LIST"); for (int i = 0; i < purchaseDataList.size(); i++) { String purchaseData = purchaseDataList.get(i); String sku = ownedSkus.get(i); JSONObject itemPurchased = new JSONObject(purchaseData); String purchaseToken = itemPurchased.getString("purchaseToken"); if (!purchaseTokens.contains(purchaseToken) && !newPurchaseTokens.contains(purchaseToken)) { newPurchaseTokens.add(purchaseToken); skusToAdd.add(sku); } } if (skusToAdd.size() > 0) sendPurchases(skusToAdd, newPurchaseTokens); else if (purchaseDataList.size() == 0) { newAsExisting = false; prefsEditor.putBoolean("ExistingPurchases", false); prefsEditor.commit(); } // TODO: Handle very large list. Test for continuationToken != null then call getPurchases again } } catch (Throwable e) { e.printStackTrace(); } isWaitingForPurchasesRequest = false; } }).start(); }
From source file:com.liferay.mobile.screens.base.list.BaseListScreenletView.java
@Override protected void onRestoreInstanceState(Parcelable inState) { Bundle state = (Bundle) inState; Parcelable superState = state.getParcelable(STATE_SUPER); super.onRestoreInstanceState(superState); List<E> entries = state.getParcelableArrayList(STATE_ENTRIES); A adapter = getAdapter();/*from www .ja v a 2s. c om*/ adapter.setRowCount(state.getInt(STATE_ROW_COUNT)); adapter.getEntries().addAll(entries == null ? new ArrayList<E>() : entries); adapter.notifyDataSetChanged(); List labelFields = state.getStringArrayList(STATE_LABEL_FIELDS); getAdapter().setLabelFields(labelFields); firstRow = state.getInt(STATE_FIRST_ROW); }
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 ww .ja v a 2 s. c o 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); }