Java 类android.graphics.LinearGradient 实例源码

项目:GitHub    文件:HeaderShadowDecoration.java   
public HeaderShadowDecoration(View view, boolean scrollsHorizontally, float parallax, float shadowSize, int columns) {
    mView = view;
    mHorizontal = scrollsHorizontally;
    mParallax = parallax;
    mShadowSize = shadowSize;
    mColumns = columns;

    if (mShadowSize > 0) {
        mShadowPaint = new Paint();
        mShadowPaint.setShader(mHorizontal ?
                new LinearGradient(mShadowSize, 0, 0, 0,
                        new int[]{Color.argb(55, 0, 0, 0), Color.argb(55, 0, 0, 0), Color.argb(3, 0, 0, 0)},
                        new float[]{0f, .5f, 1f},
                        Shader.TileMode.CLAMP) :
                new LinearGradient(0, mShadowSize, 0, 0,
                        new int[]{Color.argb(55, 0, 0, 0), Color.argb(55, 0, 0, 0), Color.argb(3, 0, 0, 0)},
                        new float[]{0f, .5f, 1f},
                        Shader.TileMode.CLAMP));
    } else {
        mShadowPaint = null;
    }
}
项目:AndroidSdrRtlTuner    文件:AnalyzerSurface.java   
/**
 * SurfaceHolder.Callback function. This is called every time the dimension changes
 * (and after the SurfaceView is created).
 *
 * @param holder    reference to the surface holder
 * @param format
 * @param width     current width of the surface view
 * @param height    current height of the surface view
 */
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    if(this.width != width || this.height != height) {
        this.width = width;
        this.height = height;

        // Recreate the shaders:
        this.fftPaint.setShader(new LinearGradient(0, 0, 0, getFftHeight(), Color.WHITE, Color.parseColor(fftColor), Shader.TileMode.MIRROR));

        // Recreate the waterfall bitmaps:
        this.createWaterfallLineBitmaps();

        // Fix the text size of the text paint objects:
        this.setFontSize(fontSize);
    }
}
项目:stynico    文件:nicoTextView.java   
@Override
   protected void onSizeChanged(int w, int h, int oldw, int oldh)
   {
super.onSizeChanged(w, h, oldw, oldh);
if (mViewWidth == 0)
{
    mViewWidth = getMeasuredWidth();
    if (mViewWidth > 0)
    {
    mPaint = getPaint();
    mLinearGradient = new LinearGradient(-mViewWidth, 0, 0, 0,new int[] { 0x45B3B5, 0x45B3B5, 0x33ffffff },new float[] { 0, 0.5f, 1 }, Shader.TileMode.CLAMP);
    mPaint.setShader(mLinearGradient);
    mGradientMatrix = new Matrix();
    }
}
   }
项目:JSSample    文件:SProgress.java   
private void init() {
   setLayerType(LAYER_TYPE_SOFTWARE,null);
    bgpaint = new Paint();
    bgpaint.setColor(backColor);
    bgpaint.setAntiAlias(true);

    proPaint = new Paint();
    proPaint.setColor(progressColor);
    LinearGradient linearGradient = new LinearGradient(0, 0, width, height, progressColor, progressendcolor, Shader.TileMode.CLAMP);
    proPaint.setShader(linearGradient);
    proPaint.setAntiAlias(true);

    textPaint = new Paint();
    textPaint.setColor(textColor);
    textPaint.setAntiAlias(true);
    textPaint.setTextSize(textsize);
    textbaseline = getFontstart(textPaint);
    rectbg = new RectF();
    rectprogress = new RectF();
}
项目:PeSanKita-android    文件:VerticalSlideColorPicker.java   
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
  super.onSizeChanged(w, h, oldw, oldh);

  viewWidth = w;
  viewHeight = h;

  centerX           = viewWidth / 2;
  colorPickerRadius = (viewWidth / 2) - borderWidth;

  colorPickerBody = new RectF(centerX - colorPickerRadius, borderWidth + colorPickerRadius, centerX + colorPickerRadius, viewHeight - (borderWidth + colorPickerRadius));

  LinearGradient gradient = new LinearGradient(0, colorPickerBody.top, 0, colorPickerBody.bottom, colors, null, Shader.TileMode.CLAMP);
  paint.setShader(gradient);

  if (bitmap != null) {
    bitmap.recycle();
  }

  bitmap       = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888);
  bitmapCanvas = new Canvas(bitmap);

  resetToDefault();
}
项目:WaveAudioVizualization    文件:VoiceWaveViewTV.java   
@Override   // will be called on UI thread
public void onSurfaceTextureAvailable(SurfaceTexture st, int width, int height) {
    Log.d(TAG, "onSurfaceTextureAvailable(" + width + "x" + height + ")");
    mWidth = width;
    mHeight = height;
    mMaxAmpl = height / 2;
    mPaints.get(0).setShader(new LinearGradient(0, 0, mWidth, mHeight, Color.parseColor("#CA67B7"), Color.parseColor("#C081C1"), Shader.TileMode.MIRROR));
    mPaints.get(0).setStrokeWidth(ScreenUtils.dp2px(getContext(), 2));
    mPaints.get(1).setColor(Color.parseColor("#D5E3FA"));
    mPaints.get(1).setStrokeWidth(ScreenUtils.dp2px(getContext(), 2));
    mPaints.get(2).setStrokeWidth(ScreenUtils.dp2px(getContext(), 1));
    mPaints.get(3).setStrokeWidth(ScreenUtils.dp2px(getContext(), 1));
    mPaints.get(2).setShader(new LinearGradient(0, 0, mWidth, mHeight, Color.parseColor("#E67EA5"), Color.parseColor("#7F7AE1"), Shader.TileMode.MIRROR));
    mPaints.get(3).setShader(new LinearGradient(0, 0, mWidth, mHeight, Color.parseColor("#E67EA5"), Color.parseColor("#7F7AE1"), Shader.TileMode.MIRROR));
    synchronized (mLock) {
        mSurfaceTexture = st;
        mLock.notify();
    }
}
项目:planetcon    文件:ColorPicker.java   
private void drawColorSquare(Canvas canvas) {
    int pureColor, brightColor, darkColor, transparentColor;

    // pureColor
    mHSV[0] = mColorHSV[0];
    mHSV[1] = 1; mHSV[2] = 1;
    pureColor = Color.HSVToColor(mHSV);
    // brightColor
    mHSV[1] = 0; mHSV[2] = 1;
    brightColor = Color.HSVToColor(mHSV);
    // darkColor
    mHSV[1] = 1; mHSV[2] = 0;
    darkColor = Color.HSVToColor(255, mHSV);
    // alphaColor
    mHSV[1] = 0; mHSV[2] = 0;
    transparentColor = Color.HSVToColor(0, mHSV);

    // drawn without compose shader, but looks worse
    Shader gradient1 = new LinearGradient(mSquareRect.right, mSquareRect.bottom, mSquareRect.right, mSquareRect.top, brightColor, pureColor, TileMode.CLAMP);
    Shader gradient2 = new LinearGradient(mSquareRect.right, mSquareRect.bottom, mSquareRect.left, mSquareRect.bottom, transparentColor, darkColor, TileMode.CLAMP);

    mColorPaint.setShader(gradient1);
    canvas.drawRect(mSquareRect, mColorPaint);
    mColorPaint.setShader(gradient2);
    canvas.drawRect(mSquareRect, mColorPaint);
}
项目:MainCalendar    文件:GradientShaderTextView.java   
@Override
protected void onSizeChanged(int w, int h, int oldW, int oldH) {
    super.onSizeChanged(w, h, oldW, oldH);
    if (mViewWidth == 0) {
        mViewWidth = getMeasuredWidth();
        if (mViewWidth > 0) {
            Paint paint = getPaint();
            String text = getText().toString();
            mTextWidth = paint.measureText(text);
            int size = (int)paint.measureText(text);
            int startX = (mViewWidth - size) / 2;
            mLinearGradient = new LinearGradient(startX + 1, 0, 0, 0,
                    new int[] { 0x90ffffff, 0xffffffff, 0x90ffffff },
                    new float[] { 0, 0.5f, 1 }, Shader.TileMode.CLAMP); //边缘融合
            paint.setShader(mLinearGradient);
            mGradientMatrix = new Matrix();
        }
    }
}
项目:chromium-for-android-56-debug-video    文件:FadingShadow.java   
/**
 * @param shadowColor The color of the shadow, e.g. 0x11000000.
 */
public FadingShadow(int shadowColor) {
    final int n = SMOOTH_ALGORITHM_INTERPOLATION_POINTS_NUM;
    float[] positions = new float[n];
    int[] colors = new int[n];
    int transparentShadowColor = shadowColor & 0x00FFFFFF;
    int shadowAlpha = Color.alpha(shadowColor);

    // Piece-wise linear interpolation of the smooth cubic function below.
    for (int i = 0; i < n; ++i) {
        float x = (float) i / (n - 1);
        // Polynomial computation by Estrin's scheme.
        float value = (1.0f - 2.2f * x) + (1.8f - 0.6f * x) * (x * x);

        positions[i] = x;
        colors[i] = (Math.round(shadowAlpha * value) << 24) | transparentShadowColor;
    }

    mShadowShader = new LinearGradient(0, 0, 0, 1, colors, positions, Shader.TileMode.CLAMP);

}
项目:microMathematics    文件:SaturationBar.java   
/**
 * Set the bar color. <br>
 * <br>
 * Its discouraged to use this method.
 * 
 * @param color
 */
public void setColor(int color) {
    int x1, y1;
    if (mOrientation == ORIENTATION_HORIZONTAL) {
        x1 = (mBarLength + mBarPointerHaloRadius);
        y1 = mBarThickness;
    } else {
        x1 = mBarThickness;
        y1 = (mBarLength + mBarPointerHaloRadius);
    }

    Color.colorToHSV(color, mHSVColor);
    shader = new LinearGradient(mBarPointerHaloRadius, 0, x1, y1,
            new int[] { Color.WHITE, color }, null, Shader.TileMode.CLAMP);
    mBarPaint.setShader(shader);
    calculateColor(mBarPointerPosition);
    mBarPointerPaint.setColor(mColor);
    if (mPicker != null) {
        mPicker.setNewCenterColor(mColor);
        if (mPicker.hasValueBar())
            mPicker.changeValueBarColor(mColor);
        else if (mPicker.hasOpacityBar())
            mPicker.changeOpacityBarColor(mColor);
    }
    invalidate();
}
项目:boohee_v5.6    文件:RoundRectDrawableWithShadow.java   
private void buildShadowCorners() {
    RectF innerBounds = new RectF(-this.mCornerRadius, -this.mCornerRadius, this.mCornerRadius, this.mCornerRadius);
    RectF outerBounds = new RectF(innerBounds);
    outerBounds.inset(-this.mShadowSize, -this.mShadowSize);
    if (this.mCornerShadowPath == null) {
        this.mCornerShadowPath = new Path();
    } else {
        this.mCornerShadowPath.reset();
    }
    this.mCornerShadowPath.setFillType(FillType.EVEN_ODD);
    this.mCornerShadowPath.moveTo(-this.mCornerRadius, 0.0f);
    this.mCornerShadowPath.rLineTo(-this.mShadowSize, 0.0f);
    this.mCornerShadowPath.arcTo(outerBounds, 180.0f, 90.0f, false);
    this.mCornerShadowPath.arcTo(innerBounds, 270.0f, -90.0f, false);
    this.mCornerShadowPath.close();
    float startRatio = this.mCornerRadius / (this.mCornerRadius + this.mShadowSize);
    this.mCornerShadowPaint.setShader(new RadialGradient(0.0f, 0.0f, this.mCornerRadius + this.mShadowSize, new int[]{this.mShadowStartColor, this.mShadowStartColor, this.mShadowEndColor}, new float[]{0.0f, startRatio, 1.0f}, TileMode.CLAMP));
    this.mEdgeShadowPaint.setShader(new LinearGradient(0.0f, (-this.mCornerRadius) + this.mShadowSize, 0.0f, (-this.mCornerRadius) - this.mShadowSize, new int[]{this.mShadowStartColor, this.mShadowStartColor, this.mShadowEndColor}, new float[]{0.0f, 0.5f, 1.0f}, TileMode.CLAMP));
    this.mEdgeShadowPaint.setAntiAlias(false);
}
项目:FakeWeather    文件:OvercastType.java   
@Override
public void generateElements() {
    cloudShader = new LinearGradient(getWidth() / 2, 0, getWidth() / 2, getHeight() * 0.618f, 0xFFFFFFFF,
            0x00FFFFFF, Shader.TileMode.CLAMP);
    final float textSize = getHeight() / 32f;
    fanPath.reset();
    final float fanSize = textSize * 0.2f;// 风扇底部半圆的半径
    final float fanHeight = textSize * 2f;
    final float fanCenterOffsetY = fanSize * 1.6f;
    fanPath.addArc(new RectF(-fanSize, -fanSize - fanCenterOffsetY, fanSize, fanSize - fanCenterOffsetY), 0,
            180);
    fanPath.quadTo(-fanSize * 1f, -fanHeight * 0.5f - fanCenterOffsetY, 0, -fanHeight - fanCenterOffsetY);
    fanPath.quadTo(fanSize * 1f, -fanHeight * 0.5f - fanCenterOffsetY, fanSize, -fanCenterOffsetY);
    fanPath.close();

    fanPillarPath.reset();
    final float fanPillarSize = textSize * 0.20f;// 柱子的宽度
    fanPillarPath.moveTo(0, 0);
    fanPillerHeight = textSize * 4f;// 柱子的高度
    fanPillarPath.lineTo(2, 0);
    fanPillarPath.lineTo(fanPillarSize, fanPillerHeight);
    fanPillarPath.lineTo(-fanPillarSize, fanPillerHeight);
    fanPillarPath.lineTo(-2, 0);
    fanPillarPath.close();
}
项目:xlight_android_native    文件:ValueBar.java   
/**
 * Set the bar color. <br>
 * <br>
 * Its discouraged to use this method.
 * 
 * @param color
 */
public void setColor(int color) {
    int x1, y1;
    if(mOrientation == ORIENTATION_HORIZONTAL) {
        x1 = (mBarLength + mBarPointerHaloRadius);
        y1 = mBarThickness;
    }
    else {
        x1 = mBarThickness;
        y1 = (mBarLength + mBarPointerHaloRadius);
    }

    Color.colorToHSV(color, mHSVColor);
    shader = new LinearGradient(mBarPointerHaloRadius, 0,
            x1, y1, new int[] {
                    color, Color.BLACK }, null, Shader.TileMode.CLAMP);
    mBarPaint.setShader(shader);
    calculateColor(mBarPointerPosition);
    mBarPointerPaint.setColor(mColor);
    if (mPicker != null) {
        mPicker.setNewCenterColor(mColor);
        if(mPicker.hasOpacityBar())
            mPicker.changeOpacityBarColor(mColor);
    }
    invalidate();
}
项目:ShimmerLayout    文件:ShimmerLayout.java   
private Bitmap getSourceMaskBitmap() {
    if (sourceMaskBitmap != null) {
        return sourceMaskBitmap;
    }

    int width = maskRect.width();
    int height = getHeight();

    final int edgeColor = reduceColorAlphaValueToZero(shimmerColor);
    LinearGradient gradient = new LinearGradient(
            -maskRect.left, 0,
            width + maskRect.left, 0,
            new int[]{edgeColor, shimmerColor, shimmerColor, edgeColor},
            getGradientColorDistribution(),
            Shader.TileMode.CLAMP);
    Paint paint = new Paint();
    paint.setShader(gradient);

    sourceMaskBitmap = createBitmap(width, height);
    Canvas canvas = new Canvas(sourceMaskBitmap);
    canvas.rotate(shimmerAngle, width / 2, height / 2);
    canvas.drawRect(-maskRect.left, maskRect.top, width + maskRect.left, maskRect.bottom, paint);

    return sourceMaskBitmap;
}
项目:spline    文件:HueDrawable.java   
@Override
public void draw(Canvas canvas) {
    Rect b = getBounds();

    Paint huePaint = new Paint();
    huePaint.setShader(new LinearGradient(0, 0, b.width(), 0,
            new int[]{
                    0xFFFF0000,
                    0xFFFFFF00,
                    0xFF00FF00,
                    0xFF00FFFF,
                    0xFF0000FF,
                    0xFFFF00FF,
                    0xFFFF0000
            },
            null,
            Shader.TileMode.REPEAT)
    );
    canvas.drawRect(b, huePaint);
}
项目:Cable-Android    文件:VerticalSlideColorPicker.java   
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
  super.onSizeChanged(w, h, oldw, oldh);

  viewWidth = w;
  viewHeight = h;

  centerX           = viewWidth / 2;
  colorPickerRadius = (viewWidth / 2) - borderWidth;

  colorPickerBody = new RectF(centerX - colorPickerRadius, borderWidth + colorPickerRadius, centerX + colorPickerRadius, viewHeight - (borderWidth + colorPickerRadius));

  LinearGradient gradient = new LinearGradient(0, colorPickerBody.top, 0, colorPickerBody.bottom, colors, null, Shader.TileMode.CLAMP);
  paint.setShader(gradient);

  if (bitmap != null) {
    bitmap.recycle();
  }

  bitmap       = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888);
  bitmapCanvas = new Canvas(bitmap);

  resetToDefault();
}
项目:terminal-seekbar    文件:TerminalSeekBar.java   
/**
 * getting the fields initialized ...
 */
private void initialize() {

    absLeft = getPaddingLeft() + mPaddingSize;
    absRight = getWidth() - getPaddingRight() - mPaddingSize;
    absTop = getPaddingTop() + mPaddingSize;
    absBottom = getHeight() - getPaddingBottom() - mPaddingSize;

    thumbRadius = thumbHeight / 2;
    mPaddingSize = (int) thumbRadius;
    barWidth = absRight - absLeft;

    mSeekBarRect = new Rect(absLeft, absTop, absRight, absTop + barHeight);

    mSeekBarGradient = new LinearGradient(0, 0, mSeekBarRect.width(), 0, mBarColor, mBarColor, Shader.TileMode.MIRROR);
    mBarRectPaint = new Paint();
    mBarRectPaint.setShader(mSeekBarGradient);
    mBarRectPaint.setAntiAlias(true);

    terminalRadius = barHeight / 2 + 5;

}
项目:GitHub    文件:SpanActivity.java   
private void initAnimSpan() {
    mShaderWidth = 64 * density * 4;
    mShader = new LinearGradient(0, 0,
            mShaderWidth, 0,
            getResources().getIntArray(R.array.rainbow),
            null,
            Shader.TileMode.REPEAT);
    matrix = new Matrix();

    mBlurMaskFilterSpan = new BlurMaskFilterSpan(25);

    mShadowSpan = new ShadowSpan(8, 8, 8, Color.WHITE);

    mForegroundAlphaColorSpan = new ForegroundAlphaColorSpan(Color.TRANSPARENT);

    mForegroundAlphaColorSpanGroup = new ForegroundAlphaColorSpanGroup(0);

    mPrinterString = "打印动画,后面的文字是为了测试打印效果...";

    mSpanUtils = new SpanUtils()
            .appendLine("彩虹动画").setFontSize(64, true).setShader(mShader)
            .appendLine("模糊动画").setFontSize(64, true).setSpans(mBlurMaskFilterSpan)
            .appendLine("阴影动画").setFontSize(64, true).setBackgroundColor(Color.BLACK).setSpans(mShadowSpan)
            .appendLine("透明动画").setFontSize(64, true).setSpans(mForegroundAlphaColorSpan);
    for (int i = 0, len = mPrinterString.length(); i < len; ++i) {
        ForegroundAlphaColorSpan span = new ForegroundAlphaColorSpan(Color.TRANSPARENT);
        mSpanUtils.append(mPrinterString.substring(i, i + 1)).setSpans(span);
        mForegroundAlphaColorSpanGroup.addSpan(span);
    }
    animSsb = mSpanUtils.create();
}
项目:Android-UtilCode    文件:ImageUtils.java   
/**
 * 添加倒影
 *
 * @param src              源图片的
 * @param reflectionHeight 倒影高度
 * @param recycle          是否回收
 * @return 带倒影图片
 */
public static Bitmap addReflection(Bitmap src, int reflectionHeight, boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    // 原图与倒影之间的间距
    final int REFLECTION_GAP = 0;
    int srcWidth = src.getWidth();
    int srcHeight = src.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionBitmap = Bitmap.createBitmap(src, 0, srcHeight - reflectionHeight,
            srcWidth, reflectionHeight, matrix, false);
    Bitmap ret = Bitmap.createBitmap(srcWidth, srcHeight + reflectionHeight, src.getConfig());
    Canvas canvas = new Canvas(ret);
    canvas.drawBitmap(src, 0, 0, null);
    canvas.drawBitmap(reflectionBitmap, 0, srcHeight + REFLECTION_GAP, null);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    LinearGradient shader = new LinearGradient(0, srcHeight,
            0, ret.getHeight() + REFLECTION_GAP,
            0x70FFFFFF, 0x00FFFFFF, Shader.TileMode.MIRROR);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.DST_IN));
    canvas.drawRect(0, srcHeight + REFLECTION_GAP,
            srcWidth, ret.getHeight(), paint);
    if (!reflectionBitmap.isRecycled()) reflectionBitmap.recycle();
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
项目:HeadlineNews    文件:ImageUtils.java   
/**
 * 添加倒影
 *
 * @param src              源图片的
 * @param reflectionHeight 倒影高度
 * @param recycle          是否回收
 * @return 带倒影图片
 */
public static Bitmap addReflection(final Bitmap src, final int reflectionHeight, final boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    // 原图与倒影之间的间距
    final int REFLECTION_GAP = 0;
    int srcWidth = src.getWidth();
    int srcHeight = src.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionBitmap = Bitmap.createBitmap(src, 0, srcHeight - reflectionHeight,
            srcWidth, reflectionHeight, matrix, false);
    Bitmap ret = Bitmap.createBitmap(srcWidth, srcHeight + reflectionHeight, src.getConfig());
    Canvas canvas = new Canvas(ret);
    canvas.drawBitmap(src, 0, 0, null);
    canvas.drawBitmap(reflectionBitmap, 0, srcHeight + REFLECTION_GAP, null);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    LinearGradient shader = new LinearGradient(0, srcHeight,
            0, ret.getHeight() + REFLECTION_GAP,
            0x70FFFFFF, 0x00FFFFFF, Shader.TileMode.MIRROR);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    canvas.drawRect(0, srcHeight + REFLECTION_GAP,
            srcWidth, ret.getHeight(), paint);
    if (!reflectionBitmap.isRecycled()) reflectionBitmap.recycle();
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
项目:phonk    文件:PCanvas.java   
@ProtoMethod(description = "Create a linear shader", example = "")
@ProtoMethodParam(params = {"x1", "y1", "x2", "y2", "colorHex1", "colorHex2", "tileMode"})
public Shader linearShader(float x1, float y1, float x2, float y2, String c1, String c2) {
    Shader.TileMode mode = Shader.TileMode.REPEAT;

    Shader shader = new LinearGradient(x1, y1, x2, y2, Color.parseColor(c1), Color.parseColor(c2), mode);
    return shader;
}
项目:MyCalendar    文件:FloatingActionButtonLibrary.java   
private Drawable createInnerStrokesDrawable(final int color, float strokeWidth) {
  if (!mStrokeVisible) {
    return new ColorDrawable(Color.TRANSPARENT);
  }

  ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());

  final int bottomStrokeColor = darkenColor(color);
  final int bottomStrokeColorHalfTransparent = halfTransparent(bottomStrokeColor);
  final int topStrokeColor = lightenColor(color);
  final int topStrokeColorHalfTransparent = halfTransparent(topStrokeColor);

  final Paint paint = shapeDrawable.getPaint();
  paint.setAntiAlias(true);
  paint.setStrokeWidth(strokeWidth);
  paint.setStyle(Style.STROKE);
  shapeDrawable.setShaderFactory(new ShaderFactory() {
    @Override
    public Shader resize(int width, int height) {
      return new LinearGradient(width / 2, 0, width / 2, height,
          new int[] { topStrokeColor, topStrokeColorHalfTransparent, color, bottomStrokeColorHalfTransparent, bottomStrokeColor },
          new float[] { 0f, 0.2f, 0.5f, 0.8f, 1f },
          TileMode.CLAMP
      );
    }
  });

  return shapeDrawable;
}
项目:WaveAudioVizualization    文件:VoiceWaveView.java   
@Override
    public void surfaceChanged(SurfaceHolder surfaceHolder, int format, int w, int h) {
        mHeight = h;
        mMaxAmpl = h / 2;
//        mCurrentAmpl = mMaxAmpl;
        mWidth = w;
        mPaints.get(0).setShader(new LinearGradient(0, 0, mWidth, mHeight, Color.parseColor("#CA67B7"), Color.parseColor("#C081C1"), Shader.TileMode.MIRROR));
        mPaints.get(0).setStrokeWidth(ScreenUtils.dp2px(getContext(), 2));
        mPaints.get(1).setColor(Color.parseColor("#D5E3FA"));
        mPaints.get(1).setStrokeWidth(ScreenUtils.dp2px(getContext(), 2));
        mPaints.get(2).setStrokeWidth(ScreenUtils.dp2px(getContext(), 1));
        mPaints.get(3).setStrokeWidth(ScreenUtils.dp2px(getContext(), 1));
        mPaints.get(2).setShader(new LinearGradient(0, 0, mWidth, mHeight, Color.parseColor("#E67EA5"), Color.parseColor("#7F7AE1"), Shader.TileMode.MIRROR));
        mPaints.get(3).setShader(new LinearGradient(0, 0, mWidth, mHeight, Color.parseColor("#E67EA5"), Color.parseColor("#7F7AE1"), Shader.TileMode.MIRROR));
    }
项目:YGuider    文件:MainActivity.java   
private Paint getPaint() {
    Paint p = new Paint();
    p.setStyle(Paint.Style.STROKE);
    p.setStrokeWidth(10);
    p.setShader(new LinearGradient(0, 0, 10, 10, Color.YELLOW, Color.RED, Shader.TileMode.REPEAT));
    p.setColor(Color.BLUE);
    return p;
}
项目:RLibrary    文件:ImageUtils.java   
/**
 * 添加倒影
 *
 * @param src              源图片的
 * @param reflectionHeight 倒影高度
 * @param recycle          是否回收
 * @return 带倒影图片
 */
public static Bitmap addReflection(Bitmap src, int reflectionHeight, boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    // 原图与倒影之间的间距
    final int REFLECTION_GAP = 0;
    int srcWidth = src.getWidth();
    int srcHeight = src.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionBitmap = Bitmap.createBitmap(src, 0, srcHeight - reflectionHeight,
            srcWidth, reflectionHeight, matrix, false);
    Bitmap ret = Bitmap.createBitmap(srcWidth, srcHeight + reflectionHeight, src.getConfig());
    Canvas canvas = new Canvas(ret);
    canvas.drawBitmap(src, 0, 0, null);
    canvas.drawBitmap(reflectionBitmap, 0, srcHeight + REFLECTION_GAP, null);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    LinearGradient shader = new LinearGradient(0, srcHeight,
            0, ret.getHeight() + REFLECTION_GAP,
            0x70FFFFFF, 0x00FFFFFF, Shader.TileMode.MIRROR);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    canvas.drawRect(0, srcHeight + REFLECTION_GAP,
            srcWidth, ret.getHeight(), paint);
    if (!reflectionBitmap.isRecycled()) reflectionBitmap.recycle();
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
项目:planetcon    文件:ColorPicker.java   
private void drawColorDiamond(Canvas canvas, double hueAngle, double radius) {
    int pureColor, brightColor, darkColor;
    double leftAngle = hueAngle + Math.toRadians(120);
    double rightAngle = hueAngle - Math.toRadians(120);

    float tipAngleX = xToDraw(Math.cos(hueAngle) * radius);
    float tipAngleY = yToDraw(Math.sin(hueAngle) * radius);
    float leftAngleX = xToDraw(Math.cos(leftAngle) * radius);
    float leftAngleY = yToDraw(Math.sin(leftAngle) * radius);
    float rightAngleX = xToDraw(Math.cos(rightAngle) * radius);
    float rightAngleY = yToDraw(Math.sin(rightAngle) * radius);

    mTrianglePath.reset();
    mTrianglePath.moveTo(tipAngleX, tipAngleY);
    mTrianglePath.lineTo(rightAngleX, rightAngleY);
    mTrianglePath.lineTo(leftAngleX, leftAngleY);
    mTrianglePath.lineTo(tipAngleX, tipAngleY);

    // pureColor
    mHSV[0] = mColorHSV[0];
    mHSV[1] = 1; mHSV[2] = 1;
    pureColor = Color.HSVToColor(mHSV);
    // brightColor
    mHSV[1] = 0; mHSV[2] = 1;
    brightColor = Color.HSVToColor(mHSV);
    // darkColor
    mHSV[1] = 1; mHSV[2] = 0;
    darkColor = Color.HSVToColor(mHSV);

    Shader gradient1 = new LinearGradient(leftAngleX, leftAngleY, tipAngleX, tipAngleY, brightColor, pureColor, TileMode.CLAMP);
    Shader gradient2 = new LinearGradient(leftAngleX, leftAngleY, rightAngleX, rightAngleY, brightColor, darkColor, TileMode.CLAMP);
    ComposeShader composeShader = new ComposeShader(gradient1, gradient2, PorterDuff.Mode.MULTIPLY);

    mColorPaint.setShader(composeShader);
    canvas.drawPath(mTrianglePath, mColorPaint);
}
项目:Building-Android-UIs-with-Custom-Views    文件:OwnCustomView.java   
@Override
protected void onDraw(Canvas canvas) {
    if (needsUpdate) {
        int[] colors = new int[] {topLeftColor, topRightColor, bottomRightColor, bottomLeftColor};

        LinearGradient lg = new LinearGradient(0, 0, getWidth(), getHeight(), colors, null, Shader.TileMode.CLAMP);
        backgroundPaint.setShader(lg);
        needsUpdate = false;
    }

    canvas.drawRect(0, 0, getWidth(), getHeight(), backgroundPaint);
    super.onDraw(canvas);
}
项目:boohee_v5.6    文件:DayView.java   
private static Drawable generateCircleDrawable(final int color) {
    ShapeDrawable drawable = new ShapeDrawable(new OvalShape());
    drawable.setShaderFactory(new ShaderFactory() {
        public Shader resize(int width, int height) {
            return new LinearGradient(0.0f, 0.0f, 0.0f, 0.0f, color, color, TileMode.REPEAT);
        }
    });
    return drawable;
}
项目:snippety    文件:MultiColorSpan.java   
@Override
public void updateDrawState(TextPaint paint) {
    paint.setStyle(Paint.Style.FILL);
    Shader shader = new LinearGradient(0, 0, 0, paint.getTextSize() * colors.length, colors, null,
            Shader.TileMode.MIRROR);
    Matrix matrix = new Matrix();
    matrix.setRotate(angle);
    shader.setLocalMatrix(matrix);
    paint.setShader(shader);
}
项目:ChangeTabLayout    文件:ChangeTabStrip.java   
/**
 * 绘制左边阴影
 */
private void drawShadow(Canvas canvas){
    final float width = shadowWidth * (1 - selectionOffsetX);
    LinearGradient linearGradient = new LinearGradient(0, getHeight(), width, getHeight(), new int[] {shadowColor, Color.TRANSPARENT}, new float[]{shadowProportion, 1f}, Shader.TileMode.CLAMP);
    shadowPaint.setShader(linearGradient);
    canvas.drawRect(0, 0, width, getHeight(), shadowPaint);
}
项目:BBSSDK-for-Android    文件:ImageUtils.java   
/**
 * 添加倒影
 *
 * @param src              源图片的
 * @param reflectionHeight 倒影高度
 * @param recycle          是否回收
 * @return 带倒影图片
 */
public static Bitmap addReflection(final Bitmap src, final int reflectionHeight, final boolean recycle) {
    if (isEmptyBitmap(src)) {
        return null;
    }
    // 原图与倒影之间的间距
    final int reflectiongap = 0;
    int srcWidth = src.getWidth();
    int srcHeight = src.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionBitmap = Bitmap.createBitmap(src, 0, srcHeight - reflectionHeight,
            srcWidth, reflectionHeight, matrix, false);
    Bitmap ret = Bitmap.createBitmap(srcWidth, srcHeight + reflectionHeight, src.getConfig());
    Canvas canvas = new Canvas(ret);
    canvas.drawBitmap(src, 0, 0, null);
    canvas.drawBitmap(reflectionBitmap, 0, srcHeight + reflectiongap, null);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    LinearGradient shader = new LinearGradient(
            0, srcHeight,
            0, ret.getHeight() + reflectiongap,
            0x70FFFFFF,
            0x00FFFFFF,
            Shader.TileMode.MIRROR);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.DST_IN));
    canvas.drawRect(0, srcHeight + reflectiongap, srcWidth, ret.getHeight(), paint);
    if (!reflectionBitmap.isRecycled()) {
        reflectionBitmap.recycle();
    }
    if (recycle && !src.isRecycled()) {
        src.recycle();
    }
    return ret;
}
项目:IdealMedia    文件:MediaUtils.java   
public static Bitmap modifyTrackCellArtworkBitmap(Bitmap source){
    if (source == null)
        return null;

    int w = source.getWidth();
    int h = source.getHeight();

    Bitmap scaled = Bitmap.createScaledBitmap(source, w, h, true);

    w = scaled.getWidth();
    h = scaled.getHeight();

    Bitmap overlay = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(overlay);
    final Paint paint = new Paint();

    canvas.drawBitmap(scaled, 0, 0, null);

    Shader shader = new LinearGradient(
            0, 0, h, 0,
            0x00FFFFFF, 0x77FFFFFF,
            Shader.TileMode.CLAMP
    );

    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));

    canvas.drawRect(0, 0, w, h, paint);

    return overlay;
}
项目:SafeView    文件:SafeView.java   
private void init() {
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setStrokeCap(Paint.Cap.ROUND);// 圆角笔触
    mLeftLinearGradient = new LinearGradient(0, 0, mCy - OFFSET, mCy - OFFSET, 0xddffffff, 0x00000000, Shader.TileMode.CLAMP);
    mRightLinearGradient = new LinearGradient(mCy - OFFSET, mCy / 2, 0, mCy / 2, 0xddffffff, 0x00000000, Shader.TileMode.CLAMP);
}
项目:SmartChart    文件:LineChartRenderer.java   
private void drawArea(Canvas canvas, Line line) {
    final int lineSize = line.getValues().size();
    if (lineSize < 2) {
        //No point to draw area for one point or empty line.
        return;
    }

    final Rect contentRect = computator.getContentRectMinusAllMargins();
    final float baseRawValue = Math.min(contentRect.bottom, Math.max(computator.computeRawY(baseValue),
            contentRect.top));
    //That checks works only if the last point is the right most one.
    final float left = Math.max(computator.computeRawX(line.getValues().get(0).getX()), contentRect.left);
    final float right = Math.min(computator.computeRawX(line.getValues().get(lineSize - 1).getX()),
            contentRect.right);

    path.lineTo(right, baseRawValue);
    path.lineTo(left, baseRawValue);
    path.close();

    linePaint.setStyle(Paint.Style.FILL);
    linePaint.setAlpha(line.getAreaTransparency());
    linePaint.setShader(line.getGradientToTransparent() ?
            new LinearGradient(0, 0, 0, canvas.getHeight(), line.getColor(),
                    line.getColor() & 0x00ffffff, Shader.TileMode.MIRROR) :
            null);
    canvas.drawPath(path, linePaint);
    linePaint.setStyle(Paint.Style.STROKE);
}
项目:Oblique    文件:Config.java   
public Shader getLinearGradient(GradientAngle gradientAngle, float width, float height) {
    float x1 = 0, x2 = 0, y1 = 0, y2 = 0;
    switch (gradientAngle) {
        case LEFT_TO_RIGHT:
            x2 = width;
            break;
        case RIGHT_TO_LEFT:
            x1 = width;
            break;
        case TOP_TO_BOTTOM:
            y2 = height;
            break;
        case BOTTOM_TO_TOP:
            y1 = height;
            break;
        case LEFT_TOP_TO_RIGHT_BOTTOM:
            x2 = width;
            y2 = height;
            break;
        case RIGHT_BOTTOM_TO_LEFT_TOP:
            x1 = width;
            y1 = height;
            break;
        case LEFT_BOTTOM_TO_RIGHT_TOP:
            x2 = width;
            y1 = height;
            break;
        case RIGHT_TOP_TO_LEFT_BOTTOM:
            x1 = width;
            y2 = height;
            break;
    }
    return new LinearGradient(x1, y1, x2, y2, startColor, endColor, Shader.TileMode.CLAMP);
}
项目:gradient-progress    文件:GradientProgress.java   
private LinearGradient getNewGradient(float barHeight, int color) {
    return new LinearGradient(
            0,
            0,
            0,
            barHeight,
            color,
            getScaledColor(color, GRADIENT_SCALE),
            Shader.TileMode.CLAMP);
}
项目:LJFramework    文件:ImageUtils.java   
/**
 * 添加倒影
 *
 * @param src 源图片的
 * @param reflectionHeight 倒影高度
 * @param recycle 是否回收
 * @return 带倒影图片
 */
public static Bitmap addReflection(Bitmap src, int reflectionHeight, boolean recycle) {
    if (isEmptyBitmap(src)) {
        return null;
    }
    // 原图与倒影之间的间距
    final int REFLECTION_GAP = 0;
    int srcWidth = src.getWidth();
    int srcHeight = src.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionBitmap = Bitmap.createBitmap(src, 0, srcHeight -
            reflectionHeight, srcWidth, reflectionHeight, matrix, false);
    Bitmap ret = Bitmap.createBitmap(srcWidth,
            srcHeight + reflectionHeight, src.getConfig());
    Canvas canvas = new Canvas(ret);
    canvas.drawBitmap(src, 0, 0, null);
    canvas.drawBitmap(reflectionBitmap, 0,
            srcHeight + REFLECTION_GAP, null);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    LinearGradient shader = new LinearGradient(0, srcHeight, 0,
            ret.getHeight() +
                    REFLECTION_GAP, 0x70FFFFFF, 0x00FFFFFF, Shader.TileMode.MIRROR);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.DST_IN));
    canvas.drawRect(0,
            srcHeight + REFLECTION_GAP, srcWidth, ret.getHeight(), paint);
    if (!reflectionBitmap.isRecycled()) {
        reflectionBitmap.recycle();
    }
    if (recycle && !src.isRecycled()) {
        src.recycle();
    }
    return ret;
}
项目:PlusGram    文件:ColorPicker.java   
@SuppressLint("DrawAllocation")
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    int width = right - left;
    int height = bottom - top;

    int backHeight = getMeasuredHeight() - AndroidUtilities.dp(26) - AndroidUtilities.dp(64);
    gradientPaint.setShader(new LinearGradient(0, AndroidUtilities.dp(26), 0, backHeight + AndroidUtilities.dp(26), COLORS, LOCATIONS, Shader.TileMode.REPEAT));
    int x = width - AndroidUtilities.dp(26) - AndroidUtilities.dp(8);
    int y = AndroidUtilities.dp(26);
    rectF.set(x, y, x + AndroidUtilities.dp(8), y + backHeight);

    settingsButton.layout(width - settingsButton.getMeasuredWidth(), height - AndroidUtilities.dp(52), width, height);
}
项目:android-audio-visualizer    文件:BlazingColorVisualizer.java   
@Override
protected void init() {
    shader = new LinearGradient(0,
            0,
            0,
            getHeight(),
            Color.BLUE,
            Color.GREEN,
            Shader.TileMode.MIRROR /*or REPEAT*/);
}
项目:lineagex86    文件:ColorPickerView.java   
private void drawAlphaPanel(Canvas canvas) {
    if (!mShowAlphaPanel || mAlphaRect == null || mAlphaPattern == null) {
        return;
    }

    final RectF rect = mAlphaRect;

    if (BORDER_WIDTH_PX > 0) {
        mBorderPaint.setColor(mBorderColor);
        canvas.drawRect(rect.left - BORDER_WIDTH_PX,
                rect.top - BORDER_WIDTH_PX,
                rect.right + BORDER_WIDTH_PX,
                rect.bottom + BORDER_WIDTH_PX,
                mBorderPaint);
    }

    mAlphaPattern.draw(canvas);

    float[] hsv = new float[] {
            mHue, mSat, mVal
    };
    int color = Color.HSVToColor(hsv);
    int acolor = Color.HSVToColor(0, hsv);

    mAlphaShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top,
            color, acolor, TileMode.CLAMP);

    mAlphaPaint.setShader(mAlphaShader);

    canvas.drawRect(rect, mAlphaPaint);

    if (mAlphaSliderText != null && mAlphaSliderText != "") {
        canvas.drawText(mAlphaSliderText, rect.centerX(), rect.centerY() + 4 * mDensity,
                mAlphaTextPaint);
    }

    float rectWidth = 4 * mDensity / 2;
    Point p = alphaToPoint(mAlpha);

    RectF r = new RectF();
    r.left = p.x - rectWidth;
    r.right = p.x + rectWidth;
    r.top = rect.top - RECTANGLE_TRACKER_OFFSET;
    r.bottom = rect.bottom + RECTANGLE_TRACKER_OFFSET;

    canvas.drawRoundRect(r, 2, 2, mHueTrackerPaint);
}