当前位置: 首页>>代码示例>>Java>>正文


Java LocaleList类代码示例

本文整理汇总了Java中android.os.LocaleList的典型用法代码示例。如果您正苦于以下问题:Java LocaleList类的具体用法?Java LocaleList怎么用?Java LocaleList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LocaleList类属于android.os包,在下文中一共展示了LocaleList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: wrap

import android.os.LocaleList; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public static ContextWrapper wrap(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String lang = prefs.getString(Constants.PREF_APP_LANGUAGE, "");
    Locale locale = StringUtils.getLocale(lang);
    locale = (locale == null) ? Locale.getDefault() : locale;
    Configuration configuration = context.getResources().getConfiguration();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        LocaleList localeList = new LocaleList(locale);
        LocaleList.setDefault(localeList);
        Locale.setDefault(locale);
        configuration.setLocale(locale);
        configuration.setLocales(localeList);
        context = context.createConfigurationContext(configuration);

    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        configuration.setLocale(locale);
        context = context.createConfigurationContext(configuration);
    } else {
        configuration.locale = locale;
        context.getResources().updateConfiguration(configuration, null);
    }

    return new InventumContextWrapper(context);
}
 
开发者ID:qqq3,项目名称:inventum,代码行数:27,代码来源:InventumContextWrapper.java

示例2: wrap

import android.os.LocaleList; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public static ContextWrapper wrap(Context context, Locale newLocale)
{
    final Resources res = context.getResources();
    final Configuration configuration = res.getConfiguration();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
    {
        configuration.setLocale(newLocale);
        LocaleList localeList = new LocaleList(newLocale);
        LocaleList.setDefault(localeList);
        configuration.setLocales(localeList);
        context = context.createConfigurationContext(configuration);
    }
    else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
    {
        configuration.setLocale(newLocale);
        context = context.createConfigurationContext(configuration);
    }
    else
    {
        configuration.locale = newLocale;
        res.updateConfiguration(configuration, res.getDisplayMetrics());
    }
    return new ContextWrapper(context);
}
 
开发者ID:mkulesh,项目名称:microMathematics,代码行数:27,代码来源:AppLocale.java

示例3: setLocale

import android.os.LocaleList; //导入依赖的package包/类
public static void setLocale(@NonNull Context context) {
    Locale locale = Preferences.get(context).getCurrentLocale();
    Locale.setDefault(locale);

    Configuration configuration = context.getResources().getConfiguration();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        LocaleList.setDefault(new LocaleList(locale));
        configuration.setLocales(new LocaleList(locale));
        configuration.setLocale(locale);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        configuration.setLocale(locale);
    } else {
        configuration.locale = locale;
    }

    //Todo:
    // Find out a solution to use context.createConfigurationContext(configuration);
    // It breaks onConfigurationChanged()
    // Still can't find a way to fix that
    // No other options, better use deprecated code for now
    context.getResources().updateConfiguration(configuration, context.getResources().getDisplayMetrics());
}
 
开发者ID:danimahardhika,项目名称:wallpaperboard,代码行数:23,代码来源:LocaleHelper.java

示例4: wrap

import android.os.LocaleList; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public static ContextWrapper wrap(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String lang = prefs.getString(Constants.PREF_APP_LANGUAGE, "");
    Locale locale = StringUtils.getLocale(lang);
    locale = (locale == null) ? Locale.getDefault() : locale;
    Configuration configuration = context.getResources().getConfiguration();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        LocaleList localeList = new LocaleList(locale);
        LocaleList.setDefault(localeList);
        Locale.setDefault(locale);
        configuration.setLocale(locale);
        configuration.setLocales(localeList);
        context = context.createConfigurationContext(configuration);

    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        configuration.setLocale(locale);
        context = context.createConfigurationContext(configuration);
    } else {
        configuration.locale = locale;
        context.getResources().updateConfiguration(configuration, null);
    }

    return new ShowChatContextWrapper(context);
}
 
开发者ID:ansarisufiyan777,项目名称:Show_Chat,代码行数:27,代码来源:ShowChatContextWrapper.java

示例5: wrap

import android.os.LocaleList; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public static ContextWrapper wrap(Context context) {

    Locale newLocale;
    Resources res = context.getResources();
    Configuration configuration = res.getConfiguration();

    if (Tools.getBoolean("forceenglish", false, context))
        newLocale = new Locale("en_US");
    else
        newLocale = new Locale(Tools.sysLocale());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        configuration.setLocale(newLocale);
        LocaleList localeList = new LocaleList(newLocale);
        LocaleList.setDefault(localeList);
        configuration.setLocales(localeList);
        context = context.createConfigurationContext(configuration);
    } else { //if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
        configuration.setLocale(newLocale);
        context = context.createConfigurationContext(configuration);
    }

    return new ContextWrapper(context);
}
 
开发者ID:bhb27,项目名称:isu,代码行数:26,代码来源:CustomContextWrapper.java

示例6: getDefault

import android.os.LocaleList; //导入依赖的package包/类
public static List<Locale> getDefault(Context context, boolean getAllIfPossible) {
    List<Locale> list = new ArrayList();
    if (VERSION.SDK_INT >= 24) {
        LocaleList locales = context.getResources().getConfiguration().getLocales();
        for (int i = 0; i < locales.size(); i++) {
            Locale locale = locales.get(i);
            if (!getAllIfPossible) {
                list.add(locale);
                break;
            }
            list.add(locale);
        }
    } else {
        list.add(context.getResources().getConfiguration().locale);
    }
    return list;
}
 
开发者ID:mrprona92,项目名称:SecretBrand,代码行数:18,代码来源:LocaleUtils.java

示例7: getDateAsText

import android.os.LocaleList; //导入依赖的package包/类
CharSequence getDateAsText() {
    if (isDirectory) {
        return "";
    }

    Locale currentLocale;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
        @SuppressWarnings("deprecation")
        Locale locale = MediaMonkeyApplication.getInstance().getResources().getConfiguration().locale;
        currentLocale = locale;
    } else {
        Resources res = MediaMonkeyApplication.getInstance().getResources();
        LocaleList locales = res.getConfiguration().getLocales();
        currentLocale = locales.getFirstMatch(res.getAssets().getLocales());
    }

    DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, currentLocale);
    return format.format(new Date(file.lastModified()));
}
 
开发者ID:FrancescoJo,项目名称:MediaMonkey,代码行数:20,代码来源:PluginPkgVo.java

示例8: getResources

import android.os.LocaleList; //导入依赖的package包/类
@NonNull
public static Resources getResources(@NonNull final Context context, @NonNull final Locale locale) {
    Resources standardResources = context.getResources();

    AssetManager assets = standardResources.getAssets();
    DisplayMetrics metrics = standardResources.getDisplayMetrics();
    Configuration config = new Configuration(standardResources.getConfiguration());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        config.setLocales(LocaleList.forLanguageTags(Locale.ENGLISH.toLanguageTag()));
    } else {
        //noinspection deprecation
        config.locale = locale;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return context.createConfigurationContext(config).getResources();
    } else {
        //noinspection deprecation
        return new Resources(assets, metrics, config);
    }
}
 
开发者ID:canyapan,项目名称:DietDiaryApp,代码行数:22,代码来源:ResourcesHelper.java

示例9: wrap

import android.os.LocaleList; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public static ContextWrapper wrap(Context context) {

    Locale newLocale;
    Resources res = context.getResources();
    Configuration configuration = res.getConfiguration();

    if (Utils.getBoolean("forceenglish", false, context))
        newLocale = new Locale("en_US");
    else
        newLocale = new Locale(Utils.sysLocale());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        configuration.setLocale(newLocale);
        LocaleList localeList = new LocaleList(newLocale);
        LocaleList.setDefault(localeList);
        configuration.setLocales(localeList);
        context = context.createConfigurationContext(configuration);
    } else { //if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
        configuration.setLocale(newLocale);
        context = context.createConfigurationContext(configuration);
    }

    return new ContextWrapper(context);
}
 
开发者ID:bhb27,项目名称:KA27,代码行数:26,代码来源:CustomContextWrapper.java

示例10: applyLocalizationContext

import android.os.LocaleList; //导入依赖的package包/类
public static Context applyLocalizationContext(Context baseContext) {
    Locale baseLocale = LocalizationUtility.getLocaleFromConfiguration(baseContext.getResources().getConfiguration());
    Locale currentLocale = LanguageSetting.getLanguage(baseContext);
    if (!baseLocale.toString().equalsIgnoreCase(currentLocale.toString())) {
        LocalizationContext context = new LocalizationContext(baseContext);
        Configuration config = context.getResources().getConfiguration();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            config.setLocale(currentLocale);
            LocaleList localeList = new LocaleList(currentLocale);
            LocaleList.setDefault(localeList);
            config.setLocales(localeList);
            return context.createConfigurationContext(config);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            config.setLocale(currentLocale);
            return context.createConfigurationContext(config);
        } else {
            return context;
        }
    } else {
        return baseContext;
    }
}
 
开发者ID:akexorcist,项目名称:Android-LocalizationActivity,代码行数:23,代码来源:LocalizationUtility.java

示例11: attachBaseContext

import android.os.LocaleList; //导入依赖的package包/类
public Context attachBaseContext(Context context) {
    Locale locale = LanguageSetting.getLanguage(context);
    Configuration config = context.getResources().getConfiguration();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        config.setLocale(locale);
        LocaleList localeList = new LocaleList(locale);
        LocaleList.setDefault(localeList);
        config.setLocales(localeList);
        return context.createConfigurationContext(config);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        config.setLocale(locale);
        return context.createConfigurationContext(config);
    } else {
        return context;
    }
}
 
开发者ID:akexorcist,项目名称:Android-LocalizationActivity,代码行数:17,代码来源:LocalizationActivityDelegate.java

示例12: AlphabeticIndexVN

import android.os.LocaleList; //导入依赖的package包/类
AlphabeticIndexVN(Context context) {
    LocaleList locales = context.getResources().getConfiguration().getLocales();
    int localeCount = locales.size();

    Locale primaryLocale = localeCount == 0 ? Locale.ENGLISH : locales.get(0);
    AlphabeticIndex indexBuilder = new AlphabeticIndex(primaryLocale);
    for (int i = 1; i < localeCount; i++) {
        indexBuilder.addLabels(locales.get(i));
    }
    indexBuilder.addLabels(Locale.ENGLISH);

    mAlphabeticIndex = indexBuilder.buildImmutableIndex();
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:14,代码来源:AlphabeticIndexCompat.java

示例13: getSystemLanguage

import android.os.LocaleList; //导入依赖的package包/类
protected String getSystemLanguage() {
    Locale locale;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        locale = LocaleList.getDefault().get(0);
    } else {
        locale = Locale.getDefault();
    }

    String language = locale.getLanguage() + "-" + locale.getCountry();
    return language;
}
 
开发者ID:olami-developers,项目名称:olami-android-client-sdk,代码行数:12,代码来源:MainActivity.java

示例14: retrieve

import android.os.LocaleList; //导入依赖的package包/类
public static List<Locale> retrieve() {
    List<Locale> systemLocales;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        systemLocales = mapToListOfLocales(LocaleList.getDefault());
    } else {
        systemLocales = Collections.singletonList(Locale.getDefault());
    }
    return systemLocales;
}
 
开发者ID:franmontiel,项目名称:LocaleChanger,代码行数:11,代码来源:SystemLocaleRetriever.java

示例15: mapToListOfLocales

import android.os.LocaleList; //导入依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.N)
private static List<Locale> mapToListOfLocales(LocaleList localeList) {
    List<Locale> locales = new ArrayList<>();
    for (int i = 0; i < localeList.size(); i++) {
        locales.add(localeList.get(i));
    }
    return locales;
}
 
开发者ID:franmontiel,项目名称:LocaleChanger,代码行数:9,代码来源:SystemLocaleRetriever.java


注:本文中的android.os.LocaleList类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。