Back to project page Sharinger.
The source code is released under:
Apache License
If you think the Android project Sharinger listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package mobi.tarantio.tools.sharinger.app; // w ww . j a v a2 s . c o m import android.content.Intent; import java.util.regex.Matcher; import java.util.regex.Pattern; import static android.content.Intent.EXTRA_SUBJECT; import static android.content.Intent.EXTRA_TEXT; /** * Created by kolipass on 23.02.14. */ public class IntentHandler { private String divider = " "; public IntentHandler() { } public IntentHandler(String divider) { this.divider = divider; } public String handleSendText(Intent intent, boolean whithoutBrackets) { String sharedBodyText = intent.getStringExtra(EXTRA_TEXT); String sharedTitleText = intent.getStringExtra(EXTRA_SUBJECT); String rawText = ""; if (sharedBodyText != null || sharedTitleText != null) { String title = sharedTitleText != null && sharedBodyText != null && !sharedBodyText.contains(sharedTitleText) ? sharedTitleText : null; String body = sharedBodyText != null ? sharedBodyText : null; body = whithoutBrackets ? clearBracketsCloseUrl(body) : checkBracketsCloseUrl(body); rawText = title != null ? title : ""; if (rawText.length() > 0) { rawText += divider; } rawText += body != null ? body : ""; } return rawText; } /** * ????? ????? ???? ??????????? ??????? ????? ??????????? ???????? * * @param body ?????? ??????????? * @return ?????? ?????????? body */ public String checkBracketsCloseUrl(String body) { String regex = "\\(?\\b(http://|www[.])[-A-Za-z0-9+&@#/%?=~_()|!:,.;]*[-A-Za-z0-9+&@#/%=~_()|]"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(body); while (m.find()) { String urlStr = m.group(); if (urlStr.startsWith("(") && urlStr.endsWith(")")) { String urlWithoutBrackets = urlStr.substring(1, urlStr.length() - 1); body = body.replace(urlWithoutBrackets, addDivider(urlWithoutBrackets)); } } return body; } /** * ????? ????? ???? ????????? ??????? ?????? url * * @param body ?????? ??????????? * @return ?????? ?????????? body */ public String clearBracketsCloseUrl(String body) { String regex = "\\(?\\b(http://|www[.])[-A-Za-z0-9+&@#/%?=~_()|!:,.;]*[-A-Za-z0-9+&@#/%=~_()|]"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(body); while (m.find()) { String urlStr = m.group(); if (urlStr.startsWith("(") && urlStr.endsWith(")")) { String urlWithoutBrackets = urlStr.substring(1, urlStr.length() - 1); body = body.replace(urlStr, urlWithoutBrackets); } } return body; } private String addDivider(String body) { return divider + body + divider; } }