Java Code Examples for android.graphics.Path#offset()

The following examples show how to use android.graphics.Path#offset() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CanvasPainter.java    From cythara with GNU General Public License v3.0 6 votes vote down vote up
private void drawIndicator() {
    float xPos = x + (getNearestDeviation() * gaugeWidth / MAX_DEVIATION);
    float yPosition = y * 1.15f;

    Matrix matrix = new Matrix();
    float scalingFactor = numbersPaint.getTextSize() / 3;
    matrix.setScale(scalingFactor, scalingFactor);

    Path indicator = new Path();
    indicator.moveTo(0, -2);
    indicator.lineTo(1, 0);
    indicator.lineTo(-1, 0);
    indicator.close();

    indicator.transform(matrix);

    indicator.offset(xPos, yPosition);
    canvas.drawPath(indicator, gaugePaint);
}
 
Example 2
Source File: PathInfo.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
PathInfo(Path path, float width, float height) {
    this.path = path;

    float tmpWidth = width;
    float tmpHeight = height;
    RectF bounds = new RectF();
    path.computeBounds(bounds, true);
    if(width <= 0 && height <= 0) {
        tmpWidth = (float) Math.ceil(bounds.width());
        tmpHeight = (float) Math.ceil(bounds.height());
        path.offset(-1 * (float) Math.floor(bounds.left),
                -1 * (float) Math.round(bounds.top));
    }

    this.width = tmpWidth;
    this.height = tmpHeight;
}
 
Example 3
Source File: PathInfo.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
PathInfo(Path path, float width, float height) {
    this.path = path;

    float tmpWidth = width;
    float tmpHeight = height;
    RectF bounds = new RectF();
    path.computeBounds(bounds, true);
    if(width <= 0 && height <= 0) {
        tmpWidth = (float) Math.ceil(bounds.width());
        tmpHeight = (float) Math.ceil(bounds.height());
        path.offset(-1 * (float) Math.floor(bounds.left),
                -1 * (float) Math.round(bounds.top));
    }

    this.width = tmpWidth;
    this.height = tmpHeight;
}
 
Example 4
Source File: CardBgTest.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
private void doGenCardBg(OutputStream os, int color, float radius, float base,
        float topAlpha, float topOffset, float topBlur,
        float bottomAlpha, float bottomOffset, float bottomBlur) throws FileNotFoundException {

    Path path = getPath(radius, base);
    path.offset(MAX_SIZE / 2, MAX_SIZE / 2);

    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    paint.setColor(color);
    Bitmap bitmap = Bitmap.createBitmap(MAX_SIZE, MAX_SIZE, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    // Draw bottom
    paint.setShadowLayer(bottomBlur, 0, bottomOffset, getColor(bottomAlpha));
    canvas.drawPath(path, paint);

    // Draw top
    paint.setShadowLayer(topBlur, 0, topOffset, getColor(topAlpha));
    canvas.drawPath(path, paint);

    bitmap.compress(Bitmap.CompressFormat.PNG, 100, os);
}
 
Example 5
Source File: Gesture.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a bitmap of the gesture with a transparent background.
 * 
 * @param width
 * @param height
 * @param inset
 * @param color
 * @return the bitmap
 */
public Bitmap toBitmap(int width, int height, int inset, int color) {
    final Bitmap bitmap = Bitmap.createBitmap(width, height,
            Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(bitmap);

    final Paint paint = new Paint();
    paint.setAntiAlias(BITMAP_RENDERING_ANTIALIAS);
    paint.setDither(BITMAP_RENDERING_DITHER);
    paint.setColor(color);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeJoin(Paint.Join.ROUND);
    paint.setStrokeCap(Paint.Cap.ROUND);
    paint.setStrokeWidth(BITMAP_RENDERING_WIDTH);

    final Path path = toPath();
    final RectF bounds = new RectF();
    path.computeBounds(bounds, true);

    final float sx = (width - 2 * inset) / bounds.width();
    final float sy = (height - 2 * inset) / bounds.height();
    final float scale = sx > sy ? sy : sx;
    paint.setStrokeWidth(2.0f / scale);

    path.offset(-bounds.left + (width - bounds.width() * scale) / 2.0f,
            -bounds.top + (height - bounds.height() * scale) / 2.0f);

    canvas.translate(inset, inset);
    canvas.scale(scale, scale);

    canvas.drawPath(path, paint);

    return bitmap;
}
 
Example 6
Source File: WaveHelper.java    From zone-sdk with MIT License 5 votes vote down vote up
private Bitmap getWave() {
    int count = (int) Math.ceil(width / mLength);

    canvas.drawColor(Color.YELLOW, PorterDuff.Mode.CLEAR);

    Path path = new Path();
    path.moveTo(0, 0);
    for (int i = 0; i < count * 2; i++) {
        path.quadTo(mLength / 4 + i * mLength, mAmplitude * 2, mLength / 2 + i * mLength, 0);
        path.quadTo(mLength * 3 / 4 + i * mLength, -mAmplitude * 2, mLength + i * mLength, 0);
    }
    //rectf.height()+mAmplitude 是因为进度为100的时候 下面不会出现暴露的假象
    path.rLineTo(0, height + mAmplitude);
    path.rLineTo(-count * 2 * mLength, 0);
    path.close();


    //弄到进度为0的位置
    path.offset(0, height + mAmplitude);
    //通过进度计算应该往上偏移多少
    float progressOffset = (height + mAmplitude * 2) * mLevelProgress;
    path.offset(0, -progressOffset);

    //计算水平速度
    path.offset(-speedOffsetX - offsetXRadioOfLength * mLength, 0);
    canvas.drawPath(path, mPaint);
    return waveBitmap;
}
 
Example 7
Source File: FontDrawable.java    From FontDrawable with Apache License 2.0 5 votes vote down vote up
private void applyOffset(Path path, RectF textBounds) {
    Rect viewBounds = getBounds();
    float startX = viewBounds.centerX() - (textBounds.width() / 2);
    float offsetX = startX - textBounds.left;
    float startY = viewBounds.centerY() - (textBounds.height() / 2);
    float offsetY = startY - (textBounds.top);
    path.offset(offsetX, offsetY);
}
 
Example 8
Source File: SafeTranslatedPath.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void addPath(Path src, float dx, float dy) {
    boolean safePath = src instanceof SafeTranslatedPath;
    if (!safePath) {
        src.offset(xOffset, yOffset);
    }
    super.addPath(src, dx, dy);
    if (!safePath) {
        src.offset(-xOffset, -yOffset);
    }
}
 
Example 9
Source File: SafeTranslatedPath.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void addPath(Path src) {
    boolean safePath = src instanceof SafeTranslatedPath;
    if (!safePath) {
        src.offset(xOffset, yOffset);
    }
    super.addPath(src);
    if (!safePath) {
        src.offset(-xOffset, -yOffset);
    }
}
 
Example 10
Source File: SquareClippingTransform.java    From AndroidFillableLoaders with Apache License 2.0 4 votes vote down vote up
@Override public void transform(Canvas canvas, float currentFillPhase, View view) {
  cacheDimensions(view.getWidth(), view.getHeight());
  Path path = buildClippingPath();
  path.offset(0, height * -currentFillPhase);
  canvas.clipPath(path, Region.Op.DIFFERENCE);
}
 
Example 11
Source File: BitesClippingTransform.java    From AndroidFillableLoaders with Apache License 2.0 4 votes vote down vote up
@Override public void transform(Canvas canvas, float currentFillPhase, View view) {
  cacheDimensions(view.getWidth(), view.getHeight());
  Path path = buildClippingPath();
  path.offset(0, height * -currentFillPhase);
  canvas.clipPath(path, Region.Op.DIFFERENCE);
}