[Android] Fix Locale resetting problem when opening about

habib kazemi git at videolan.org
Fri Jun 2 12:04:44 CEST 2017


vlc-android | branch: master | habib kazemi <kazemihabib1996 at gmail.com> | Fri Jun  2 03:14:12 2017 +0430| [41a4049a8aed2ae7a21fcb9cfd98b03beb88c1ba] | committer: Geoffrey Métais

Fix Locale resetting problem when opening about

https://code.videolan.org/videolan/vlc-android/issues/285

Signed-off-by: Geoffrey Métais <geoffrey.metais at gmail.com>

Close #285

> https://code.videolan.org/videolan/vlc-android/commit/41a4049a8aed2ae7a21fcb9cfd98b03beb88c1ba
---

 .../src/org/videolan/vlc/VLCApplication.java       | 27 +++++++++++++++-------
 .../src/org/videolan/vlc/gui/AboutFragment.java    |  6 +++++
 2 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/VLCApplication.java b/vlc-android/src/org/videolan/vlc/VLCApplication.java
index 8973f5d93..db4dfad91 100644
--- a/vlc-android/src/org/videolan/vlc/VLCApplication.java
+++ b/vlc-android/src/org/videolan/vlc/VLCApplication.java
@@ -83,13 +83,8 @@ public class VLCApplication extends Application {
 
     private static int sDialogCounter = 0;
 
-    @Override
-    public void onCreate() {
-        super.onCreate();
-        instance = this;
-
+    public static void setLocale(Context context){
         // Are we using advanced debugging - locale?
-        mSettings = PreferenceManager.getDefaultSharedPreferences(this);
         String p = mSettings.getString("set_locale", "");
         if (!p.equals("")) {
             Locale locale;
@@ -115,9 +110,18 @@ public class VLCApplication extends Application {
             Locale.setDefault(locale);
             Configuration config = new Configuration();
             config.locale = locale;
-            getResources().updateConfiguration(config,
-                    getResources().getDisplayMetrics());
+            context.getResources().updateConfiguration(config,
+                    context.getResources().getDisplayMetrics());
         }
+    }
+
+    @Override
+    public void onCreate() {
+        super.onCreate();
+        instance = this;
+        mSettings = PreferenceManager.getDefaultSharedPreferences(this);
+
+        setLocale(this);
 
         runBackground(new Runnable() {
             @Override
@@ -138,6 +142,13 @@ public class VLCApplication extends Application {
         });
     }
 
+    @Override
+    public void onConfigurationChanged(Configuration newConfig) {
+        super.onConfigurationChanged(newConfig);
+        if (AndroidUtil.isNougatOrLater)
+            setLocale(this);
+    }
+
     /**
      * Called when the overall system is running low on memory
      */
diff --git a/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java b/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java
index ad9d05c68..4722742d2 100644
--- a/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java
@@ -30,8 +30,10 @@ import android.view.View;
 import android.view.ViewGroup;
 import android.webkit.WebView;
 
+import org.videolan.libvlc.util.AndroidUtil;
 import org.videolan.vlc.BuildConfig;
 import org.videolan.vlc.R;
+import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.audio.AudioPagerAdapter;
 import org.videolan.vlc.gui.helpers.UiTools;
 import org.videolan.vlc.util.Util;
@@ -51,6 +53,10 @@ public class AboutFragment extends Fragment {
         if (getActivity() instanceof AppCompatActivity)
             ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle("VLC " + BuildConfig.VERSION_NAME);
         View v = inflater.inflate(R.layout.about, container, false);
+        //Fix android 7 Locale problem with webView
+        //https://stackoverflow.com/questions/40398528/android-webview-locale-changes-abruptly-on-android-n
+        if (AndroidUtil.isNougatOrLater)
+            VLCApplication.setLocale(getContext());
 
         View aboutMain = v.findViewById(R.id.about_main);
         WebView webView = (WebView)v.findViewById(R.id.webview);



More information about the Android mailing list