Example usage for android.content.res TypedArray getFraction

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

Introduction

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

Prototype

public float getFraction(@StyleableRes int index, int base, int pbase, float defValue) 

Source Link

Document

Retrieves a fractional unit attribute at index.

Usage

From source file:de.vanita5.twittnuker.view.ShapedImageView.java

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

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ShapedImageView, defStyle, 0);

    mMatrix = new Matrix();
    mSource = new RectF();
    mDestination = new RectF();
    mTempDestination = new RectF();

    mBitmapPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBitmapPaint.setFilterBitmap(true);/*from   ww  w  .  j av a  2  s  .co m*/
    mBitmapPaint.setDither(true);
    mSolidColorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    mBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBorderPaint.setStyle(Paint.Style.STROKE);

    mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    if (a.hasValue(R.styleable.ShapedImageView_sivBorder)) {
        setBorderEnabled(a.getBoolean(R.styleable.ShapedImageView_sivBorder, false));
    } else if (a.hasValue(R.styleable.ShapedImageView_sivBorderColor)
            || a.hasValue(R.styleable.ShapedImageView_sivBorderWidth)) {
        setBorderEnabled(true);
    }
    setBorderColor(a.getColor(R.styleable.ShapedImageView_sivBorderColor, Color.TRANSPARENT));
    setBorderWidth(a.getDimensionPixelSize(R.styleable.ShapedImageView_sivBorderWidth, 0));
    @ShapeStyle
    final int shapeStyle = a.getInt(R.styleable.ShapedImageView_sivShape, SHAPE_RECTANGLE);
    setStyle(shapeStyle);
    setCornerRadius(a.getDimension(R.styleable.ShapedImageView_sivCornerRadius, 0));
    setCornerRadiusRatio(a.getFraction(R.styleable.ShapedImageView_sivCornerRadiusRatio, 1, 1, -1));

    if (USE_OUTLINE) {
        if (a.hasValue(R.styleable.ShapedImageView_sivElevation)) {
            ViewCompat.setElevation(this, a.getDimensionPixelSize(R.styleable.ShapedImageView_sivElevation, 0));
        }
    } else {
        mShadowRadius = a.getDimensionPixelSize(R.styleable.ShapedImageView_sivElevation, 0);
    }
    setBackgroundColor(a.getColor(R.styleable.ShapedImageView_sivBackgroundColor, 0));
    a.recycle();

    if (USE_OUTLINE) {
        initOutlineProvider();
    }
}

From source file:org.mariotaku.twidere.view.ShapedImageView.java

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

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ShapedImageView, defStyle, 0);

    mMatrix = new Matrix();
    mSource = new RectF();
    mDestination = new RectF();
    mTempDestination = new RectF();

    mBitmapPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBitmapPaint.setFilterBitmap(true);/*w ww  .j  a v  a 2 s .co  m*/
    mBitmapPaint.setDither(true);
    mSolidColorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    mBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBorderPaint.setStyle(Paint.Style.STROKE);

    mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    if (a.hasValue(R.styleable.ShapedImageView_sivBorder)) {
        setBorderEnabled(a.getBoolean(R.styleable.ShapedImageView_sivBorder, false));
    } else if (a.hasValue(R.styleable.ShapedImageView_sivBorderColor)
            || a.hasValue(R.styleable.ShapedImageView_sivBorderWidth)) {
        setBorderEnabled(true);
    }
    setBorderColor(a.getColor(R.styleable.ShapedImageView_sivBorderColor, Color.TRANSPARENT));
    setBorderWidth(a.getDimensionPixelSize(R.styleable.ShapedImageView_sivBorderWidth, 0));
    @ShapeStyle
    final int shapeStyle = a.getInt(R.styleable.ShapedImageView_sivShape, SHAPE_RECTANGLE);
    setStyle(shapeStyle);
    setCornerRadius(a.getDimension(R.styleable.ShapedImageView_sivCornerRadius, 0));
    setCornerRadiusRatio(a.getFraction(R.styleable.ShapedImageView_sivCornerRadiusRatio, 1, 1, -1));

    if (useOutline()) {
        if (a.hasValue(R.styleable.ShapedImageView_sivElevation)) {
            ViewCompat.setElevation(this, a.getDimensionPixelSize(R.styleable.ShapedImageView_sivElevation, 0));
        }
    } else {
        mShadowRadius = a.getDimensionPixelSize(R.styleable.ShapedImageView_sivElevation, 0);
    }
    setBackgroundColor(a.getColor(R.styleable.ShapedImageView_sivBackgroundColor, 0));
    a.recycle();

    initOutlineProvider();
}

From source file:de.mrapp.android.sidebar.Sidebar.java

/**
 * Obtains the ratio between the distance, the sidebar is moved by when it becomes shown or
 * hidden, in relation to the distance, the content is moved by, from a specific typed array.
 *
 * @param typedArray/* w  ww  .  j  a v  a2 s  .c o m*/
 *         The typed array, the scroll ratio should be obtained from, as an instance of the
 *         class {@link TypedArray}. The typed array may not be null
 */
private void obtainScrollRatio(@NonNull final TypedArray typedArray) {
    setScrollRatio(typedArray.getFraction(R.styleable.Sidebar_scrollRatio, 1, 1, DEFAULT_SCROLL_RATIO));
}

From source file:de.mrapp.android.sidebar.Sidebar.java

/**
 * Obtains the width of the sidebar in relation to the width of its parent view, from a specific
 * typed array.//  w ww.j  a  va2  s .  c o m
 *
 * @param typedArray
 *         The typed array, the width of the sidebar should be obtained from, as an instance of
 *         the class {@link TypedArray}. The typed array may not be null
 */
private void obtainSidebarWidth(@NonNull final TypedArray typedArray) {
    setSidebarWidth(typedArray.getFraction(R.styleable.Sidebar_sidebarWidth, 1, 1, DEFAULT_SIDEBAR_WIDTH));
}

From source file:de.mrapp.android.sidebar.Sidebar.java

/**
 * Obtains the amount of space in relation to the width of the parent view, the sidebar is
 * visible, even if it is currently hidden, from a specific typed array.
 *
 * @param typedArray/*from  www.  java2 s . c  om*/
 *         The typed array, the offset should be obtained from, as an instance of the class
 *         {@link TypedArray}. The typed array may not be null
 */
private void obtainSidebarOffset(@NonNull final TypedArray typedArray) {
    setSidebarOffset(typedArray.getFraction(R.styleable.Sidebar_sidebarOffset, 1, 1, DEFAULT_SIDEBAR_OFFSET));
}

From source file:de.mrapp.android.sidebar.Sidebar.java

/**
 * Obtains the distance, the sidebar has to be dragged until its state changes, in relation to
 * the whole distance, from a specific typed array.
 *
 * @param typedArray//from   w w  w  . j  a  v a  2s.co  m
 *         The typed array, the threshold should be obtained from, as an instance of the class
 *         {@link TypedArray}. The typed array may not be null
 */
private void obtainDragThreshold(@NonNull final TypedArray typedArray) {
    setDragThreshold(typedArray.getFraction(R.styleable.Sidebar_dragThreshold, 1, 1, DEFAULT_DRAG_THRESHOLD));
}

From source file:de.mrapp.android.sidebar.Sidebar.java

/**
 * Obtains the transparency of the overlay, which is shown in front of the main content, when
 * the sidebar is shown, from a specific typed array.
 *
 * @param typedArray//from   w  w w.j  av a 2s . c  om
 *         The typed array, the transparency of the overlay should be obtained from, as an
 *         instance of the class {@link TypedArray}. The typed array may not be null
 */
private void obtainContentOverlayTransparency(@NonNull final TypedArray typedArray) {
    setContentOverlayTransparency(typedArray.getFraction(R.styleable.Sidebar_contentOverlayTransparency, 1, 1,
            DEFAULT_CONTENT_OVERLAY_TRANSPARENCY));
}

From source file:de.mrapp.android.sidebar.Sidebar.java

/**
 * Obtains the sensitivity, which specifies the distance after which dragging has an effect on
 * the sidebar, from a specific typed array.
 *
 * @param typedArray/*w ww  .j ava2  s.com*/
 *         The typed array, the sensitivity should be obtained from, as an instance of the class
 *         {@link TypedArray}. The typed array may not be null
 */
private void obtainDragSensitivity(@NonNull final TypedArray typedArray) {
    setDragSensitivity(
            typedArray.getFraction(R.styleable.Sidebar_dragSensitivity, 1, 1, DEFAULT_DRAG_SENSITIVITY));
}