List of usage examples for android.os Bundle keySet
public Set<String> keySet()
From source file:com.nbplus.vbroadlauncher.HomeLauncherActivity.java
protected void updateValuesFromBundle(Bundle savedInstanceState) { if (savedInstanceState != null) { // Update the value of mRequestingLocationUpdates from the Bundle, and // make sure that the Start Updates and Stop Updates buttons are // correctly enabled or disabled. if (savedInstanceState.keySet().contains(REQUESTING_LOCATION_UPDATES_KEY)) { mRequestingLocationUpdates = savedInstanceState.getBoolean(REQUESTING_LOCATION_UPDATES_KEY); }//from w ww. j a v a2 s . c om // Update the value of mCurrentLocation from the Bundle and update the // UI to show the correct latitude and longitude. if (savedInstanceState.keySet().contains(LOCATION_KEY)) { mLastLocation = savedInstanceState.getParcelable(LOCATION_KEY); } } }
From source file:com.eleybourn.bookcatalogue.utils.Utils.java
/** * Format the passed bundle in a way that is convenient for display * /* w w w .ja v a 2 s .c o m*/ * @param b Bundle to format * * @return Formatted string */ public static String bundleToString(Bundle b) { StringBuilder sb = new StringBuilder(); for (String k : b.keySet()) { sb.append(k); sb.append("->"); try { sb.append(b.get(k).toString()); } catch (Exception e) { sb.append("<<Unknown>>"); } sb.append("\n"); } return sb.toString(); }
From source file:com.rothconsulting.android.billing.util.IabHelper.java
int queryPurchases(Inventory inv, String itemType) throws JSONException, RemoteException { // Query purchases logDebug("Querying owned items, item type: " + itemType); logDebug("Package name: " + mContext.getPackageName()); boolean verificationFailed = false; String continueToken = null;/* w ww . j a v a 2 s . c o m*/ do { logDebug("Calling getPurchases with continuation token: " + continueToken); Bundle ownedItems = mService.getPurchases(3, mContext.getPackageName(), itemType, continueToken); Utils.log(mDebugTag, "++ --- ownedItems from Service = " + ownedItems); Utils.log(mDebugTag, "++ --- ownedItems itemType = " + itemType); Utils.log(mDebugTag, "++ --- ownedItems keySet = " + ownedItems.keySet()); Utils.log(mDebugTag, "++ --- ownedItems isEmpty = " + ownedItems.isEmpty()); Utils.log(mDebugTag, "++ --- ownedItems INAPP_PURCHASE_ITEM_LIST = " + ownedItems.get("INAPP_PURCHASE_ITEM_LIST")); Utils.log(mDebugTag, "++ --- ownedItems INAPP_PURCHASE_DATA_LIST = " + ownedItems.get("INAPP_PURCHASE_DATA_LIST")); Utils.log(mDebugTag, "++ --- ownedItems INAPP_DATA_SIGNATURE_LIST = " + ownedItems.get("INAPP_DATA_SIGNATURE_LIST")); Utils.log(mDebugTag, "++ --- ownedItems RESPONSE_CODE = " + ownedItems.get("RESPONSE_CODE")); int response = getResponseCodeFromBundle(ownedItems); logDebug("Owned items response: " + String.valueOf(response)); if (response != BILLING_RESPONSE_RESULT_OK) { logDebug("getPurchases() failed: " + getResponseDesc(response)); return response; } if (!ownedItems.containsKey(RESPONSE_INAPP_ITEM_LIST) || !ownedItems.containsKey(RESPONSE_INAPP_PURCHASE_DATA_LIST) || !ownedItems.containsKey(RESPONSE_INAPP_SIGNATURE_LIST)) { logError("Bundle returned from getPurchases() doesn't contain required fields."); return IABHELPER_BAD_RESPONSE; } ArrayList<String> ownedSkus = ownedItems.getStringArrayList(RESPONSE_INAPP_ITEM_LIST); ArrayList<String> purchaseDataList = ownedItems.getStringArrayList(RESPONSE_INAPP_PURCHASE_DATA_LIST); ArrayList<String> signatureList = ownedItems.getStringArrayList(RESPONSE_INAPP_SIGNATURE_LIST); for (int i = 0; i < purchaseDataList.size(); ++i) { String purchaseData = purchaseDataList.get(i); String signature = signatureList.get(i); String sku = ownedSkus.get(i); if (Security.verifyPurchase(mSignatureBase64, purchaseData, signature)) { logDebug("Sku is owned: " + sku); Purchase purchase = new Purchase(itemType, purchaseData, signature); if (TextUtils.isEmpty(purchase.getToken())) { logWarn("BUG: empty/null token!"); logDebug("Purchase data: " + purchaseData); } // Record ownership and token inv.addPurchase(purchase); } else { logWarn("Purchase signature verification **FAILED**. Not adding item."); logDebug(" Purchase data: " + purchaseData); logDebug(" Signature: " + signature); verificationFailed = true; } } continueToken = ownedItems.getString(INAPP_CONTINUATION_TOKEN); logDebug("Continuation token: " + continueToken); } while (!TextUtils.isEmpty(continueToken)); return verificationFailed ? IABHELPER_VERIFICATION_FAILED : BILLING_RESPONSE_RESULT_OK; }
From source file:com.android.launcher3.Utilities.java
/** * Returns true if the intent is a valid launch intent for a launcher activity of an app. * This is used to identify shortcuts which are different from the ones exposed by the * applications' manifest file.//from www. j av a 2 s.c o m * * @param launchIntent The intent that will be launched when the shortcut is clicked. */ public static boolean isLauncherAppTarget(Intent launchIntent) { if (launchIntent != null && Intent.ACTION_MAIN.equals(launchIntent.getAction()) && launchIntent.getComponent() != null && launchIntent.getCategories() != null && launchIntent.getCategories().size() == 1 && launchIntent.hasCategory(Intent.CATEGORY_LAUNCHER) && TextUtils.isEmpty(launchIntent.getDataString())) { // An app target can either have no extra or have ItemInfo.EXTRA_PROFILE. Bundle extras = launchIntent.getExtras(); if (extras == null) { return true; } else { Set<String> keys = extras.keySet(); return keys.size() == 1 && keys.contains(ItemInfo.EXTRA_PROFILE); } } ; return false; }
From source file:com.cloudzilla.fb.FacebookServiceProxy.java
public void showFacebookDialog(final String action, final Bundle params) { Log.d(TAG, "showFacebookDialog action=" + action + " params=" + toString(params)); if (mInstance == null || !mInstance.isOnFacebook()) { Log.e(TAG, "You are not on Facebook"); return;/* ww w.j a va 2 s. c om*/ } new AsyncTask<Void, Void, JSONObject>() { private final IFacebookService facebookService = mFacebookService; protected JSONObject doInBackground(Void... nada) { JSONObject result = null; try { JSONObject jsonRequest = new JSONObject(); jsonRequest.put("method", action); for (String key : params.keySet()) { jsonRequest.put(key, params.get(key)); } String resultAsStr = facebookService.ui(jsonRequest.toString()); if (resultAsStr != null) { result = new JSONObject(resultAsStr); } } catch (JSONException e) { Log.e(TAG, "Exception: ", e); } catch (RemoteException e) { Log.e(TAG, "Failed to invoke FacebookService", e); } return result; } protected void onPostExecute(JSONObject result) { Bundle bundle = null; if (result != null) { try { bundle = toBundle(result); } catch (JSONException e) { // Nothing to do. We'll return a Facebook // exception below. } if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Response from Facebook: "); for (String key : bundle.keySet()) { Log.d(TAG, "\t" + key + "=" + bundle.get(key)); } } // listener.onComplete(bundle, null); } else { // listener.onComplete(null, new FacebookException()); } } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:com.wareninja.opensource.common.wsrequest.WebServiceNew.java
public String webPost(String methodName, Bundle params) throws MalformedURLException, IOException { // random string as boundary for multi-part http post String strBoundary = "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f"; String endLine = "\r\n"; OutputStream os;//from w w w . j av a 2 s . c o m ret = null; String postUrl = webServiceUrl + methodName; if (LOGGING.DEBUG) { Log.d(TAG, "POST URL: " + postUrl); } HttpURLConnection conn = (HttpURLConnection) new URL(postUrl).openConnection(); conn.setRequestProperty("User-Agent", System.getProperties().getProperty("http.agent") + " WareNinjaAndroidSDK"); HttpParams httpParams = httpClient.getParams(); HttpProtocolParams.setUseExpectContinue(httpParams, false); Bundle dataparams = new Bundle(); for (String key : params.keySet()) { byte[] byteArr = null; try { byteArr = (byte[]) params.get(key); } catch (Exception ex1) { } if (byteArr != null) dataparams.putByteArray(key, byteArr); } conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + strBoundary); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestProperty("Connection", "Keep-Alive"); appendRequestHeaders(conn, headers); conn.connect(); os = new BufferedOutputStream(conn.getOutputStream()); os.write(("--" + strBoundary + endLine).getBytes()); os.write((WareNinjaUtils.encodePostBody(params, strBoundary)).getBytes()); os.write((endLine + "--" + strBoundary + endLine).getBytes()); if (!dataparams.isEmpty()) { for (String key : dataparams.keySet()) { os.write(("Content-Disposition: form-data; filename=\"" + key + "\"" + endLine).getBytes()); os.write(("Content-Type: content/unknown" + endLine + endLine).getBytes()); os.write(dataparams.getByteArray(key)); os.write((endLine + "--" + strBoundary + endLine).getBytes()); } } os.flush(); String response = ""; try { response = WareNinjaUtils.read(conn.getInputStream()); } catch (FileNotFoundException e) { // Error Stream contains JSON that we can parse to a FB error response = WareNinjaUtils.read(conn.getErrorStream()); } if (LOGGING.DEBUG) Log.d(TAG, "POST response: " + response); return response; }
From source file:com.android.talkback.SpeechController.java
private boolean processNextFragmentInternal() { if (mCurrentFragmentIterator == null || !mCurrentFragmentIterator.hasNext()) { return false; }/*from www . ja va 2 s . co m*/ FeedbackFragment fragment = mCurrentFragmentIterator.next(); playEarconsFromFragment(fragment); playHapticsFromFragment(fragment); // Reuse the global instance of speech parameters. final HashMap<String, String> params = mSpeechParametersMap; params.clear(); // Add all custom speech parameters. final Bundle speechParams = fragment.getSpeechParams(); for (String key : speechParams.keySet()) { params.put(key, String.valueOf(speechParams.get(key))); } // Utterance ID, stream, and volume override item params. params.put(Engine.KEY_PARAM_UTTERANCE_ID, mCurrentFeedbackItem.getUtteranceId()); params.put(Engine.KEY_PARAM_STREAM, String.valueOf(DEFAULT_STREAM)); params.put(Engine.KEY_PARAM_VOLUME, String.valueOf(mSpeechVolume)); final float pitch = mSpeechPitch * (mUseIntonation ? parseFloatParam(params, SpeechParam.PITCH, 1) : 1); final float rate = mSpeechRate * (mUseIntonation ? parseFloatParam(params, SpeechParam.RATE, 1) : 1); final CharSequence text; if (shouldSilenceSpeech(mCurrentFeedbackItem) || TextUtils.isEmpty(fragment.getText())) { text = null; } else { text = fragment.getText(); } String logText = text == null ? null : text.toString(); LogUtils.log(this, Log.VERBOSE, "Speaking fragment text \"%s\"", logText); mVoiceRecognitionChecker.onUtteranceStart(); // It's okay if the utterance is empty, the fail-over TTS will // immediately call the fragment completion listener. This process is // important for things like continuous reading. mFailoverTts.speak(text, pitch, rate, params, DEFAULT_STREAM, mSpeechVolume); if (mTtsOverlay != null) { mTtsOverlay.speak(text); } return true; }
From source file:com.facebook.Request.java
private static void serializeParameters(Bundle bundle, Serializer serializer, Request request) throws IOException { Set<String> keys = bundle.keySet(); for (String key : keys) { Object value = bundle.get(key); if (isSupportedParameterType(value)) { serializer.writeObject(key, value, request); }//from ww w .ja v a2s. c o m } }
From source file:org.mozilla.gecko.fxa.authenticator.AndroidFxAccount.java
public static AndroidFxAccount addAndroidAccount(Context context, String email, String profile, String idpServerURI, String tokenServerURI, String profileServerURI, State state, final Map<String, Boolean> authoritiesToSyncAutomaticallyMap, final int accountVersion, final boolean fromPickle, ExtendedJSONObject bundle) throws UnsupportedEncodingException, GeneralSecurityException, URISyntaxException { if (email == null) { throw new IllegalArgumentException("email must not be null"); }//from w w w . j a v a 2s . com if (profile == null) { throw new IllegalArgumentException("profile must not be null"); } if (idpServerURI == null) { throw new IllegalArgumentException("idpServerURI must not be null"); } if (tokenServerURI == null) { throw new IllegalArgumentException("tokenServerURI must not be null"); } if (profileServerURI == null) { throw new IllegalArgumentException("profileServerURI must not be null"); } if (state == null) { throw new IllegalArgumentException("state must not be null"); } // TODO: Add migration code. if (accountVersion != CURRENT_ACCOUNT_VERSION) { throw new IllegalStateException("Could not create account of version " + accountVersion + ". Current version is " + CURRENT_ACCOUNT_VERSION + "."); } // Android has internal restrictions that require all values in this // bundle to be strings. *sigh* Bundle userdata = new Bundle(); userdata.putString(ACCOUNT_KEY_ACCOUNT_VERSION, "" + CURRENT_ACCOUNT_VERSION); userdata.putString(ACCOUNT_KEY_IDP_SERVER, idpServerURI); userdata.putString(ACCOUNT_KEY_TOKEN_SERVER, tokenServerURI); userdata.putString(ACCOUNT_KEY_PROFILE_SERVER, profileServerURI); userdata.putString(ACCOUNT_KEY_PROFILE, profile); if (bundle == null) { bundle = new ExtendedJSONObject(); // TODO: How to upgrade? bundle.put(BUNDLE_KEY_BUNDLE_VERSION, CURRENT_BUNDLE_VERSION); } bundle.put(BUNDLE_KEY_STATE_LABEL, state.getStateLabel().name()); bundle.put(BUNDLE_KEY_STATE, state.toJSONObject().toJSONString()); userdata.putString(ACCOUNT_KEY_DESCRIPTOR, bundle.toJSONString()); Account account = new Account(email, FxAccountConstants.ACCOUNT_TYPE); AccountManager accountManager = AccountManager.get(context); // We don't set an Android password, because we don't want to persist the // password (or anything else as powerful as the password). Instead, we // internally manage a sessionToken with a remotely owned lifecycle. boolean added = accountManager.addAccountExplicitly(account, null, userdata); if (!added) { return null; } // Try to work around an intermittent issue described at // http://stackoverflow.com/a/11698139. What happens is that tests that // delete and re-create the same account frequently will find the account // missing all or some of the userdata bundle, possibly due to an Android // AccountManager caching bug. for (String key : userdata.keySet()) { accountManager.setUserData(account, key, userdata.getString(key)); } AndroidFxAccount fxAccount = new AndroidFxAccount(context, account); if (!fromPickle) { fxAccount.clearSyncPrefs(); } fxAccount.setAuthoritiesToSyncAutomaticallyMap(authoritiesToSyncAutomaticallyMap); return fxAccount; }
From source file:RhodesService.java
@Override public void startActivity(Intent intent) { RhodesActivity ra = RhodesActivity.getInstance(); if (intent.getComponent() != null && intent.getComponent().compareTo(new ComponentName(this, RhodesActivity.class.getName())) == 0) { Logger.T(TAG, "Start or bring main activity: " + RhodesActivity.class.getName() + "."); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); if (ra == null) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); super.startActivity(intent); return; }//from w w w. jav a 2 s .c om } if (ra != null) { Logger.T(TAG, "Starting new activity on top."); if (DEBUG) { Bundle extras = intent.getExtras(); if (extras != null) { for (String key : extras.keySet()) { Object val = extras.get(key); if (val != null) Log.d(TAG, key + ": " + val.toString()); else Log.d(TAG, key + ": <empty>"); } } } ra.startActivity(intent); } else { throw new IllegalStateException( "Trying to start activity, but there is no main activity instance (we are in background, no UI active)"); } }