Example usage for android.util AttributeSet getAttributeValue

List of usage examples for android.util AttributeSet getAttributeValue

Introduction

In this page you can find the example usage for android.util AttributeSet getAttributeValue.

Prototype

public String getAttributeValue(String namespace, String name);

Source Link

Document

Returns the value of the specified attribute as a string representation.

Usage

From source file:com.nihaskalam.progressbuttonlibrary.CircularProgressButton.java

private void initAttributes(Context context, AttributeSet attributeSet) {
    String xmlProvidedSize = attributeSet.getAttributeValue("http://schemas.android.com/apk/res/android",
            "textSize");
    String[] parts = xmlProvidedSize.split("\\.");
    String part1 = parts[0];/*from   w  ww  .  j a v a 2 s . co m*/
    textSize = new Integer(part1);
    if (textSize < 0) {
        float sourceTextSize = getTextSize();
        textSize = (int) (sourceTextSize / getContext().getResources().getDisplayMetrics().density);
    }
    TypedArray attr = getTypedArray(context, attributeSet, R.styleable.CircularProgressButton);
    if (attr == null) {
        return;
    }
    try {

        mIdleText = attr.getString(R.styleable.CircularProgressButton_pb_textIdle);
        mCompleteText = attr.getString(R.styleable.CircularProgressButton_pb_textComplete);
        mCancelText = attr.getString(R.styleable.CircularProgressButton_pb_textCancel);
        mErrorText = attr.getString(R.styleable.CircularProgressButton_pb_textError);
        mProgressText = attr.getString(R.styleable.CircularProgressButton_pb_textProgress);

        mIconComplete = attr.getResourceId(R.styleable.CircularProgressButton_pb_iconComplete, 0);
        mIconCancel = attr.getResourceId(R.styleable.CircularProgressButton_pb_iconCancel, 0);
        mIconError = attr.getResourceId(R.styleable.CircularProgressButton_pb_iconError, 0);
        mCornerRadius = attr.getDimension(R.styleable.CircularProgressButton_pb_cornerRadius, 0);
        mPaddingProgress = attr.getDimensionPixelSize(R.styleable.CircularProgressButton_pb_paddingProgress, 0);
        mIndeterminateProgressMode = attr.getBoolean(R.styleable.CircularProgressButton_pb_isIndeterminate,
                false);

        int blue = getColor(R.color.pb_blue);
        int white = getColor(R.color.pb_white);
        int grey = getColor(R.color.pb_grey);

        int idleStateSelector = attr.getResourceId(R.styleable.CircularProgressButton_pb_selectorIdle,
                R.color.pb_idle_state_selector);
        mIdleColorState = ContextCompat.getColorStateList(context, idleStateSelector);

        int completeStateSelector = attr.getResourceId(R.styleable.CircularProgressButton_pb_selectorComplete,
                R.color.pb_complete_state_selector);
        mCompleteColorState = ContextCompat.getColorStateList(context, completeStateSelector);
        int cancelStateSelector = attr.getResourceId(R.styleable.CircularProgressButton_pb_selectorCancel,
                R.color.pb_cancel_state_selector);
        mCancelColorState = ContextCompat.getColorStateList(context, cancelStateSelector);
        int errorStateSelector = attr.getResourceId(R.styleable.CircularProgressButton_pb_selectorError,
                R.color.pb_error_state_selector);
        mErrorColorState = ContextCompat.getColorStateList(context, errorStateSelector);

        mColorProgress = attr.getColor(R.styleable.CircularProgressButton_pb_colorProgress, white);
        mColorIndicator = attr.getColor(R.styleable.CircularProgressButton_pb_colorIndicator, blue);
        mColorProgressCancelIcon = attr.getColor(R.styleable.CircularProgressButton_pb_colorProgressCancelIcon,
                mColorIndicator);
        mColorIndicatorBackground = attr
                .getColor(R.styleable.CircularProgressButton_pb_colorIndicatorBackground, grey);
        mIdleStateTextColorAfterClick = attr.getColor(R.styleable.CircularProgressButton_pb_textColorAfterClick,
                getNormalColor(mIdleColorState));
        if (idleStateStrokeColor != -1) {
            mIdleStateBackgroundColorAfterClick = attr.getColor(
                    R.styleable.CircularProgressButton_pb_backgroundColorAfterClick,
                    getColor(idleStateStrokeColor));
        } else {
            mIdleStateBackgroundColorAfterClick = attr.getColor(
                    R.styleable.CircularProgressButton_pb_backgroundColorAfterClick,
                    getPressedColor(mIdleColorState));
        }
        mColorCancelText = attr.getColor(R.styleable.CircularProgressButton_pb_colorCancelText,
                getNormalColor(this.getTextColors()));
        mColorCompleteText = attr.getColor(R.styleable.CircularProgressButton_pb_colorCompleteText,
                getNormalColor(this.getTextColors()));
        mColorErrorText = attr.getColor(R.styleable.CircularProgressButton_pb_colorErrorText,
                getNormalColor(this.getTextColors()));
        mColorIdleText = getNormalColor(this.getTextColors());
    } finally {
        attr.recycle();
    }
}

From source file:com.youqu.piclbs.util.SlidingTabLayout.java

public SlidingTabLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setFillViewport(true);//???
    setWillNotDraw(false);//?onDraw,??flag
    setClipChildren(false);/*  w w  w. ja  va 2 s.  com*/
    setClipToPadding(false);

    this.mContext = context;
    mTabsContainer = new LinearLayout(context);
    addView(mTabsContainer);

    obtainAttributes(context, attrs);

    //get layout_height
    String height = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "layout_height");
    if (height.equals(ViewGroup.LayoutParams.MATCH_PARENT + "")) {
    } else if (height.equals(ViewGroup.LayoutParams.WRAP_CONTENT + "")) {
    } else {
        int[] systemAttrs = { android.R.attr.layout_height };
        TypedArray a = context.obtainStyledAttributes(attrs, systemAttrs);
        mHeight = a.getDimensionPixelSize(0, ViewGroup.LayoutParams.WRAP_CONTENT);
        a.recycle();
    }
}

From source file:de.madvertise.android.sdk.MadView.java

/**
 * Reads all parameters, not needed for a request to the ad server (colors,
 * refresh timeout, ...)/*from   ww w . j  av a 2 s.  co  m*/
 * 
 * @param attrs
 *            attribute set for the view
 */
private void initParameters(AttributeSet attrs) {
    if (attrs != null) {
        String packageName = "http://schemas.android.com/apk/res/" + getContext().getPackageName();
        if (packageName != null) {
            MadUtil.logMessage(null, Log.DEBUG, "namespace = " + packageName);
        }
        testMode = attrs.getAttributeBooleanValue(packageName, "isTestMode", IS_TESTMODE_DEFAULT);
        textColor = attrs.getAttributeIntValue(packageName, "textColor", MadUtil.TEXT_COLOR_DEFAULT);
        backgroundColor = attrs.getAttributeIntValue(packageName, "backgroundColor",
                MadUtil.BACKGROUND_COLOR_DEFAULT);
        secondsToRefreshAd = attrs.getAttributeIntValue(packageName, "secondsToRefresh",
                MadUtil.SECONDS_TO_REFRESH_AD_DEFAULT);
        bannerType = attrs.getAttributeValue(packageName, "bannerType");
        if (bannerType == null)
            bannerType = MadUtil.BANNER_TYPE_DEFAULT;
        deliverOnlyText = attrs.getAttributeBooleanValue(packageName, "deliverOnlyText",
                MadUtil.DELIVER_ONLY_TEXT_DEFAULT);
        textSize = attrs.getAttributeIntValue(packageName, "textSize", MadUtil.TEXT_SIZE_DEFAULT);
    } else {
        MadUtil.logMessage(null, Log.DEBUG, "AttributeSet is null!");
    }

    if (secondsToRefreshAd != 0 && secondsToRefreshAd < 60)
        secondsToRefreshAd = MadUtil.SECONDS_TO_REFRESH_AD_DEFAULT;

    if (bannerType.equals("iab"))
        bannerHeight = MadUtil.IAB_BANNER_HEIGHT_DEFAULT;

    MadUtil.logMessage(null, Log.DEBUG, "Using following attributes values:");
    MadUtil.logMessage(null, Log.DEBUG, " testMode = " + testMode);
    MadUtil.logMessage(null, Log.DEBUG, " textColor = " + textColor);
    MadUtil.logMessage(null, Log.DEBUG, " backgroundColor = " + backgroundColor);
    MadUtil.logMessage(null, Log.DEBUG, " secondsToRefreshAd = " + secondsToRefreshAd);
    MadUtil.logMessage(null, Log.DEBUG, " bannerType = " + bannerType);
    MadUtil.logMessage(null, Log.DEBUG, " deliverOnlyText = " + deliverOnlyText);
    MadUtil.logMessage(null, Log.DEBUG, " textSize = " + textSize);
    MadUtil.logMessage(null, Log.DEBUG, " bannerHeight = " + bannerHeight);
}

From source file:de.madvertise.android.sdk.MadvertiseView.java

/**
 * Reads all parameters, not needed for a request to the ad server (colors,
 * refresh timeout, ...)/* ww w. j a  v  a 2 s  .  c  o  m*/
 *
 * @param attrs attribute set for the view
 */
private void initParameters(final AttributeSet attrs) {
    mDp = getContext().getApplicationContext().getResources().getDisplayMetrics().density;

    if (attrs != null) {
        String packageName = "http://schemas.android.com/apk/res/"
                + getContext().getApplicationContext().getPackageName();
        if (packageName != null) {
            MadvertiseUtil.logMessage(null, Log.DEBUG, "namespace = " + packageName);
        }

        mTestMode = attrs.getAttributeBooleanValue(packageName, "isTestMode", IS_TESTMODE_DEFAULT);

        mTextColor = attrs.getAttributeIntValue(packageName, "textColor", MadvertiseUtil.TEXT_COLOR_DEFAULT);

        mBackgroundColor = attrs.getAttributeIntValue(packageName, "backgroundColor",
                MadvertiseUtil.BACKGROUND_COLOR_DEFAULT);

        mSecondsToRefreshAd = attrs.getAttributeIntValue(packageName, "secondsToRefresh",
                MadvertiseUtil.SECONDS_TO_REFRESH_AD_DEFAULT);

        if (attrs.getAttributeValue(packageName, "bannerType") != null) {
            mBannerType = attrs.getAttributeValue(packageName, "bannerType");
        }

        if (attrs.getAttributeValue(packageName, "animation") != null) {
            mAnimationType = attrs.getAttributeValue(packageName, "animation");
        }

        mDeliverOnlyText = attrs.getAttributeBooleanValue(packageName, "deliverOnlyText",
                MadvertiseUtil.DELIVER_ONLY_TEXT_DEFAULT);

        if (!mBannerType.equals(MadvertiseUtil.BANNER_TYPE_MMA) && mDeliverOnlyText) {
            MadvertiseUtil.logMessage(null, Log.DEBUG,
                    "Only banners in mma-format can show text. Setting deliferOnlyText to false.");
            mDeliverOnlyText = false;
        }

        mTextSize = attrs.getAttributeIntValue(packageName, "textSize", MadvertiseUtil.TEXT_SIZE_DEFAULT);

        if (mTextSize > 20) {
            MadvertiseUtil.logMessage(null, Log.DEBUG, "The text size must be set to 20 at maximum.");
            mTextSize = 20;
        } else if (mTextSize < 10) {
            MadvertiseUtil.logMessage(null, Log.DEBUG, "The text size must be set to 10 at minimum.");
            mTextSize = 10;
        }

        mIsMraid = attrs.getAttributeBooleanValue(packageName, "mraid", true);

        final String placementTypeStr = attrs.getAttributeValue(packageName, "placement_type");
        if (placementTypeStr != null && placementTypeStr.equalsIgnoreCase("inline")) {
            mPlacementType = MadvertiseUtil.PLACEMENT_TYPE_INLINE;
        } else if (placementTypeStr != null && placementTypeStr.equalsIgnoreCase("interstitial")) {
            mPlacementType = MadvertiseUtil.PLACEMENT_TYPE_INTERSTITIAL;
        }
    } else {
        MadvertiseUtil.logMessage(null, Log.DEBUG, "AttributeSet is null. Using default parameters");
    }

    if (mSecondsToRefreshAd != 0 && mSecondsToRefreshAd < 30) {
        mSecondsToRefreshAd = MadvertiseUtil.SECONDS_TO_REFRESH_AD_DEFAULT;
        MadvertiseUtil.logMessage(null, Log.DEBUG, "Refresh intervall must be higher than 60");
    }

    calculateBannerDimensions();

    MadvertiseUtil.logMessage(null, Log.DEBUG, "Using following attributes values:");
    MadvertiseUtil.logMessage(null, Log.DEBUG, " testMode = " + mTestMode);
    MadvertiseUtil.logMessage(null, Log.DEBUG, " textColor = " + mTextColor);
    MadvertiseUtil.logMessage(null, Log.DEBUG, " backgroundColor = " + mBackgroundColor);
    MadvertiseUtil.logMessage(null, Log.DEBUG, " secondsToRefreshAd = " + mSecondsToRefreshAd);
    MadvertiseUtil.logMessage(null, Log.DEBUG, " bannerType = " + mBannerType);
    MadvertiseUtil.logMessage(null, Log.DEBUG, " animationType = " + mAnimationType);
    MadvertiseUtil.logMessage(null, Log.DEBUG, " deliverOnlyText = " + mDeliverOnlyText);
    MadvertiseUtil.logMessage(null, Log.DEBUG, " textSize = " + mTextSize);
    MadvertiseUtil.logMessage(null, Log.DEBUG, " isMraid = " + mIsMraid);
    MadvertiseUtil.logMessage(null, Log.DEBUG, " placementType = " + mPlacementType);
    MadvertiseUtil.logMessage(null, Log.DEBUG, " bannerWidth = " + mBannerWidth);
    MadvertiseUtil.logMessage(null, Log.DEBUG, " bannerHeight = " + mBannerHeight);
    MadvertiseUtil.logMessage(null, Log.DEBUG, " bannerWidthDp = " + mBannerWidthDp);
    MadvertiseUtil.logMessage(null, Log.DEBUG, " bannerHeightDp = " + mBannerHeightDp);
}

From source file:android.app.FragmentManager.java

@Override
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
    if (!"fragment".equals(name)) {
        return null;
    }//from w  w  w.j a  v  a  2s  .c om

    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 ? findFragmentById(id) : null;
    if (fragment == null && tag != null) {
        fragment = findFragmentByTag(tag);
    }
    if (fragment == null && containerId != View.NO_ID) {
        fragment = findFragmentById(containerId);
    }

    if (FragmentManagerImpl.DEBUG)
        Log.v(TAG,
                "onCreateView: id=0x" + Integer.toHexString(id) + " fname=" + fname + " existing=" + fragment);
    if (fragment == null) {
        fragment = Fragment.instantiate(context, fname);
        fragment.mFromLayout = true;
        fragment.mFragmentId = id != 0 ? id : containerId;
        fragment.mContainerId = containerId;
        fragment.mTag = tag;
        fragment.mInLayout = true;
        fragment.mFragmentManager = this;
        fragment.onInflate(mActivity, attrs, fragment.mSavedFragmentState);
        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(mActivity, attrs, fragment.mSavedFragmentState);
        }
    }

    // If we haven't finished entering the CREATED state ourselves yet,
    // push the inflated child fragment along.
    if (mCurState < Fragment.CREATED && fragment.mFromLayout) {
        moveToState(fragment, Fragment.CREATED, 0, 0, false);
    } else {
        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.bvhloc.numpicker.widget.NumberPicker.java

public NumberPicker(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);

    mStart = DEFAULT_START;//from  w  w w . ja  va  2  s  . co m
    mEnd = DEFAULT_END;
    mCurrent = mStart;

    boolean vertical = true;
    int displayedValues = 0;

    if (attrs != null && !isInEditMode()) {
        // this crashes in edit mode (?!)
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.NumberPicker);

        mStart = a.getInt(R.styleable.NumberPicker_rangeStart, DEFAULT_START);
        mEnd = a.getInt(R.styleable.NumberPicker_rangeEnd, DEFAULT_END);
        mSpeed = a.getInt(R.styleable.NumberPicker_speed, (int) mSpeed);
        mSpeedUp = mSpeed;
        mCurrent = a.getInt(R.styleable.NumberPicker_current, mCurrent);

        mNumColor = a.getColor(R.styleable.NumberPicker_numColor,
                ContextCompat.getColor(context, android.R.color.primary_text_light));
        mNumBackground = a.getDrawable(R.styleable.NumberPicker_numBackground);
        mNumSize = a.getDimension(R.styleable.NumberPicker_numSize, mNumSize);
        mNumHorizontalPadding = (int) a.getDimension(R.styleable.NumberPicker_numHorizontalPadding, mNumSize);
        mNumHorizontalPadding = (int) a.getDimension(R.styleable.NumberPicker_numVeticalPadding, mNumSize);
        mIncrementDrawable = a.getDrawable(R.styleable.NumberPicker_incrementDrawable);
        mDecrementDrawable = a.getDrawable(R.styleable.NumberPicker_decrementDrawable);
        mKeyboardInput = a.getBoolean(R.styleable.NumberPicker_keyboardInput, mKeyboardInput);

        String orientation = a.getString(R.styleable.NumberPicker_android_orientation);
        displayedValues = a.getResourceId(R.styleable.NumberPicker_displayedValues, 0);

        if (orientation != null) {
            vertical = !"0".equals(orientation);
        }

        a.recycle();
    } else if (attrs != null && isInEditMode()) {
        // fix orientation attribute for editor
        String orientation = attrs.getAttributeValue("http://schemas.android.com/apk/res/android",
                "orientation");

        if (orientation != null) {
            vertical = !"horizontal".equals(orientation);
        }
    }
    // set a wrong orientation so our own orientation method will perform changes
    super.setOrientation(!vertical ? VERTICAL : HORIZONTAL);
    setOrientation(vertical ? VERTICAL : HORIZONTAL);

    mChangeHandler = new Handler();
    InputFilter inputFilter = new NumberPickerInputFilter();
    mNumberInputFilter = new NumberRangeKeyListener();
    mIncrementButton = (NumberPickerButton) findViewById(R.id.increment);
    mIncrementButton.setOnClickListener(this);
    mIncrementButton.setOnLongClickListener(this);
    mIncrementButton.setNumberPicker(this);
    mDecrementButton = (NumberPickerButton) findViewById(R.id.decrement);
    mDecrementButton.setOnClickListener(this);
    mDecrementButton.setOnLongClickListener(this);
    mDecrementButton.setNumberPicker(this);

    mIncrementButton.setBackground(null);
    mDecrementButton.setBackground(null);
    mIncrementButton.setScaleType(ImageView.ScaleType.FIT_CENTER);
    mDecrementButton.setScaleType(ImageView.ScaleType.FIT_CENTER);

    if (mIncrementDrawable != null) {
        mIncrementButton.setImageDrawable(mIncrementDrawable);
    }
    if (mDecrementDrawable != null) {
        mDecrementButton.setImageDrawable(mDecrementDrawable);
    }

    mText = (EditText) findViewById(R.id.timepicker_input);
    mText.setOnFocusChangeListener(this);
    mText.setFilters(new InputFilter[] { inputFilter });
    mText.setRawInputType(InputType.TYPE_CLASS_NUMBER);
    LayoutParams params = (LayoutParams) mText.getLayoutParams();
    params.weight = 1;
    mText.setLayoutParams(params);

    mText.setPadding(mNumHorizontalPadding, mNumVerticalPadding, mNumHorizontalPadding, mNumVerticalPadding);
    mText.setTextSize(mNumSize);
    if (mNumBackground != null) {
        mText.setBackground(mNumBackground);
    } else {
        mText.setBackground(ContextCompat.getDrawable(context, android.R.drawable.edit_text));
    }
    if (!mKeyboardInput) {
        mText.setEnabled(false);
    }
    mText.setTextColor(mNumColor);

    if (!isEnabled()) {
        setEnabled(false);
    }

    if (displayedValues != 0) {
        setDisplayedRange(mStart, displayedValues);
    } else {
        setRange(mStart, mEnd);
    }
}

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

private static Pair<String, String> parsePackageSplitNames(XmlPullParser parser, AttributeSet attrs, int flags)
        throws IOException, XmlPullParserException, PackageParserException {

    int type;//from  w ww .  ja  v a2  s . c o  m
    while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
    }

    if (type != XmlPullParser.START_TAG) {
        throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, "No start tag found");
    }
    if (!parser.getName().equals("manifest")) {
        throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, "No <manifest> tag");
    }

    final String packageName = attrs.getAttributeValue(null, "package");
    if (!"android".equals(packageName)) {
        final String error = validateName(packageName, true, true);
        if (error != null) {
            throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME,
                    "Invalid manifest package: " + error);
        }
    }

    String splitName = attrs.getAttributeValue(null, "split");
    if (splitName != null) {
        if (splitName.length() == 0) {
            splitName = null;
        } else {
            final String error = validateName(splitName, false, false);
            if (error != null) {
                throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME,
                        "Invalid manifest split: " + error);
            }
        }
    }

    return Pair.create(packageName.intern(), (splitName != null) ? splitName.intern() : splitName);
}

From source file:android.app.Activity.java

/**
 * Standard implementation of/*from   w w w .  j  a  va2s. co m*/
 * {@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:android.content.pm.PackageParser.java

private boolean parseIntent(Resources res, XmlPullParser parser, AttributeSet attrs, boolean allowGlobs,
        boolean allowAutoVerify, IntentInfo outInfo, String[] outError)
        throws XmlPullParserException, IOException {

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

    int priority = sa.getInt(com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
    outInfo.setPriority(priority);/*from www  .  j  a  v a  2  s . co  m*/

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

    outInfo.icon = sa.getResourceId(com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);

    outInfo.logo = sa.getResourceId(com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);

    outInfo.banner = sa.getResourceId(com.android.internal.R.styleable.AndroidManifestIntentFilter_banner, 0);

    if (allowAutoVerify) {
        outInfo.setAutoVerify(
                sa.getBoolean(com.android.internal.R.styleable.AndroidManifestIntentFilter_autoVerify, false));
    }

    sa.recycle();

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

        String nodeName = parser.getName();
        if (nodeName.equals("action")) {
            String value = attrs.getAttributeValue(ANDROID_RESOURCES, "name");
            if (value == null || value == "") {
                outError[0] = "No value supplied for <android:name>";
                return false;
            }
            XmlUtils.skipCurrentTag(parser);

            outInfo.addAction(value);
        } else if (nodeName.equals("category")) {
            String value = attrs.getAttributeValue(ANDROID_RESOURCES, "name");
            if (value == null || value == "") {
                outError[0] = "No value supplied for <android:name>";
                return false;
            }
            XmlUtils.skipCurrentTag(parser);

            outInfo.addCategory(value);

        } else if (nodeName.equals("data")) {
            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestData);

            String str = sa.getNonConfigurationString(
                    com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
            if (str != null) {
                try {
                    outInfo.addDataType(str);
                } catch (IntentFilter.MalformedMimeTypeException e) {
                    outError[0] = e.toString();
                    sa.recycle();
                    return false;
                }
            }

            str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
            if (str != null) {
                outInfo.addDataScheme(str);
            }

            str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_ssp, 0);
            if (str != null) {
                outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_LITERAL);
            }

            str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_sspPrefix,
                    0);
            if (str != null) {
                outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_PREFIX);
            }

            str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_sspPattern,
                    0);
            if (str != null) {
                if (!allowGlobs) {
                    outError[0] = "sspPattern not allowed here; ssp must be literal";
                    return false;
                }
                outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
            }

            String host = sa
                    .getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_host, 0);
            String port = sa
                    .getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_port, 0);
            if (host != null) {
                outInfo.addDataAuthority(host, port);
            }

            str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_path, 0);
            if (str != null) {
                outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
            }

            str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_pathPrefix,
                    0);
            if (str != null) {
                outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
            }

            str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_pathPattern,
                    0);
            if (str != null) {
                if (!allowGlobs) {
                    outError[0] = "pathPattern not allowed here; path must be literal";
                    return false;
                }
                outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
            }

            sa.recycle();
            XmlUtils.skipCurrentTag(parser);
        } else if (!RIGID_PARSER) {
            Slog.w(TAG, "Unknown element under <intent-filter>: " + parser.getName() + " at "
                    + mArchiveSourcePath + " " + parser.getPositionDescription());
            XmlUtils.skipCurrentTag(parser);
        } else {
            outError[0] = "Bad element under <intent-filter>: " + parser.getName();
            return false;
        }
    }

    outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);

    if (DEBUG_PARSER) {
        final StringBuilder cats = new StringBuilder("Intent d=");
        cats.append(outInfo.hasDefault);
        cats.append(", cat=");

        final Iterator<String> it = outInfo.categoriesIterator();
        if (it != null) {
            while (it.hasNext()) {
                cats.append(' ');
                cats.append(it.next());
            }
        }
        Slog.d(TAG, cats.toString());
    }

    return true;
}