Example usage for android.content.res TypedArray getInt

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

Introduction

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

Prototype

public int getInt(@StyleableRes int index, int defValue) 

Source Link

Document

Retrieve the integer value for the attribute at index.

Usage

From source file:com.cocoa.cocoautils.widget.navigationtabbar.ntb.NavigationTabBar.java

@SuppressWarnings("ResourceAsColor")
public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTB/*from  w w  w .  j  a v  a  2 s.c o  m*/

    // Always draw
    setWillNotDraw(false);
    // Speed and fix for pre 17 API
    ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null);
    setLayerType(LAYER_TYPE_SOFTWARE, null);

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabBar);
    try {
        setIsTitled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_titled, false));
        setIsBadged(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badged, false));
        setIsScaled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_scaled, true));
        setIsTinted(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_tinted, true));
        setIsSwiped(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_swiped, true));
        setTitleSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_title_size, -2f));
        setIsBadgeUseTypeface(
                typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badge_use_typeface, false));

        setTitleMode(typedArray.getInt(R.styleable.NavigationTabBar_ntb_title_mode, TitleMode.ALL_INDEX));
        setBadgeSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_badge_size, -2f));
        setBadgePosition(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_position, BadgePosition.RIGHT_INDEX));
        setBadgeGravity(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_gravity, BadgeGravity.TOP_INDEX));
        setBadgeBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_bg_color, AUTO_COLOR));
        setBadgeTitleColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_title_color, AUTO_COLOR));

        setTypeface(typedArray.getString(R.styleable.NavigationTabBar_ntb_typeface));
        setInactiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_inactive_color, DEFAULT_INACTIVE_COLOR));
        setActiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_active_color, DEFAULT_ACTIVE_COLOR));
        setBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_bg_color, DEFAULT_BG_COLOR));
        setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabBar_ntb_animation_duration,
                DEFAULT_ANIMATION_DURATION));
        setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_corners_radius, 0.0F));
        setIconSizeFraction(
                typedArray.getFloat(R.styleable.NavigationTabBar_ntb_icon_size_fraction, AUTO_SCALE));

        // Init animator
        mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION);
        mAnimator.setInterpolator(new LinearInterpolator());
        mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(final ValueAnimator animation) {
                updateIndicatorPosition((Float) animation.getAnimatedValue());
            }
        });

        // Set preview models
        if (isInEditMode()) {
            // Get preview colors
            String[] previewColors = null;
            try {
                final int previewColorsId = typedArray
                        .getResourceId(R.styleable.NavigationTabBar_ntb_preview_colors, 0);
                previewColors = previewColorsId == 0 ? null
                        : typedArray.getResources().getStringArray(previewColorsId);
            } catch (Exception exception) {
                previewColors = null;
                exception.printStackTrace();
            } finally {
                if (previewColors == null)
                    previewColors = typedArray.getResources().getStringArray(R.array.default_preview);

                for (String previewColor : previewColors)
                    mModels.add(new Model.Builder(null, Color.parseColor(previewColor)).build());
                requestLayout();
            }
        }
    } finally {
        typedArray.recycle();
    }
}

From source file:cn.oddcloud.www.navigationtabbar.ntb.NavigationTabBar.java

@SuppressWarnings("ResourceAsColor")
public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTB//from ww  w  .  ja v  a  2s .co m

    // Always draw
    setWillNotDraw(false);
    // Speed and fix for pre 17 API
    ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null);
    setLayerType(LAYER_TYPE_SOFTWARE, null);

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabBar);
    try {
        setIsTitled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_titled, false));
        setIsBadged(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badged, false));
        setIsScaled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_scaled, true));
        setIsTinted(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_tinted, true));
        setIsSwiped(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_swiped, true));
        setTitleSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_title_size, AUTO_SIZE));
        setIsBadgeUseTypeface(
                typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badge_use_typeface, false));

        setTitleMode(typedArray.getInt(R.styleable.NavigationTabBar_ntb_title_mode, TitleMode.ALL_INDEX));
        setBadgeSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_badge_size, AUTO_SIZE));
        setBadgePosition(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_position, BadgePosition.RIGHT_INDEX));
        setBadgeGravity(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_gravity, BadgeGravity.TOP_INDEX));
        setBadgeBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_bg_color, AUTO_COLOR));
        setBadgeTitleColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_title_color, AUTO_COLOR));

        setTypeface(typedArray.getString(R.styleable.NavigationTabBar_ntb_typeface));
        setInactiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_inactive_color, DEFAULT_INACTIVE_COLOR));
        setActiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_active_color, DEFAULT_ACTIVE_COLOR));
        setBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_bg_color, DEFAULT_BG_COLOR));
        setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabBar_ntb_animation_duration,
                DEFAULT_ANIMATION_DURATION));
        setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_corners_radius, 0.0F));
        setIconSizeFraction(
                typedArray.getFloat(R.styleable.NavigationTabBar_ntb_icon_size_fraction, AUTO_SCALE));

        // Init animator
        mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION);
        mAnimator.setInterpolator(new LinearInterpolator());
        mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(final ValueAnimator animation) {
                updateIndicatorPosition((Float) animation.getAnimatedValue());
            }
        });

        // Set preview models
        if (isInEditMode()) {
            // Get preview colors
            String[] previewColors = null;
            try {
                final int previewColorsId = typedArray
                        .getResourceId(R.styleable.NavigationTabBar_ntb_preview_colors, 0);
                previewColors = previewColorsId == 0 ? null
                        : typedArray.getResources().getStringArray(previewColorsId);
            } catch (Exception exception) {
                previewColors = null;
                exception.printStackTrace();
            } finally {
                if (previewColors == null)
                    previewColors = typedArray.getResources().getStringArray(R.array.default_preview);

                for (String previewColor : previewColors)
                    mModels.add(new Model.Builder(null, Color.parseColor(previewColor)).build());
                requestLayout();
            }
        }
    } finally {
        typedArray.recycle();
    }
}

From source file:com.spectrum.widget.materialloadingprogressbar.CircleProgressBar.java

private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleProgressBar, defStyleAttr, 0);
    // <attr name="mlpb_inner_radius" format="dimension"/>
    // <attr name="mlpb_background_color" format="color"/>
    // <attr name="mlpb_progress_color" format="color"/>
    // <attr name="mlpb_progress_stoke_width" format="dimension"/>
    // <attr name="mlpb_arrow_width" format="dimension"/>
    // <attr name="mlpb_arrow_height" format="dimension"/>
    ///*from   w ww.ja va2  s  .  c  o  m*/
    // <attr name="mlpb_progress" format="integer"/>
    // <attr name="mlpb_max" format="integer"/>
    //
    //
    // <attr name="mlpb_progress_text_size" format="dimension"/>
    // <attr name="mlpb_progress_text_color" format="color"/>
    //
    // <attr name="mlpb_progress_text_offset" format="dimension"/>
    //
    // <attr name="mlpb_progress_text_visibility" format="enum">
    // <enum name="visible" value="0"/>
    // <enum name="invisible" value="1"/>
    // </attr>
    final float density = getContext().getResources().getDisplayMetrics().density;

    mBackGroundColor = a.getColor(R.styleable.CircleProgressBar_mlpb_background_color, DEFAULT_CIRCLE_BG_LIGHT);

    mProgressColor = a.getColor(R.styleable.CircleProgressBar_mlpb_progress_color, DEFAULT_CIRCLE_BG_LIGHT);
    mColors = new int[] { mProgressColor };

    mInnerRadius = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_inner_radius, -1);

    mProgressStokeWidth = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_progress_stoke_width,
            (int) (STROKE_WIDTH_LARGE * density));
    mArrowWidth = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_arrow_width, -1);
    mArrowHeight = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_arrow_height, -1);
    mTextSize = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_progress_text_size,
            (int) (DEFAULT_TEXT_SIZE * density));
    mTextColor = a.getColor(R.styleable.CircleProgressBar_mlpb_progress_text_color, Color.BLACK);

    mShowArrow = a.getBoolean(R.styleable.CircleProgressBar_mlpb_show_arrow, false);
    mCircleBackgroundEnabled = a.getBoolean(R.styleable.CircleProgressBar_mlpb_enable_circle_background, true);

    mProgress = a.getInt(R.styleable.CircleProgressBar_mlpb_progress, 0);
    mMax = a.getInt(R.styleable.CircleProgressBar_mlpb_max, 100);
    int textVisible = a.getInt(R.styleable.CircleProgressBar_mlpb_progress_text_visibility, 1);
    if (textVisible != 1) {
        mIfDrawText = true;
    }

    mTextPaint = new Paint();
    mTextPaint.setStyle(Paint.Style.FILL);
    mTextPaint.setColor(mTextColor);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setAntiAlias(true);
    a.recycle();
    mProgressDrawable = new MaterialProgressDrawable(getContext(), this);
    super.setImageDrawable(mProgressDrawable);
}

From source file:com.commonsware.cwac.crossport.design.widget.TextInputLayout.java

public TextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    // Can't call through to super(Context, AttributeSet, int) since it doesn't exist on API 10
    super(context, attrs);

    // ThemeUtils.checkAppCompatTheme(context);

    setOrientation(VERTICAL);//from w  w w  . ja  va 2s  .  c om
    setWillNotDraw(false);
    setAddStatesFromChildren(true);

    mInputFrame = new FrameLayout(context);
    mInputFrame.setAddStatesFromChildren(true);
    addView(mInputFrame);

    mCollapsingTextHelper.setTextSizeInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
    mCollapsingTextHelper.setPositionInterpolator(new AccelerateInterpolator());
    mCollapsingTextHelper.setCollapsedTextGravity(Gravity.TOP | GravityCompat.START);

    mHintExpanded = mCollapsingTextHelper.getExpansionFraction() == 1f;

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TextInputLayout, defStyleAttr,
            R.style.Widget_Design_TextInputLayout);
    mHintEnabled = a.getBoolean(R.styleable.TextInputLayout_hintEnabled, true);
    setHint(a.getText(R.styleable.TextInputLayout_android_hint));
    mHintAnimationEnabled = a.getBoolean(R.styleable.TextInputLayout_hintAnimationEnabled, true);

    if (a.hasValue(R.styleable.TextInputLayout_android_textColorHint)) {
        mDefaultTextColor = mFocusedTextColor = a
                .getColorStateList(R.styleable.TextInputLayout_android_textColorHint);
    }

    final int hintAppearance = a.getResourceId(R.styleable.TextInputLayout_hintTextAppearance, -1);
    if (hintAppearance != -1) {
        setHintTextAppearance(a.getResourceId(R.styleable.TextInputLayout_hintTextAppearance, 0));
    }

    mErrorTextAppearance = a.getResourceId(R.styleable.TextInputLayout_errorTextAppearance, 0);
    final boolean errorEnabled = a.getBoolean(R.styleable.TextInputLayout_errorEnabled, false);

    final boolean counterEnabled = a.getBoolean(R.styleable.TextInputLayout_counterEnabled, false);
    setCounterMaxLength(a.getInt(R.styleable.TextInputLayout_counterMaxLength, INVALID_MAX_LENGTH));
    mCounterTextAppearance = a.getResourceId(R.styleable.TextInputLayout_counterTextAppearance, 0);
    mCounterOverflowTextAppearance = a.getResourceId(R.styleable.TextInputLayout_counterOverflowTextAppearance,
            0);

    mPasswordToggleEnabled = a.getBoolean(R.styleable.TextInputLayout_passwordToggleEnabled, false);
    mPasswordToggleDrawable = a.getDrawable(R.styleable.TextInputLayout_passwordToggleDrawable);
    mPasswordToggleContentDesc = a.getText(R.styleable.TextInputLayout_passwordToggleContentDescription);
    if (a.hasValue(R.styleable.TextInputLayout_passwordToggleTint)) {
        mHasPasswordToggleTintList = true;
        mPasswordToggleTintList = a.getColorStateList(R.styleable.TextInputLayout_passwordToggleTint);
    }
    if (a.hasValue(R.styleable.TextInputLayout_passwordToggleTintMode)) {
        mHasPasswordToggleTintMode = true;
        mPasswordToggleTintMode = ViewUtils
                .parseTintMode(a.getInt(R.styleable.TextInputLayout_passwordToggleTintMode, -1), null);
    }

    a.recycle();

    setErrorEnabled(errorEnabled);
    setCounterEnabled(counterEnabled);
    applyPasswordToggleTint();

    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        // Make sure we're important for accessibility if we haven't been explicitly not
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }

    ViewCompat.setAccessibilityDelegate(this, new TextInputAccessibilityDelegate());
}

From source file:com.android.demos.module.animation.materialloadingprogressbar.CircleProgressBar.java

private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleProgressBar, defStyleAttr, 0);
    //        <attr name="mlpb_inner_radius" format="dimension"/>
    //        <attr name="mlpb_background_color" format="color"/>
    //        <attr name="mlpb_progress_color" format="color"/>
    //        <attr name="mlpb_progress_stoke_width" format="dimension"/>
    //        <attr name="mlpb_arrow_width" format="dimension"/>
    //        <attr name="mlpb_arrow_height" format="dimension"/>
    ////from w ww.  j a v  a2  s . com
    //        <attr name="mlpb_progress" format="integer"/>
    //        <attr name="mlpb_max" format="integer"/>
    //
    //
    //        <attr name="mlpb_progress_text_size" format="dimension"/>
    //        <attr name="mlpb_progress_text_color" format="color"/>
    //
    //        <attr name="mlpb_progress_text_offset" format="dimension"/>
    //
    //        <attr name="mlpb_progress_text_visibility" format="enum">
    //        <enum name="visible" value="0"/>
    //        <enum name="invisible" value="1"/>
    //        </attr>
    final float density = getContext().getResources().getDisplayMetrics().density;

    mBackGroundColor = a.getColor(R.styleable.CircleProgressBar_mlpb_background_color, DEFAULT_CIRCLE_BG_LIGHT);

    mProgressColor = a.getColor(R.styleable.CircleProgressBar_mlpb_progress_color, DEFAULT_CIRCLE_BG_LIGHT);//ToDO 

    mInnerRadius = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_inner_radius, -1);

    mProgressStokeWidth = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_progress_stoke_width,
            (int) (STROKE_WIDTH_LARGE * density));
    mArrowWidth = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_arrow_width, -1);
    mArrowHeight = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_arrow_height, -1);
    mTextSize = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_progress_text_size,
            (int) (DEFAULT_TEXT_SIZE * density));
    mTextColor = a.getColor(R.styleable.CircleProgressBar_mlpb_progress_text_color, Color.BLACK);

    mShowArrow = a.getBoolean(R.styleable.CircleProgressBar_mlpb_show_arrow, false);
    mCircleBackgroundEnabled = a.getBoolean(R.styleable.CircleProgressBar_mlpb_enable_circle_background, true);

    mProgress = a.getInt(R.styleable.CircleProgressBar_mlpb_progress, 0);
    mMax = a.getInt(R.styleable.CircleProgressBar_mlpb_max, 100);
    int textVisible = a.getInt(R.styleable.CircleProgressBar_mlpb_progress_text_visibility, 1);
    if (textVisible != 1) {
        mIfDrawText = true;
    }

    mTextPaint = new Paint();
    mTextPaint.setStyle(Paint.Style.FILL);
    mTextPaint.setColor(mTextColor);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setAntiAlias(true);
    a.recycle();
    mProgressDrawable = new MaterialProgressDrawable(getContext(), this);
    super.setImageDrawable(mProgressDrawable);
}

From source file:com.cxsplay.wallyskim.widget.flexbox.FlexboxLayout.java

public FlexboxLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FlexboxLayout, defStyleAttr, 0);
    mFlexDirection = a.getInt(R.styleable.FlexboxLayout_flexDirection, FLEX_DIRECTION_ROW);
    mFlexWrap = a.getInt(R.styleable.FlexboxLayout_flexWrap, FLEX_WRAP_NOWRAP);
    mJustifyContent = a.getInt(R.styleable.FlexboxLayout_justifyContent, JUSTIFY_CONTENT_FLEX_START);
    mAlignItems = a.getInt(R.styleable.FlexboxLayout_alignItems, ALIGN_ITEMS_STRETCH);
    mAlignContent = a.getInt(R.styleable.FlexboxLayout_alignContent, ALIGN_CONTENT_STRETCH);
    Drawable drawable = a.getDrawable(R.styleable.FlexboxLayout_dividerDrawable);
    if (drawable != null) {
        setDividerDrawableHorizontal(drawable);
        setDividerDrawableVertical(drawable);
    }//from   w  ww.  j  a va2  s.c  om
    Drawable drawableHorizontal = a.getDrawable(R.styleable.FlexboxLayout_dividerDrawableHorizontal);
    if (drawableHorizontal != null) {
        setDividerDrawableHorizontal(drawableHorizontal);
    }
    Drawable drawableVertical = a.getDrawable(R.styleable.FlexboxLayout_dividerDrawableVertical);
    if (drawableVertical != null) {
        setDividerDrawableVertical(drawableVertical);
    }
    int dividerMode = a.getInt(R.styleable.FlexboxLayout_showDivider, SHOW_DIVIDER_NONE);
    if (dividerMode != SHOW_DIVIDER_NONE) {
        mShowDividerVertical = dividerMode;
        mShowDividerHorizontal = dividerMode;
    }
    int dividerModeVertical = a.getInt(R.styleable.FlexboxLayout_showDividerVertical, SHOW_DIVIDER_NONE);
    if (dividerModeVertical != SHOW_DIVIDER_NONE) {
        mShowDividerVertical = dividerModeVertical;
    }
    int dividerModeHorizontal = a.getInt(R.styleable.FlexboxLayout_showDividerHorizontal, SHOW_DIVIDER_NONE);
    if (dividerModeHorizontal != SHOW_DIVIDER_NONE) {
        mShowDividerHorizontal = dividerModeHorizontal;
    }
    a.recycle();
}

From source file:com.aspsine.swipetoloadlayout.widget.CircleProgressBar.java

private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleProgressBar, defStyleAttr, 0);
    //        <attr name="mlpb_inner_radius" format="dimension"/>
    //        <attr name="mlpb_background_color" format="color"/>
    //        <attr name="mlpb_progress_color" format="color"/>
    //        <attr name="mlpb_progress_stoke_width" format="dimension"/>
    //        <attr name="mlpb_arrow_width" format="dimension"/>
    //        <attr name="mlpb_arrow_height" format="dimension"/>
    ///*from ww w .ja v a  2s  . c  om*/
    //        <attr name="mlpb_progress" format="integer"/>
    //        <attr name="mlpb_max" format="integer"/>
    //
    //
    //        <attr name="mlpb_progress_text_size" format="dimension"/>
    //        <attr name="mlpb_progress_text_color" format="color"/>
    //
    //        <attr name="mlpb_progress_text_offset" format="dimension"/>
    //
    //        <attr name="mlpb_progress_text_visibility" format="enum">
    //        <enum name="visible" value="0"/>
    //        <enum name="invisible" value="1"/>
    //        </attr>
    final float density = getContext().getResources().getDisplayMetrics().density;

    mBackGroundColor = a.getColor(R.styleable.CircleProgressBar_mlpb_background_color, DEFAULT_CIRCLE_BG_LIGHT);

    mProgressColor = a.getColor(R.styleable.CircleProgressBar_mlpb_progress_color, DEFAULT_CIRCLE_BG_LIGHT);
    mColors = new int[] { mProgressColor };

    mInnerRadius = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_inner_radius, -1);

    mProgressStokeWidth = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_progress_stoke_width,
            (int) (STROKE_WIDTH_LARGE * density));
    mArrowWidth = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_arrow_width, -1);
    mArrowHeight = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_arrow_height, -1);
    mTextSize = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_progress_text_size,
            (int) (DEFAULT_TEXT_SIZE * density));
    mTextColor = a.getColor(R.styleable.CircleProgressBar_mlpb_progress_text_color, Color.BLACK);

    mShowArrow = a.getBoolean(R.styleable.CircleProgressBar_mlpb_show_arrow, false);
    mCircleBackgroundEnabled = a.getBoolean(R.styleable.CircleProgressBar_mlpb_enable_circle_background, true);

    mProgress = a.getInt(R.styleable.CircleProgressBar_mlpb_progress, 0);
    mMax = a.getInt(R.styleable.CircleProgressBar_mlpb_max, 100);
    int textVisible = a.getInt(R.styleable.CircleProgressBar_mlpb_progress_text_visibility, 1);
    if (textVisible != 1) {
        mIfDrawText = true;
    }

    mTextPaint = new Paint();
    mTextPaint.setStyle(Paint.Style.FILL);
    mTextPaint.setColor(mTextColor);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setAntiAlias(true);
    a.recycle();
    mProgressDrawable = new MaterialProgressDrawable(getContext(), this);
    super.setImageDrawable(mProgressDrawable);
}

From source file:com.msport.clientmaster.view.CircleProgressBar.java

private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleProgressBar, defStyleAttr, 0);
    //        <attr name="mlpb_inner_radius" format="dimension"/>
    //        <attr name="mlpb_background_color" format="color"/>
    //        <attr name="mlpb_progress_color" format="color"/>
    //        <attr name="mlpb_progress_stoke_width" format="dimension"/>
    //        <attr name="mlpb_arrow_width" format="dimension"/>
    //        <attr name="mlpb_arrow_height" format="dimension"/>
    ////from  w w w  .j  a v  a2 s  .  c  om
    //        <attr name="mlpb_progress" format="integer"/>
    //        <attr name="mlpb_max" format="integer"/>
    //
    //
    //        <attr name="mlpb_progress_text_size" format="dimension"/>
    //        <attr name="mlpb_progress_text_color" format="color"/>
    //
    //        <attr name="mlpb_progress_text_offset" format="dimension"/>
    //
    //        <attr name="mlpb_progress_text_visibility" format="enum">
    //        <enum name="visible" value="0"/>
    //        <enum name="invisible" value="1"/>
    //        </attr>
    final float density = getContext().getResources().getDisplayMetrics().density;
    this.context = context;
    mBackGroundColor = a.getColor(R.styleable.CircleProgressBar_mlpb_background_color, DEFAULT_CIRCLE_BG_LIGHT);

    mProgressColor = a.getColor(R.styleable.CircleProgressBar_mlpb_progress_color, DEFAULT_CIRCLE_BG_LIGHT);
    mColors = new int[] { mProgressColor };

    mInnerRadius = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_inner_radius, -1);

    mProgressStokeWidth = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_progress_stoke_width,
            (int) (STROKE_WIDTH_LARGE * density));
    mArrowWidth = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_arrow_width, -1);
    mArrowHeight = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_arrow_height, -1);
    mTextSize = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_progress_text_size,
            (int) (DEFAULT_TEXT_SIZE * density));
    mTextColor = a.getColor(R.styleable.CircleProgressBar_mlpb_progress_text_color, Color.BLACK);

    mShowArrow = a.getBoolean(R.styleable.CircleProgressBar_mlpb_show_arrow, false);
    mCircleBackgroundEnabled = a.getBoolean(R.styleable.CircleProgressBar_mlpb_enable_circle_background, true);

    mProgress = a.getInt(R.styleable.CircleProgressBar_mlpb_progress, 0);
    mMax = a.getInt(R.styleable.CircleProgressBar_mlpb_max, 100);
    int textVisible = a.getInt(R.styleable.CircleProgressBar_mlpb_progress_text_visibility, 1);
    if (textVisible != 1) {
        mIfDrawText = true;
    }

    mTextPaint = new Paint();
    mTextPaint.setStyle(Paint.Style.FILL);
    mTextPaint.setColor(mTextColor);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setAntiAlias(true);
    a.recycle();
    mProgressDrawable = new MaterialProgressDrawable(getContext(), this);
    super.setImageDrawable(mProgressDrawable);
}

From source file:com.albedinsky.android.support.ui.widget.BaseProgressBar.java

/**
 * Creates a new instance of BaseProgressBar within the given <var>context</var>.
 *
 * @param context      Context in which will be this view presented.
 * @param attrs        Set of Xml attributes used to configure the new instance of this view.
 * @param defStyleAttr An attribute which contains a reference to a default style resource for
 *                     this view within a theme of the given context.
 *///  ww  w. j a va2 s  .com
public BaseProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    this.mResources = context.getResources();
    this.mUiThreadId = Thread.currentThread().getId();

    onAttachDrawable();
    if (mDrawable == null) {
        throw new IllegalArgumentException("No progress drawable has been attached.");
    }

    /**
     * Process attributes.
     */
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_Widget_ProgressBar,
            defStyleAttr, 0);
    if (typedArray != null) {
        this.processTintValues(context, typedArray);

        final int n = typedArray.getIndexCount();
        for (int i = 0; i < n; i++) {
            final int index = typedArray.getIndex(i);
            if (index == R.styleable.Ui_Widget_ProgressBar_uiColorProgress) {
                mDrawable.setColor(typedArray.getColor(index, mDrawable.getColor()));
            } else if (index == R.styleable.Ui_Widget_ProgressBar_uiColorsProgress) {
                final int colorsResId = typedArray.getResourceId(index, -1);
                if (colorsResId > 0) {
                    mDrawable.setColors(mResources.getIntArray(colorsResId));
                }
            } else if (index == R.styleable.Ui_Widget_ProgressBar_uiMultiColored) {
                mDrawable.setMultiColored(typedArray.getBoolean(index, mDrawable.isMultiColored()));
            } else if (index == R.styleable.Ui_Widget_ProgressBar_uiColorProgressBackground) {
                mDrawable.setBackgroundColor(typedArray.getInt(index, Color.TRANSPARENT));
            } else if (index == R.styleable.Ui_Widget_ProgressBar_android_thickness) {
                mDrawable.setThickness(typedArray.getDimensionPixelSize(index, 0));
            } else if (index == R.styleable.Ui_Widget_ProgressBar_uiRounded) {
                mDrawable.setRounded(typedArray.getBoolean(index, false));
            } else if (index == R.styleable.Ui_Widget_ProgressBar_uiIndeterminateSpeed) {
                mDrawable.setIndeterminateSpeed(typedArray.getFloat(index, 1));
            }
        }
    }

    this.applyProgressTint();
    this.applyIndeterminateTint();
    this.applyProgressBackgroundTint();
}

From source file:com.demo.wpq.mydemo.customview.progressbar.QLKCircleProgressBar.java

private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.QLKCircleProgressBar, defStyleAttr,
            0);//from  w  w  w .ja  v  a 2  s . com
    //        <attr name="mlpb_inner_radius" format="dimension"/>
    //        <attr name="mlpb_background_color" format="color"/>
    //        <attr name="mlpb_progress_color" format="color"/>
    //        <attr name="mlpb_progress_stoke_width" format="dimension"/>
    //        <attr name="mlpb_arrow_width" format="dimension"/>
    //        <attr name="mlpb_arrow_height" format="dimension"/>
    //
    //        <attr name="mlpb_progress" format="integer"/>
    //        <attr name="mlpb_max" format="integer"/>
    //
    //
    //        <attr name="mlpb_progress_text_size" format="dimension"/>
    //        <attr name="mlpb_progress_text_color" format="color"/>
    //
    //        <attr name="mlpb_progress_text_offset" format="dimension"/>
    //
    //        <attr name="mlpb_progress_text_visibility" format="enum">
    //        <enum name="visible" value="0"/>
    //        <enum name="invisible" value="1"/>
    //        </attr>
    final float density = getContext().getResources().getDisplayMetrics().density;

    mBackGroundColor = a.getColor(R.styleable.QLKCircleProgressBar_mlpb_background_color,
            DEFAULT_CIRCLE_BG_LIGHT);

    mProgressColor = a.getColor(R.styleable.QLKCircleProgressBar_mlpb_progress_color, DEFAULT_CIRCLE_BG_LIGHT);
    mColors = new int[] { mProgressColor };

    mInnerRadius = a.getDimensionPixelOffset(R.styleable.QLKCircleProgressBar_mlpb_inner_radius, -1);

    mProgressStokeWidth = a.getDimensionPixelOffset(R.styleable.QLKCircleProgressBar_mlpb_progress_stoke_width,
            (int) (STROKE_WIDTH_LARGE * density));
    mArrowWidth = a.getDimensionPixelOffset(R.styleable.QLKCircleProgressBar_mlpb_arrow_width, -1);
    mArrowHeight = a.getDimensionPixelOffset(R.styleable.QLKCircleProgressBar_mlpb_arrow_height, -1);
    mTextSize = a.getDimensionPixelOffset(R.styleable.QLKCircleProgressBar_mlpb_progress_text_size,
            (int) (DEFAULT_TEXT_SIZE * density));
    mTextColor = a.getColor(R.styleable.QLKCircleProgressBar_mlpb_progress_text_color, Color.BLACK);

    mShowArrow = a.getBoolean(R.styleable.QLKCircleProgressBar_mlpb_show_arrow, false);
    mCircleBackgroundEnabled = a.getBoolean(R.styleable.QLKCircleProgressBar_mlpb_enable_circle_background,
            true);

    mProgress = a.getInt(R.styleable.QLKCircleProgressBar_mlpb_progress, 0);
    mMax = a.getInt(R.styleable.QLKCircleProgressBar_mlpb_max, 100);
    int textVisible = a.getInt(R.styleable.QLKCircleProgressBar_mlpb_progress_text_visibility, 1);
    if (textVisible != 1) {
        mIfDrawText = true;
    }

    mTextPaint = new Paint();
    mTextPaint.setStyle(Paint.Style.FILL);
    mTextPaint.setColor(mTextColor);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setAntiAlias(true);
    a.recycle();
    mProgressDrawable = new QLKCircleProgressDrawable(getContext(), this);
    super.setImageDrawable(mProgressDrawable);
}