From 1ae403b51fae4195b97b00f5ef2124b8bdafd8c9 Mon Sep 17 00:00:00 2001 From: Florian Quirin Date: Tue, 19 Jul 2022 20:50:57 +0200 Subject: [PATCH 1/5] removed redundant code and fixed 'hadwareBackButton' typo - 'hardwareBackButton' was misspelled - 'showWebPage' redefined some defaults that should be set at the top --- src/android/InAppBrowser.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index 76dc150cc..026f14800 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -130,7 +130,7 @@ public class InAppBrowser extends CordovaPlugin { private boolean openWindowHidden = false; private boolean clearAllCache = false; private boolean clearSessionCache = false; - private boolean hadwareBackButton = true; + private boolean hardwareBackButton = true; private boolean mediaPlaybackRequiresUserGesture = false; private boolean shouldPauseInAppBrowser = false; private boolean useWideViewPort = true; @@ -576,7 +576,7 @@ public boolean canGoBack() { * @return boolean */ public boolean hardwareBack() { - return hadwareBackButton; + return hardwareBackButton; } /** @@ -626,12 +626,6 @@ private InAppBrowser getInAppBrowser() { * @param features jsonObject */ public String showWebPage(final String url, HashMap features) { - // 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) { @@ -653,9 +647,9 @@ public String showWebPage(final String url, HashMap features) { } String hardwareBack = features.get(HARDWARE_BACK_BUTTON); if (hardwareBack != null) { - hadwareBackButton = hardwareBack.equals("yes") ? true : false; + hardwareBackButton = hardwareBack.equals("yes") ? true : false; } else { - hadwareBackButton = DEFAULT_HARDWARE_BACK; + hardwareBackButton = DEFAULT_HARDWARE_BACK; } String mediaPlayback = features.get(MEDIA_PLAYBACK_REQUIRES_USER_ACTION); if (mediaPlayback != null) { From bc4c7ded4bc846ddbdca8eccbff27d1b68f8407a Mon Sep 17 00:00:00 2001 From: Florian Quirin Date: Tue, 19 Jul 2022 20:57:11 +0200 Subject: [PATCH 2/5] made 'customizableOptions' more readable --- src/android/InAppBrowser.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index 026f14800..4ec3d7c83 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -119,7 +119,8 @@ public class InAppBrowser extends CordovaPlugin { private static final int TOOLBAR_HEIGHT = 48; - private static final List customizableOptions = Arrays.asList(CLOSE_BUTTON_CAPTION, TOOLBAR_COLOR, NAVIGATION_COLOR, CLOSE_BUTTON_COLOR, FOOTER_COLOR); + private static final List customizableOptions = Arrays.asList( + CLOSE_BUTTON_CAPTION, TOOLBAR_COLOR, NAVIGATION_COLOR, CLOSE_BUTTON_COLOR, FOOTER_COLOR); private InAppBrowserDialog dialog; private WebView inAppWebView; From b427e15ed98fdee1b1e638c387200f5a858d7ebb Mon Sep 17 00:00:00 2001 From: Florian Quirin Date: Tue, 19 Jul 2022 21:18:43 +0200 Subject: [PATCH 3/5] better organize drawable resources --- src/android/InAppBrowser.java | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index 4ec3d7c83..f293ce07d 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -122,6 +122,11 @@ public class InAppBrowser extends CordovaPlugin { private static final List customizableOptions = Arrays.asList( CLOSE_BUTTON_CAPTION, TOOLBAR_COLOR, NAVIGATION_COLOR, CLOSE_BUTTON_COLOR, FOOTER_COLOR); + // Resources + private static final String TOOLBAR_CLOSE_BUTTON = "ic_action_remove"; + private static final String TOOLBAR_BACK_BUTTON = "ic_action_previous_item"; + private static final String TOOLBAR_FORWARD_BUTTON = "ic_action_next_item"; + private InAppBrowserDialog dialog; private WebView inAppWebView; private EditText edittext; @@ -619,6 +624,15 @@ private boolean getShowLocationBar() { private InAppBrowser getInAppBrowser() { return this; } + + /** + * Get a drawable by name from the main package. + */ + private Drawable getDrawableFromResources(String name){ + Resources activityRes = cordova.getActivity().getResources(); + int resId = activityRes.getIdentifier(name, "drawable", cordova.getActivity().getPackageName()); + return activityRes.getDrawable(resId, cordova.getActivity().getTheme()); + } /** * Display a new browser with the specified URL. @@ -743,8 +757,7 @@ private View createCloseButton(int id) { } else { ImageButton close = new ImageButton(cordova.getActivity()); - int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName()); - Drawable closeIcon = activityRes.getDrawable(closeResId); + Drawable closeIcon = getDrawableFromResources(TOOLBAR_CLOSE_BUTTON); if (closeButtonColor != "") close.setColorFilter(android.graphics.Color.parseColor(closeButtonColor)); close.setImageDrawable(closeIcon); close.setScaleType(ImageView.ScaleType.FIT_CENTER); @@ -823,8 +836,7 @@ public void run() { back.setContentDescription("Back Button"); back.setId(Integer.valueOf(2)); Resources activityRes = cordova.getActivity().getResources(); - int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName()); - Drawable backIcon = activityRes.getDrawable(backResId); + Drawable backIcon = getDrawableFromResources(TOOLBAR_BACK_BUTTON); if (navigationButtonColor != "") back.setColorFilter(android.graphics.Color.parseColor(navigationButtonColor)); back.setBackground(null); back.setImageDrawable(backIcon); @@ -845,8 +857,7 @@ public void onClick(View v) { forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(Integer.valueOf(3)); - int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName()); - Drawable fwdIcon = activityRes.getDrawable(fwdResId); + Drawable fwdIcon = getDrawableFromResources(TOOLBAR_FORWARD_BUTTON); if (navigationButtonColor != "") forward.setColorFilter(android.graphics.Color.parseColor(navigationButtonColor)); forward.setBackground(null); forward.setImageDrawable(fwdIcon); From e531c7df95b8f16534b46fa68e1afdf46230bc3d Mon Sep 17 00:00:00 2001 From: Florian Quirin Date: Tue, 19 Jul 2022 21:28:42 +0200 Subject: [PATCH 4/5] new Android option 'enablethirdpartycookies' (default yes) --- src/android/InAppBrowser.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index f293ce07d..6c170dad8 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -100,6 +100,7 @@ public class InAppBrowser extends CordovaPlugin { private static final String MESSAGE_EVENT = "message"; private static final String CLEAR_ALL_CACHE = "clearcache"; private static final String CLEAR_SESSION_CACHE = "clearsessioncache"; + private static final String ENABLE_THIRD_PARTY_COOKIES = "enablethirdpartycookies"; private static final String HARDWARE_BACK_BUTTON = "hardwareback"; private static final String MEDIA_PLAYBACK_REQUIRES_USER_ACTION = "mediaPlaybackRequiresUserAction"; private static final String SHOULD_PAUSE = "shouldPauseOnSuspend"; @@ -136,6 +137,7 @@ public class InAppBrowser extends CordovaPlugin { private boolean openWindowHidden = false; private boolean clearAllCache = false; private boolean clearSessionCache = false; + private boolean enableThirdPartyCookies = true; private boolean hardwareBackButton = true; private boolean mediaPlaybackRequiresUserGesture = false; private boolean shouldPauseInAppBrowser = false; @@ -679,6 +681,10 @@ public String showWebPage(final String url, HashMap features) { clearSessionCache = cache.equals("yes") ? true : false; } } + String thirdPartyCookies = features.get(ENABLE_THIRD_PARTY_COOKIES); + if (thirdPartyCookies != null) { + enableThirdPartyCookies = thirdPartyCookies.equals("yes") ? true : false; + } String shouldPause = features.get(SHOULD_PAUSE); if (shouldPause != null) { shouldPauseInAppBrowser = shouldPause.equals("yes") ? true : false; @@ -807,7 +813,7 @@ public void run() { // Toolbar layout RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); - //Please, no more black! + //"Please, no more black!" <- who said this?!? Black is awesome, especially on OLED! ^^ toolbar.setBackgroundColor(toolbarColor); toolbar.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(TOOLBAR_HEIGHT))); toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); @@ -998,7 +1004,7 @@ public void postMessage(String data) { } // Enable Thirdparty Cookies - CookieManager.getInstance().setAcceptThirdPartyCookies(inAppWebView,true); + CookieManager.getInstance().setAcceptThirdPartyCookies(inAppWebView, enableThirdPartyCookies); inAppWebView.loadUrl(url); inAppWebView.setId(Integer.valueOf(6)); From 43527867c79e8452cdba1df862542d4eee6af75d Mon Sep 17 00:00:00 2001 From: Florian Quirin Date: Tue, 19 Jul 2022 21:35:17 +0200 Subject: [PATCH 5/5] minor style fix --- src/android/InAppBrowser.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index 6c170dad8..1c60b766f 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -124,9 +124,9 @@ public class InAppBrowser extends CordovaPlugin { CLOSE_BUTTON_CAPTION, TOOLBAR_COLOR, NAVIGATION_COLOR, CLOSE_BUTTON_COLOR, FOOTER_COLOR); // Resources - private static final String TOOLBAR_CLOSE_BUTTON = "ic_action_remove"; - private static final String TOOLBAR_BACK_BUTTON = "ic_action_previous_item"; - private static final String TOOLBAR_FORWARD_BUTTON = "ic_action_next_item"; + private static final String TOOLBAR_CLOSE_BUTTON = "ic_action_remove"; + private static final String TOOLBAR_BACK_BUTTON = "ic_action_previous_item"; + private static final String TOOLBAR_FORWARD_BUTTON = "ic_action_next_item"; private InAppBrowserDialog dialog; private WebView inAppWebView;