Example usage for android.content.res TypedArray getDimensionPixelOffset

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

Introduction

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

Prototype

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

Source Link

Document

Retrieve a dimensional unit attribute at index for use as an offset in raw pixels.

Usage

From source file:jp.co.ipublishing.esnavi.views.MarqueeView.java

/**
 * (XML??)//from ww  w. j  av  a 2s . c o m
 *
 * @param context 
 * @param attrs   XML???
 */
public MarqueeView(Context context, AttributeSet attrs) {
    super(context, attrs);

    initMarqueeView();

    // XML??
    final TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.MarqueeView);

    final String marqueeText = attributes.getString(R.styleable.MarqueeView_marquee_text);
    if (marqueeText != null) {
        setText(marqueeText);
    }

    final int textSize = attributes.getDimensionPixelOffset(R.styleable.MarqueeView_marquee_textSize, 0);
    if (textSize > 0) {
        setTextSize(textSize);
    }

    final int padding = attributes.getDimensionPixelOffset(R.styleable.MarqueeView_marquee_padding, 0);
    if (padding > 0) {
        setPadding(padding, padding, padding, padding);
    }

    setTextColor(attributes.getColor(R.styleable.MarqueeView_marquee_textColor, 0xFFFFFFFF));
    setBackgroundColor(attributes.getColor(R.styleable.MarqueeView_marquee_background, 0xFF000000));
    setRepeatLimit(attributes.getInteger(R.styleable.MarqueeView_marquee_repeatLimit, 1));
    setTextMoveSpeed(attributes.getInteger(R.styleable.MarqueeView_marquee_textMoveSpeed, 5));

    attributes.recycle();
}

From source file:com.lokiy.widget.BannerView.java

public BannerView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.BannerView);
    isShowIndicator = a.getBoolean(R.styleable.BannerView_showIndicator, true);
    mIndicatorId = a.getResourceId(R.styleable.BannerView_indicator, 0);
    isCorner = a.getBoolean(R.styleable.BannerView_corner, false);
    mRectRoundRadius = a.getDimensionPixelOffset(R.styleable.BannerView_cornerRadii, 0);
    mPageMargin = a.getDimensionPixelSize(R.styleable.BannerView_pageMargin, 0);
    int mIndicatorGravity = a.getInt(R.styleable.BannerView_indicator_gravity,
            Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
    a.recycle();//from w  w  w .  j av  a 2 s .c om
    mViewPager = new XViewPager(getContext(), null);
    mViewPager.setPageMargin(mPageMargin);
    setClipChildren(false);
    mAdapter = new BannerAdapter();
    //noinspection deprecation
    mViewPager.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageSelected(int position) {
            position = position % mAdapter.getRealCount();
            if (isShowIndicator) {
                vRadioGroup.check(position);
            }
            if (onPageSelectedListener != null) {
                onPageSelectedListener.onPageSelected(position, mAdapter.mBannerList.get(position));
            }
        }

        @Override
        public void onPageScrollStateChanged(int position) {
        }
    });
    mViewPager.setAdapter(mAdapter);
    addView(mViewPager, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    if (isShowIndicator) {
        vRadioGroup = new RadioGroup(getContext());
        LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        params.gravity = mIndicatorGravity;
        vRadioGroup.setGravity(Gravity.CENTER);
        vRadioGroup.setOrientation(LinearLayout.HORIZONTAL);
        addView(vRadioGroup, params);
    }
}

From source file:android.support.wear.widget.drawer.PageIndicatorView.java

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

    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.PageIndicatorView, defStyleAttr,
            R.style.WsPageIndicatorViewStyle);

    mDotSpacing = a.getDimensionPixelOffset(R.styleable.PageIndicatorView_wsPageIndicatorDotSpacing, 0);
    mDotRadius = a.getDimension(R.styleable.PageIndicatorView_wsPageIndicatorDotRadius, 0);
    mDotRadiusSelected = a.getDimension(R.styleable.PageIndicatorView_wsPageIndicatorDotRadiusSelected, 0);
    mDotColor = a.getColor(R.styleable.PageIndicatorView_wsPageIndicatorDotColor, 0);
    mDotColorSelected = a.getColor(R.styleable.PageIndicatorView_wsPageIndicatorDotColorSelected, 0);
    mDotFadeOutDelay = a.getInt(R.styleable.PageIndicatorView_wsPageIndicatorDotFadeOutDelay, 0);
    mDotFadeOutDuration = a.getInt(R.styleable.PageIndicatorView_wsPageIndicatorDotFadeOutDuration, 0);
    mDotFadeInDuration = a.getInt(R.styleable.PageIndicatorView_wsPageIndicatorDotFadeInDuration, 0);
    mDotFadeWhenIdle = a.getBoolean(R.styleable.PageIndicatorView_wsPageIndicatorDotFadeWhenIdle, false);
    mDotShadowDx = a.getDimension(R.styleable.PageIndicatorView_wsPageIndicatorDotShadowDx, 0);
    mDotShadowDy = a.getDimension(R.styleable.PageIndicatorView_wsPageIndicatorDotShadowDy, 0);
    mDotShadowRadius = a.getDimension(R.styleable.PageIndicatorView_wsPageIndicatorDotShadowRadius, 0);
    mDotShadowColor = a.getColor(R.styleable.PageIndicatorView_wsPageIndicatorDotShadowColor, 0);
    a.recycle();//from w ww . j  av a2 s.  co  m

    mDotPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDotPaint.setColor(mDotColor);
    mDotPaint.setStyle(Style.FILL);

    mDotPaintSelected = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDotPaintSelected.setColor(mDotColorSelected);
    mDotPaintSelected.setStyle(Style.FILL);
    mDotPaintShadow = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDotPaintShadowSelected = new Paint(Paint.ANTI_ALIAS_FLAG);

    mCurrentViewPagerState = ViewPager.SCROLL_STATE_IDLE;
    if (isInEditMode()) {
        // When displayed in layout preview:
        // Simulate 5 positions, currently on the 3rd position.
        mNumberOfPositions = 5;
        mSelectedPosition = 2;
        mDotFadeWhenIdle = false;
    }

    if (mDotFadeWhenIdle) {
        mVisible = false;
        animate().alpha(0f).setStartDelay(2000).setDuration(mDotFadeOutDuration).start();
    } else {
        animate().cancel();
        setAlpha(1.0f);
    }
    updateShadows();
}

From source file:com.dkstudio.icorrect.practice.speaking.ui.custom.MaterialProgressBar.java

private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MaterialProgressBar, defStyleAttr,
            0);//from  w ww .j av a 2 s .c o m

    final float density = getContext().getResources().getDisplayMetrics().density;

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

    mProgressColor = a.getColor(R.styleable.MaterialProgressBar_progress_color, DEFAULT_CIRCLE_BG_LIGHT);

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

    mProgressStokeWidth = a.getDimensionPixelOffset(R.styleable.MaterialProgressBar_progress_stoke_width,
            (int) (STROKE_WIDTH_LARGE * density));
    mArrowWidth = a.getDimensionPixelOffset(R.styleable.MaterialProgressBar_arrow_width, -1);
    mArrowHeight = a.getDimensionPixelOffset(R.styleable.MaterialProgressBar_arrow_height, -1);
    mTextSize = a.getDimensionPixelOffset(R.styleable.MaterialProgressBar_progress_text_size,
            (int) (DEFAULT_TEXT_SIZE * density));
    mTextColor = a.getColor(R.styleable.MaterialProgressBar_progress_text_color, Color.BLACK);

    mShowArrow = a.getBoolean(R.styleable.MaterialProgressBar_show_arrow, false);
    mCircleBackgroundEnabled = a.getBoolean(R.styleable.MaterialProgressBar_enable_circle_background, true);

    mProgress = a.getInt(R.styleable.MaterialProgressBar_progress, 0);
    mMax = a.getInt(R.styleable.MaterialProgressBar_max, 100);
    int textVisible = a.getInt(R.styleable.MaterialProgressBar_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.uaeemployee.Utils.MaterialProgressBar.java

private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MaterialProgressBar, defStyleAttr,
            0);//from w  w w . ja v  a2 s .com

    final float density = getContext().getResources().getDisplayMetrics().density;

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

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

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

    mProgressStokeWidth = a.getDimensionPixelOffset(R.styleable.MaterialProgressBar_progress_stoke_width,
            (int) (STROKE_WIDTH_LARGE * density));
    mArrowWidth = a.getDimensionPixelOffset(R.styleable.MaterialProgressBar_arrow_width, -1);
    mArrowHeight = a.getDimensionPixelOffset(R.styleable.MaterialProgressBar_arrow_height, -1);
    mTextSize = a.getDimensionPixelOffset(R.styleable.MaterialProgressBar_progress_text_size,
            (int) (DEFAULT_TEXT_SIZE * density));
    mTextColor = a.getColor(R.styleable.MaterialProgressBar_progress_text_color, Color.BLACK);

    mShowArrow = a.getBoolean(R.styleable.MaterialProgressBar_show_arrow, false);
    mCircleBackgroundEnabled = a.getBoolean(R.styleable.MaterialProgressBar_enable_circle_background, true);

    mProgress = a.getInt(R.styleable.MaterialProgressBar_progress, 0);
    mMax = a.getInt(R.styleable.MaterialProgressBar_max, 100);
    int textVisible = a.getInt(R.styleable.MaterialProgressBar_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.example.abner.dynamicfragment.view.CustomSlidingTabLayout.java

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

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);
    // Make sure that the Tab Strips fills this View
    setFillViewport(true);//from www.java  2 s. c  o m

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CustomSlidingTabLayout, 0, 0);

    setShouldExpand(ta.getBoolean(R.styleable.CustomSlidingTabLayout_shouldExpand, false));

    dTextColor = ta.getColor(R.styleable.CustomSlidingTabLayout_defaultTextColor, Color.BLACK);
    sTextColor = ta.getColor(R.styleable.CustomSlidingTabLayout_selectedTextColor, Color.RED);
    mTextSize = ta.getDimensionPixelOffset(R.styleable.CustomSlidingTabLayout_textSize, TAB_VIEW_TEXT_SIZE_SP);

    mNeedBold = ta.getBoolean(R.styleable.CustomSlidingTabLayout_needBold, false);

    mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);

    mTabStrip = new CustomSlidingTabStrip(context);
    addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    // mTabStrip attrs
    int mBottomLineColor = ta.getColor(R.styleable.CustomSlidingTabLayout_BottomLineColor,
            getResources().getColor(R.color.grey_cccccc));
    int mIndicatorHeight = ta.getDimensionPixelOffset(R.styleable.CustomSlidingTabLayout_IndicatorHeight,
            DensityUtils.dip2px(getContext(), 6));
    int mBottomLineHeight = ta.getDimensionPixelOffset(R.styleable.CustomSlidingTabLayout_BottomLineHeight, 0);

    setBottomHeight(mBottomLineHeight);

    setIndicatorHeight(mIndicatorHeight);

    setBottomLineColor(mBottomLineColor);

    ta.recycle();

}

From source file:com.socialapp.utils.MaterialProgressBar.java

private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MaterialProgressBar, defStyleAttr,
            0);/*  w  w w .j a v a  2 s. c  o m*/

    final float density = getContext().getResources().getDisplayMetrics().density;

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

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

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

    mProgressStokeWidth = a.getDimensionPixelOffset(R.styleable.MaterialProgressBar_progress_stoke_width,
            (int) (STROKE_WIDTH_LARGE * density));
    mArrowWidth = a.getDimensionPixelOffset(R.styleable.MaterialProgressBar_arrow_width, -1);
    mArrowHeight = a.getDimensionPixelOffset(R.styleable.MaterialProgressBar_arrow_height, -1);
    mTextSize = a.getDimensionPixelOffset(R.styleable.MaterialProgressBar_progress_text_size,
            (int) (DEFAULT_TEXT_SIZE * density));
    mTextColor = a.getColor(R.styleable.MaterialProgressBar_progress_text_color, Color.BLACK);

    mShowArrow = a.getBoolean(R.styleable.MaterialProgressBar_show_arrow, false);
    mCircleBackgroundEnabled = a.getBoolean(R.styleable.MaterialProgressBar_enable_circle_background, true);

    mProgress = a.getInt(R.styleable.MaterialProgressBar_progress, 0);
    mMax = a.getInt(R.styleable.MaterialProgressBar_max, 100);
    int textVisible = a.getInt(R.styleable.MaterialProgressBar_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.chn.halo.view.progressbar.MaterialProgressBar.java

private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MaterialProgressBar, defStyleAttr,
            0);//from  w  w  w. jav  a2  s  .  co  m

    final float density = getContext().getResources().getDisplayMetrics().density;

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

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

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

    mProgressStokeWidth = a.getDimensionPixelOffset(R.styleable.MaterialProgressBar_progress_stoke_width,
            (int) (STROKE_WIDTH_LARGE * density));
    mArrowWidth = a.getDimensionPixelOffset(R.styleable.MaterialProgressBar_arrow_width, -1);
    mArrowHeight = a.getDimensionPixelOffset(R.styleable.MaterialProgressBar_arrow_height, -1);
    mTextSize = a.getDimensionPixelOffset(R.styleable.MaterialProgressBar_progress_text_size,
            (int) (DEFAULT_TEXT_SIZE * density));
    mTextColor = a.getColor(R.styleable.MaterialProgressBar_progress_text_color, Color.BLACK);

    mShowArrow = a.getBoolean(R.styleable.MaterialProgressBar_show_arrow, false);
    mCircleBackgroundEnabled = a.getBoolean(R.styleable.MaterialProgressBar_enable_circle_background, true);

    mProgress = a.getInt(R.styleable.MaterialProgressBar_progress, 0);
    mMax = a.getInt(R.styleable.MaterialProgressBar_max, 100);
    int textVisible = a.getInt(R.styleable.MaterialProgressBar_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.itutorgroup.tutorchat.phone.ui.CircleProgressBar.java

private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleProgressBar, defStyleAttr, 0);
    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;//  w  ww. j ava2  s  .  c o  m
    }

    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.eventer.app.view.CircleProgressBar.java

private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleProgressBar, defStyleAttr, 0);
    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;//from  w  ww  . j av a 2 s  . co  m
    }

    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);
}