This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[url_launcher] Split Activity and plugin files #1936
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9812791
Update AGP to 3.4.2 and gradle to 5.1.1
juliocbcotta 4a4d998
Move WebViewActivity to its own class file.
juliocbcotta 5015e08
fix formatting
juliocbcotta 179e21a
update CHANGELOG.md and pubspec.yaml
juliocbcotta 5a4f009
- fix pubspec.yaml and CHANGELOG.md version.
juliocbcotta 0a48f44
fix formatting
juliocbcotta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
...es/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| 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 { | ||
|
|
||
| /* | ||
| * 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(); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| 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); | ||
| 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<String, String> 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); | ||
|
|
||
| // Register receiver that may finish this Activity. | ||
| registerReceiver(broadcastReceiver, closeIntentFilter); | ||
| } | ||
|
|
||
| private Map<String, String> extractHeaders(Bundle headersBundle) { | ||
| final Map<String, String> 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); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/url_launcher/example/android/gradle/wrapper/gradle-wrapper.properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Some Javadoc explaining what this constant is used for would be useful. https://google.github.io/styleguide/javaguide.html#s7.3-javadoc-where-required
I didn't realize spaces were supported here. Neat.