Example usage for android.content.res Configuration Configuration

List of usage examples for android.content.res Configuration Configuration

Introduction

In this page you can find the example usage for android.content.res Configuration Configuration.

Prototype

private Configuration(Parcel source) 

Source Link

Document

Construct this Configuration object, reading from the Parcel.

Usage

From source file:im.vector.VectorApp.java

/**
 * Update the font size from the locale description.
 *
 * @param fontScaleDescription the font scale description
 *//*www.j av a  2 s  .c  o m*/
public static void updateFontScale(String fontScaleDescription) {
    Context context = VectorApp.getInstance();
    for (Map.Entry<String, Integer> entry : mFontTextScaleIdByPrefKey.entrySet()) {
        if (TextUtils.equals(context.getString(entry.getValue()), fontScaleDescription)) {
            saveFontScale(entry.getKey());
        }
    }

    Configuration config = new Configuration(context.getResources().getConfiguration());
    config.fontScale = getFontScaleValue();
    context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
}

From source file:im.vector.VectorApp.java

/**
 * Update the application locale.//from  www  . j  av a  2 s.  c  o m
 *
 * @param locale the locale
 * @param theme  the new theme
 */
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private static void updateApplicationSettings(Locale locale, String textSize, String theme) {
    Context context = VectorApp.getInstance();

    saveApplicationLocale(locale);
    saveFontScale(textSize);
    Locale.setDefault(locale);

    Configuration config = new Configuration(context.getResources().getConfiguration());
    config.locale = locale;
    config.fontScale = getFontScaleValue();
    context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());

    ThemeUtils.setApplicationTheme(context, theme);
    PhoneNumberUtils.onLocaleUpdate();
}

From source file:im.vector.VectorApp.java

/**
 * Get String from a locale/*from  w  w w. j  a  v  a  2  s . co  m*/
 *
 * @param context    the context
 * @param locale     the locale
 * @param resourceId the string resource id
 * @return the localized string
 */
private static String getString(Context context, Locale locale, int resourceId) {
    String result;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Configuration config = new Configuration(context.getResources().getConfiguration());
        config.setLocale(locale);
        try {
            result = context.createConfigurationContext(config).getText(resourceId).toString();
        } catch (Exception e) {
            Log.e(LOG_TAG, "## getString() failed : " + e.getMessage());
            // use the default one
            result = context.getString(resourceId);
        }
    } else {
        Resources resources = context.getResources();
        Configuration conf = resources.getConfiguration();
        Locale savedLocale = conf.locale;
        conf.locale = locale;
        resources.updateConfiguration(conf, null);

        // retrieve resources from desired locale
        result = resources.getString(resourceId);

        // restore original locale
        conf.locale = savedLocale;
        resources.updateConfiguration(conf, null);
    }

    return result;
}