summaryrefslogtreecommitdiffstats
path: root/core/java
diff options
context:
space:
mode:
authorAlan Viverette <alanv@google.com>2014-10-29 17:09:36 -0700
committerAlan Viverette <alanv@google.com>2014-10-29 17:09:36 -0700
commitf2969405020a72e282c348a6ea201d56e9f8d4ba (patch)
treee128dfe858f314d151ad3462e77f18d4aa973f66 /core/java
parent720a5c51beb5beab442832ea8d169aa5b4edb43f (diff)
downloadframeworks_base-f2969405020a72e282c348a6ea201d56e9f8d4ba.zip
frameworks_base-f2969405020a72e282c348a6ea201d56e9f8d4ba.tar.gz
frameworks_base-f2969405020a72e282c348a6ea201d56e9f8d4ba.tar.bz2
Distinguish unspecified and explicit null values in resources
BUG: 17919345 Change-Id: Ic4f04f7dd0f986f58a749b5950d80c1cfdb074ea
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/content/res/TypedArray.java24
-rw-r--r--core/java/android/util/TypedValue.java11
2 files changed, 35 insertions, 0 deletions
diff --git a/core/java/android/content/res/TypedArray.java b/core/java/android/content/res/TypedArray.java
index 73b93c6..02602fb 100644
--- a/core/java/android/content/res/TypedArray.java
+++ b/core/java/android/content/res/TypedArray.java
@@ -807,6 +807,9 @@ public class TypedArray {
/**
* Determines whether there is an attribute at <var>index</var>.
+ * <p>
+ * <strong>Note:</strong> If the attribute was set to {@code @empty} or
+ * {@code @undefined}, this method returns {@code false}.
*
* @param index Index of attribute to retrieve.
*
@@ -824,6 +827,27 @@ public class TypedArray {
}
/**
+ * Determines whether there is an attribute at <var>index</var>, returning
+ * {@code true} if the attribute was explicitly set to {@code @empty} and
+ * {@code false} only if the attribute was undefined.
+ *
+ * @param index Index of attribute to retrieve.
+ *
+ * @return True if the attribute has a value or is empty, false otherwise.
+ */
+ public boolean hasValueOrEmpty(int index) {
+ if (mRecycled) {
+ throw new RuntimeException("Cannot make calls to a recycled instance!");
+ }
+
+ index *= AssetManager.STYLE_NUM_ENTRIES;
+ final int[] data = mData;
+ final int type = data[index+AssetManager.STYLE_TYPE];
+ return type != TypedValue.TYPE_NULL
+ || data[index+AssetManager.STYLE_DATA] == TypedValue.DATA_NULL_EMPTY;
+ }
+
+ /**
* Retrieve the raw TypedValue for the attribute at <var>index</var>
* and return a temporary object holding its data. This object is only
* valid until the next call on to {@link TypedArray}.
diff --git a/core/java/android/util/TypedValue.java b/core/java/android/util/TypedValue.java
index 931fb81..d42ed03 100644
--- a/core/java/android/util/TypedValue.java
+++ b/core/java/android/util/TypedValue.java
@@ -139,6 +139,17 @@ public class TypedValue {
/* ------------------------------------------------------------ */
/**
+ * {@link #TYPE_NULL} data indicating the value was not specified.
+ */
+ public static final int DATA_NULL_UNDEFINED = 0;
+ /**
+ * {@link #TYPE_NULL} data indicating the value was explicitly set to null.
+ */
+ public static final int DATA_NULL_EMPTY = 1;
+
+ /* ------------------------------------------------------------ */
+
+ /**
* If {@link #density} is equal to this value, then the density should be
* treated as the system's default density value: {@link DisplayMetrics#DENSITY_DEFAULT}.
*/