summaryrefslogtreecommitdiffstats
path: root/tools/layoutlib/bridge/src/android
diff options
context:
space:
mode:
authorDeepanshu Gupta <deepanshu@google.com>2015-04-16 17:41:54 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-04-16 17:41:54 +0000
commitc4affce9df0817b84df3e61c3932f53b77ee0986 (patch)
tree5c8cda109ebae7896875c60c7209b672a010e585 /tools/layoutlib/bridge/src/android
parent40955edf9dc1e90b337af89543919eec4868dbe0 (diff)
parent1f3c7f3f500bdbfd790c20872961d84ef617f066 (diff)
downloadframeworks_base-c4affce9df0817b84df3e61c3932f53b77ee0986.zip
frameworks_base-c4affce9df0817b84df3e61c3932f53b77ee0986.tar.gz
frameworks_base-c4affce9df0817b84df3e61c3932f53b77ee0986.tar.bz2
am 1f3c7f3f: am f18ceefc: am cd6e00c6: Merge changes from topic \'layoutlib-api-15\' into lmp-mr1-dev
* commit '1f3c7f3f500bdbfd790c20872961d84ef617f066': Update golden image for tests. Update to using LayoutlibCallback. Remove implementation of deprecated method. Add @empty support.
Diffstat (limited to 'tools/layoutlib/bridge/src/android')
-rw-r--r--tools/layoutlib/bridge/src/android/app/Fragment_Delegate.java22
-rw-r--r--tools/layoutlib/bridge/src/android/content/res/BridgeResources.java29
-rw-r--r--tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java38
-rw-r--r--tools/layoutlib/bridge/src/android/util/BridgeXmlPullAttributes.java6
-rw-r--r--tools/layoutlib/bridge/src/android/view/BridgeInflater.java23
5 files changed, 71 insertions, 47 deletions
diff --git a/tools/layoutlib/bridge/src/android/app/Fragment_Delegate.java b/tools/layoutlib/bridge/src/android/app/Fragment_Delegate.java
index aabd3f1..f7654ce 100644
--- a/tools/layoutlib/bridge/src/android/app/Fragment_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/app/Fragment_Delegate.java
@@ -16,7 +16,7 @@
package android.app;
-import com.android.ide.common.rendering.api.IProjectCallback;
+import com.android.ide.common.rendering.api.LayoutlibCallback;
import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
import android.content.Context;
@@ -30,19 +30,19 @@ import android.os.Bundle;
*
* The methods being re-implemented are the ones responsible for instantiating Fragment objects.
* Because the classes of these objects are found in the project, these methods need access to
- * {@link IProjectCallback} object. They are however static methods, so the callback is set
- * before the inflation through {@link #setProjectCallback(IProjectCallback)}.
+ * {@link LayoutlibCallback} object. They are however static methods, so the callback is set
+ * before the inflation through {@link #setLayoutlibCallback(LayoutlibCallback)}.
*/
public class Fragment_Delegate {
- private static IProjectCallback sProjectCallback;
+ private static LayoutlibCallback sLayoutlibCallback;
/**
- * Sets the current {@link IProjectCallback} to be used to instantiate classes coming
+ * Sets the current {@link LayoutlibCallback} to be used to instantiate classes coming
* from the project being rendered.
*/
- public static void setProjectCallback(IProjectCallback projectCallback) {
- sProjectCallback = projectCallback;
+ public static void setLayoutlibCallback(LayoutlibCallback layoutlibCallback) {
+ sLayoutlibCallback = layoutlibCallback;
}
/**
@@ -62,17 +62,17 @@ public class Fragment_Delegate {
* This is currently just used to get its ClassLoader.
* @param fname The class name of the fragment to instantiate.
* @param args Bundle of arguments to supply to the fragment, which it
- * can retrieve with {@link #getArguments()}. May be null.
+ * can retrieve with {@link Fragment#getArguments()}. May be null.
* @return Returns a new fragment instance.
- * @throws InstantiationException If there is a failure in instantiating
+ * @throws Fragment.InstantiationException If there is a failure in instantiating
* the given fragment class. This is a runtime exception; it is not
* normally expected to happen.
*/
@LayoutlibDelegate
/*package*/ static Fragment instantiate(Context context, String fname, Bundle args) {
try {
- if (sProjectCallback != null) {
- Fragment f = (Fragment) sProjectCallback.loadView(fname,
+ if (sLayoutlibCallback != null) {
+ Fragment f = (Fragment) sLayoutlibCallback.loadView(fname,
new Class[0], new Object[0]);
if (args != null) {
diff --git a/tools/layoutlib/bridge/src/android/content/res/BridgeResources.java b/tools/layoutlib/bridge/src/android/content/res/BridgeResources.java
index 96ca250..2c2c672 100644
--- a/tools/layoutlib/bridge/src/android/content/res/BridgeResources.java
+++ b/tools/layoutlib/bridge/src/android/content/res/BridgeResources.java
@@ -16,8 +16,8 @@
package android.content.res;
-import com.android.ide.common.rendering.api.IProjectCallback;
import com.android.ide.common.rendering.api.LayoutLog;
+import com.android.ide.common.rendering.api.LayoutlibCallback;
import com.android.ide.common.rendering.api.ResourceValue;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
@@ -49,7 +49,7 @@ import java.io.InputStream;
public final class BridgeResources extends Resources {
private BridgeContext mContext;
- private IProjectCallback mProjectCallback;
+ private LayoutlibCallback mLayoutlibCallback;
private boolean[] mPlatformResourceFlag = new boolean[1];
private TypedValue mTmpValue = new TypedValue();
@@ -94,12 +94,12 @@ public final class BridgeResources extends Resources {
AssetManager assets,
DisplayMetrics metrics,
Configuration config,
- IProjectCallback projectCallback) {
+ LayoutlibCallback layoutlibCallback) {
return Resources.mSystem = new BridgeResources(context,
assets,
metrics,
config,
- projectCallback);
+ layoutlibCallback);
}
/**
@@ -109,16 +109,16 @@ public final class BridgeResources extends Resources {
public static void disposeSystem() {
if (Resources.mSystem instanceof BridgeResources) {
((BridgeResources)(Resources.mSystem)).mContext = null;
- ((BridgeResources)(Resources.mSystem)).mProjectCallback = null;
+ ((BridgeResources)(Resources.mSystem)).mLayoutlibCallback = null;
}
Resources.mSystem = null;
}
private BridgeResources(BridgeContext context, AssetManager assets, DisplayMetrics metrics,
- Configuration config, IProjectCallback projectCallback) {
+ Configuration config, LayoutlibCallback layoutlibCallback) {
super(assets, metrics, config);
mContext = context;
- mProjectCallback = projectCallback;
+ mLayoutlibCallback = layoutlibCallback;
}
public BridgeTypedArray newTypeArray(int numEntries, boolean platformFile) {
@@ -138,8 +138,8 @@ public final class BridgeResources extends Resources {
}
// didn't find a match in the framework? look in the project.
- if (mProjectCallback != null) {
- resourceInfo = mProjectCallback.resolveResourceId(id);
+ if (mLayoutlibCallback != null) {
+ resourceInfo = mLayoutlibCallback.resolveResourceId(id);
if (resourceInfo != null) {
platformResFlag_out[0] = false;
@@ -154,11 +154,6 @@ public final class BridgeResources extends Resources {
}
@Override
- public Drawable getDrawable(int id) throws NotFoundException {
- return getDrawable(id, null);
- }
-
- @Override
public Drawable getDrawable(int id, Theme theme) {
Pair<String, ResourceValue> value = getResourceValue(id, mPlatformResourceFlag);
@@ -257,7 +252,7 @@ public final class BridgeResources extends Resources {
try {
// check if the current parser can provide us with a custom parser.
if (mPlatformResourceFlag[0] == false) {
- parser = mProjectCallback.getParser(value);
+ parser = mLayoutlibCallback.getParser(value);
}
// create a new one manually if needed.
@@ -692,8 +687,8 @@ public final class BridgeResources extends Resources {
Pair<ResourceType, String> resourceInfo = Bridge.resolveResourceId(id);
// if the name is unknown in the framework, get it from the custom view loader.
- if (resourceInfo == null && mProjectCallback != null) {
- resourceInfo = mProjectCallback.resolveResourceId(id);
+ if (resourceInfo == null && mLayoutlibCallback != null) {
+ resourceInfo = mLayoutlibCallback.resolveResourceId(id);
}
String message = null;
diff --git a/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java b/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java
index 1803692..7d4271b 100644
--- a/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java
+++ b/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java
@@ -16,6 +16,7 @@
package android.content.res;
+import com.android.annotations.Nullable;
import com.android.ide.common.rendering.api.AttrResourceValue;
import com.android.ide.common.rendering.api.LayoutLog;
import com.android.ide.common.rendering.api.RenderResources;
@@ -40,9 +41,12 @@ import android.view.LayoutInflater_Delegate;
import android.view.ViewGroup.LayoutParams;
import java.io.File;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
+import static com.android.ide.common.rendering.api.RenderResources.*;
+
/**
* Custom implementation of TypedArray to handle non compiled resources.
*/
@@ -56,6 +60,11 @@ public final class BridgeTypedArray extends TypedArray {
private final String[] mNames;
private final boolean[] mIsFramework;
+ // Contains ids that are @empty. We still store null in mResourceData for that index, since we
+ // want to save on the check against empty, each time a resource value is requested.
+ @Nullable
+ private int[] mEmptyIds;
+
public BridgeTypedArray(BridgeResources resources, BridgeContext context, int len,
boolean platformFile) {
super(resources, null, null, 0);
@@ -90,19 +99,32 @@ public final class BridgeTypedArray extends TypedArray {
// fills TypedArray.mIndices which is used to implement getIndexCount/getIndexAt
// first count the array size
int count = 0;
+ ArrayList<Integer> emptyIds = null;
for (int i = 0; i < mResourceData.length; i++) {
ResourceValue data = mResourceData[i];
if (data != null) {
- if (RenderResources.REFERENCE_NULL.equals(data.getValue())) {
- // No need to store this resource value. This saves needless checking for
- // "@null" every time an attribute is requested.
+ String dataValue = data.getValue();
+ if (REFERENCE_NULL.equals(dataValue) || REFERENCE_UNDEFINED.equals(dataValue)) {
+ mResourceData[i] = null;
+ } else if (REFERENCE_EMPTY.equals(dataValue)) {
mResourceData[i] = null;
+ if (emptyIds == null) {
+ emptyIds = new ArrayList<Integer>(4);
+ }
+ emptyIds.add(i);
} else {
count++;
}
}
}
+ if (emptyIds != null) {
+ mEmptyIds = new int[emptyIds.size()];
+ for (int i = 0; i < emptyIds.size(); i++) {
+ mEmptyIds[i] = emptyIds.get(i);
+ }
+ }
+
// allocate the table with an extra to store the size
mIndices = new int[count+1];
mIndices[0] = count;
@@ -624,7 +646,7 @@ public final class BridgeTypedArray extends TypedArray {
if (isFrameworkId) {
idValue = Bridge.getResourceId(ResourceType.ID, idName);
} else {
- idValue = mContext.getProjectCallback().getResourceId(ResourceType.ID, idName);
+ idValue = mContext.getLayoutlibCallback().getResourceId(ResourceType.ID, idName);
}
return idValue == null ? defValue : idValue;
}
@@ -644,7 +666,7 @@ public final class BridgeTypedArray extends TypedArray {
idValue = Bridge.getResourceId(resValue.getResourceType(),
resValue.getName());
} else {
- idValue = mContext.getProjectCallback().getResourceId(
+ idValue = mContext.getLayoutlibCallback().getResourceId(
resValue.getResourceType(), resValue.getName());
}
@@ -748,6 +770,12 @@ public final class BridgeTypedArray extends TypedArray {
return index >= 0 && index < mResourceData.length && mResourceData[index] != null;
}
+ @Override
+ public boolean hasValueOrEmpty(int index) {
+ return hasValue(index) || index >= 0 && index < mResourceData.length &&
+ mEmptyIds != null && Arrays.binarySearch(mEmptyIds, index) >= 0;
+ }
+
/**
* Retrieve the raw TypedValue for the attribute at <var>index</var>
* and return a temporary object holding its data. This object is only
diff --git a/tools/layoutlib/bridge/src/android/util/BridgeXmlPullAttributes.java b/tools/layoutlib/bridge/src/android/util/BridgeXmlPullAttributes.java
index 691339e..138b2d5 100644
--- a/tools/layoutlib/bridge/src/android/util/BridgeXmlPullAttributes.java
+++ b/tools/layoutlib/bridge/src/android/util/BridgeXmlPullAttributes.java
@@ -69,8 +69,8 @@ public class BridgeXmlPullAttributes extends XmlPullAttributes {
// this is not an attribute in the android namespace, we query the customviewloader, if
// the namespaces match.
- if (mContext.getProjectCallback().getNamespace().equals(ns)) {
- Integer v = mContext.getProjectCallback().getResourceId(ResourceType.ATTR, name);
+ if (mContext.getLayoutlibCallback().getNamespace().equals(ns)) {
+ Integer v = mContext.getLayoutlibCallback().getResourceId(ResourceType.ATTR, name);
if (v != null) {
return v.intValue();
}
@@ -273,7 +273,7 @@ public class BridgeXmlPullAttributes extends XmlPullAttributes {
if (mPlatformFile || resource.isFramework()) {
id = Bridge.getResourceId(resource.getResourceType(), resource.getName());
} else {
- id = mContext.getProjectCallback().getResourceId(
+ id = mContext.getLayoutlibCallback().getResourceId(
resource.getResourceType(), resource.getName());
}
diff --git a/tools/layoutlib/bridge/src/android/view/BridgeInflater.java b/tools/layoutlib/bridge/src/android/view/BridgeInflater.java
index 4acbd1c..5db9556 100644
--- a/tools/layoutlib/bridge/src/android/view/BridgeInflater.java
+++ b/tools/layoutlib/bridge/src/android/view/BridgeInflater.java
@@ -16,7 +16,7 @@
package android.view;
-import com.android.ide.common.rendering.api.IProjectCallback;
+import com.android.ide.common.rendering.api.LayoutlibCallback;
import com.android.ide.common.rendering.api.LayoutLog;
import com.android.ide.common.rendering.api.MergeCookie;
import com.android.ide.common.rendering.api.ResourceReference;
@@ -46,7 +46,7 @@ import static com.android.layoutlib.bridge.android.BridgeContext.getBaseContext;
*/
public final class BridgeInflater extends LayoutInflater {
- private final IProjectCallback mProjectCallback;
+ private final LayoutlibCallback mLayoutlibCallback;
private boolean mIsInMerge = false;
private ResourceReference mResourceReference;
@@ -64,21 +64,21 @@ public final class BridgeInflater extends LayoutInflater {
super(original, newContext);
newContext = getBaseContext(newContext);
if (newContext instanceof BridgeContext) {
- mProjectCallback = ((BridgeContext) newContext).getProjectCallback();
+ mLayoutlibCallback = ((BridgeContext) newContext).getLayoutlibCallback();
} else {
- mProjectCallback = null;
+ mLayoutlibCallback = null;
}
}
/**
- * Instantiate a new BridgeInflater with an {@link IProjectCallback} object.
+ * Instantiate a new BridgeInflater with an {@link LayoutlibCallback} object.
*
* @param context The Android application context.
- * @param projectCallback the {@link IProjectCallback} object.
+ * @param layoutlibCallback the {@link LayoutlibCallback} object.
*/
- public BridgeInflater(Context context, IProjectCallback projectCallback) {
+ public BridgeInflater(Context context, LayoutlibCallback layoutlibCallback) {
super(context);
- mProjectCallback = projectCallback;
+ mLayoutlibCallback = layoutlibCallback;
mConstructorArgs[0] = context;
}
@@ -167,12 +167,13 @@ public final class BridgeInflater extends LayoutInflater {
ResourceValue value = null;
+ @SuppressWarnings("deprecation")
Pair<ResourceType, String> layoutInfo = Bridge.resolveResourceId(resource);
if (layoutInfo != null) {
value = bridgeContext.getRenderResources().getFrameworkResource(
ResourceType.LAYOUT, layoutInfo.getSecond());
} else {
- layoutInfo = mProjectCallback.resolveResourceId(resource);
+ layoutInfo = mLayoutlibCallback.resolveResourceId(resource);
if (layoutInfo != null) {
value = bridgeContext.getRenderResources().getProjectResource(
@@ -203,7 +204,7 @@ public final class BridgeInflater extends LayoutInflater {
}
private View loadCustomView(String name, AttributeSet attrs) throws Exception {
- if (mProjectCallback != null) {
+ if (mLayoutlibCallback != null) {
// first get the classname in case it's not the node name
if (name.equals("view")) {
name = attrs.getAttributeValue(null, "class");
@@ -211,7 +212,7 @@ public final class BridgeInflater extends LayoutInflater {
mConstructorArgs[1] = attrs;
- Object customView = mProjectCallback.loadView(name, mConstructorSignature,
+ Object customView = mLayoutlibCallback.loadView(name, mConstructorSignature,
mConstructorArgs);
if (customView instanceof View) {