Commit d89cd5df authored by pichillilorenzo's avatar pichillilorenzo

updated android and ios options, added downloader on android, fixed back-button webview android

parent fb689181
...@@ -7,8 +7,19 @@ ...@@ -7,8 +7,19 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="9b41f7a2-a71e-4923-91fb-249d7815b3e7" name="Default" comment=""> <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$/.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/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> </list>
<ignored path="$PROJECT_DIR$/.dart_tool/" /> <ignored path="$PROJECT_DIR$/.dart_tool/" />
<ignored path="$PROJECT_DIR$/.idea/" /> <ignored path="$PROJECT_DIR$/.idea/" />
...@@ -25,10 +36,10 @@ ...@@ -25,10 +36,10 @@
</component> </component>
<component name="FileEditorManager"> <component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300"> <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file leaf-file-name="flutter_inappbrowser.dart" pinned="false" current-in-tab="true"> <file leaf-file-name="flutter_inappbrowser.dart" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart"> <entry file="file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="120"> <state relative-caret-position="1725">
<caret line="136" column="29" lean-forward="false" selection-start-line="136" selection-start-column="29" selection-end-line="136" selection-end-column="29" /> <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> <folding>
<element signature="e#814#834#0" expanded="true" /> <element signature="e#814#834#0" expanded="true" />
...@@ -37,11 +48,11 @@ ...@@ -37,11 +48,11 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file leaf-file-name="main.dart" pinned="false" current-in-tab="false"> <file leaf-file-name="main.dart" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/example/lib/main.dart"> <entry file="file://$PROJECT_DIR$/example/lib/main.dart">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="195"> <state relative-caret-position="212">
<caret line="15" column="34" lean-forward="false" selection-start-line="15" selection-start-column="34" selection-end-line="15" selection-end-column="34" /> <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 /> <folding />
</state> </state>
</provider> </provider>
...@@ -87,6 +98,7 @@ ...@@ -87,6 +98,7 @@
<find>injectScriptCode</find> <find>injectScriptCode</find>
<find>injectDeferredObject</find> <find>injectDeferredObject</find>
<find>sourceFile</find> <find>sourceFile</find>
<find>hideUrlBar</find>
</findStrings> </findStrings>
<replaceStrings> <replaceStrings>
<replace>activity.getPreferences(0)</replace> <replace>activity.getPreferences(0)</replace>
...@@ -128,12 +140,12 @@ ...@@ -128,12 +140,12 @@
<option value="$PROJECT_DIR$/README.md" /> <option value="$PROJECT_DIR$/README.md" />
<option value="$PROJECT_DIR$/android/build.gradle" /> <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$/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$/lib/flutter_inappbrowser.dart" />
<option value="$PROJECT_DIR$/example/lib/main.dart" />
</list> </list>
</option> </option>
</component> </component>
<component name="ProjectFrameBounds" extendedState="6"> <component name="ProjectFrameBounds">
<option name="x" value="362" /> <option name="x" value="362" />
<option name="y" value="23" /> <option name="y" value="23" />
<option name="width" value="1554" /> <option name="width" value="1554" />
...@@ -155,7 +167,6 @@ ...@@ -155,7 +167,6 @@
<foldersAlwaysOnTop value="true" /> <foldersAlwaysOnTop value="true" />
</navigator> </navigator>
<panes> <panes>
<pane id="Scope" />
<pane id="ProjectPane"> <pane id="ProjectPane">
<subPane> <subPane>
<expand> <expand>
...@@ -210,9 +221,10 @@ ...@@ -210,9 +221,10 @@
</subPane> </subPane>
<option name="show-excluded-files" value="false" /> <option name="show-excluded-files" value="false" />
</pane> </pane>
<pane id="Scratches" />
<pane id="AndroidView" /> <pane id="AndroidView" />
<pane id="Scope" />
<pane id="PackagesPane" /> <pane id="PackagesPane" />
<pane id="Scratches" />
</panes> </panes>
</component> </component>
<component name="PropertiesComponent"> <component name="PropertiesComponent">
...@@ -400,7 +412,7 @@ ...@@ -400,7 +412,7 @@
<servers /> <servers />
</component> </component>
<component name="ToolWindowManager"> <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" /> <editor active="true" />
<layout> <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" /> <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 @@ ...@@ -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="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="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="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.30143014" 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.36208734" 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="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.3278328" 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.32694355" 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="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="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.33" 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.32936507" 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="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="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.21001221" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" /> <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.20965609" 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="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.24969475" 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="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="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" /> <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 @@ ...@@ -803,17 +815,9 @@
</state> </state>
</provider> </provider>
</entry> </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"> <entry file="file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="120"> <state relative-caret-position="1725">
<caret line="136" column="29" lean-forward="false" selection-start-line="136" selection-start-column="29" selection-end-line="136" selection-end-column="29" /> <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> <folding>
<element signature="e#814#834#0" expanded="true" /> <element signature="e#814#834#0" expanded="true" />
...@@ -821,6 +825,14 @@ ...@@ -821,6 +825,14 @@
</state> </state>
</provider> </provider>
</entry> </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>
<component name="masterDetails"> <component name="masterDetails">
<states> <states>
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
package="com.pichillilorenzo.flutter_inappbrowser"> package="com.pichillilorenzo.flutter_inappbrowser">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application <application
android:theme="@style/AppTheme" > android:theme="@style/AppTheme" >
......
...@@ -294,442 +294,6 @@ public class InAppBrowser implements MethodCallHandler { ...@@ -294,442 +294,6 @@ public class InAppBrowser implements MethodCallHandler {
intent.putExtras(extras); intent.putExtras(extras);
activity.startActivity(intent); 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) { public void loadUrl(String url, Map<String, String> headers, Result result) {
...@@ -794,6 +358,10 @@ public class InAppBrowser implements MethodCallHandler { ...@@ -794,6 +358,10 @@ public class InAppBrowser implements MethodCallHandler {
this.activity.runOnUiThread(new Runnable() { this.activity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { 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 // The JS protects against multiple calls, so this should happen only when
// close() is called by other native code. // close() is called by other native code.
if (webViewActivity == null) if (webViewActivity == null)
...@@ -809,9 +377,6 @@ public class InAppBrowser implements MethodCallHandler { ...@@ -809,9 +377,6 @@ public class InAppBrowser implements MethodCallHandler {
// other than your app's UI thread, it can cause unexpected results." // other than your app's UI thread, it can cause unexpected results."
// http://developer.android.com/guide/webapps/migrating.html#Threads // http://developer.android.com/guide/webapps/migrating.html#Threads
webViewActivity.webView.loadUrl("about:blank"); webViewActivity.webView.loadUrl("about:blank");
Map<String, Object> obj = new HashMap<>();
channel.invokeMethod("exit", obj);
} }
}); });
} }
......
package com.pichillilorenzo.flutter_inappbrowser; package com.pichillilorenzo.flutter_inappbrowser;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.Log; import android.util.Log;
import java.lang.reflect.Field; import java.lang.reflect.Field;
...@@ -14,11 +12,14 @@ public class InAppBrowserOptions { ...@@ -14,11 +12,14 @@ public class InAppBrowserOptions {
boolean clearCache = false; boolean clearCache = false;
boolean clearSessionCache = false; boolean clearSessionCache = false;
String userAgent = ""; String userAgent = "";
boolean spinner = true; boolean progressBar = true;
boolean hidden = false; boolean hidden = false;
boolean toolbarTop = true; boolean toolbarTop = true;
String toolbarTopColor = "toolbarTopColor"; String toolbarTopBackgroundColor = "";
String toolbarTopFixedTitle = "";
boolean hideUrlBar = false; boolean hideUrlBar = false;
boolean hideTitleBar = false;
boolean closeOnCannotGoBack = true;
boolean mediaPlaybackRequiresUserGesture = true; boolean mediaPlaybackRequiresUserGesture = true;
boolean javaScriptCanOpenWindowsAutomatically = false; boolean javaScriptCanOpenWindowsAutomatically = false;
boolean javaScriptEnabled = true; boolean javaScriptEnabled = true;
...@@ -29,15 +30,16 @@ public class InAppBrowserOptions { ...@@ -29,15 +30,16 @@ public class InAppBrowserOptions {
boolean useWideViewPort = true; boolean useWideViewPort = true;
boolean safeBrowsingEnabled = true; boolean safeBrowsingEnabled = true;
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public void parse(HashMap<String, Object> options) { public void parse(HashMap<String, Object> options) {
Iterator it = options.entrySet().iterator(); Iterator it = options.entrySet().iterator();
while (it.hasNext()) { while (it.hasNext()) {
Map.Entry<String, Object> pair = (Map.Entry<String, Object>)it.next(); Map.Entry<String, Object> pair = (Map.Entry<String, Object>)it.next();
try { try {
this.getClass().getField(pair.getKey()).set(this, pair.getValue()); this.getClass().getDeclaredField(pair.getKey()).set(this, pair.getValue());
} catch (NoSuchFieldException | IllegalAccessException e) { } catch (NoSuchFieldException e) {
// silent Log.d("InAppBrowserOptions", e.getMessage());
} catch (IllegalAccessException e) {
Log.d("InAppBrowserOptions", e.getMessage());
} }
} }
} }
...@@ -48,7 +50,7 @@ public class InAppBrowserOptions { ...@@ -48,7 +50,7 @@ public class InAppBrowserOptions {
try { try {
options.put(f.getName(), f.get(this)); options.put(f.getName(), f.get(this));
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
// silent Log.d("InAppBrowserOptions", e.getMessage());
} }
} }
return options; return options;
......
...@@ -4,8 +4,6 @@ import android.content.Intent; ...@@ -4,8 +4,6 @@ import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.Log;
import android.view.View; import android.view.View;
import android.webkit.ValueCallback; import android.webkit.ValueCallback;
import android.webkit.WebChromeClient; import android.webkit.WebChromeClient;
...@@ -44,8 +42,8 @@ public class InAppBrowserWebChromeClient extends WebChromeClient { ...@@ -44,8 +42,8 @@ public class InAppBrowserWebChromeClient extends WebChromeClient {
@Override @Override
public void onReceivedTitle(WebView view, String title) { public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title); super.onReceivedTitle(view, title);
if (activity.getSupportActionBar() != null) if (activity.actionBar != null && activity.options.toolbarTopFixedTitle.isEmpty())
activity.getSupportActionBar().setTitle(title); activity.actionBar.setTitle(title);
} }
@Override @Override
......
...@@ -150,4 +150,5 @@ public class InAppBrowserWebViewClient extends WebViewClient { ...@@ -150,4 +150,5 @@ public class InAppBrowserWebViewClient extends WebViewClient {
// By default handle 401 like we'd normally do! // By default handle 401 like we'd normally do!
super.onReceivedHttpAuthRequest(view, handler, host, realm); super.onReceivedHttpAuthRequest(view, handler, host, realm);
} }
} }
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);
}
}
}
}
package com.pichillilorenzo.flutter_inappbrowser; package com.pichillilorenzo.flutter_inappbrowser;
import android.annotation.TargetApi; import android.Manifest;
import android.app.ProgressDialog; import android.app.Activity;
import android.app.DownloadManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; 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.Build;
import android.os.Environment;
import android.support.annotation.RequiresApi; 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.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.Display;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.WindowManager;
import android.webkit.CookieManager; import android.webkit.CookieManager;
import android.webkit.DownloadListener;
import android.webkit.URLUtil;
import android.webkit.ValueCallback; import android.webkit.ValueCallback;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
import android.widget.AutoCompleteTextView;
import android.widget.ImageView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.SearchView; import android.widget.SearchView;
import android.widget.Toast;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -31,6 +43,7 @@ import io.flutter.plugin.common.MethodChannel; ...@@ -31,6 +43,7 @@ import io.flutter.plugin.common.MethodChannel;
public class WebViewActivity extends AppCompatActivity { public class WebViewActivity extends AppCompatActivity {
WebView webView; WebView webView;
ActionBar actionBar;
InAppBrowserWebViewClient inAppBrowserWebViewClient; InAppBrowserWebViewClient inAppBrowserWebViewClient;
InAppBrowserWebChromeClient inAppBrowserWebChromeClient; InAppBrowserWebChromeClient inAppBrowserWebChromeClient;
SearchView searchView; SearchView searchView;
...@@ -38,23 +51,23 @@ public class WebViewActivity extends AppCompatActivity { ...@@ -38,23 +51,23 @@ public class WebViewActivity extends AppCompatActivity {
ProgressBar progressBar; ProgressBar progressBar;
public boolean isLoading = false; public boolean isLoading = false;
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view); setContentView(R.layout.activity_web_view);
webView = findViewById(R.id.webView); webView = findViewById(R.id.webView);
progressBar = findViewById(R.id.progressBar);
progressBar.setMax(100);
Bundle b = getIntent().getExtras(); Bundle b = getIntent().getExtras();
String url = b.getString("url"); String url = b.getString("url");
options = new InAppBrowserOptions(); options = new InAppBrowserOptions();
options.parse((HashMap<String, Object>) b.getSerializable("options")); options.parse((HashMap<String, Object>) b.getSerializable("options"));
InAppBrowser.webViewActivity = this; InAppBrowser.webViewActivity = this;
actionBar = getSupportActionBar();
prepareWebView(); prepareWebView();
webView.loadUrl(url); webView.loadUrl(url);
...@@ -69,47 +82,96 @@ public class WebViewActivity extends AppCompatActivity { ...@@ -69,47 +82,96 @@ public class WebViewActivity extends AppCompatActivity {
inAppBrowserWebViewClient = new InAppBrowserWebViewClient(this); inAppBrowserWebViewClient = new InAppBrowserWebViewClient(this);
webView.setWebViewClient(inAppBrowserWebViewClient); 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(); WebSettings settings = webView.getSettings();
if (options.hidden)
hide();
else
show();
settings.setJavaScriptEnabled(options.javaScriptEnabled); settings.setJavaScriptEnabled(options.javaScriptEnabled);
settings.setJavaScriptCanOpenWindowsAutomatically(options.javaScriptCanOpenWindowsAutomatically); settings.setJavaScriptCanOpenWindowsAutomatically(options.javaScriptCanOpenWindowsAutomatically);
settings.setBuiltInZoomControls(options.builtInZoomControls); 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.setSafeBrowsingEnabled(options.safeBrowsingEnabled);
}
settings.setMediaPlaybackRequiresUserGesture(options.mediaPlaybackRequiresUserGesture); settings.setMediaPlaybackRequiresUserGesture(options.mediaPlaybackRequiresUserGesture);
settings.setDatabaseEnabled(options.databaseEnabled); settings.setDatabaseEnabled(options.databaseEnabled);
settings.setDomStorageEnabled(options.domStorageEnabled); settings.setDomStorageEnabled(options.domStorageEnabled);
if (!options.userAgent.isEmpty()) { if (!options.userAgent.isEmpty())
settings.setUserAgentString(options.userAgent); settings.setUserAgentString(options.userAgent);
}
if (options.clearCache) { if (options.clearCache)
clearCache(); clearCache();
} else if (options.clearSessionCache) { else if (options.clearSessionCache)
CookieManager.getInstance().removeSessionCookie(); CookieManager.getInstance().removeSessionCookie();
}
// Enable Thirdparty Cookies on >=Android 5.0 device // 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); CookieManager.getInstance().setAcceptThirdPartyCookies(webView,true);
}
settings.setLoadWithOverviewMode(true); settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(options.useWideViewPort); settings.setUseWideViewPort(options.useWideViewPort);
settings.setSupportZoom(options.supportZoom); settings.setSupportZoom(options.supportZoom);
// fix webview scaling // 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); settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
} else
else {
settings.setTextZoom(100); 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 @Override
...@@ -119,13 +181,25 @@ public class WebViewActivity extends AppCompatActivity { ...@@ -119,13 +181,25 @@ public class WebViewActivity extends AppCompatActivity {
inflater.inflate(R.menu.menu_main, menu); inflater.inflate(R.menu.menu_main, menu);
searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView(); 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); searchView.setQuery(webView.getUrl(), false);
getSupportActionBar().setTitle(webView.getTitle());
if (options.toolbarTopFixedTitle.isEmpty())
actionBar.setTitle(webView.getTitle());
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override @Override
public boolean onQueryTextSubmit(String query) { public boolean onQueryTextSubmit(String query) {
if (!query.isEmpty()) {
webView.loadUrl(query); webView.loadUrl(query);
searchView.setQuery("", false);
searchView.setIconified(true);
return true;
}
return false; return false;
} }
...@@ -133,6 +207,26 @@ public class WebViewActivity extends AppCompatActivity { ...@@ -133,6 +207,26 @@ public class WebViewActivity extends AppCompatActivity {
public boolean onQueryTextChange(String newText) { public boolean onQueryTextChange(String newText) {
return false; 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; return true;
...@@ -158,7 +252,10 @@ public class WebViewActivity extends AppCompatActivity { ...@@ -158,7 +252,10 @@ public class WebViewActivity extends AppCompatActivity {
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK)) { if ((keyCode == KeyEvent.KEYCODE_BACK)) {
if (canGoBack())
goBack(); goBack();
else if (options.closeOnCannotGoBack)
close();
return true; return true;
} }
return super.onKeyDown(keyCode, event); return super.onKeyDown(keyCode, event);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:clickable="true"
android:focusableInTouchMode="true" android:focusableInTouchMode="true"
android:orientation="vertical" android:orientation="vertical"
tools:context=".WebViewActivity"> tools:context=".WebViewActivity">
......
...@@ -44,6 +44,6 @@ ...@@ -44,6 +44,6 @@
android:id="@+id/menu_search" android:id="@+id/menu_search"
android:title="@string/menu_search" android:title="@string/menu_search"
appcompat:actionViewClass="android.widget.SearchView" appcompat:actionViewClass="android.widget.SearchView"
appcompat:showAsAction="ifRoom" /> appcompat:showAsAction="ifRoom|withText" />
</menu> </menu>
...@@ -67,6 +67,8 @@ class _MyAppState extends State<MyApp> { ...@@ -67,6 +67,8 @@ class _MyAppState extends State<MyApp> {
body: new Center( body: new Center(
child: new RaisedButton(onPressed: () { child: new RaisedButton(onPressed: () {
inAppBrowser.open("https://flutter.io/", options: { inAppBrowser.open("https://flutter.io/", options: {
//"toolbarTopFixedTitle": "Fixed title",
"hideUrlBar": true,
//"toolbarTop": false, //"toolbarTop": false,
//"toolbarBottom": false //"toolbarBottom": false
}); });
......
...@@ -18,10 +18,10 @@ public class InAppBrowserOptions: NSObject { ...@@ -18,10 +18,10 @@ public class InAppBrowserOptions: NSObject {
var hidden = false var hidden = false
var disallowOverScroll = false var disallowOverScroll = false
var toolbarTop = true var toolbarTop = true
var toolbarTopColor = "" var toolbarTopBackgroundColor = ""
var toolbarTopTranslucent = true var toolbarTopTranslucent = true
var toolbarBottom = true var toolbarBottom = true
var toolbarBottomColor = "" var toolbarBottomBackgroundColor = ""
var toolbarBottomTranslucent = true var toolbarBottomTranslucent = true
var hideUrlBar = false var hideUrlBar = false
var presentationStyle = 0 //fullscreen var presentationStyle = 0 //fullscreen
......
...@@ -141,8 +141,8 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio ...@@ -141,8 +141,8 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio
} }
if (browserOptions?.toolbarTop)! { if (browserOptions?.toolbarTop)! {
if browserOptions?.toolbarTopColor != "" { if browserOptions?.toolbarTopBackgroundColor != "" {
self.toolbarTop.backgroundColor = color(fromHexString: (browserOptions?.toolbarTopColor)!) self.toolbarTop.backgroundColor = color(fromHexString: (browserOptions?.toolbarTopBackgroundColor)!)
} }
} }
else { else {
...@@ -156,8 +156,8 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio ...@@ -156,8 +156,8 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio
} }
if (browserOptions?.toolbarBottom)! { if (browserOptions?.toolbarBottom)! {
if browserOptions?.toolbarBottomColor != "" { if browserOptions?.toolbarBottomBackgroundColor != "" {
self.toolbarBottom.backgroundColor = color(fromHexString: (browserOptions?.toolbarBottomColor)!) self.toolbarBottom.backgroundColor = color(fromHexString: (browserOptions?.toolbarBottomBackgroundColor)!)
} }
self.toolbarBottom.isTranslucent = (browserOptions?.toolbarBottomTranslucent)! self.toolbarBottom.isTranslucent = (browserOptions?.toolbarBottomTranslucent)!
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment