session-android/src/org/thoughtcrime/securesms/util/DynamicLanguage.java

56 lines
1.6 KiB
Java
Raw Normal View History

2013-06-30 01:03:55 +00:00
package org.thoughtcrime.securesms.util;
import android.app.Activity;
import android.app.Service;
import android.content.Context;
2013-06-30 01:03:55 +00:00
import android.content.res.Configuration;
import org.thoughtcrime.securesms.util.dynamiclanguage.LanguageString;
2013-06-30 01:03:55 +00:00
import java.util.Locale;
/**
* @deprecated Use a base activity that uses the {@link org.thoughtcrime.securesms.util.dynamiclanguage.DynamicLanguageContextWrapper}
*/
@Deprecated
2013-06-30 01:03:55 +00:00
public class DynamicLanguage {
public void onCreate(Activity activity) {
}
public void onResume(Activity activity) {
}
public void updateServiceLocale(Service service) {
setContextLocale(service, getSelectedLocale(service));
}
public Locale getCurrentLocale() {
return Locale.getDefault();
}
static int getLayoutDirection(Context context) {
2015-11-26 18:04:27 +00:00
Configuration configuration = context.getResources().getConfiguration();
return configuration.getLayoutDirection();
}
private static void setContextLocale(Context context, Locale selectedLocale) {
Configuration configuration = context.getResources().getConfiguration();
2013-06-30 01:03:55 +00:00
2014-03-11 17:47:35 +00:00
if (!configuration.locale.equals(selectedLocale)) {
configuration.setLocale(selectedLocale);
context.getResources().updateConfiguration(configuration,
2015-11-26 18:04:27 +00:00
context.getResources().getDisplayMetrics());
2013-06-30 01:03:55 +00:00
}
}
private static Locale getSelectedLocale(Context context) {
Locale locale = LanguageString.parseLocale(TextSecurePreferences.getLanguage(context));
if (locale == null) {
2014-03-11 17:47:35 +00:00
return Locale.getDefault();
} else {
return locale;
2013-06-30 01:03:55 +00:00
}
}
}