本文整理了Java中android.content.res.Resources.obtainAttributes
方法的一些代码示例,展示了Resources.obtainAttributes
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Resources.obtainAttributes
方法的具体详情如下:
包路径:android.content.res.Resources
类名称:Resources
方法名:obtainAttributes
暂无
代码示例来源:origin: aa112901/remusic
static TypedArray obtainAttributes(
Resources res, Resources.Theme theme, AttributeSet set, int[] attrs) {
if (theme == null) {
return res.obtainAttributes(set, attrs);
}
return theme.obtainStyledAttributes(set, attrs, 0, 0);
}
代码示例来源:origin: ZieIony/Carbon
static TypedArray obtainAttributes(Resources res, Resources.Theme theme, AttributeSet set, int[] attrs) {
if (theme == null) {
return res.obtainAttributes(set, attrs);
}
return theme.obtainStyledAttributes(set, attrs, 0, 0);
}
代码示例来源:origin: qiujuer/Genius-Android
static TypedArray obtainAttributes(
Resources res, Resources.Theme theme, AttributeSet set, int[] attrs) {
if (theme == null) {
return res.obtainAttributes(set, attrs);
}
return theme.obtainStyledAttributes(set, attrs, 0, 0);
}
代码示例来源:origin: android-hacker/VirtualXposed
private static AuthenticatorDescription parseAuthenticatorDescription(Resources resources, String packageName,
AttributeSet attributeSet) {
TypedArray array = resources.obtainAttributes(attributeSet, R_Hide.styleable.AccountAuthenticator.get());
try {
String accountType = array.getString(R_Hide.styleable.AccountAuthenticator_accountType.get());
int label = array.getResourceId(R_Hide.styleable.AccountAuthenticator_label.get(), 0);
int icon = array.getResourceId(R_Hide.styleable.AccountAuthenticator_icon.get(), 0);
int smallIcon = array.getResourceId(R_Hide.styleable.AccountAuthenticator_smallIcon.get(), 0);
int accountPreferences = array.getResourceId(R_Hide.styleable.AccountAuthenticator_accountPreferences.get(), 0);
boolean customTokens = array.getBoolean(R_Hide.styleable.AccountAuthenticator_customTokens.get(), false);
if (TextUtils.isEmpty(accountType)) {
return null;
}
return new AuthenticatorDescription(accountType, packageName, label, icon, smallIcon, accountPreferences,
customTokens);
} finally {
array.recycle();
}
}
代码示例来源:origin: robolectric/robolectric
@Implementation
protected TypedArray obtainAttributes(AttributeSet set, int[] attrs) {
if (isLegacyAssetManager()) {
return legacyShadowOf(realResources.getAssets())
.attrsToTypedArray(realResources, set, attrs, 0, 0, 0);
} else {
return directlyOn(realResources, Resources.class).obtainAttributes(set, attrs);
}
}
代码示例来源:origin: android-hacker/VirtualXposed
private SyncAdapterType parseSyncAdapterType(Resources res, AttributeSet set) {
TypedArray obtainAttributes = res.obtainAttributes(set, R_Hide.styleable.SyncAdapter.get());
try {
String contentAuthority = obtainAttributes.getString(R_Hide.styleable.SyncAdapter_contentAuthority.get());
String accountType = obtainAttributes.getString(R_Hide.styleable.SyncAdapter_accountType.get());
if (contentAuthority == null || accountType == null) {
obtainAttributes.recycle();
return null;
}
boolean userVisible = obtainAttributes.getBoolean(R_Hide.styleable.SyncAdapter_userVisible.get(), true);
boolean supportsUploading = obtainAttributes.getBoolean(R_Hide.styleable.SyncAdapter_supportsUploading.get(), true);
boolean isAlwaysSyncable = obtainAttributes.getBoolean(R_Hide.styleable.SyncAdapter_isAlwaysSyncable.get(), true);
boolean allowParallelSyncs = obtainAttributes.getBoolean(R_Hide.styleable.SyncAdapter_allowParallelSyncs.get(), true);
String settingsActivity = obtainAttributes.getString(R_Hide.styleable.SyncAdapter_settingsActivity.get());
SyncAdapterType type;
if (SyncAdapterTypeN.ctor != null) {
type = SyncAdapterTypeN.ctor.newInstance(contentAuthority, accountType, userVisible, supportsUploading, isAlwaysSyncable, allowParallelSyncs, settingsActivity, null);
obtainAttributes.recycle();
return type;
}
type = mirror.android.content.SyncAdapterType.ctor.newInstance(contentAuthority, accountType, userVisible, supportsUploading, isAlwaysSyncable, allowParallelSyncs, settingsActivity);
obtainAttributes.recycle();
return type;
} catch (Throwable e) {
e.printStackTrace();
}
return null;
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void attrsToTypedArray_shouldAllowMockedAttributeSets() throws Exception {
if (!useLegacy()) return;
AttributeSet mockAttributeSet = mock(AttributeSet.class);
when(mockAttributeSet.getAttributeCount()).thenReturn(1);
when(mockAttributeSet.getAttributeNameResource(0)).thenReturn(android.R.attr.windowBackground);
when(mockAttributeSet.getAttributeName(0)).thenReturn("android:windowBackground");
when(mockAttributeSet.getAttributeValue(0)).thenReturn("value");
resources.obtainAttributes(mockAttributeSet, new int[]{android.R.attr.windowBackground});
}
代码示例来源:origin: robolectric/robolectric
@Test
public void obtainAttributes_shouldReturnValuesFromResources() throws Exception {
XmlPullParser parser = resources.getXml(R.xml.xml_attrs);
parser.next();
parser.next();
AttributeSet attributes = Xml.asAttributeSet(parser);
TypedArray typedArray = resources
.obtainAttributes(attributes, new int[]{android.R.attr.title, android.R.attr.scrollbarFadeDuration});
assertThat(typedArray.getString(0)).isEqualTo("Android Title");
assertThat(typedArray.getInt(1, 0)).isEqualTo(1111);
typedArray.recycle();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void obtainAttributes_shouldUseReferencedIdFromAttributeSet() throws Exception {
// android:id/mask was introduced in API 21, but it's still possible for apps built against API 21 to refer to it
// in older runtimes because referenced resource ids are compiled (by aapt) into the binary XML format.
AttributeSet attributeSet = Robolectric.buildAttributeSet()
.addAttribute(android.R.attr.id, "@android:id/mask").build();
TypedArray typedArray = resources.obtainAttributes(attributeSet, new int[]{android.R.attr.id});
assertThat(typedArray.getResourceId(0, -9)).isEqualTo(android.R.id.mask);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void obtainAttributes_shouldReturnValuesFromAttributeSet() throws Exception {
AttributeSet attributes = Robolectric.buildAttributeSet()
.addAttribute(android.R.attr.title, "A title!")
.addAttribute(android.R.attr.width, "12px")
.addAttribute(android.R.attr.height, "1in")
.build();
TypedArray typedArray = resources
.obtainAttributes(attributes, new int[]{android.R.attr.height,
android.R.attr.width, android.R.attr.title});
assertThat(typedArray.getDimension(0, 0)).isEqualTo(160f);
assertThat(typedArray.getDimension(1, 0)).isEqualTo(12f);
assertThat(typedArray.getString(2)).isEqualTo("A title!");
typedArray.recycle();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void multiFormatAttributes_integerHexValue() {
AttributeSet attributeSet =
Robolectric.buildAttributeSet().addAttribute(R.attr.multiformat, "0x10").build();
TypedArray typedArray =
resources.obtainAttributes(attributeSet, new int[] {R.attr.multiformat});
TypedValue outValue = new TypedValue();
typedArray.getValue(0, outValue);
assertThat(outValue.type).isEqualTo(TypedValue.TYPE_INT_HEX);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void multiFormatAttributes_integerDecimalValue() {
AttributeSet attributeSet =
Robolectric.buildAttributeSet().addAttribute(R.attr.multiformat, "16").build();
TypedArray typedArray =
resources.obtainAttributes(attributeSet, new int[] {R.attr.multiformat});
TypedValue outValue = new TypedValue();
typedArray.getValue(0, outValue);
assertThat(outValue.type).isEqualTo(TypedValue.TYPE_INT_DEC);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void multiFormatAttributes_stringValue() {
AttributeSet attributeSet =
Robolectric.buildAttributeSet().addAttribute(R.attr.multiformat, "Hello World").build();
TypedArray typedArray =
resources.obtainAttributes(attributeSet, new int[] {R.attr.multiformat});
TypedValue outValue = new TypedValue();
typedArray.getValue(0, outValue);
assertThat(outValue.type).isEqualTo(TypedValue.TYPE_STRING);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void multiFormatAttributes_booleanValue() {
AttributeSet attributeSet =
Robolectric.buildAttributeSet().addAttribute(R.attr.multiformat, "true").build();
TypedArray typedArray =
resources.obtainAttributes(attributeSet, new int[] {R.attr.multiformat});
TypedValue outValue = new TypedValue();
typedArray.getValue(0, outValue);
assertThat(outValue.type).isEqualTo(TypedValue.TYPE_INT_BOOLEAN);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void obtainAttributes() {
TypedArray typedArray = resources.obtainAttributes(Robolectric.buildAttributeSet()
.addAttribute(R.attr.styleReference, "@xml/shortcuts")
.build(), new int[]{R.attr.styleReference});
assertThat(typedArray).isNotNull();
assertThat(typedArray.peekValue(0).resourceId).isEqualTo(R.xml.shortcuts);
}
代码示例来源:origin: iqiyi/Neptune
@Override
public TypedArray obtainAttributes(AttributeSet set, int[] attrs) {
try {
return super.obtainAttributes(set, attrs);
} catch (NotFoundException e) {
return mHostResources.obtainAttributes(set, attrs);
}
}
代码示例来源:origin: baidu/GPT
@Override
public TypedArray obtainAttributes(AttributeSet set, int[] attrs) {
try {
return super.obtainAttributes(set, attrs);
} catch (NotFoundException e) {
return mHostResources.obtainAttributes(set, attrs);
}
}
代码示例来源:origin: AlexMofer/ProjectX
static TypedArray obtainAttributes(Resources res, Resources.Theme theme,
AttributeSet set, int[] attrs) {
if (theme == null) {
return res.obtainAttributes(set, attrs);
}
return theme.obtainStyledAttributes(set, attrs, 0, 0);
}
代码示例来源:origin: alexjlockwood/kyrie
/**
* Obtains styled attributes from the theme, if available, or unstyled resources if the theme is
* null.
*/
@NonNull
private static TypedArray obtainAttributes(
Resources res, @Nullable Resources.Theme theme, AttributeSet set, @StyleableRes int[] attrs) {
return theme == null
? res.obtainAttributes(set, attrs)
: theme.obtainStyledAttributes(set, attrs, 0, 0);
}
代码示例来源:origin: org.robolectric/shadows-framework
@Implementation
protected TypedArray obtainAttributes(AttributeSet set, int[] attrs) {
if (isLegacyAssetManager()) {
return legacyShadowOf(realResources.getAssets())
.attrsToTypedArray(realResources, set, attrs, 0, 0, 0);
} else {
return directlyOn(realResources, Resources.class).obtainAttributes(set, attrs);
}
}
内容来源于网络,如有侵权,请联系作者删除!