Skip to content

Commit 47bb23c

Browse files
committed
Added RTL check method
1 parent 9e8f558 commit 47bb23c

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

compoundicontextview/src/main/java/com/github/aakira/compoundicontextview/CompoundIconTextView.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@
1818
import android.support.annotation.Nullable;
1919
import android.support.v4.content.ContextCompat;
2020
import android.support.v4.graphics.drawable.DrawableCompat;
21+
import android.support.v4.text.TextUtilsCompat;
22+
import android.support.v4.view.ViewCompat;
2123
import android.support.v7.content.res.AppCompatResources;
2224
import android.support.v7.widget.AppCompatTextView;
2325
import android.util.AttributeSet;
2426

27+
import java.util.Locale;
28+
2529
/**
2630
* You can use a vector drawable in TextView instead of drawableLeft, drawableTop, drawableRight and
2731
* drawableBottom.
@@ -176,7 +180,7 @@ public void setIconColor(@ColorInt final int color) {
176180
/**
177181
* Change drawable icon size
178182
*
179-
* @param widthRes Set width resource id
183+
* @param widthRes Set width resource id
180184
* @param heightRes Set height resource id
181185
*/
182186
public void setIconSizeResource(@DimenRes final int widthRes, @DimenRes final int heightRes) {
@@ -187,7 +191,7 @@ public void setIconSizeResource(@DimenRes final int widthRes, @DimenRes final in
187191
/**
188192
* Change drawable icon size
189193
*
190-
* @param width Set width size
194+
* @param width Set width size
191195
* @param height Set height size
192196
*/
193197
public void setIconSize(@Dimension final int width, @Dimension final int height) {
@@ -302,4 +306,12 @@ private static void fixVectorDrawableTinting(final Drawable drawable) {
302306
// Now set the original state
303307
drawable.setState(originalState);
304308
}
309+
310+
private boolean isRtl() {
311+
Resources resources = getContext().getResources();
312+
Locale locale = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
313+
? resources.getConfiguration().getLocales().getFirstMatch(resources.getAssets().getLocales())
314+
: resources.getConfiguration().locale;
315+
return TextUtilsCompat.getLayoutDirectionFromLocale(locale) == ViewCompat.LAYOUT_DIRECTION_RTL;
316+
}
305317
}

0 commit comments

Comments
 (0)