1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

Restructure the code a bit

This commit is contained in:
cketti 2015-04-04 00:55:53 +02:00
parent 8bcf9b1d50
commit 09babb6e88

View File

@ -53,21 +53,30 @@ public abstract class K9WebViewClient extends WebViewClient {
@Override @Override
public boolean shouldOverrideUrlLoading(WebView webView, String url) { public boolean shouldOverrideUrlLoading(WebView webView, String url) {
Context context = webView.getContext();
Uri uri = Uri.parse(url); Uri uri = Uri.parse(url);
if (!CID_SCHEME.equals(uri.getScheme())) { if (CID_SCHEME.equals(uri.getScheme())) {
Intent intent = new Intent(Intent.ACTION_VIEW, uri); return false;
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
try {
context.startActivity(intent);
return true;
} catch (ActivityNotFoundException ex) {
// If no application can handle the URL, assume that the
// WebView can handle it.
}
} }
return false;
Context context = webView.getContext();
Intent intent = createBrowserViewIntent(uri, context);
boolean overridingUrlLoading = false;
try {
context.startActivity(intent);
overridingUrlLoading = true;
} catch (ActivityNotFoundException ex) {
// If no application can handle the URL, assume that the WebView can handle it.
}
return overridingUrlLoading;
}
private Intent createBrowserViewIntent(Uri uri, Context context) {
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
return intent;
} }
protected WebResourceResponse shouldInterceptRequest(WebView webView, Uri uri) { protected WebResourceResponse shouldInterceptRequest(WebView webView, Uri uri) {