Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
Flutter Inappwebview
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李增强
Flutter Inappwebview
Commits
d89cd5df
Commit
d89cd5df
authored
Sep 21, 2018
by
pichillilorenzo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated android and ios options, added downloader on android, fixed back-button webview android
parent
fb689181
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
244 additions
and
519 deletions
+244
-519
.idea/workspace.xml
.idea/workspace.xml
+36
-24
android/src/main/AndroidManifest.xml
android/src/main/AndroidManifest.xml
+1
-0
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowser.java
...om/pichillilorenzo/flutter_inappbrowser/InAppBrowser.java
+18
-453
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserOptions.java
...illilorenzo/flutter_inappbrowser/InAppBrowserOptions.java
+11
-9
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserWebChromeClient.java
...nzo/flutter_inappbrowser/InAppBrowserWebChromeClient.java
+2
-4
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserWebViewClient.java
...renzo/flutter_inappbrowser/InAppBrowserWebViewClient.java
+1
-0
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/RequestPermissionHandler.java
...orenzo/flutter_inappbrowser/RequestPermissionHandler.java
+46
-0
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/WebViewActivity.java
...pichillilorenzo/flutter_inappbrowser/WebViewActivity.java
+119
-22
android/src/main/res/layout/activity_web_view.xml
android/src/main/res/layout/activity_web_view.xml
+1
-0
android/src/main/res/menu/menu_main.xml
android/src/main/res/menu/menu_main.xml
+1
-1
example/lib/main.dart
example/lib/main.dart
+2
-0
ios/Classes/InAppBrowserOptions.swift
ios/Classes/InAppBrowserOptions.swift
+2
-2
ios/Classes/InAppBrowserWebViewController.swift
ios/Classes/InAppBrowserWebViewController.swift
+4
-4
No files found.
.idea/workspace.xml
View file @
d89cd5df
...
...
@@ -7,8 +7,19 @@
</component>
<component
name=
"ChangeListManager"
>
<list
default=
"true"
id=
"9b41f7a2-a71e-4923-91fb-249d7815b3e7"
name=
"Default"
comment=
""
>
<change
beforePath=
""
afterPath=
"$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/RequestPermissionHandler.java"
/>
<change
beforePath=
"$PROJECT_DIR$/.idea/workspace.xml"
afterPath=
"$PROJECT_DIR$/.idea/workspace.xml"
/>
<change
beforePath=
"$PROJECT_DIR$/android/src/main/AndroidManifest.xml"
afterPath=
"$PROJECT_DIR$/android/src/main/AndroidManifest.xml"
/>
<change
beforePath=
"$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowser.java"
afterPath=
"$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowser.java"
/>
<change
beforePath=
"$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserOptions.java"
afterPath=
"$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserOptions.java"
/>
<change
beforePath=
"$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserWebChromeClient.java"
afterPath=
"$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserWebChromeClient.java"
/>
<change
beforePath=
"$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserWebViewClient.java"
afterPath=
"$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserWebViewClient.java"
/>
<change
beforePath=
"$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/WebViewActivity.java"
afterPath=
"$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/WebViewActivity.java"
/>
<change
beforePath=
"$PROJECT_DIR$/android/src/main/res/layout/activity_web_view.xml"
afterPath=
"$PROJECT_DIR$/android/src/main/res/layout/activity_web_view.xml"
/>
<change
beforePath=
"$PROJECT_DIR$/android/src/main/res/menu/menu_main.xml"
afterPath=
"$PROJECT_DIR$/android/src/main/res/menu/menu_main.xml"
/>
<change
beforePath=
"$PROJECT_DIR$/example/lib/main.dart"
afterPath=
"$PROJECT_DIR$/example/lib/main.dart"
/>
<change
beforePath=
"$PROJECT_DIR$/ios/Classes/InAppBrowserOptions.swift"
afterPath=
"$PROJECT_DIR$/ios/Classes/InAppBrowserOptions.swift"
/>
<change
beforePath=
"$PROJECT_DIR$/ios/Classes/InAppBrowserWebViewController.swift"
afterPath=
"$PROJECT_DIR$/ios/Classes/InAppBrowserWebViewController.swift"
/>
</list>
<ignored
path=
"$PROJECT_DIR$/.dart_tool/"
/>
<ignored
path=
"$PROJECT_DIR$/.idea/"
/>
...
...
@@ -25,10 +36,10 @@
</component>
<component
name=
"FileEditorManager"
>
<leaf
SIDE_TABS_SIZE_LIMIT_KEY=
"300"
>
<file
leaf-file-name=
"flutter_inappbrowser.dart"
pinned=
"false"
current-in-tab=
"
tru
e"
>
<file
leaf-file-name=
"flutter_inappbrowser.dart"
pinned=
"false"
current-in-tab=
"
fals
e"
>
<entry
file=
"file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart"
>
<provider
selected=
"true"
editor-type-id=
"text-editor"
>
<state
relative-caret-position=
"1
20
"
>
<state
relative-caret-position=
"1
725
"
>
<caret
line=
"136"
column=
"29"
lean-forward=
"false"
selection-start-line=
"136"
selection-start-column=
"29"
selection-end-line=
"136"
selection-end-column=
"29"
/>
<folding>
<element
signature=
"e#814#834#0"
expanded=
"true"
/>
...
...
@@ -37,11 +48,11 @@
</provider>
</entry>
</file>
<file
leaf-file-name=
"main.dart"
pinned=
"false"
current-in-tab=
"
fals
e"
>
<file
leaf-file-name=
"main.dart"
pinned=
"false"
current-in-tab=
"
tru
e"
>
<entry
file=
"file://$PROJECT_DIR$/example/lib/main.dart"
>
<provider
selected=
"true"
editor-type-id=
"text-editor"
>
<state
relative-caret-position=
"
195
"
>
<caret
line=
"
15"
column=
"34"
lean-forward=
"false"
selection-start-line=
"15"
selection-start-column=
"34"
selection-end-line=
"15"
selection-end-column=
"34
"
/>
<state
relative-caret-position=
"
212
"
>
<caret
line=
"
43"
column=
"51"
lean-forward=
"false"
selection-start-line=
"43"
selection-start-column=
"51"
selection-end-line=
"43"
selection-end-column=
"51
"
/>
<folding
/>
</state>
</provider>
...
...
@@ -87,6 +98,7 @@
<find>
injectScriptCode
</find>
<find>
injectDeferredObject
</find>
<find>
sourceFile
</find>
<find>
hideUrlBar
</find>
</findStrings>
<replaceStrings>
<replace>
activity.getPreferences(0)
</replace>
...
...
@@ -128,12 +140,12 @@
<option
value=
"$PROJECT_DIR$/README.md"
/>
<option
value=
"$PROJECT_DIR$/android/build.gradle"
/>
<option
value=
"$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowser.java"
/>
<option
value=
"$PROJECT_DIR$/example/lib/main.dart"
/>
<option
value=
"$PROJECT_DIR$/lib/flutter_inappbrowser.dart"
/>
<option
value=
"$PROJECT_DIR$/example/lib/main.dart"
/>
</list>
</option>
</component>
<component
name=
"ProjectFrameBounds"
extendedState=
"6"
>
<component
name=
"ProjectFrameBounds"
>
<option
name=
"x"
value=
"362"
/>
<option
name=
"y"
value=
"23"
/>
<option
name=
"width"
value=
"1554"
/>
...
...
@@ -155,7 +167,6 @@
<foldersAlwaysOnTop
value=
"true"
/>
</navigator>
<panes>
<pane
id=
"Scope"
/>
<pane
id=
"ProjectPane"
>
<subPane>
<expand>
...
...
@@ -210,9 +221,10 @@
</subPane>
<option
name=
"show-excluded-files"
value=
"false"
/>
</pane>
<pane
id=
"Scratches"
/>
<pane
id=
"AndroidView"
/>
<pane
id=
"Scope"
/>
<pane
id=
"PackagesPane"
/>
<pane
id=
"Scratches"
/>
</panes>
</component>
<component
name=
"PropertiesComponent"
>
...
...
@@ -400,7 +412,7 @@
<servers
/>
</component>
<component
name=
"ToolWindowManager"
>
<frame
x=
"
0"
y=
"23"
width=
"1680"
height=
"1027"
extended-state=
"6
"
/>
<frame
x=
"
362"
y=
"23"
width=
"1554"
height=
"1057"
extended-state=
"0
"
/>
<editor
active=
"true"
/>
<layout>
<window_info
id=
"Android Profiler"
active=
"false"
anchor=
"bottom"
auto_hide=
"false"
internal_type=
"DOCKED"
type=
"DOCKED"
visible=
"false"
show_stripe_button=
"false"
weight=
"0.33"
sideWeight=
"0.5"
order=
"7"
side_tool=
"false"
content_ui=
"tabs"
/>
...
...
@@ -411,16 +423,16 @@
<window_info
id=
"Capture Analysis"
active=
"false"
anchor=
"right"
auto_hide=
"false"
internal_type=
"DOCKED"
type=
"DOCKED"
visible=
"false"
show_stripe_button=
"true"
weight=
"0.33"
sideWeight=
"0.5"
order=
"3"
side_tool=
"false"
content_ui=
"tabs"
/>
<window_info
id=
"Event Log"
active=
"false"
anchor=
"bottom"
auto_hide=
"false"
internal_type=
"DOCKED"
type=
"DOCKED"
visible=
"false"
show_stripe_button=
"true"
weight=
"0.31735888"
sideWeight=
"0.5026455"
order=
"7"
side_tool=
"true"
content_ui=
"tabs"
/>
<window_info
id=
"Dart Analysis"
active=
"false"
anchor=
"bottom"
auto_hide=
"false"
internal_type=
"DOCKED"
type=
"DOCKED"
visible=
"false"
show_stripe_button=
"true"
weight=
"0.3290735"
sideWeight=
"0.5"
order=
"7"
side_tool=
"false"
content_ui=
"tabs"
/>
<window_info
id=
"Run"
active=
"false"
anchor=
"bottom"
auto_hide=
"false"
internal_type=
"DOCKED"
type=
"DOCKED"
visible=
"true"
show_stripe_button=
"true"
weight=
"0.3
014301
4"
sideWeight=
"0.4973545"
order=
"2"
side_tool=
"false"
content_ui=
"tabs"
/>
<window_info
id=
"Run"
active=
"false"
anchor=
"bottom"
auto_hide=
"false"
internal_type=
"DOCKED"
type=
"DOCKED"
visible=
"true"
show_stripe_button=
"true"
weight=
"0.3
620873
4"
sideWeight=
"0.4973545"
order=
"2"
side_tool=
"false"
content_ui=
"tabs"
/>
<window_info
id=
"Version Control"
active=
"false"
anchor=
"bottom"
auto_hide=
"false"
internal_type=
"DOCKED"
type=
"DOCKED"
visible=
"false"
show_stripe_button=
"true"
weight=
"0.33"
sideWeight=
"0.5"
order=
"7"
side_tool=
"false"
content_ui=
"tabs"
/>
<window_info
id=
"Terminal"
active=
"false"
anchor=
"bottom"
auto_hide=
"false"
internal_type=
"DOCKED"
type=
"DOCKED"
visible=
"false"
show_stripe_button=
"true"
weight=
"0.32
78328
"
sideWeight=
"0.4973545"
order=
"7"
side_tool=
"false"
content_ui=
"tabs"
/>
<window_info
id=
"Terminal"
active=
"false"
anchor=
"bottom"
auto_hide=
"false"
internal_type=
"DOCKED"
type=
"DOCKED"
visible=
"false"
show_stripe_button=
"true"
weight=
"0.32
694355
"
sideWeight=
"0.4973545"
order=
"7"
side_tool=
"false"
content_ui=
"tabs"
/>
<window_info
id=
"Flutter Outline"
active=
"false"
anchor=
"right"
auto_hide=
"false"
internal_type=
"DOCKED"
type=
"DOCKED"
visible=
"false"
show_stripe_button=
"true"
weight=
"0.32936507"
sideWeight=
"0.5"
order=
"3"
side_tool=
"false"
content_ui=
"tabs"
/>
<window_info
id=
"Logcat"
active=
"false"
anchor=
"bottom"
auto_hide=
"false"
internal_type=
"DOCKED"
type=
"DOCKED"
visible=
"false"
show_stripe_button=
"true"
weight=
"0.33"
sideWeight=
"0.5"
order=
"7"
side_tool=
"false"
content_ui=
"tabs"
/>
<window_info
id=
"Captures"
active=
"false"
anchor=
"left"
auto_hide=
"false"
internal_type=
"DOCKED"
type=
"DOCKED"
visible=
"false"
show_stripe_button=
"true"
weight=
"0.3
3
"
sideWeight=
"0.5"
order=
"2"
side_tool=
"false"
content_ui=
"tabs"
/>
<window_info
id=
"Captures"
active=
"false"
anchor=
"left"
auto_hide=
"false"
internal_type=
"DOCKED"
type=
"DOCKED"
visible=
"false"
show_stripe_button=
"true"
weight=
"0.3
2936507
"
sideWeight=
"0.5"
order=
"2"
side_tool=
"false"
content_ui=
"tabs"
/>
<window_info
id=
"Capture Tool"
active=
"false"
anchor=
"left"
auto_hide=
"false"
internal_type=
"DOCKED"
type=
"DOCKED"
visible=
"false"
show_stripe_button=
"true"
weight=
"0.33"
sideWeight=
"0.5"
order=
"2"
side_tool=
"false"
content_ui=
"tabs"
/>
<window_info
id=
"Designer"
active=
"false"
anchor=
"left"
auto_hide=
"false"
internal_type=
"DOCKED"
type=
"DOCKED"
visible=
"false"
show_stripe_button=
"true"
weight=
"0.33"
sideWeight=
"0.5"
order=
"2"
side_tool=
"false"
content_ui=
"tabs"
/>
<window_info
id=
"Project"
active=
"false"
anchor=
"left"
auto_hide=
"false"
internal_type=
"DOCKED"
type=
"DOCKED"
visible=
"true"
show_stripe_button=
"true"
weight=
"0.2
1001221
"
sideWeight=
"0.5"
order=
"0"
side_tool=
"false"
content_ui=
"combo"
/>
<window_info
id=
"Structure"
active=
"false"
anchor=
"left"
auto_hide=
"false"
internal_type=
"DOCKED"
type=
"DOCKED"
visible=
"false"
show_stripe_button=
"true"
weight=
"0.25"
sideWeight=
"0.5"
order=
"1"
side_tool=
"false"
content_ui=
"tabs"
/>
<window_info
id=
"Project"
active=
"false"
anchor=
"left"
auto_hide=
"false"
internal_type=
"DOCKED"
type=
"DOCKED"
visible=
"true"
show_stripe_button=
"true"
weight=
"0.2
0965609
"
sideWeight=
"0.5"
order=
"0"
side_tool=
"false"
content_ui=
"combo"
/>
<window_info
id=
"Structure"
active=
"false"
anchor=
"left"
auto_hide=
"false"
internal_type=
"DOCKED"
type=
"DOCKED"
visible=
"false"
show_stripe_button=
"true"
weight=
"0.2
496947
5"
sideWeight=
"0.5"
order=
"1"
side_tool=
"false"
content_ui=
"tabs"
/>
<window_info
id=
"Device File Explorer"
active=
"false"
anchor=
"right"
auto_hide=
"false"
internal_type=
"DOCKED"
type=
"DOCKED"
visible=
"false"
show_stripe_button=
"true"
weight=
"0.33"
sideWeight=
"0.5"
order=
"3"
side_tool=
"true"
content_ui=
"tabs"
/>
<window_info
id=
"Theme Preview"
active=
"false"
anchor=
"right"
auto_hide=
"false"
internal_type=
"DOCKED"
type=
"DOCKED"
visible=
"false"
show_stripe_button=
"true"
weight=
"0.33"
sideWeight=
"0.5"
order=
"3"
side_tool=
"false"
content_ui=
"tabs"
/>
<window_info
id=
"Debug"
active=
"false"
anchor=
"bottom"
auto_hide=
"false"
internal_type=
"DOCKED"
type=
"DOCKED"
visible=
"false"
show_stripe_button=
"true"
weight=
"0.4"
sideWeight=
"0.5"
order=
"3"
side_tool=
"false"
content_ui=
"tabs"
/>
...
...
@@ -803,17 +815,9 @@
</state>
</provider>
</entry>
<entry
file=
"file://$PROJECT_DIR$/example/lib/main.dart"
>
<provider
selected=
"true"
editor-type-id=
"text-editor"
>
<state
relative-caret-position=
"195"
>
<caret
line=
"15"
column=
"34"
lean-forward=
"false"
selection-start-line=
"15"
selection-start-column=
"34"
selection-end-line=
"15"
selection-end-column=
"34"
/>
<folding
/>
</state>
</provider>
</entry>
<entry
file=
"file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart"
>
<provider
selected=
"true"
editor-type-id=
"text-editor"
>
<state
relative-caret-position=
"1
20
"
>
<state
relative-caret-position=
"1
725
"
>
<caret
line=
"136"
column=
"29"
lean-forward=
"false"
selection-start-line=
"136"
selection-start-column=
"29"
selection-end-line=
"136"
selection-end-column=
"29"
/>
<folding>
<element
signature=
"e#814#834#0"
expanded=
"true"
/>
...
...
@@ -821,6 +825,14 @@
</state>
</provider>
</entry>
<entry
file=
"file://$PROJECT_DIR$/example/lib/main.dart"
>
<provider
selected=
"true"
editor-type-id=
"text-editor"
>
<state
relative-caret-position=
"212"
>
<caret
line=
"43"
column=
"51"
lean-forward=
"false"
selection-start-line=
"43"
selection-start-column=
"51"
selection-end-line=
"43"
selection-end-column=
"51"
/>
<folding
/>
</state>
</provider>
</entry>
</component>
<component
name=
"masterDetails"
>
<states>
...
...
android/src/main/AndroidManifest.xml
View file @
d89cd5df
...
...
@@ -3,6 +3,7 @@
package=
"com.pichillilorenzo.flutter_inappbrowser"
>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<uses-permission
android:name=
"android.permission.WRITE_EXTERNAL_STORAGE"
/>
<application
android:theme=
"@style/AppTheme"
>
...
...
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowser.java
View file @
d89cd5df
...
...
@@ -294,442 +294,6 @@ public class InAppBrowser implements MethodCallHandler {
intent
.
putExtras
(
extras
);
activity
.
startActivity
(
intent
);
// Determine if we should hide the location bar.
// showLocationBar = true;
// showZoomControls = true;
// openWindowHidden = false;
// mediaPlaybackRequiresUserGesture = false;
// if (features != null) {
// String show = features.get(LOCATION);
// if (show != null) {
// showLocationBar = show.equals("yes") ? true : false;
// }
// if(showLocationBar) {
// String hideNavigation = features.get(HIDE_NAVIGATION);
// String hideUrl = features.get(HIDE_URL);
// if(hideNavigation != null) hideNavigationButtons = hideNavigation.equals("yes") ? true : false;
// if(hideUrl != null) hideUrlBar = hideUrl.equals("yes") ? true : false;
// }
// String zoom = features.get(ZOOM);
// if (zoom != null) {
// showZoomControls = zoom.equals("yes") ? true : false;
// }
// String hidden = features.get(HIDDEN);
// if (hidden != null) {
// openWindowHidden = hidden.equals("yes") ? true : false;
// }
// String hardwareBack = features.get(HARDWARE_BACK_BUTTON);
// if (hardwareBack != null) {
// hadwareBackButton = hardwareBack.equals("yes") ? true : false;
// } else {
// hadwareBackButton = DEFAULT_HARDWARE_BACK;
// }
// String mediaPlayback = features.get(MEDIA_PLAYBACK_REQUIRES_USER_ACTION);
// if (mediaPlayback != null) {
// mediaPlaybackRequiresUserGesture = mediaPlayback.equals("yes") ? true : false;
// }
// String cache = features.get(CLEAR_ALL_CACHE);
// if (cache != null) {
// clearAllCache = cache.equals("yes") ? true : false;
// } else {
// cache = features.get(CLEAR_SESSION_CACHE);
// if (cache != null) {
// clearSessionCache = cache.equals("yes") ? true : false;
// }
// }
// String shouldPause = features.get(SHOULD_PAUSE);
// if (shouldPause != null) {
// shouldPauseInAppBrowser = shouldPause.equals("yes") ? true : false;
// }
// String wideViewPort = features.get(USER_WIDE_VIEW_PORT);
// if (wideViewPort != null ) {
// useWideViewPort = wideViewPort.equals("yes") ? true : false;
// }
// String closeButtonCaptionSet = features.get(CLOSE_BUTTON_CAPTION);
// if (closeButtonCaptionSet != null) {
// closeButtonCaption = closeButtonCaptionSet;
// }
// String closeButtonColorSet = features.get(CLOSE_BUTTON_COLOR);
// if (closeButtonColorSet != null) {
// closeButtonColor = closeButtonColorSet;
// }
// String toolbarColorSet = features.get(TOOLBAR_COLOR);
// if (toolbarColorSet != null) {
// toolbarColor = android.graphics.Color.parseColor(toolbarColorSet);
// }
// String navigationButtonColorSet = features.get(NAVIGATION_COLOR);
// if (navigationButtonColorSet != null) {
// navigationButtonColor = navigationButtonColorSet;
// }
// String showFooterSet = features.get(FOOTER);
// if (showFooterSet != null) {
// showFooter = showFooterSet.equals("yes") ? true : false;
// }
// String footerColorSet = features.get(FOOTER_COLOR);
// if (footerColorSet != null) {
// footerColor = footerColorSet;
// }
// }
//
// // Create dialog in new thread
// Runnable runnable = new Runnable() {
// /**
// * Convert our DIP units to Pixels
// *
// * @return int
// */
// private int dpToPixels(int dipValue) {
// int value = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP,
// (float) dipValue,
// activity.getResources().getDisplayMetrics()
// );
//
// return value;
// }
//
// @TargetApi(8)
// private View createCloseButton(int id){
// View _close;
// Resources activityRes = activity.getResources();
//
// if (closeButtonCaption != "") {
// // Use TextView for text
// TextView close = new TextView(activity);
// close.setText(closeButtonCaption);
// close.setTextSize(20);
// if (closeButtonColor != "") close.setTextColor(android.graphics.Color.parseColor(closeButtonColor));
// close.setGravity(android.view.Gravity.CENTER_VERTICAL);
// close.setPadding(this.dpToPixels(10), 0, this.dpToPixels(10), 0);
// _close = close;
// }
// else {
// ImageButton close = new ImageButton(activity);
// int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", activity.getPackageName());
// Drawable closeIcon = activityRes.getDrawable(closeResId);
// if (closeButtonColor != "") close.setColorFilter(android.graphics.Color.parseColor(closeButtonColor));
// close.setImageDrawable(closeIcon);
// close.setScaleType(ImageView.ScaleType.FIT_CENTER);
// if (Build.VERSION.SDK_INT >= 16)
// close.getAdjustViewBounds();
//
// _close = close;
// }
//
// RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
// closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
// _close.setLayoutParams(closeLayoutParams);
//
// if (Build.VERSION.SDK_INT >= 16)
// _close.setBackground(null);
// else
// _close.setBackgroundDrawable(null);
//
// _close.setContentDescription("Close Button");
// _close.setId(Integer.valueOf(id));
// _close.setOnClickListener(new View.OnClickListener() {
// public void onClick(View v) {
// closeDialog();
// }
// });
//
// return _close;
// }
//
// @SuppressLint("NewApi")
// public void run() {
// // CB-6702 InAppBrowser hangs when opening more than one instance
// if (dialog != null) {
// dialog.dismiss();
// };
//
// // Let's create the main dialog
// dialog = new InAppBrowserDialog(activity, android.R.style.Theme_NoTitleBar);
// dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
// dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
// dialog.setCancelable(true);
// dialog.setInAppBroswer(getInAppBrowser());
//
// int mainId = activity.getResources().getIdentifier("activity_web_view", "layout", activity.getPackageName());
// LinearLayout main = (LinearLayout) LayoutInflater.from(registrar.context()).inflate(mainId, null);
//
// WebView webView = (WebView) main.getChildAt(1));
// webView.loadUrl("https://www.google.com");
//
// // Main container layout
//// LinearLayout main = new LinearLayout(activity);
//// main.setOrientation(LinearLayout.VERTICAL);
////
//// // Toolbar layout
//// RelativeLayout toolbar = new RelativeLayout(activity);
//// //Please, no more black!
////
//// toolbar.setBackgroundColor(toolbarColor);
//// toolbar.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44)));
//// toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
//// toolbar.setHorizontalGravity(Gravity.LEFT);
//// toolbar.setVerticalGravity(Gravity.TOP);
////
//// // Action Button Container layout
//// RelativeLayout actionButtonContainer = new RelativeLayout(activity);
//// actionButtonContainer.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
//// actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
//// actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
//// actionButtonContainer.setId(Integer.valueOf(1));
////
//// // Back button
//// ImageButton back = new ImageButton(activity);
//// RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
//// backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
//// back.setLayoutParams(backLayoutParams);
//// back.setContentDescription("Back Button");
//// back.setId(Integer.valueOf(2));
//// Resources activityRes = activity.getResources();
//// int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", activity.getPackageName());
//// Drawable backIcon = activityRes.getDrawable(backResId);
//// if (navigationButtonColor != "") back.setColorFilter(android.graphics.Color.parseColor(navigationButtonColor));
//// if (Build.VERSION.SDK_INT >= 16)
//// back.setBackground(null);
//// else
//// back.setBackgroundDrawable(null);
//// back.setImageDrawable(backIcon);
//// back.setScaleType(ImageView.ScaleType.FIT_CENTER);
//// back.setPadding(0, this.dpToPixels(10), 0, this.dpToPixels(10));
//// if (Build.VERSION.SDK_INT >= 16)
//// back.getAdjustViewBounds();
////
//// back.setOnClickListener(new View.OnClickListener() {
//// public void onClick(View v) {
//// goBack();
//// }
//// });
////
//// // Forward button
//// ImageButton forward = new ImageButton(activity);
//// RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
//// forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
//// forward.setLayoutParams(forwardLayoutParams);
//// forward.setContentDescription("Forward Button");
//// forward.setId(Integer.valueOf(3));
//// int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", activity.getPackageName());
//// Drawable fwdIcon = activityRes.getDrawable(fwdResId);
//// if (navigationButtonColor != "") forward.setColorFilter(android.graphics.Color.parseColor(navigationButtonColor));
//// if (Build.VERSION.SDK_INT >= 16)
//// forward.setBackground(null);
//// else
//// forward.setBackgroundDrawable(null);
//// forward.setImageDrawable(fwdIcon);
//// forward.setScaleType(ImageView.ScaleType.FIT_CENTER);
//// forward.setPadding(0, this.dpToPixels(10), 0, this.dpToPixels(10));
//// if (Build.VERSION.SDK_INT >= 16)
//// forward.getAdjustViewBounds();
////
//// forward.setOnClickListener(new View.OnClickListener() {
//// public void onClick(View v) {
//// goForward();
//// }
//// });
////
//// // Edit Text Box
//// edittext = new EditText(activity);
//// RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
//// textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
//// textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
//// edittext.setLayoutParams(textLayoutParams);
//// edittext.setId(Integer.valueOf(4));
//// edittext.setSingleLine(true);
//// edittext.setText(url);
//// edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
//// edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
//// edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
//// edittext.setOnKeyListener(new View.OnKeyListener() {
//// public boolean onKey(View v, int keyCode, KeyEvent event) {
//// // If the event is a key-down event on the "enter" button
//// if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
//// navigate(edittext.getText().toString());
//// return true;
//// }
//// return false;
//// }
//// });
////
////
//// // Header Close/Done button
//// View close = createCloseButton(5);
//// toolbar.addView(close);
////
//// // Footer
//// RelativeLayout footer = new RelativeLayout(activity);
//// int _footerColor;
//// if(footerColor != ""){
//// _footerColor = Color.parseColor(footerColor);
//// }else{
//// _footerColor = android.graphics.Color.LTGRAY;
//// }
//// footer.setBackgroundColor(_footerColor);
//// RelativeLayout.LayoutParams footerLayout = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44));
//// footerLayout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
//// footer.setLayoutParams(footerLayout);
//// if (closeButtonCaption != "") footer.setPadding(this.dpToPixels(8), this.dpToPixels(8), this.dpToPixels(8), this.dpToPixels(8));
//// footer.setHorizontalGravity(Gravity.LEFT);
//// footer.setVerticalGravity(Gravity.BOTTOM);
////
//// View footerClose = createCloseButton(7);
//// footer.addView(footerClose);
////
////
//// // WebView
//// inAppWebView = new WebView(activity);
//// inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
//// inAppWebView.setId(Integer.valueOf(6));
//// inAppWebView.setWebChromeClient(new WebChromeClient() {
////
//// @Override
//// public void onProgressChanged(WebView view, int newProgress) {
//// super.onProgressChanged(view, newProgress);
//// }
////
//// @Override
//// public void onReceivedTitle(WebView view, String title) {
//// super.onReceivedTitle(view, title);
//// }
////
//// @Override
//// public void onReceivedIcon(WebView view, Bitmap icon) {
//// super.onReceivedIcon(view, icon);
//// }
////
//// // For Android 5.0+
//// public boolean onShowFileChooser (WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams)
//// {
//// Log.d(LOG_TAG, "File Chooser 5.0+");
//// // If callback exists, finish it.
//// if(mUploadCallbackLollipop != null) {
//// mUploadCallbackLollipop.onReceiveValue(null);
//// }
//// mUploadCallbackLollipop = filePathCallback;
////
//// // Create File Chooser Intent
//// Intent content = new Intent(Intent.ACTION_GET_CONTENT);
//// content.addCategory(Intent.CATEGORY_OPENABLE);
//// content.setType("*/*");
////
//// registrar.context().startActivity(Intent.createChooser(content, "Select File"));
//// return true;
//// }
////
//// // For Android 4.1+
//// public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture)
//// {
//// Log.d(LOG_TAG, "File Chooser 4.1+");
//// // Call file chooser for Android 3.0+
//// openFileChooser(uploadMsg, acceptType);
//// }
////
//// // For Android 3.0+
//// public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType)
//// {
//// Log.d(LOG_TAG, "File Chooser 3.0+");
//// mUploadCallback = uploadMsg;
//// Intent content = new Intent(Intent.ACTION_GET_CONTENT);
//// content.addCategory(Intent.CATEGORY_OPENABLE);
////
//// registrar.context().startActivity(Intent.createChooser(content, "Select File"));
//// }
//// });
////
//// WebViewClient client = new InAppBrowserClient(edittext, activity, channel);
//// inAppWebView.setWebViewClient(client);
//// WebSettings settings = inAppWebView.getSettings();
//// settings.setJavaScriptEnabled(true);
//// //settings.setJavaScinAppWebViewriptCanOpenWindowsAutomatically(true);
//// settings.setBuiltInZoomControls(showZoomControls);
//// settings.setPluginState(android.webkit.WebSettings.PluginState.ON);
////
//// if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
//// settings.setMediaPlaybackRequiresUserGesture(mediaPlaybackRequiresUserGesture);
//// }
////
//// String overrideUserAgent = activity.getPreferences(0).getString("OverrideUserAgent", null);
//// String appendUserAgent = activity.getPreferences(0).getString("AppendUserAgent", null);
////
//// if (overrideUserAgent != null) {
//// settings.setUserAgentString(overrideUserAgent);
//// }
//// if (appendUserAgent != null) {
//// settings.setUserAgentString(settings.getUserAgentString() + appendUserAgent);
//// }
////
//// //Toggle whether this is enabled or not!
//// Bundle appSettings = activity.getIntent().getExtras();
//// boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true);
//// if (enableDatabase) {
//// String databasePath = activity.getApplicationContext().getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath();
//// settings.setDatabasePath(databasePath);
//// settings.setDatabaseEnabled(true);
//// }
//// settings.setDomStorageEnabled(true);
////
//// if (clearAllCache) {
//// CookieManager.getInstance().removeAllCookie();
//// } else if (clearSessionCache) {
//// CookieManager.getInstance().removeSessionCookie();
//// }
////
//// // Enable Thirdparty Cookies on >=Android 5.0 device
//// if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
//// CookieManager.getInstance().setAcceptThirdPartyCookies(inAppWebView,true);
//// }
////
//// inAppWebView.loadUrl(url);
//// inAppWebView.setId(Integer.valueOf(6));
//// inAppWebView.getSettings().setLoadWithOverviewMode(true);
//// inAppWebView.getSettings().setUseWideViewPort(useWideViewPort);
//// inAppWebView.requestFocus();
//// inAppWebView.requestFocusFromTouch();
////
//// // Add the back and forward buttons to our action button container layout
//// actionButtonContainer.addView(back);
//// actionButtonContainer.addView(forward);
////
//// // Add the views to our toolbar if they haven't been disabled
//// if (!hideNavigationButtons) toolbar.addView(actionButtonContainer);
//// if (!hideUrlBar) toolbar.addView(edittext);
////
//// // Don't add the toolbar if its been disabled
//// if (getShowLocationBar()) {
//// // Add our toolbar to our main view/layout
//// main.addView(toolbar);
//// }
////
//// // Add our webview to our main view/layout
//// RelativeLayout webViewLayout = new RelativeLayout(activity);
//// webViewLayout.addView(inAppWebView);
//// main.addView(webViewLayout);
////
//// // Don't add the footer unless it's been enabled
//// if (showFooter) {
//// webViewLayout.addView(footer);
//// }
//
// WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
// lp.copyFrom(dialog.getWindow().getAttributes());
// lp.width = WindowManager.LayoutParams.MATCH_PARENT;
// lp.height = WindowManager.LayoutParams.MATCH_PARENT;
//
// dialog.setContentView(main);
// dialog.show();
// dialog.getWindow().setAttributes(lp);
// // the goal of openhidden is to load the url and not display it
// // Show() needs to be called to cause the URL to be loaded
// if(openWindowHidden) {
// dialog.hide();
// }
// }
// };
// this.activity.runOnUiThread(runnable);
//return "";
}
public
void
loadUrl
(
String
url
,
Map
<
String
,
String
>
headers
,
Result
result
)
{
...
...
@@ -794,6 +358,10 @@ public class InAppBrowser implements MethodCallHandler {
this
.
activity
.
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
Map
<
String
,
Object
>
obj
=
new
HashMap
<>();
channel
.
invokeMethod
(
"exit"
,
obj
);
// The JS protects against multiple calls, so this should happen only when
// close() is called by other native code.
if
(
webViewActivity
==
null
)
...
...
@@ -809,9 +377,6 @@ public class InAppBrowser implements MethodCallHandler {
// other than your app's UI thread, it can cause unexpected results."
// http://developer.android.com/guide/webapps/migrating.html#Threads
webViewActivity
.
webView
.
loadUrl
(
"about:blank"
);
Map
<
String
,
Object
>
obj
=
new
HashMap
<>();
channel
.
invokeMethod
(
"exit"
,
obj
);
}
});
}
...
...
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserOptions.java
View file @
d89cd5df
package
com.pichillilorenzo.flutter_inappbrowser
;
import
android.os.Build
;
import
android.support.annotation.RequiresApi
;
import
android.util.Log
;
import
java.lang.reflect.Field
;
...
...
@@ -14,11 +12,14 @@ public class InAppBrowserOptions {
boolean
clearCache
=
false
;
boolean
clearSessionCache
=
false
;
String
userAgent
=
""
;
boolean
spinne
r
=
true
;
boolean
progressBa
r
=
true
;
boolean
hidden
=
false
;
boolean
toolbarTop
=
true
;
String
toolbarTopColor
=
"toolbarTopColor"
;
String
toolbarTopBackgroundColor
=
""
;
String
toolbarTopFixedTitle
=
""
;
boolean
hideUrlBar
=
false
;
boolean
hideTitleBar
=
false
;
boolean
closeOnCannotGoBack
=
true
;
boolean
mediaPlaybackRequiresUserGesture
=
true
;
boolean
javaScriptCanOpenWindowsAutomatically
=
false
;
boolean
javaScriptEnabled
=
true
;
...
...
@@ -29,15 +30,16 @@ public class InAppBrowserOptions {
boolean
useWideViewPort
=
true
;
boolean
safeBrowsingEnabled
=
true
;
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
KITKAT
)
public
void
parse
(
HashMap
<
String
,
Object
>
options
)
{
Iterator
it
=
options
.
entrySet
().
iterator
();
while
(
it
.
hasNext
())
{
Map
.
Entry
<
String
,
Object
>
pair
=
(
Map
.
Entry
<
String
,
Object
>)
it
.
next
();
try
{
this
.
getClass
().
getField
(
pair
.
getKey
()).
set
(
this
,
pair
.
getValue
());
}
catch
(
NoSuchFieldException
|
IllegalAccessException
e
)
{
// silent
this
.
getClass
().
getDeclaredField
(
pair
.
getKey
()).
set
(
this
,
pair
.
getValue
());
}
catch
(
NoSuchFieldException
e
)
{
Log
.
d
(
"InAppBrowserOptions"
,
e
.
getMessage
());
}
catch
(
IllegalAccessException
e
)
{
Log
.
d
(
"InAppBrowserOptions"
,
e
.
getMessage
());
}
}
}
...
...
@@ -48,7 +50,7 @@ public class InAppBrowserOptions {
try
{
options
.
put
(
f
.
getName
(),
f
.
get
(
this
));
}
catch
(
IllegalAccessException
e
)
{
// silent
Log
.
d
(
"InAppBrowserOptions"
,
e
.
getMessage
());
}
}
return
options
;
...
...
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserWebChromeClient.java
View file @
d89cd5df
...
...
@@ -4,8 +4,6 @@ import android.content.Intent;
import
android.graphics.Bitmap
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.support.annotation.RequiresApi
;
import
android.util.Log
;
import
android.view.View
;
import
android.webkit.ValueCallback
;
import
android.webkit.WebChromeClient
;
...
...
@@ -44,8 +42,8 @@ public class InAppBrowserWebChromeClient extends WebChromeClient {
@Override
public
void
onReceivedTitle
(
WebView
view
,
String
title
)
{
super
.
onReceivedTitle
(
view
,
title
);
if
(
activity
.
getSupportActionBar
()
!=
null
)
activity
.
getSupportActionBar
()
.
setTitle
(
title
);
if
(
activity
.
actionBar
!=
null
&&
activity
.
options
.
toolbarTopFixedTitle
.
isEmpty
()
)
activity
.
actionBar
.
setTitle
(
title
);
}
@Override
...
...
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserWebViewClient.java
View file @
d89cd5df
...
...
@@ -150,4 +150,5 @@ public class InAppBrowserWebViewClient extends WebViewClient {
// By default handle 401 like we'd normally do!
super
.
onReceivedHttpAuthRequest
(
view
,
handler
,
host
,
realm
);
}
}
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/RequestPermissionHandler.java
0 → 100644
View file @
d89cd5df
package
com.pichillilorenzo.flutter_inappbrowser
;
import
android.app.Activity
;
import
android.content.pm.PackageManager
;
import
android.support.annotation.NonNull
;
import
android.support.v4.app.ActivityCompat
;
import
android.support.v4.content.ContextCompat
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
public
abstract
class
RequestPermissionHandler
implements
ActivityCompat
.
OnRequestPermissionsResultCallback
{
public
static
int
REQUEST_CODE_WRITE_EXTERNAL_STORAGE
=
0
;
private
static
Map
<
Integer
,
List
<
Runnable
>>
actionDictionary
=
new
HashMap
<>();
public
static
void
checkAndRun
(
Activity
activity
,
String
permission
,
int
requestCode
,
Runnable
runnable
)
{
int
permissionCheck
=
ContextCompat
.
checkSelfPermission
(
activity
.
getApplicationContext
(),
permission
);
if
(
permissionCheck
!=
PackageManager
.
PERMISSION_GRANTED
)
{
if
(
actionDictionary
.
containsKey
(
requestCode
))
actionDictionary
.
get
(
requestCode
).
add
(
runnable
);
else
actionDictionary
.
put
(
requestCode
,
Arrays
.
asList
(
runnable
));
ActivityCompat
.
requestPermissions
(
activity
,
new
String
[]{
permission
},
requestCode
);
}
else
runnable
.
run
();
}
@Override
public
void
onRequestPermissionsResult
(
int
requestCode
,
@NonNull
String
permissions
[],
@NonNull
int
[]
grantResults
)
{
if
((
grantResults
.
length
>
0
)
&&
(
grantResults
[
0
]
==
PackageManager
.
PERMISSION_GRANTED
))
{
List
<
Runnable
>
callbacks
=
actionDictionary
.
get
(
requestCode
);
for
(
Runnable
runnable
:
callbacks
)
{
runnable
.
run
();
callbacks
.
remove
(
runnable
);
}
}
}
}
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/WebViewActivity.java
View file @
d89cd5df
package
com.pichillilorenzo.flutter_inappbrowser
;
import
android.annotation.TargetApi
;
import
android.app.ProgressDialog
;
import
android.Manifest
;
import
android.app.Activity
;
import
android.app.DownloadManager
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.pm.PackageManager
;
import
android.graphics.Color
;
import
android.graphics.drawable.ColorDrawable
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Environment
;
import
android.support.annotation.RequiresApi
;
import
android.support.v4.app.ActivityCompat
;
import
android.support.v4.content.ContextCompat
;
import
android.support.v7.app.ActionBar
;
import
android.support.v7.app.AppCompatActivity
;
import
android.os.Bundle
;
import
android.util.Log
;
import
android.view.Display
;
import
android.view.KeyEvent
;
import
android.view.Menu
;
import
android.view.MenuInflater
;
import
android.view.MenuItem
;
import
android.view.View
;
import
android.view.WindowManager
;
import
android.webkit.CookieManager
;
import
android.webkit.DownloadListener
;
import
android.webkit.URLUtil
;
import
android.webkit.ValueCallback
;
import
android.webkit.WebSettings
;
import
android.webkit.WebView
;
import
android.widget.AutoCompleteTextView
;
import
android.widget.ImageView
;
import
android.widget.ProgressBar
;
import
android.widget.SearchView
;
import
android.widget.Toast
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -31,6 +43,7 @@ import io.flutter.plugin.common.MethodChannel;
public
class
WebViewActivity
extends
AppCompatActivity
{
WebView
webView
;
ActionBar
actionBar
;
InAppBrowserWebViewClient
inAppBrowserWebViewClient
;
InAppBrowserWebChromeClient
inAppBrowserWebChromeClient
;
SearchView
searchView
;
...
...
@@ -38,23 +51,23 @@ public class WebViewActivity extends AppCompatActivity {
ProgressBar
progressBar
;
public
boolean
isLoading
=
false
;
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
KITKAT
)
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_web_view
);
webView
=
findViewById
(
R
.
id
.
webView
);
progressBar
=
findViewById
(
R
.
id
.
progressBar
);
progressBar
.
setMax
(
100
);
Bundle
b
=
getIntent
().
getExtras
();
String
url
=
b
.
getString
(
"url"
);
options
=
new
InAppBrowserOptions
();
options
.
parse
((
HashMap
<
String
,
Object
>)
b
.
getSerializable
(
"options"
));
InAppBrowser
.
webViewActivity
=
this
;
actionBar
=
getSupportActionBar
();
prepareWebView
();
webView
.
loadUrl
(
url
);
...
...
@@ -69,47 +82,96 @@ public class WebViewActivity extends AppCompatActivity {
inAppBrowserWebViewClient
=
new
InAppBrowserWebViewClient
(
this
);
webView
.
setWebViewClient
(
inAppBrowserWebViewClient
);
final
Activity
activity
=
this
;
webView
.
setDownloadListener
(
new
DownloadListener
()
{
@Override
public
void
onDownloadStart
(
final
String
url
,
final
String
userAgent
,
final
String
contentDisposition
,
final
String
mimetype
,
final
long
contentLength
)
{
RequestPermissionHandler
.
checkAndRun
(
activity
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
,
RequestPermissionHandler
.
REQUEST_CODE_WRITE_EXTERNAL_STORAGE
,
new
Runnable
(){
@Override
public
void
run
(){
DownloadManager
.
Request
request
=
new
DownloadManager
.
Request
(
Uri
.
parse
(
url
));
final
String
filename
=
URLUtil
.
guessFileName
(
url
,
contentDisposition
,
mimetype
);
request
.
allowScanningByMediaScanner
();
request
.
setNotificationVisibility
(
DownloadManager
.
Request
.
VISIBILITY_VISIBLE_NOTIFY_COMPLETED
);
//Notify client once download is completed!
request
.
setVisibleInDownloadsUi
(
true
);
request
.
setDestinationInExternalPublicDir
(
Environment
.
DIRECTORY_DOWNLOADS
,
filename
);
DownloadManager
dm
=
(
DownloadManager
)
getSystemService
(
DOWNLOAD_SERVICE
);
if
(
dm
!=
null
)
{
dm
.
enqueue
(
request
);
Toast
.
makeText
(
getApplicationContext
(),
"Downloading File: "
+
filename
,
//To notify the Client that the file is being downloaded
Toast
.
LENGTH_LONG
).
show
();
}
else
{
Toast
.
makeText
(
getApplicationContext
(),
"Cannot Download File: "
+
filename
,
//To notify the Client that the file cannot be downloaded
Toast
.
LENGTH_LONG
).
show
();
}
}
});
}
});
WebSettings
settings
=
webView
.
getSettings
();
if
(
options
.
hidden
)
hide
();
else
show
();
settings
.
setJavaScriptEnabled
(
options
.
javaScriptEnabled
);
settings
.
setJavaScriptCanOpenWindowsAutomatically
(
options
.
javaScriptCanOpenWindowsAutomatically
);
settings
.
setBuiltInZoomControls
(
options
.
builtInZoomControls
);
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
settings
.
setSafeBrowsingEnabled
(
options
.
safeBrowsingEnabled
);
}
settings
.
setMediaPlaybackRequiresUserGesture
(
options
.
mediaPlaybackRequiresUserGesture
);
settings
.
setDatabaseEnabled
(
options
.
databaseEnabled
);
settings
.
setDomStorageEnabled
(
options
.
domStorageEnabled
);
if
(!
options
.
userAgent
.
isEmpty
())
{
if
(!
options
.
userAgent
.
isEmpty
())
settings
.
setUserAgentString
(
options
.
userAgent
);
}
if
(
options
.
clearCache
)
{
if
(
options
.
clearCache
)
clearCache
();
}
else
if
(
options
.
clearSessionCache
)
{
else
if
(
options
.
clearSessionCache
)
CookieManager
.
getInstance
().
removeSessionCookie
();
}
// Enable Thirdparty Cookies on >=Android 5.0 device
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
CookieManager
.
getInstance
().
setAcceptThirdPartyCookies
(
webView
,
true
);
}
settings
.
setLoadWithOverviewMode
(
true
);
settings
.
setUseWideViewPort
(
options
.
useWideViewPort
);
settings
.
setSupportZoom
(
options
.
supportZoom
);
// fix webview scaling
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
KITKAT
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
KITKAT
)
settings
.
setLayoutAlgorithm
(
WebSettings
.
LayoutAlgorithm
.
TEXT_AUTOSIZING
);
}
else
{
else
settings
.
setTextZoom
(
100
);
if
(
options
.
progressBar
)
{
progressBar
=
findViewById
(
R
.
id
.
progressBar
);
progressBar
.
setMax
(
100
);
}
actionBar
.
setDisplayShowTitleEnabled
(!
options
.
hideTitleBar
);
if
(!
options
.
toolbarTop
)
actionBar
.
hide
();
if
(!
options
.
toolbarTopBackgroundColor
.
isEmpty
())
actionBar
.
setBackgroundDrawable
(
new
ColorDrawable
(
Color
.
parseColor
(
options
.
toolbarTopBackgroundColor
)));
if
(!
options
.
toolbarTopFixedTitle
.
isEmpty
())
actionBar
.
setTitle
(
options
.
toolbarTopFixedTitle
);
}
@Override
...
...
@@ -119,13 +181,25 @@ public class WebViewActivity extends AppCompatActivity {
inflater
.
inflate
(
R
.
menu
.
menu_main
,
menu
);
searchView
=
(
SearchView
)
menu
.
findItem
(
R
.
id
.
menu_search
).
getActionView
();
searchView
.
setFocusable
(
true
);
if
(
options
.
hideUrlBar
)
menu
.
findItem
(
R
.
id
.
menu_search
).
setVisible
(
false
);
searchView
.
setQuery
(
webView
.
getUrl
(),
false
);
getSupportActionBar
().
setTitle
(
webView
.
getTitle
());
if
(
options
.
toolbarTopFixedTitle
.
isEmpty
())
actionBar
.
setTitle
(
webView
.
getTitle
());
searchView
.
setOnQueryTextListener
(
new
SearchView
.
OnQueryTextListener
()
{
@Override
public
boolean
onQueryTextSubmit
(
String
query
)
{
if
(!
query
.
isEmpty
())
{
webView
.
loadUrl
(
query
);
searchView
.
setQuery
(
""
,
false
);
searchView
.
setIconified
(
true
);
return
true
;
}
return
false
;
}
...
...
@@ -133,6 +207,26 @@ public class WebViewActivity extends AppCompatActivity {
public
boolean
onQueryTextChange
(
String
newText
)
{
return
false
;
}
});
searchView
.
setOnCloseListener
(
new
SearchView
.
OnCloseListener
()
{
@Override
public
boolean
onClose
()
{
if
(
searchView
.
getQuery
().
toString
().
isEmpty
())
searchView
.
setQuery
(
webView
.
getUrl
(),
false
);
return
false
;
}
});
searchView
.
setOnQueryTextFocusChangeListener
(
new
View
.
OnFocusChangeListener
()
{
@Override
public
void
onFocusChange
(
View
view
,
boolean
b
)
{
if
(!
b
)
{
searchView
.
setQuery
(
""
,
false
);
searchView
.
setIconified
(
true
);
}
}
});
return
true
;
...
...
@@ -158,7 +252,10 @@ public class WebViewActivity extends AppCompatActivity {
public
boolean
onKeyDown
(
int
keyCode
,
KeyEvent
event
)
{
if
((
keyCode
==
KeyEvent
.
KEYCODE_BACK
))
{
if
(
canGoBack
())
goBack
();
else
if
(
options
.
closeOnCannotGoBack
)
close
();
return
true
;
}
return
super
.
onKeyDown
(
keyCode
,
event
);
...
...
android/src/main/res/layout/activity_web_view.xml
View file @
d89cd5df
...
...
@@ -4,6 +4,7 @@
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:clickable=
"true"
android:focusableInTouchMode=
"true"
android:orientation=
"vertical"
tools:context=
".WebViewActivity"
>
...
...
android/src/main/res/menu/menu_main.xml
View file @
d89cd5df
...
...
@@ -44,6 +44,6 @@
android:id=
"@+id/menu_search"
android:title=
"@string/menu_search"
appcompat:actionViewClass=
"android.widget.SearchView"
appcompat:showAsAction=
"ifRoom"
/>
appcompat:showAsAction=
"ifRoom
|withText
"
/>
</menu>
example/lib/main.dart
View file @
d89cd5df
...
...
@@ -67,6 +67,8 @@ class _MyAppState extends State<MyApp> {
body:
new
Center
(
child:
new
RaisedButton
(
onPressed:
()
{
inAppBrowser
.
open
(
"https://flutter.io/"
,
options:
{
//"toolbarTopFixedTitle": "Fixed title",
"hideUrlBar"
:
true
,
//"toolbarTop": false,
//"toolbarBottom": false
});
...
...
ios/Classes/InAppBrowserOptions.swift
View file @
d89cd5df
...
...
@@ -18,10 +18,10 @@ public class InAppBrowserOptions: NSObject {
var
hidden
=
false
var
disallowOverScroll
=
false
var
toolbarTop
=
true
var
toolbarTopColor
=
""
var
toolbarTop
Background
Color
=
""
var
toolbarTopTranslucent
=
true
var
toolbarBottom
=
true
var
toolbarBottomColor
=
""
var
toolbarBottom
Background
Color
=
""
var
toolbarBottomTranslucent
=
true
var
hideUrlBar
=
false
var
presentationStyle
=
0
//fullscreen
...
...
ios/Classes/InAppBrowserWebViewController.swift
View file @
d89cd5df
...
...
@@ -141,8 +141,8 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio
}
if
(
browserOptions
?
.
toolbarTop
)
!
{
if
browserOptions
?
.
toolbarTopColor
!=
""
{
self
.
toolbarTop
.
backgroundColor
=
color
(
fromHexString
:
(
browserOptions
?
.
toolbarTopColor
)
!
)
if
browserOptions
?
.
toolbarTop
Background
Color
!=
""
{
self
.
toolbarTop
.
backgroundColor
=
color
(
fromHexString
:
(
browserOptions
?
.
toolbarTop
Background
Color
)
!
)
}
}
else
{
...
...
@@ -156,8 +156,8 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio
}
if
(
browserOptions
?
.
toolbarBottom
)
!
{
if
browserOptions
?
.
toolbarBottomColor
!=
""
{
self
.
toolbarBottom
.
backgroundColor
=
color
(
fromHexString
:
(
browserOptions
?
.
toolbarBottomColor
)
!
)
if
browserOptions
?
.
toolbarBottom
Background
Color
!=
""
{
self
.
toolbarBottom
.
backgroundColor
=
color
(
fromHexString
:
(
browserOptions
?
.
toolbarBottom
Background
Color
)
!
)
}
self
.
toolbarBottom
.
isTranslucent
=
(
browserOptions
?
.
toolbarBottomTranslucent
)
!
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment