Merge "Catch OperationUnsupportedException when linkifying using WebView" into klp-modular-dev
This commit is contained in:
@@ -465,32 +465,39 @@ public class Linkify {
|
|||||||
String address;
|
String address;
|
||||||
int base = 0;
|
int base = 0;
|
||||||
|
|
||||||
while ((address = WebView.findAddress(string)) != null) {
|
try {
|
||||||
int start = string.indexOf(address);
|
while ((address = WebView.findAddress(string)) != null) {
|
||||||
|
int start = string.indexOf(address);
|
||||||
|
|
||||||
if (start < 0) {
|
if (start < 0) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
LinkSpec spec = new LinkSpec();
|
||||||
|
int length = address.length();
|
||||||
|
int end = start + length;
|
||||||
|
|
||||||
|
spec.start = base + start;
|
||||||
|
spec.end = base + end;
|
||||||
|
string = string.substring(end);
|
||||||
|
base += end;
|
||||||
|
|
||||||
|
String encodedAddress = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
encodedAddress = URLEncoder.encode(address,"UTF-8");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
spec.url = "geo:0,0?q=" + encodedAddress;
|
||||||
|
links.add(spec);
|
||||||
}
|
}
|
||||||
|
} catch (UnsupportedOperationException e) {
|
||||||
LinkSpec spec = new LinkSpec();
|
// findAddress may fail with an unsupported exception on platforms without a WebView.
|
||||||
int length = address.length();
|
// In this case, we will not append anything to the links variable: it would have died
|
||||||
int end = start + length;
|
// in WebView.findAddress.
|
||||||
|
return;
|
||||||
spec.start = base + start;
|
|
||||||
spec.end = base + end;
|
|
||||||
string = string.substring(end);
|
|
||||||
base += end;
|
|
||||||
|
|
||||||
String encodedAddress = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
encodedAddress = URLEncoder.encode(address,"UTF-8");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
spec.url = "geo:0,0?q=" + encodedAddress;
|
|
||||||
links.add(spec);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user