[Android] Set app locale in background

Geoffrey Métais git at videolan.org
Tue Dec 18 14:55:48 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Dec 18 11:31:21 2018 +0100| [596cfd0853bc3045740ee2c9163d90d36cded572] | committer: Geoffrey Métais

Set app locale in background

> https://code.videolan.org/videolan/vlc-android/commit/596cfd0853bc3045740ee2c9163d90d36cded572
---

 .../src/org/videolan/vlc/VLCApplication.java       | 28 +++++++++++++---------
 .../src/org/videolan/vlc/gui/MainActivity.java     |  2 --
 2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/VLCApplication.java b/vlc-android/src/org/videolan/vlc/VLCApplication.java
index 9ba6c3674..b6eacafcd 100644
--- a/vlc-android/src/org/videolan/vlc/VLCApplication.java
+++ b/vlc-android/src/org/videolan/vlc/VLCApplication.java
@@ -21,14 +21,10 @@ package org.videolan.vlc;
 
 import android.annotation.SuppressLint;
 import android.app.Application;
-import androidx.lifecycle.Lifecycle;
-import androidx.lifecycle.ProcessLifecycleOwner;
 import android.content.Context;
 import android.content.Intent;
 import android.content.res.Configuration;
 import android.content.res.Resources;
-import androidx.fragment.app.DialogFragment;
-import androidx.collection.SimpleArrayMap;
 import android.util.Log;
 
 import org.videolan.libvlc.Dialog;
@@ -49,6 +45,11 @@ import java.lang.ref.WeakReference;
 import java.lang.reflect.InvocationTargetException;
 import java.util.Calendar;
 
+import androidx.collection.SimpleArrayMap;
+import androidx.fragment.app.DialogFragment;
+import androidx.lifecycle.Lifecycle;
+import androidx.lifecycle.ProcessLifecycleOwner;
+
 import static org.videolan.vlc.gui.helpers.UiTools.setLocale;
 
 public class VLCApplication extends Application {
@@ -76,10 +77,15 @@ public class VLCApplication extends Application {
     @Override
     public void onCreate() {
         super.onCreate();
-        locale = Settings.INSTANCE.getInstance(this).getString("set_locale", "");
+        WorkersKt.runIO(new Runnable() {
+            @Override
+            public void run() {
+                locale = Settings.INSTANCE.getInstance(instance).getString("set_locale", "");
 
-        // Set the locale for API < 24 and set application resources and direction for API >=24
-        setLocale(getAppContext());
+                // Set the locale for API < 24 and set application resources and direction for API >=24
+                setLocale(getAppContext());
+            }
+        });
 
         WorkersKt.runIO(new Runnable() {
             @Override
@@ -129,10 +135,10 @@ public class VLCApplication extends Application {
         else {
             try {
                 instance = (VLCApplication) Class.forName("android.app.ActivityThread").getDeclaredMethod("currentApplication").invoke(null);
-            } catch (IllegalAccessException e) {}
-              catch (InvocationTargetException e) {}
-              catch (NoSuchMethodException e) {}
-              catch (ClassNotFoundException e) {}
+            } catch (IllegalAccessException ignored) {}
+            catch (InvocationTargetException ignored) {}
+            catch (NoSuchMethodException ignored) {}
+            catch (ClassNotFoundException ignored) {}
             return instance;
         }
     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index d5febafa3..2b89c26a2 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -25,13 +25,11 @@ import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
 import android.content.ServiceConnection;
-import android.database.Cursor;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.IBinder;
 import android.view.KeyEvent;
 import android.view.MenuItem;
-import android.widget.FilterQueryProvider;
 
 import com.google.android.material.navigation.NavigationView;
 



More information about the Android mailing list