diff options
Diffstat (limited to 'main/src/main/java/de')
3 files changed, 90 insertions, 1 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java b/main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java index 92bfb61f..b8e3d646 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java +++ b/main/src/main/java/de/blinkt/openvpn/core/ICSOpenVPNApplication.java @@ -10,12 +10,14 @@ import android.app.Application; import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; +import android.content.res.Configuration; import android.graphics.Color; import android.os.Build; import android.os.StrictMode; import android.os.strictmode.Violation; +import androidx.annotation.NonNull; import androidx.annotation.RequiresApi; import java.util.concurrent.Executors; @@ -35,7 +37,9 @@ public class ICSOpenVPNApplication extends Application { if("robolectric".equals(Build.FINGERPRINT)) return; + LocaleHelper.setDesiredLocale(this); super.onCreate(); + PRNGFixes.apply(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) @@ -48,6 +52,13 @@ public class ICSOpenVPNApplication extends Application { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { AppRestrictions.getInstance(this).checkRestrictions(this); } + + + } + + @Override + protected void attachBaseContext(Context base) { + super.attachBaseContext(LocaleHelper.updateResources(base)); } private void enableStrictModes() { @@ -74,6 +85,12 @@ public class ICSOpenVPNApplication extends Application { } + @Override + public void onConfigurationChanged(@NonNull Configuration newConfig) { + super.onConfigurationChanged(newConfig); + LocaleHelper.onConfigurationChange(this); + } + @RequiresApi(api = Build.VERSION_CODES.P) public void logViolation(Violation v) { String name = Application.getProcessName(); diff --git a/main/src/main/java/de/blinkt/openvpn/core/LocaleHelper.java b/main/src/main/java/de/blinkt/openvpn/core/LocaleHelper.java new file mode 100644 index 00000000..2b0c1975 --- /dev/null +++ b/main/src/main/java/de/blinkt/openvpn/core/LocaleHelper.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2012-2021 Arne Schwabe + * Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt + */ + +package de.blinkt.openvpn.core; + +import android.content.Context; +import android.content.res.Configuration; +import android.content.res.Resources; +import android.os.Build; + +import java.util.Locale; + +public class LocaleHelper { + static private Locale desiredLocale = null; + + public static void setDesiredLocale(Context c) + { + Locale current = Locale.getDefault(); + boolean defForce = true; + if (current.getLanguage().equals(new Locale("de").getLanguage())) + defForce = false; + + boolean allow_translation = Preferences.getDefaultSharedPreferences(c).getBoolean("allow_translation", defForce); + + if (!allow_translation) + desiredLocale = new Locale("en", current.getCountry()); + } + + public static Context updateResources(Context context) { + if (desiredLocale == null) + return context; + + Locale.setDefault(desiredLocale); + + Resources res = context.getResources(); + Configuration config = new Configuration(res.getConfiguration()); + if (Build.VERSION.SDK_INT >= 17) { + config.setLocale(desiredLocale); + context = context.createConfigurationContext(config); + } else { + config.locale = desiredLocale; + res.updateConfiguration(config, res.getDisplayMetrics()); + } + return context; + } + + public static void onConfigurationChange(Context context) + { + Resources res = context.getResources(); + + Locale current; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + current = res.getConfiguration().getLocales().get(0); + else + current = res.getConfiguration().locale; + + + if (current == desiredLocale) + return; + + Configuration config = new Configuration(res.getConfiguration()); + + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) + config.setLocale(desiredLocale); + else + config.locale = desiredLocale; + + res.updateConfiguration(config, res.getDisplayMetrics()); + } +} diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java index e4123838..f72c759f 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java +++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java @@ -490,7 +490,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement { if (proxyType == Connection.ProxyType.ORBOT) {
VpnStatus.updateStateString("WAIT_ORBOT", "Waiting for Orbot to start", R.string.state_waitorbot, ConnectionStatus.LEVEL_CONNECTING_NO_SERVER_REPLY_YET);
OrbotHelper orbotHelper = OrbotHelper.get(mOpenVPNService);
- if (!orbotHelper.checkTorReceier(mOpenVPNService))
+ if (!OrbotHelper.checkTorReceier(mOpenVPNService))
VpnStatus.logError("Orbot does not seem to be installed!");
mResumeHandler.postDelayed(orbotStatusTimeOutRunnable, ORBOT_TIMEOUT_MS);
|