diff options
author | Brint E. Kriebel <bekit@cyngn.com> | 2014-05-08 18:21:48 -0700 |
---|---|---|
committer | Brint E. Kriebel <bekit@cyngn.com> | 2014-05-08 18:21:48 -0700 |
commit | 66b6af8c7dab5cb9b70127d1653ece0d9cfbe5b5 (patch) | |
tree | 6b5099eeecd23a1f963f110ee25d166e8fa7e0fb | |
parent | d07299b321c4b7f82b5aaaae6e5e4bf44336c2d8 (diff) | |
parent | 50e3c5aa849d94b5ba24c676554f416343b57efd (diff) | |
download | android_packages_apps_Bluetooth-66b6af8c7dab5cb9b70127d1653ece0d9cfbe5b5.tar.gz android_packages_apps_Bluetooth-66b6af8c7dab5cb9b70127d1653ece0d9cfbe5b5.tar.bz2 android_packages_apps_Bluetooth-66b6af8c7dab5cb9b70127d1653ece0d9cfbe5b5.zip |
Merge remote-tracking branch 'github/cm-11.0' into HEAD
-rw-r--r-- | src/com/android/bluetooth/map/BluetoothMapContentObserver.java | 27 | ||||
-rw-r--r-- | src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java | 106 |
2 files changed, 120 insertions, 13 deletions
diff --git a/src/com/android/bluetooth/map/BluetoothMapContentObserver.java b/src/com/android/bluetooth/map/BluetoothMapContentObserver.java index 052188e66..12203a13f 100644 --- a/src/com/android/bluetooth/map/BluetoothMapContentObserver.java +++ b/src/com/android/bluetooth/map/BluetoothMapContentObserver.java @@ -409,6 +409,13 @@ public class BluetoothMapContentObserver { mMsgListMms = msgListMms; } + private String getFolderName(String[] names, int folderTypeId) { + if (folderTypeId < names.length) { + return names[folderTypeId]; + } + return "unknown"; + } + private void handleMsgListChangesSms() { if (V) Log.d(TAG, "handleMsgListChangesSms"); @@ -430,7 +437,7 @@ public class BluetoothMapContentObserver { msg = new Msg(id, type); msgListSms.put(id, msg); - if (folderSms[type].equals("inbox")) { + if (type == Sms.MESSAGE_TYPE_INBOX) { Event evt = new Event("NewMessage", id, folderSms[type], null, mSmsType); sendEvent(evt); @@ -438,9 +445,11 @@ public class BluetoothMapContentObserver { } else { /* Existing message */ if (type != msg.type) { + String newFolder = getFolderName(folderSms,type); + String oldFolder = getFolderName(folderSms,msg.type); Log.d(TAG, "new type: " + type + " old type: " + msg.type); - Event evt = new Event("MessageShift", id, folderSms[type], - folderSms[msg.type], mSmsType); + Event evt = new Event("MessageShift", id, newFolder, + oldFolder, mSmsType); sendEvent(evt); msg.type = type; } @@ -479,7 +488,7 @@ public class BluetoothMapContentObserver { if (msg == null) { /* New message - only notify on retrieve conf */ - if (folderMms[type].equals("inbox") && + if (type == Mms.MESSAGE_BOX_INBOX && mtype != MESSAGE_TYPE_RETRIEVE_CONF) { continue; } @@ -487,7 +496,7 @@ public class BluetoothMapContentObserver { msg = new Msg(id, type); msgListMms.put(id, msg); - if (folderMms[type].equals("inbox")) { + if (type == Mms.MESSAGE_BOX_INBOX) { Event evt = new Event("NewMessage", id, folderMms[type], null, TYPE.MMS); sendEvent(evt); @@ -495,13 +504,15 @@ public class BluetoothMapContentObserver { } else { /* Existing message */ if (type != msg.type) { + String newFolder = getFolderName(folderMms,type); + String oldFolder = getFolderName(folderMms,msg.type); Log.d(TAG, "new type: " + type + " old type: " + msg.type); - Event evt = new Event("MessageShift", id, folderMms[type], - folderMms[msg.type], TYPE.MMS); + Event evt = new Event("MessageShift", id, newFolder, + oldFolder, TYPE.MMS); sendEvent(evt); msg.type = type; - if (folderMms[type].equals("sent")) { + if (type == Mms.MESSAGE_BOX_SENT) { evt = new Event("SendingSuccess", id, folderSms[type], null, TYPE.MMS); sendEvent(evt); diff --git a/src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java b/src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java index e63d67cb1..39116a0d3 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java +++ b/src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java @@ -51,6 +51,11 @@ import android.os.Bundle; import android.util.Log; import android.provider.Settings; +import android.util.Patterns; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.Locale; + /** * This class is designed to act as the entry point of handling the share intent * via BT from other APPs. and also make "Bluetooth" available in sharing method @@ -61,6 +66,10 @@ public class BluetoothOppLauncherActivity extends Activity { private static final boolean D = Constants.DEBUG; private static final boolean V = Constants.VERBOSE; + // Regex that matches characters that have special meaning in HTML. '<', '>', '&' and + // multiple continuous spaces. + private static final Pattern PLAIN_TEXT_TO_ESCAPE = Pattern.compile("[<>&]| {2,}|\r?\n"); + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -250,11 +259,58 @@ public class BluetoothOppLauncherActivity extends Activity { String fileName = getString(R.string.bluetooth_share_file_name) + ".html"; context.deleteFile(fileName); - String uri = shareContent.toString(); - String content = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;" - + " charset=UTF-8\"/></head><body>" + "<a href=\"" + uri + "\">" + uri + "</a></p>" - + "</body></html>"; - byte[] byteBuff = content.getBytes(); + /* + * Convert the plain text to HTML + */ + StringBuffer sb = new StringBuffer("<html><head><meta http-equiv=\"Content-Type\"" + + " content=\"text/html; charset=UTF-8\"/></head><body>"); + // Escape any inadvertent HTML in the text message + String text = escapeCharacterToDisplay(shareContent.toString()); + + // Regex that matches Web URL protocol part as case insensitive. + Pattern webUrlProtocol = Pattern.compile("(?i)(http|https)://"); + + Pattern pattern = Pattern.compile("(" + + Patterns.WEB_URL.pattern() + ")|(" + + Patterns.EMAIL_ADDRESS.pattern() + ")|(" + + Patterns.PHONE.pattern() + ")"); + // Find any embedded URL's and linkify + Matcher m = pattern.matcher(text); + while (m.find()) { + String matchStr = m.group(); + String link = null; + + // Find any embedded URL's and linkify + if (Patterns.WEB_URL.matcher(matchStr).matches()) { + Matcher proto = webUrlProtocol.matcher(matchStr); + if (proto.find()) { + // This is work around to force URL protocol part be lower case, + // because WebView could follow only lower case protocol link. + link = proto.group().toLowerCase(Locale.US) + + matchStr.substring(proto.end()); + } else { + // Patterns.WEB_URL matches URL without protocol part, + // so added default protocol to link. + link = "http://" + matchStr; + } + + // Find any embedded email address + } else if (Patterns.EMAIL_ADDRESS.matcher(matchStr).matches()) { + link = "mailto:" + matchStr; + + // Find any embedded phone numbers and linkify + } else if (Patterns.PHONE.matcher(matchStr).matches()) { + link = "tel:" + matchStr; + } + if (link != null) { + String href = String.format("<a href=\"%s\">%s</a>", link, matchStr); + m.appendReplacement(sb, href); + } + } + m.appendTail(sb); + sb.append("</body></html>"); + + byte[] byteBuff = sb.toString().getBytes(); outStream = context.openFileOutput(fileName, Context.MODE_PRIVATE); if (outStream != null) { @@ -283,4 +339,44 @@ public class BluetoothOppLauncherActivity extends Activity { } return fileUri; } + + /** + * Escape some special character as HTML escape sequence. + * + * @param text Text to be displayed using WebView. + * @return Text correctly escaped. + */ + private static String escapeCharacterToDisplay(String text) { + Pattern pattern = PLAIN_TEXT_TO_ESCAPE; + Matcher match = pattern.matcher(text); + + if (match.find()) { + StringBuilder out = new StringBuilder(); + int end = 0; + do { + int start = match.start(); + out.append(text.substring(end, start)); + end = match.end(); + int c = text.codePointAt(start); + if (c == ' ') { + // Escape successive spaces into series of " ". + for (int i = 1, n = end - start; i < n; ++i) { + out.append(" "); + } + out.append(' '); + } else if (c == '\r' || c == '\n') { + out.append("<br>"); + } else if (c == '<') { + out.append("<"); + } else if (c == '>') { + out.append(">"); + } else if (c == '&') { + out.append("&"); + } + } while (match.find()); + out.append(text.substring(end)); + text = out.toString(); + } + return text; + } } |