@@ -109,6 +109,7 @@ private static enum BorderStyle {
109
109
110
110
private @ Nullable float [] mBorderCornerRadii ;
111
111
private final Context mContext ;
112
+ private int mLayoutDirection ;
112
113
113
114
public enum BorderRadiusLocation {
114
115
TOP_LEFT ,
@@ -290,6 +291,25 @@ public void setColor(int color) {
290
291
invalidateSelf ();
291
292
}
292
293
294
+ /** Similar to Drawable.getLayoutDirection, but available in APIs < 23. */
295
+ public int getResolvedLayoutDirection () {
296
+ return mLayoutDirection ;
297
+ }
298
+
299
+ /** Similar to Drawable.setLayoutDirection, but available in APIs < 23. */
300
+ public boolean setResolvedLayoutDirection (int layoutDirection ) {
301
+ if (mLayoutDirection != layoutDirection ) {
302
+ mLayoutDirection = layoutDirection ;
303
+ return onResolvedLayoutDirectionChanged (layoutDirection );
304
+ }
305
+ return false ;
306
+ }
307
+
308
+ /** Similar to Drawable.onLayoutDirectionChanged, but available in APIs < 23. */
309
+ public boolean onResolvedLayoutDirectionChanged (int layoutDirection ) {
310
+ return false ;
311
+ }
312
+
293
313
@ VisibleForTesting
294
314
public int getColor () {
295
315
return mColor ;
@@ -323,8 +343,8 @@ private void drawRoundedBackgroundWithBorders(Canvas canvas) {
323
343
int colorRight = getBorderColor (Spacing .RIGHT );
324
344
int colorBottom = getBorderColor (Spacing .BOTTOM );
325
345
326
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
327
- final boolean isRTL = getLayoutDirection () == View .LAYOUT_DIRECTION_RTL ;
346
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR1 ) {
347
+ final boolean isRTL = getResolvedLayoutDirection () == View .LAYOUT_DIRECTION_RTL ;
328
348
int colorStart = getBorderColor (Spacing .START );
329
349
int colorEnd = getBorderColor (Spacing .END );
330
350
@@ -478,13 +498,13 @@ private void updatePath() {
478
498
float bottomRightRadius =
479
499
getBorderRadiusOrDefaultTo (borderRadius , BorderRadiusLocation .BOTTOM_RIGHT );
480
500
481
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
482
- final boolean isRTL = getLayoutDirection () == View .LAYOUT_DIRECTION_RTL ;
501
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR1 ) {
502
+ final boolean isRTL = getResolvedLayoutDirection () == View .LAYOUT_DIRECTION_RTL ;
483
503
float topStartRadius = getBorderRadius (BorderRadiusLocation .TOP_START );
484
504
float topEndRadius = getBorderRadius (BorderRadiusLocation .TOP_END );
485
505
float bottomStartRadius = getBorderRadius (BorderRadiusLocation .BOTTOM_START );
486
506
float bottomEndRadius = getBorderRadius (BorderRadiusLocation .BOTTOM_END );
487
-
507
+
488
508
if (I18nUtil .getInstance ().doLeftAndRightSwapInRTL (mContext )) {
489
509
if (YogaConstants .isUndefined (topStartRadius )) {
490
510
topStartRadius = topLeftRadius ;
@@ -930,8 +950,8 @@ private void drawRectangularBackgroundWithBorders(Canvas canvas) {
930
950
int colorRight = getBorderColor (Spacing .RIGHT );
931
951
int colorBottom = getBorderColor (Spacing .BOTTOM );
932
952
933
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
934
- final boolean isRTL = getLayoutDirection () == View .LAYOUT_DIRECTION_RTL ;
953
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR1 ) {
954
+ final boolean isRTL = getResolvedLayoutDirection () == View .LAYOUT_DIRECTION_RTL ;
935
955
int colorStart = getBorderColor (Spacing .START );
936
956
int colorEnd = getBorderColor (Spacing .END );
937
957
@@ -1140,8 +1160,8 @@ public RectF getDirectionAwareBorderInsets() {
1140
1160
float borderLeftWidth = getBorderWidthOrDefaultTo (borderWidth , Spacing .LEFT );
1141
1161
float borderRightWidth = getBorderWidthOrDefaultTo (borderWidth , Spacing .RIGHT );
1142
1162
1143
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M && mBorderWidth != null ) {
1144
- final boolean isRTL = getLayoutDirection () == View .LAYOUT_DIRECTION_RTL ;
1163
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR1 && mBorderWidth != null ) {
1164
+ final boolean isRTL = getResolvedLayoutDirection () == View .LAYOUT_DIRECTION_RTL ;
1145
1165
float borderStartWidth = mBorderWidth .getRaw (Spacing .START );
1146
1166
float borderEndWidth = mBorderWidth .getRaw (Spacing .END );
1147
1167
0 commit comments