diff options
author | Deepanshu Gupta <deepanshu@google.com> | 2015-03-30 14:53:38 -0700 |
---|---|---|
committer | Deepanshu Gupta <deepanshu@google.com> | 2015-04-15 18:20:47 -0700 |
commit | 9ca97747260b9906fc3a159ce3930109022cf2dd (patch) | |
tree | c105fb93d6d6ae7d729d3da9ed50d2924603eef3 /tools/layoutlib/bridge/src/android | |
parent | 9d6e95879aff4608db400c270fa8f89b6b55d0e6 (diff) | |
download | frameworks_base-9ca97747260b9906fc3a159ce3930109022cf2dd.zip frameworks_base-9ca97747260b9906fc3a159ce3930109022cf2dd.tar.gz frameworks_base-9ca97747260b9906fc3a159ce3930109022cf2dd.tar.bz2 |
Add @empty support.
Bug: http://b.android.com/162428
Change-Id: Id7a981de2fce21213e12cdabcce4104f146fd4d3
Diffstat (limited to 'tools/layoutlib/bridge/src/android')
-rw-r--r-- | tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java b/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java index 1803692..ae2c173 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; @@ -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 |