use of com.android.ide.common.rendering.api.StyleResourceValue in project android by JetBrains.
the class StyleFilter method isDerived.
@VisibleForTesting
boolean isDerived(@NotNull StyleResourceValue style) {
String styleName = getStyleName(style);
if (myDerivedStyles.contains(styleName)) {
return true;
}
if (myOtherStyles.contains(styleName)) {
return false;
}
StyleResourceValue parentStyle = myResolver.getParent(style);
if (parentStyle != null && !myCurrentInheritanceChain.contains(styleName)) {
myCurrentInheritanceChain.add(styleName);
return found(styleName, isDerived(parentStyle));
}
return found(styleName, false);
}
use of com.android.ide.common.rendering.api.StyleResourceValue in project android by JetBrains.
the class EnumSupportFactoryTest method testStyle.
public void testStyle() {
StyleResourceValue checkboxStyle = new StyleResourceValue(ResourceType.STYLE, "Widget.CompoundButton.CheckBox", true);
ResourceValueMap frameworkResources = ResourceValueMap.create();
frameworkResources.put(checkboxStyle.getName(), checkboxStyle);
ResourceValueMap projectResources = ResourceValueMap.create();
when(myProperty.getTagName()).thenReturn(CHECK_BOX);
when(myResolver.getFrameworkResources()).thenReturn(Collections.singletonMap(ResourceType.STYLE, frameworkResources));
when(myResolver.getProjectResources()).thenReturn(Collections.singletonMap(ResourceType.STYLE, projectResources));
checkSupported(ATTR_STYLE, StyleEnumSupport.class);
}
use of com.android.ide.common.rendering.api.StyleResourceValue in project android by JetBrains.
the class StyleFilterTest method assertStyle.
private void assertStyle(@NotNull String name, boolean isFramework, boolean userDefined, boolean isDerived, boolean filteredOut) {
StyleResourceValue style;
if (isFramework) {
style = (StyleResourceValue) (myResolver.getFrameworkResources().get(ResourceType.STYLE).get(name));
} else {
style = (StyleResourceValue) (myResolver.getProjectResources().get(ResourceType.STYLE).get(name));
}
assertNotNull(style);
assertStyle(style, name, isFramework, userDefined, isDerived, filteredOut);
}
use of com.android.ide.common.rendering.api.StyleResourceValue in project android by JetBrains.
the class StyleFilterTest method dumpStyles.
private static void dumpStyles(@NotNull List<StyleResourceValue> styles) {
StringBuilder builder = new StringBuilder();
String divider = StringUtil.repeat("=", 80) + "\n";
builder.append(divider);
builder.append("Origin ");
builder.append("Name\n");
builder.append(divider);
for (StyleResourceValue style : styles) {
if (style.isUserDefined()) {
builder.append("User ");
} else if (!style.isFramework()) {
builder.append("AppCompat ");
} else {
builder.append("Framework ");
}
builder.append(style.getName());
builder.append("\n");
}
builder.append(divider);
System.err.println(builder);
}
use of com.android.ide.common.rendering.api.StyleResourceValue in project android_frameworks_base by crdroidandroid.
the class BridgeTypedArray method getResourceId.
/**
* Retrieve the resource identifier for the attribute at
* <var>index</var>. Note that attribute resource as resolved when
* the overall {@link TypedArray} object is retrieved. As a
* result, this function will return the resource identifier of the
* final resource value that was found, <em>not</em> necessarily the
* original resource that was specified by the attribute.
*
* @param index Index of attribute to retrieve.
* @param defValue Value to return if the attribute is not defined or
* not a resource.
*
* @return Attribute resource identifier, or defValue if not defined.
*/
@Override
public int getResourceId(int index, int defValue) {
if (index < 0 || index >= mResourceData.length) {
return defValue;
}
// get the Resource for this index
ResourceValue resValue = mResourceData[index];
// no data, return the default value.
if (resValue == null) {
return defValue;
}
// check if this is a style resource
if (resValue instanceof StyleResourceValue) {
// get the id that will represent this style.
return mContext.getDynamicIdByStyle((StyleResourceValue) resValue);
}
// (and getValue() returning null!). We need to handle this!
if (resValue.getResourceType() != null) {
// if this is a framework id
if (mPlatformFile || resValue.isFramework()) {
// look for idName in the android R classes
return mContext.getFrameworkResourceValue(resValue.getResourceType(), resValue.getName(), defValue);
}
// look for idName in the project R class.
return mContext.getProjectResourceValue(resValue.getResourceType(), resValue.getName(), defValue);
}
// else, try to get the value, and resolve it somehow.
String value = resValue.getValue();
if (value == null) {
return defValue;
}
// if the value is just an integer, return it.
try {
int i = Integer.parseInt(value);
if (Integer.toString(i).equals(value)) {
return i;
}
} catch (NumberFormatException e) {
// pass
}
// if this is a reference to an id, find it.
if (value.startsWith("@id/") || value.startsWith("@+") || value.startsWith("@android:id/")) {
int pos = value.indexOf('/');
String idName = value.substring(pos + 1);
boolean create = value.startsWith("@+");
boolean isFrameworkId = mPlatformFile || value.startsWith("@android") || value.startsWith("@+android");
// Look for the idName in project or android R class depending on isPlatform.
if (create) {
Integer idValue;
if (isFrameworkId) {
idValue = Bridge.getResourceId(ResourceType.ID, idName);
} else {
idValue = mContext.getLayoutlibCallback().getResourceId(ResourceType.ID, idName);
}
return idValue == null ? defValue : idValue;
}
// one is not found.
if (isFrameworkId) {
return mContext.getFrameworkResourceValue(ResourceType.ID, idName, defValue);
} else {
return mContext.getProjectResourceValue(ResourceType.ID, idName, defValue);
}
}
// not a direct id valid reference? resolve it
Integer idValue;
if (resValue.isFramework()) {
idValue = Bridge.getResourceId(resValue.getResourceType(), resValue.getName());
} else {
idValue = mContext.getLayoutlibCallback().getResourceId(resValue.getResourceType(), resValue.getName());
}
if (idValue != null) {
return idValue;
}
Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_RESOLVE, String.format("Unable to resolve id \"%1$s\" for attribute \"%2$s\"", value, mNames[index]), resValue);
return defValue;
}
Aggregations