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:de.mrapp.android.util.ThemeUtil.java

/**
 * Obtains the dimension pixel offset, which corresponds to a specific resource id, from a
 * specific theme. If the given resource id is invalid, a {@link NotFoundException} will be
 * thrown.//from  w  w  w . java 2 s.  c o  m
 *
 * @param context
 *         The context, which should be used, as an instance of the class {@link Context}. The
 *         context may not be null
 * @param themeResourceId
 *         The resource id of the theme, the attribute should be obtained from, as an {@link
 *         Integer} value or -1, if the attribute should be obtained from the given context's
 *         theme
 * @param resourceId
 *         The resource id of the attribute, which should be obtained, as an {@link Integer}
 *         value. The resource id must corresponds to a valid theme attribute
 * @return The dimension pixel offset, which has been obtained, as an {@link Integer} value
 */
public static int getDimensionPixelOffset(@NonNull final Context context, @StyleRes final int themeResourceId,
        @AttrRes final int resourceId) {
    TypedArray typedArray = null;

    try {
        typedArray = obtainStyledAttributes(context, themeResourceId, resourceId);
        int dimension = typedArray.getDimensionPixelOffset(0, -1);

        if (dimension == -1) {
            throw new NotFoundException("Resource ID #0x" + Integer.toHexString(resourceId) + " is not valid");
        }

        return dimension;
    } finally {
        if (typedArray != null) {
            typedArray.recycle();
        }
    }
}

From source file:ooo.oxo.mr.widget.OhRecyclerView.java

public OhRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    final int padding;

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.OhRecyclerView);
    padding = a.getDimensionPixelOffset(R.styleable.OhRecyclerView_padding, 0);
    a.recycle();/*from   ww w . j av  a 2s .  c  o  m*/

    setPadding(padding, padding, padding, padding);

    ViewCompat.setOnApplyWindowInsetsListener(this, (v, insets) -> {
        final int l = padding + insets.getSystemWindowInsetLeft();
        final int r = padding + insets.getSystemWindowInsetRight();
        final int b = padding + insets.getSystemWindowInsetBottom();
        setPadding(l, padding, r, b);
        return insets.consumeSystemWindowInsets();
    });
}

From source file:ooo.oxo.mr.widget.InsetsRecyclerView.java

public InsetsRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.InsetsRecyclerView);
    padding = a.getDimensionPixelOffset(R.styleable.InsetsRecyclerView_padding, 0);
    a.recycle();/*from  ww  w  .j a v a  2s.  com*/

    setPadding(padding, padding, padding, padding);

    ViewCompat.setOnApplyWindowInsetsListener(this, (v, insets) -> {
        final int l = padding + insets.getSystemWindowInsetLeft();
        final int r = padding + insets.getSystemWindowInsetRight();
        final int b = padding + insets.getSystemWindowInsetBottom();
        setPadding(l, padding, r, b);
        return insets.consumeSystemWindowInsets();
    });
}

From source file:meizhi.meizhi.malin.widget.InsetsRecyclerView.java

public InsetsRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.InsetsRecyclerView);
    padding = a.getDimensionPixelOffset(R.styleable.InsetsRecyclerView_padding, 0);
    a.recycle();/*from w w  w .  j  a v  a2s  .  co  m*/
    setPadding(padding, padding, padding, padding);

    ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            final int l = padding + insets.getSystemWindowInsetLeft();
            final int r = padding + insets.getSystemWindowInsetRight();
            final int b = padding + insets.getSystemWindowInsetBottom();
            setPadding(l, padding, r, b);
            return insets.consumeSystemWindowInsets();
        }
    });
}

From source file:com.zhihu.android.app.mirror.widget.ArtboardView.java

private void init(AttributeSet attrs) {
    mDragDismissDistance = DisplayUtils.dp2px(getContext(), 112.0F);
    mDragElacticity = 0.8F;//ww w .ja v a2  s.com
    if (attrs != null) {
        TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.ArtboardView);
        mDragDismissDistance = array.getDimensionPixelOffset(R.styleable.ArtboardView_avDragDismissDistance,
                (int) mDragDismissDistance);
        mDragElacticity = array.getFloat(R.styleable.ArtboardView_avDragElasticity, mDragElacticity);
        array.recycle();
    }

    mGestureDetector = new GestureDetector(getContext(), buildSimpleOnGestureListener());
    setOnTouchListener(this);
}

From source file:com.ouyangzn.view.TopDragLayout.java

private void init(Context context, AttributeSet attrs) {
    mDragHelper = ViewDragHelper.create(this, new ViewDragCallback());
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.TopDragLayout);
    mRemainHeight = ta.getDimensionPixelOffset(R.styleable.TopDragLayout_remain_height, 0);
    mThresholdHeight = ta.getDimensionPixelOffset(R.styleable.TopDragLayout_threshold_height, 0);
    mDraggedViewId = ta.getResourceId(R.styleable.TopDragLayout_dragged_view_id, View.NO_ID);
    ta.recycle();//from  ww  w .  j a  v a2s  .  c  o  m
}

From source file:com.ouyangzn.view.DragLayout.java

private void init(Context context, AttributeSet attrs) {
    mContext = context;/*from   w w  w .  j  av a 2 s .c  o  m*/

    mDragHelper = ViewDragHelper.create(this, new DragLayout.ViewDragCallback());
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.DragLayout);
    mRemainDistance = ta.getDimensionPixelOffset(R.styleable.DragLayout_remain_distance, 0);
    mThresholdDistance = ta.getDimensionPixelOffset(R.styleable.DragLayout_threshold_distance, 0);
    //mDraggedViewId = ta.getResourceId(R.styleable.DragLayout_dragged_view_id, View.NO_ID);
    mDirection = ta.getInt(R.styleable.DragLayout_direction, DIRECTION_TOP);
    ta.recycle();
}

From source file:com.zhi.android.libs.pager.PageIndicatorView.java

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

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PageIndicatorView, defStyleAttr,
            defStyleRes);// ww  w. ja v  a2 s. c om
    mNormalColor = a.getColor(R.styleable.PageIndicatorView_pageIndicatorNormalColor, 0);
    mSelectedColor = a.getColor(R.styleable.PageIndicatorView_pageIndicatorSelectedColor, 0);
    mAnimated = a.getBoolean(R.styleable.PageIndicatorView_pageIndicatorAnimated, true);
    mRadius = a.getDimensionPixelOffset(R.styleable.PageIndicatorView_pageIndicatorRadius, 0);
    mSpacing = a.getDimensionPixelOffset(R.styleable.PageIndicatorView_pageIndicatorSpacing, 0);
    a.recycle();

    mPaint = new Paint();
    mPaint.setAntiAlias(false);
}

From source file:com.alex.view.loop.IndicatorView.java

public IndicatorView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    // ?//www.ja  v  a 2  s  .  co  m
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.IndicatorView);
    normalBp = drawableToBitamp(ta.getDrawable(R.styleable.IndicatorView_normalDrawable));
    selectBp = drawableToBitamp(ta.getDrawable(R.styleable.IndicatorView_selectDrawable));
    mInterval = ta.getDimensionPixelOffset(R.styleable.IndicatorView_indicatorInterval, 6);
    normalColor = ta.getColor(R.styleable.IndicatorView_normalColor, Color.GRAY);
    selectColor = ta.getColor(R.styleable.IndicatorView_selectColor, Color.RED);
    mRadius = ta.getInteger(R.styleable.IndicatorView_indicatorRadius, 6);
    isCirculate = ta.getBoolean(R.styleable.IndicatorView_isCirculate, true);
    ta.recycle();
    // ?
    init();

}

From source file:com.nick.documents.widget.FlexibleImageView.java

private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FlexibleImageView, defStyleAttr, 0);

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

    mBgColor = a.getColor(R.styleable.FlexibleImageView_background_color, DEFAULT_CIRCLE_BG_LIGHT);

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

    mProgressStokeWidth = a.getDimensionPixelOffset(R.styleable.FlexibleImageView_progress_stoke_width,
            (int) (STROKE_WIDTH_LARGE * density));
    mTextSize = a.getDimensionPixelOffset(R.styleable.FlexibleImageView_progress_text_size,
            (int) (DEFAULT_TEXT_SIZE * density));
    mTextColor = a.getColor(R.styleable.FlexibleImageView_progress_text_color, Color.BLACK);

    mCircleBackgroundEnabled = a.getBoolean(R.styleable.FlexibleImageView_enable_circle_background, true);

    mProgress = a.getInt(R.styleable.FlexibleImageView_progress, 0);
    mMax = a.getInt(R.styleable.FlexibleImageView_max_flip, 100);
    int textVisible = a.getInt(R.styleable.FlexibleImageView_progress_text_visibility, 1);
    if (textVisible != 1) {
        mHasText = true;/* w  w w . j a  v  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);
    mRingColors = context.getResources().getIntArray(R.array.ring_colors);
    super.setImageDrawable(mProgressDrawable);
    mHandler = new Handler();
}