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