List of usage examples for android.text TextUtils split
public static String[] split(String text, Pattern pattern)
From source file:tw.idv.palatis.danboorugallery.siteapi.DanbooruLegacyAPI.java
public static Post parseJSONObjectToPost(Host host, JSONObject json) throws JSONException, ParseException { if (json == null) return null; String file_url = json.getString(DanbooruLegacyPost.KEY_POST_FILE_URL); String file_url_large = json.getString(DanbooruLegacyPost.KEY_POST_LARGE_FILE_URL); String file_url_preview = json.getString(DanbooruLegacyPost.KEY_POST_PREVIEW_FILE_URL); if (!file_url.startsWith("http")) file_url = host.url + file_url;//from w w w . j a v a 2 s.co m if (!file_url_large.startsWith("http")) file_url_large = host.url + file_url_large; if (!file_url_preview.startsWith("http")) file_url_preview = host.url + file_url_preview; JSONObject json_date = json.getJSONObject(DanbooruLegacyPost.KEY_POST_CREATED_AT); Date date = new Date(json_date.getLong("s") * 1000 + json_date.getLong("n") / 1000000); int uploader_id = -1; String uploader_name = ""; try { uploader_id = json.getInt(DanbooruLegacyPost.KEY_POST_UPLOADER_ID); } catch (JSONException ignored) { } try { uploader_name = json.getString(DanbooruLegacyPost.KEY_POST_UPLOADER_NAME); } catch (JSONException ignored) { } return new DanbooruLegacyPost(host, json.getInt(DanbooruLegacyPost.KEY_POST_ID), json.getInt(DanbooruLegacyPost.KEY_POST_IMAGE_WIDTH), json.getInt(DanbooruLegacyPost.KEY_POST_IMAGE_HEIGHT), date, date, json.getInt(DanbooruLegacyPost.KEY_POST_FILE_SIZE), file_url, file_url_large, file_url_preview, TextUtils.split(json.getString(DanbooruLegacyPost.KEY_POST_TAG_STRING), " "), json.getString(DanbooruLegacyPost.KEY_POST_RATING), uploader_id, uploader_name, json.getString(DanbooruLegacyPost.KEY_POST_MD5), json.getInt(DanbooruLegacyPost.KEY_POST_SCORE)); }
From source file:comp3111h.anytaxi.driver.Register_FormFragment.java
private String licenseBeautifier(String license) { String[] partialLicense = TextUtils.split(license.trim().toUpperCase(Locale.getDefault()), " +"); license = TextUtils.join(" ", partialLicense); return license; }
From source file:com.openerp.addons.messages.Message.java
public void setupListView(List<OEListViewRows> message_list) { // Destroying pre-loaded instance and going to create new one lstview = null;/*from ww w . j a v a 2 s . c om*/ // Fetching required messages for listview by filtering of requrement if (list != null && list.size() <= 0) { list = message_list;// getMessages(message_list); } else { rootView.findViewById(R.id.messageSyncWaiter).setVisibility(View.GONE); rootView.findViewById(R.id.txvMessageAllReadMessage).setVisibility(View.GONE); } // Handling List View controls and keys String[] from = new String[] { "subject|type", "body", "starred", "author_id|email_from", "date", "model|type" }; int[] to = new int[] { R.id.txvMessageSubject, R.id.txvMessageBody, R.id.imgMessageStarred, R.id.txvMessageFrom, R.id.txvMessageDate, R.id.txvMessageTag }; // Creating instance for listAdapter listAdapter = new OEListViewAdapter(scope.context(), R.layout.message_listview_items, list, from, to, db, true, new int[] { R.drawable.message_listview_bg_toread_selector, R.drawable.message_listview_bg_tonotread_selector }, "to_read"); // Telling adapter to clean HTML text for key value listAdapter.cleanHtmlToTextOn("body"); listAdapter.cleanDate("date", scope.User().getTimezone()); // Setting callback handler for boolean field value change. listAdapter.setBooleanEventOperation("starred", R.drawable.ic_action_starred, R.drawable.ic_action_unstarred, updateStarred); listAdapter.addViewListener(new OEListViewOnCreateListener() { @Override public View listViewOnCreateListener(int position, View row_view, OEListViewRows row_data) { String model_name = row_data.getRow_data().get("model").toString(); String model = model_name; String res_id = row_data.getRow_data().get("res_id").toString(); if (model_name.equals("false")) { model_name = capitalizeString(row_data.getRow_data().get("type").toString()); } else { String[] model_parts = TextUtils.split(model_name, "\\."); HashSet unique_parts = new HashSet(Arrays.asList(model_parts)); model_name = capitalizeString(TextUtils.join(" ", unique_parts.toArray())); } TextView msgTag = (TextView) row_view.findViewById(R.id.txvMessageTag); int tag_color = 0; if (message_model_colors.containsKey(model_name)) { tag_color = message_model_colors.get(model_name); } else { tag_color = Color.parseColor(tag_colors[tag_color_count]); message_model_colors.put(model_name, tag_color); tag_color_count++; if (tag_color_count > tag_colors.length) { tag_color_count = 0; } } if (model.equals("mail.group")) { if (UserGroups.group_names.containsKey("group_" + res_id)) { model_name = UserGroups.group_names.get("group_" + res_id); tag_color = UserGroups.menu_color.get("group_" + res_id); } } msgTag.setBackgroundColor(tag_color); msgTag.setText(model_name); TextView txvSubject = (TextView) row_view.findViewById(R.id.txvMessageSubject); TextView txvAuthor = (TextView) row_view.findViewById(R.id.txvMessageFrom); if (row_data.getRow_data().get("to_read").toString().equals("false")) { txvSubject.setTypeface(null, Typeface.NORMAL); txvSubject.setTextColor(Color.BLACK); txvAuthor.setTypeface(null, Typeface.NORMAL); txvAuthor.setTextColor(Color.BLACK); } else { txvSubject.setTypeface(null, Typeface.BOLD); txvSubject.setTextColor(Color.parseColor("#414141")); txvAuthor.setTypeface(null, Typeface.BOLD); txvAuthor.setTextColor(Color.parseColor("#414141")); } return row_view; } }); // Creating instance for listview control lstview = (ListView) rootView.findViewById(R.id.lstMessages); // Providing adapter to listview scope.context().runOnUiThread(new Runnable() { @Override public void run() { lstview.setAdapter(listAdapter); } }); // Setting listview choice mode to multiple model lstview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); // Seeting item long click listern to activate action mode. lstview.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View view, int index, long arg3) { // TODO Auto-generated method stub OEListViewRows data = (OEListViewRows) lstview.getAdapter().getItem(index); Toast.makeText(scope.context(), data.getRow_id() + " id clicked", Toast.LENGTH_LONG).show(); view.setSelected(true); if (mActionMode != null) { return false; } // Start the CAB using the ActionMode.Callback defined above mActionMode = scope.context().startActionMode(mActionModeCallback); selectedCounter++; view.setBackgroundResource(R.drawable.listitem_pressed); // lstview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); return true; } }); // Setting multi choice selection listener lstview.setMultiChoiceModeListener(new MultiChoiceModeListener() { HashMap<Integer, Boolean> selectedList = new HashMap<Integer, Boolean>(); @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { // Here you can do something when items are // selected/de-selected, // such as update the title in the CAB selectedList.put(position, checked); if (checked) { selectedCounter++; } else { selectedCounter--; } if (selectedCounter != 0) { mode.setTitle(selectedCounter + ""); } } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { // Respond to clicks on the actions in the CAB HashMap<Integer, Integer> msg_pos = new HashMap<Integer, Integer>(); OEDialog dialog = null; switch (item.getItemId()) { case R.id.menu_message_mark_unread_selected: Log.e("menu_message_context", "Mark as Unread"); for (int pos : selectedList.keySet()) { msg_pos.put(list.get(pos).getRow_id(), pos); } readunreadoperation = new PerformReadUnreadArchiveOperation(msg_pos, false); readunreadoperation.execute((Void) null); mode.finish(); return true; case R.id.menu_message_mark_read_selected: Log.e("menu_message_context", "Mark as Read"); for (int pos : selectedList.keySet()) { msg_pos.put(list.get(pos).getRow_id(), pos); } readunreadoperation = new PerformReadUnreadArchiveOperation(msg_pos, true); readunreadoperation.execute((Void) null); mode.finish(); return true; case R.id.menu_message_more_move_to_archive_selected: Log.e("menu_message_context", "Archive"); for (int pos : selectedList.keySet()) { msg_pos.put(list.get(pos).getRow_id(), pos); } readunreadoperation = new PerformReadUnreadArchiveOperation(msg_pos, false); readunreadoperation.execute((Void) null); mode.finish(); return true; case R.id.menu_message_more_add_star_selected: for (int pos : selectedList.keySet()) { msg_pos.put(list.get(pos).getRow_id(), pos); } markasTodoTask = new PerformOperation(msg_pos, true); markasTodoTask.execute((Void) null); mode.finish(); return true; case R.id.menu_message_more_remove_star_selected: for (int pos : selectedList.keySet()) { msg_pos.put(list.get(pos).getRow_id(), pos); } markasTodoTask = new PerformOperation(msg_pos, false); markasTodoTask.execute((Void) null); mode.finish(); return true; default: return false; } } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { // Inflate the menu for the CAB MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.menu_fragment_message_context, menu); return true; } @Override public void onDestroyActionMode(ActionMode mode) { // Here you can make any necessary updates to the activity when // the CAB is removed. By default, selected items are // deselected/unchecked. /* * Perform Operation on Selected Ids. * * row_ids are list of selected message Ids. */ selectedList.clear(); selectedCounter = 0; lstview.clearChoices(); } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { // Here you can perform updates to the CAB due to // an invalidate() request return false; } }); lstview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View view, int index, long id) { // TODO Auto-generated method stub MessageDetail messageDetail = new MessageDetail(); Bundle bundle = new Bundle(); bundle.putInt("message_id", list.get(index).getRow_id()); bundle.putInt("position", index); messageDetail.setArguments(bundle); scope.context().fragmentHandler.setBackStack(true, null); scope.context().fragmentHandler.replaceFragmnet(messageDetail); if (!type.equals("archive")) { list.remove(index); } listAdapter.refresh(list); } }); // Getting Pull To Refresh Attacher from Main Activity mPullToRefreshAttacher = scope.context().getPullToRefreshAttacher(); // Set the Refreshable View to be the ListView and the refresh listener // to be this. if (mPullToRefreshAttacher != null & lstview != null) { mPullToRefreshAttacher.setRefreshableView(lstview, this); } }
From source file:comp3111h.anytaxi.driver.Register_FormFragment.java
private String nameBeautifier(String name) { String[] partialNames = TextUtils.split(name.trim().toUpperCase(Locale.getDefault()), " +"); for (int i = 0; i < partialNames.length; i++) partialNames[i] = partialNames[i].charAt(0) + partialNames[i].substring(1).toLowerCase(Locale.getDefault()); name = TextUtils.join(" ", partialNames); return name;/* w w w .j a v a 2 s. c om*/ }
From source file:com.example.android.apprestrictionenforcer.AppRestrictionEnforcerFragment.java
/** * Loads the restrictions for the AppRestrictionSchema sample. * * @param activity The activity/* www . j a v a 2 s . c om*/ */ private void loadRestrictions(Activity activity) { RestrictionsManager manager = (RestrictionsManager) activity.getSystemService(Context.RESTRICTIONS_SERVICE); List<RestrictionEntry> restrictions = manager .getManifestRestrictions(Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA); SharedPreferences prefs = activity.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE); for (RestrictionEntry restriction : restrictions) { String key = restriction.getKey(); if (RESTRICTION_KEY_SAY_HELLO.equals(key)) { updateCanSayHello(prefs.getBoolean(RESTRICTION_KEY_SAY_HELLO, restriction.getSelectedState())); } else if (RESTRICTION_KEY_MESSAGE.equals(key)) { updateMessage(prefs.getString(RESTRICTION_KEY_MESSAGE, restriction.getSelectedString())); } else if (RESTRICTION_KEY_NUMBER.equals(key)) { updateNumber(prefs.getInt(RESTRICTION_KEY_NUMBER, restriction.getIntValue())); } else if (RESTRICTION_KEY_RANK.equals(key)) { updateRank(activity, restriction.getChoiceValues(), prefs.getString(RESTRICTION_KEY_RANK, restriction.getSelectedString())); } else if (RESTRICTION_KEY_APPROVALS.equals(key)) { updateApprovals(activity, restriction.getChoiceValues(), TextUtils.split( prefs.getString(RESTRICTION_KEY_APPROVALS, TextUtils.join(DELIMETER, restriction.getAllSelectedStrings())), DELIMETER)); } else if (BUNDLE_SUPPORTED && RESTRICTION_KEY_ITEMS.equals(key)) { String itemsString = prefs.getString(RESTRICTION_KEY_ITEMS, ""); HashMap<String, String> items = new HashMap<>(); for (String itemString : TextUtils.split(itemsString, DELIMETER)) { String[] strings = itemString.split(SEPARATOR, 2); items.put(strings[0], strings[1]); } updateItems(activity, items); } } }
From source file:com.microsoft.services.msa.AuthorizationRequest.java
/** * Turns the fragment parameters of the uri into a map. * * @param uri to get fragment parameters from * @return a map containing the fragment parameters */// w ww . ja v a 2s . c o m private static Map<String, String> getFragmentParametersMap(Uri uri) { String fragment = uri.getFragment(); String[] keyValuePairs = TextUtils.split(fragment, AMPERSAND); Map<String, String> fragementParameters = new HashMap<String, String>(); for (String keyValuePair : keyValuePairs) { int index = keyValuePair.indexOf(EQUALS); String key = keyValuePair.substring(0, index); String value = keyValuePair.substring(index + 1); fragementParameters.put(key, value); } return fragementParameters; }
From source file:dev.drsoran.moloko.fragments.AbstractTaskEditFragment.java
public List<String> getTags() { return Arrays.asList(TextUtils.split(getCurrentValue(Tasks.TAGS, String.class), Tasks.TAGS_SEPARATOR)); }
From source file:com.df.push.DemoActivity.java
private void readSubscriptions() { final SharedPreferences prefs = getGcmPreferences(context); String serialized = prefs.getString(PROPERTY_SUB, null); if (serialized != null) subscriptions = Arrays.asList(TextUtils.split(serialized, ",")); }
From source file:com.csipsimple.utils.PreferencesWrapper.java
public String[] getCodecList() { return TextUtils.split(prefs.getString(CODECS_LIST, ""), Pattern.quote(CODECS_SEPARATOR)); }
From source file:com.microsoft.services.msa.LiveAuthClient.java
private List<String> getCookieKeysFromPreferences() { SharedPreferences settings = getSharedPreferences(); String cookieKeys = settings.getString(PreferencesConstants.COOKIES_KEY, ""); return Arrays.asList(TextUtils.split(cookieKeys, PreferencesConstants.COOKIE_DELIMITER)); }