Code example for TypedArray

Methods: getBoolean, getDimensionPixelSize, getDrawable, getInt, getInteger, getResourceId, recycle

0
        TypedArray a =
            context.obtainStyledAttributes(attrs, /*R.styleable.*/ProgressBar, defStyle, styleRes);
 
        mNoInvalidate = true;
 
        Drawable drawable = a.getDrawable(/*R.styleable.*/ProgressBar_progressDrawable);
        if (drawable != null) {
            drawable = tileify(drawable, false);
            // Calling this method can set mMaxHeight, make sure the corresponding 
            // XML attribute for mMaxHeight is read after calling this method 
            setProgressDrawable(drawable);
        } 
 
 
        mDuration = a.getInt(/*R.styleable.*/ProgressBar_indeterminateDuration, mDuration);
 
        mMinWidth = a.getDimensionPixelSize(/*R.styleable.*/ProgressBar_minWidth, mMinWidth);
        mMaxWidth = a.getDimensionPixelSize(/*R.styleable.*/ProgressBar_maxWidth, mMaxWidth);
        mMinHeight = a.getDimensionPixelSize(/*R.styleable.*/ProgressBar_minHeight, mMinHeight);
        mMaxHeight = a.getDimensionPixelSize(/*R.styleable.*/ProgressBar_maxHeight, mMaxHeight);
 
        mBehavior = a.getInt(/*R.styleable.*/ProgressBar_indeterminateBehavior, mBehavior);
 
        final int resID = a.getResourceId(
                /*com.android.internal.R.styleable.*/ProgressBar_interpolator,
                android.R.anim.linear_interpolator); // default to linear interpolator
        if (resID > 0) {
            setInterpolator(context, resID);
        } 
 
        setMax(a.getInt(/*R.styleable.*/ProgressBar_max, mMax));
 
        setProgress(a.getInt(/*R.styleable.*/ProgressBar_progress, mProgress));
 
        setSecondaryProgress( 
                a.getInt(/*R.styleable.*/ProgressBar_secondaryProgress, mSecondaryProgress));
 
        drawable = a.getDrawable(/*R.styleable.*/ProgressBar_indeterminateDrawable);
        if (drawable != null) {
            drawable = tileifyIndeterminate(drawable);
            setIndeterminateDrawable(drawable);
        } 
 
        mOnlyIndeterminate = a.getBoolean(
                /*R.styleable.*/ProgressBar_indeterminateOnly, mOnlyIndeterminate);
 
        mNoInvalidate = false;
 
        setIndeterminate(mOnlyIndeterminate || a.getBoolean(
                /*R.styleable.*/ProgressBar_indeterminate, mIndeterminate));
 
        mAnimationResolution = a.getInteger(/*R.styleable.*/ProgressBar_animationResolution,
                ANIMATION_RESOLUTION);
 
        a.recycle();
 
        mAccessibilityManager = (AccessibilityManager)context.getSystemService(Context.ACCESSIBILITY_SERVICE);
    } 
 
    /**