List of usage examples for android.os Bundle size
public int size()
From source file:com.acc.android.network.operator.base.BaseHttpOperator.java
private String encodeUrlParam(Object paramObject) throws UnsupportedEncodingException { if (paramObject == null) return HttpConstant.DEFAULTPARAM; StringBuilder sb = new StringBuilder(); if (paramObject instanceof Bundle) { Bundle bundle = (Bundle) paramObject; if (bundle.size() == 0) { return HttpConstant.DEFAULTPARAM; } else {/*from ww w .ja v a 2 s.c o m*/ boolean isFirst = true; for (String key : bundle.keySet()) { if (isFirst) isFirst = false; else sb.append("&"); // Object object; sb.append(key + "=" + URLEncoder.encode(bundle.getString(key), HttpConstant.ENCODE)); // + paramBundle.getString(key)); } } } else if (paramObject instanceof Map) { HashMap<String, String> map = (HashMap<String, String>) paramObject; if (map.size() == 0) { return HttpConstant.DEFAULTPARAM; } else { boolean isFirst = true; for (Object key : map.keySet()) { if (isFirst) isFirst = false; else sb.append("&"); // Object object; sb.append(key + "=" + URLEncoder.encode(map.get(key).toString(), HttpConstant.ENCODE)); // + paramBundle.getString(key)); } } } else if (paramObject instanceof List && ((List) paramObject).get(0) instanceof NameValuePair) { // if (paramObject instanceof List) { // List list = (List) paramObject; // Object object = list.get(0); // if (object instanceof NameValuePair) { boolean isFirst = true; for (NameValuePair nameValuePair : (List<NameValuePair>) paramObject) { if (isFirst) isFirst = false; else sb.append("&"); // Object object; sb.append(nameValuePair.getName() + "=" + URLEncoder.encode(nameValuePair.getValue(), HttpConstant.ENCODE)); // + paramBundle.getString(key)); } } else { // sb.append("&"); // Object object; sb.append(HttpConstant.DEFAULT_KEY_REQUEST_PARAM + "=" + URLEncoder.encode(this.jsonManager.getJson(paramObject), HttpConstant.ENCODE)); } return sb.toString(); }
From source file:android.support.v7ox.app.AppCompatDelegateImplV7.java
private void doInvalidatePanelMenu(int featureId) { PanelFeatureState st = getPanelState(featureId, true); Bundle savedActionViewStates = null; if (st.menu != null) { savedActionViewStates = new Bundle(); st.menu.saveActionViewStates(savedActionViewStates); if (savedActionViewStates.size() > 0) { st.frozenActionViewState = savedActionViewStates; }/*from w ww . j a v a 2 s . c o m*/ // This will be started again when the panel is prepared. st.menu.stopDispatchingItemsChanged(); st.menu.clear(); } st.refreshMenuContent = true; st.refreshDecorView = true; // Prepare the options panel if we have an action bar if ((featureId == FEATURE_SUPPORT_ACTION_BAR || featureId == FEATURE_OPTIONS_PANEL) && mDecorContentParent != null) { st = getPanelState(Window.FEATURE_OPTIONS_PANEL, false); if (st != null) { st.isPrepared = false; preparePanel(st, null); } } }
From source file:com.trk.aboutme.facebook.Request.java
private void serializeToBatch(JSONArray batch, Bundle attachments) throws JSONException, IOException { JSONObject batchEntry = new JSONObject(); if (this.batchEntryName != null) { batchEntry.put(BATCH_ENTRY_NAME_PARAM, this.batchEntryName); batchEntry.put(BATCH_ENTRY_OMIT_RESPONSE_ON_SUCCESS_PARAM, this.batchEntryOmitResultOnSuccess); }/*from ww w. j ava 2 s. c o m*/ if (this.batchEntryDependsOn != null) { batchEntry.put(BATCH_ENTRY_DEPENDS_ON_PARAM, this.batchEntryDependsOn); } String relativeURL = getUrlForBatchedRequest(); batchEntry.put(BATCH_RELATIVE_URL_PARAM, relativeURL); batchEntry.put(BATCH_METHOD_PARAM, httpMethod); if (this.session != null) { String accessToken = this.session.getAccessToken(); Logger.registerAccessToken(accessToken); } // Find all of our attachments. Remember their names and put them in the attachment map. ArrayList<String> attachmentNames = new ArrayList<String>(); Set<String> keys = this.parameters.keySet(); for (String key : keys) { Object value = this.parameters.get(key); if (isSupportedAttachmentType(value)) { // Make the name unique across this entire batch. String name = String.format("%s%d", ATTACHMENT_FILENAME_PREFIX, attachments.size()); attachmentNames.add(name); Utility.putObjectInBundle(attachments, name, value); } } if (!attachmentNames.isEmpty()) { String attachmentNamesString = TextUtils.join(",", attachmentNames); batchEntry.put(ATTACHED_FILES_PARAM, attachmentNamesString); } if (this.graphObject != null) { // Serialize the graph object into the "body" parameter. final ArrayList<String> keysAndValues = new ArrayList<String>(); processGraphObject(this.graphObject, relativeURL, new KeyValueSerializer() { @Override public void writeString(String key, String value) throws IOException { keysAndValues.add(String.format("%s=%s", key, URLEncoder.encode(value, "UTF-8"))); } }); String bodyValue = TextUtils.join("&", keysAndValues); batchEntry.put(BATCH_BODY_PARAM, bodyValue); } batch.put(batchEntry); }
From source file:org.kontalk.ui.AbstractComposeFragment.java
private void processArguments(Bundle savedInstanceState) { Bundle args; if (savedInstanceState != null) { Uri uri = savedInstanceState.getParcelable(Uri.class.getName()); // threadId = ContentUris.parseId(uri); args = new Bundle(); args.putString("action", ComposeMessage.ACTION_VIEW_USERID); args.putParcelable("data", uri); String currentPhoto = savedInstanceState.getString("currentPhoto"); if (currentPhoto != null) { mCurrentPhoto = new File(currentPhoto); }//w ww . j a va 2 s.c o m // audio playing setAudioStatus(savedInstanceState.getInt("mediaPlayerStatus", AudioContentView.STATUS_IDLE)); // audio dialog stuff mAudioDialog = AudioDialog.onRestoreInstanceState(getActivity(), savedInstanceState, getAudioFragment(), this); if (mAudioDialog != null) { Log.d(TAG, "recreating audio dialog"); mAudioDialog.show(); } } else { args = getArguments(); } if (args != null && args.size() > 0) { final String action = args.getString("action"); // view intent if (Intent.ACTION_VIEW.equals(action)) { Uri uri = args.getParcelable("data"); handleActionView(uri); } // view conversation - just threadId provided else if (ComposeMessage.ACTION_VIEW_CONVERSATION.equals(action)) { Uri uri = args.getParcelable("data"); loadConversationMetadata(uri); } // view conversation - just userId provided else if (ComposeMessage.ACTION_VIEW_USERID.equals(action)) { Uri uri = args.getParcelable("data"); if (!handleActionViewConversation(uri, args)) { getActivity().finish(); return; } } } // set title if we are autonomous if (args != null) { String title = mUserName; //if (mUserPhone != null) title += " <" + mUserPhone + ">"; setActivityTitle(title, ""); } // update conversation stuff if (mConversation != null) onConversationCreated(); onArgumentsProcessed(); }
From source file:com.gelakinetic.mtgfam.FamiliarActivity.java
private boolean processIntent(Intent intent) { boolean isDeepLink = false; if (Intent.ACTION_SEARCH.equals(intent.getAction())) { /* Do a search by name, launched from the quick search */ String query = intent.getStringExtra(SearchManager.QUERY); Bundle args = new Bundle(); SearchCriteria sc = new SearchCriteria(); sc.name = query;/*from ww w . j av a2s .com*/ args.putSerializable(SearchViewFragment.CRITERIA, sc); selectItem(R.string.main_card_search, args, false, true); /* Don't clear backstack, do force the intent */ } else if (Intent.ACTION_VIEW.equals(intent.getAction())) { boolean shouldSelectItem = true; Uri data = intent.getData(); Bundle args = new Bundle(); assert data != null; boolean shouldClearFragmentStack = true; /* Clear backstack for deep links */ if (data.getAuthority().toLowerCase().contains("gatherer.wizards")) { SQLiteDatabase database = DatabaseManager.getInstance(this, false).openDatabase(false); try { String queryParam; if ((queryParam = data.getQueryParameter("multiverseid")) != null) { Cursor cursor = CardDbAdapter.fetchCardByMultiverseId(Long.parseLong(queryParam), new String[] { CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_ID }, database); if (cursor.getCount() != 0) { isDeepLink = true; args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY, new long[] { cursor.getInt(cursor.getColumnIndex(CardDbAdapter.KEY_ID)) }); } cursor.close(); if (args.size() == 0) { throw new Exception("Not Found"); } } else if ((queryParam = data.getQueryParameter("name")) != null) { Cursor cursor = CardDbAdapter.fetchCardByName(queryParam, new String[] { CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_ID }, true, database); if (cursor.getCount() != 0) { isDeepLink = true; args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY, new long[] { cursor.getInt(cursor.getColumnIndex(CardDbAdapter.KEY_ID)) }); } cursor.close(); if (args.size() == 0) { throw new Exception("Not Found"); } } else { throw new Exception("Not Found"); } } catch (Exception e) { /* empty cursor, just return */ ToastWrapper.makeText(this, R.string.no_results_found, ToastWrapper.LENGTH_LONG).show(); this.finish(); shouldSelectItem = false; } finally { DatabaseManager.getInstance(this, false).closeDatabase(false); } } else if (data.getAuthority().contains("CardSearchProvider")) { /* User clicked a card in the quick search autocomplete, jump right to it */ args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY, new long[] { Long.parseLong(data.getLastPathSegment()) }); shouldClearFragmentStack = false; /* Don't clear backstack for search intents */ } else { /* User clicked a deep link, jump to the card(s) */ isDeepLink = true; SQLiteDatabase database = DatabaseManager.getInstance(this, false).openDatabase(false); try { Cursor cursor = null; boolean screenLaunched = false; if (data.getScheme().toLowerCase().equals("card") && data.getAuthority().toLowerCase().equals("multiverseid")) { if (data.getLastPathSegment() == null) { /* Home screen deep link */ launchHomeScreen(); screenLaunched = true; shouldSelectItem = false; } else { try { /* Don't clear the fragment stack for internal links (thanks Meld cards) */ if (data.getPathSegments().contains("internal")) { shouldClearFragmentStack = false; } cursor = CardDbAdapter.fetchCardByMultiverseId( Long.parseLong(data.getLastPathSegment()), new String[] { CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_ID }, database); } catch (NumberFormatException e) { cursor = null; } } } if (cursor != null) { if (cursor.getCount() != 0) { args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY, new long[] { cursor.getInt(cursor.getColumnIndex(CardDbAdapter.KEY_ID)) }); } else { /* empty cursor, just return */ ToastWrapper.makeText(this, R.string.no_results_found, ToastWrapper.LENGTH_LONG).show(); this.finish(); shouldSelectItem = false; } cursor.close(); } else if (!screenLaunched) { /* null cursor, just return */ ToastWrapper.makeText(this, R.string.no_results_found, ToastWrapper.LENGTH_LONG).show(); this.finish(); shouldSelectItem = false; } } catch (FamiliarDbException e) { e.printStackTrace(); } DatabaseManager.getInstance(this, false).closeDatabase(false); } args.putInt(CardViewPagerFragment.STARTING_CARD_POSITION, 0); if (shouldSelectItem) { selectItem(R.string.main_card_search, args, shouldClearFragmentStack, true); } } else if (ACTION_ROUND_TIMER.equals(intent.getAction())) { selectItem(R.string.main_timer, null, true, false); } else if (ACTION_CARD_SEARCH.equals(intent.getAction())) { selectItem(R.string.main_card_search, null, true, false); } else if (ACTION_LIFE.equals(intent.getAction())) { selectItem(R.string.main_life_counter, null, true, false); } else if (ACTION_DICE.equals(intent.getAction())) { selectItem(R.string.main_dice, null, true, false); } else if (ACTION_TRADE.equals(intent.getAction())) { selectItem(R.string.main_trade, null, true, false); } else if (ACTION_MANA.equals(intent.getAction())) { selectItem(R.string.main_mana_pool, null, true, false); } else if (ACTION_WISH.equals(intent.getAction())) { selectItem(R.string.main_wishlist, null, true, false); } else if (ACTION_RULES.equals(intent.getAction())) { selectItem(R.string.main_rules, null, true, false); } else if (ACTION_JUDGE.equals(intent.getAction())) { selectItem(R.string.main_judges_corner, null, true, false); } else if (ACTION_MOJHOSTO.equals(intent.getAction())) { selectItem(R.string.main_mojhosto, null, true, false); } else if (ACTION_PROFILE.equals(intent.getAction())) { selectItem(R.string.main_profile, null, true, false); } else if (ACTION_DECKLIST.equals(intent.getAction())) { selectItem(R.string.main_decklist, null, true, false); } else if (Intent.ACTION_MAIN.equals(intent.getAction())) { /* App launched as regular, show the default fragment if there isn't one already */ if (getSupportFragmentManager().getFragments() == null) { launchHomeScreen(); } } else { /* Some unknown intent, just finish */ finish(); } mDrawerList.setItemChecked(mCurrentFrag, true); return isDeepLink; }
From source file:org.kontalk.ui.ComposeMessageFragment.java
private void processArguments(Bundle savedInstanceState) { Bundle args; if (savedInstanceState != null) { Uri uri = savedInstanceState.getParcelable(Uri.class.getName()); // threadId = ContentUris.parseId(uri); args = new Bundle(); args.putString("action", ComposeMessage.ACTION_VIEW_USERID); args.putParcelable("data", uri); String currentPhoto = savedInstanceState.getString("currentPhoto"); if (currentPhoto != null) { mCurrentPhoto = new File(currentPhoto); }//from www .j a v a 2s.co m mAudioDialog = AudioDialog.onRestoreInstanceState(getActivity(), savedInstanceState, getAudioFragment(), this); if (mAudioDialog != null) { Log.d(TAG, "recreating audio dialog"); mAudioDialog.show(); } } else { args = myArguments(); } if (args != null && args.size() > 0) { final String action = args.getString("action"); // view intent if (Intent.ACTION_VIEW.equals(action)) { Uri uri = args.getParcelable("data"); ContentResolver cres = getActivity().getContentResolver(); /* * FIXME this will retrieve name directly from contacts, * resulting in a possible discrepancy with users database */ Cursor c = cres.query(uri, new String[] { Syncer.DATA_COLUMN_DISPLAY_NAME, Syncer.DATA_COLUMN_PHONE }, null, null, null); if (c.moveToFirst()) { mUserName = c.getString(0); mUserPhone = c.getString(1); // FIXME should it be retrieved from RawContacts.SYNC3 ?? mUserJID = XMPPUtils.createLocalJID(getActivity(), MessageUtils.sha1(mUserPhone)); Cursor cp = cres.query(Messages.CONTENT_URI, new String[] { Messages.THREAD_ID }, Messages.PEER + " = ?", new String[] { mUserJID }, null); if (cp.moveToFirst()) threadId = cp.getLong(0); cp.close(); } c.close(); if (threadId > 0) { mConversation = Conversation.loadFromId(getActivity(), threadId); } else { mConversation = Conversation.createNew(getActivity()); mConversation.setRecipient(mUserJID); } } // view conversation - just threadId provided else if (ComposeMessage.ACTION_VIEW_CONVERSATION.equals(action)) { Uri uri = args.getParcelable("data"); loadConversationMetadata(uri); } // view conversation - just userId provided else if (ComposeMessage.ACTION_VIEW_USERID.equals(action)) { Uri uri = args.getParcelable("data"); mUserJID = uri.getPathSegments().get(1); mConversation = Conversation.loadFromUserId(getActivity(), mUserJID); if (mConversation == null) { mConversation = Conversation.createNew(getActivity()); mConversation.setNumberHint(args.getString("number")); mConversation.setRecipient(mUserJID); } // this way avoid doing the users database query twice else { if (mConversation.getContact() == null) { mConversation.setNumberHint(args.getString("number")); mConversation.setRecipient(mUserJID); } } threadId = mConversation.getThreadId(); Contact contact = mConversation.getContact(); if (contact != null) { mUserName = contact.getName(); mUserPhone = contact.getNumber(); } else { mUserName = mUserJID; mUserPhone = null; } } } // set title if we are autonomous if (mArguments != null) { String title = mUserName; //if (mUserPhone != null) title += " <" + mUserPhone + ">"; setActivityTitle(title, ""); } // update conversation stuff if (mConversation != null) onConversationCreated(); // non existant thread - check for not synced contact if (threadId <= 0 && mConversation != null) { Contact contact = mConversation.getContact(); if (mUserPhone != null && contact != null ? !contact.isRegistered() : true) { // ask user to send invitation DialogInterface.OnClickListener noListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // FIXME is this specific to sms app? Intent i = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + mUserPhone)); i.putExtra("sms_body", getString(R.string.text_invite_message)); startActivity(i); getActivity().finish(); } }; AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(getActivity()); builder.setTitle(R.string.title_user_not_found).setMessage(R.string.message_user_not_found) // nothing happens if user chooses to contact the user anyway .setPositiveButton(R.string.yes_user_not_found, null) .setNegativeButton(R.string.no_user_not_found, noListener).show(); } } }
From source file:com.androzic.Preferences.java
/** * Parse the given XML file as a header description, adding each * parsed Header into the target list.//from w w w . j a v a 2 s .com * * @param resid * The XML resource to load and parse. * @param target * The list in which the parsed headers should be placed. */ public void loadHeadersFromResource(int resid, List<Header> target) { Androzic application = Androzic.getApplication(); XmlResourceParser parser = null; try { Resources resources = getResources(); parser = resources.getXml(resid); AttributeSet attrs = Xml.asAttributeSet(parser); int type; //noinspection StatementWithEmptyBody while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) { // Parse next until start tag is found } String nodeName = parser.getName(); if (!"preference-headers".equals(nodeName)) { throw new RuntimeException("XML document must start with <preference-headers> tag; found" + nodeName + " at " + parser.getPositionDescription()); } Bundle curBundle = null; final int outerDepth = parser.getDepth(); while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { continue; } nodeName = parser.getName(); if ("header".equals(nodeName)) { Header header = new Header(); TypedArray sa = resources.obtainAttributes(attrs, R.styleable.PreferenceHeader); header.id = sa.getResourceId(R.styleable.PreferenceHeader_id, (int) HEADER_ID_UNDEFINED); TypedValue tv = sa.peekValue(R.styleable.PreferenceHeader_title); if (tv != null && tv.type == TypedValue.TYPE_STRING) { if (tv.resourceId != 0) { header.titleRes = tv.resourceId; } else { header.title = tv.string; } } tv = sa.peekValue(R.styleable.PreferenceHeader_summary); if (tv != null && tv.type == TypedValue.TYPE_STRING) { if (tv.resourceId != 0) { header.summaryRes = tv.resourceId; } else { header.summary = tv.string; } } tv = sa.peekValue(R.styleable.PreferenceHeader_breadCrumbTitle); if (tv != null && tv.type == TypedValue.TYPE_STRING) { if (tv.resourceId != 0) { header.breadCrumbTitleRes = tv.resourceId; } else { header.breadCrumbTitle = tv.string; } } tv = sa.peekValue(R.styleable.PreferenceHeader_breadCrumbShortTitle); if (tv != null && tv.type == TypedValue.TYPE_STRING) { if (tv.resourceId != 0) { header.breadCrumbShortTitleRes = tv.resourceId; } else { header.breadCrumbShortTitle = tv.string; } } header.iconRes = sa.getResourceId(R.styleable.PreferenceHeader_icon, 0); header.fragment = sa.getString(R.styleable.PreferenceHeader_fragment); header.help = sa.getResourceId(R.styleable.PreferenceHeader_help, 0); sa.recycle(); if (curBundle == null) { curBundle = new Bundle(); } final int innerDepth = parser.getDepth(); while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { continue; } String innerNodeName = parser.getName(); if (innerNodeName.equals("extra")) { resources.parseBundleExtra(innerNodeName, attrs, curBundle); XmlUtils.skipCurrentTag(parser); } else if (innerNodeName.equals("intent")) { header.intent = Intent.parseIntent(resources, parser, attrs); } else { XmlUtils.skipCurrentTag(parser); } } if (curBundle.size() > 0) { header.fragmentArguments = curBundle; curBundle = null; } if (header.id == R.id.pref_plugins && application.getPluginsPreferences().size() == 0) continue; target.add(header); } else { XmlUtils.skipCurrentTag(parser); } } } catch (XmlPullParserException | IOException e) { throw new RuntimeException("Error parsing headers", e); } finally { if (parser != null) parser.close(); } }