Commit e1e1574d authored by Lorenzo Pichilli's avatar Lorenzo Pichilli

added onEnterFullscreen and onExitFullscreen events, added android Log.d for debug

parent ddb4d556
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
- Updated Android context menu workaround - Updated Android context menu workaround
- Calling `onCreateContextMenu` event on iOS also when the context menu is disabled in order to have the same effect as Android - Calling `onCreateContextMenu` event on iOS also when the context menu is disabled in order to have the same effect as Android
- Added Android keyboard workaround to hide the keyboard when clicking other HTML elements, losing the focus on the previous input - Added Android keyboard workaround to hide the keyboard when clicking other HTML elements, losing the focus on the previous input
- Added `onEnterFullscreen`, `onExitFullscreen` webview events
- Fixed `Print preview is not working? java.lang.IllegalStateException: Can print only from an activity` [#128](https://github.com/pichillilorenzo/flutter_inappwebview/issues/128) - Fixed `Print preview is not working? java.lang.IllegalStateException: Can print only from an activity` [#128](https://github.com/pichillilorenzo/flutter_inappwebview/issues/128)
## 3.2.0 ## 3.2.0
......
...@@ -54,6 +54,8 @@ public class FlutterWebView implements PlatformView, MethodCallHandler { ...@@ -54,6 +54,8 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
InAppWebViewOptions options = new InAppWebViewOptions(); InAppWebViewOptions options = new InAppWebViewOptions();
options.parse(initialOptions); options.parse(initialOptions);
Log.d(LOG_TAG, "\n\n\n Shared.activity " + ((Shared.activity == null) ? "is null" : "is NOT null!") + "\n\n\n");
webView = new InAppWebView(Shared.activity, this, id, options, contextMenu, containerView); webView = new InAppWebView(Shared.activity, this, id, options, contextMenu, containerView);
displayListenerProxy.onPostWebViewInitialization(displayManager); displayListenerProxy.onPostWebViewInitialization(displayManager);
......
...@@ -88,6 +88,11 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR ...@@ -88,6 +88,11 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR
Shared.activity.setRequestedOrientation(this.mOriginalOrientation); Shared.activity.setRequestedOrientation(this.mOriginalOrientation);
this.mCustomViewCallback.onCustomViewHidden(); this.mCustomViewCallback.onCustomViewHidden();
this.mCustomViewCallback = null; this.mCustomViewCallback = null;
Map<String, Object> obj = new HashMap<>();
if (inAppBrowserActivity != null)
obj.put("uuid", inAppBrowserActivity.uuid);
channel.invokeMethod("onExitFullscreen", obj);
} }
@Override @Override
...@@ -125,6 +130,11 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR ...@@ -125,6 +130,11 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN); | View.SYSTEM_UI_FLAG_FULLSCREEN);
} }
Map<String, Object> obj = new HashMap<>();
if (inAppBrowserActivity != null)
obj.put("uuid", inAppBrowserActivity.uuid);
channel.invokeMethod("onEnterFullscreen", obj);
} }
@Override @Override
...@@ -549,8 +559,6 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR ...@@ -549,8 +559,6 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR
super.onReceivedIcon(view, icon); super.onReceivedIcon(view, icon);
} }
//The undocumented magic method override
//Eclipse will swear at you if you try to put @Override here
// For Android 3.0+ // For Android 3.0+
public void openFileChooser(ValueCallback<Uri> uploadMsg) { public void openFileChooser(ValueCallback<Uri> uploadMsg) {
...@@ -573,7 +581,7 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR ...@@ -573,7 +581,7 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR
FILECHOOSER_RESULTCODE); FILECHOOSER_RESULTCODE);
} }
//For Android 4.1 // For Android 4.1
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
mUploadMessage = uploadMsg; mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT); Intent i = new Intent(Intent.ACTION_GET_CONTENT);
...@@ -583,7 +591,7 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR ...@@ -583,7 +591,7 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR
} }
//For Android 5.0+ // For Android 5.0+
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
InAppWebViewFlutterPlugin.uploadMessageArray = filePathCallback; InAppWebViewFlutterPlugin.uploadMessageArray = filePathCallback;
try { try {
......
...@@ -4,6 +4,7 @@ import android.app.Activity; ...@@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.util.Log;
import android.webkit.ValueCallback; import android.webkit.ValueCallback;
import com.pichillilorenzo.flutter_inappwebview.InAppWebView.FlutterWebViewFactory; import com.pichillilorenzo.flutter_inappwebview.InAppWebView.FlutterWebViewFactory;
...@@ -47,6 +48,9 @@ public class InAppWebViewFlutterPlugin implements FlutterPlugin, ActivityAware { ...@@ -47,6 +48,9 @@ public class InAppWebViewFlutterPlugin implements FlutterPlugin, ActivityAware {
private void onAttachedToEngine(Context applicationContext, BinaryMessenger messenger, Activity activity, PlatformViewRegistry platformViewRegistry, FlutterView flutterView) { private void onAttachedToEngine(Context applicationContext, BinaryMessenger messenger, Activity activity, PlatformViewRegistry platformViewRegistry, FlutterView flutterView) {
Log.d(LOG_TAG, "\n\n\n onAttachedToEngine CALLED! \n\n\n");
Shared.applicationContext = applicationContext; Shared.applicationContext = applicationContext;
Shared.activity = activity; Shared.activity = activity;
Shared.messenger = messenger; Shared.messenger = messenger;
...@@ -67,6 +71,9 @@ public class InAppWebViewFlutterPlugin implements FlutterPlugin, ActivityAware { ...@@ -67,6 +71,9 @@ public class InAppWebViewFlutterPlugin implements FlutterPlugin, ActivityAware {
@Override @Override
public void onDetachedFromEngine(FlutterPluginBinding binding) { public void onDetachedFromEngine(FlutterPluginBinding binding) {
Log.d(LOG_TAG, "\n\n\n onDetachedFromEngine CALLED! \n\n\n");
if (inAppBrowserManager != null) { if (inAppBrowserManager != null) {
inAppBrowserManager.dispose(); inAppBrowserManager.dispose();
inAppBrowserManager = null; inAppBrowserManager = null;
...@@ -100,24 +107,36 @@ public class InAppWebViewFlutterPlugin implements FlutterPlugin, ActivityAware { ...@@ -100,24 +107,36 @@ public class InAppWebViewFlutterPlugin implements FlutterPlugin, ActivityAware {
@Override @Override
public void onAttachedToActivity(ActivityPluginBinding activityPluginBinding) { public void onAttachedToActivity(ActivityPluginBinding activityPluginBinding) {
Log.d(LOG_TAG, "\n\n\n onAttachedToActivity CALLED! \n\n\n");
Shared.activityPluginBinding = activityPluginBinding; Shared.activityPluginBinding = activityPluginBinding;
Shared.activity = activityPluginBinding.getActivity(); Shared.activity = activityPluginBinding.getActivity();
} }
@Override @Override
public void onDetachedFromActivityForConfigChanges() { public void onDetachedFromActivityForConfigChanges() {
Log.d(LOG_TAG, "\n\n\n onDetachedFromActivityForConfigChanges CALLED! \n\n\n");
Shared.activityPluginBinding = null; Shared.activityPluginBinding = null;
Shared.activity = null; Shared.activity = null;
} }
@Override @Override
public void onReattachedToActivityForConfigChanges(ActivityPluginBinding activityPluginBinding) { public void onReattachedToActivityForConfigChanges(ActivityPluginBinding activityPluginBinding) {
Log.d(LOG_TAG, "\n\n\n onReattachedToActivityForConfigChanges CALLED! \n\n\n");
Shared.activityPluginBinding = activityPluginBinding; Shared.activityPluginBinding = activityPluginBinding;
Shared.activity = activityPluginBinding.getActivity(); Shared.activity = activityPluginBinding.getActivity();
} }
@Override @Override
public void onDetachedFromActivity() { public void onDetachedFromActivity() {
Log.d(LOG_TAG, "\n\n\n onDetachedFromActivity CALLED! \n\n\n");
Shared.activityPluginBinding = null; Shared.activityPluginBinding = null;
Shared.activity = null; Shared.activity = null;
} }
......
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"connectivity","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity-0.4.8+5/","dependencies":[]},{"name":"flutter_downloader","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.4.4/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.7/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-3.3.0/","dependencies":[]}],"android":[{"name":"connectivity","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity-0.4.8+5/","dependencies":[]},{"name":"flutter_downloader","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.4.4/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.7/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-3.3.0/","dependencies":[]}],"macos":[{"name":"connectivity_macos","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_macos-0.1.0+3/","dependencies":[]},{"name":"path_provider_macos","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+2/","dependencies":[]}],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"connectivity","dependencies":["connectivity_macos"]},{"name":"connectivity_macos","dependencies":[]},{"name":"flutter_downloader","dependencies":[]},{"name":"flutter_inappwebview","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"permission_handler","dependencies":[]}],"date_created":"2020-05-22 12:58:00.364435","version":"1.17.1"} {"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"connectivity","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity-0.4.8+5/","dependencies":[]},{"name":"flutter_downloader","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.4.4/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.7/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-3.3.0/","dependencies":[]}],"android":[{"name":"connectivity","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity-0.4.8+5/","dependencies":[]},{"name":"flutter_downloader","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.4.4/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.7/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-3.3.0/","dependencies":[]}],"macos":[{"name":"connectivity_macos","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_macos-0.1.0+3/","dependencies":[]},{"name":"path_provider_macos","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+2/","dependencies":[]}],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"connectivity","dependencies":["connectivity_macos"]},{"name":"connectivity_macos","dependencies":[]},{"name":"flutter_downloader","dependencies":[]},{"name":"flutter_inappwebview","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"permission_handler","dependencies":[]}],"date_created":"2020-05-22 16:46:33.343831","version":"1.17.1"}
\ No newline at end of file \ No newline at end of file
...@@ -2,10 +2,11 @@ ...@@ -2,10 +2,11 @@
# This is a generated file; do not edit or check into version control. # This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/lorenzopichilli/flutter" export "FLUTTER_ROOT=/Users/lorenzopichilli/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/lorenzopichilli/Desktop/flutter_inappwebview/example" export "FLUTTER_APPLICATION_PATH=/Users/lorenzopichilli/Desktop/flutter_inappwebview/example"
export "FLUTTER_TARGET=lib/main.dart" export "FLUTTER_TARGET=/Users/lorenzopichilli/Desktop/flutter_inappwebview/example/lib/main.dart"
export "FLUTTER_BUILD_DIR=build" export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios" export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "OTHER_LDFLAGS=$(inherited) -framework Flutter" export "OTHER_LDFLAGS=$(inherited) -framework Flutter"
export "FLUTTER_FRAMEWORK_DIR=/Users/lorenzopichilli/flutter/bin/cache/artifacts/engine/ios" export "FLUTTER_FRAMEWORK_DIR=/Users/lorenzopichilli/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_BUILD_NAME=1.0.0" export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1" export "FLUTTER_BUILD_NUMBER=1"
export "TRACK_WIDGET_CREATION=true"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildSystemType</key>
<string>Original</string>
<key>PreviewsEnabled</key>
<false/>
</dict>
</plist>
...@@ -76,7 +76,7 @@ class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> { ...@@ -76,7 +76,7 @@ class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> {
BoxDecoration(border: Border.all(color: Colors.blueAccent)), BoxDecoration(border: Border.all(color: Colors.blueAccent)),
child: InAppWebView( child: InAppWebView(
contextMenu: contextMenu, contextMenu: contextMenu,
initialUrl: "https://github.com/flutter", initialUrl: "https://www.youtube.com/watch?v=oD5RtLhhubg",
// initialFile: "assets/index.html", // initialFile: "assets/index.html",
initialHeaders: {}, initialHeaders: {},
initialOptions: InAppWebViewGroupOptions( initialOptions: InAppWebViewGroupOptions(
......
...@@ -860,6 +860,7 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi ...@@ -860,6 +860,7 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
lastTouchPointTimestamp = Int64(Date().timeIntervalSince1970 * 1000) lastTouchPointTimestamp = Int64(Date().timeIntervalSince1970 * 1000)
SharedLastTouchPointTimestamp[self] = lastTouchPointTimestamp SharedLastTouchPointTimestamp[self] = lastTouchPointTimestamp
// re-build context menu items for the current webview
UIMenuController.shared.menuItems = [] UIMenuController.shared.menuItems = []
if let menu = self.contextMenu { if let menu = self.contextMenu {
if let menuItems = menu["menuItems"] as? [[String : Any]] { if let menuItems = menu["menuItems"] as? [[String : Any]] {
...@@ -903,6 +904,7 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi ...@@ -903,6 +904,7 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
} }
return false return false
} }
if contextMenuIsShowing, !action.description.starts(with: "onContextMenuActionItemClicked-") { if contextMenuIsShowing, !action.description.starts(with: "onContextMenuActionItemClicked-") {
let id = action.description.compactMap({ $0.asciiValue?.description }).joined() let id = action.description.compactMap({ $0.asciiValue?.description }).joined()
let arguments: [String: Any?] = [ let arguments: [String: Any?] = [
...@@ -944,6 +946,18 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi ...@@ -944,6 +946,18 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
name: UIMenuController.didHideMenuNotification, name: UIMenuController.didHideMenuNotification,
object: nil) object: nil)
// listen for videos playing in fullscreen
NotificationCenter.default.addObserver(self,
selector: #selector(onEnterFullscreen(_:)),
name: UIWindow.didBecomeVisibleNotification,
object: window)
// listen for videos stopping to play in fullscreen
NotificationCenter.default.addObserver(self,
selector: #selector(onExitFullscreen(_:)),
name: UIWindow.didBecomeHiddenNotification,
object: window)
configuration.userContentController = WKUserContentController() configuration.userContentController = WKUserContentController()
configuration.preferences = WKPreferences() configuration.preferences = WKPreferences()
...@@ -2480,6 +2494,34 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi ...@@ -2480,6 +2494,34 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
channel?.invokeMethod("onDidReceiveServerRedirectForProvisionalNavigation", arguments: []) channel?.invokeMethod("onDidReceiveServerRedirectForProvisionalNavigation", arguments: [])
} }
// https://stackoverflow.com/a/42840541/4637638
public func isVideoPlayerWindow(_ notificationObject: AnyObject?) -> Bool {
let nonVideoClasses = ["_UIAlertControllerShimPresenterWindow",
"UITextEffectsWindow",
"UIRemoteKeyboardWindow"]
var isVideo = true
if let obj = notificationObject {
for nonVideoClass in nonVideoClasses {
if let clazz = NSClassFromString(nonVideoClass) {
isVideo = isVideo && !(obj.isKind(of: clazz))
}
}
}
return isVideo
}
@objc func onEnterFullscreen(_ notification: Notification) {
if (isVideoPlayerWindow(notification.object as AnyObject?)) {
channel?.invokeMethod("onEnterFullscreen", arguments: [])
}
}
@objc func onExitFullscreen(_ notification: Notification) {
if (isVideoPlayerWindow(notification.object as AnyObject?)) {
channel?.invokeMethod("onExitFullscreen", arguments: [])
}
}
// public func onContextMenuConfigurationForElement(linkURL: String?, result: FlutterResult?) { // public func onContextMenuConfigurationForElement(linkURL: String?, result: FlutterResult?) {
// let arguments: [String: Any?] = ["linkURL": linkURL] // let arguments: [String: Any?] = ["linkURL": linkURL]
// channel?.invokeMethod("onContextMenuConfigurationForElement", arguments: arguments, result: result) // channel?.invokeMethod("onContextMenuConfigurationForElement", arguments: arguments, result: result)
......
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