Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
ToogleDrawableDown draw a triangle using drawable
package com.ui;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.Path.FillType;
import android.graphics.Point;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.util.Log;
public class ToogleDrawableDown extends Drawable {
public ToogleDrawableDown() {}
@Override
public void draw(Canvas canvas) {
// Set the correct values in the Paint
Paint paint = new Paint();
paint.setColor(android.graphics.Color.TRANSPARENT);
paint.setStyle(Paint.Style.FILL);
canvas.drawPaint(paint);
int stroke = 4;
int paddingLeft =10;
double TriBottom = 8.3;
double TriHeight = 8.8;
paint.setStrokeWidth(4);
paint.setColor(android.graphics.Color.RED);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setAntiAlias(true);
Point a = new Point(paddingLeft+0+stroke, Math.max(canvas.getHeight()/3*2-(int)TriHeight-stroke,0));
Point b = new Point(paddingLeft+(int)TriBottom*2 +stroke, Math.max(canvas.getHeight()/3*2-(int)TriHeight-stroke,0));
Point c = new Point(paddingLeft+(int)TriBottom+stroke, Math.max(canvas.getHeight()/3*2-stroke,0));
Path path = new Path();
path.setFillType(FillType.EVEN_ODD);
path.moveTo(a.x, a.y);
path.lineTo(b.x, b.y);
path.lineTo(c.x, c.y);
path.lineTo(a.x, a.y);
path.close();
canvas.drawPath(path, paint);
}
@Override
public void setAlpha(int alpha) {}
@Override
public void setColorFilter(ColorFilter cf) {}
@Override
public int getOpacity() {
// TODO Auto-generated method stub
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment