0
0
mirror of https://github.com/TrianguloY/UrlChecker.git synced 2024-09-19 20:02:16 +02:00

fix module title position in rtl

fixes #69
This commit is contained in:
TrianguloY 2022-08-24 17:53:36 +02:00
parent c6b7bc8011
commit 2c24f4553a
5 changed files with 33 additions and 9 deletions

View File

@ -115,7 +115,8 @@ public class ConfigActivity extends Activity {
title.setOnClickListener(v -> {
boolean checked = child.getVisibility() == View.GONE;
child.setVisibility(checked ? View.VISIBLE : View.GONE);
title.setCompoundDrawablesWithIntrinsicBounds(checked ? R.drawable.arrow_down : R.drawable.arrow_right, 0, 0, 0);
AndroidUtils.setStartDrawables(title,
checked ? R.drawable.arrow_down : R.drawable.arrow_right);
});
title.performClick(); // initial hide
}

View File

@ -1,6 +1,5 @@
package com.trianguloy.urlchecker.activities;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
@ -55,7 +54,7 @@ public class MainActivity extends Activity {
break;
case R.id.m_img_icon:
// click on the app icon
if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (BuildConfig.DEBUG) {
chooseLocaleDebug();
break;
}
@ -71,13 +70,16 @@ public class MainActivity extends Activity {
* To be replaced with a proper implementation with issue
* https://github.com/TrianguloY/UrlChecker/issues/45
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void chooseLocaleDebug() {
String[] locales = new String[]{"en", "es", "fr-FR", "iw", "pt-PT", "tr", "uk"};
new AlertDialog.Builder(this)
.setItems(locales, (dialog, which) -> {
Configuration config = new Configuration();
config.setLocale(Locale.forLanguageTag(locales[which]));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
config.setLocale(Locale.forLanguageTag(locales[which]));
}else{
config.locale = new Locale(locales[which]);
}
getBaseContext().getResources()
.updateConfiguration(config, null);
recreate();

View File

@ -152,11 +152,10 @@ class RemoveQueriesDialog extends AModuleDialog implements View.OnClickListener
* Sets the 'more' indicator.
*/
private void updateMoreIndicator() {
info.setCompoundDrawablesWithIntrinsicBounds(
AndroidUtils.setStartDrawables(info,
box.getChildCount() == 0 ? 0
: box.getVisibility() == View.VISIBLE ? R.drawable.arrow_down
: R.drawable.arrow_right,
0, 0, 0);
: R.drawable.arrow_right);
}
/**

View File

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.res.Configuration;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.SpannableStringBuilder;
import android.text.style.ClickableSpan;
import android.util.Log;
@ -30,6 +31,26 @@ public class AndroidUtils {
);
}
/**
* Sets the start drawable of a textview
* Wrapped for android compatibility
*/
public static void setStartDrawables(TextView txt, int start) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
// we can use the function directly!
txt.setCompoundDrawablesRelativeWithIntrinsicBounds(start, 0, 0, 0);
} else {
// we need to manually adjust
if ((txt.getContext().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_LAYOUTDIR_MASK) == Configuration.SCREENLAYOUT_LAYOUTDIR_RTL) {
// rtl
txt.setCompoundDrawablesWithIntrinsicBounds(0, 0, start, 0);
} else {
// ltr
txt.setCompoundDrawablesWithIntrinsicBounds(start, 0, 0, 0);
}
}
}
/**
* In debug mode, throws an AssertionError, in production just logs it and continues.
*/

View File

@ -19,7 +19,8 @@
android:drawableStart="@drawable/arrow_right"
android:drawableLeft="@drawable/arrow_right"
android:drawableTint="?attr/colorAccent"
android:gravity="center_vertical"
android:textAlignment="viewStart"
android:gravity="center_vertical|start"
android:padding="5dp"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"
android:textStyle="bold" />