Make language change stick properly
As seen in https://stackoverflow.com/questions/2264874/changing-locale-within-the-app-itself. Fixes #458.
This commit is contained in:
parent
8307015d8d
commit
2ceeda40b7
@ -91,7 +91,7 @@
|
||||
<activity
|
||||
android:name=".FDroid"
|
||||
android:launchMode="singleTop"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize" >
|
||||
android:configChanges="layoutDirection|locale|keyboardHidden|orientation|screenSize" >
|
||||
|
||||
<!-- App URLs -->
|
||||
<intent-filter>
|
||||
@ -300,7 +300,8 @@
|
||||
<activity
|
||||
android:name=".privileged.views.InstallConfirmActivity"
|
||||
android:label="@string/menu_install"
|
||||
android:parentActivityName=".FDroid">
|
||||
android:parentActivityName=".FDroid"
|
||||
android:configChanges="layoutDirection|locale" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".FDroid" />
|
||||
@ -309,7 +310,8 @@
|
||||
android:name=".views.ManageReposActivity"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleTask"
|
||||
android:parentActivityName=".FDroid" >
|
||||
android:parentActivityName=".FDroid"
|
||||
android:configChanges="layoutDirection|locale" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".FDroid" />
|
||||
@ -323,12 +325,14 @@
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".NfcNotEnabledActivity"
|
||||
android:noHistory="true" />
|
||||
android:noHistory="true"
|
||||
android:configChanges="layoutDirection|locale" />
|
||||
<activity
|
||||
android:name=".views.RepoDetailsActivity"
|
||||
android:label="@string/repo_details"
|
||||
android:parentActivityName=".views.ManageReposActivity"
|
||||
android:windowSoftInputMode="stateHidden">
|
||||
android:windowSoftInputMode="stateHidden"
|
||||
android:configChanges="layoutDirection|locale" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".views.ManageReposActivity" />
|
||||
@ -338,7 +342,8 @@
|
||||
android:name=".AppDetails"
|
||||
android:label="@string/app_details"
|
||||
android:exported="true"
|
||||
android:parentActivityName=".FDroid" >
|
||||
android:parentActivityName=".FDroid"
|
||||
android:configChanges="layoutDirection|locale" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".FDroid" />
|
||||
@ -378,7 +383,8 @@
|
||||
android:label="@string/search_results"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTop"
|
||||
android:parentActivityName=".FDroid" >
|
||||
android:parentActivityName=".FDroid"
|
||||
android:configChanges="layoutDirection|locale" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".FDroid" />
|
||||
|
@ -66,6 +66,8 @@ public class FDroidApp extends Application {
|
||||
|
||||
private static final String TAG = "FDroidApp";
|
||||
|
||||
private static Locale locale = null;
|
||||
|
||||
// for the local repo on this device, all static since there is only one
|
||||
public static int port;
|
||||
public static String ipAddressString;
|
||||
@ -145,18 +147,25 @@ public class FDroidApp extends Application {
|
||||
bssid = "";
|
||||
}
|
||||
|
||||
public static void updateLanguage(Context c) {
|
||||
SharedPreferences prefs = PreferenceManager
|
||||
.getDefaultSharedPreferences(c);
|
||||
public void updateLanguage() {
|
||||
Context ctx = getBaseContext();
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||
String lang = prefs.getString("language", "");
|
||||
updateLanguage(c, lang);
|
||||
locale = Utils.getLocaleFromAndroidLangTag(lang);
|
||||
applyLanguage();
|
||||
}
|
||||
|
||||
public static void updateLanguage(Context c, String lang) {
|
||||
final Configuration cfg = new Configuration();
|
||||
final Locale newLocale = Utils.getLocaleFromAndroidLangTag(lang);
|
||||
cfg.locale = newLocale == null ? Locale.getDefault() : newLocale;
|
||||
c.getResources().updateConfiguration(cfg, null);
|
||||
private void applyLanguage() {
|
||||
Context ctx = getBaseContext();
|
||||
Configuration cfg = new Configuration();
|
||||
cfg.locale = locale == null ? Locale.getDefault() : locale;
|
||||
ctx.getResources().updateConfiguration(cfg, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
applyLanguage();
|
||||
}
|
||||
|
||||
@TargetApi(9)
|
||||
@ -172,7 +181,7 @@ public class FDroidApp extends Application {
|
||||
.penaltyLog()
|
||||
.build());
|
||||
}
|
||||
updateLanguage(this);
|
||||
updateLanguage();
|
||||
super.onCreate();
|
||||
|
||||
// Needs to be setup before anything else tries to access it.
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.fdroid.fdroid.views.fragments;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
@ -130,8 +131,9 @@ public class PreferencesFragment extends PreferenceFragment
|
||||
entrySummary(key);
|
||||
if (changing) {
|
||||
result |= PreferencesActivity.RESULT_RESTART;
|
||||
getActivity().setResult(result);
|
||||
FDroidApp.updateLanguage(this.getActivity());
|
||||
Activity activity = getActivity();
|
||||
activity.setResult(result);
|
||||
((FDroidApp) activity.getApplication()).updateLanguage();
|
||||
}
|
||||
break;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user