List of usage examples for android.text TextUtils split
public static String[] split(String text, Pattern pattern)
From source file:org.adblockplus.android.CrashReportDialog.java
public void onOk(View v) { String comment = ((EditText) findViewById(R.id.comments)).getText().toString(); try {//w ww .j a v a2 s . com String[] reportLines = report.split(System.getProperty("line.separator")); int api = Integer.parseInt(reportLines[0]); int build = Integer.parseInt(reportLines[1]); XmlSerializer xmlSerializer = Xml.newSerializer(); StringWriter writer = new StringWriter(); xmlSerializer.setOutput(writer); xmlSerializer.startDocument("UTF-8", true); xmlSerializer.startTag("", "crashreport"); xmlSerializer.attribute("", "version", "1"); xmlSerializer.attribute("", "api", String.valueOf(api)); xmlSerializer.attribute("", "build", String.valueOf(build)); xmlSerializer.startTag("", "error"); xmlSerializer.attribute("", "type", reportLines[2]); xmlSerializer.startTag("", "message"); xmlSerializer.text(reportLines[3]); xmlSerializer.endTag("", "message"); xmlSerializer.startTag("", "stacktrace"); Pattern p = Pattern.compile("\\|"); boolean hasCause = false; int i = 4; while (i < reportLines.length) { if ("cause".equals(reportLines[i])) { xmlSerializer.endTag("", "stacktrace"); xmlSerializer.startTag("", "cause"); hasCause = true; i++; xmlSerializer.attribute("", "type", reportLines[i]); i++; xmlSerializer.startTag("", "message"); xmlSerializer.text(reportLines[i]); i++; xmlSerializer.endTag("", "message"); xmlSerializer.startTag("", "stacktrace"); continue; } Log.e(TAG, "Line: " + reportLines[i]); String[] element = TextUtils.split(reportLines[i], p); xmlSerializer.startTag("", "frame"); xmlSerializer.attribute("", "class", element[0]); xmlSerializer.attribute("", "method", element[1]); xmlSerializer.attribute("", "isnative", element[2]); xmlSerializer.attribute("", "file", element[3]); xmlSerializer.attribute("", "line", element[4]); xmlSerializer.endTag("", "frame"); i++; } xmlSerializer.endTag("", "stacktrace"); if (hasCause) xmlSerializer.endTag("", "cause"); xmlSerializer.endTag("", "error"); xmlSerializer.startTag("", "comment"); xmlSerializer.text(comment); xmlSerializer.endTag("", "comment"); xmlSerializer.endTag("", "crashreport"); xmlSerializer.endDocument(); String xml = writer.toString(); HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(getString(R.string.crash_report_url)); httppost.setHeader("Content-Type", "text/xml; charset=UTF-8"); httppost.addHeader("X-Adblock-Plus", "yes"); httppost.setEntity(new StringEntity(xml)); HttpResponse httpresponse = httpclient.execute(httppost); StatusLine statusLine = httpresponse.getStatusLine(); Log.e(TAG, statusLine.getStatusCode() + " " + statusLine.getReasonPhrase()); Log.e(TAG, EntityUtils.toString(httpresponse.getEntity())); if (statusLine.getStatusCode() != 200) throw new ClientProtocolException(); String response = EntityUtils.toString(httpresponse.getEntity()); if (!"saved".equals(response)) throw new ClientProtocolException(); deleteFile(CrashHandler.REPORT_FILE); } catch (ClientProtocolException e) { Log.e(TAG, "Failed to submit a crash", e); Toast.makeText(this, R.string.msg_crash_submission_failure, Toast.LENGTH_LONG).show(); } catch (IOException e) { Log.e(TAG, "Failed to submit a crash", e); Toast.makeText(this, R.string.msg_crash_submission_failure, Toast.LENGTH_LONG).show(); } catch (Exception e) { Log.e(TAG, "Failed to create report", e); // Assuming corrupted report file, just silently deleting it deleteFile(CrashHandler.REPORT_FILE); } finish(); }
From source file:org.changhong.Note.java
public void removeTag(String tag) { String[] taga = TextUtils.split(this.tags, ","); String newTags = ""; for (String atag : taga) { if (!atag.equals(tag)) newTags += atag;//w ww .ja va 2 s . co m } this.tags = newTags; }
From source file:net.kjmaster.cookiemom.settings.SettingsActivity.java
@Override public void onBackPressed() { if (!iSettings.CookieList().get().equals(cookieList)) { iSettings.CookieList().put(cookieList); Intent data = getIntent();/*from www. j a v a2s .co m*/ data.putExtra("cookie_list", cookieList); Constants.updateCookieTypes(TextUtils.split(cookieList, ",")); setResult(Constants.SETTINGS_RESULT_DIRTY, data); } finish(); }
From source file:net.kjmaster.cookiemom.settings.SettingsFragment.java
public void fillCookieList(String cookieList) { ArrayList<String> arrayList = new ArrayList<String>(); Collections.addAll(arrayList, TextUtils.split(cookieList, ",")); SpinnerAdapter spinnerAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item, arrayList); settings_edit_cookie.setText(""); setting_cookie_list.setAdapter(spinnerAdapter); setting_cookie_list.requestLayout(); }
From source file:de.fmaul.android.cmis.utils.FeedUtils.java
public static String getSearchQueryFeedFullText(String urlTemplate, String query) { String[] words = TextUtils.split(query.trim(), "\\s+"); for (int i = 0; i < words.length; i++) { words[i] = "contains ('" + words[i] + "')"; }//w ww . j a v a 2 s .co m String condition = TextUtils.join(" AND ", words); return getSearchQueryFeedCmisQuery(urlTemplate, "SELECT * FROM cmis:document WHERE " + condition); }
From source file:tw.idv.palatis.danboorugallery.siteapi.GelbooruAPI.java
private Post parseXMLElementToPost(Host host, Element item) { if (item == null) return null; String file_url = item.getAttribute(GelbooruPost.KEY_POST_FILE_URL); String file_url_large = item.getAttribute(GelbooruPost.KEY_POST_LARGE_FILE_URL); String file_url_preview = item.getAttribute(GelbooruPost.KEY_POST_PREVIEW_FILE_URL); if (!file_url.startsWith("http")) file_url = host.url + file_url;//from w w w. java 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; Date date; try { date = sDateFormat.parse(item.getAttribute(GelbooruPost.KEY_POST_CREATED_AT)); } catch (ParseException e) { date = new Date(0); } return new GelbooruPost(host, ParseUtils.parseInt(item.getAttribute(GelbooruPost.KEY_POST_ID)), ParseUtils.parseInt(item.getAttribute(GelbooruPost.KEY_POST_IMAGE_WIDTH), -1), ParseUtils.parseInt(item.getAttribute(GelbooruPost.KEY_POST_IMAGE_HEIGHT), -1), date, date, 0, // no file size file_url, file_url_large, file_url_preview, TextUtils.split(item.getAttribute(GelbooruPost.KEY_POST_TAG_STRING).trim(), " "), item.getAttribute(GelbooruPost.KEY_POST_RATING), item.getAttribute(GelbooruPost.KEY_POST_MD5), ParseUtils.parseInt(item.getAttribute(GelbooruPost.KEY_POST_UPLOADER_ID)), ParseUtils.parseInt(item.getAttribute(GelbooruPost.KEY_POST_SCORE))); }
From source file:tw.idv.palatis.danboorugallery.siteapi.ShimmieAPI.java
private Post parseXMLElementToPost(Host host, Element item) { if (item == null) return null; String file_url = item.getAttribute(ShimmiePost.KEY_POST_FILE_URL); String file_url_preview = item.getAttribute(ShimmiePost.KEY_POST_PREVIEW_FILE_URL); if (!file_url.startsWith("http")) file_url = host.url + file_url;/*from www . ja v a2s . co m*/ if (!file_url_preview.startsWith("http")) file_url_preview = host.url + file_url_preview; Date date; try { date = sDateFormat.parse(item.getAttribute(ShimmiePost.KEY_POST_CREATED_AT)); } catch (ParseException e) { date = new Date(0); } return new ShimmiePost(host, ParseUtils.parseInt(item.getAttribute(ShimmiePost.KEY_POST_ID)), ParseUtils.parseInt(item.getAttribute(ShimmiePost.KEY_POST_IMAGE_WIDTH), -1), ParseUtils.parseInt(item.getAttribute(ShimmiePost.KEY_POST_IMAGE_HEIGHT), -1), date, date, -1, // no file size file_url, file_url, file_url_preview, TextUtils.split(item.getAttribute(ShimmiePost.KEY_POST_TAG_STRING).trim(), " "), "e", // item.getAttribute(ShimmiePost.KEY_POST_RATING), // rating always "u"... we don't recognize that. item.getAttribute(ShimmiePost.KEY_POST_MD5), item.getAttribute(ShimmiePost.KEY_POST_UPLOADER_NAME), ParseUtils.parseInt(item.getAttribute(ShimmiePost.KEY_POST_SCORE))); }
From source file:net.bither.preference.PersistentCookieStore.java
@SuppressLint("InlinedApi") public void reload() { // Load any previously stored cookies into the store this.cookiePrefs = BitherApplication.mContext.getSharedPreferences(COOKIE_PREFS, Context.MODE_MULTI_PROCESS); cookies = new ConcurrentHashMap<String, Cookie>(); String storedCookieNames = this.cookiePrefs.getString(COOKIE_NAME_STORE, null); if (storedCookieNames != null) { String[] cookieNames = TextUtils.split(storedCookieNames, ","); for (String name : cookieNames) { String encodedCookie = this.cookiePrefs.getString(COOKIE_NAME_PREFIX + name, null); if (encodedCookie != null) { Cookie decodedCookie = decodeCookie(encodedCookie); if (decodedCookie != null) { cookies.put(name, decodedCookie); }//from w ww. j a v a 2s. c o m } } // Clear out expired cookies clearExpired(new Date()); } }
From source file:tw.idv.palatis.danboorugallery.siteapi.MoebooruAPI.java
public static Post parseJSONObjectToPost(Host host, JSONObject json) throws JSONException, ParseException { if (json == null) return null; String file_url = json.getString(MoebooruPost.KEY_POST_FILE_URL); String file_url_large = json.getString(MoebooruPost.KEY_POST_LARGE_FILE_URL); String file_url_preview = json.getString(MoebooruPost.KEY_POST_PREVIEW_FILE_URL); if (!file_url.startsWith("http")) file_url = host.url + file_url;//from www .j a v a2 s .c o 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; int uploader_id = -1; String uploader_name = ""; try { uploader_id = json.getInt(MoebooruPost.KEY_POST_UPLOADER_ID); } catch (JSONException ignored) { } try { uploader_name = json.getString(MoebooruPost.KEY_POST_UPLOADER_NAME); } catch (JSONException ignored) { } Date date = new Date(json.getLong(MoebooruPost.KEY_POST_CREATED_AT) * 1000); return new MoebooruPost(host, json.getInt(MoebooruPost.KEY_POST_ID), json.getInt(MoebooruPost.KEY_POST_IMAGE_WIDTH), json.getInt(MoebooruPost.KEY_POST_IMAGE_HEIGHT), date, date, json.getInt(MoebooruPost.KEY_POST_FILE_SIZE), file_url, file_url_large, file_url_preview, TextUtils.split(json.getString(MoebooruPost.KEY_POST_TAG_STRING), " "), json.getString(MoebooruPost.KEY_POST_RATING), uploader_id, uploader_name, json.getString(MoebooruPost.KEY_POST_MD5), json.getInt(MoebooruPost.KEY_POST_SCORE)); }
From source file:tw.idv.palatis.danboorugallery.siteapi.DanbooruAPI.java
public static Post parseJSONObjectToPost(Host host, JSONObject json) throws JSONException, ParseException { if (json == null) return null; String file_url = json.getString(DanbooruPost.KEY_POST_FILE_URL); String file_url_large = json.getString(DanbooruPost.KEY_POST_LARGE_FILE_URL); String file_url_preview = json.getString(DanbooruPost.KEY_POST_PREVIEW_FILE_URL); if (!file_url.startsWith("http")) file_url = host.url + file_url;/*from w w w .ja v a 2 s.com*/ 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; int uploader_id = -1; String uploader_name = ""; try { uploader_id = json.getInt(DanbooruPost.KEY_POST_UPLOADER_ID); } catch (JSONException ignored) { } try { uploader_name = json.getString(DanbooruPost.KEY_POST_UPLOADER_NAME); } catch (JSONException ignored) { } return new DanbooruPost(host, json.getInt(DanbooruPost.KEY_POST_ID), json.getInt(DanbooruPost.KEY_POST_IMAGE_WIDTH), json.getInt(DanbooruPost.KEY_POST_IMAGE_HEIGHT), sDateFormat.parse(json.getString(DanbooruPost.KEY_POST_CREATED_AT)), sDateFormat.parse(json.getString(DanbooruPost.KEY_POST_UPDATED_AT)), json.getInt(DanbooruPost.KEY_POST_FILE_SIZE), file_url, file_url_large, file_url_preview, TextUtils.split(json.getString(DanbooruPost.KEY_POST_TAG_STRING), " "), json.getString(DanbooruPost.KEY_POST_RATING), uploader_id, uploader_name, json.getString(DanbooruPost.KEY_POST_MD5), json.getString(DanbooruPost.KEY_POST_FILE_EXT), json.getInt(DanbooruPost.KEY_POST_SCORE), Math.abs(json.getInt(DanbooruPost.KEY_POST_UP_SCORE)), Math.abs(json.getInt(DanbooruPost.KEY_POST_DOWN_SCORE))); }