List of usage examples for android.os Bundle keySet
public Set<String> keySet()
From source file:com.wareninja.android.opensource.mongolab_sdk.common.WebService.java
public String getJsonFromParams2(Bundle params) { Map<String, Object> paramsMap = new LinkedHashMap<String, Object>(); String valStr;/*from w ww . j a v a 2 s . co m*/ Object valObj; for (String key : params.keySet()) { valObj = params.get(key); if (valObj instanceof String) { // ugly check if the string value is JSONObj or JSONArr valStr = "" + valObj; // if (AppContext.isDebugMode()) Log.d(TAG, "valStr->"+valStr); valObj = null; try { valObj = new JSONObject(valStr); // note: very ugly hack just for tag loco part! if (valStr.contains("{") && valStr.contains("lat") && valStr.contains("lng")) { LinkedHashMap<String, Object> tempMap = new LinkedHashMap<String, Object>(); tempMap.put("lng", ((JSONObject) valObj).get("lng")); tempMap.put("lat", ((JSONObject) valObj).get("lat")); JSONObject tempJson = new JSONObject(tempMap); if (AppContext.isDebugMode()) Log.d(TAG, "tempJson->" + tempJson + "| len:" + tempJson.length()); if (AppContext.isDebugMode()) Log.d(TAG, "valObj(before)->" + valObj); if (tempJson.length() > 0) { valObj = tempJson; } if (AppContext.isDebugMode()) Log.d(TAG, "valObj(after)->" + valObj); } } catch (JSONException ex) { valObj = null; } if (valObj == null) { try { valObj = new JSONArray(valStr); } catch (JSONException ex) { valObj = null; } } if (valObj == null) valObj = valStr; } if (valObj != null) paramsMap.put(key, valObj); } return getJsonFromParams(paramsMap); }
From source file:uk.co.ashtonbrsc.intentexplode.Explode.java
/** textViewToIgnore is not updated so current selected char in that textview will not change */ private void showAllIntentData(TextView textViewToIgnore) { showTextViewIntentData(textViewToIgnore); categoriesLayout.removeAllViews();//from ww w. j ava 2 s. c o m Set<String> categories = editableIntent.getCategories(); StringBuilder stringBuilder = new StringBuilder(); if (categories != null) { categoriesHeader.setVisibility(View.VISIBLE); stringBuilder.append(getResources().getString(R.string.categories)); for (String category : categories) { stringBuilder.append(category).append(NEWLINE); TextView categoryTextView = new TextView(this); categoryTextView.setText(category); categoryTextView.setTextAppearance(this, R.style.TextFlags); categoriesLayout.addView(categoryTextView); } } else { categoriesHeader.setVisibility(View.GONE); // addTextToLayout("NONE", Typeface.NORMAL, categoriesLayout); } flagsLayout.removeAllViews(); ArrayList<String> flagsStrings = getFlags(); if (!flagsStrings.isEmpty()) { for (String thisFlagString : flagsStrings) { addTextToLayout(thisFlagString, Typeface.NORMAL, flagsLayout); } } else { addTextToLayout(getResources().getString(R.string.none), Typeface.NORMAL, flagsLayout); } extrasLayout.removeAllViews(); try { Bundle intentBundle = editableIntent.getExtras(); if (intentBundle != null) { Set<String> keySet = intentBundle.keySet(); stringBuilder.append(getResources().getString(R.string.bundle_title_bold)); int count = 0; for (String key : keySet) { count++; Object thisObject = intentBundle.get(key); addTextToLayout(getResources().getString(R.string.extra) + count, Typeface.BOLD, extrasLayout); String thisClass = thisObject.getClass().getName(); if (thisClass != null) { addTextToLayout(getResources().getString(R.string.class_text) + thisClass, Typeface.ITALIC, STANDARD_INDENT_SIZE_IN_DIP, extrasLayout); } addTextToLayout(getResources().getString(R.string.key) + key, Typeface.ITALIC, STANDARD_INDENT_SIZE_IN_DIP, extrasLayout); if (thisObject instanceof String || thisObject instanceof Long || thisObject instanceof Integer || thisObject instanceof Boolean || thisObject instanceof Uri) { addTextToLayout(getResources().getString(R.string.value) + thisObject.toString(), Typeface.ITALIC, STANDARD_INDENT_SIZE_IN_DIP, extrasLayout); } else if (thisObject instanceof ArrayList) { addTextToLayout(getResources().getString(R.string.values), Typeface.ITALIC, extrasLayout); ArrayList thisArrayList = (ArrayList) thisObject; for (Object thisArrayListObject : thisArrayList) { addTextToLayout(thisArrayListObject.toString(), Typeface.ITALIC, STANDARD_INDENT_SIZE_IN_DIP, extrasLayout); } } } } else { addTextToLayout(getResources().getString(R.string.none), Typeface.NORMAL, extrasLayout); } } catch (Exception e) { // TODO Should make this red to highlight error addTextToLayout(getResources().getString(R.string.error_extracting_extras), Typeface.NORMAL, extrasLayout); e.printStackTrace(); } // resolveInfo = pm.queryIntentServices(intent, 0); // stringBuilder.append("<br><b><u>" + resolveInfo.size() // + " services match this intent:</u></b><br>"); // for (int i = 0; i < resolveInfo.size(); i++) { // ResolveInfo info = resolveInfo.get(i); // ActivityInfo activityinfo = info.activityInfo; // stringBuilder.append(activityinfo.packageName + "<br>"); // } // intentDetailsHtml = stringBuilder.toString(); // (((TextView) findViewById(R.id.text))).setText(intentDetailsHtml); refreshUI(); }
From source file:com.futureplatforms.kirin.extensions.localnotifications.LocalNotificationsBackend.java
public void showNotification(Bundle settings, Intent intent) { Uri uri = intent.getData();//from w w w . j ava2 s.c om int uriCode = URI_MATCHER.match(uri); if (uriCode != C.REQUEST_CODE_LOCALNOTIFICATION) { Log.w(C.TAG, "Notification with invalid uri: " + uri); return; } String idString = uri.getLastPathSegment(); if (idString == null) { Log.w(C.TAG, "Just got a notification with no data"); return; } Log.i(C.TAG, "LocalNotificationsBackend.showNotification: " + settings + " keys: " + settings.keySet()); String key = PREFS_PREFIX + idString; JSONObject obj = getJSONNotificationObject(key); if (obj == null) { // return; obj = new JSONObject(); try { obj.put("vibrate", false); obj.put("sound", false); obj.put("title", "A test notification"); obj.put("body", "New job: fix Mr. Gluck's hazy TV, PDQ!"); obj.put("id", 42); obj.put("timeMillisSince1970", System.currentTimeMillis()); } catch (JSONException e) { Log.e(C.TAG, "Erm not thought possible"); } } Notification n = createNotification(settings, obj); if (n != null) { NotificationManager nm = (NotificationManager) mContext.getSystemService(Service.NOTIFICATION_SERVICE); nm.notify(NOTIFICATION_MASK | obj.optInt("id"), n); } mPrefs.edit().remove(key).commit(); }
From source file:com.example.newfragmentstatepageradapter.NewFragmentStatePagerAdapter.java
@Override public void restoreState(Parcelable state, ClassLoader loader) { if (state != null) { Bundle bundle = (Bundle) state; bundle.setClassLoader(loader);/*from w w w.ja v a 2s.co m*/ mItemIds = bundle.getLongArray("itemids"); if (mItemIds == null) { mItemIds = new long[] {}; } Parcelable[] fss = bundle.getParcelableArray("states"); mSavedState.clear(); mFragments.clear(); if (fss != null) { for (int i = 0; i < fss.length; i++) { mSavedState.add((Fragment.SavedState) fss[i]); } } Iterable<String> keys = bundle.keySet(); for (String key : keys) { if (key.startsWith("f")) { int index = Integer.parseInt(key.substring(1)); Fragment f = mFragmentManager.getFragment(bundle, key); if (f != null) { while (mFragments.size() <= index) { mFragments.add(null); } f.setMenuVisibility(false); mFragments.set(index, f); } else { Log.w(TAG, "Bad fragment at key " + key); } } } } }
From source file:com.grouzen.android.serenity.HttpConnection.java
private HttpResponse post(String url, Bundle params) throws ClientProtocolException, IOException { HttpPost method = new HttpPost(url); if (params != null) { try {/*from w w w . j a v a 2 s.co m*/ if (mMultipartKey != null && mMultipartFileName != null) { ByteArrayBody byteArrayBody = new ByteArrayBody(params.getByteArray(mMultipartKey), mMultipartFileName); MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); Charset charset = Charset.forName(CHARSET); entity.addPart(mMultipartKey, byteArrayBody); params.remove(mMultipartKey); for (String k : params.keySet()) { entity.addPart(new FormBodyPart(k, new StringBody(params.getString(k), charset))); } method.setEntity(entity); } else { ArrayList<NameValuePair> entity = convertParams(params); method.setEntity(new UrlEncodedFormEntity(entity, CHARSET)); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } return execute(method); }
From source file:uk.co.ashtonbrsc.intentexplode.Explode.java
private Spanned getIntentDetailsString() { // TODO make sure this has all // the details StringBuilder stringBuilder = new StringBuilder(); // k3b so intent can be reloaded using // Intent.parseUri("Intent:....", Intent.URI_INTENT_SCHEME) stringBuilder.append(getUri(editableIntent)).append(NEWLINE); // support for onActivityResult if (this.lastResultCode != null) { stringBuilder.append(getResources().getString(R.string.last_result)) .append(this.lastResultCode.toString()); if (this.lastResultIntent != null) { stringBuilder.append(getResources().getString(R.string.data)).append(lastResultIntent); }// ww w . j a va 2 s . c o m stringBuilder.append(NEWLINE); } stringBuilder.append(NEWLINE).append(getResources().getString(R.string.action_bold)) .append(editableIntent.getAction()).append(NEWLINE); stringBuilder.append(getResources().getString(R.string.data_bold)).append(editableIntent.getData()) .append(NEWLINE); stringBuilder.append(getResources().getString(R.string.type_bold)).append(editableIntent.getType()) .append(NEWLINE); Set<String> categories = editableIntent.getCategories(); if (categories != null) { stringBuilder.append(getResources().getString(R.string.categories_title_bold)); for (String category : categories) { stringBuilder.append(category).append(NEWLINE); } } stringBuilder.append(getResources().getString(R.string.flags_title_bold)); ArrayList<String> flagsStrings = getFlags(); if (!flagsStrings.isEmpty()) { for (String thisFlagString : flagsStrings) { stringBuilder.append(thisFlagString).append(NEWLINE); } } else { stringBuilder.append(getResources().getString(R.string.none)).append(NEWLINE); } try { Bundle intentBundle = editableIntent.getExtras(); if (intentBundle != null) { Set<String> keySet = intentBundle.keySet(); stringBuilder.append(getResources().getString(R.string.extras_title_bold)); int count = 0; for (String key : keySet) { count++; Object thisObject = intentBundle.get(key); stringBuilder.append(getResources().getQuantityString(R.plurals.extra_count, count, count)); String thisClass = thisObject.getClass().getName(); if (thisClass != null) { stringBuilder.append(getResources().getString(R.string.class_text)).append(thisClass) .append(NEWLINE); } stringBuilder.append(getResources().getString(R.string.key)).append(key).append(NEWLINE); if (thisObject instanceof String || thisObject instanceof Long || thisObject instanceof Integer || thisObject instanceof Boolean || thisObject instanceof Uri) { stringBuilder.append(getResources().getString(R.string.value)).append(thisObject.toString()) .append(NEWLINE); } else if (thisObject instanceof ArrayList) { stringBuilder.append(getResources().getString(R.string.values_break)); ArrayList thisArrayList = (ArrayList) thisObject; for (Object thisArrayListObject : thisArrayList) { stringBuilder.append(thisArrayListObject.toString()).append(NEWLINE); } } } } } catch (Exception e) { stringBuilder.append(getResources().getString(R.string.bundle_title_bold_uppercase)); stringBuilder.append(getResources().getString(R.string.error_extracting_extras_red)); e.printStackTrace(); } PackageManager pm = getPackageManager(); List<ResolveInfo> resolveInfo = pm.queryIntentActivities(editableIntent, 0); // Remove Intent Intercept from matching activities int numberOfMatchingActivities = resolveInfo.size() - 1; if (numberOfMatchingActivities < 1) { stringBuilder.append(getResources().getString(R.string.no_activities_match_intent_title_bold)); } else { stringBuilder.append(getResources().getQuantityString(R.plurals.activites_match_intent_title_bold, numberOfMatchingActivities, numberOfMatchingActivities)); for (int i = 0; i <= numberOfMatchingActivities; i++) { ResolveInfo info = resolveInfo.get(i); ActivityInfo activityinfo = info.activityInfo; if (!activityinfo.packageName.equals(getPackageName())) { stringBuilder.append(activityinfo.loadLabel(pm)) .append(getResources().getString(R.string.open_bracket)) .append(activityinfo.packageName).append(getResources().getString(R.string.dash)) .append(activityinfo.name) .append(getResources().getString(R.string.close_bracket_break)); } } } return Html.fromHtml(stringBuilder.toString()); }
From source file:com.trk.aboutme.facebook.Request.java
private static void serializeParameters(Bundle bundle, Serializer serializer) throws IOException { Set<String> keys = bundle.keySet(); for (String key : keys) { Object value = bundle.get(key); if (isSupportedParameterType(value)) { serializer.writeObject(key, value); }//from w w w . ja va2 s.c o m } }
From source file:com.trk.aboutme.facebook.Request.java
private static void serializeAttachments(Bundle bundle, Serializer serializer) throws IOException { Set<String> keys = bundle.keySet(); for (String key : keys) { Object value = bundle.get(key); if (isSupportedAttachmentType(value)) { serializer.writeObject(key, value); }/*from w w w . j a v a 2 s .c om*/ } }
From source file:com.example.craiger.nav.FragmentItemIdStatePagerAdapter.java
@Override public void restoreState(Parcelable state, ClassLoader loader) { if (state != null) { Bundle bundle = (Bundle) state; bundle.setClassLoader(loader);// w ww . j a v a 2s. c o m long[] itemIdsForState = bundle.getLongArray("itemIdsForState"); Parcelable[] fss = bundle.getParcelableArray("states"); mFragmentToItemIdMap.clear(); mItemIdToFragmentMap.clear(); mUnusedRestoredFragments.clear(); mSavedState.clear(); if (fss != null) { for (int i = 0; i < fss.length; i++) { mSavedState.put(itemIdsForState[i], (Fragment.SavedState) fss[i]); } } Iterable<String> keys = bundle.keySet(); for (String key : keys) { if (key.startsWith(KEY_FRAGMENT)) { Long itemId = Long.parseLong(key.substring(KEY_FRAGMENT.length())); Fragment f = mFragmentManager.getFragment(bundle, key); if (f != null) { f.setMenuVisibility(false); mFragmentToItemIdMap.put(f, itemId); mItemIdToFragmentMap.put(itemId, f); } else { Log.w(TAG, "Bad fragment at key " + key); } } } mUnusedRestoredFragments.addAll(mFragmentToItemIdMap.keySet()); } }