Java Code Examples for android.content.res.Configuration#setToDefaults()

The following examples show how to use android.content.res.Configuration#setToDefaults() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: bt.java    From letv with Apache License 2.0 6 votes vote down vote up
private static Locale y(Context context) {
    Locale locale = null;
    try {
        Configuration configuration = new Configuration();
        configuration.setToDefaults();
        System.getConfiguration(context.getContentResolver(), configuration);
        if (configuration != null) {
            locale = configuration.locale;
        }
    } catch (Exception e) {
        bv.c(a, "fail to read user config locale");
    }
    if (locale == null) {
        return Locale.getDefault();
    }
    return locale;
}
 
Example 2
Source File: BaseActivity.java    From AndroidPicker with MIT License 6 votes vote down vote up
@Override
public Resources getResources() {
    Resources res = super.getResources();
    //强制字体大小不随系统改变而改变:https://blog.csdn.net/xuxian361/article/details/74909602
    if (res.getConfiguration().fontScale != 1f) {
        Configuration newConfig = new Configuration();
        newConfig.setToDefaults();
        res.updateConfiguration(newConfig, res.getDisplayMetrics());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            createConfigurationContext(newConfig);
        } else {
            res.updateConfiguration(newConfig, res.getDisplayMetrics());
        }
    }
    return res;
}
 
Example 3
Source File: BaseActivity.java    From BlogDemo with Apache License 2.0 5 votes vote down vote up
/**
 * 重写getResources()方法,让APP的字体不受系统设置字体大小影响
 */
@Override
public Resources getResources() {
    Resources res = super.getResources();
    Configuration config = new Configuration();
    config.setToDefaults();
    res.updateConfiguration(config, res.getDisplayMetrics());
    return res;
}
 
Example 4
Source File: App.java    From kAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    context = this;
    // 加载系统默认设置,字体不随用户设置变化
    Resources res = super.getResources();
    Configuration config = new Configuration();
    config.setToDefaults();
    res.updateConfiguration(config, res.getDisplayMetrics());


}
 
Example 5
Source File: RongRTCBaseActivity.java    From sealrtc-android with MIT License 5 votes vote down vote up
/**
 * 字体大小不随系统变化而变化 字体待定
 *
 * @return
 */
@Override
public Resources getResources() {
    Resources res = super.getResources();
    try {
        Configuration config = new Configuration();
        config.setToDefaults();
        res.updateConfiguration(config, res.getDisplayMetrics());
    } catch (Exception e) {
        e.printStackTrace();
    }
    return res;
}
 
Example 6
Source File: MyApplication.java    From SimpleProject with MIT License 5 votes vote down vote up
/**
 * 放大系统字体将导致布局错乱,所以一般可将其屏蔽
 * @return
 */
@Override
public Resources getResources() {
	Resources res = super.getResources();
	if (res.getConfiguration().fontScale != 1) {
		Configuration newConfig = new Configuration();
		newConfig.setToDefaults();
		res.updateConfiguration(newConfig, res.getDisplayMetrics());
	}

	return res;
}
 
Example 7
Source File: FrmApplication.java    From quickhybrid-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Resources getResources() {
    Resources res = super.getResources();
    if (res.getConfiguration().fontScale != 1) {//非默认值
        Configuration newConfig = new Configuration();
        newConfig.setToDefaults();//设置默认
        res.updateConfiguration(newConfig, res.getDisplayMetrics());
    }
    return res;
}
 
Example 8
Source File: CommonActivity.java    From FastAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 文本不随系统字体增大儿增大
 *
 * @return
 */
@Override
public Resources getResources() {
    Resources res = super.getResources();
    Configuration config = new Configuration();
    config.setToDefaults();
    res.updateConfiguration(config, res.getDisplayMetrics());
    return res;
}
 
Example 9
Source File: BasicActivity.java    From letv with Apache License 2.0 5 votes vote down vote up
public Resources getResources() {
    Resources res = super.getResources();
    Configuration config = new Configuration();
    config.setToDefaults();
    res.updateConfiguration(config, res.getDisplayMetrics());
    return res;
}
 
Example 10
Source File: ThemeManager.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
public void applyThemeToActivity(Activity activity) {
    if (currentCustomThemePatcher == null && currentCustomTheme != null) {
        ThemeResourceFileBuilder.CustomTheme theme = ThemeResourceFileBuilder
                .createTheme(context, currentCustomTheme);
        currentTheme = theme;
        File themeFile = ThemeResourceFileBuilder.createThemeZipFile(context,
                theme.getResTable());
        currentCustomThemePatcher = new Theme(context, themeFile.getAbsolutePath());
    }
    ThemeResInfo currentBaseTheme = currentTheme;
    if (currentCustomTheme != null)
        currentBaseTheme = currentCustomTheme.baseThemeInfo;
    boolean isThemeDark = currentBaseTheme instanceof BaseTheme &&
            ((BaseTheme) currentBaseTheme).isDark;
    if (currentCustomThemePatcher == null && isThemeDark) {
        currentCustomThemePatcher = new Theme(activity.getAssets());
    }
    if (mNeedsApplyIrcColors) {
        Configuration c = new Configuration();
        c.setToDefaults();
        c.uiMode = Configuration.UI_MODE_TYPE_NORMAL;
        if (currentBaseTheme instanceof BaseTheme && ((BaseTheme) currentBaseTheme).isDark)
            c.uiMode |= Configuration.UI_MODE_NIGHT_YES;
        Resources r = new Resources(currentCustomThemePatcher != null ?
                currentCustomThemePatcher.getAssetManager() : context.getAssets(),
                new DisplayMetrics(), c);
        Resources.Theme t = r.newTheme();
        ThemeResInfo resInfo = currentTheme != null ? currentTheme : fallbackTheme;
        t.applyStyle(resInfo.getThemeResId(), true);
        IRCColorUtils.loadColors(t, resInfo.getIRCColorsResId());
        mNeedsApplyIrcColors = false;
    }
    if (currentCustomThemePatcher != null) {
        currentCustomThemePatcher.applyToActivity(activity);
    }
    if (isThemeDark)
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
    else
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
 
Example 11
Source File: GApplication.java    From opencdk-appwidget with Apache License 2.0 5 votes vote down vote up
/**
 * 重写此方法, 使得app使用统一的默认配置
 */
@Override
public Resources getResources() {
	Resources res = super.getResources();
	Configuration config = new Configuration();
	config.setToDefaults();
	res.updateConfiguration(config, res.getDisplayMetrics());
	return res;
}
 
Example 12
Source File: WebViewActivity.java    From CloudReader with Apache License 2.0 5 votes vote down vote up
/**
 * 禁止改变字体大小
 */
@Override
public Resources getResources() {
    Resources res = super.getResources();
    Configuration config = new Configuration();
    config.setToDefaults();
    res.updateConfiguration(config, res.getDisplayMetrics());
    return res;
}
 
Example 13
Source File: MainActivity.java    From CloudReader with Apache License 2.0 5 votes vote down vote up
/**
 * 禁止改变字体大小
 */
@Override
public Resources getResources() {
    Resources res = super.getResources();
    Configuration config = new Configuration();
    config.setToDefaults();
    res.updateConfiguration(config, res.getDisplayMetrics());
    return res;
}
 
Example 14
Source File: BaseActivity.java    From CloudReader with Apache License 2.0 5 votes vote down vote up
/**
 * 禁止改变字体大小
 */
@Override
public Resources getResources() {
    Resources res = super.getResources();
    Configuration config = new Configuration();
    config.setToDefaults();
    res.updateConfiguration(config, res.getDisplayMetrics());
    return res;
}