Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 09591e89 authored by Alan Viverette's avatar Alan Viverette Committed by Android (Google) Code Review
Browse files

Merge "Add support for assigning keyed View tags via XML"

parents f556adf4 451a3417
Loading
Loading
Loading
Loading
+31 −2
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@ public abstract class LayoutInflater {
    private static final String TAG_INCLUDE = "include";
    private static final String TAG_1995 = "blink";
    private static final String TAG_REQUEST_FOCUS = "requestFocus";
    private static final String TAG_TAG = "tag";

    private static final int[] ATTRS_THEME = new int[] {
            com.android.internal.R.attr.theme };
@@ -778,6 +779,8 @@ public abstract class LayoutInflater {
            
            if (TAG_REQUEST_FOCUS.equals(name)) {
                parseRequestFocus(parser, parent);
            } else if (TAG_TAG.equals(name)) {
                parseViewTag(parser, parent, attrs);
            } else if (TAG_INCLUDE.equals(name)) {
                if (parser.getDepth() == 0) {
                    throw new InflateException("<include /> cannot be the root element");
@@ -797,10 +800,36 @@ public abstract class LayoutInflater {
        if (finishInflate) parent.onFinishInflate();
    }

    private void parseRequestFocus(XmlPullParser parser, View parent)
    /**
     * Parses a <code>&lt;request-focus&gt;</code> element and requests focus on
     * the containing View.
     */
    private void parseRequestFocus(XmlPullParser parser, View view)
            throws XmlPullParserException, IOException {
        int type;
        view.requestFocus();
        final int currentDepth = parser.getDepth();
        while (((type = parser.next()) != XmlPullParser.END_TAG ||
                parser.getDepth() > currentDepth) && type != XmlPullParser.END_DOCUMENT) {
            // Empty
        }
    }

    /**
     * Parses a <code>&lt;tag&gt;</code> element and sets a keyed tag on the
     * containing View.
     */
    private void parseViewTag(XmlPullParser parser, View view, AttributeSet attrs)
            throws XmlPullParserException, IOException {
        int type;
        parent.requestFocus();

        final TypedArray ta = mContext.obtainStyledAttributes(
                attrs, com.android.internal.R.styleable.ViewTag);
        final int key = ta.getResourceId(com.android.internal.R.styleable.ViewTag_id, 0);
        final CharSequence value = ta.getText(com.android.internal.R.styleable.ViewTag_value);
        view.setTag(key, value);
        ta.recycle();

        final int currentDepth = parser.getDepth();
        while (((type = parser.next()) != XmlPullParser.END_TAG ||
                parser.getDepth() > currentDepth) && type != XmlPullParser.END_DOCUMENT) {
+8 −0
Original line number Diff line number Diff line
@@ -2257,6 +2257,14 @@
        <attr name="sharedElementName" format="string" />
    </declare-styleable>

    <!-- Attributes that can be assigned to a tag for a particular View. -->
    <declare-styleable name="ViewTag">
        <!-- Specifies the key identifying a tag. This must be a resource reference. -->
        <attr name="id" />
        <!-- Specifies the value with which to tag the view. -->
        <attr name="value" />
    </declare-styleable>

    <!-- Attributes that can be used with a {@link android.view.ViewGroup} or any
         of its subclasses.  Also see {@link #ViewGroup_Layout} for
         attributes that this class processes in its children. -->