Small refactoring
Delete useless methods
This commit is contained in:
parent
22ea47b722
commit
5447289720
2 changed files with 22 additions and 27 deletions
|
@ -647,24 +647,15 @@ public class AndroidUtils {
|
|||
}
|
||||
|
||||
public static void setCompoundDrawablesWithIntrinsicBounds(@NonNull TextView tv, Drawable start, Drawable top, Drawable end, Drawable bottom){
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
if (isSupportRTL()) {
|
||||
tv.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom);
|
||||
} else {
|
||||
tv.setCompoundDrawablesWithIntrinsicBounds(start, top, end, bottom);
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<View> getChildrenViews(ViewGroup vg) {
|
||||
ArrayList<View> result = new ArrayList<>();
|
||||
for (int i = 0; i < vg.getChildCount(); i++) {
|
||||
View child = vg.getChildAt(i);
|
||||
result.add(child);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void setPadding(View view, int start, int top, int end, int bottom) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
if (isSupportRTL()) {
|
||||
view.setPaddingRelative(start, top, end, bottom);
|
||||
} else {
|
||||
view.setPadding(start, top, end, bottom);
|
||||
|
@ -673,7 +664,7 @@ public class AndroidUtils {
|
|||
|
||||
public static void setMargins(ViewGroup.MarginLayoutParams layoutParams, int start, int top, int end, int bottom) {
|
||||
layoutParams.setMargins(start, top, end, bottom);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
if (isSupportRTL()) {
|
||||
layoutParams.setMarginStart(start);
|
||||
layoutParams.setMarginEnd(end);
|
||||
}
|
||||
|
@ -684,6 +675,10 @@ public class AndroidUtils {
|
|||
return TextUtilsCompat.getLayoutDirectionFromLocale(currentLocale);
|
||||
}
|
||||
|
||||
public static boolean isSupportRTL() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1;
|
||||
}
|
||||
|
||||
public static float getFreeSpaceGb(File dir) {
|
||||
if (dir.canRead()) {
|
||||
StatFs fs = new StatFs(dir.getAbsolutePath());
|
||||
|
@ -692,6 +687,15 @@ public class AndroidUtils {
|
|||
return -1;
|
||||
}
|
||||
|
||||
public static ArrayList<View> getChildrenViews(ViewGroup vg) {
|
||||
ArrayList<View> result = new ArrayList<>();
|
||||
for (int i = 0; i < vg.getChildCount(); i++) {
|
||||
View child = vg.getChildAt(i);
|
||||
result.add(child);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static float getTotalSpaceGb(File dir) {
|
||||
if (dir.canRead()) {
|
||||
return (float) (dir.getTotalSpace()) / (1 << 30);
|
||||
|
|
|
@ -390,12 +390,13 @@ public class UiUtilities {
|
|||
}
|
||||
|
||||
public static void setupLayoutDirection(View view) {
|
||||
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
if (view == null || !AndroidUtils.isSupportRTL()) {
|
||||
return;
|
||||
}
|
||||
int layoutDirection = AndroidUtils.getLayoutDirection(view.getContext());
|
||||
Context ctx = view.getContext();
|
||||
int layoutDirection = AndroidUtils.getLayoutDirection(ctx);
|
||||
if (view instanceof ViewGroup) {
|
||||
setupLayoutDirection(view, layoutDirection);
|
||||
view.setLayoutDirection(layoutDirection);
|
||||
ArrayList<View> childrenViews = AndroidUtils.getChildrenViews((ViewGroup) view);
|
||||
if (childrenViews != null) {
|
||||
for (View child : childrenViews) {
|
||||
|
@ -403,22 +404,12 @@ public class UiUtilities {
|
|||
}
|
||||
}
|
||||
} else if (view instanceof TextView) {
|
||||
int textDirection = layoutDirection ==
|
||||
ViewCompat.LAYOUT_DIRECTION_RTL ?
|
||||
int textDirection = layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL ?
|
||||
View.TEXT_DIRECTION_RTL : View.TEXT_DIRECTION_LTR;
|
||||
setupTextDirection((TextView) view, textDirection);
|
||||
view.setTextDirection(textDirection);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setupLayoutDirection(View layout, int direction) {
|
||||
ViewCompat.setLayoutDirection(layout, direction);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
private static void setupTextDirection(TextView text, int direction) {
|
||||
text.setTextDirection(direction);
|
||||
}
|
||||
|
||||
public static void setupCompoundButtonDrawable(Context ctx, boolean nightMode, @ColorInt int activeColor, Drawable drawable) {
|
||||
int inactiveColor = ContextCompat.getColor(ctx, nightMode ? R.color.icon_color_default_dark : R.color.icon_color_default_light);
|
||||
int[][] states = new int[][] {
|
||||
|
|
Loading…
Reference in a new issue