@capgo/inappbrowser 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CapgoInappbrowser.podspec +17 -0
  2. package/README.md +118 -0
  3. package/android/build.gradle +58 -0
  4. package/android/src/main/AndroidManifest.xml +3 -0
  5. package/android/src/main/java/ee/forgr/capacitor_inappbrowser/InAppBrowserPlugin.java +160 -0
  6. package/android/src/main/java/ee/forgr/capacitor_inappbrowser/Options.java +88 -0
  7. package/android/src/main/java/ee/forgr/capacitor_inappbrowser/WebViewCallbacks.java +7 -0
  8. package/android/src/main/java/ee/forgr/capacitor_inappbrowser/WebViewDialog.java +218 -0
  9. package/android/src/main/res/.gitkeep +0 -0
  10. package/android/src/main/res/drawable/arrow_back_disabled.xml +9 -0
  11. package/android/src/main/res/drawable/arrow_back_enabled.xml +9 -0
  12. package/android/src/main/res/drawable/arrow_forward_disabled.xml +9 -0
  13. package/android/src/main/res/drawable/arrow_forward_enabled.xml +9 -0
  14. package/android/src/main/res/drawable/ic_clear_24px.xml +9 -0
  15. package/android/src/main/res/layout/activity_browser.xml +22 -0
  16. package/android/src/main/res/layout/bridge_layout_main.xml +15 -0
  17. package/android/src/main/res/layout/content_browser.xml +16 -0
  18. package/android/src/main/res/layout/tool_bar.xml +50 -0
  19. package/android/src/main/res/values/colors.xml +5 -0
  20. package/android/src/main/res/values/dimens.xml +3 -0
  21. package/android/src/main/res/values/strings.xml +9 -0
  22. package/android/src/main/res/values/styles.xml +12 -0
  23. package/dist/docs.json +234 -0
  24. package/dist/esm/definitions.d.ts +34 -0
  25. package/dist/esm/definitions.js +8 -0
  26. package/dist/esm/definitions.js.map +1 -0
  27. package/dist/esm/index.d.ts +4 -0
  28. package/dist/esm/index.js +7 -0
  29. package/dist/esm/index.js.map +1 -0
  30. package/dist/esm/web.d.ts +7 -0
  31. package/dist/esm/web.js +16 -0
  32. package/dist/esm/web.js.map +1 -0
  33. package/dist/plugin.cjs.js +40 -0
  34. package/dist/plugin.cjs.js.map +1 -0
  35. package/dist/plugin.js +43 -0
  36. package/dist/plugin.js.map +1 -0
  37. package/ios/Plugin/Enums.swift +64 -0
  38. package/ios/Plugin/InAppBrowserPlugin.h +10 -0
  39. package/ios/Plugin/InAppBrowserPlugin.m +14 -0
  40. package/ios/Plugin/InAppBrowserPlugin.swift +191 -0
  41. package/ios/Plugin/Info.plist +24 -0
  42. package/ios/Plugin/WKWebViewController.swift +782 -0
  43. package/package.json +78 -0
@@ -0,0 +1,17 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'CapgoInappbrowser'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.license = package['license']
10
+ s.homepage = package['repository']['url']
11
+ s.author = package['author']
12
+ s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
+ s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
+ s.ios.deployment_target = '12.0'
15
+ s.dependency 'Capacitor'
16
+ s.swift_version = '5.1'
17
+ end
package/README.md ADDED
@@ -0,0 +1,118 @@
1
+ # @capgo/inappbrowser
2
+
3
+ Capacitor plugin in app browser
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @capgo/inappbrowser
9
+ npx cap sync
10
+ ```
11
+
12
+ ## API
13
+
14
+ <docgen-index>
15
+
16
+ * [`open(...)`](#open)
17
+ * [`close()`](#close)
18
+ * [`openWebView(...)`](#openwebview)
19
+ * [Interfaces](#interfaces)
20
+ * [Enums](#enums)
21
+
22
+ </docgen-index>
23
+
24
+ <docgen-api>
25
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
26
+
27
+ ### open(...)
28
+
29
+ ```typescript
30
+ open(options: OpenOptions) => Promise<any>
31
+ ```
32
+
33
+ | Param | Type |
34
+ | ------------- | --------------------------------------------------- |
35
+ | **`options`** | <code><a href="#openoptions">OpenOptions</a></code> |
36
+
37
+ **Returns:** <code>Promise&lt;any&gt;</code>
38
+
39
+ --------------------
40
+
41
+
42
+ ### close()
43
+
44
+ ```typescript
45
+ close() => Promise<any>
46
+ ```
47
+
48
+ **Returns:** <code>Promise&lt;any&gt;</code>
49
+
50
+ --------------------
51
+
52
+
53
+ ### openWebView(...)
54
+
55
+ ```typescript
56
+ openWebView(options: OpenWebViewOptions) => Promise<any>
57
+ ```
58
+
59
+ | Param | Type |
60
+ | ------------- | ----------------------------------------------------------------- |
61
+ | **`options`** | <code><a href="#openwebviewoptions">OpenWebViewOptions</a></code> |
62
+
63
+ **Returns:** <code>Promise&lt;any&gt;</code>
64
+
65
+ --------------------
66
+
67
+
68
+ ### Interfaces
69
+
70
+
71
+ #### OpenOptions
72
+
73
+ | Prop | Type |
74
+ | ---------------------------- | ------------------------------------------- |
75
+ | **`url`** | <code>string</code> |
76
+ | **`headers`** | <code><a href="#headers">Headers</a></code> |
77
+ | **`isPresentAfterPageLoad`** | <code>boolean</code> |
78
+
79
+
80
+ #### Headers
81
+
82
+
83
+ #### OpenWebViewOptions
84
+
85
+ | Prop | Type |
86
+ | ---------------------------- | --------------------------------------------------------------- |
87
+ | **`url`** | <code>string</code> |
88
+ | **`headers`** | <code><a href="#headers">Headers</a></code> |
89
+ | **`shareDisclaimer`** | <code><a href="#disclaimeroptions">DisclaimerOptions</a></code> |
90
+ | **`toolbarType`** | <code><a href="#toolbartype">ToolBarType</a></code> |
91
+ | **`shareSubject`** | <code>string</code> |
92
+ | **`title`** | <code>string</code> |
93
+ | **`isPresentAfterPageLoad`** | <code>boolean</code> |
94
+
95
+
96
+ #### DisclaimerOptions
97
+
98
+ | Prop | Type |
99
+ | ---------------- | ------------------- |
100
+ | **`title`** | <code>string</code> |
101
+ | **`message`** | <code>string</code> |
102
+ | **`confirmBtn`** | <code>string</code> |
103
+ | **`cancelBtn`** | <code>string</code> |
104
+
105
+
106
+ ### Enums
107
+
108
+
109
+ #### ToolBarType
110
+
111
+ | Members | Value |
112
+ | ---------------- | ------------------------- |
113
+ | **`ACTIVITY`** | <code>"activity"</code> |
114
+ | **`NAVIGATION`** | <code>"navigation"</code> |
115
+ | **`BLANK`** | <code>"blank"</code> |
116
+ | **`DEFAULT`** | <code>""</code> |
117
+
118
+ </docgen-api>
@@ -0,0 +1,58 @@
1
+ ext {
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.1'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.2.0'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.2'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.3.0'
6
+ }
7
+
8
+ buildscript {
9
+ repositories {
10
+ google()
11
+ jcenter()
12
+ }
13
+ dependencies {
14
+ classpath 'com.android.tools.build:gradle:4.2.1'
15
+ }
16
+ }
17
+
18
+ apply plugin: 'com.android.library'
19
+
20
+ android {
21
+ compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 30
22
+ defaultConfig {
23
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 21
24
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 30
25
+ versionCode 1
26
+ versionName "1.0"
27
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
28
+ }
29
+ buildTypes {
30
+ release {
31
+ minifyEnabled false
32
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
33
+ }
34
+ }
35
+ lintOptions {
36
+ abortOnError false
37
+ }
38
+ compileOptions {
39
+ sourceCompatibility JavaVersion.VERSION_1_8
40
+ targetCompatibility JavaVersion.VERSION_1_8
41
+ }
42
+ }
43
+
44
+ repositories {
45
+ google()
46
+ mavenCentral()
47
+ jcenter()
48
+ }
49
+
50
+
51
+ dependencies {
52
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
53
+ implementation project(':capacitor-android')
54
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
55
+ testImplementation "junit:junit:$junitVersion"
56
+ androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
57
+ androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
58
+ }
@@ -0,0 +1,3 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="ee.forgr.capacitor_inappbrowser">
3
+ </manifest>
@@ -0,0 +1,160 @@
1
+ package ee.forgr.capacitor_inappbrowser;
2
+
3
+ import android.content.ComponentName;
4
+ import android.content.Intent;
5
+ import android.net.Uri;
6
+ import android.os.Bundle;
7
+ import android.support.customtabs.CustomTabsCallback;
8
+ import android.support.customtabs.CustomTabsClient;
9
+ import android.support.customtabs.CustomTabsIntent;
10
+ import android.support.customtabs.CustomTabsServiceConnection;
11
+ import android.support.customtabs.CustomTabsSession;
12
+ import android.text.TextUtils;
13
+ import android.util.Log;
14
+
15
+ import com.getcapacitor.JSObject;
16
+ import com.getcapacitor.NativePlugin;
17
+ import com.getcapacitor.Plugin;
18
+ import com.getcapacitor.PluginCall;
19
+ import com.getcapacitor.PluginMethod;
20
+
21
+ import java.util.Iterator;
22
+
23
+ @NativePlugin()
24
+ public class CapBrowser extends Plugin {
25
+ public static final String CUSTOM_TAB_PACKAGE_NAME = "com.android.chrome"; // Change when in stable
26
+ private CustomTabsClient customTabsClient;
27
+ private CustomTabsSession currentSession;
28
+ private WebViewDialog webViewDialog = null;
29
+
30
+ CustomTabsServiceConnection connection = new CustomTabsServiceConnection() {
31
+ @Override
32
+ public void onCustomTabsServiceConnected(ComponentName name, CustomTabsClient client) {
33
+ customTabsClient = client;
34
+ client.warmup(0);
35
+ }
36
+
37
+ @Override
38
+ public void onServiceDisconnected(ComponentName name) {
39
+ }
40
+ };
41
+
42
+ @PluginMethod()
43
+ public void open(PluginCall call) {
44
+ String url = call.getString("url");
45
+ if(url == null || TextUtils.isEmpty(url)) {
46
+ call.error("Invalid URL");
47
+ }
48
+ CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(getCustomTabsSession());
49
+ builder.addDefaultShareMenuItem();
50
+ CustomTabsIntent tabsIntent = builder.build();
51
+ tabsIntent.intent.putExtra(Intent.EXTRA_REFERRER,
52
+ Uri.parse(Intent.URI_ANDROID_APP_SCHEME + "//" + getContext().getPackageName()));
53
+ tabsIntent.intent.putExtra(android.provider.Browser.EXTRA_HEADERS, this.getHeaders(call));
54
+ tabsIntent.launchUrl(getContext(), Uri.parse(url));
55
+
56
+ call.success();
57
+ }
58
+
59
+ @PluginMethod()
60
+ public void openWebView(PluginCall call) {
61
+ String url = call.getString("url");
62
+ if(url == null || TextUtils.isEmpty(url)) {
63
+ call.error("Invalid URL");
64
+ }
65
+ final Options options = new Options();
66
+ options.setUrl(url);
67
+ options.setHeaders(call.getObject("headers"));
68
+ options.setTitle(call.getString("title", "New Window"));
69
+ options.setShareDisclaimer(call.getObject("shareDisclaimer", null));
70
+ options.setShareSubject(call.getString("shareSubject", null));
71
+ options.setToolbarType(call.getString("toolbarType", ""));
72
+ options.setPresentAfterPageLoad(call.getBoolean("isPresentAfterPageLoad", false));
73
+ options.setPluginCall(call);
74
+ options.setCallbacks(new WebViewCallbacks() {
75
+ @Override
76
+ public void urlChangeEvent(String url) {
77
+ notifyListeners("urlChangeEvent", new JSObject().put("url", url));
78
+ }
79
+
80
+ @Override
81
+ public void pageLoaded() {
82
+ notifyListeners("browserPageLoaded", new JSObject());
83
+ }
84
+
85
+ @Override
86
+ public void pageLoadError() {
87
+ notifyListeners("pageLoadError", new JSObject());
88
+ }
89
+ });
90
+ getActivity().runOnUiThread(new Runnable() {
91
+ @Override
92
+ public void run() {
93
+ webViewDialog = new WebViewDialog(getContext(), android.R.style.Theme_NoTitleBar, options);
94
+ webViewDialog.presentWebView();
95
+ }
96
+ });
97
+ }
98
+
99
+ @PluginMethod()
100
+ public void close(PluginCall call) {
101
+ if (webViewDialog != null) {
102
+ webViewDialog.dismiss();
103
+ webViewDialog = null;
104
+ } else {
105
+ Intent intent = new Intent(getContext(), getBridge().getActivity().getClass());
106
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
107
+ getContext().startActivity(intent);
108
+ }
109
+ call.success();
110
+ }
111
+
112
+ private Bundle getHeaders(PluginCall pluginCall) {
113
+ JSObject headersProvided = pluginCall.getObject("headers");
114
+ Bundle headers = new Bundle();
115
+ if(headersProvided != null) {
116
+ Iterator<String> keys = headersProvided.keys();
117
+ while(keys.hasNext()) {
118
+ String key = keys.next();
119
+ headers.putString(key, headersProvided.getString(key));
120
+ }
121
+ }
122
+ return headers;
123
+ }
124
+
125
+ protected void handleOnResume() {
126
+ boolean ok = CustomTabsClient.bindCustomTabsService(getContext(), CUSTOM_TAB_PACKAGE_NAME, connection);
127
+ if (!ok) {
128
+ Log.e(getLogTag(), "Error binding to custom tabs service");
129
+ }
130
+ }
131
+
132
+ protected void handleOnPause() {
133
+ getContext().unbindService(connection);
134
+ }
135
+
136
+ public CustomTabsSession getCustomTabsSession() {
137
+ if (customTabsClient == null) {
138
+ return null;
139
+ }
140
+
141
+ if (currentSession == null) {
142
+ currentSession = customTabsClient.newSession(new CustomTabsCallback(){
143
+ @Override
144
+ public void onNavigationEvent(int navigationEvent, Bundle extras) {
145
+ switch (navigationEvent) {
146
+ case NAVIGATION_FINISHED:
147
+ notifyListeners("browserPageLoaded", new JSObject());
148
+ break;
149
+ }
150
+ }
151
+ });
152
+ }
153
+ return currentSession;
154
+ }
155
+
156
+ @Override
157
+ protected void handleOnActivityResult(int requestCode, int resultCode, Intent data) {
158
+ super.handleOnActivityResult(requestCode, resultCode, data);
159
+ }
160
+ }
@@ -0,0 +1,88 @@
1
+ package ee.forgr.capacitor_inappbrowser;
2
+
3
+ import com.getcapacitor.JSObject;
4
+ import com.getcapacitor.PluginCall;
5
+
6
+ public class Options {
7
+ private String title;
8
+ private String url;
9
+ private JSObject headers;
10
+ private String toolbarType;
11
+ private JSObject shareDisclaimer;
12
+ private String shareSubject;
13
+ private boolean isPresentAfterPageLoad;
14
+ private WebViewCallbacks callbacks;
15
+ private PluginCall pluginCall;
16
+
17
+ public PluginCall getPluginCall() {
18
+ return pluginCall;
19
+ }
20
+
21
+ public void setPluginCall(PluginCall pluginCall) {
22
+ this.pluginCall = pluginCall;
23
+ }
24
+
25
+ public String getTitle() {
26
+ return title;
27
+ }
28
+
29
+ public void setTitle(String title) {
30
+ this.title = title;
31
+ }
32
+
33
+ public String getUrl() {
34
+ return url;
35
+ }
36
+
37
+ public void setUrl(String url) {
38
+ this.url = url;
39
+ }
40
+
41
+ public JSObject getHeaders() {
42
+ return headers;
43
+ }
44
+
45
+ public void setHeaders(JSObject headers) {
46
+ this.headers = headers;
47
+ }
48
+
49
+ public String getToolbarType() {
50
+ return toolbarType;
51
+ }
52
+
53
+ public void setToolbarType(String toolbarType) {
54
+ this.toolbarType = toolbarType;
55
+ }
56
+
57
+ public JSObject getShareDisclaimer() {
58
+ return shareDisclaimer;
59
+ }
60
+
61
+ public void setShareDisclaimer(JSObject shareDisclaimer) {
62
+ this.shareDisclaimer = shareDisclaimer;
63
+ }
64
+
65
+ public String getShareSubject() {
66
+ return shareSubject;
67
+ }
68
+
69
+ public void setShareSubject(String shareSubject) {
70
+ this.shareSubject = shareSubject;
71
+ }
72
+
73
+ public boolean isPresentAfterPageLoad() {
74
+ return isPresentAfterPageLoad;
75
+ }
76
+
77
+ public void setPresentAfterPageLoad(boolean presentAfterPageLoad) {
78
+ isPresentAfterPageLoad = presentAfterPageLoad;
79
+ }
80
+
81
+ public WebViewCallbacks getCallbacks() {
82
+ return callbacks;
83
+ }
84
+
85
+ public void setCallbacks(WebViewCallbacks callbacks) {
86
+ this.callbacks = callbacks;
87
+ }
88
+ }
@@ -0,0 +1,7 @@
1
+ package ee.forgr.capacitor_inappbrowser;
2
+
3
+ public interface WebViewCallbacks {
4
+ public void urlChangeEvent(String url);
5
+ public void pageLoaded();
6
+ public void pageLoadError();
7
+ }
@@ -0,0 +1,218 @@
1
+ package ee.forgr.capacitor_inappbrowser;
2
+
3
+ import android.app.Dialog;
4
+ import android.content.Context;
5
+ import android.graphics.Bitmap;
6
+ import android.support.v7.widget.Toolbar;
7
+ import android.text.TextUtils;
8
+ import android.view.View;
9
+ import android.view.Window;
10
+ import android.view.WindowManager;
11
+ import android.webkit.WebResourceError;
12
+ import android.webkit.WebResourceRequest;
13
+ import android.webkit.WebView;
14
+ import android.webkit.WebViewClient;
15
+ import android.widget.ImageButton;
16
+ import android.widget.TextView;
17
+
18
+ import com.cap.browser.plugin.capbrowser.R;
19
+
20
+ import java.net.URI;
21
+ import java.net.URISyntaxException;
22
+ import java.util.HashMap;
23
+ import java.util.Iterator;
24
+ import java.util.Map;
25
+
26
+ public class WebViewDialog extends Dialog {
27
+ private WebView _webView;
28
+ private Toolbar _toolbar;
29
+ private Options _options;
30
+ private boolean isInitialized = false;
31
+
32
+ public WebViewDialog(Context context, int theme, Options options) {
33
+ super(context, theme);
34
+ this._options = options;
35
+ this.isInitialized = false;
36
+ }
37
+
38
+ public void presentWebView() {
39
+ requestWindowFeature(Window.FEATURE_NO_TITLE);
40
+ setCancelable(true);
41
+ getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
42
+ setContentView(R.layout.activity_browser);
43
+ getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
44
+
45
+ this._webView = findViewById(R.id.browser_view);
46
+
47
+ _webView.getSettings().setJavaScriptEnabled(true);
48
+ _webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
49
+ _webView.getSettings().setDatabaseEnabled(true);
50
+ _webView.getSettings().setDomStorageEnabled(true);
51
+ _webView.getSettings().setPluginState(android.webkit.WebSettings.PluginState.ON);
52
+ _webView.getSettings().setLoadWithOverviewMode(true);
53
+ _webView.getSettings().setUseWideViewPort(true);
54
+
55
+ Map<String, String> requestHeaders = new HashMap<>();
56
+ if(_options.getHeaders() != null) {
57
+ Iterator<String> keys = _options.getHeaders().keys();
58
+ while(keys.hasNext()) {
59
+ String key = keys.next();
60
+ if(TextUtils.equals(key, "User-Agent")) {
61
+ _webView.getSettings().setUserAgentString(_options.getHeaders().getString(key));
62
+ } else {
63
+ requestHeaders.put(key, _options.getHeaders().getString(key));
64
+ }
65
+ }
66
+ }
67
+
68
+ _webView.loadUrl(this._options.getUrl(), requestHeaders);
69
+ _webView.requestFocus();
70
+ _webView.requestFocusFromTouch();
71
+
72
+ setupToolbar();
73
+ setWebViewClient();
74
+
75
+ if(!this._options.isPresentAfterPageLoad()) {
76
+ show();
77
+ _options.getPluginCall().success();
78
+ }
79
+ }
80
+
81
+ private void setTitle(String newTitleText) {
82
+ TextView textView = (TextView) _toolbar.findViewById(R.id.titleText);
83
+ textView.setText(newTitleText);
84
+ }
85
+
86
+ private void setupToolbar() {
87
+ _toolbar = this.findViewById(R.id.tool_bar);
88
+ if(!TextUtils.isEmpty(_options.getTitle())) {
89
+ this.setTitle(_options.getTitle());
90
+ } else {
91
+ try {
92
+ URI uri = new URI(_options.getUrl());
93
+ this.setTitle(uri.getHost());
94
+ } catch (URISyntaxException e) {
95
+ this.setTitle(_options.getTitle());
96
+ }
97
+ }
98
+
99
+ View backButton = _toolbar.findViewById(R.id.backButton);
100
+ backButton.setOnClickListener(new View.OnClickListener() {
101
+ @Override
102
+ public void onClick(View view) {
103
+ if(_webView.canGoBack()) {
104
+ _webView.goBack();
105
+ }
106
+ }
107
+ });
108
+
109
+ View forwardButton = _toolbar.findViewById(R.id.forwardButton);
110
+ forwardButton.setOnClickListener(new View.OnClickListener() {
111
+ @Override
112
+ public void onClick(View view) {
113
+ if(_webView.canGoForward()) {
114
+ _webView.goForward();
115
+ }
116
+ }
117
+ });
118
+
119
+ View closeButton = _toolbar.findViewById(R.id.closeButton);
120
+ closeButton.setOnClickListener(new View.OnClickListener() {
121
+ @Override
122
+ public void onClick(View view) {
123
+ dismiss();
124
+ }
125
+ });
126
+
127
+ if(TextUtils.equals(_options.getToolbarType(), "activity")) {
128
+ _toolbar.findViewById(R.id.forwardButton).setVisibility(View.GONE);
129
+ _toolbar.findViewById(R.id.backButton).setVisibility(View.GONE);
130
+ //TODO: Add share button functionality
131
+ } else if(TextUtils.equals(_options.getToolbarType(), "navigation")) {
132
+ //TODO: Remove share button when implemented
133
+ } else if(TextUtils.equals(_options.getToolbarType(), "blank")){
134
+ _toolbar.setVisibility(View.GONE);
135
+ } else {
136
+ _toolbar.findViewById(R.id.forwardButton).setVisibility(View.GONE);
137
+ _toolbar.findViewById(R.id.backButton).setVisibility(View.GONE);
138
+ }
139
+ }
140
+
141
+ private void setWebViewClient() {
142
+ _webView.setWebViewClient(new WebViewClient() {
143
+
144
+ @Override
145
+ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
146
+ return false;
147
+ }
148
+
149
+ @Override
150
+ public void onLoadResource(WebView view, String url) {
151
+ super.onLoadResource(view, url);
152
+ }
153
+
154
+ @Override
155
+ public void onPageStarted(WebView view, String url, Bitmap favicon) {
156
+ super.onPageStarted(view, url, favicon);
157
+ try {
158
+ URI uri = new URI(url);
159
+ setTitle(uri.getHost());
160
+ } catch (URISyntaxException e) {
161
+ // Do nothing
162
+ }
163
+ _options.getCallbacks().urlChangeEvent(url);
164
+ }
165
+
166
+ @Override
167
+ public void onPageFinished(WebView view, String url) {
168
+ super.onPageFinished(view, url);
169
+ _options.getCallbacks().pageLoaded();
170
+ if(!isInitialized) {
171
+ isInitialized = true;
172
+ _webView.clearHistory();
173
+ if(_options.isPresentAfterPageLoad()) {
174
+ show();
175
+ _options.getPluginCall().success();
176
+ }
177
+ }
178
+
179
+ ImageButton backButton = _toolbar.findViewById(R.id.backButton);
180
+ if(_webView.canGoBack()) {
181
+ backButton.setImageResource(R.drawable.arrow_back_enabled);
182
+ backButton.setEnabled(true);
183
+ } else {
184
+ backButton.setImageResource(R.drawable.arrow_back_disabled);
185
+ backButton.setEnabled(false);
186
+ }
187
+
188
+ ImageButton forwardButton = _toolbar.findViewById(R.id.forwardButton);
189
+ if(_webView.canGoForward()) {
190
+ forwardButton.setImageResource(R.drawable.arrow_forward_enabled);
191
+ forwardButton.setEnabled(true);
192
+ } else {
193
+ forwardButton.setImageResource(R.drawable.arrow_forward_disabled);
194
+ forwardButton.setEnabled(false);
195
+ }
196
+
197
+ _options.getCallbacks().pageLoaded();
198
+ }
199
+
200
+ @Override
201
+ public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
202
+ super.onReceivedError(view, request, error);
203
+ _options.getCallbacks().pageLoadError();
204
+ }
205
+ });
206
+ }
207
+
208
+
209
+
210
+ @Override
211
+ public void onBackPressed() {
212
+ if(_webView.canGoBack() && TextUtils.equals(_options.getToolbarType(), "navigation")) {
213
+ _webView.goBack();
214
+ } else {
215
+ super.onBackPressed();
216
+ }
217
+ }
218
+ }
File without changes
@@ -0,0 +1,9 @@
1
+ <vector xmlns:android="http://schemas.android.com/apk/res/android"
2
+ android:width="24dp"
3
+ android:height="24dp"
4
+ android:viewportWidth="24"
5
+ android:viewportHeight="24">
6
+ <path
7
+ android:fillColor="@color/disable"
8
+ android:pathData="M11.67,3.87L9.9,2.1 0,12l9.9,9.9 1.77,-1.77L3.54,12z"/>
9
+ </vector>
@@ -0,0 +1,9 @@
1
+ <vector xmlns:android="http://schemas.android.com/apk/res/android"
2
+ android:width="24dp"
3
+ android:height="24dp"
4
+ android:viewportWidth="24"
5
+ android:viewportHeight="24">
6
+ <path
7
+ android:fillColor="@color/enable"
8
+ android:pathData="M11.67,3.87L9.9,2.1 0,12l9.9,9.9 1.77,-1.77L3.54,12z"/>
9
+ </vector>