Example usage for android.content.res TypedArray getString

List of usage examples for android.content.res TypedArray getString

Introduction

In this page you can find the example usage for android.content.res TypedArray getString.

Prototype

@Nullable
public String getString(@StyleableRes int index) 

Source Link

Document

Retrieves the string value for the attribute at index.

Usage

From source file:com.hippo.vector.VectorDrawable.java

private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException {
    final VectorDrawableState state = mVectorState;
    final VPathRenderer pathRenderer = state.mVPathRenderer;

    // Account for any configuration changes.
    state.mChangingConfigurations |= Utils.getChangingConfigurations(a);

    final int tintMode = a.getInt(R.styleable.VectorDrawable_tintMode, -1);
    if (tintMode != -1) {
        state.mTintMode = Utils.parseTintMode(tintMode, Mode.SRC_IN);
    }//w w w  . jav  a2 s .  c o m

    final ColorStateList tint = a.getColorStateList(R.styleable.VectorDrawable_tint);
    if (tint != null) {
        state.mTint = tint;
    }

    state.mAutoMirrored = a.getBoolean(R.styleable.VectorDrawable_autoMirrored, state.mAutoMirrored);

    setAllowCaching(a.getBoolean(R.styleable.VectorDrawable_allowCaching, true));

    pathRenderer.mViewportWidth = a.getFloat(R.styleable.VectorDrawable_viewportWidth,
            pathRenderer.mViewportWidth);
    pathRenderer.mViewportHeight = a.getFloat(R.styleable.VectorDrawable_viewportHeight,
            pathRenderer.mViewportHeight);

    if (pathRenderer.mViewportWidth <= 0) {
        throw new XmlPullParserException(
                a.getPositionDescription() + "<vector> tag requires viewportWidth > 0");
    } else if (pathRenderer.mViewportHeight <= 0) {
        throw new XmlPullParserException(
                a.getPositionDescription() + "<vector> tag requires viewportHeight > 0");
    }

    pathRenderer.mBaseWidth = a.getDimension(R.styleable.VectorDrawable_width, pathRenderer.mBaseWidth);
    pathRenderer.mBaseHeight = a.getDimension(R.styleable.VectorDrawable_height, pathRenderer.mBaseHeight);

    if (pathRenderer.mBaseWidth <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires width > 0");
    } else if (pathRenderer.mBaseHeight <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires height > 0");
    }

    final int insetLeft = a.getDimensionPixelSize(R.styleable.VectorDrawable_opticalInsetLeft,
            pathRenderer.mOpticalInsets.left);
    final int insetTop = a.getDimensionPixelSize(R.styleable.VectorDrawable_opticalInsetTop,
            pathRenderer.mOpticalInsets.top);
    final int insetRight = a.getDimensionPixelSize(R.styleable.VectorDrawable_opticalInsetRight,
            pathRenderer.mOpticalInsets.right);
    final int insetBottom = a.getDimensionPixelSize(R.styleable.VectorDrawable_opticalInsetBottom,
            pathRenderer.mOpticalInsets.bottom);
    pathRenderer.mOpticalInsets = Insets.of(insetLeft, insetTop, insetRight, insetBottom);

    final float alphaInFloat = a.getFloat(R.styleable.VectorDrawable_alpha, pathRenderer.getAlpha());
    pathRenderer.setAlpha(alphaInFloat);

    final String name = a.getString(R.styleable.VectorDrawable_name);
    if (name != null) {
        pathRenderer.mRootName = name;
        pathRenderer.mVGTargetsMap.put(name, pathRenderer);
    }
}

From source file:net.yaly.ViewPagerDoubleIndicator.java

public ViewPagerDoubleIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);//from ww  w .j  a v a 2 s  .  c o  m
    setWillNotDraw(false);
    mTabsContainer = new LinearLayout(context);
    mTabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    addView(mTabsContainer);

    mRectPaint = new Paint();
    mRectPaint.setAntiAlias(true);
    mRectPaint.setStyle(Style.FILL);
    mPaintLine = new Paint();
    mPaintLine.setStyle(Style.FILL);
    mPaintLine.setAntiAlias(true);

    //
    DisplayMetrics dm = getResources().getDisplayMetrics();
    mScrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mScrollOffset, dm);
    mIndicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mIndicatorHeight, dm);
    mUnderlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mUnderlineHeight, dm);
    mDividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerPadding, dm);
    mTabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mTabPadding, dm);
    mDividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerWidth, dm);
    mTabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabTextSize, dm);
    // ?
    mDividerPaint = new Paint();
    mDividerPaint.setAntiAlias(true);
    mDividerPaint.setStrokeWidth(mDividerWidth);

    // get system attrs for container?
    TypedArray a = context.obtainStyledAttributes(attrs, ANDROID_ATTRS);
    int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, getResources().getColor(android.R.color.black));
    mUnderlineColor = textPrimaryColor;
    mDividerColor = textPrimaryColor;
    mBaseLineColor = textPrimaryColor;
    mIndicatorColor = textPrimaryColor;
    int padding = a.getDimensionPixelSize(PADDING_INDEX, 0);
    mPaddingLeft = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_LEFT_INDEX, 0);
    mPaddingRight = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_RIGHT_INDEX, 0);
    a.recycle();

    String tabTextTypefaceName = "sans-serif";
    // Use Roboto Medium as the default typeface from API 21 onwards
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        tabTextTypefaceName = "sans-serif-medium";
        mTabTextTypefaceStyle = Typeface.NORMAL;
    }

    // get custom attrs for tabs and container ?attr?
    a = context.obtainStyledAttributes(attrs, R.styleable.ViewPagerDoubleIndicator);
    mBaseLineColor = a.getColor(R.styleable.ViewPagerDoubleIndicator_vpdiBaseLineColor, mBaseLineColor);
    mIndicatorColor = a.getColor(R.styleable.ViewPagerDoubleIndicator_vpdiIndicatorColor, mIndicatorColor);
    mIndicatorHeight = a.getDimensionPixelSize(R.styleable.ViewPagerDoubleIndicator_vpdiIndicatorHeight,
            mIndicatorHeight);
    mUnderlineColor = a.getColor(R.styleable.ViewPagerDoubleIndicator_vpdiUnderlineColor, mUnderlineColor);
    mUnderlineHeight = a.getDimensionPixelSize(R.styleable.ViewPagerDoubleIndicator_vpdiUnderlineHeight,
            mUnderlineHeight);
    mDividerColor = a.getColor(R.styleable.ViewPagerDoubleIndicator_vpdiDividerColor, mDividerColor);
    mDividerWidth = a.getDimensionPixelSize(R.styleable.ViewPagerDoubleIndicator_vpdiDividerWidth,
            mDividerWidth);
    mDividerPadding = a.getDimensionPixelSize(R.styleable.ViewPagerDoubleIndicator_vpdiDividerPadding,
            mDividerPadding);
    isExpandTabs = a.getBoolean(R.styleable.ViewPagerDoubleIndicator_vpdiShouldExpand, isExpandTabs);
    mScrollOffset = a.getDimensionPixelSize(R.styleable.ViewPagerDoubleIndicator_vpdiScrollOffset,
            mScrollOffset);
    isPaddingMiddle = a.getBoolean(R.styleable.ViewPagerDoubleIndicator_vpdiPaddingMiddle, isPaddingMiddle);
    isHorizontalSplit = a.getBoolean(R.styleable.ViewPagerDoubleIndicator_vpdiHorizontalSplit,
            isHorizontalSplit);
    mTabPadding = a.getDimensionPixelSize(R.styleable.ViewPagerDoubleIndicator_vpdiTabPaddingLeftRight,
            mTabPadding);
    mTabBackgroundResId = a.getResourceId(R.styleable.ViewPagerDoubleIndicator_vpdiTabBackground,
            mTabBackgroundResId);
    mTabTextSize = a.getDimensionPixelSize(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextSize, mTabTextSize);
    mTabTextColor = a.hasValue(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextColor)
            ? a.getColorStateList(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextColor)
            : null;
    mTabTextColorUnSelected = a.hasValue(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextColorUnSelected)
            ? a.getColorStateList(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextColorUnSelected)
            : null;
    mTabTextTypefaceStyle = a.getInt(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextStyle,
            mTabTextTypefaceStyle);
    isTabTextAllCaps = a.getBoolean(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextAllCaps, isTabTextAllCaps);
    int tabTextAlpha = a.getInt(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextAlpha,
            DEF_VALUE_TAB_TEXT_ALPHA);
    String fontFamily = a.getString(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextFontFamily);
    a.recycle();

    //Tab text color selector
    if (mTabTextColor == null) {
        mTabTextColor = createColorStateList(textPrimaryColor, textPrimaryColor, Color.argb(tabTextAlpha,
                Color.red(textPrimaryColor), Color.green(textPrimaryColor), Color.blue(textPrimaryColor)));
    }

    //Tab text typeface and style
    if (fontFamily != null) {
        tabTextTypefaceName = fontFamily;
    }
    mTabTextTypeface = Typeface.create(tabTextTypefaceName, mTabTextTypefaceStyle);

    //Bottom padding for the tabs container parent view to show indicator and underline
    setTabsContainerParentViewPaddings();

    //Configure tab's container LayoutParams for either equal divided space or just wrap tabs
    //?Viewlayout? TODO
    if (isHorizontalSplit) {
        mTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
                1f);//?view
    } else {
        mTabLayoutParams = isExpandTabs ? new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f)
                : new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);//?view
    }
}

From source file:com.github.yggie.pulltorefresh.PullListFragment.java

/**
 * Applies the xml attributes sent through the Bundle object
 *
 * @param a The TypedArray object containing the xml attributes
 *///from   w  w w  .j  ava  2s.c o  m

private void parseXmlAttributes(final TypedArray a) {
    if (a != null) {
        /** apply the background color */
        final int backgroundColor = a.getColor(R.styleable.PullListFragment_list_backgroundColor, 0);
        if (backgroundColor != 0) {
            setListViewBackgroundColor(backgroundColor);
        }

        /**
         * Applies the padding, more specific padding has higher priority
         */

        int paddingTop = listView.getPaddingTop();
        int paddingBottom = listView.getPaddingBottom();
        int paddingLeft = listView.getPaddingLeft();
        int paddingRight = listView.getPaddingRight();

        final int padding = a.getDimensionPixelSize(R.styleable.PullListFragment_list_padding, -1);
        if (padding != -1) {
            paddingTop = padding;
            paddingBottom = padding;
            paddingLeft = padding;
            paddingRight = padding;
        }

        paddingTop = a.getDimensionPixelSize(R.styleable.PullListFragment_list_paddingTop, paddingTop);
        paddingBottom = a.getDimensionPixelSize(R.styleable.PullListFragment_list_paddingBottom, paddingBottom);
        paddingLeft = a.getDimensionPixelSize(R.styleable.PullListFragment_list_paddingLeft, paddingLeft);
        paddingRight = a.getDimensionPixelSize(R.styleable.PullListFragment_list_paddingRight, paddingRight);

        listView.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);

        /**
         * apply pull modes
         */

        final int topMode = a.getInt(R.styleable.PullListFragment_top_mode, MODE_PULL);
        if (topMode != MODE_PULL) {
            enableTopPull(false);
        }

        final int bottomMode = a.getInt(R.styleable.PullListFragment_bottom_mode, MODE_PULL);
        if (bottomMode != MODE_PULL) {
            enableBottomPull(false);
        }

        /**
         * apply custom pulled views
         */

        final int topViewResId = a.getResourceId(R.styleable.PullListFragment_top_view, -1);
        if (topViewResId != -1) {
            setTopPulledView(topViewResId);
        }

        final int bottomViewResId = a.getResourceId(R.styleable.PullListFragment_bottom_view, -1);
        if (bottomViewResId != -1) {
            setBottomPulledView(bottomViewResId);
        }

        /**
         * apply custom text to default views
         */

        if (topManager != null) {
            final String pullStartedText = a.getString(R.styleable.PullListFragment_top_pullStartedText);
            if (pullStartedText != null) {
                topManager.setPullStartedText(pullStartedText);
            }

            final String pullThresholdText = a.getString(R.styleable.PullListFragment_top_pullThresholdText);
            if (pullThresholdText != null) {
                topManager.setPullThresholdText(pullThresholdText);
            }

            final String refreshingText = a.getString(R.styleable.PullListFragment_top_refreshingText);
            if (refreshingText != null) {
                topManager.setRefreshingText(refreshingText);
            }

            final String refreshSuccessText = a.getString(R.styleable.PullListFragment_top_refreshSuccessText);
            if (refreshSuccessText != null) {
                topManager.setRefreshSuccessText(refreshSuccessText);
            }

            final String refreshFailedText = a.getString(R.styleable.PullListFragment_top_refreshFailedText);
            if (refreshFailedText != null) {
                topManager.setRefreshFailedText(refreshFailedText);
            }

            final int bgColor = a.getInt(R.styleable.PullListFragment_top_backgroundColor, -1);
            if (bgColor != -1) {
                topManager.setBackgroundColor(bgColor);
            }

            final int innerBgColor = a.getInt(R.styleable.PullListFragment_top_innerBackgroundColor, -1);
            if (innerBgColor != -1) {
                topManager.setInnerBackgroundColor(innerBgColor);
            }

            final int textSize = a.getDimensionPixelSize(R.styleable.PullListFragment_top_textSize,
                    (int) topManager.getTextSize());
            topManager.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);

            final int textColor = a.getInt(R.styleable.PullListFragment_top_textColor,
                    topManager.getTextColor());
            topManager.setTextColor(textColor);
        }

        if (bottomManager != null) {
            final String pullStartedText = a.getString(R.styleable.PullListFragment_bottom_pullStartedText);
            if (pullStartedText != null) {
                bottomManager.setPullStartedText(pullStartedText);
            }

            final String pullThresholdText = a.getString(R.styleable.PullListFragment_bottom_pullThresholdText);
            if (pullThresholdText != null) {
                bottomManager.setPullThresholdText(pullThresholdText);
            }

            final String refreshingText = a.getString(R.styleable.PullListFragment_bottom_refreshingText);
            if (refreshingText != null) {
                bottomManager.setRefreshingText(refreshingText);
            }

            final String refreshSuccessText = a
                    .getString(R.styleable.PullListFragment_bottom_refreshSuccessText);
            if (refreshSuccessText != null) {
                bottomManager.setRefreshSuccessText(refreshSuccessText);
            }

            final String refreshFailedText = a.getString(R.styleable.PullListFragment_bottom_refreshFailedText);
            if (refreshFailedText != null) {
                bottomManager.setRefreshFailedText(refreshFailedText);
            }

            final int bgColor = a.getInt(R.styleable.PullListFragment_bottom_backgroundColor, -1);
            if (bgColor != -1) {
                bottomManager.setBackgroundColor(bgColor);
            }

            final int innerBgColor = a.getInt(R.styleable.PullListFragment_bottom_innerBackgroundColor, -1);
            if (innerBgColor != -1) {
                bottomManager.setInnerBackgroundColor(innerBgColor);
            }

            final float textSize = a.getDimensionPixelSize(R.styleable.PullListFragment_bottom_textSize,
                    (int) bottomManager.getTextSize());
            bottomManager.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);

            final int textColor = a.getInt(R.styleable.PullListFragment_bottom_textSize,
                    bottomManager.getTextColor());
            bottomManager.setTextColor(textColor);
        }

        /**
         * Apply custom empty view configurations
         */

        final int emptyViewId = a.getResourceId(R.styleable.PullListFragment_empty_view, -1);
        if (emptyViewId != -1) {
            setEmptyView(emptyViewId);
        } else {
            final String emptyText = a.getString(R.styleable.PullListFragment_empty_text);
            if (emptyText != null) {
                setEmptyText(emptyText);
            }
        }

        /**
         * Apply custom behaviour to scroller
         */

        final int delay = a.getInt(R.styleable.PullListFragment_pull_delay,
                scroller.getOnRequestCompleteDelay());
        scroller.setOnRequestCompleteDelay(delay);

        final float damping = a.getFloat(R.styleable.PullListFragment_pull_damping, scroller.getDamping());
        scroller.setDamping(damping);

        final float easing = a.getFloat(R.styleable.PullListFragment_release_easing, scroller.getEasing());
        scroller.setEasing(easing);

        a.recycle();
    }
}

From source file:eu.long1.spacetablayout.SpaceTabLayout.java

private void initArrts(AttributeSet attrs) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.SpaceTabLayout);
    for (int i = 0; i < a.getIndexCount(); ++i) {
        int attr = a.getIndex(i);
        if (attr == R.styleable.SpaceTabLayout_number_of_tabs) {
            numberOfTabs = a.getInt(attr, 3);
            if (numberOfTabs == 0) {
                numberOfTabs = 3;/*from   w  ww . j av  a  2 s.c o m*/
                iconOnly = true;
            }
        } else if (attr == R.styleable.SpaceTabLayout_starting_position) {
            startingPosition = a.getInt(attr, 0);
            int test = startingPosition + 1;
            if (test > numberOfTabs) {
                switch (numberOfTabs) {
                case 3:
                    startingPosition = 1;
                    actionButton.setImageDrawable(defaultTabTwoButtonIcon);
                    actionButton.setOnClickListener(tabTwoOnClickListener);
                    break;
                case 4:
                    startingPosition = 0;
                    actionButton.setImageDrawable(defaultTabOneButtonIcon);
                    actionButton.setOnClickListener(tabOneOnClickListener);
                    break;
                case 5:
                    startingPosition = 2;
                    actionButton.setImageDrawable(defaultTabThreeButtonIcon);
                    actionButton.setOnClickListener(tabThreeOnClickListener);
                    break;
                }
            } else {
                switch (startingPosition) {
                case 0:
                    actionButton.setImageDrawable(defaultTabOneButtonIcon);
                    actionButton.setOnClickListener(tabOneOnClickListener);
                    break;
                case 1:
                    actionButton.setImageDrawable(defaultTabTwoButtonIcon);
                    actionButton.setOnClickListener(tabTwoOnClickListener);
                    break;
                case 2:
                    actionButton.setImageDrawable(defaultTabThreeButtonIcon);
                    actionButton.setOnClickListener(tabThreeOnClickListener);
                    break;
                case 3:
                    actionButton.setImageDrawable(defaultTabFourButtonIcon);
                    actionButton.setOnClickListener(tabFourOnClickListener);
                    break;
                case 4:
                    actionButton.setImageDrawable(defaultTabFiveButtonIcon);
                    actionButton.setOnClickListener(tabFiveOnClickListener);
                    break;
                }
            }
        } else if (attr == R.styleable.SpaceTabLayout_tab_color) {
            defaultTabColor = a.getColor(attr, getContext().getResources().getIdentifier("colorAccent", "color",
                    getContext().getPackageName()));

        } else if (attr == R.styleable.SpaceTabLayout_button_color) {
            defaultButtonColor = a.getColor(attr, getContext().getResources().getIdentifier("colorPrimary",
                    "color", getContext().getPackageName()));

        } else if (attr == R.styleable.SpaceTabLayout_text_color) {
            defaultTextColor = a.getColor(attr,
                    ContextCompat.getColor(getContext(), android.R.color.primary_text_dark));

        } else if (attr == R.styleable.SpaceTabLayout_icon_one) {
            defaultTabOneButtonIcon = a.getDrawable(attr);

        } else if (attr == R.styleable.SpaceTabLayout_icon_two) {
            defaultTabTwoButtonIcon = a.getDrawable(attr);

        } else if (attr == R.styleable.SpaceTabLayout_icon_three) {
            defaultTabThreeButtonIcon = a.getDrawable(attr);

        } else if (attr == R.styleable.SpaceTabLayout_icon_four) {
            if (numberOfTabs > 3)
                defaultTabFourButtonIcon = a.getDrawable(attr);

        } else if (attr == R.styleable.SpaceTabLayout_icon_five) {
            if (numberOfTabs > 4)
                defaultTabFiveButtonIcon = a.getDrawable(attr);

        } else if (attr == R.styleable.SpaceTabLayout_text_one) {
            text_one = a.getString(attr);

        } else if (attr == R.styleable.SpaceTabLayout_text_two) {
            text_two = a.getString(attr);

        } else if (attr == R.styleable.SpaceTabLayout_text_three) {
            text_three = a.getString(attr);

        }
    }
    a.recycle();
}

From source file:com.stfalcon.chatkit.messages.MessagesListStyle.java

static MessagesListStyle parse(Context context, AttributeSet attrs) {
    MessagesListStyle style = new MessagesListStyle(context, attrs);
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MessagesList);

    style.incomingAvatarWidth = typedArray.getDimensionPixelSize(R.styleable.MessagesList_incomingAvatarWidth,
            context.getResources().getDimensionPixelSize(R.dimen.message_avatar_width));
    style.incomingAvatarHeight = typedArray.getDimensionPixelSize(R.styleable.MessagesList_incomingAvatarHeight,
            context.getResources().getDimensionPixelSize(R.dimen.message_avatar_height));

    style.incomingBubbleDrawable = typedArray.getResourceId(R.styleable.MessagesList_incomingBubbleDrawable,
            -1);/*from   ww  w.  ja v  a  2 s  .  co  m*/
    style.incomingDefaultBubbleColor = typedArray.getColor(R.styleable.MessagesList_incomingDefaultBubbleColor,
            ContextCompat.getColor(context, R.color.white_two));
    style.incomingDefaultBubblePressedColor = typedArray.getColor(
            R.styleable.MessagesList_incomingDefaultBubblePressedColor,
            ContextCompat.getColor(context, R.color.white_two));
    style.incomingDefaultBubbleSelectedColor = typedArray.getColor(
            R.styleable.MessagesList_incomingDefaultBubbleSelectedColor,
            ContextCompat.getColor(context, R.color.cornflower_blue_two_24));

    style.incomingDefaultBubblePaddingLeft = typedArray.getDimensionPixelSize(
            R.styleable.MessagesList_incomingBubblePaddingLeft,
            context.getResources().getDimensionPixelSize(R.dimen.message_padding_left));
    style.incomingDefaultBubblePaddingRight = typedArray.getDimensionPixelSize(
            R.styleable.MessagesList_incomingBubblePaddingRight,
            context.getResources().getDimensionPixelSize(R.dimen.message_padding_right));
    style.incomingDefaultBubblePaddingTop = typedArray.getDimensionPixelSize(
            R.styleable.MessagesList_incomingBubblePaddingTop,
            context.getResources().getDimensionPixelSize(R.dimen.message_padding_top));
    style.incomingDefaultBubblePaddingBottom = typedArray.getDimensionPixelSize(
            R.styleable.MessagesList_incomingBubblePaddingBottom,
            context.getResources().getDimensionPixelSize(R.dimen.message_padding_bottom));
    style.incomingTextColor = typedArray.getColor(R.styleable.MessagesList_incomingTextColor,
            ContextCompat.getColor(context, R.color.dark_grey_two));
    style.incomingTextSize = typedArray.getDimensionPixelSize(R.styleable.MessagesList_incomingTextSize,
            context.getResources().getDimensionPixelSize(R.dimen.message_text_size));
    style.incomingTimeTextColor = typedArray.getColor(R.styleable.MessagesList_incomingTimeTextColor,
            ContextCompat.getColor(context, R.color.warm_grey_four));
    style.incomingTimeTextSize = typedArray.getDimensionPixelSize(R.styleable.MessagesList_incomingTimeTextSize,
            context.getResources().getDimensionPixelSize(R.dimen.message_time_text_size));

    style.outcomingBubbleDrawable = typedArray.getResourceId(R.styleable.MessagesList_outcomingBubbleDrawable,
            -1);
    style.outcomingDefaultBubbleColor = typedArray.getColor(
            R.styleable.MessagesList_outcomingDefaultBubbleColor,
            ContextCompat.getColor(context, R.color.cornflower_blue_two));
    style.outcomingDefaultBubblePressedColor = typedArray.getColor(
            R.styleable.MessagesList_outcomingDefaultBubblePressedColor,
            ContextCompat.getColor(context, R.color.cornflower_blue_two));
    style.outcomingDefaultBubbleSelectedColor = typedArray.getColor(
            R.styleable.MessagesList_outcomingDefaultBubbleSelectedColor,
            ContextCompat.getColor(context, R.color.cornflower_blue_two_24));

    style.outcomingDefaultBubblePaddingLeft = typedArray.getDimensionPixelSize(
            R.styleable.MessagesList_outcomingBubblePaddingLeft,
            context.getResources().getDimensionPixelSize(R.dimen.message_padding_left));
    style.outcomingDefaultBubblePaddingRight = typedArray.getDimensionPixelSize(
            R.styleable.MessagesList_outcomingBubblePaddingRight,
            context.getResources().getDimensionPixelSize(R.dimen.message_padding_right));
    style.outcomingDefaultBubblePaddingTop = typedArray.getDimensionPixelSize(
            R.styleable.MessagesList_outcomingBubblePaddingTop,
            context.getResources().getDimensionPixelSize(R.dimen.message_padding_top));
    style.outcomingDefaultBubblePaddingBottom = typedArray.getDimensionPixelSize(
            R.styleable.MessagesList_outcomingBubblePaddingBottom,
            context.getResources().getDimensionPixelSize(R.dimen.message_padding_bottom));
    style.outcomingTextColor = typedArray.getColor(R.styleable.MessagesList_outcomingTextColor,
            ContextCompat.getColor(context, R.color.white));
    style.outcomingTextSize = typedArray.getDimensionPixelSize(R.styleable.MessagesList_outcomingTextSize,
            context.getResources().getDimensionPixelSize(R.dimen.message_text_size));
    style.outcomingTimeTextColor = typedArray.getColor(R.styleable.MessagesList_outcomingTimeTextColor,
            ContextCompat.getColor(context, R.color.white60));
    style.outcomingTimeTextSize = typedArray.getDimensionPixelSize(
            R.styleable.MessagesList_outcomingTimeTextSize,
            context.getResources().getDimensionPixelSize(R.dimen.message_time_text_size));

    style.dateHeaderTextColor = typedArray.getColor(R.styleable.MessagesList_dateHeaderTextColor,
            ContextCompat.getColor(context, R.color.warm_grey_two));
    style.dateHeaderTextSize = typedArray.getDimensionPixelSize(R.styleable.MessagesList_dateHeaderTextSize,
            context.getResources().getDimensionPixelSize(R.dimen.message_date_header_text_size));
    style.dateHeaderPadding = typedArray.getDimensionPixelSize(R.styleable.MessagesList_dateHeaderPadding,
            context.getResources().getDimensionPixelSize(R.dimen.message_date_header_padding));
    style.dateHeaderFormat = typedArray.getString(R.styleable.MessagesList_dateHeaderFormat);

    typedArray.recycle();

    return style;
}

From source file:android.app.Activity.java

/**
 * Standard implementation of//  w  w  w .ja v  a 2  s  .  c  om
 * {@link android.view.LayoutInflater.Factory2#onCreateView(View, String, Context, AttributeSet)}
 * used when inflating with the LayoutInflater returned by {@link #getSystemService}.
 * This implementation handles <fragment> tags to embed fragments inside
 * of the activity.
 *
 * @see android.view.LayoutInflater#createView
 * @see android.view.Window#getLayoutInflater
 */
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
    if (!"fragment".equals(name)) {
        return onCreateView(name, context, attrs);
    }

    String fname = attrs.getAttributeValue(null, "class");
    TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.Fragment);
    if (fname == null) {
        fname = a.getString(com.android.internal.R.styleable.Fragment_name);
    }
    int id = a.getResourceId(com.android.internal.R.styleable.Fragment_id, View.NO_ID);
    String tag = a.getString(com.android.internal.R.styleable.Fragment_tag);
    a.recycle();

    int containerId = parent != null ? parent.getId() : 0;
    if (containerId == View.NO_ID && id == View.NO_ID && tag == null) {
        throw new IllegalArgumentException(attrs.getPositionDescription()
                + ": Must specify unique android:id, android:tag, or have a parent with an id for " + fname);
    }

    // If we restored from a previous state, we may already have
    // instantiated this fragment from the state and should use
    // that instance instead of making a new one.
    Fragment fragment = id != View.NO_ID ? mFragments.findFragmentById(id) : null;
    if (fragment == null && tag != null) {
        fragment = mFragments.findFragmentByTag(tag);
    }
    if (fragment == null && containerId != View.NO_ID) {
        fragment = mFragments.findFragmentById(containerId);
    }

    if (FragmentManagerImpl.DEBUG)
        Log.v(TAG,
                "onCreateView: id=0x" + Integer.toHexString(id) + " fname=" + fname + " existing=" + fragment);
    if (fragment == null) {
        fragment = Fragment.instantiate(this, fname);
        fragment.mFromLayout = true;
        fragment.mFragmentId = id != 0 ? id : containerId;
        fragment.mContainerId = containerId;
        fragment.mTag = tag;
        fragment.mInLayout = true;
        fragment.mFragmentManager = mFragments;
        fragment.onInflate(this, attrs, fragment.mSavedFragmentState);
        mFragments.addFragment(fragment, true);

    } else if (fragment.mInLayout) {
        // A fragment already exists and it is not one we restored from
        // previous state.
        throw new IllegalArgumentException(attrs.getPositionDescription() + ": Duplicate id 0x"
                + Integer.toHexString(id) + ", tag " + tag + ", or parent id 0x"
                + Integer.toHexString(containerId) + " with another fragment for " + fname);
    } else {
        // This fragment was retained from a previous instance; get it
        // going now.
        fragment.mInLayout = true;
        // If this fragment is newly instantiated (either right now, or
        // from last saved state), then give it the attributes to
        // initialize itself.
        if (!fragment.mRetaining) {
            fragment.onInflate(this, attrs, fragment.mSavedFragmentState);
        }
        mFragments.moveToState(fragment);
    }

    if (fragment.mView == null) {
        throw new IllegalStateException("Fragment " + fname + " did not create a view.");
    }
    if (id != 0) {
        fragment.mView.setId(id);
    }
    if (fragment.mView.getTag() == null) {
        fragment.mView.setTag(tag);
    }
    return fragment.mView;
}

From source file:com.facebook.litho.InternalNode.java

void applyAttributes(TypedArray a) {
    for (int i = 0, size = a.getIndexCount(); i < size; i++) {
        final int attr = a.getIndex(i);

        if (attr == R.styleable.ComponentLayout_android_layout_width) {
            int width = a.getLayoutDimension(attr, -1);
            // We don't support WRAP_CONTENT or MATCH_PARENT so no-op for them
            if (width >= 0) {
                widthPx(width);/* w ww . j ava2 s.c o  m*/
            }
        } else if (attr == R.styleable.ComponentLayout_android_layout_height) {
            int height = a.getLayoutDimension(attr, -1);
            // We don't support WRAP_CONTENT or MATCH_PARENT so no-op for them
            if (height >= 0) {
                heightPx(height);
            }
        } else if (attr == R.styleable.ComponentLayout_android_paddingLeft) {
            paddingPx(LEFT, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_paddingTop) {
            paddingPx(TOP, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_paddingRight) {
            paddingPx(RIGHT, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_paddingBottom) {
            paddingPx(BOTTOM, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_paddingStart && SUPPORTS_RTL) {
            paddingPx(START, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_paddingEnd && SUPPORTS_RTL) {
            paddingPx(END, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_padding) {
            paddingPx(ALL, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_layout_marginLeft) {
            marginPx(LEFT, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_layout_marginTop) {
            marginPx(TOP, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_layout_marginRight) {
            marginPx(RIGHT, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_layout_marginBottom) {
            marginPx(BOTTOM, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_layout_marginStart && SUPPORTS_RTL) {
            marginPx(START, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_layout_marginEnd && SUPPORTS_RTL) {
            marginPx(END, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_layout_margin) {
            marginPx(ALL, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_importantForAccessibility
                && SDK_INT >= JELLY_BEAN) {
            importantForAccessibility(a.getInt(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_duplicateParentState) {
            duplicateParentState(a.getBoolean(attr, false));
        } else if (attr == R.styleable.ComponentLayout_android_background) {
            if (TypedArrayUtils.isColorAttribute(a, R.styleable.ComponentLayout_android_background)) {
                backgroundColor(a.getColor(attr, 0));
            } else {
                backgroundRes(a.getResourceId(attr, -1));
            }
        } else if (attr == R.styleable.ComponentLayout_android_foreground) {
            if (TypedArrayUtils.isColorAttribute(a, R.styleable.ComponentLayout_android_foreground)) {
                foregroundColor(a.getColor(attr, 0));
            } else {
                foregroundRes(a.getResourceId(attr, -1));
            }
        } else if (attr == R.styleable.ComponentLayout_android_contentDescription) {
            contentDescription(a.getString(attr));
        } else if (attr == R.styleable.ComponentLayout_flex_direction) {
            flexDirection(YogaFlexDirection.fromInt(a.getInteger(attr, 0)));
        } else if (attr == R.styleable.ComponentLayout_flex_wrap) {
            wrap(YogaWrap.fromInt(a.getInteger(attr, 0)));
        } else if (attr == R.styleable.ComponentLayout_flex_justifyContent) {
            justifyContent(YogaJustify.fromInt(a.getInteger(attr, 0)));
        } else if (attr == R.styleable.ComponentLayout_flex_alignItems) {
            alignItems(YogaAlign.fromInt(a.getInteger(attr, 0)));
        } else if (attr == R.styleable.ComponentLayout_flex_alignSelf) {
            alignSelf(YogaAlign.fromInt(a.getInteger(attr, 0)));
        } else if (attr == R.styleable.ComponentLayout_flex_positionType) {
            positionType(YogaPositionType.fromInt(a.getInteger(attr, 0)));
        } else if (attr == R.styleable.ComponentLayout_flex) {
            final float flex = a.getFloat(attr, -1);
            if (flex >= 0f) {
                flex(flex);
            }
        } else if (attr == R.styleable.ComponentLayout_flex_left) {
            positionPx(LEFT, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_flex_top) {
            positionPx(TOP, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_flex_right) {
            positionPx(RIGHT, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_flex_bottom) {
            positionPx(BOTTOM, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_flex_layoutDirection) {
            final int layoutDirection = a.getInteger(attr, -1);
            layoutDirection(YogaDirection.fromInt(layoutDirection));
        }
    }
}

From source file:android.content.pm.PackageParser.java

/**
 * Parse the manifest of a <em>base APK</em>.
 * <p>//from  w  w w . j a  v  a  2  s.com
 * When adding new features, carefully consider if they should also be
 * supported by split APKs.
 */
private Package parseBaseApk(Resources res, XmlResourceParser parser, int flags, String[] outError)
        throws XmlPullParserException, IOException {
    final boolean trustedOverlay = (flags & PARSE_TRUSTED_OVERLAY) != 0;

    AttributeSet attrs = parser;

    mParseInstrumentationArgs = null;
    mParseActivityArgs = null;
    mParseServiceArgs = null;
    mParseProviderArgs = null;

    final String pkgName;
    final String splitName;
    try {
        Pair<String, String> packageSplit = parsePackageSplitNames(parser, attrs, flags);
        pkgName = packageSplit.first;
        splitName = packageSplit.second;
    } catch (PackageParserException e) {
        mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
        return null;
    }

    int type;

    if (!TextUtils.isEmpty(splitName)) {
        outError[0] = "Expected base APK, but found split " + splitName;
        mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
        return null;
    }

    final Package pkg = new Package(pkgName);
    boolean foundApp = false;

    TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifest);
    pkg.mVersionCode = pkg.applicationInfo.versionCode = sa
            .getInteger(com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
    pkg.baseRevisionCode = sa.getInteger(com.android.internal.R.styleable.AndroidManifest_revisionCode, 0);
    pkg.mVersionName = sa
            .getNonConfigurationString(com.android.internal.R.styleable.AndroidManifest_versionName, 0);
    if (pkg.mVersionName != null) {
        pkg.mVersionName = pkg.mVersionName.intern();
    }
    String str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0);
    if (str != null && str.length() > 0) {
        String nameError = validateName(str, true, false);
        if (nameError != null && !"android".equals(pkgName)) {
            outError[0] = "<manifest> specifies bad sharedUserId name \"" + str + "\": " + nameError;
            mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
            return null;
        }
        pkg.mSharedUserId = str.intern();
        pkg.mSharedUserLabel = sa
                .getResourceId(com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
    }

    pkg.installLocation = sa.getInteger(com.android.internal.R.styleable.AndroidManifest_installLocation,
            PARSE_DEFAULT_INSTALL_LOCATION);
    pkg.applicationInfo.installLocation = pkg.installLocation;

    pkg.coreApp = attrs.getAttributeBooleanValue(null, "coreApp", false);

    sa.recycle();

    /* Set the global "forward lock" flag */
    if ((flags & PARSE_FORWARD_LOCK) != 0) {
        pkg.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_FORWARD_LOCK;
    }

    /* Set the global "on SD card" flag */
    if ((flags & PARSE_EXTERNAL_STORAGE) != 0) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
    }

    // Resource boolean are -1, so 1 means we don't know the value.
    int supportsSmallScreens = 1;
    int supportsNormalScreens = 1;
    int supportsLargeScreens = 1;
    int supportsXLargeScreens = 1;
    int resizeable = 1;
    int anyDensity = 1;

    int outerDepth = parser.getDepth();
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }

        String tagName = parser.getName();
        if (tagName.equals("application")) {
            if (foundApp) {
                if (RIGID_PARSER) {
                    outError[0] = "<manifest> has more than one <application>";
                    mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                    return null;
                } else {
                    Slog.w(TAG, "<manifest> has more than one <application>");
                    XmlUtils.skipCurrentTag(parser);
                    continue;
                }
            }

            foundApp = true;
            if (!parseBaseApplication(pkg, res, parser, attrs, flags, outError)) {
                return null;
            }
        } else if (tagName.equals("overlay")) {
            pkg.mTrustedOverlay = trustedOverlay;

            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestResourceOverlay);
            pkg.mOverlayTarget = sa
                    .getString(com.android.internal.R.styleable.AndroidManifestResourceOverlay_targetPackage);
            pkg.mOverlayPriority = sa
                    .getInt(com.android.internal.R.styleable.AndroidManifestResourceOverlay_priority, -1);
            sa.recycle();

            if (pkg.mOverlayTarget == null) {
                outError[0] = "<overlay> does not specify a target package";
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return null;
            }
            if (pkg.mOverlayPriority < 0 || pkg.mOverlayPriority > 9999) {
                outError[0] = "<overlay> priority must be between 0 and 9999";
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return null;
            }
            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("key-sets")) {
            if (!parseKeySets(pkg, res, parser, attrs, outError)) {
                return null;
            }
        } else if (tagName.equals("permission-group")) {
            if (parsePermissionGroup(pkg, flags, res, parser, attrs, outError) == null) {
                return null;
            }
        } else if (tagName.equals("permission")) {
            if (parsePermission(pkg, res, parser, attrs, outError) == null) {
                return null;
            }
        } else if (tagName.equals("permission-tree")) {
            if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
                return null;
            }
        } else if (tagName.equals("uses-permission")) {
            if (!parseUsesPermission(pkg, res, parser, attrs)) {
                return null;
            }
        } else if (tagName.equals("uses-permission-sdk-m") || tagName.equals("uses-permission-sdk-23")) {
            if (!parseUsesPermission(pkg, res, parser, attrs)) {
                return null;
            }
        } else if (tagName.equals("uses-configuration")) {
            ConfigurationInfo cPref = new ConfigurationInfo();
            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
            cPref.reqTouchScreen = sa.getInt(
                    com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
                    Configuration.TOUCHSCREEN_UNDEFINED);
            cPref.reqKeyboardType = sa.getInt(
                    com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
                    Configuration.KEYBOARD_UNDEFINED);
            if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
                    false)) {
                cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
            }
            cPref.reqNavigation = sa.getInt(
                    com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
                    Configuration.NAVIGATION_UNDEFINED);
            if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
                    false)) {
                cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
            }
            sa.recycle();
            pkg.configPreferences = ArrayUtils.add(pkg.configPreferences, cPref);

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("uses-feature")) {
            FeatureInfo fi = parseUsesFeature(res, attrs);
            pkg.reqFeatures = ArrayUtils.add(pkg.reqFeatures, fi);

            if (fi.name == null) {
                ConfigurationInfo cPref = new ConfigurationInfo();
                cPref.reqGlEsVersion = fi.reqGlEsVersion;
                pkg.configPreferences = ArrayUtils.add(pkg.configPreferences, cPref);
            }

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("feature-group")) {
            FeatureGroupInfo group = new FeatureGroupInfo();
            ArrayList<FeatureInfo> features = null;
            final int innerDepth = parser.getDepth();
            while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
                    && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
                    continue;
                }

                final String innerTagName = parser.getName();
                if (innerTagName.equals("uses-feature")) {
                    FeatureInfo featureInfo = parseUsesFeature(res, attrs);
                    // FeatureGroups are stricter and mandate that
                    // any <uses-feature> declared are mandatory.
                    featureInfo.flags |= FeatureInfo.FLAG_REQUIRED;
                    features = ArrayUtils.add(features, featureInfo);
                } else {
                    Slog.w(TAG, "Unknown element under <feature-group>: " + innerTagName + " at "
                            + mArchiveSourcePath + " " + parser.getPositionDescription());
                }
                XmlUtils.skipCurrentTag(parser);
            }

            if (features != null) {
                group.features = new FeatureInfo[features.size()];
                group.features = features.toArray(group.features);
            }
            pkg.featureGroups = ArrayUtils.add(pkg.featureGroups, group);

        } else if (tagName.equals("uses-sdk")) {
            if (SDK_VERSION > 0) {
                sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestUsesSdk);

                int minVers = 0;
                String minCode = null;
                int targetVers = 0;
                String targetCode = null;

                TypedValue val = sa
                        .peekValue(com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
                if (val != null) {
                    if (val.type == TypedValue.TYPE_STRING && val.string != null) {
                        targetCode = minCode = val.string.toString();
                    } else {
                        // If it's not a string, it's an integer.
                        targetVers = minVers = val.data;
                    }
                }

                val = sa.peekValue(com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
                if (val != null) {
                    if (val.type == TypedValue.TYPE_STRING && val.string != null) {
                        targetCode = minCode = val.string.toString();
                    } else {
                        // If it's not a string, it's an integer.
                        targetVers = val.data;
                    }
                }

                sa.recycle();

                if (minCode != null) {
                    boolean allowedCodename = false;
                    for (String codename : SDK_CODENAMES) {
                        if (minCode.equals(codename)) {
                            allowedCodename = true;
                            break;
                        }
                    }
                    if (!allowedCodename) {
                        if (SDK_CODENAMES.length > 0) {
                            outError[0] = "Requires development platform " + minCode
                                    + " (current platform is any of " + Arrays.toString(SDK_CODENAMES) + ")";
                        } else {
                            outError[0] = "Requires development platform " + minCode
                                    + " but this is a release platform.";
                        }
                        mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
                        return null;
                    }
                } else if (minVers > SDK_VERSION) {
                    outError[0] = "Requires newer sdk version #" + minVers + " (current version is #"
                            + SDK_VERSION + ")";
                    mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
                    return null;
                }

                if (targetCode != null) {
                    boolean allowedCodename = false;
                    for (String codename : SDK_CODENAMES) {
                        if (targetCode.equals(codename)) {
                            allowedCodename = true;
                            break;
                        }
                    }
                    if (!allowedCodename) {
                        if (SDK_CODENAMES.length > 0) {
                            outError[0] = "Requires development platform " + targetCode
                                    + " (current platform is any of " + Arrays.toString(SDK_CODENAMES) + ")";
                        } else {
                            outError[0] = "Requires development platform " + targetCode
                                    + " but this is a release platform.";
                        }
                        mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
                        return null;
                    }
                    // If the code matches, it definitely targets this SDK.
                    pkg.applicationInfo.targetSdkVersion = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
                } else {
                    pkg.applicationInfo.targetSdkVersion = targetVers;
                }
            }

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("supports-screens")) {
            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestSupportsScreens);

            pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp, 0);
            pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp, 0);
            pkg.applicationInfo.largestWidthLimitDp = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp, 0);

            // This is a trick to get a boolean and still able to detect
            // if a value was actually set.
            supportsSmallScreens = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
                    supportsSmallScreens);
            supportsNormalScreens = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
                    supportsNormalScreens);
            supportsLargeScreens = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
                    supportsLargeScreens);
            supportsXLargeScreens = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens,
                    supportsXLargeScreens);
            resizeable = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable, resizeable);
            anyDensity = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity, anyDensity);

            sa.recycle();

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("protected-broadcast")) {
            sa = res.obtainAttributes(attrs,
                    com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);

            // Note: don't allow this value to be a reference to a resource
            // that may change.
            String name = sa.getNonResourceString(
                    com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);

            sa.recycle();

            if (name != null && (flags & PARSE_IS_SYSTEM) != 0) {
                if (pkg.protectedBroadcasts == null) {
                    pkg.protectedBroadcasts = new ArrayList<String>();
                }
                if (!pkg.protectedBroadcasts.contains(name)) {
                    pkg.protectedBroadcasts.add(name.intern());
                }
            }

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("instrumentation")) {
            if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
                return null;
            }

        } else if (tagName.equals("original-package")) {
            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestOriginalPackage);

            String orig = sa.getNonConfigurationString(
                    com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
            if (!pkg.packageName.equals(orig)) {
                if (pkg.mOriginalPackages == null) {
                    pkg.mOriginalPackages = new ArrayList<String>();
                    pkg.mRealPackage = pkg.packageName;
                }
                pkg.mOriginalPackages.add(orig);
            }

            sa.recycle();

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("adopt-permissions")) {
            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestOriginalPackage);

            String name = sa.getNonConfigurationString(
                    com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);

            sa.recycle();

            if (name != null) {
                if (pkg.mAdoptPermissions == null) {
                    pkg.mAdoptPermissions = new ArrayList<String>();
                }
                pkg.mAdoptPermissions.add(name);
            }

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("uses-gl-texture")) {
            // Just skip this tag
            XmlUtils.skipCurrentTag(parser);
            continue;

        } else if (tagName.equals("compatible-screens")) {
            // Just skip this tag
            XmlUtils.skipCurrentTag(parser);
            continue;
        } else if (tagName.equals("supports-input")) {
            XmlUtils.skipCurrentTag(parser);
            continue;

        } else if (tagName.equals("eat-comment")) {
            // Just skip this tag
            XmlUtils.skipCurrentTag(parser);
            continue;

        } else if (RIGID_PARSER) {
            outError[0] = "Bad element under <manifest>: " + parser.getName();
            mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
            return null;

        } else {
            Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName() + " at " + mArchiveSourcePath
                    + " " + parser.getPositionDescription());
            XmlUtils.skipCurrentTag(parser);
            continue;
        }
    }

    if (!foundApp && pkg.instrumentation.size() == 0) {
        outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
    }

    final int NP = PackageParser.NEW_PERMISSIONS.length;
    StringBuilder implicitPerms = null;
    for (int ip = 0; ip < NP; ip++) {
        final PackageParser.NewPermissionInfo npi = PackageParser.NEW_PERMISSIONS[ip];
        if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
            break;
        }
        if (!pkg.requestedPermissions.contains(npi.name)) {
            if (implicitPerms == null) {
                implicitPerms = new StringBuilder(128);
                implicitPerms.append(pkg.packageName);
                implicitPerms.append(": compat added ");
            } else {
                implicitPerms.append(' ');
            }
            implicitPerms.append(npi.name);
            pkg.requestedPermissions.add(npi.name);
        }
    }
    if (implicitPerms != null) {
        Slog.i(TAG, implicitPerms.toString());
    }

    final int NS = PackageParser.SPLIT_PERMISSIONS.length;
    for (int is = 0; is < NS; is++) {
        final PackageParser.SplitPermissionInfo spi = PackageParser.SPLIT_PERMISSIONS[is];
        if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk
                || !pkg.requestedPermissions.contains(spi.rootPerm)) {
            continue;
        }
        for (int in = 0; in < spi.newPerms.length; in++) {
            final String perm = spi.newPerms[in];
            if (!pkg.requestedPermissions.contains(perm)) {
                pkg.requestedPermissions.add(perm);
            }
        }
    }

    if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
            && pkg.applicationInfo.targetSdkVersion >= android.os.Build.VERSION_CODES.DONUT)) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
    }
    if (supportsNormalScreens != 0) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
    }
    if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
            && pkg.applicationInfo.targetSdkVersion >= android.os.Build.VERSION_CODES.DONUT)) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
    }
    if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
            && pkg.applicationInfo.targetSdkVersion >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
    }
    if (resizeable < 0 || (resizeable > 0
            && pkg.applicationInfo.targetSdkVersion >= android.os.Build.VERSION_CODES.DONUT)) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
    }
    if (anyDensity < 0 || (anyDensity > 0
            && pkg.applicationInfo.targetSdkVersion >= android.os.Build.VERSION_CODES.DONUT)) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
    }

    return pkg;
}

From source file:android.content.pm.PackageParser.java

/**
 * Parse the {@code application} XML tree at the current parse location in a
 * <em>base APK</em> manifest.
 * <p>/*from w  w w. j av a2  s.  c o m*/
 * When adding new features, carefully consider if they should also be
 * supported by split APKs.
 */
private boolean parseBaseApplication(Package owner, Resources res, XmlPullParser parser, AttributeSet attrs,
        int flags, String[] outError) throws XmlPullParserException, IOException {
    final ApplicationInfo ai = owner.applicationInfo;
    final String pkgName = owner.applicationInfo.packageName;

    TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestApplication);

    String name = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestApplication_name,
            0);
    if (name != null) {
        ai.className = buildClassName(pkgName, name, outError);
        if (ai.className == null) {
            sa.recycle();
            mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
            return false;
        }
    }

    String manageSpaceActivity = sa.getNonConfigurationString(
            com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity,
            Configuration.NATIVE_CONFIG_VERSION);
    if (manageSpaceActivity != null) {
        ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity, outError);
    }

    boolean allowBackup = sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_allowBackup,
            true);
    if (allowBackup) {
        ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;

        // backupAgent, killAfterRestore, fullBackupContent and restoreAnyVersion are only
        // relevant if backup is possible for the given application.
        String backupAgent = sa.getNonConfigurationString(
                com.android.internal.R.styleable.AndroidManifestApplication_backupAgent,
                Configuration.NATIVE_CONFIG_VERSION);
        if (backupAgent != null) {
            ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
            if (DEBUG_BACKUP) {
                Slog.v(TAG,
                        "android:backupAgent = " + ai.backupAgentName + " from " + pkgName + "+" + backupAgent);
            }

            if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
                    true)) {
                ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
            }
            if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
                    false)) {
                ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
            }
            if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_fullBackupOnly,
                    false)) {
                ai.flags |= ApplicationInfo.FLAG_FULL_BACKUP_ONLY;
            }
        }

        TypedValue v = sa
                .peekValue(com.android.internal.R.styleable.AndroidManifestApplication_fullBackupContent);
        if (v != null && (ai.fullBackupContent = v.resourceId) == 0) {
            if (DEBUG_BACKUP) {
                Slog.v(TAG, "fullBackupContent specified as boolean=" + (v.data == 0 ? "false" : "true"));
            }
            // "false" => -1, "true" => 0
            ai.fullBackupContent = (v.data == 0 ? -1 : 0);
        }
        if (DEBUG_BACKUP) {
            Slog.v(TAG, "fullBackupContent=" + ai.fullBackupContent + " for " + pkgName);
        }
    }

    TypedValue v = sa.peekValue(com.android.internal.R.styleable.AndroidManifestApplication_label);
    if (v != null && (ai.labelRes = v.resourceId) == 0) {
        ai.nonLocalizedLabel = v.coerceToString();
    }

    ai.icon = sa.getResourceId(com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
    ai.logo = sa.getResourceId(com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
    ai.banner = sa.getResourceId(com.android.internal.R.styleable.AndroidManifestApplication_banner, 0);
    ai.theme = sa.getResourceId(com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
    ai.descriptionRes = sa
            .getResourceId(com.android.internal.R.styleable.AndroidManifestApplication_description, 0);

    if ((flags & PARSE_IS_SYSTEM) != 0) {
        if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_persistent, false)) {
            ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
        }
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_requiredForAllUsers, false)) {
        owner.mRequiredForAllUsers = true;
    }

    String restrictedAccountType = sa
            .getString(com.android.internal.R.styleable.AndroidManifestApplication_restrictedAccountType);
    if (restrictedAccountType != null && restrictedAccountType.length() > 0) {
        owner.mRestrictedAccountType = restrictedAccountType;
    }

    String requiredAccountType = sa
            .getString(com.android.internal.R.styleable.AndroidManifestApplication_requiredAccountType);
    if (requiredAccountType != null && requiredAccountType.length() > 0) {
        owner.mRequiredAccountType = requiredAccountType;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_debuggable, false)) {
        ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode, false)) {
        ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
    }

    owner.baseHardwareAccelerated = sa.getBoolean(
            com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
            owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
    if (owner.baseHardwareAccelerated) {
        ai.flags |= ApplicationInfo.FLAG_HARDWARE_ACCELERATED;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_hasCode, true)) {
        ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
            false)) {
        ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData, true)) {
        ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_testOnly, false)) {
        ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_largeHeap, false)) {
        ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_usesCleartextTraffic, true)) {
        ai.flags |= ApplicationInfo.FLAG_USES_CLEARTEXT_TRAFFIC;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl,
            false /* default is no RTL support*/)) {
        ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_multiArch, false)) {
        ai.flags |= ApplicationInfo.FLAG_MULTIARCH;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_extractNativeLibs, true)) {
        ai.flags |= ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS;
    }

    String str;
    str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestApplication_permission,
            0);
    ai.permission = (str != null && str.length() > 0) ? str.intern() : null;

    if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
        str = sa.getNonConfigurationString(
                com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity,
                Configuration.NATIVE_CONFIG_VERSION);
    } else {
        // Some older apps have been seen to use a resource reference
        // here that on older builds was ignored (with a warning).  We
        // need to continue to do this for them so they don't break.
        str = sa.getNonResourceString(com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
    }
    ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName, str, outError);

    if (outError[0] == null) {
        CharSequence pname;
        if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
            pname = sa.getNonConfigurationString(
                    com.android.internal.R.styleable.AndroidManifestApplication_process,
                    Configuration.NATIVE_CONFIG_VERSION);
        } else {
            // Some older apps have been seen to use a resource reference
            // here that on older builds was ignored (with a warning).  We
            // need to continue to do this for them so they don't break.
            pname = sa
                    .getNonResourceString(com.android.internal.R.styleable.AndroidManifestApplication_process);
        }
        ai.processName = buildProcessName(ai.packageName, null, pname, flags, mSeparateProcesses, outError);

        ai.enabled = sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);

        if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_isGame, false)) {
            ai.flags |= ApplicationInfo.FLAG_IS_GAME;
        }

        if (false) {
            if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
                    false)) {
                ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE;

                // A heavy-weight application can not be in a custom process.
                // We can do direct compare because we intern all strings.
                if (ai.processName != null && ai.processName != ai.packageName) {
                    outError[0] = "cantSaveState applications can not use custom processes";
                }
            }
        }
    }

    ai.uiOptions = sa.getInt(com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0);

    sa.recycle();

    if (outError[0] != null) {
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return false;
    }

    final int innerDepth = parser.getDepth();
    int type;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }

        String tagName = parser.getName();
        if (tagName.equals("activity")) {
            Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
                    owner.baseHardwareAccelerated);
            if (a == null) {
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return false;
            }

            owner.activities.add(a);

        } else if (tagName.equals("receiver")) {
            Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
            if (a == null) {
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return false;
            }

            owner.receivers.add(a);

        } else if (tagName.equals("service")) {
            Service s = parseService(owner, res, parser, attrs, flags, outError);
            if (s == null) {
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return false;
            }

            owner.services.add(s);

        } else if (tagName.equals("provider")) {
            Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
            if (p == null) {
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return false;
            }

            owner.providers.add(p);

        } else if (tagName.equals("activity-alias")) {
            Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
            if (a == null) {
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return false;
            }

            owner.activities.add(a);

        } else if (parser.getName().equals("meta-data")) {
            // note: application meta-data is stored off to the side, so it can
            // remain null in the primary copy (we like to avoid extra copies because
            // it can be large)
            if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
                    outError)) == null) {
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return false;
            }

        } else if (tagName.equals("library")) {
            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestLibrary);

            // Note: don't allow this value to be a reference to a resource
            // that may change.
            String lname = sa
                    .getNonResourceString(com.android.internal.R.styleable.AndroidManifestLibrary_name);

            sa.recycle();

            if (lname != null) {
                lname = lname.intern();
                if (!ArrayUtils.contains(owner.libraryNames, lname)) {
                    owner.libraryNames = ArrayUtils.add(owner.libraryNames, lname);
                }
            }

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("uses-library")) {
            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestUsesLibrary);

            // Note: don't allow this value to be a reference to a resource
            // that may change.
            String lname = sa
                    .getNonResourceString(com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
            boolean req = sa.getBoolean(com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
                    true);

            sa.recycle();

            if (lname != null) {
                lname = lname.intern();
                if (req) {
                    owner.usesLibraries = ArrayUtils.add(owner.usesLibraries, lname);
                } else {
                    owner.usesOptionalLibraries = ArrayUtils.add(owner.usesOptionalLibraries, lname);
                }
            }

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("uses-package")) {
            // Dependencies for app installers; we don't currently try to
            // enforce this.
            XmlUtils.skipCurrentTag(parser);

        } else {
            if (!RIGID_PARSER) {
                Slog.w(TAG, "Unknown element under <application>: " + tagName + " at " + mArchiveSourcePath
                        + " " + parser.getPositionDescription());
                XmlUtils.skipCurrentTag(parser);
                continue;
            } else {
                outError[0] = "Bad element under <application>: " + tagName;
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return false;
            }
        }
    }

    modifySharedLibrariesForBackwardCompatibility(owner);

    if (hasDomainURLs(owner)) {
        owner.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS;
    } else {
        owner.applicationInfo.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS;
    }

    return true;
}

From source file:cn.ismartv.recyclerview.widget.RecyclerView.java

public RecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setScrollContainer(true);/*www . j  ava  2  s.  c  o  m*/
    setFocusableInTouchMode(true);
    final int version = Build.VERSION.SDK_INT;
    mPostUpdatesOnAnimation = version >= 16;

    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    setWillNotDraw(ViewCompat.getOverScrollMode(this) == ViewCompat.OVER_SCROLL_NEVER);

    mItemAnimator.setListener(mItemAnimatorListener);
    initAdapterManager();
    initChildrenHelper();
    // If not explicitly specified this view is important for accessibility.
    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }
    mAccessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    setAccessibilityDelegateCompat(new RecyclerViewAccessibilityDelegate(this));
    // Create the layoutManager if specified.
    if (attrs != null) {
        int defStyleRes = 0;
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RecyclerView, defStyle, defStyleRes);
        String layoutManagerName = a.getString(R.styleable.RecyclerView_layoutManager);
        a.recycle();
        createLayoutManager(context, layoutManagerName, attrs, defStyle, defStyleRes);
    }

    mScrollingChildHelper = new NestedScrollingChildHelper(this);
    setNestedScrollingEnabled(true);
}