android.content.res.Configuration类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(241)

本文整理了Java中android.content.res.Configuration类的一些代码示例,展示了Configuration类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration类的具体详情如下:
包路径:android.content.res.Configuration
类名称:Configuration

Configuration介绍

暂无

代码示例

代码示例来源:origin: robolectric/robolectric

static Configuration ConstructConfigurationObject(/* JNIEnv* env,*/ ResTable_config config) {
 // jobject result =
 //     env.NewObject(gConfigurationOffsets.classObject, gConfigurationOffsets.constructor);
 Configuration result = new Configuration();
 // if (result == null) {
 //   return null;
 // }
 result.smallestScreenWidthDp = config.smallestScreenWidthDp;
 result.screenWidthDp = config.screenWidthDp;
 result.screenHeightDp = config.screenHeightDp;
 return result;
}

代码示例来源:origin: robolectric/robolectric

private static void setLocale(int apiLevel, Configuration configuration, Locale locale) {
 if (apiLevel >= VERSION_CODES.JELLY_BEAN_MR1) {
  configuration.setLocale(locale);
 } else {
  configuration.locale = locale;
 }
}

代码示例来源:origin: facebook/litho

@TargetApi(JELLY_BEAN_MR1)
private static int getLayoutDirection(Context context) {
 return context.getResources().getConfiguration().getLayoutDirection();
}

代码示例来源:origin: facebook/litho

static synchronized ResourceCache getLatest(Configuration configuration) {
 if (latest == null || !latest.mConfiguration.equals(configuration)) {
  latest = new LruResourceCache(new Configuration(configuration));
 }
 return latest;
}

代码示例来源:origin: gzu-liyujiang/AndroidPicker

@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;
}

代码示例来源:origin: seven332/EhViewer

public static ContextLocalWrapper wrap(Context context, Locale newLocale) {
  Resources res = context.getResources();
  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 ContextLocalWrapper(context);
 }
}

代码示例来源:origin: westnordost/StreetComplete

private Resources getResources(Locale locale)
  {
    Configuration configuration = new Configuration(applicationContext.getResources().getConfiguration());
    configuration.setLocale(locale);
    return applicationContext.createConfigurationContext(configuration).getResources();
  }
}

代码示例来源:origin: robolectric/robolectric

private static Locale getLocale(Configuration configuration, int apiLevel) {
 Locale locale;
 if (apiLevel > Build.VERSION_CODES.M) {
  locale = configuration.getLocales().get(0);
 } else {
  locale = configuration.locale;
 }
 return locale;
}

代码示例来源:origin: robolectric/robolectric

new android.content.res.Configuration();
DisplayMetrics displayMetrics = new DisplayMetrics();
  ? androidConfiguration.getLocales().get(0)
  : androidConfiguration.locale;
Locale.setDefault(locale);

代码示例来源:origin: facebook/litho

private LithoView setupLithoViewForDoubleMeasureTest(
  int screenWidthDp, float density, int screenWidthPx) {
 final Context context = spy(new ContextWrapper(RuntimeEnvironment.application));
 final Resources resources = spy(context.getResources());
 doReturn(resources).when(context).getResources();
 final Configuration configuration = new Configuration();
 configuration.setTo(resources.getConfiguration());
 final DisplayMetrics displayMetrics = new DisplayMetrics();
 displayMetrics.setTo(resources.getDisplayMetrics());
 doReturn(configuration).when(resources).getConfiguration();
 doReturn(displayMetrics).when(resources).getDisplayMetrics();
 configuration.screenWidthDp = screenWidthDp;
 displayMetrics.density = density;
 displayMetrics.widthPixels = screenWidthPx;
 return new LithoView(context);
}

代码示例来源:origin: robolectric/robolectric

@Test public void testToString_shouldntExplode() throws Exception {
  assertThat(new Configuration().toString()).contains("mcc");
 }
}

代码示例来源:origin: robolectric/robolectric

@Test
public void setToDefaultsShouldSetRealDefaults() {
 configuration.setToDefaults();
 assertThat(configuration.fontScale).isEqualTo(1.0f);
 assertThat(configuration.screenLayout).isEqualTo(SCREENLAYOUT_UNDEFINED);
}

代码示例来源:origin: MichaelJokAr/MultiLanguages

/**
 * 设置语言类型
 */
public static void setApplicationLanguage(Context context) {
  Resources resources = context.getApplicationContext().getResources();
  DisplayMetrics dm = resources.getDisplayMetrics();
  Configuration config = resources.getConfiguration();
  Locale locale = getSetLanguageLocale(context);
  config.locale = locale;
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    LocaleList localeList = new LocaleList(locale);
    LocaleList.setDefault(localeList);
    config.setLocales(localeList);
    context.getApplicationContext().createConfigurationContext(config);
    Locale.setDefault(locale);
  }
  resources.updateConfiguration(config, dm);
}

代码示例来源:origin: ukanth/afwall

private static Context updateResources(Context context, String language) {
  Locale locale = new Locale(language);
  Locale.setDefault(locale);
  Resources res = context.getResources();
  Configuration config = new Configuration(res.getConfiguration());
  if (Build.VERSION.SDK_INT >= 17) {
    config.setLocale(locale);
    context = context.createConfigurationContext(config);
  } else {
    config.locale = locale;
    res.updateConfiguration(config, res.getDisplayMetrics());
  }
  return context;
}

代码示例来源:origin: robolectric/robolectric

@Test
public void testConstructCopy() {
 configuration.setToDefaults();
 Configuration clone = new Configuration(configuration);
 assertThat(configuration).isEqualTo(clone);
}

代码示例来源:origin: ukanth/afwall

public static ContextWrapper wrap(Context context, Locale newLocale) {
  Resources res = context.getResources();
  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);
}

代码示例来源:origin: robolectric/robolectric

private static List<Locale> getLocales(Configuration config) {
  List<Locale> locales = new ArrayList<>();
  if (RuntimeEnvironment.getApiLevel() > Build.VERSION_CODES.M) {
   LocaleList localeList = config.getLocales();
   for (int i = 0; i < localeList.size(); i++) {
    locales.add(localeList.get(i));
   }
  } else if (config.locale != null) {
   locales.add(config.locale);
  }
  return locales;
 }
}

代码示例来源:origin: org.robolectric/robolectric

Configuration configuration = new Configuration();
DisplayMetrics displayMetrics = new DisplayMetrics();
  ? configuration.getLocales().get(0)
  : configuration.locale;
Locale.setDefault(locale);

代码示例来源:origin: org.robolectric/shadows-core

@Deprecated
@Implementation
public void setToDefaults() {
 directlyOn(realConfiguration, Configuration.class).setToDefaults();
}

代码示例来源:origin: facebook/litho

public static ComparableResDrawable create(Context context, @DrawableRes int resId) {
  Configuration config = new Configuration(context.getResources().getConfiguration());
  Drawable drawable = ContextCompat.getDrawable(context, resId);
  return new ComparableResDrawable(resId, config, drawable);
 }
}

相关文章