示例#1
0
        /// <summary>Fill in this object based on the contents of an XML "selector" element.</summary>
        /// <remarks>Fill in this object based on the contents of an XML "selector" element.</remarks>
        /// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        private void inflate(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser
                             parser, android.util.AttributeSet attrs)
        {
            int type;
            int innerDepth = parser.getDepth() + 1;
            int depth;
            int listAllocated = 20;
            int listSize      = 0;

            int[]   colorList     = new int[listAllocated];
            int[][] stateSpecList = new int[listAllocated][];
            while ((type = parser.next()) != org.xmlpull.v1.XmlPullParserClass.END_DOCUMENT &&
                   ((depth = parser.getDepth()) >= innerDepth || type != org.xmlpull.v1.XmlPullParserClass.END_TAG
                   ))
            {
                if (type != org.xmlpull.v1.XmlPullParserClass.START_TAG)
                {
                    continue;
                }
                if (depth > innerDepth || !parser.getName().Equals("item"))
                {
                    continue;
                }
                int   colorRes  = 0;
                int   color     = unchecked ((int)(0xffff0000));
                bool  haveColor = false;
                int   i;
                int   j         = 0;
                int   numAttrs  = attrs.getAttributeCount();
                int[] stateSpec = new int[numAttrs];
                for (i = 0; i < numAttrs; i++)
                {
                    int stateResId = attrs.getAttributeNameResource(i);
                    if (stateResId == 0)
                    {
                        break;
                    }
                    if (stateResId == [email protected])
                    {
                        colorRes = attrs.getAttributeResourceValue(i, 0);
                        if (colorRes == 0)
                        {
                            color     = attrs.getAttributeIntValue(i, color);
                            haveColor = true;
                        }
                    }
                    else
                    {
                        stateSpec[j++] = attrs.getAttributeBooleanValue(i, false) ? stateResId : -stateResId;
                    }
                }
                stateSpec = android.util.StateSet.trimStateSet(stateSpec, j);
                if (colorRes != 0)
                {
                    color = r.getColor(colorRes);
                }
                else
                {
                    if (!haveColor)
                    {
                        throw new org.xmlpull.v1.XmlPullParserException(parser.getPositionDescription() +
                                                                        ": <item> tag requires a 'android:color' attribute.");
                    }
                }
                if (listSize == 0 || stateSpec.Length == 0)
                {
                    mDefaultColor = color;
                }
                if (listSize + 1 >= listAllocated)
                {
                    listAllocated = [email protected](listSize + 1);
                    int[] ncolor = new int[listAllocated];
                    System.Array.Copy(colorList, 0, ncolor, 0, listSize);
                    int[][] nstate = new int[listAllocated][];
                    System.Array.Copy(stateSpecList, 0, nstate, 0, listSize);
                    colorList     = ncolor;
                    stateSpecList = nstate;
                }
                colorList[listSize]     = color;
                stateSpecList[listSize] = stateSpec;
                listSize++;
            }
            mColors     = new int[listSize];
            mStateSpecs = new int[listSize][];
            System.Array.Copy(colorList, 0, mColors, 0, listSize);
            System.Array.Copy(stateSpecList, 0, mStateSpecs, 0, listSize);
        }