Merge "Fix BridgeContext.get*ResourceValue()" into lmp-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
9b64954cb5
@@ -19,6 +19,7 @@ package com.android.layoutlib.bridge;
|
|||||||
import static com.android.ide.common.rendering.api.Result.Status.ERROR_UNKNOWN;
|
import static com.android.ide.common.rendering.api.Result.Status.ERROR_UNKNOWN;
|
||||||
import static com.android.ide.common.rendering.api.Result.Status.SUCCESS;
|
import static com.android.ide.common.rendering.api.Result.Status.SUCCESS;
|
||||||
|
|
||||||
|
import com.android.annotations.NonNull;
|
||||||
import com.android.ide.common.rendering.api.Capability;
|
import com.android.ide.common.rendering.api.Capability;
|
||||||
import com.android.ide.common.rendering.api.DrawableParams;
|
import com.android.ide.common.rendering.api.DrawableParams;
|
||||||
import com.android.ide.common.rendering.api.LayoutLog;
|
import com.android.ide.common.rendering.api.LayoutLog;
|
||||||
@@ -459,7 +460,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
|
|||||||
|
|
||||||
public static void setLog(LayoutLog log) {
|
public static void setLog(LayoutLog log) {
|
||||||
// check only the thread currently owning the lock can do this.
|
// check only the thread currently owning the lock can do this.
|
||||||
if (sLock.isHeldByCurrentThread() == false) {
|
if (!sLock.isHeldByCurrentThread()) {
|
||||||
throw new IllegalStateException("scene must be acquired first. see #acquire(long)");
|
throw new IllegalStateException("scene must be acquired first. see #acquire(long)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -489,7 +490,6 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the name of a framework resource whose value is an int array.
|
* Returns the name of a framework resource whose value is an int array.
|
||||||
* @param array
|
|
||||||
*/
|
*/
|
||||||
public static String resolveResourceId(int[] array) {
|
public static String resolveResourceId(int[] array) {
|
||||||
sIntArrayWrapper.set(array);
|
sIntArrayWrapper.set(array);
|
||||||
@@ -502,6 +502,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
|
|||||||
* @param name the name of the resource.
|
* @param name the name of the resource.
|
||||||
* @return an {@link Integer} containing the resource id, or null if no resource were found.
|
* @return an {@link Integer} containing the resource id, or null if no resource were found.
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
public static Integer getResourceId(ResourceType type, String name) {
|
public static Integer getResourceId(ResourceType type, String name) {
|
||||||
Map<String, Integer> map = sRevRMap.get(type);
|
Map<String, Integer> map = sRevRMap.get(type);
|
||||||
Integer value = null;
|
Integer value = null;
|
||||||
@@ -509,11 +510,8 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
|
|||||||
value = map.get(name);
|
value = map.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value == null) {
|
return value == null ? sDynamicIds.getId(type, name) : value;
|
||||||
value = sDynamicIds.getId(type, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ import android.content.res.BridgeTypedArray;
|
|||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.Resources.Theme;
|
import android.content.res.Resources.Theme;
|
||||||
import android.content.res.TypedArray;
|
|
||||||
import android.database.DatabaseErrorHandler;
|
import android.database.DatabaseErrorHandler;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteDatabase.CursorFactory;
|
import android.database.sqlite.SQLiteDatabase.CursorFactory;
|
||||||
@@ -127,7 +126,6 @@ public final class BridgeContext extends Context {
|
|||||||
* @param metrics the {@link DisplayMetrics}.
|
* @param metrics the {@link DisplayMetrics}.
|
||||||
* @param renderResources the configured resources (both framework and projects) for this
|
* @param renderResources the configured resources (both framework and projects) for this
|
||||||
* render.
|
* render.
|
||||||
* @param projectCallback
|
|
||||||
* @param config the Configuration object for this render.
|
* @param config the Configuration object for this render.
|
||||||
* @param targetSdkVersion the targetSdkVersion of the application.
|
* @param targetSdkVersion the targetSdkVersion of the application.
|
||||||
*/
|
*/
|
||||||
@@ -331,7 +329,7 @@ public final class BridgeContext extends Context {
|
|||||||
boolean attachToRoot, boolean skipCallbackParser) {
|
boolean attachToRoot, boolean skipCallbackParser) {
|
||||||
boolean isPlatformLayout = resource.isFramework();
|
boolean isPlatformLayout = resource.isFramework();
|
||||||
|
|
||||||
if (isPlatformLayout == false && skipCallbackParser == false) {
|
if (!isPlatformLayout && !skipCallbackParser) {
|
||||||
// check if the project callback can provide us with a custom parser.
|
// check if the project callback can provide us with a custom parser.
|
||||||
ILayoutPullParser parser = getParser(resource);
|
ILayoutPullParser parser = getParser(resource);
|
||||||
|
|
||||||
@@ -663,7 +661,7 @@ public final class BridgeContext extends Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String attrName = attribute.getFirst();
|
String attrName = attribute.getFirst();
|
||||||
boolean frameworkAttr = attribute.getSecond().booleanValue();
|
boolean frameworkAttr = attribute.getSecond();
|
||||||
String value = null;
|
String value = null;
|
||||||
if (set != null) {
|
if (set != null) {
|
||||||
value = set.getAttributeValue(
|
value = set.getAttributeValue(
|
||||||
@@ -672,7 +670,7 @@ public final class BridgeContext extends Context {
|
|||||||
|
|
||||||
// if this is an app attribute, and the first get fails, try with the
|
// if this is an app attribute, and the first get fails, try with the
|
||||||
// new res-auto namespace as well
|
// new res-auto namespace as well
|
||||||
if (frameworkAttr == false && value == null) {
|
if (!frameworkAttr && value == null) {
|
||||||
value = set.getAttributeValue(BridgeConstants.NS_APP_RES_AUTO, attrName);
|
value = set.getAttributeValue(BridgeConstants.NS_APP_RES_AUTO, attrName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -789,13 +787,13 @@ public final class BridgeContext extends Context {
|
|||||||
List<Pair<String, Boolean>> results = new ArrayList<Pair<String, Boolean>>(attrs.length);
|
List<Pair<String, Boolean>> results = new ArrayList<Pair<String, Boolean>>(attrs.length);
|
||||||
|
|
||||||
// for each attribute, get its name so that we can search it in the style
|
// for each attribute, get its name so that we can search it in the style
|
||||||
for (int i = 0 ; i < attrs.length ; i++) {
|
for (int attr : attrs) {
|
||||||
Pair<ResourceType, String> resolvedResource = Bridge.resolveResourceId(attrs[i]);
|
Pair<ResourceType, String> resolvedResource = Bridge.resolveResourceId(attr);
|
||||||
boolean isFramework = false;
|
boolean isFramework = false;
|
||||||
if (resolvedResource != null) {
|
if (resolvedResource != null) {
|
||||||
isFramework = true;
|
isFramework = true;
|
||||||
} else {
|
} else {
|
||||||
resolvedResource = mProjectCallback.resolveResourceId(attrs[i]);
|
resolvedResource = mProjectCallback.resolveResourceId(attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resolvedResource != null) {
|
if (resolvedResource != null) {
|
||||||
@@ -841,7 +839,7 @@ public final class BridgeContext extends Context {
|
|||||||
|
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
// generate a new id
|
// generate a new id
|
||||||
id = Integer.valueOf(++mDynamicIdGenerator);
|
id = ++mDynamicIdGenerator;
|
||||||
|
|
||||||
// and add it to the maps.
|
// and add it to the maps.
|
||||||
mDynamicIdToStyleMap.put(id, resValue);
|
mDynamicIdToStyleMap.put(id, resValue);
|
||||||
@@ -860,19 +858,24 @@ public final class BridgeContext extends Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getFrameworkResourceValue(ResourceType resType, String resName, int defValue) {
|
public int getFrameworkResourceValue(ResourceType resType, String resName, int defValue) {
|
||||||
Integer value = Bridge.getResourceId(resType, resName);
|
if (getRenderResources().getFrameworkResource(resType, resName) != null) {
|
||||||
if (value != null) {
|
// Bridge.getResourceId creates a new resource id if an existing one isn't found. So,
|
||||||
return value.intValue();
|
// we check for the existence of the resource before calling it.
|
||||||
|
return Bridge.getResourceId(resType, resName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return defValue;
|
return defValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getProjectResourceValue(ResourceType resType, String resName, int defValue) {
|
public int getProjectResourceValue(ResourceType resType, String resName, int defValue) {
|
||||||
|
// getResourceId creates a new resource id if an existing resource id isn't found. So, we
|
||||||
|
// check for the existence of the resource before calling it.
|
||||||
|
if (getRenderResources().getProjectResource(resType, resName) != null) {
|
||||||
if (mProjectCallback != null) {
|
if (mProjectCallback != null) {
|
||||||
Integer value = mProjectCallback.getResourceId(resType, resName);
|
Integer value = mProjectCallback.getResourceId(resType, resName);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
return value.intValue();
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1455,9 +1458,6 @@ public final class BridgeContext extends Context {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public int getUserId() {
|
public int getUserId() {
|
||||||
return 0; // not used
|
return 0; // not used
|
||||||
|
|||||||
@@ -130,21 +130,15 @@ public abstract class CustomActionBarWrapper {
|
|||||||
MenuInflater inflater = new MenuInflater(getActionMenuContext());
|
MenuInflater inflater = new MenuInflater(getActionMenuContext());
|
||||||
MenuBuilder menuBuilder = getMenuBuilder();
|
MenuBuilder menuBuilder = getMenuBuilder();
|
||||||
for (String name : mCallback.getMenuIdNames()) {
|
for (String name : mCallback.getMenuIdNames()) {
|
||||||
int id = -1;
|
int id;
|
||||||
if (name.startsWith(ANDROID_NS_NAME_PREFIX)) {
|
if (name.startsWith(ANDROID_NS_NAME_PREFIX)) {
|
||||||
// Framework menu.
|
// Framework menu.
|
||||||
name = name.substring(ANDROID_NS_NAME_PREFIX.length());
|
name = name.substring(ANDROID_NS_NAME_PREFIX.length());
|
||||||
if (mContext.getRenderResources().getFrameworkResource(MENU, name) != null) {
|
|
||||||
// We need to check for the existence of the menu first, since getting the id
|
|
||||||
// never returns the default value. It creates a new value if one is not found.
|
|
||||||
id = mContext.getFrameworkResourceValue(MENU, name, -1);
|
id = mContext.getFrameworkResourceValue(MENU, name, -1);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Project menu.
|
// Project menu.
|
||||||
if (mContext.getRenderResources().getProjectResource(MENU, name) != null) {
|
|
||||||
id = mContext.getProjectResourceValue(MENU, name, -1);
|
id = mContext.getProjectResourceValue(MENU, name, -1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (id > -1) {
|
if (id > -1) {
|
||||||
inflater.inflate(id, menuBuilder);
|
inflater.inflate(id, menuBuilder);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.layoutlib.bridge.util;
|
package com.android.layoutlib.bridge.util;
|
||||||
|
|
||||||
|
import com.android.annotations.NonNull;
|
||||||
import com.android.resources.ResourceType;
|
import com.android.resources.ResourceType;
|
||||||
import com.android.util.Pair;
|
import com.android.util.Pair;
|
||||||
|
|
||||||
@@ -48,6 +49,7 @@ public class DynamicIdMap {
|
|||||||
* @param name the name of the resource
|
* @param name the name of the resource
|
||||||
* @return an integer.
|
* @return an integer.
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
public Integer getId(ResourceType type, String name) {
|
public Integer getId(ResourceType type, String name) {
|
||||||
return getId(Pair.of(type, name));
|
return getId(Pair.of(type, name));
|
||||||
}
|
}
|
||||||
@@ -59,10 +61,11 @@ public class DynamicIdMap {
|
|||||||
* @param resource the type/name of the resource
|
* @param resource the type/name of the resource
|
||||||
* @return an integer.
|
* @return an integer.
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
public Integer getId(Pair<ResourceType, String> resource) {
|
public Integer getId(Pair<ResourceType, String> resource) {
|
||||||
Integer value = mDynamicIds.get(resource);
|
Integer value = mDynamicIds.get(resource);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
value = Integer.valueOf(++mDynamicSeed);
|
value = ++mDynamicSeed;
|
||||||
mDynamicIds.put(resource, value);
|
mDynamicIds.put(resource, value);
|
||||||
mRevDynamicIds.put(value, resource);
|
mRevDynamicIds.put(value, resource);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user