[ 
https://issues.apache.org/jira/browse/CB-13791?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16337968#comment-16337968
 ] 

ASF GitHub Bot commented on CB-13791:
-------------------------------------

infil00p closed pull request #258: CB-13791: (android) Add Android support for 
a footer close button
URL: https://github.com/apache/cordova-plugin-inappbrowser/pull/258
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/README.md b/README.md
index 7a2ec96a..936f1dce 100644
--- a/README.md
+++ b/README.md
@@ -112,9 +112,13 @@ instance, or the system browser.
     - __hidden__: set to `yes` to create the browser and load the page, but 
not show it. The loadstop event fires when loading is complete. Omit or set to 
`no` (default) to have the browser open and load normally.
     - __clearcache__: set to `yes` to have the browser's cookie cache cleared 
before the new window is opened
     - __clearsessioncache__: set to `yes` to have the session cookie cache 
cleared before the new window is opened
-    - __closebuttoncaption__: set to a string to use as the close buttons 
caption instead of a X. Note that you need to localize this value yourself.
+    - __closebuttoncaption__: set to a string to use as the close button's 
caption instead of a X. Note that you need to localize this value yourself.
     - __closebuttoncolor__: set to a valid hex color string, for example: 
`#00ff00`, and it will change the
     close button color from default, regardless of being a text or default X. 
Only has effect if user has location set to `yes`.
+    - __footer__: set to `yes` to show a close button in the footer similar to 
the iOS __Done__ button. 
+    The close button will appear the same as for the header hence use 
__closebuttoncaption__ and __closebuttoncolor__ to set its properties.
+    - __footercolor__: set to a valid hex color string, for example `#00ff00` 
or `#CC00ff00` (`#aarrggbb`) , and it will change the footer color from default.
+    Only has effect if user has __footer__ set to `yes`.
     - __hardwareback__: set to `yes` to use the hardware back button to 
navigate backwards through the `InAppBrowser`'s history. If there is no 
previous page, the `InAppBrowser` will close.  The default value is `yes`, so 
you must set it to `no` if you want the back button to simply close the 
InAppBrowser.
     - __hidenavigationbuttons__: set to `yes` to hide the navigation buttons 
on the location toolbar, only has effect if user has location set to `yes`. The 
default value is `no`.
     - __hideurlbar__: set to `yes` to hide the url bar on the location 
toolbar, only has effect if user has location set to `yes`. The default value 
is `no`.
diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java
index 8f937fb7..2b0dbe0f 100644
--- a/src/android/InAppBrowser.java
+++ b/src/android/InAppBrowser.java
@@ -103,8 +103,10 @@ Licensed to the Apache Software Foundation (ASF) under one
     private static final String HIDE_NAVIGATION = "hidenavigationbuttons";
     private static final String NAVIGATION_COLOR = "navigationbuttoncolor";
     private static final String HIDE_URL = "hideurlbar";
+    private static final String FOOTER = "footer";
+    private static final String FOOTER_COLOR = "footercolor";
 
-    private static final List customizableOptions = 
Arrays.asList(CLOSE_BUTTON_CAPTION, TOOLBAR_COLOR, NAVIGATION_COLOR, 
CLOSE_BUTTON_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;
@@ -129,6 +131,8 @@ Licensed to the Apache Software Foundation (ASF) under one
     private boolean hideNavigationButtons = false;
     private String navigationButtonColor = "";
     private boolean hideUrlBar = false;
+    private boolean showFooter = false;
+    private String footerColor = "";
 
     /**
      * Executes the request and returns PluginResult.
@@ -397,11 +401,9 @@ public void run() {
                 option = new StringTokenizer(features.nextToken(), "=");
                 if (option.hasMoreElements()) {
                     String key = option.nextToken();
-                    String value = null;
-                    if (customizableOptions.contains(key)) value = 
option.nextToken();
-                    else {
-                      String token = option.nextToken();
-                      value = token.equals("yes") || token.equals("no") ? 
token : "yes";
+                    String value = option.nextToken();
+                    if (!customizableOptions.contains(key)){
+                        value = value.equals("yes") || value.equals("no") ? 
value : "yes";
                     }
                     map.put(key, value);
                 }
@@ -431,7 +433,7 @@ public String openExternal(String url) {
             intent.putExtra(Browser.EXTRA_APPLICATION_ID, 
cordova.getActivity().getPackageName());
             this.cordova.getActivity().startActivity(intent);
             return "";
-        // not catching FileUriExposedException explicitly because 
buildtools<24 doesn't know about it
+            // not catching FileUriExposedException explicitly because 
buildtools<24 doesn't know about it
         } catch (java.lang.RuntimeException e) {
             LOG.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ 
e.toString());
             return e.toString();
@@ -561,10 +563,10 @@ public String showWebPage(final String url, 
HashMap<String, String> features) {
                 showLocationBar = show.equals("yes") ? true : false;
             }
             if(showLocationBar) {
-              String hideNavigation = features.get(HIDE_NAVIGATION);
-              String hideUrl = features.get(HIDE_URL);
-              if(hideNavigation != null) hideNavigationButtons = 
hideNavigation.equals("yes") ? true : false;
-              if(hideUrl != null) hideUrlBar = hideUrl.equals("yes") ? true : 
false;
+                String hideNavigation = features.get(HIDE_NAVIGATION);
+                String hideUrl = features.get(HIDE_URL);
+                if(hideNavigation != null) hideNavigationButtons = 
hideNavigation.equals("yes") ? true : false;
+                if(hideUrl != null) hideUrlBar = hideUrl.equals("yes") ? true 
: false;
             }
             String zoom = features.get(ZOOM);
             if (zoom != null) {
@@ -599,7 +601,7 @@ public String showWebPage(final String url, HashMap<String, 
String> features) {
             }
             String wideViewPort = features.get(USER_WIDE_VIEW_PORT);
             if (wideViewPort != null ) {
-                           useWideViewPort = wideViewPort.equals("yes") ? true 
: false;
+                useWideViewPort = wideViewPort.equals("yes") ? true : false;
             }
             String closeButtonCaptionSet = features.get(CLOSE_BUTTON_CAPTION);
             if (closeButtonCaptionSet != null) {
@@ -607,7 +609,7 @@ public String showWebPage(final String url, HashMap<String, 
String> features) {
             }
             String closeButtonColorSet = features.get(CLOSE_BUTTON_COLOR);
             if (closeButtonColorSet != null) {
-              closeButtonColor = closeButtonColorSet;
+                closeButtonColor = closeButtonColorSet;
             }
             String toolbarColorSet = features.get(TOOLBAR_COLOR);
             if (toolbarColorSet != null) {
@@ -617,6 +619,14 @@ public String showWebPage(final String url, 
HashMap<String, String> features) {
             if (navigationButtonColorSet != null) {
                 navigationButtonColor = navigationButtonColorSet;
             }
+            String showFooterSet = features.get(FOOTER);
+            if (showFooterSet != null) {
+                showFooter = showFooterSet.equals("yes") ? true : false;
+            }
+            String footerColorSet = features.get(FOOTER_COLOR);
+            if (footerColorSet != null) {
+                footerColor = footerColorSet;
+            }
         }
 
         final CordovaWebView thatWebView = this.webView;
@@ -630,13 +640,60 @@ public String showWebPage(final String url, 
HashMap<String, String> features) {
              */
             private int dpToPixels(int dipValue) {
                 int value = (int) TypedValue.applyDimension( 
TypedValue.COMPLEX_UNIT_DIP,
-                                                            (float) dipValue,
-                                                            
cordova.getActivity().getResources().getDisplayMetrics()
+                        (float) dipValue,
+                        
cordova.getActivity().getResources().getDisplayMetrics()
                 );
 
                 return value;
             }
 
+            private View createCloseButton(int id){
+                View _close;
+                Resources activityRes = cordova.getActivity().getResources();
+
+                if (closeButtonCaption != "") {
+                    // Use TextView for text
+                    TextView close = new TextView(cordova.getActivity());
+                    close.setText(closeButtonCaption);
+                    close.setTextSize(20);
+                    if (closeButtonColor != "") 
close.setTextColor(android.graphics.Color.parseColor(closeButtonColor));
+                    close.setGravity(android.view.Gravity.CENTER_VERTICAL);
+                    close.setPadding(this.dpToPixels(10), 0, 
this.dpToPixels(10), 0);
+                    _close = close;
+                }
+                else {
+                    ImageButton close = new ImageButton(cordova.getActivity());
+                    int closeResId = 
activityRes.getIdentifier("ic_action_remove", "drawable", 
cordova.getActivity().getPackageName());
+                    Drawable closeIcon = activityRes.getDrawable(closeResId);
+                    if (closeButtonColor != "") 
close.setColorFilter(android.graphics.Color.parseColor(closeButtonColor));
+                    close.setImageDrawable(closeIcon);
+                    close.setScaleType(ImageView.ScaleType.FIT_CENTER);
+                    if (Build.VERSION.SDK_INT >= 16)
+                        close.getAdjustViewBounds();
+
+                    _close = close;
+                }
+
+                RelativeLayout.LayoutParams closeLayoutParams = new 
RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 
LayoutParams.MATCH_PARENT);
+                closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
+                _close.setLayoutParams(closeLayoutParams);
+
+                if (Build.VERSION.SDK_INT >= 16)
+                    _close.setBackground(null);
+                else
+                    _close.setBackgroundDrawable(null);
+
+                _close.setContentDescription("Close Button");
+                _close.setId(Integer.valueOf(id));
+                _close.setOnClickListener(new View.OnClickListener() {
+                    public void onClick(View v) {
+                        closeDialog();
+                    }
+                });
+
+                return _close;
+            }
+
             @SuppressLint("NewApi")
             public void run() {
 
@@ -741,67 +798,37 @@ public void onClick(View v) {
                     public boolean onKey(View v, int keyCode, KeyEvent event) {
                         // If the event is a key-down event on the "enter" 
button
                         if ((event.getAction() == KeyEvent.ACTION_DOWN) && 
(keyCode == KeyEvent.KEYCODE_ENTER)) {
-                          navigate(edittext.getText().toString());
-                          return true;
+                            navigate(edittext.getText().toString());
+                            return true;
                         }
                         return false;
                     }
                 });
 
-                // Close/Done button
-                if (closeButtonCaption != "") {
-                  // Use TextView for text
-                  TextView close = new TextView(cordova.getActivity());
-                  close.setText(closeButtonCaption);
-                  close.setTextSize(20);
-                  if (closeButtonColor != "") 
close.setTextColor(android.graphics.Color.parseColor(closeButtonColor));
-                  close.setGravity(android.view.Gravity.CENTER_VERTICAL);
-                  RelativeLayout.LayoutParams closeLayoutParams = new 
RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 
LayoutParams.MATCH_PARENT);
-                  closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
-                  close.setLayoutParams(closeLayoutParams);
-
-                  close.setContentDescription("Close Button");
-                  close.setId(Integer.valueOf(5));
-                  if (Build.VERSION.SDK_INT >= 16)
-                      close.setBackground(null);
-                  else
-                      close.setBackgroundDrawable(null);
-                  back.setPadding(0, this.dpToPixels(10), 0, 
this.dpToPixels(10));
-                  close.setPadding(this.dpToPixels(10), 0, 
this.dpToPixels(10), 0);
-                  close.setOnClickListener(new View.OnClickListener() {
-                      public void onClick(View v) {
-                          closeDialog();
-                      }
-                  });
-                  toolbar.addView(close);
-                }
-                else {
-                  ImageButton close = new ImageButton(cordova.getActivity());
-                  RelativeLayout.LayoutParams closeLayoutParams = new 
RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 
LayoutParams.MATCH_PARENT);
-                  closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
-                  close.setLayoutParams(closeLayoutParams);
-                  close.setContentDescription("Close Button");
-                  close.setId(Integer.valueOf(5));
-                  int closeResId = 
activityRes.getIdentifier("ic_action_remove", "drawable", 
cordova.getActivity().getPackageName());
-                  Drawable closeIcon = activityRes.getDrawable(closeResId);
-                  if (closeButtonColor != "") 
close.setColorFilter(android.graphics.Color.parseColor(closeButtonColor));
-                  if (Build.VERSION.SDK_INT >= 16)
-                      close.setBackground(null);
-                  else
-                      close.setBackgroundDrawable(null);
-                  close.setImageDrawable(closeIcon);
-                  close.setScaleType(ImageView.ScaleType.FIT_CENTER);
-                  back.setPadding(0, this.dpToPixels(10), 0, 
this.dpToPixels(10));
-                  if (Build.VERSION.SDK_INT >= 16)
-                      close.getAdjustViewBounds();
-
-                  close.setOnClickListener(new View.OnClickListener() {
-                      public void onClick(View v) {
-                          closeDialog();
-                      }
-                  });
-                  toolbar.addView(close);
+
+                // Header Close/Done button
+                View close = createCloseButton(5);
+                toolbar.addView(close);
+
+                // Footer
+                RelativeLayout footer = new 
RelativeLayout(cordova.getActivity());
+                int _footerColor;
+                if(footerColor != ""){
+                    _footerColor = Color.parseColor(footerColor);
+                }else{
+                    _footerColor = android.graphics.Color.LTGRAY;
                 }
+                footer.setBackgroundColor(_footerColor);
+                RelativeLayout.LayoutParams footerLayout = new 
RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44));
+                footerLayout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 
RelativeLayout.TRUE);
+                footer.setLayoutParams(footerLayout);
+                if (closeButtonCaption != "") 
footer.setPadding(this.dpToPixels(8), this.dpToPixels(8), this.dpToPixels(8), 
this.dpToPixels(8));
+                footer.setHorizontalGravity(Gravity.LEFT);
+                footer.setVerticalGravity(Gravity.BOTTOM);
+
+                View footerClose = createCloseButton(7);
+                footer.addView(footerClose);
+
 
                 // WebView
                 inAppWebView = new WebView(cordova.getActivity());
@@ -915,7 +942,14 @@ public void openFileChooser(ValueCallback<Uri> uploadMsg, 
String acceptType)
                 }
 
                 // Add our webview to our main view/layout
-                main.addView(inAppWebView);
+                RelativeLayout webViewLayout = new 
RelativeLayout(cordova.getActivity());
+                webViewLayout.addView(inAppWebView);
+                main.addView(webViewLayout);
+
+                // Don't add the footer unless it's been enabled
+                if (showFooter) {
+                    webViewLayout.addView(footer);
+                }
 
                 WindowManager.LayoutParams lp = new 
WindowManager.LayoutParams();
                 lp.copyFrom(dialog.getWindow().getAttributes());
@@ -1105,7 +1139,7 @@ public void onPageStarted(WebView view, String url, 
Bitmap favicon) {
             // Update the UI if we haven't already
             if (!newloc.equals(edittext.getText().toString())) {
                 edittext.setText(newloc);
-             }
+            }
 
             try {
                 JSONObject obj = new JSONObject();


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Add Android support for a footer close button.
> ----------------------------------------------
>
>                 Key: CB-13791
>                 URL: https://issues.apache.org/jira/browse/CB-13791
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: cordova-plugin-inappbrowser
>         Environment: Android
>            Reporter: Dave Alden
>            Priority: Minor
>              Labels: features, newbie
>
> Extending the work done in [PR 
> #246|https://github.com/apache/cordova-plugin-inappbrowser/pull/246] under 
> CB-13409, this adds support to Android for a footer close button similar to 
> the "Done" button on iOS.
> The following options are added for Android:
>  * *footer* - set to "yes" to show a close button in the footer similar to 
> the iOS "Done" button.
>  The close button will appear the same as for the header hence use 
> _closebuttoncaption_ and _closebuttoncolor_ to set its properties.
>  * *footercolor* - set to a valid hex color string, for example #00ff00 or 
> #CC00ff00 (#aarrggbb) , and it will change the footer color from default. 
> Only has effect if user has _footer_ set to "yes".
> Here are some example screenshots with the relevant options:
> _location=yes,footer=yes_
>  
> !https://user-images.githubusercontent.com/2345062/33147006-2a602f88-cfbe-11e7-9580-438b07236400.png|width=300!
> _location=no,footer=yes_
>  
> !https://user-images.githubusercontent.com/2345062/33147147-a60efaba-cfbe-11e7-8132-120179e8b43e.png|width=300!
> _location=yes,footer=yes,closebuttoncaption=Done_
>  
> !https://user-images.githubusercontent.com/2345062/33147185-ca8d1e6c-cfbe-11e7-9646-0e1cea52abce.png|width=300!
> _location=no,footer=yes,closebuttoncaption=Done,closebuttoncolor=#0000ff_
>  
> !https://user-images.githubusercontent.com/2345062/33147285-1aa7bc54-cfbf-11e7-9b9b-576f0d87ed9a.png|width=300!
> _location=no,footer=yes,footercolor=#0000ff,closebuttoncaption=Done_
>  
> !https://user-images.githubusercontent.com/2345062/33147316-3ab511fe-cfbf-11e7-8b19-d1de80ad289e.png|width=300!
> _location=no,footer=yes,footercolor=#00ff00,closebuttoncaption=Done,closebuttoncolor=#0000ff_
>  
> !https://user-images.githubusercontent.com/2345062/33147348-581b55c8-cfbf-11e7-9490-c61d83957079.png|width=300!
> _location=no,footer=yes,footercolor=#CC000000,closebuttoncaption=Done,closebuttoncolor=#00FFFF_
>  
> !https://user-images.githubusercontent.com/2345062/33147377-6ec46c6a-cfbf-11e7-969e-a075142133c4.png|width=300!



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to