package
kr.co.test;
import
java.util.ArrayList;
import
android.content.Context;
import
android.graphics.Canvas;
import
android.graphics.Color;
import
android.graphics.Paint;
import
android.util.Log;
import
android.view.MotionEvent;
import
android.view.View;
public
class
SignView
extends
View
{
Paint p =
new
Paint();
ArrayList<Vertex> list =
new
ArrayList<Vertex>();
public
int
count;
public
SignView(Context context)
{
super
(context);
p.setColor(Color.BLACK);
p.setAntiAlias(
true
);
p.setStrokeWidth(
5
);
count =
0
;
}
public
class
Vertex
{
public
Vertex(
float
x,
float
y,
boolean
stat)
{
this
.x = x;
this
.y = y;
this
.stat = stat;
}
float
x;
float
y;
boolean
stat;
}
@Override
public
void
onDraw(Canvas can)
{
can.drawColor(Color.TRANSPARENT);
for
(
int
i =
0
; i < list.size() ; i++)
{
Vertex v = list.get(i);
if
(v.stat ==
true
)
{
can.drawLine(list.get(i -
1
).x, list.get(i -
1
).y, list.get(i).x, list.get(i).y, p);
}
}
}
@Override
public
boolean
onTouchEvent(MotionEvent e)
{
count++;
if
(e.getAction() == MotionEvent.ACTION_DOWN)
{
list.add(
new
Vertex(e.getX(), e.getY(),
false
));
}
if
(e.getAction() == MotionEvent.ACTION_MOVE)
{
list.add(
new
Vertex(e.getX(), e.getY(),
true
));
invalidate();
}
return
true
;
}
}