Skip to content

Commit

Permalink
fix #182, updated java classes for Flutter 1.12 new Java Embedding AP…
Browse files Browse the repository at this point in the history
…I (Android)
  • Loading branch information
pichillilorenzo committed Dec 14, 2019
1 parent 63f77cf commit 5e272c4
Show file tree
Hide file tree
Showing 25 changed files with 455 additions and 819 deletions.
488 changes: 266 additions & 222 deletions .idea/workspace.xml

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 2.2.0
## 3.0.0

- Updated for Flutter 1.12 new Java Embedding API (Android)
- Updated `clearCache` for Android
- Added `Promise` javascript [polyfill](https://github.com/taylorhakes/promise-polyfill/blob/master/src/index.js) for webviews that doesn't support it for `window.flutter_inappwebview.callHandler`
- Added `getDefaultUserAgent` static method to `InAppWebViewController`
Expand All @@ -11,6 +12,7 @@
- Fix for Android `InAppBrowser` for some controller methods not exposed.
- Merge "Fixes null error when calling getOptions for InAppBrowser class" [#214](https://github.com/pichillilorenzo/flutter_inappwebview/pull/214) (thanks to [panndoraBoo](https://github.com/panndoraBoo))
- Added `dropDownWorkaroundEnabled` webview option for Android to enable a temporary workaround for html dropdowns (issue [#182](https://github.com/pichillilorenzo/flutter_inappwebview/issues/182))
- Fixed "App Crashes after clicking on dropdown (Using inappwebview)" [#182](https://github.com/pichillilorenzo/flutter_inappwebview/issues/182)

### BREAKING CHANGES

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ A Flutter plugin that allows you to add an inline webview or open an in-app brow

- Dart sdk: ">=2.0.0-dev.68.0 <3.0.0"
- Flutter: ">=1.9.1+hotfix.5 <2.0.0"
- Android: `minSdkVersion 17`
- Android: `minSdkVersion 17` and add support for `androidx` (see [AndroidX Migration](https://flutter.dev/docs/development/androidx-migration) to migrate an existing app)
- iOS: `--ios-language swift`, Xcode version `>= 11`

### IMPORTANT Note for Android

If you are starting a new fresh app, you need to create the Flutter App with `flutter create --androidx -i swift` to add support for `androidx`, otherwise it won't work (see [AndroidX Migration](https://flutter.dev/docs/development/androidx-migration) to migrate an existing app).

During the build, if Android fails with `Error: uses-sdk:minSdkVersion 16 cannot be smaller than version 17 declared in library`, it means that you need to update the `minSdkVersion` of your `android/app/build.gradle` file to at least `17`.

Also, you need to add `<uses-permission android:name="android.permission.INTERNET"/>` in the `android/app/src/main/AndroidManifest.xml` file in order to give minimum permission to perform network operations in your application.
Expand All @@ -26,7 +28,7 @@ Because of [Flutter AndroidX compatibility](https://flutter.dev/docs/development

### IMPORTANT Note for iOS

If you are starting a new fresh app, you need to create the Flutter App with `flutter create -i swift` (see [flutter/flutter#13422 (comment)](https://github.com/flutter/flutter/issues/13422#issuecomment-392133780)), otherwise, you will get this message:
If you are starting a new fresh app, you need to create the Flutter App with `flutter create --androidx -i swift` (see [flutter/flutter#13422 (comment)](https://github.com/flutter/flutter/issues/13422#issuecomment-392133780)), otherwise, you will get this message:
```
=== BUILD TARGET flutter_inappwebview OF PROJECT Pods WITH CONFIGURATION Debug ===
The “Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift. Supported values are: 3.0, 4.0, 4.2, 5.0. This setting can be set in the build settings editor.
Expand Down Expand Up @@ -410,7 +412,6 @@ Instead, on the `onLoadStop` WebView event, you can use `callHandler` directly:
* `hardwareAcceleration`: Boolean value to enable Hardware Acceleration in the WebView.
* `supportMultipleWindows`: Sets whether the WebView whether supports multiple windows.
* `regexToCancelSubFramesLoading`: Regular expression used by `shouldOverrideUrlLoading` event to cancel navigation for frames that are not the main frame. If the url request of a subframe matches the regular expression, then the request of that subframe is canceled.
* `dropDownWorkaroundEnabled`: Enable a temporary workaround for html dropdowns (`<select>` tags) (available on Android 19+). It requires **JavaScript enabled**. It attempts to block click events for the dropdowns creating a custom `<div>` layer over the dropdown to intercept user's clicks. This workaround is applied as soon as the web page fires the `DOMContentLoaded` JavaScript event. The default value is `false`.

##### `InAppWebView` iOS-specific options

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.List;
import java.util.Map;

import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry;
Expand All @@ -22,15 +23,13 @@ public class CredentialDatabaseHandler implements MethodChannel.MethodCallHandle

static final String LOG_TAG = "CredentialDatabaseHandler";

public static PluginRegistry.Registrar registrar;
public static MethodChannel channel;
public static CredentialDatabase credentialDatabase;

public CredentialDatabaseHandler(PluginRegistry.Registrar r) {
registrar = r;
channel = new MethodChannel(registrar.messenger(), "com.pichillilorenzo/flutter_inappwebview_credential_database");
public CredentialDatabaseHandler(BinaryMessenger messenger) {
channel = new MethodChannel(messenger, "com.pichillilorenzo/flutter_inappwebview_credential_database");
channel.setMethodCallHandler(this);
credentialDatabase = CredentialDatabase.getInstance(registrar.context());
credentialDatabase = CredentialDatabase.getInstance(Shared.applicationContext);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.hardware.display.DisplayManager;
import android.os.Build;
import android.util.Log;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
Expand All @@ -15,10 +16,12 @@
import com.pichillilorenzo.flutter_inappwebview.InAppWebView.InAppWebViewOptions;

import java.io.IOException;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry.Registrar;
Expand All @@ -31,15 +34,10 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {

static final String LOG_TAG = "FlutterWebView";

public final Activity activity;
public InAppWebView webView;
public final MethodChannel channel;
public final Registrar registrar;

public FlutterWebView(Registrar registrar, final Context context, int id, HashMap<String, Object> params, View containerView) {
this.registrar = registrar;
this.activity = registrar.activity();

public FlutterWebView(BinaryMessenger messenger, final Context context, int id, HashMap<String, Object> params, View containerView) {
DisplayListenerProxy displayListenerProxy = new DisplayListenerProxy();
DisplayManager displayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
displayListenerProxy.onPreWebViewInitialization(displayManager);
Expand All @@ -53,17 +51,31 @@ public FlutterWebView(Registrar registrar, final Context context, int id, HashMa
InAppWebViewOptions options = new InAppWebViewOptions();
options.parse(initialOptions);

webView = new InAppWebView(registrar, context, this, id, options, containerView);
webView = new InAppWebView(Shared.activity, this, id, options, containerView);
displayListenerProxy.onPostWebViewInitialization(displayManager);

// fix https://github.com/pichillilorenzo/flutter_inappwebview/issues/182
try {
Class superClass = webView.getClass().getSuperclass();
while(!superClass.getName().equals("android.view.View")) {
superClass = superClass.getSuperclass();
}
Field mContext = superClass.getDeclaredField("mContext");
mContext.setAccessible(true);
mContext.set(webView, context);
} catch (Exception e) {
e.printStackTrace();
Log.e(LOG_TAG, "Cannot find mContext for this WebView");
}

webView.prepare();

channel = new MethodChannel(registrar.messenger(), "com.pichillilorenzo/flutter_inappwebview_" + id);
channel = new MethodChannel(messenger, "com.pichillilorenzo/flutter_inappwebview_" + id);
channel.setMethodCallHandler(this);

if (initialFile != null) {
try {
initialUrl = Util.getUrlAsset(registrar, initialFile);
initialUrl = Util.getUrlAsset(initialFile);
} catch (IOException e) {
e.printStackTrace();
Log.e(LOG_TAG, initialFile + " asset file cannot be found!", e);
Expand Down Expand Up @@ -375,12 +387,17 @@ public void onInputConnectionUnlocked() {
webView.unlockInputConnection();
}

@Override
public void onFlutterViewAttached(View flutterView) {
webView.setContainerView(flutterView);
if (webView != null) {
webView.setContainerView(flutterView);
}
}

@Override
public void onFlutterViewDetached() {
webView.setContainerView(null);
if (webView != null) {
webView.setContainerView(null);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@

import java.util.HashMap;

import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import io.flutter.plugin.common.StandardMessageCodec;
import io.flutter.plugin.platform.PlatformView;
import io.flutter.plugin.platform.PlatformViewFactory;

public class FlutterWebViewFactory extends PlatformViewFactory {
private final Registrar registrar;
private final View containerView;
private final BinaryMessenger messenger;

public FlutterWebViewFactory(Registrar registrar, View containerView) {
public FlutterWebViewFactory(BinaryMessenger messenger, View containerView) {
super(StandardMessageCodec.INSTANCE);
this.registrar = registrar;
this.containerView = containerView;
this.messenger = messenger;
}

@Override
public PlatformView create(Context context, int id, Object args) {
HashMap<String, Object> params = (HashMap<String, Object>) args;
return new FlutterWebView(registrar, context, id, params, containerView);
return new FlutterWebView(messenger, context, id, params, containerView);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package com.pichillilorenzo.flutter_inappwebview;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
Expand All @@ -47,6 +48,7 @@
import java.util.List;
import java.util.Map;

import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.Result;
Expand All @@ -57,24 +59,22 @@
*/
public class InAppBrowser implements MethodChannel.MethodCallHandler {

public Registrar registrar;
public MethodChannel channel;
public Map<String, InAppBrowserActivity> webViewActivities = new HashMap<>();
public Map<String, ChromeCustomTabsActivity> chromeCustomTabsActivities = new HashMap<>();

protected static final String LOG_TAG = "IABFlutterPlugin";

public InAppBrowser(Registrar r) {
registrar = r;
channel = new MethodChannel(registrar.messenger(), "com.pichillilorenzo/flutter_inappbrowser");
public InAppBrowser(BinaryMessenger messenger) {
channel = new MethodChannel(messenger, "com.pichillilorenzo/flutter_inappbrowser");
channel.setMethodCallHandler(this);
}

@Override
public void onMethodCall(final MethodCall call, final Result result) {
String source;
String urlFile;
final Activity activity = registrar.activity();
final Activity activity = Shared.activity;
final String uuid = (String) call.argument("uuid");

switch (call.method) {
Expand Down Expand Up @@ -114,7 +114,7 @@ public void run() {
if (isLocalFile) {
// check if the asset file exists
try {
url = Util.getUrlAsset(registrar, url);
url = Util.getUrlAsset(url);
} catch (IOException e) {
e.printStackTrace();
result.error(LOG_TAG, url + " asset file cannot be found!", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ protected void onCreate(Bundle savedInstanceState) {

webView = findViewById(R.id.webView);
webView.inAppBrowserActivity = this;
webView.registrar = InAppWebViewFlutterPlugin.inAppBrowser.registrar;

Bundle b = getIntent().getExtras();
uuid = b.getString("uuid");
Expand Down
Loading

0 comments on commit 5e272c4

Please sign in to comment.