@@ -103,8 +103,10 @@ public class InAppBrowser extends CordovaPlugin {
103
103
private static final String HIDE_NAVIGATION = "hidenavigationbuttons" ;
104
104
private static final String NAVIGATION_COLOR = "navigationbuttoncolor" ;
105
105
private static final String HIDE_URL = "hideurlbar" ;
106
+ private static final String FOOTER = "footer" ;
107
+ private static final String FOOTER_COLOR = "footercolor" ;
106
108
107
- private static final List customizableOptions = Arrays .asList (CLOSE_BUTTON_CAPTION , TOOLBAR_COLOR , NAVIGATION_COLOR , CLOSE_BUTTON_COLOR );
109
+ private static final List customizableOptions = Arrays .asList (CLOSE_BUTTON_CAPTION , TOOLBAR_COLOR , NAVIGATION_COLOR , CLOSE_BUTTON_COLOR , FOOTER_COLOR );
108
110
109
111
private InAppBrowserDialog dialog ;
110
112
private WebView inAppWebView ;
@@ -129,6 +131,8 @@ public class InAppBrowser extends CordovaPlugin {
129
131
private boolean hideNavigationButtons = false ;
130
132
private String navigationButtonColor = "" ;
131
133
private boolean hideUrlBar = false ;
134
+ private boolean showFooter = false ;
135
+ private String footerColor = "" ;
132
136
133
137
/**
134
138
* Executes the request and returns PluginResult.
@@ -397,11 +401,9 @@ private HashMap<String, String> parseFeature(String optString) {
397
401
option = new StringTokenizer (features .nextToken (), "=" );
398
402
if (option .hasMoreElements ()) {
399
403
String key = option .nextToken ();
400
- String value = null ;
401
- if (customizableOptions .contains (key )) value = option .nextToken ();
402
- else {
403
- String token = option .nextToken ();
404
- value = token .equals ("yes" ) || token .equals ("no" ) ? token : "yes" ;
404
+ String value = option .nextToken ();
405
+ if (!customizableOptions .contains (key )){
406
+ value = value .equals ("yes" ) || value .equals ("no" ) ? value : "yes" ;
405
407
}
406
408
map .put (key , value );
407
409
}
@@ -431,7 +433,7 @@ public String openExternal(String url) {
431
433
intent .putExtra (Browser .EXTRA_APPLICATION_ID , cordova .getActivity ().getPackageName ());
432
434
this .cordova .getActivity ().startActivity (intent );
433
435
return "" ;
434
- // not catching FileUriExposedException explicitly because buildtools<24 doesn't know about it
436
+ // not catching FileUriExposedException explicitly because buildtools<24 doesn't know about it
435
437
} catch (java .lang .RuntimeException e ) {
436
438
LOG .d (LOG_TAG , "InAppBrowser: Error loading url " +url +":" + e .toString ());
437
439
return e .toString ();
@@ -561,10 +563,10 @@ public String showWebPage(final String url, HashMap<String, String> features) {
561
563
showLocationBar = show .equals ("yes" ) ? true : false ;
562
564
}
563
565
if (showLocationBar ) {
564
- String hideNavigation = features .get (HIDE_NAVIGATION );
565
- String hideUrl = features .get (HIDE_URL );
566
- if (hideNavigation != null ) hideNavigationButtons = hideNavigation .equals ("yes" ) ? true : false ;
567
- if (hideUrl != null ) hideUrlBar = hideUrl .equals ("yes" ) ? true : false ;
566
+ String hideNavigation = features .get (HIDE_NAVIGATION );
567
+ String hideUrl = features .get (HIDE_URL );
568
+ if (hideNavigation != null ) hideNavigationButtons = hideNavigation .equals ("yes" ) ? true : false ;
569
+ if (hideUrl != null ) hideUrlBar = hideUrl .equals ("yes" ) ? true : false ;
568
570
}
569
571
String zoom = features .get (ZOOM );
570
572
if (zoom != null ) {
@@ -599,15 +601,15 @@ public String showWebPage(final String url, HashMap<String, String> features) {
599
601
}
600
602
String wideViewPort = features .get (USER_WIDE_VIEW_PORT );
601
603
if (wideViewPort != null ) {
602
- useWideViewPort = wideViewPort .equals ("yes" ) ? true : false ;
604
+ useWideViewPort = wideViewPort .equals ("yes" ) ? true : false ;
603
605
}
604
606
String closeButtonCaptionSet = features .get (CLOSE_BUTTON_CAPTION );
605
607
if (closeButtonCaptionSet != null ) {
606
608
closeButtonCaption = closeButtonCaptionSet ;
607
609
}
608
610
String closeButtonColorSet = features .get (CLOSE_BUTTON_COLOR );
609
611
if (closeButtonColorSet != null ) {
610
- closeButtonColor = closeButtonColorSet ;
612
+ closeButtonColor = closeButtonColorSet ;
611
613
}
612
614
String toolbarColorSet = features .get (TOOLBAR_COLOR );
613
615
if (toolbarColorSet != null ) {
@@ -617,6 +619,14 @@ public String showWebPage(final String url, HashMap<String, String> features) {
617
619
if (navigationButtonColorSet != null ) {
618
620
navigationButtonColor = navigationButtonColorSet ;
619
621
}
622
+ String showFooterSet = features .get (FOOTER );
623
+ if (showFooterSet != null ) {
624
+ showFooter = showFooterSet .equals ("yes" ) ? true : false ;
625
+ }
626
+ String footerColorSet = features .get (FOOTER_COLOR );
627
+ if (footerColorSet != null ) {
628
+ footerColor = footerColorSet ;
629
+ }
620
630
}
621
631
622
632
final CordovaWebView thatWebView = this .webView ;
@@ -630,13 +640,60 @@ public String showWebPage(final String url, HashMap<String, String> features) {
630
640
*/
631
641
private int dpToPixels (int dipValue ) {
632
642
int value = (int ) TypedValue .applyDimension ( TypedValue .COMPLEX_UNIT_DIP ,
633
- (float ) dipValue ,
634
- cordova .getActivity ().getResources ().getDisplayMetrics ()
643
+ (float ) dipValue ,
644
+ cordova .getActivity ().getResources ().getDisplayMetrics ()
635
645
);
636
646
637
647
return value ;
638
648
}
639
649
650
+ private View createCloseButton (int id ){
651
+ View _close ;
652
+ Resources activityRes = cordova .getActivity ().getResources ();
653
+
654
+ if (closeButtonCaption != "" ) {
655
+ // Use TextView for text
656
+ TextView close = new TextView (cordova .getActivity ());
657
+ close .setText (closeButtonCaption );
658
+ close .setTextSize (20 );
659
+ if (closeButtonColor != "" ) close .setTextColor (android .graphics .Color .parseColor (closeButtonColor ));
660
+ close .setGravity (android .view .Gravity .CENTER_VERTICAL );
661
+ close .setPadding (this .dpToPixels (10 ), 0 , this .dpToPixels (10 ), 0 );
662
+ _close = close ;
663
+ }
664
+ else {
665
+ ImageButton close = new ImageButton (cordova .getActivity ());
666
+ int closeResId = activityRes .getIdentifier ("ic_action_remove" , "drawable" , cordova .getActivity ().getPackageName ());
667
+ Drawable closeIcon = activityRes .getDrawable (closeResId );
668
+ if (closeButtonColor != "" ) close .setColorFilter (android .graphics .Color .parseColor (closeButtonColor ));
669
+ close .setImageDrawable (closeIcon );
670
+ close .setScaleType (ImageView .ScaleType .FIT_CENTER );
671
+ if (Build .VERSION .SDK_INT >= 16 )
672
+ close .getAdjustViewBounds ();
673
+
674
+ _close = close ;
675
+ }
676
+
677
+ RelativeLayout .LayoutParams closeLayoutParams = new RelativeLayout .LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .MATCH_PARENT );
678
+ closeLayoutParams .addRule (RelativeLayout .ALIGN_PARENT_RIGHT );
679
+ _close .setLayoutParams (closeLayoutParams );
680
+
681
+ if (Build .VERSION .SDK_INT >= 16 )
682
+ _close .setBackground (null );
683
+ else
684
+ _close .setBackgroundDrawable (null );
685
+
686
+ _close .setContentDescription ("Close Button" );
687
+ _close .setId (Integer .valueOf (id ));
688
+ _close .setOnClickListener (new View .OnClickListener () {
689
+ public void onClick (View v ) {
690
+ closeDialog ();
691
+ }
692
+ });
693
+
694
+ return _close ;
695
+ }
696
+
640
697
@ SuppressLint ("NewApi" )
641
698
public void run () {
642
699
@@ -741,67 +798,37 @@ public void onClick(View v) {
741
798
public boolean onKey (View v , int keyCode , KeyEvent event ) {
742
799
// If the event is a key-down event on the "enter" button
743
800
if ((event .getAction () == KeyEvent .ACTION_DOWN ) && (keyCode == KeyEvent .KEYCODE_ENTER )) {
744
- navigate (edittext .getText ().toString ());
745
- return true ;
801
+ navigate (edittext .getText ().toString ());
802
+ return true ;
746
803
}
747
804
return false ;
748
805
}
749
806
});
750
807
751
- // Close/Done button
752
- if (closeButtonCaption != "" ) {
753
- // Use TextView for text
754
- TextView close = new TextView (cordova .getActivity ());
755
- close .setText (closeButtonCaption );
756
- close .setTextSize (20 );
757
- if (closeButtonColor != "" ) close .setTextColor (android .graphics .Color .parseColor (closeButtonColor ));
758
- close .setGravity (android .view .Gravity .CENTER_VERTICAL );
759
- RelativeLayout .LayoutParams closeLayoutParams = new RelativeLayout .LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .MATCH_PARENT );
760
- closeLayoutParams .addRule (RelativeLayout .ALIGN_PARENT_RIGHT );
761
- close .setLayoutParams (closeLayoutParams );
762
-
763
- close .setContentDescription ("Close Button" );
764
- close .setId (Integer .valueOf (5 ));
765
- if (Build .VERSION .SDK_INT >= 16 )
766
- close .setBackground (null );
767
- else
768
- close .setBackgroundDrawable (null );
769
- back .setPadding (0 , this .dpToPixels (10 ), 0 , this .dpToPixels (10 ));
770
- close .setPadding (this .dpToPixels (10 ), 0 , this .dpToPixels (10 ), 0 );
771
- close .setOnClickListener (new View .OnClickListener () {
772
- public void onClick (View v ) {
773
- closeDialog ();
774
- }
775
- });
776
- toolbar .addView (close );
777
- }
778
- else {
779
- ImageButton close = new ImageButton (cordova .getActivity ());
780
- RelativeLayout .LayoutParams closeLayoutParams = new RelativeLayout .LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .MATCH_PARENT );
781
- closeLayoutParams .addRule (RelativeLayout .ALIGN_PARENT_RIGHT );
782
- close .setLayoutParams (closeLayoutParams );
783
- close .setContentDescription ("Close Button" );
784
- close .setId (Integer .valueOf (5 ));
785
- int closeResId = activityRes .getIdentifier ("ic_action_remove" , "drawable" , cordova .getActivity ().getPackageName ());
786
- Drawable closeIcon = activityRes .getDrawable (closeResId );
787
- if (closeButtonColor != "" ) close .setColorFilter (android .graphics .Color .parseColor (closeButtonColor ));
788
- if (Build .VERSION .SDK_INT >= 16 )
789
- close .setBackground (null );
790
- else
791
- close .setBackgroundDrawable (null );
792
- close .setImageDrawable (closeIcon );
793
- close .setScaleType (ImageView .ScaleType .FIT_CENTER );
794
- back .setPadding (0 , this .dpToPixels (10 ), 0 , this .dpToPixels (10 ));
795
- if (Build .VERSION .SDK_INT >= 16 )
796
- close .getAdjustViewBounds ();
797
-
798
- close .setOnClickListener (new View .OnClickListener () {
799
- public void onClick (View v ) {
800
- closeDialog ();
801
- }
802
- });
803
- toolbar .addView (close );
808
+
809
+ // Header Close/Done button
810
+ View close = createCloseButton (5 );
811
+ toolbar .addView (close );
812
+
813
+ // Footer
814
+ RelativeLayout footer = new RelativeLayout (cordova .getActivity ());
815
+ int _footerColor ;
816
+ if (footerColor != "" ){
817
+ _footerColor = Color .parseColor (footerColor );
818
+ }else {
819
+ _footerColor = android .graphics .Color .LTGRAY ;
804
820
}
821
+ footer .setBackgroundColor (_footerColor );
822
+ RelativeLayout .LayoutParams footerLayout = new RelativeLayout .LayoutParams (LayoutParams .MATCH_PARENT , this .dpToPixels (44 ));
823
+ footerLayout .addRule (RelativeLayout .ALIGN_PARENT_BOTTOM , RelativeLayout .TRUE );
824
+ footer .setLayoutParams (footerLayout );
825
+ if (closeButtonCaption != "" ) footer .setPadding (this .dpToPixels (8 ), this .dpToPixels (8 ), this .dpToPixels (8 ), this .dpToPixels (8 ));
826
+ footer .setHorizontalGravity (Gravity .LEFT );
827
+ footer .setVerticalGravity (Gravity .BOTTOM );
828
+
829
+ View footerClose = createCloseButton (7 );
830
+ footer .addView (footerClose );
831
+
805
832
806
833
// WebView
807
834
inAppWebView = new WebView (cordova .getActivity ());
@@ -915,7 +942,14 @@ public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType)
915
942
}
916
943
917
944
// Add our webview to our main view/layout
918
- main .addView (inAppWebView );
945
+ RelativeLayout webViewLayout = new RelativeLayout (cordova .getActivity ());
946
+ webViewLayout .addView (inAppWebView );
947
+ main .addView (webViewLayout );
948
+
949
+ // Don't add the footer unless it's been enabled
950
+ if (showFooter ) {
951
+ webViewLayout .addView (footer );
952
+ }
919
953
920
954
WindowManager .LayoutParams lp = new WindowManager .LayoutParams ();
921
955
lp .copyFrom (dialog .getWindow ().getAttributes ());
@@ -1105,7 +1139,7 @@ public void onPageStarted(WebView view, String url, Bitmap favicon) {
1105
1139
// Update the UI if we haven't already
1106
1140
if (!newloc .equals (edittext .getText ().toString ())) {
1107
1141
edittext .setText (newloc );
1108
- }
1142
+ }
1109
1143
1110
1144
try {
1111
1145
JSONObject obj = new JSONObject ();
0 commit comments