Fix manually switching language to Chinese

This commit is contained in:
Cameron Gutman
2017-05-04 22:24:18 -07:00
parent b21ee5ca31
commit b5c96cbb53
6 changed files with 31 additions and 29 deletions

View File

@@ -9,6 +9,9 @@ import android.content.res.Configuration;
import android.view.View;
import com.limelight.R;
import com.limelight.preferences.PreferenceConfiguration;
import java.util.Locale;
public class UiHelper {
@@ -16,6 +19,28 @@ public class UiHelper {
private static final int TV_VERTICAL_PADDING_DP = 27;
private static final int TV_HORIZONTAL_PADDING_DP = 48;
public static void setLocale(Activity activity)
{
String locale = PreferenceConfiguration.readPreferences(activity).language;
if (!locale.equals(PreferenceConfiguration.DEFAULT_LANGUAGE)) {
Configuration config = new Configuration(activity.getResources().getConfiguration());
// Some locales include both language and country which must be separated
// before calling the Locale constructor.
if (locale.contains("-"))
{
config.locale = new Locale(locale.substring(0, locale.indexOf('-')),
locale.substring(locale.indexOf('-') + 1));
}
else
{
config.locale = new Locale(locale);
}
activity.getResources().updateConfiguration(config, activity.getResources().getDisplayMetrics());
}
}
public static void notifyNewRootView(Activity activity)
{
View rootView = activity.findViewById(android.R.id.content);