Example usage for android.graphics SweepGradient setLocalMatrix

List of usage examples for android.graphics SweepGradient setLocalMatrix

Introduction

In this page you can find the example usage for android.graphics SweepGradient setLocalMatrix.

Prototype

public void setLocalMatrix(@Nullable Matrix localM) 

Source Link

Document

Set the shader's local matrix.

Usage

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

private void updateBorderShader() {
    final int[] colors = mBorderColors;
    if (colors == null || colors.length == 0) {
        mBorderPaint.setShader(null);/*from  w w  w. j  a v  a 2s  .  c  o m*/
        return;
    }
    mDestination.set(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(),
            getHeight() - getPaddingBottom());
    final float cx = mDestination.centerX(), cy = mDestination.centerY();
    final int[] sweepColors = new int[colors.length * 2];
    final float[] positions = new float[colors.length * 2];
    for (int i = 0, j = colors.length; i < j; i++) {
        sweepColors[i * 2] = sweepColors[i * 2 + 1] = colors[i];
        positions[i * 2] = i == 0 ? 0 : i / (float) j;
        positions[i * 2 + 1] = i == j - 1 ? 1 : (i + 1) / (float) j;
    }
    final SweepGradient shader = new SweepGradient(cx, cy, sweepColors, positions);
    final Matrix matrix = new Matrix();
    matrix.setRotate(90, cx, cy);
    shader.setLocalMatrix(matrix);
    mBorderPaint.setShader(shader);
}

From source file:org.getlantern.firetweet.view.ShapedImageView.java

private void updateBorderShader() {
    final int[] colors = mBorderColors;
    if (colors == null || colors.length == 0) {
        mBorderAlpha = 0;//from   w  w  w.j  ava  2s.c  om
        return;
    }
    mDestination.set(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(),
            getHeight() - getPaddingBottom());
    final float cx = mDestination.centerX(), cy = mDestination.centerY();
    final int[] sweepColors = new int[colors.length * 2];
    final float[] positions = new float[colors.length * 2];
    for (int i = 0, j = colors.length; i < j; i++) {
        sweepColors[i * 2] = sweepColors[i * 2 + 1] = colors[i];
        positions[i * 2] = i == 0 ? 0 : i / (float) j;
        positions[i * 2 + 1] = i == j - 1 ? 1 : (i + 1) / (float) j;
    }
    final SweepGradient shader = new SweepGradient(cx, cy, sweepColors, positions);
    final Matrix matrix = new Matrix();
    matrix.setRotate(90, cx, cy);
    shader.setLocalMatrix(matrix);
    mBorderPaint.setShader(shader);
}

From source file:com.skumar.flexibleciruclarseekbar.CircularSeekBar.java

/**
 * Method to drawing the gradient color for the arc
 *//* w  ww  .  j ava2 s  . c o  m*/
public void setShader() {
    SweepGradient sweepgradient = new SweepGradient(mArcRadius, mArcRadius, Color.parseColor("#2f8bca"),
            Color.parseColor("#c91200"));
    Matrix matrix = new Matrix();
    matrix.reset();
    sweepgradient.getLocalMatrix(matrix);
    matrix.postRotate(90, mArcRadius, mArcRadius);
    sweepgradient.setLocalMatrix(matrix);
    mArcPaint.setShader(sweepgradient);
    mNeedleScalePaint.setShader(sweepgradient);
}