Commit e0982e36 authored by pichillilorenzo's avatar pichillilorenzo

updating Android

parent 802663ab
This diff is collapsed.
......@@ -25,8 +25,10 @@ android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 16
minSdkVersion 17
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
lintOptions {
disable 'InvalidPackage'
......@@ -35,4 +37,6 @@ android {
dependencies {
implementation 'com.android.support:customtabs:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pichillilorenzo.flutter_inappbrowser">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:theme="@style/AppTheme">
<activity android:name=".WebViewActivity"></activity>
</application>
</manifest>
\ No newline at end of file
package com.pichillilorenzo.flutter_inappbrowser;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.Log;
import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
public class InAppBrowserOptions {
boolean clearCache = false;
boolean clearSessionCache = false;
boolean spinner = true;
boolean hidden = false;
boolean toolbarTop = true;
String toolbarTopColor = "toolbarTopColor";
boolean hideUrlBar = false;
boolean enableViewportScale = false;
boolean keyboardDisplayRequiresUserAction = true;
boolean suppressesIncrementalRendering = false;
boolean allowsAirPlayForMediaPlayback = true;
boolean mediaTypesRequiringUserActionForPlayback = true;
boolean allowsBackForwardNavigationGestures = true;
boolean allowsLinkPreview = true;
boolean ignoresViewportScaleLimits = false;
boolean allowsInlineMediaPlayback = false;
boolean allowsPictureInPictureMediaPlayback = true;
boolean javaScriptCanOpenWindowsAutomatically = false;
boolean javaScriptEnabled = 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
}
}
}
public HashMap<String, Object> getHashMap() {
HashMap<String, Object> options = new HashMap<>();
for (Field f: this.getClass().getDeclaredFields()) {
try {
options.put(f.getName(), f.get(this));
} catch (IllegalAccessException e) {
// silent
}
}
return options;
}
}
package com.pichillilorenzo.flutter_inappbrowser;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.webkit.WebView;
import android.widget.EditText;
import android.widget.SearchView;
import java.util.HashMap;
public class WebViewActivity extends AppCompatActivity {
WebView wv;
SearchView searchView;
InAppBrowserOptions options;
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle b = getIntent().getExtras();
String url = b.getString("url");
options = new InAppBrowserOptions();
options.parse((HashMap<String, Object>) b.getSerializable("options"));
setContentView(R.layout.activity_web_view);
wv = (WebView) findViewById(R.id.webView);
InAppBrowser.webViewActivity = this;
wv.loadUrl(url);
getSupportActionBar().setTitle(wv.getTitle());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
// Inflate menu to add items to action bar if it is present.
inflater.inflate(R.menu.menu_main, menu);
searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
searchView.setQuery(wv.getUrl(), false);
getSupportActionBar().setTitle(wv.getTitle());
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
wv.loadUrl(query);
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
return true;
}
}
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM12,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"/>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical"
tools:context=".WebViewActivity">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:appcompat="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools">
<item
android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100"
app:showAsAction="never"/>
<item
android:id="@+id/menu_search"
android:title="@string/menu_search"
appcompat:actionViewClass="android.widget.SearchView"
appcompat:showAsAction="always" />
</menu>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="action_settings">Settings</string>
<string name="menu_search">Search</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light">
</style>
</resources>
......@@ -34,7 +34,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.pichillilorenzo.flutter_inappbrowserexample"
minSdkVersion 16
minSdkVersion 17
targetSdkVersion 27
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
......
......@@ -22,7 +22,7 @@
<imageView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" image="LaunchImage" translatesAutoresizingMaskIntoConstraints="NO" id="5cB-8U-Az3">
<rect key="frame" x="206.66666666666666" y="367.66666666666669" width="1" height="1"/>
</imageView>
<wkWebView contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="gA9-n8-qaQ">
<wkWebView contentMode="scaleToFill" allowsBackForwardNavigationGestures="YES" translatesAutoresizingMaskIntoConstraints="NO" id="gA9-n8-qaQ">
<rect key="frame" x="0.0" y="67" width="414" height="625"/>
<color key="backgroundColor" red="0.36078431370000003" green="0.38823529410000002" blue="0.4039215686" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<wkWebViewConfiguration key="configuration" applicationNameForUserAgent="">
......
......@@ -18,6 +18,7 @@ class MyInAppBrowser extends InAppBrowser {
this.injectScriptCode("""
\$( "body" ).html( "Next Step..." )
""");
this.injectStyleCode("""
body {
background-color: #3c3c3c !important;
......
......@@ -14,11 +14,6 @@ public class InAppBrowserOptions: NSObject {
var clearCache = false
var clearSessionCache = false
var spinner = true
var enableViewportScale = false
var mediaPlaybackRequiresUserAction = false
var allowInlineMediaPlayback = false
var keyboardDisplayRequiresUserAction = true
var suppressesIncrementalRendering = false
var hidden = false
var disallowOverScroll = false
var toolbarTop = true
......@@ -30,6 +25,18 @@ public class InAppBrowserOptions: NSObject {
var hideUrlBar = false
var presentationStyle = 0 //fullscreen
var transitionStyle = 0 //crossDissolve
var enableViewportScale = false
var keyboardDisplayRequiresUserAction = true
var suppressesIncrementalRendering = false
var allowsAirPlayForMediaPlayback = true
var mediaTypesRequiringUserActionForPlayback = "none"
var allowsBackForwardNavigationGestures = true
var allowsLinkPreview = true
var ignoresViewportScaleLimits = false
var allowsInlineMediaPlayback = false
var allowsPictureInPictureMediaPlayback = true
var javaScriptCanOpenWindowsAutomatically = false
var javaScriptEnabled = true
public func parse(options: [String: Any]) {
for (key, value) in options {
......
......@@ -59,6 +59,25 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
self.hide()
result(true)
break
case "reload":
self.webViewController?.reload()
result(true)
break
case "goBack":
self.webViewController?.goBack()
result(true)
break
case "goForward":
self.webViewController?.goForward()
result(true)
break
case "isLoading":
result(self.webViewController?.webView.isLoading == true)
break
case "stopLoading":
self.webViewController?.webView.stopLoading()
result(true)
break
case "injectScriptCode":
self.injectScriptCode(arguments: arguments!)
result(true)
......
......@@ -144,6 +144,31 @@ class InAppBrowser {
return await _channel.invokeMethod('close');
}
///Reloads the [InAppBrowser] window.
Future<void> reload() async {
return await _channel.invokeMethod('reload');
}
///Goes back in the history of the [InAppBrowser] window.
Future<void> goBack() async {
return await _channel.invokeMethod('goBack');
}
///Goes forward in the history of the [InAppBrowser] window.
Future<void> goForward() async {
return await _channel.invokeMethod('goForward');
}
///Check if the Web View of the [InAppBrowser] instance is in a loading state.
Future<bool> isLoading() async {
return await _channel.invokeMethod('isLoading');
}
///Stops the Web View of the [InAppBrowser] instance from loading.
Future<void> stopLoading() async {
return await _channel.invokeMethod('stopLoading');
}
///Injects JavaScript code into the [InAppBrowser] window. (Only available when the target is set to `_blank` or to `_self`)
Future<void> injectScriptCode(String source) async {
Map<String, dynamic> args = <String, dynamic>{};
......
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