@@ -25,6 +25,9 @@ Licensed to the Apache Software Foundation (ASF) under one
2525import android .content .res .Resources ;
2626import android .graphics .Bitmap ;
2727import android .graphics .drawable .Drawable ;
28+ import android .graphics .PorterDuff ;
29+ import android .graphics .PorterDuffColorFilter ;
30+ import android .graphics .Color ;
2831import android .net .Uri ;
2932import android .os .Build ;
3033import android .os .Bundle ;
@@ -51,6 +54,7 @@ Licensed to the Apache Software Foundation (ASF) under one
5154import android .widget .ImageView ;
5255import android .widget .LinearLayout ;
5356import android .widget .RelativeLayout ;
57+ import android .widget .TextView ;
5458
5559import org .apache .cordova .CallbackContext ;
5660import org .apache .cordova .Config ;
@@ -91,6 +95,8 @@ public class InAppBrowser extends CordovaPlugin {
9195 private static final String SHOULD_PAUSE = "shouldPauseOnSuspend" ;
9296 private static final Boolean DEFAULT_HARDWARE_BACK = true ;
9397 private static final String USER_WIDE_VIEW_PORT = "useWideViewPort" ;
98+ private static final String CLOSE_BUTTON_TEXT = "closeButtonText" ;
99+ private static final String CLOSE_BUTTON_COLOR = "closeButtonColor" ;
94100
95101 private InAppBrowserDialog dialog ;
96102 private WebView inAppWebView ;
@@ -109,6 +115,8 @@ public class InAppBrowser extends CordovaPlugin {
109115 private ValueCallback <Uri []> mUploadCallbackLollipop ;
110116 private final static int FILECHOOSER_REQUESTCODE = 1 ;
111117 private final static int FILECHOOSER_REQUESTCODE_LOLLIPOP = 2 ;
118+ private String closeButtonText = "" ;
119+ private int closeButtonColor = android .graphics .Color .LTGRAY ;
112120
113121 /**
114122 * Executes the request and returns PluginResult.
@@ -127,7 +135,7 @@ public boolean execute(String action, CordovaArgs args, final CallbackContext ca
127135 t = SELF ;
128136 }
129137 final String target = t ;
130- final HashMap <String , Boolean > features = parseFeature (args .optString (2 ));
138+ final HashMap <String , String > features = parseFeature (args .optString (2 ));
131139
132140 LOG .d (LOG_TAG , "target = " + target );
133141
@@ -366,18 +374,23 @@ public void run() {
366374 * @param optString
367375 * @return
368376 */
369- private HashMap <String , Boolean > parseFeature (String optString ) {
377+ private HashMap <String , String > parseFeature (String optString ) {
370378 if (optString .equals (NULL )) {
371379 return null ;
372380 } else {
373- HashMap <String , Boolean > map = new HashMap <String , Boolean >();
381+ HashMap <String , String > map = new HashMap <String , String >();
374382 StringTokenizer features = new StringTokenizer (optString , "," );
375383 StringTokenizer option ;
376384 while (features .hasMoreElements ()) {
377385 option = new StringTokenizer (features .nextToken (), "=" );
378386 if (option .hasMoreElements ()) {
379387 String key = option .nextToken ();
380- Boolean value = option .nextToken ().equals ("no" ) ? Boolean .FALSE : Boolean .TRUE ;
388+ String value = null ;
389+ if (key .equals (CLOSE_BUTTON_TEXT )) value = option .nextToken ();
390+ else {
391+ String token = option .nextToken ();
392+ value = token .equals ("yes" ) || token .equals ("no" ) ? token : "yes" ; // hér!!
393+ }
381394 map .put (key , value );
382395 }
383396 }
@@ -523,52 +536,60 @@ private InAppBrowser getInAppBrowser(){
523536 * @param url the url to load.
524537 * @param features jsonObject
525538 */
526- public String showWebPage (final String url , HashMap <String , Boolean > features ) {
539+ public String showWebPage (final String url , HashMap <String , String > features ) {
527540 // Determine if we should hide the location bar.
528541 showLocationBar = true ;
529542 showZoomControls = true ;
530543 openWindowHidden = false ;
531544 mediaPlaybackRequiresUserGesture = false ;
532545
533546 if (features != null ) {
534- Boolean show = features .get (LOCATION );
547+ String show = features .get (LOCATION );
535548 if (show != null ) {
536- showLocationBar = show .booleanValue () ;
549+ showLocationBar = show .equals ( "yes" ) ? true : false ;
537550 }
538- Boolean zoom = features .get (ZOOM );
551+ String zoom = features .get (ZOOM );
539552 if (zoom != null ) {
540- showZoomControls = zoom .booleanValue () ;
553+ showZoomControls = zoom .equals ( "yes" ) ? true : false ;
541554 }
542- Boolean hidden = features .get (HIDDEN );
555+ String hidden = features .get (HIDDEN );
543556 if (hidden != null ) {
544- openWindowHidden = hidden .booleanValue () ;
557+ openWindowHidden = hidden .equals ( "yes" ) ? true : false ;
545558 }
546- Boolean hardwareBack = features .get (HARDWARE_BACK_BUTTON );
559+ String hardwareBack = features .get (HARDWARE_BACK_BUTTON );
547560 if (hardwareBack != null ) {
548- hadwareBackButton = hardwareBack .booleanValue () ;
561+ hadwareBackButton = hardwareBack .equals ( "yes" ) ? true : false ;
549562 } else {
550563 hadwareBackButton = DEFAULT_HARDWARE_BACK ;
551564 }
552- Boolean mediaPlayback = features .get (MEDIA_PLAYBACK_REQUIRES_USER_ACTION );
565+ String mediaPlayback = features .get (MEDIA_PLAYBACK_REQUIRES_USER_ACTION );
553566 if (mediaPlayback != null ) {
554- mediaPlaybackRequiresUserGesture = mediaPlayback .booleanValue () ;
567+ mediaPlaybackRequiresUserGesture = mediaPlayback .equals ( "yes" ) ? true : false ;
555568 }
556- Boolean cache = features .get (CLEAR_ALL_CACHE );
569+ String cache = features .get (CLEAR_ALL_CACHE );
557570 if (cache != null ) {
558- clearAllCache = cache .booleanValue () ;
571+ clearAllCache = cache .equals ( "yes" ) ? true : false ;
559572 } else {
560573 cache = features .get (CLEAR_SESSION_CACHE );
561574 if (cache != null ) {
562- clearSessionCache = cache .booleanValue () ;
575+ clearSessionCache = cache .equals ( "yes" ) ? true : false ;
563576 }
564577 }
565- Boolean shouldPause = features .get (SHOULD_PAUSE );
578+ String shouldPause = features .get (SHOULD_PAUSE );
566579 if (shouldPause != null ) {
567- shouldPauseInAppBrowser = shouldPause .booleanValue () ;
580+ shouldPauseInAppBrowser = shouldPause .equals ( "yes" ) ? true : false ;
568581 }
569- Boolean wideViewPort = features .get (USER_WIDE_VIEW_PORT );
582+ String wideViewPort = features .get (USER_WIDE_VIEW_PORT );
570583 if (wideViewPort != null ) {
571- useWideViewPort = wideViewPort .booleanValue ();
584+ useWideViewPort = wideViewPort .equals ("yes" ) ? true : false ;
585+ }
586+ String closeButtonTextSet = features .get (CLOSE_BUTTON_TEXT );
587+ if (closeButtonTextSet != null ) {
588+ closeButtonText = closeButtonTextSet ;
589+ }
590+ String closeButtonTextColorSet = features .get (CLOSE_BUTTON_COLOR );
591+ if (closeButtonTextColorSet != null ) {
592+ closeButtonColor = Color .parseColor (closeButtonTextColorSet );
572593 }
573594 }
574595
@@ -612,7 +633,7 @@ public void run() {
612633 // Toolbar layout
613634 RelativeLayout toolbar = new RelativeLayout (cordova .getActivity ());
614635 //Please, no more black!
615- toolbar .setBackgroundColor (android . graphics . Color . LTGRAY );
636+ toolbar .setBackgroundColor (closeButtonColor );
616637 toolbar .setLayoutParams (new RelativeLayout .LayoutParams (LayoutParams .MATCH_PARENT , this .dpToPixels (44 )));
617638 toolbar .setPadding (this .dpToPixels (2 ), this .dpToPixels (2 ), this .dpToPixels (2 ), this .dpToPixels (2 ));
618639 toolbar .setHorizontalGravity (Gravity .LEFT );
@@ -700,29 +721,46 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
700721 });
701722
702723 // Close/Done button
703- ImageButton close = new ImageButton (cordova .getActivity ());
704- RelativeLayout .LayoutParams closeLayoutParams = new RelativeLayout .LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .MATCH_PARENT );
705- closeLayoutParams .addRule (RelativeLayout .ALIGN_PARENT_RIGHT );
706- close .setLayoutParams (closeLayoutParams );
707- close .setContentDescription ("Close Button" );
708- close .setId (Integer .valueOf (5 ));
709- int closeResId = activityRes .getIdentifier ("ic_action_remove" , "drawable" , cordova .getActivity ().getPackageName ());
710- Drawable closeIcon = activityRes .getDrawable (closeResId );
711- if (Build .VERSION .SDK_INT >= 16 )
712- close .setBackground (null );
713- else
714- close .setBackgroundDrawable (null );
715- close .setImageDrawable (closeIcon );
716- close .setScaleType (ImageView .ScaleType .FIT_CENTER );
717- back .setPadding (0 , this .dpToPixels (10 ), 0 , this .dpToPixels (10 ));
718- if (Build .VERSION .SDK_INT >= 16 )
719- close .getAdjustViewBounds ();
720-
721- close .setOnClickListener (new View .OnClickListener () {
722- public void onClick (View v ) {
723- closeDialog ();
724- }
725- });
724+ if (closeButtonText != "" ) {
725+ /* Use TextView for text */
726+ TextView close = new TextView (cordova .getActivity ());
727+ close .setText (closeButtonText );
728+ close .setTextSize (25 );
729+ back .setPadding (0 , this .dpToPixels (10 ), 0 , this .dpToPixels (10 ));
730+ close .setId (Integer .valueOf (5 ));
731+ close .setOnClickListener (new View .OnClickListener () {
732+ public void onClick (View v ) {
733+ closeDialog ();
734+ }
735+ });
736+ toolbar .addView (close );
737+ }
738+ else {
739+ ImageButton close = new ImageButton (cordova .getActivity ());
740+ RelativeLayout .LayoutParams closeLayoutParams = new RelativeLayout .LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .MATCH_PARENT );
741+ closeLayoutParams .addRule (RelativeLayout .ALIGN_PARENT_RIGHT );
742+ close .setLayoutParams (closeLayoutParams );
743+ close .setContentDescription ("Close Button" );
744+ close .setId (Integer .valueOf (5 ));
745+ int closeResId = activityRes .getIdentifier ("ic_action_remove" , "drawable" , cordova .getActivity ().getPackageName ());
746+ Drawable closeIcon = activityRes .getDrawable (closeResId );
747+ if (Build .VERSION .SDK_INT >= 16 )
748+ close .setBackground (null );
749+ else
750+ close .setBackgroundDrawable (null );
751+ close .setImageDrawable (closeIcon );
752+ close .setScaleType (ImageView .ScaleType .FIT_CENTER );
753+ back .setPadding (0 , this .dpToPixels (10 ), 0 , this .dpToPixels (10 ));
754+ if (Build .VERSION .SDK_INT >= 16 )
755+ close .getAdjustViewBounds ();
756+
757+ close .setOnClickListener (new View .OnClickListener () {
758+ public void onClick (View v ) {
759+ closeDialog ();
760+ }
761+ });
762+ toolbar .addView (close );
763+ }
726764
727765 // WebView
728766 inAppWebView = new WebView (cordova .getActivity ());
@@ -828,7 +866,7 @@ public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType)
828866 // Add the views to our toolbar
829867 toolbar .addView (actionButtonContainer );
830868 toolbar .addView (edittext );
831- toolbar .addView (close );
869+ // toolbar.addView(close);
832870
833871 // Don't add the toolbar if its been disabled
834872 if (getShowLocationBar ()) {
0 commit comments