org.robolectric.res.Qualifiers.parse()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(121)

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

Qualifiers.parse介绍

暂无

代码示例

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

public static Qualifiers parse(String qualifiers) {
 return parse(qualifiers, true);
}

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

public static Qualifiers fromParentDir(Path parentDir) {
 if (parentDir == null) {
  return parse("");
 } else {
  String parentDirName = parentDir.getFileName().toString();
  Matcher matcher = DIR_QUALIFIER_PATTERN.matcher(parentDirName);
  if (!matcher.find()) {
   throw new IllegalStateException(parentDirName);
  }
  String qualifiers = matcher.group(1);
  return parse(qualifiers != null ? qualifiers : "");
 }
}

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

public static void applyQualifiers(String qualifiersStrs, int apiLevel,
  Configuration configuration, DisplayMetrics displayMetrics) {
 String[] qualifiersParts = qualifiersStrs.split(" ", 0);
 int i = qualifiersParts.length - 1;
 // find the index of the left-most qualifier string that doesn't start with '+'
 for (; i >= 0 ; i--) {
  String qualifiersStr = qualifiersParts[i];
  if (qualifiersStr.startsWith("+")) {
   qualifiersParts[i] = qualifiersStr.substring(1);
  } else {
   break;
  }
 }
 for (i = (i < 0) ? 0 : i; i < qualifiersParts.length ; i++) {
  String qualifiersStr = qualifiersParts[i];
  int platformVersion = Qualifiers.getPlatformVersion(qualifiersStr);
  if (platformVersion != -1 && platformVersion != apiLevel) {
   throw new IllegalArgumentException(
     "Cannot specify conflicting platform version in qualifiers: \"" + qualifiersStr + "\"");
  }
  Qualifiers qualifiers = Qualifiers.parse(qualifiersStr);
  DeviceConfig.applyToConfiguration(qualifiers, apiLevel, configuration, displayMetrics);
 }
 DeviceConfig.applyRules(configuration, displayMetrics, apiLevel);
 fixJellyBean(configuration, displayMetrics);
}

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

private void applyQualifiers(String qualifiers) {
 DeviceConfig.applyToConfiguration(Qualifiers.parse(qualifiers),
   apiLevel, configuration, displayMetrics);
}

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

@Nonnull
private static TypedResource<String> createStringTypedResource(String str, String qualifiersStr) {
 XmlContext mockXmlContext = mock(XmlContext.class);
 Qualifiers qualifiers = Qualifiers.parse(qualifiersStr);
 when(mockXmlContext.getQualifiers()).thenReturn(qualifiers);
 when(mockXmlContext.getConfig()).thenReturn(qualifiers.getConfig());
 return new TypedResource<>(str, ResType.CHAR_SEQUENCE, mockXmlContext);
}

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

@Test
public void shouldNotOverwriteValuesWithMatchingQualifiers() {
 ResBundle bundle = new ResBundle();
 XmlContext xmlContext = mock(XmlContext.class);
 when(xmlContext.getQualifiers()).thenReturn(Qualifiers.parse("--"));
 when(xmlContext.getConfig()).thenReturn(new ResTable_config());
 when(xmlContext.getPackageName()).thenReturn("org.robolectric");
 TypedResource firstValue = new TypedResource<>("first_value", ResType.CHAR_SEQUENCE, xmlContext);
 TypedResource secondValue = new TypedResource<>("second_value", ResType.CHAR_SEQUENCE, xmlContext);
 bundle.put(new ResName("org.robolectric", "string", "resource_name"), firstValue);
 bundle.put(new ResName("org.robolectric", "string", "resource_name"), secondValue);
 assertThat(bundle.get(new ResName("org.robolectric", "string", "resource_name"), from("")).getData()).isEqualTo("first_value");
}

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

@Override
public TypedResource getValue(@Nonnull ResName resName, ResTable_config config) {
 System.out.println("getValue(" + resName + ", \"" + config + "\")");
 return new TypedResource<>(null, ResType.NULL,
   new XmlContext("", Fs.newFile("."), Qualifiers.parse("")));
}

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

@Override
public TypedResource getValue(int resId, ResTable_config config) {
 System.out.println("getValue(" + resId + ", \"" + config + "\")");
 return new TypedResource<>(null, ResType.NULL,
   new XmlContext("", Fs.newFile("."), Qualifiers.parse("")));
}

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

public static Qualifiers parse(String qualifiers) {
 return parse(qualifiers, true);
}

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

public static Qualifiers fromParentDir(FsFile parentDir) {
 if (parentDir == null) {
  return parse("");
 } else {
  String parentDirName = parentDir.getName();
  Matcher matcher = DIR_QUALIFIER_PATTERN.matcher(parentDirName);
  if (!matcher.find()) throw new IllegalStateException(parentDirName);
  String qualifiers = matcher.group(1);
  return parse(qualifiers != null ? qualifiers : "");
 }
}

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

Qualifiers toMatch = Qualifiers.parse(qualifiersStr);
 Qualifiers qualifiers = Qualifiers.parse(candidate.getQualifiers());
 if (qualifiers.passesRequirements(toMatch)) {
  passesRequirements.add(candidate);
TypedResource bestMatch = null;
for (TypedResource candidate : passesRequirements) {
 Qualifiers qualifiers = Qualifiers.parse(candidate.getQualifiers());
 if (qualifiers.matches(toMatch)) {
  if (bestMatchQualifiers == null || qualifiers.isBetterThan(bestMatchQualifiers, toMatch)) {

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

public static void applyQualifiers(String qualifiersStrs, int apiLevel,
  Configuration configuration, DisplayMetrics displayMetrics) {
 String[] qualifiersParts = qualifiersStrs.split(" ", 0);
 int i = qualifiersParts.length - 1;
 // find the index of the left-most qualifier string that doesn't start with '+'
 for (; i >= 0 ; i--) {
  String qualifiersStr = qualifiersParts[i];
  if (qualifiersStr.startsWith("+")) {
   qualifiersParts[i] = qualifiersStr.substring(1);
  } else {
   break;
  }
 }
 for (i = (i < 0) ? 0 : i; i < qualifiersParts.length ; i++) {
  String qualifiersStr = qualifiersParts[i];
  int platformVersion = Qualifiers.getPlatformVersion(qualifiersStr);
  if (platformVersion != -1 && platformVersion != apiLevel) {
   throw new IllegalArgumentException(
     "Cannot specify conflicting platform version in qualifiers: \"" + qualifiersStr + "\"");
  }
  Qualifiers qualifiers = Qualifiers.parse(qualifiersStr);
  DeviceConfig.applyToConfiguration(qualifiers, apiLevel, configuration, displayMetrics);
 }
 DeviceConfig.applyRules(configuration, displayMetrics, apiLevel);
 fixJellyBean(configuration, displayMetrics);
}

相关文章