2020-02-28 19:10:00 +01:00
|
|
|
package com.darkweb.genesissearchengine.helperManager;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.res.Configuration;
|
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.view.ContextThemeWrapper;
|
|
|
|
|
2021-02-03 11:54:19 +01:00
|
|
|
import com.darkweb.genesissearchengine.appManager.homeManager.homeController.homeController;
|
2020-02-28 19:10:00 +01:00
|
|
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Umesh on 10/10/16.
|
|
|
|
*/
|
|
|
|
public class LocaleUtils {
|
|
|
|
|
|
|
|
private static Locale mLocale;
|
|
|
|
|
|
|
|
public static void setLocale(Locale locale){
|
|
|
|
mLocale = locale;
|
|
|
|
if(mLocale != null){
|
|
|
|
Locale.setDefault(mLocale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void updateConfiguration(ContextThemeWrapper wrapper){
|
|
|
|
if(mLocale != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
|
|
|
|
Configuration configuration = new Configuration();
|
|
|
|
configuration.setLocale(mLocale);
|
|
|
|
wrapper.applyOverrideConfiguration(configuration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void updateConfiguration(homeController application, Configuration configuration){
|
|
|
|
if(mLocale != null && Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1){
|
|
|
|
Configuration config = new Configuration(configuration);
|
|
|
|
config.locale = mLocale;
|
|
|
|
Resources res = application.getBaseContext().getResources();
|
|
|
|
res.updateConfiguration(configuration, res.getDisplayMetrics());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void updateConfiguration(Context context, String language, String country){
|
|
|
|
Locale locale = new Locale(language,country);
|
|
|
|
setLocale(locale);
|
|
|
|
if(mLocale != null){
|
|
|
|
Resources res = context.getResources();
|
|
|
|
Configuration configuration = res.getConfiguration();
|
|
|
|
configuration.locale = mLocale;
|
|
|
|
res.updateConfiguration(configuration,res.getDisplayMetrics());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String getPrefLangCode(Context context) {
|
|
|
|
return PreferenceManager.getDefaultSharedPreferences(context).getString("lang_code","en");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setPrefLangCode(Context context, String mPrefLangCode) {
|
|
|
|
|
|
|
|
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
|
|
|
|
editor.putString("lang_code",mPrefLangCode);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getPrefCountryCode(Context context) {
|
|
|
|
return PreferenceManager.getDefaultSharedPreferences(context).getString("country_code","US");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setPrefCountryCode(Context context,String mPrefCountryCode) {
|
|
|
|
|
|
|
|
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
|
|
|
|
editor.putString("country_code",mPrefCountryCode);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
}
|