forked from organicmaps/organicmaps
[android] RTL layout mirroring will switch on only for Persian and Arabian locales, for which we already have translation.
Signed-off-by: Dzmitry Yarmolenka <dzmitry.yarmolenka.1986@gmail.com>
This commit is contained in:
parent
d28d122daa
commit
9524e4165d
2 changed files with 29 additions and 0 deletions
|
@ -21,6 +21,7 @@ import com.mapswithme.maps.MwmApplication;
|
|||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.SplashActivity;
|
||||
import com.mapswithme.util.Config;
|
||||
import com.mapswithme.util.RtlUtils;
|
||||
import com.mapswithme.util.ThemeUtils;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.Utils;
|
||||
|
@ -66,6 +67,7 @@ public abstract class BaseMwmFragmentActivity extends AppCompatActivity
|
|||
protected final void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
mBaseDelegate.onCreate();
|
||||
RtlUtils.manageRtl(this);
|
||||
// An intent that was skipped due to core wasn't initialized has to be used
|
||||
// as a target intent for this activity, otherwise all input extras will be lost
|
||||
// in a splash activity loop.
|
||||
|
|
27
android/src/com/mapswithme/util/RtlUtils.java
Normal file
27
android/src/com/mapswithme/util/RtlUtils.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package com.mapswithme.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.text.TextUtilsCompat;
|
||||
import androidx.core.view.ViewCompat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class RtlUtils
|
||||
{
|
||||
private final static List<String> rtlLocalesWithTranslation = Arrays.asList("ar", "fa");
|
||||
|
||||
public static void manageRtl(@NonNull final Activity activity)
|
||||
{
|
||||
final String currentLanguage = Locale.getDefault().getLanguage();
|
||||
final boolean isRTL = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL;
|
||||
if (isRTL && rtlLocalesWithTranslation.contains(currentLanguage))
|
||||
activity.getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
|
||||
else
|
||||
activity.getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue