diff options
| author | Aurimas Liutikas <aurimas@google.com> | 2019-01-31 18:23:02 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-01-31 18:23:02 +0000 |
| commit | 83cbd348c3eb6005aa262eecbdb47c05bbd8d176 (patch) | |
| tree | 9c13b891cf8ca64fffc6e0008701a72111d65347 /core/java | |
| parent | 68f93a1fb07186ea94420cde64fb80959321ecff (diff) | |
| parent | aae06631e19e4edbb25220c5175330b665ae58d0 (diff) | |
Merge "Add View#getSourceLayoutResId()."
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/content/res/Resources.java | 11 | ||||
| -rw-r--r-- | core/java/android/content/res/ResourcesImpl.java | 14 | ||||
| -rw-r--r-- | core/java/android/content/res/XmlBlock.java | 18 | ||||
| -rw-r--r-- | core/java/android/view/View.java | 18 |
4 files changed, 57 insertions, 4 deletions
diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java index baf64ad72a51..59db49e0d37e 100644 --- a/core/java/android/content/res/Resources.java +++ b/core/java/android/content/res/Resources.java @@ -1394,6 +1394,17 @@ public class Resources { mResourcesImpl.getValue(name, outValue, resolveRefs); } + + /** + * @param set AttributeSet for which we want to find the source. + * @return The resource id for the source that is backing the given AttributeSet + * @hide + */ + @AnyRes + public static int getAttributeSetSourceResId(@Nullable AttributeSet set) { + return ResourcesImpl.getAttributeSetSourceResId(set); + } + /** * This class holds the current attribute values for a particular theme. * In other words, a Theme is a set of values for resource attributes; diff --git a/core/java/android/content/res/ResourcesImpl.java b/core/java/android/content/res/ResourcesImpl.java index d8564d570a4d..98980799a365 100644 --- a/core/java/android/content/res/ResourcesImpl.java +++ b/core/java/android/content/res/ResourcesImpl.java @@ -15,6 +15,8 @@ */ package android.content.res; +import static android.content.res.Resources.ID_NULL; + import android.animation.Animator; import android.animation.StateListAnimator; import android.annotation.AnyRes; @@ -1222,7 +1224,7 @@ public class ResourcesImpl { for (int i = 0; i < num; i++) { if (cachedXmlBlockCookies[i] == assetCookie && cachedXmlBlockFiles[i] != null && cachedXmlBlockFiles[i].equals(file)) { - return cachedXmlBlocks[i].newParser(); + return cachedXmlBlocks[i].newParser(id); } } @@ -1239,7 +1241,7 @@ public class ResourcesImpl { cachedXmlBlockCookies[pos] = assetCookie; cachedXmlBlockFiles[pos] = file; cachedXmlBlocks[pos] = block; - return block.newParser(); + return block.newParser(id); } } } catch (Exception e) { @@ -1299,6 +1301,14 @@ public class ResourcesImpl { } } + @AnyRes + static int getAttributeSetSourceResId(@Nullable AttributeSet set) { + if (set == null) { + return ID_NULL; + } + return ((XmlBlock.Parser) set).getSourceResId(); + } + LongSparseArray<Drawable.ConstantState> getPreloadedDrawables() { return sPreloadedDrawables[0]; } diff --git a/core/java/android/content/res/XmlBlock.java b/core/java/android/content/res/XmlBlock.java index 4e1159a9bce9..d8c3ddec66f8 100644 --- a/core/java/android/content/res/XmlBlock.java +++ b/core/java/android/content/res/XmlBlock.java @@ -16,6 +16,9 @@ package android.content.res; +import static android.content.res.Resources.ID_NULL; + +import android.annotation.AnyRes; import android.annotation.Nullable; import android.annotation.UnsupportedAppUsage; import android.util.TypedValue; @@ -73,19 +76,29 @@ final class XmlBlock implements AutoCloseable { @UnsupportedAppUsage public XmlResourceParser newParser() { + return newParser(ID_NULL); + } + + public XmlResourceParser newParser(@AnyRes int resId) { synchronized (this) { if (mNative != 0) { - return new Parser(nativeCreateParseState(mNative), this); + return new Parser(nativeCreateParseState(mNative), this, resId); } return null; } } /*package*/ final class Parser implements XmlResourceParser { - Parser(long parseState, XmlBlock block) { + Parser(long parseState, XmlBlock block, @AnyRes int sourceResId) { mParseState = parseState; mBlock = block; block.mOpenCount++; + mSourceResId = sourceResId; + } + + @AnyRes + public int getSourceResId() { + return mSourceResId; } public void setFeature(String name, boolean state) throws XmlPullParserException { @@ -473,6 +486,7 @@ final class XmlBlock implements AutoCloseable { private boolean mDecNextDepth = false; private int mDepth = 0; private int mEventType = START_DOCUMENT; + private @AnyRes int mSourceResId; } protected void finalize() throws Throwable { diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 519181d364c2..ec8ed5b2d5be 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -16,6 +16,7 @@ package android.view; +import static android.content.res.Resources.ID_NULL; import static android.view.ViewRootImpl.NEW_INSETS_MODE_FULL; import static android.view.accessibility.AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED; @@ -5052,6 +5053,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, @Nullable private WeakReference<ContentCaptureSession> mContentCaptureSession; + @LayoutRes + private int mSourceLayoutId = ID_NULL; + /** * Simple constructor to use when creating a view from code. * @@ -5217,6 +5221,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, public View(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { this(context); + mSourceLayoutId = Resources.getAttributeSetSourceResId(attrs); + final TypedArray a = context.obtainStyledAttributes( attrs, com.android.internal.R.styleable.View, defStyleAttr, defStyleRes); @@ -23253,6 +23259,18 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } /** + * A {@link View} can be inflated from an XML layout. For such Views this method returns the + * resource ID of the source layout. + * + * @return The layout resource id if this view was inflated from XML, otherwise + * {@link Resources#ID_NULL}. + */ + @LayoutRes + public int getSourceLayoutResId() { + return mSourceLayoutId; + } + + /** * Returns the top padding of this view. * * @return the top padding in pixels |
