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