From 981279165e655844be490bf6bb94619a65e70f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20Cotta?= Date: Wed, 31 Jul 2019 21:09:25 -0300 Subject: [PATCH 1/6] Update AGP to 3.4.2 and gradle to 5.1.1 --- packages/url_launcher/android/build.gradle | 2 +- packages/url_launcher/example/android/build.gradle | 2 +- .../example/android/gradle/wrapper/gradle-wrapper.properties | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/url_launcher/android/build.gradle b/packages/url_launcher/android/build.gradle index 641b2e29f81a..e2c6ea5af7ae 100644 --- a/packages/url_launcher/android/build.gradle +++ b/packages/url_launcher/android/build.gradle @@ -21,7 +21,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.3.0' + classpath 'com.android.tools.build:gradle:3.4.2' } } diff --git a/packages/url_launcher/example/android/build.gradle b/packages/url_launcher/example/android/build.gradle index 541636cc492a..6b1a639efd76 100644 --- a/packages/url_launcher/example/android/build.gradle +++ b/packages/url_launcher/example/android/build.gradle @@ -5,7 +5,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.3.0' + classpath 'com.android.tools.build:gradle:3.4.2' } } diff --git a/packages/url_launcher/example/android/gradle/wrapper/gradle-wrapper.properties b/packages/url_launcher/example/android/gradle/wrapper/gradle-wrapper.properties index 019065d1d650..1cedb28ea41f 100644 --- a/packages/url_launcher/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/packages/url_launcher/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Wed Jul 31 20:16:04 BRT 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip From 4a4d9989ea2b641e3281c5b1c89b113e776a7c44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20Cotta?= Date: Wed, 31 Jul 2019 21:10:00 -0300 Subject: [PATCH 2/6] Move WebViewActivity to its own class file. --- .../android/src/main/AndroidManifest.xml | 2 +- .../urllauncher/UrlLauncherPlugin.java | 157 ++++-------------- .../plugins/urllauncher/WebViewActivity.java | 123 ++++++++++++++ 3 files changed, 160 insertions(+), 122 deletions(-) create mode 100644 packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java diff --git a/packages/url_launcher/android/src/main/AndroidManifest.xml b/packages/url_launcher/android/src/main/AndroidManifest.xml index 3b455eabc021..f43e5ba2474d 100644 --- a/packages/url_launcher/android/src/main/AndroidManifest.xml +++ b/packages/url_launcher/android/src/main/AndroidManifest.xml @@ -1,7 +1,7 @@ - diff --git a/packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/UrlLauncherPlugin.java b/packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/UrlLauncherPlugin.java index b877a45bdb25..6d0d5052eb0a 100644 --- a/packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/UrlLauncherPlugin.java +++ b/packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/UrlLauncherPlugin.java @@ -4,26 +4,19 @@ package io.flutter.plugins.urllauncher; -import android.app.Activity; -import android.content.BroadcastReceiver; + import android.content.ComponentName; import android.content.Context; import android.content.Intent; -import android.content.IntentFilter; + import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.provider.Browser; -import android.view.KeyEvent; -import android.webkit.WebResourceRequest; -import android.webkit.WebView; -import android.webkit.WebViewClient; import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel.MethodCallHandler; import io.flutter.plugin.common.MethodChannel.Result; import io.flutter.plugin.common.PluginRegistry.Registrar; -import java.util.HashMap; import java.util.Map; /** UrlLauncherPlugin */ @@ -32,7 +25,7 @@ public class UrlLauncherPlugin implements MethodCallHandler { public static void registerWith(Registrar registrar) { MethodChannel channel = - new MethodChannel(registrar.messenger(), "plugins.flutter.io/url_launcher"); + new MethodChannel(registrar.messenger(), "plugins.flutter.io/url_launcher"); UrlLauncherPlugin instance = new UrlLauncherPlugin(registrar); channel.setMethodCallHandler(instance); } @@ -43,15 +36,20 @@ private UrlLauncherPlugin(Registrar registrar) { @Override public void onMethodCall(MethodCall call, Result result) { - String url = call.argument("url"); - if (call.method.equals("canLaunch")) { - canLaunch(url, result); - } else if (call.method.equals("launch")) { - launch(call, result, url); - } else if (call.method.equals("closeWebView")) { - closeWebView(result); - } else { - result.notImplemented(); + final String url = call.argument("url"); + switch (call.method) { + case "canLaunch": + canLaunch(url, result); + break; + case "launch": + launch(call, result, url); + break; + case "closeWebView": + closeWebView(result); + break; + default: + result.notImplemented(); + break; } } @@ -59,12 +57,12 @@ private void canLaunch(String url, Result result) { Intent launchIntent = new Intent(Intent.ACTION_VIEW); launchIntent.setData(Uri.parse(url)); ComponentName componentName = - launchIntent.resolveActivity(mRegistrar.context().getPackageManager()); + launchIntent.resolveActivity(mRegistrar.context().getPackageManager()); boolean canLaunch = - componentName != null - && !"{com.android.fallback/com.android.fallback.Fallback}" - .equals(componentName.toShortString()); + componentName != null + && !"{com.android.fallback/com.android.fallback.Fallback}" + .equals(componentName.toShortString()); result.success(canLaunch); } @@ -74,31 +72,33 @@ private void launch(MethodCall call, Result result, String url) { final boolean enableJavaScript = call.argument("enableJavaScript"); final boolean enableDomStorage = call.argument("enableDomStorage"); final Map headersMap = call.argument("headers"); - final Activity activity = mRegistrar.activity(); + final Bundle headersBundle = extractBundle(headersMap); + final Context context = mRegistrar.activity(); - if (activity == null) { + if (context == null) { result.error("NO_ACTIVITY", "Launching a URL requires a foreground activity.", null); return; } + + if (useWebView) { - launchIntent = new Intent(activity, WebViewActivity.class); - launchIntent.putExtra("url", url); - launchIntent.putExtra("enableJavaScript", enableJavaScript); - launchIntent.putExtra("enableDomStorage", enableDomStorage); + launchIntent = WebViewActivity.createIntent( + context, url, + enableJavaScript, enableDomStorage, + headersBundle + ); } else { - launchIntent = new Intent(Intent.ACTION_VIEW); - launchIntent.setData(Uri.parse(url)); + launchIntent = new Intent(Intent.ACTION_VIEW) + .setData(Uri.parse(url)) + .putExtra(Browser.EXTRA_HEADERS, headersBundle); } - final Bundle headersBundle = extractBundle(headersMap); - launchIntent.putExtra(Browser.EXTRA_HEADERS, headersBundle); - - activity.startActivity(launchIntent); + context.startActivity(launchIntent); result.success(true); } private void closeWebView(Result result) { - Intent intent = new Intent("close"); + Intent intent = new Intent(WebViewActivity.ACTION_CLOSE); mRegistrar.context().sendBroadcast(intent); result.success(null); } @@ -111,89 +111,4 @@ private Bundle extractBundle(Map headersMap) { } return headersBundle; } - - /* Launches WebView activity */ - public static class WebViewActivity extends Activity { - private WebView webview; - private BroadcastReceiver broadcastReceiver; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - webview = new WebView(this); - setContentView(webview); - // Get the Intent that started this activity and extract the string - final Intent intent = getIntent(); - final String url = intent.getStringExtra("url"); - final boolean enableJavaScript = intent.getBooleanExtra("enableJavaScript", false); - final boolean enableDomStorage = intent.getBooleanExtra("enableDomStorage", false); - final Bundle headersBundle = intent.getBundleExtra(Browser.EXTRA_HEADERS); - - final Map headersMap = extractHeaders(headersBundle); - webview.loadUrl(url, headersMap); - - webview.getSettings().setJavaScriptEnabled(enableJavaScript); - webview.getSettings().setDomStorageEnabled(enableDomStorage); - - // Open new urls inside the webview itself. - webview.setWebViewClient( - new WebViewClient() { - - @Override - @SuppressWarnings("deprecation") - public boolean shouldOverrideUrlLoading(WebView view, String url) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - view.loadUrl(url); - return false; - } - return super.shouldOverrideUrlLoading(view, url); - } - - @Override - public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - view.loadUrl(request.getUrl().toString()); - } - return false; - } - }); - - // Set broadcast receiver to handle calls to close the web view - broadcastReceiver = - new BroadcastReceiver() { - @Override - public void onReceive(Context arg0, Intent intent) { - String action = intent.getAction(); - if ("close".equals(action)) { - finish(); - } - } - }; - registerReceiver(broadcastReceiver, new IntentFilter("close")); - } - - private Map extractHeaders(Bundle headersBundle) { - final Map headersMap = new HashMap<>(); - for (String key : headersBundle.keySet()) { - final String value = headersBundle.getString(key); - headersMap.put(key, value); - } - return headersMap; - } - - @Override - protected void onDestroy() { - super.onDestroy(); - unregisterReceiver(broadcastReceiver); - } - - @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK && webview.canGoBack()) { - webview.goBack(); - return true; - } - return super.onKeyDown(keyCode, event); - } - } } diff --git a/packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java b/packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java new file mode 100644 index 000000000000..f5d955ccf202 --- /dev/null +++ b/packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java @@ -0,0 +1,123 @@ +package io.flutter.plugins.urllauncher; + +import android.app.Activity; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.os.Build; +import android.os.Bundle; +import android.provider.Browser; +import android.view.KeyEvent; +import android.webkit.WebResourceRequest; +import android.webkit.WebView; +import android.webkit.WebViewClient; +import java.util.HashMap; +import java.util.Map; + +/* Launches WebView activity */ +public class WebViewActivity extends Activity { + + public static String ACTION_CLOSE = "close action"; + + final private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (ACTION_CLOSE.equals(action)) { + finish(); + } + } + }; + + final private WebViewClient webViewClient = new WebViewClient() { + + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + view.loadUrl(url); + return false; + } + return super.shouldOverrideUrlLoading(view, url); + } + + @Override + public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + view.loadUrl(request.getUrl().toString()); + } + return false; + } + }; + + private WebView webview; + + private IntentFilter closeIntentFilter = new IntentFilter(ACTION_CLOSE); + + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + webview = new WebView(this); + setContentView(webview); + // Get the Intent that started this activity and extract the string + final Intent intent = getIntent(); + final String url = intent.getStringExtra(URL_EXTRA); + final boolean enableJavaScript = intent.getBooleanExtra(ENABLE_JS_EXTRA, false); + final boolean enableDomStorage = intent.getBooleanExtra(ENABLE_DOM_EXTRA, false); + final Bundle headersBundle = intent.getBundleExtra(Browser.EXTRA_HEADERS); + + final Map headersMap = extractHeaders(headersBundle); + webview.loadUrl(url, headersMap); + + webview.getSettings().setJavaScriptEnabled(enableJavaScript); + webview.getSettings().setDomStorageEnabled(enableDomStorage); + + // Open new urls inside the webview itself. + webview.setWebViewClient(webViewClient); + + registerReceiver(broadcastReceiver, closeIntentFilter); + } + + private Map extractHeaders(Bundle headersBundle) { + final Map headersMap = new HashMap<>(); + for (String key : headersBundle.keySet()) { + final String value = headersBundle.getString(key); + headersMap.put(key, value); + } + return headersMap; + } + + @Override + protected void onDestroy() { + super.onDestroy(); + unregisterReceiver(broadcastReceiver); + } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + if (keyCode == KeyEvent.KEYCODE_BACK && webview.canGoBack()) { + webview.goBack(); + return true; + } + return super.onKeyDown(keyCode, event); + } + + private static String URL_EXTRA = "url"; + private static String ENABLE_JS_EXTRA = "enableJavaScript"; + private static String ENABLE_DOM_EXTRA = "enableDomStorage"; + + /* Hides the constants used to forward data to the Activity instance. */ + public static Intent createIntent(Context context, + String url, + boolean enableJavaScript, + boolean enableDomStorage, + Bundle headersBundle + ) { + return new Intent(context, WebViewActivity.class) + .putExtra(URL_EXTRA, url) + .putExtra(ENABLE_JS_EXTRA, enableJavaScript) + .putExtra(ENABLE_DOM_EXTRA, enableDomStorage) + .putExtra(Browser.EXTRA_HEADERS, headersBundle); + } +} \ No newline at end of file From 5015e08528448873839205b8e0648bbdcdf59366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20Cotta?= Date: Wed, 31 Jul 2019 21:18:02 -0300 Subject: [PATCH 3/6] fix formatting --- .../urllauncher/UrlLauncherPlugin.java | 28 +++---- .../plugins/urllauncher/WebViewActivity.java | 83 ++++++++++--------- 2 files changed, 54 insertions(+), 57 deletions(-) diff --git a/packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/UrlLauncherPlugin.java b/packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/UrlLauncherPlugin.java index 6d0d5052eb0a..b2b0eb906952 100644 --- a/packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/UrlLauncherPlugin.java +++ b/packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/UrlLauncherPlugin.java @@ -4,11 +4,9 @@ package io.flutter.plugins.urllauncher; - import android.content.ComponentName; import android.content.Context; import android.content.Intent; - import android.net.Uri; import android.os.Bundle; import android.provider.Browser; @@ -25,7 +23,7 @@ public class UrlLauncherPlugin implements MethodCallHandler { public static void registerWith(Registrar registrar) { MethodChannel channel = - new MethodChannel(registrar.messenger(), "plugins.flutter.io/url_launcher"); + new MethodChannel(registrar.messenger(), "plugins.flutter.io/url_launcher"); UrlLauncherPlugin instance = new UrlLauncherPlugin(registrar); channel.setMethodCallHandler(instance); } @@ -57,12 +55,12 @@ private void canLaunch(String url, Result result) { Intent launchIntent = new Intent(Intent.ACTION_VIEW); launchIntent.setData(Uri.parse(url)); ComponentName componentName = - launchIntent.resolveActivity(mRegistrar.context().getPackageManager()); + launchIntent.resolveActivity(mRegistrar.context().getPackageManager()); boolean canLaunch = - componentName != null - && !"{com.android.fallback/com.android.fallback.Fallback}" - .equals(componentName.toShortString()); + componentName != null + && !"{com.android.fallback/com.android.fallback.Fallback}" + .equals(componentName.toShortString()); result.success(canLaunch); } @@ -80,17 +78,15 @@ private void launch(MethodCall call, Result result, String url) { return; } - if (useWebView) { - launchIntent = WebViewActivity.createIntent( - context, url, - enableJavaScript, enableDomStorage, - headersBundle - ); + launchIntent = + WebViewActivity.createIntent( + context, url, enableJavaScript, enableDomStorage, headersBundle); } else { - launchIntent = new Intent(Intent.ACTION_VIEW) - .setData(Uri.parse(url)) - .putExtra(Browser.EXTRA_HEADERS, headersBundle); + launchIntent = + new Intent(Intent.ACTION_VIEW) + .setData(Uri.parse(url)) + .putExtra(Browser.EXTRA_HEADERS, headersBundle); } context.startActivity(launchIntent); diff --git a/packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java b/packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java index f5d955ccf202..f131047ee72b 100644 --- a/packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java +++ b/packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java @@ -20,41 +20,42 @@ public class WebViewActivity extends Activity { public static String ACTION_CLOSE = "close action"; - final private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - if (ACTION_CLOSE.equals(action)) { - finish(); - } - } - }; - - final private WebViewClient webViewClient = new WebViewClient() { - - @Override - public boolean shouldOverrideUrlLoading(WebView view, String url) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - view.loadUrl(url); - return false; - } - return super.shouldOverrideUrlLoading(view, url); - } - - @Override - public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - view.loadUrl(request.getUrl().toString()); - } - return false; - } - }; + private final BroadcastReceiver broadcastReceiver = + new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (ACTION_CLOSE.equals(action)) { + finish(); + } + } + }; + + private final WebViewClient webViewClient = + new WebViewClient() { + + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + view.loadUrl(url); + return false; + } + return super.shouldOverrideUrlLoading(view, url); + } + + @Override + public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + view.loadUrl(request.getUrl().toString()); + } + return false; + } + }; private WebView webview; private IntentFilter closeIntentFilter = new IntentFilter(ACTION_CLOSE); - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -108,16 +109,16 @@ public boolean onKeyDown(int keyCode, KeyEvent event) { private static String ENABLE_DOM_EXTRA = "enableDomStorage"; /* Hides the constants used to forward data to the Activity instance. */ - public static Intent createIntent(Context context, - String url, - boolean enableJavaScript, - boolean enableDomStorage, - Bundle headersBundle - ) { + public static Intent createIntent( + Context context, + String url, + boolean enableJavaScript, + boolean enableDomStorage, + Bundle headersBundle) { return new Intent(context, WebViewActivity.class) - .putExtra(URL_EXTRA, url) - .putExtra(ENABLE_JS_EXTRA, enableJavaScript) - .putExtra(ENABLE_DOM_EXTRA, enableDomStorage) - .putExtra(Browser.EXTRA_HEADERS, headersBundle); + .putExtra(URL_EXTRA, url) + .putExtra(ENABLE_JS_EXTRA, enableJavaScript) + .putExtra(ENABLE_DOM_EXTRA, enableDomStorage) + .putExtra(Browser.EXTRA_HEADERS, headersBundle); } -} \ No newline at end of file +} From 179e21acbf31de885adce503fbb3d5004567ce26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20Cotta?= Date: Wed, 31 Jul 2019 21:18:11 -0300 Subject: [PATCH 4/6] update CHANGELOG.md and pubspec.yaml --- packages/url_launcher/CHANGELOG.md | 5 +++++ packages/url_launcher/pubspec.yaml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/url_launcher/CHANGELOG.md b/packages/url_launcher/CHANGELOG.md index d4d785eeccb0..c8417ece6822 100644 --- a/packages/url_launcher/CHANGELOG.md +++ b/packages/url_launcher/CHANGELOG.md @@ -1,3 +1,8 @@ +## 5.1.1+1 + +* Update AGP and gradle. +* Split plugin and WebViewActivity class files. + ## 5.1.1 * Suppress a handled deprecation warning on iOS diff --git a/packages/url_launcher/pubspec.yaml b/packages/url_launcher/pubspec.yaml index 71a94f9e565c..debfd3cf21e0 100644 --- a/packages/url_launcher/pubspec.yaml +++ b/packages/url_launcher/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for launching a URL on Android and iOS. Supports web, phone, SMS, and email schemes. author: Flutter Team homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher -version: 5.1.1 +version: 5.1.1+1 flutter: plugin: From 5a4f00965c0984d19a29b19661a99d425651fdb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20Cotta?= Date: Thu, 1 Aug 2019 22:08:12 -0300 Subject: [PATCH 5/6] - fix pubspec.yaml and CHANGELOG.md version. - add javadoc. --- packages/url_launcher/CHANGELOG.md | 2 +- .../plugins/urllauncher/WebViewActivity.java | 71 ++++++++++--------- packages/url_launcher/pubspec.yaml | 2 +- 3 files changed, 40 insertions(+), 35 deletions(-) diff --git a/packages/url_launcher/CHANGELOG.md b/packages/url_launcher/CHANGELOG.md index c8417ece6822..db2ace15b1e9 100644 --- a/packages/url_launcher/CHANGELOG.md +++ b/packages/url_launcher/CHANGELOG.md @@ -1,4 +1,4 @@ -## 5.1.1+1 +## 5.1.2 * Update AGP and gradle. * Split plugin and WebViewActivity class files. diff --git a/packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java b/packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java index f131047ee72b..dc17be912659 100644 --- a/packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java +++ b/packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java @@ -18,39 +18,43 @@ /* Launches WebView activity */ public class WebViewActivity extends Activity { + /* + * Use this to trigger a BroadcastReceiver inside WebViewActivity + * that will request the current instance to finish. + * */ public static String ACTION_CLOSE = "close action"; private final BroadcastReceiver broadcastReceiver = - new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - if (ACTION_CLOSE.equals(action)) { - finish(); - } + new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (ACTION_CLOSE.equals(action)) { + finish(); } - }; + } + }; private final WebViewClient webViewClient = - new WebViewClient() { - - @Override - public boolean shouldOverrideUrlLoading(WebView view, String url) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - view.loadUrl(url); - return false; - } - return super.shouldOverrideUrlLoading(view, url); - } + new WebViewClient() { - @Override - public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - view.loadUrl(request.getUrl().toString()); - } + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + view.loadUrl(url); return false; } - }; + return super.shouldOverrideUrlLoading(view, url); + } + + @Override + public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + view.loadUrl(request.getUrl().toString()); + } + return false; + } + }; private WebView webview; @@ -77,6 +81,7 @@ public void onCreate(Bundle savedInstanceState) { // Open new urls inside the webview itself. webview.setWebViewClient(webViewClient); + // Register receiver that may finish this Activity. registerReceiver(broadcastReceiver, closeIntentFilter); } @@ -110,15 +115,15 @@ public boolean onKeyDown(int keyCode, KeyEvent event) { /* Hides the constants used to forward data to the Activity instance. */ public static Intent createIntent( - Context context, - String url, - boolean enableJavaScript, - boolean enableDomStorage, - Bundle headersBundle) { + Context context, + String url, + boolean enableJavaScript, + boolean enableDomStorage, + Bundle headersBundle) { return new Intent(context, WebViewActivity.class) - .putExtra(URL_EXTRA, url) - .putExtra(ENABLE_JS_EXTRA, enableJavaScript) - .putExtra(ENABLE_DOM_EXTRA, enableDomStorage) - .putExtra(Browser.EXTRA_HEADERS, headersBundle); + .putExtra(URL_EXTRA, url) + .putExtra(ENABLE_JS_EXTRA, enableJavaScript) + .putExtra(ENABLE_DOM_EXTRA, enableDomStorage) + .putExtra(Browser.EXTRA_HEADERS, headersBundle); } } diff --git a/packages/url_launcher/pubspec.yaml b/packages/url_launcher/pubspec.yaml index debfd3cf21e0..f7b77db58818 100644 --- a/packages/url_launcher/pubspec.yaml +++ b/packages/url_launcher/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for launching a URL on Android and iOS. Supports web, phone, SMS, and email schemes. author: Flutter Team homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher -version: 5.1.1+1 +version: 5.1.2 flutter: plugin: From 0a48f445e28da0ec54d7435b018d787c55987ea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20Cotta?= Date: Thu, 1 Aug 2019 22:42:39 -0300 Subject: [PATCH 6/6] fix formatting --- .../plugins/urllauncher/WebViewActivity.java | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java b/packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java index dc17be912659..52714790a25c 100644 --- a/packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java +++ b/packages/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java @@ -25,36 +25,36 @@ public class WebViewActivity extends Activity { public static String ACTION_CLOSE = "close action"; private final BroadcastReceiver broadcastReceiver = - new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - if (ACTION_CLOSE.equals(action)) { - finish(); + new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (ACTION_CLOSE.equals(action)) { + finish(); + } } - } - }; + }; private final WebViewClient webViewClient = - new WebViewClient() { - - @Override - public boolean shouldOverrideUrlLoading(WebView view, String url) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - view.loadUrl(url); - return false; + new WebViewClient() { + + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + view.loadUrl(url); + return false; + } + return super.shouldOverrideUrlLoading(view, url); } - return super.shouldOverrideUrlLoading(view, url); - } - @Override - public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - view.loadUrl(request.getUrl().toString()); + @Override + public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + view.loadUrl(request.getUrl().toString()); + } + return false; } - return false; - } - }; + }; private WebView webview; @@ -115,15 +115,15 @@ public boolean onKeyDown(int keyCode, KeyEvent event) { /* Hides the constants used to forward data to the Activity instance. */ public static Intent createIntent( - Context context, - String url, - boolean enableJavaScript, - boolean enableDomStorage, - Bundle headersBundle) { + Context context, + String url, + boolean enableJavaScript, + boolean enableDomStorage, + Bundle headersBundle) { return new Intent(context, WebViewActivity.class) - .putExtra(URL_EXTRA, url) - .putExtra(ENABLE_JS_EXTRA, enableJavaScript) - .putExtra(ENABLE_DOM_EXTRA, enableDomStorage) - .putExtra(Browser.EXTRA_HEADERS, headersBundle); + .putExtra(URL_EXTRA, url) + .putExtra(ENABLE_JS_EXTRA, enableJavaScript) + .putExtra(ENABLE_DOM_EXTRA, enableDomStorage) + .putExtra(Browser.EXTRA_HEADERS, headersBundle); } }