Merge "LayoutLib: display warning when a resource reference fails to resolve." into honeycomb
This commit is contained in:
committed by
Android (Google) Code Review
commit
5c6b786e1c
@@ -92,7 +92,7 @@ public final class BridgeContext extends Activity {
|
|||||||
|
|
||||||
// cache for TypedArray generated from IStyleResourceValue object
|
// cache for TypedArray generated from IStyleResourceValue object
|
||||||
private Map<int[], Map<Integer, TypedArray>> mTypedArrayCache;
|
private Map<int[], Map<Integer, TypedArray>> mTypedArrayCache;
|
||||||
private BridgeInflater mInflater;
|
private BridgeInflater mBridgeInflater;
|
||||||
|
|
||||||
private final IProjectCallback mProjectCallback;
|
private final IProjectCallback mProjectCallback;
|
||||||
private BridgeContentResolver mContentResolver;
|
private BridgeContentResolver mContentResolver;
|
||||||
@@ -160,7 +160,7 @@ public final class BridgeContext extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setBridgeInflater(BridgeInflater inflater) {
|
public void setBridgeInflater(BridgeInflater inflater) {
|
||||||
mInflater = inflater;
|
mBridgeInflater = inflater;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addViewKey(View view, Object viewKey) {
|
public void addViewKey(View view, Object viewKey) {
|
||||||
@@ -221,7 +221,7 @@ public final class BridgeContext extends Activity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LayoutInflater getLayoutInflater() {
|
public LayoutInflater getLayoutInflater() {
|
||||||
return mInflater;
|
return mBridgeInflater;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------ Context methods
|
// ------------ Context methods
|
||||||
@@ -244,7 +244,7 @@ public final class BridgeContext extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
public Object getSystemService(String service) {
|
public Object getSystemService(String service) {
|
||||||
if (LAYOUT_INFLATER_SERVICE.equals(service)) {
|
if (LAYOUT_INFLATER_SERVICE.equals(service)) {
|
||||||
return mInflater;
|
return mBridgeInflater;
|
||||||
}
|
}
|
||||||
|
|
||||||
// AutoCompleteTextView and MultiAutoCompleteTextView want a window
|
// AutoCompleteTextView and MultiAutoCompleteTextView want a window
|
||||||
@@ -591,7 +591,7 @@ public final class BridgeContext extends Activity {
|
|||||||
|
|
||||||
boolean frameworkOnly = false;
|
boolean frameworkOnly = false;
|
||||||
|
|
||||||
// eleminate the prefix from the string
|
// eliminate the prefix from the string
|
||||||
if (reference.startsWith(BridgeConstants.PREFIX_ANDROID_THEME_REF)) {
|
if (reference.startsWith(BridgeConstants.PREFIX_ANDROID_THEME_REF)) {
|
||||||
frameworkOnly = true;
|
frameworkOnly = true;
|
||||||
reference = reference.substring(BridgeConstants.PREFIX_ANDROID_THEME_REF.length());
|
reference = reference.substring(BridgeConstants.PREFIX_ANDROID_THEME_REF.length());
|
||||||
@@ -677,7 +677,7 @@ public final class BridgeContext extends Activity {
|
|||||||
* project resources
|
* project resources
|
||||||
*/
|
*/
|
||||||
private ResourceValue findResValue(String resType, String resName, boolean frameworkOnly) {
|
private ResourceValue findResValue(String resType, String resName, boolean frameworkOnly) {
|
||||||
// map of IResouceValue for the given type
|
// map of ResouceValue for the given type
|
||||||
Map<String, ResourceValue> typeMap;
|
Map<String, ResourceValue> typeMap;
|
||||||
|
|
||||||
// if allowed, search in the project resources first.
|
// if allowed, search in the project resources first.
|
||||||
@@ -701,6 +701,13 @@ public final class BridgeContext extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// didn't find the resource anywhere.
|
// didn't find the resource anywhere.
|
||||||
|
// This is normal if the resource is an ID that is generated automatically.
|
||||||
|
// For other resources, we output a warning
|
||||||
|
if ("+id".equals(resType) == false && "+android:id".equals(resType) == false) { //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
Bridge.getLog().warning("resources", //$NON-NLS-1$
|
||||||
|
"Couldn't resolve resource @" +
|
||||||
|
(frameworkOnly ? "android:" : "") + resType + "/" + resName);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1303,4 +1310,15 @@ public final class BridgeContext extends Activity {
|
|||||||
public Context getApplicationContext() {
|
public Context getApplicationContext() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startActivities(Intent[] arg0) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isRestricted() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,25 +43,25 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public final class BridgeTypedArray extends TypedArray {
|
public final class BridgeTypedArray extends TypedArray {
|
||||||
|
|
||||||
private BridgeResources mResources;
|
private BridgeResources mBridgeResources;
|
||||||
private BridgeContext mContext;
|
private BridgeContext mContext;
|
||||||
private ResourceValue[] mData;
|
private ResourceValue[] mResourceData;
|
||||||
private String[] mNames;
|
private String[] mNames;
|
||||||
private final boolean mPlatformFile;
|
private final boolean mPlatformFile;
|
||||||
|
|
||||||
public BridgeTypedArray(BridgeResources resources, BridgeContext context, int len,
|
public BridgeTypedArray(BridgeResources resources, BridgeContext context, int len,
|
||||||
boolean platformFile) {
|
boolean platformFile) {
|
||||||
super(null, null, null, 0);
|
super(null, null, null, 0);
|
||||||
mResources = resources;
|
mBridgeResources = resources;
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mPlatformFile = platformFile;
|
mPlatformFile = platformFile;
|
||||||
mData = new ResourceValue[len];
|
mResourceData = new ResourceValue[len];
|
||||||
mNames = new String[len];
|
mNames = new String[len];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A bridge-specific method that sets a value in the type array */
|
/** A bridge-specific method that sets a value in the type array */
|
||||||
public void bridgeSetValue(int index, String name, ResourceValue value) {
|
public void bridgeSetValue(int index, String name, ResourceValue value) {
|
||||||
mData[index] = value;
|
mResourceData[index] = value;
|
||||||
mNames[index] = name;
|
mNames[index] = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
// fills TypedArray.mIndices which is used to implement getIndexCount/getIndexAt
|
// fills TypedArray.mIndices which is used to implement getIndexCount/getIndexAt
|
||||||
// first count the array size
|
// first count the array size
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (ResourceValue data : mData) {
|
for (ResourceValue data : mResourceData) {
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
@@ -87,8 +87,8 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
|
|
||||||
// fill the array with the indices.
|
// fill the array with the indices.
|
||||||
int index = 1;
|
int index = 1;
|
||||||
for (int i = 0 ; i < mData.length ; i++) {
|
for (int i = 0 ; i < mResourceData.length ; i++) {
|
||||||
if (mData[i] != null) {
|
if (mResourceData[i] != null) {
|
||||||
mIndices[index++] = i;
|
mIndices[index++] = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,7 +99,7 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int length() {
|
public int length() {
|
||||||
return mData.length;
|
return mResourceData.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -107,7 +107,7 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Resources getResources() {
|
public Resources getResources() {
|
||||||
return mResources;
|
return mBridgeResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -120,9 +120,9 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getText(int index) {
|
public CharSequence getText(int index) {
|
||||||
if (mData[index] != null) {
|
if (mResourceData[index] != null) {
|
||||||
// FIXME: handle styled strings!
|
// FIXME: handle styled strings!
|
||||||
return mData[index].getValue();
|
return mResourceData[index].getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -138,8 +138,8 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getString(int index) {
|
public String getString(int index) {
|
||||||
if (mData[index] != null) {
|
if (mResourceData[index] != null) {
|
||||||
return mData[index].getValue();
|
return mResourceData[index].getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -155,11 +155,11 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean getBoolean(int index, boolean defValue) {
|
public boolean getBoolean(int index, boolean defValue) {
|
||||||
if (mData[index] == null) {
|
if (mResourceData[index] == null) {
|
||||||
return defValue;
|
return defValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String s = mData[index].getValue();
|
String s = mResourceData[index].getValue();
|
||||||
if (s != null) {
|
if (s != null) {
|
||||||
return XmlUtils.convertValueToBoolean(s, defValue);
|
return XmlUtils.convertValueToBoolean(s, defValue);
|
||||||
}
|
}
|
||||||
@@ -177,11 +177,11 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getInt(int index, int defValue) {
|
public int getInt(int index, int defValue) {
|
||||||
if (mData[index] == null) {
|
if (mResourceData[index] == null) {
|
||||||
return defValue;
|
return defValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String s = mData[index].getValue();
|
String s = mResourceData[index].getValue();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return (s == null) ? defValue : XmlUtils.convertValueToInt(s, defValue);
|
return (s == null) ? defValue : XmlUtils.convertValueToInt(s, defValue);
|
||||||
@@ -225,11 +225,11 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public float getFloat(int index, float defValue) {
|
public float getFloat(int index, float defValue) {
|
||||||
if (mData[index] == null) {
|
if (mResourceData[index] == null) {
|
||||||
return defValue;
|
return defValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String s = mData[index].getValue();
|
String s = mResourceData[index].getValue();
|
||||||
|
|
||||||
if (s != null) {
|
if (s != null) {
|
||||||
try {
|
try {
|
||||||
@@ -259,11 +259,11 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getColor(int index, int defValue) {
|
public int getColor(int index, int defValue) {
|
||||||
if (mData[index] == null) {
|
if (mResourceData[index] == null) {
|
||||||
return defValue;
|
return defValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String s = mData[index].getValue();
|
String s = mResourceData[index].getValue();
|
||||||
try {
|
try {
|
||||||
return ResourceHelper.getColor(s);
|
return ResourceHelper.getColor(s);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
@@ -288,11 +288,11 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ColorStateList getColorStateList(int index) {
|
public ColorStateList getColorStateList(int index) {
|
||||||
if (mData[index] == null) {
|
if (mResourceData[index] == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String value = mData[index].getValue();
|
String value = mResourceData[index].getValue();
|
||||||
|
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return null;
|
return null;
|
||||||
@@ -347,11 +347,11 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getInteger(int index, int defValue) {
|
public int getInteger(int index, int defValue) {
|
||||||
if (mData[index] == null) {
|
if (mResourceData[index] == null) {
|
||||||
return defValue;
|
return defValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String s = mData[index].getValue();
|
String s = mResourceData[index].getValue();
|
||||||
|
|
||||||
if (s != null) {
|
if (s != null) {
|
||||||
try {
|
try {
|
||||||
@@ -386,11 +386,11 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public float getDimension(int index, float defValue) {
|
public float getDimension(int index, float defValue) {
|
||||||
if (mData[index] == null) {
|
if (mResourceData[index] == null) {
|
||||||
return defValue;
|
return defValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String s = mData[index].getValue();
|
String s = mResourceData[index].getValue();
|
||||||
|
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
return defValue;
|
return defValue;
|
||||||
@@ -402,7 +402,7 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ResourceHelper.stringToFloat(s, mValue)) {
|
if (ResourceHelper.stringToFloat(s, mValue)) {
|
||||||
return mValue.getDimension(mResources.mMetrics);
|
return mValue.getDimension(mBridgeResources.mMetrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
// looks like we were unable to resolve the dimension value
|
// looks like we were unable to resolve the dimension value
|
||||||
@@ -456,11 +456,11 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getDimensionPixelSize(int index, int defValue) {
|
public int getDimensionPixelSize(int index, int defValue) {
|
||||||
if (mData[index] == null) {
|
if (mResourceData[index] == null) {
|
||||||
return defValue;
|
return defValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String s = mData[index].getValue();
|
String s = mResourceData[index].getValue();
|
||||||
|
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
return defValue;
|
return defValue;
|
||||||
@@ -522,11 +522,11 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public float getFraction(int index, int base, int pbase, float defValue) {
|
public float getFraction(int index, int base, int pbase, float defValue) {
|
||||||
if (mData[index] == null) {
|
if (mResourceData[index] == null) {
|
||||||
return defValue;
|
return defValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String value = mData[index].getValue();
|
String value = mResourceData[index].getValue();
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return defValue;
|
return defValue;
|
||||||
}
|
}
|
||||||
@@ -560,8 +560,8 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getResourceId(int index, int defValue) {
|
public int getResourceId(int index, int defValue) {
|
||||||
// get the IResource for this index
|
// get the Resource for this index
|
||||||
ResourceValue resValue = mData[index];
|
ResourceValue resValue = mResourceData[index];
|
||||||
|
|
||||||
// no data, return the default value.
|
// no data, return the default value.
|
||||||
if (resValue == null) {
|
if (resValue == null) {
|
||||||
@@ -575,7 +575,7 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if the attribute was a reference to an id, and not a declaration of an id (@+id), then
|
// if the attribute was a reference to an id, and not a declaration of an id (@+id), then
|
||||||
// the xml attribute value was "resolved" which leads us to a IResourceValue with
|
// the xml attribute value was "resolved" which leads us to a ResourceValue with
|
||||||
// getType() returning "id" and getName() returning the id name
|
// getType() returning "id" and getName() returning the id name
|
||||||
// (and getValue() returning null!). We need to handle this!
|
// (and getValue() returning null!). We need to handle this!
|
||||||
if (resValue.getType() != null && resValue.getType().equals(BridgeConstants.RES_ID)) {
|
if (resValue.getType() != null && resValue.getType().equals(BridgeConstants.RES_ID)) {
|
||||||
@@ -662,17 +662,17 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Drawable getDrawable(int index) {
|
public Drawable getDrawable(int index) {
|
||||||
if (mData[index] == null) {
|
if (mResourceData[index] == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceValue value = mData[index];
|
ResourceValue value = mResourceData[index];
|
||||||
String stringValue = value.getValue();
|
String stringValue = value.getValue();
|
||||||
if (stringValue == null || BridgeConstants.REFERENCE_NULL.equals(stringValue)) {
|
if (stringValue == null || BridgeConstants.REFERENCE_NULL.equals(stringValue)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Drawable d = ResourceHelper.getDrawable(value, mContext, mData[index].isFramework());
|
Drawable d = ResourceHelper.getDrawable(value, mContext, mResourceData[index].isFramework());
|
||||||
|
|
||||||
if (d != null) {
|
if (d != null) {
|
||||||
return d;
|
return d;
|
||||||
@@ -700,18 +700,18 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public CharSequence[] getTextArray(int index) {
|
public CharSequence[] getTextArray(int index) {
|
||||||
if (mData[index] == null) {
|
if (mResourceData[index] == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String value = mData[index].getValue();
|
String value = mResourceData[index].getValue();
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
return new CharSequence[] { value };
|
return new CharSequence[] { value };
|
||||||
}
|
}
|
||||||
|
|
||||||
Bridge.getLog().warning(null, String.format(
|
Bridge.getLog().warning(null, String.format(
|
||||||
String.format("Unknown value for getTextArray(%d) => %s", //DEBUG
|
String.format("Unknown value for getTextArray(%d) => %s", //DEBUG
|
||||||
index, mData[index].getName())));
|
index, mResourceData[index].getName())));
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -727,11 +727,11 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean getValue(int index, TypedValue outValue) {
|
public boolean getValue(int index, TypedValue outValue) {
|
||||||
if (mData[index] == null) {
|
if (mResourceData[index] == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String s = mData[index].getValue();
|
String s = mResourceData[index].getValue();
|
||||||
|
|
||||||
return ResourceHelper.stringToFloat(s, outValue);
|
return ResourceHelper.stringToFloat(s, outValue);
|
||||||
}
|
}
|
||||||
@@ -745,7 +745,7 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean hasValue(int index) {
|
public boolean hasValue(int index) {
|
||||||
return mData[index] != null;
|
return mResourceData[index] != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -792,6 +792,6 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return mData.toString();
|
return mResourceData.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user