@@ -25,6 +25,9 @@ Licensed to the Apache Software Foundation (ASF) under one
25
25
import android .content .res .Resources ;
26
26
import android .graphics .Bitmap ;
27
27
import android .graphics .drawable .Drawable ;
28
+ import android .graphics .PorterDuff ;
29
+ import android .graphics .PorterDuffColorFilter ;
30
+ import android .graphics .Color ;
28
31
import android .net .Uri ;
29
32
import android .os .Build ;
30
33
import android .os .Bundle ;
@@ -51,6 +54,7 @@ Licensed to the Apache Software Foundation (ASF) under one
51
54
import android .widget .ImageView ;
52
55
import android .widget .LinearLayout ;
53
56
import android .widget .RelativeLayout ;
57
+ import android .widget .TextView ;
54
58
55
59
import org .apache .cordova .CallbackContext ;
56
60
import org .apache .cordova .Config ;
@@ -91,6 +95,8 @@ public class InAppBrowser extends CordovaPlugin {
91
95
private static final String SHOULD_PAUSE = "shouldPauseOnSuspend" ;
92
96
private static final Boolean DEFAULT_HARDWARE_BACK = true ;
93
97
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" ;
94
100
95
101
private InAppBrowserDialog dialog ;
96
102
private WebView inAppWebView ;
@@ -109,6 +115,8 @@ public class InAppBrowser extends CordovaPlugin {
109
115
private ValueCallback <Uri []> mUploadCallbackLollipop ;
110
116
private final static int FILECHOOSER_REQUESTCODE = 1 ;
111
117
private final static int FILECHOOSER_REQUESTCODE_LOLLIPOP = 2 ;
118
+ private String closeButtonText = "" ;
119
+ private int closeButtonColor = android .graphics .Color .LTGRAY ;
112
120
113
121
/**
114
122
* Executes the request and returns PluginResult.
@@ -127,7 +135,7 @@ public boolean execute(String action, CordovaArgs args, final CallbackContext ca
127
135
t = SELF ;
128
136
}
129
137
final String target = t ;
130
- final HashMap <String , Boolean > features = parseFeature (args .optString (2 ));
138
+ final HashMap <String , String > features = parseFeature (args .optString (2 ));
131
139
132
140
LOG .d (LOG_TAG , "target = " + target );
133
141
@@ -366,18 +374,23 @@ public void run() {
366
374
* @param optString
367
375
* @return
368
376
*/
369
- private HashMap <String , Boolean > parseFeature (String optString ) {
377
+ private HashMap <String , String > parseFeature (String optString ) {
370
378
if (optString .equals (NULL )) {
371
379
return null ;
372
380
} else {
373
- HashMap <String , Boolean > map = new HashMap <String , Boolean >();
381
+ HashMap <String , String > map = new HashMap <String , String >();
374
382
StringTokenizer features = new StringTokenizer (optString , "," );
375
383
StringTokenizer option ;
376
384
while (features .hasMoreElements ()) {
377
385
option = new StringTokenizer (features .nextToken (), "=" );
378
386
if (option .hasMoreElements ()) {
379
387
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
+ }
381
394
map .put (key , value );
382
395
}
383
396
}
@@ -523,52 +536,60 @@ private InAppBrowser getInAppBrowser(){
523
536
* @param url the url to load.
524
537
* @param features jsonObject
525
538
*/
526
- public String showWebPage (final String url , HashMap <String , Boolean > features ) {
539
+ public String showWebPage (final String url , HashMap <String , String > features ) {
527
540
// Determine if we should hide the location bar.
528
541
showLocationBar = true ;
529
542
showZoomControls = true ;
530
543
openWindowHidden = false ;
531
544
mediaPlaybackRequiresUserGesture = false ;
532
545
533
546
if (features != null ) {
534
- Boolean show = features .get (LOCATION );
547
+ String show = features .get (LOCATION );
535
548
if (show != null ) {
536
- showLocationBar = show .booleanValue () ;
549
+ showLocationBar = show .equals ( "yes" ) ? true : false ;
537
550
}
538
- Boolean zoom = features .get (ZOOM );
551
+ String zoom = features .get (ZOOM );
539
552
if (zoom != null ) {
540
- showZoomControls = zoom .booleanValue () ;
553
+ showZoomControls = zoom .equals ( "yes" ) ? true : false ;
541
554
}
542
- Boolean hidden = features .get (HIDDEN );
555
+ String hidden = features .get (HIDDEN );
543
556
if (hidden != null ) {
544
- openWindowHidden = hidden .booleanValue () ;
557
+ openWindowHidden = hidden .equals ( "yes" ) ? true : false ;
545
558
}
546
- Boolean hardwareBack = features .get (HARDWARE_BACK_BUTTON );
559
+ String hardwareBack = features .get (HARDWARE_BACK_BUTTON );
547
560
if (hardwareBack != null ) {
548
- hadwareBackButton = hardwareBack .booleanValue () ;
561
+ hadwareBackButton = hardwareBack .equals ( "yes" ) ? true : false ;
549
562
} else {
550
563
hadwareBackButton = DEFAULT_HARDWARE_BACK ;
551
564
}
552
- Boolean mediaPlayback = features .get (MEDIA_PLAYBACK_REQUIRES_USER_ACTION );
565
+ String mediaPlayback = features .get (MEDIA_PLAYBACK_REQUIRES_USER_ACTION );
553
566
if (mediaPlayback != null ) {
554
- mediaPlaybackRequiresUserGesture = mediaPlayback .booleanValue () ;
567
+ mediaPlaybackRequiresUserGesture = mediaPlayback .equals ( "yes" ) ? true : false ;
555
568
}
556
- Boolean cache = features .get (CLEAR_ALL_CACHE );
569
+ String cache = features .get (CLEAR_ALL_CACHE );
557
570
if (cache != null ) {
558
- clearAllCache = cache .booleanValue () ;
571
+ clearAllCache = cache .equals ( "yes" ) ? true : false ;
559
572
} else {
560
573
cache = features .get (CLEAR_SESSION_CACHE );
561
574
if (cache != null ) {
562
- clearSessionCache = cache .booleanValue () ;
575
+ clearSessionCache = cache .equals ( "yes" ) ? true : false ;
563
576
}
564
577
}
565
- Boolean shouldPause = features .get (SHOULD_PAUSE );
578
+ String shouldPause = features .get (SHOULD_PAUSE );
566
579
if (shouldPause != null ) {
567
- shouldPauseInAppBrowser = shouldPause .booleanValue () ;
580
+ shouldPauseInAppBrowser = shouldPause .equals ( "yes" ) ? true : false ;
568
581
}
569
- Boolean wideViewPort = features .get (USER_WIDE_VIEW_PORT );
582
+ String wideViewPort = features .get (USER_WIDE_VIEW_PORT );
570
583
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 );
572
593
}
573
594
}
574
595
@@ -612,7 +633,7 @@ public void run() {
612
633
// Toolbar layout
613
634
RelativeLayout toolbar = new RelativeLayout (cordova .getActivity ());
614
635
//Please, no more black!
615
- toolbar .setBackgroundColor (android . graphics . Color . LTGRAY );
636
+ toolbar .setBackgroundColor (closeButtonColor );
616
637
toolbar .setLayoutParams (new RelativeLayout .LayoutParams (LayoutParams .MATCH_PARENT , this .dpToPixels (44 )));
617
638
toolbar .setPadding (this .dpToPixels (2 ), this .dpToPixels (2 ), this .dpToPixels (2 ), this .dpToPixels (2 ));
618
639
toolbar .setHorizontalGravity (Gravity .LEFT );
@@ -700,29 +721,46 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
700
721
});
701
722
702
723
// 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
+ }
726
764
727
765
// WebView
728
766
inAppWebView = new WebView (cordova .getActivity ());
@@ -828,7 +866,7 @@ public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType)
828
866
// Add the views to our toolbar
829
867
toolbar .addView (actionButtonContainer );
830
868
toolbar .addView (edittext );
831
- toolbar .addView (close );
869
+ // toolbar.addView(close);
832
870
833
871
// Don't add the toolbar if its been disabled
834
872
if (getShowLocationBar ()) {
0 commit comments