@@ -85,6 +85,8 @@ Licensed to the Apache Software Foundation (ASF) under one
85
85
import java .util .HashMap ;
86
86
import java .util .StringTokenizer ;
87
87
88
+ import android .content .res .Configuration ;
89
+
88
90
@ SuppressLint ("SetJavaScriptEnabled" )
89
91
public class InAppBrowser extends CordovaPlugin {
90
92
@@ -745,8 +747,10 @@ private View createCloseButton(int id){
745
747
_close = close ;
746
748
}
747
749
750
+ Configuration config = activityRes .getConfiguration ();
751
+ boolean isLeftToRight = config .getLayoutDirection () == View .LAYOUT_DIRECTION_LTR ;
748
752
RelativeLayout .LayoutParams closeLayoutParams = new RelativeLayout .LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .MATCH_PARENT );
749
- closeLayoutParams .addRule (RelativeLayout .ALIGN_PARENT_RIGHT );
753
+ closeLayoutParams .addRule (isLeftToRight ? RelativeLayout .ALIGN_PARENT_RIGHT : RelativeLayout . ALIGN_PARENT_LEFT );
750
754
_close .setLayoutParams (closeLayoutParams );
751
755
752
756
if (Build .VERSION .SDK_INT >= 16 )
@@ -773,6 +777,9 @@ public void run() {
773
777
dialog .dismiss ();
774
778
};
775
779
780
+ Configuration config = cordova .getActivity ().getResources ().getConfiguration ();
781
+ boolean isLeftToRight = config .getLayoutDirection () == View .LAYOUT_DIRECTION_LTR ;
782
+
776
783
// Let's create the main dialog
777
784
dialog = new InAppBrowserDialog (cordova .getActivity (), android .R .style .Theme_NoTitleBar );
778
785
dialog .getWindow ().getAttributes ().windowAnimations = android .R .style .Animation_Dialog ;
@@ -790,25 +797,25 @@ public void run() {
790
797
toolbar .setBackgroundColor (toolbarColor );
791
798
toolbar .setLayoutParams (new RelativeLayout .LayoutParams (LayoutParams .MATCH_PARENT , this .dpToPixels (44 )));
792
799
toolbar .setPadding (this .dpToPixels (2 ), this .dpToPixels (2 ), this .dpToPixels (2 ), this .dpToPixels (2 ));
793
- toolbar .setHorizontalGravity (Gravity .LEFT );
800
+ toolbar .setHorizontalGravity (isLeftToRight ? Gravity .LEFT : Gravity . RIGHT );
794
801
toolbar .setVerticalGravity (Gravity .TOP );
795
802
796
803
// Action Button Container layout
797
804
RelativeLayout actionButtonContainer = new RelativeLayout (cordova .getActivity ());
798
805
actionButtonContainer .setLayoutParams (new RelativeLayout .LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT ));
799
- actionButtonContainer .setHorizontalGravity (Gravity .LEFT );
806
+ actionButtonContainer .setHorizontalGravity (isLeftToRight ? Gravity .LEFT : Gravity . RIGHT );
800
807
actionButtonContainer .setVerticalGravity (Gravity .CENTER_VERTICAL );
801
808
actionButtonContainer .setId (Integer .valueOf (1 ));
802
809
803
810
// Back button
804
811
ImageButton back = new ImageButton (cordova .getActivity ());
805
812
RelativeLayout .LayoutParams backLayoutParams = new RelativeLayout .LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .MATCH_PARENT );
806
- backLayoutParams .addRule (RelativeLayout .ALIGN_LEFT );
813
+ backLayoutParams .addRule (isLeftToRight ? RelativeLayout .ALIGN_LEFT : RelativeLayout . ALIGN_RIGHT );
807
814
back .setLayoutParams (backLayoutParams );
808
815
back .setContentDescription ("Back Button" );
809
816
back .setId (Integer .valueOf (2 ));
810
817
Resources activityRes = cordova .getActivity ().getResources ();
811
- int backResId = activityRes .getIdentifier ("ic_action_previous_item" , "drawable" , cordova .getActivity ().getPackageName ());
818
+ int backResId = activityRes .getIdentifier (isLeftToRight ? "ic_action_previous_item" : "ic_action_next_item " , "drawable" , cordova .getActivity ().getPackageName ());
812
819
Drawable backIcon = activityRes .getDrawable (backResId );
813
820
if (navigationButtonColor != "" ) back .setColorFilter (android .graphics .Color .parseColor (navigationButtonColor ));
814
821
if (Build .VERSION .SDK_INT >= 16 )
@@ -830,11 +837,11 @@ public void onClick(View v) {
830
837
// Forward button
831
838
ImageButton forward = new ImageButton (cordova .getActivity ());
832
839
RelativeLayout .LayoutParams forwardLayoutParams = new RelativeLayout .LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .MATCH_PARENT );
833
- forwardLayoutParams .addRule (RelativeLayout .RIGHT_OF , 2 );
840
+ forwardLayoutParams .addRule (isLeftToRight ? RelativeLayout .RIGHT_OF : RelativeLayout . LEFT_OF , 2 );
834
841
forward .setLayoutParams (forwardLayoutParams );
835
842
forward .setContentDescription ("Forward Button" );
836
843
forward .setId (Integer .valueOf (3 ));
837
- int fwdResId = activityRes .getIdentifier ("ic_action_next_item" , "drawable" , cordova .getActivity ().getPackageName ());
844
+ int fwdResId = activityRes .getIdentifier (isLeftToRight ? "ic_action_next_item" : "ic_action_previous_item " , "drawable" , cordova .getActivity ().getPackageName ());
838
845
Drawable fwdIcon = activityRes .getDrawable (fwdResId );
839
846
if (navigationButtonColor != "" ) forward .setColorFilter (android .graphics .Color .parseColor (navigationButtonColor ));
840
847
if (Build .VERSION .SDK_INT >= 16 )
@@ -856,8 +863,8 @@ public void onClick(View v) {
856
863
// Edit Text Box
857
864
edittext = new EditText (cordova .getActivity ());
858
865
RelativeLayout .LayoutParams textLayoutParams = new RelativeLayout .LayoutParams (LayoutParams .MATCH_PARENT , LayoutParams .MATCH_PARENT );
859
- textLayoutParams .addRule (RelativeLayout .RIGHT_OF , 1 );
860
- textLayoutParams .addRule (RelativeLayout .LEFT_OF , 5 );
866
+ textLayoutParams .addRule (isLeftToRight ? RelativeLayout .RIGHT_OF : RelativeLayout . LEFT_OF , 1 );
867
+ textLayoutParams .addRule (isLeftToRight ? RelativeLayout .LEFT_OF : RelativeLayout . RIGHT_OF , 5 );
861
868
edittext .setLayoutParams (textLayoutParams );
862
869
edittext .setId (Integer .valueOf (4 ));
863
870
edittext .setSingleLine (true );
@@ -894,7 +901,7 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
894
901
footerLayout .addRule (RelativeLayout .ALIGN_PARENT_BOTTOM , RelativeLayout .TRUE );
895
902
footer .setLayoutParams (footerLayout );
896
903
if (closeButtonCaption != "" ) footer .setPadding (this .dpToPixels (8 ), this .dpToPixels (8 ), this .dpToPixels (8 ), this .dpToPixels (8 ));
897
- footer .setHorizontalGravity (Gravity .LEFT );
904
+ footer .setHorizontalGravity (isLeftToRight ? Gravity .LEFT : Gravity . RIGHT );
898
905
footer .setVerticalGravity (Gravity .BOTTOM );
899
906
900
907
View footerClose = createCloseButton (7 );
0 commit comments