CuneiPainter  Version 1.2
DrawingCanvas Class Reference

Canvas for drawing lines that indicate cuneiform characters. More...

Inheritance diagram for DrawingCanvas:
Collaboration diagram for DrawingCanvas:

Public Member Functions

 DrawingCanvas (Context c, AttributeSet attrs)
 Constructor for this class. More...
 
void undoPath ()
 
void redoPath ()
 
void setOnLongClickListener (@Nullable OnLongClickListener l)
 
boolean onTouchEvent (MotionEvent event)
 

Public Attributes

List< LineParameterslines = new LinkedList<>()
 
List< String > strokes = new LinkedList<>()
 
int width
 
int height
 

Protected Member Functions

void onSizeChanged (int w, int h, int oldw, int oldh)
 
void onDraw (Canvas canvas)
 

Package Functions

void clearCanvas ()
 Clears the canvas. More...
 

Package Attributes

Integer a =0
 
Integer b =0
 
Integer c =0
 
Integer d =0
 
Integer s =0
 
Integer left =0
 
Integer right =0
 
Integer up =0
 
Integer down =0
 
String paleocodage =""
 
float mY
 

Private Member Functions

void startTouch (float x, float y)
 
void moveTouch (float x, float y)
 
void upTouch ()
 

Private Attributes

Canvas mCanvas
 
float startX
 
float startY
 
Path mPath
 
CuneiPainter context
 
Paint mPaint
 
float mX
 
List< Path > paths
 
List< Path > undonepaths
 

Static Private Attributes

static final float TOLERANCE = 5
 

Detailed Description

Canvas for drawing lines that indicate cuneiform characters.

Constructor & Destructor Documentation

DrawingCanvas ( Context  c,
AttributeSet  attrs 
)

Constructor for this class.

Parameters
cthe context of this canvas
attrsthe attributes to consider

References DrawingCanvas.context, DrawingCanvas.mPaint, and DrawingCanvas.mPath.

42  {
43  super(c, attrs);
44  this.paths=new ArrayList<>();
45  this.undonepaths=new ArrayList<>();
46  context = (CuneiPainter)c;
47 
48  // we set a new Path
49  mPath = new Path();
50 
51  // and we set a new Paint with the desired attributes
52  mPaint = new Paint();
53  mPaint.setAntiAlias(true);
54  mPaint.setColor(Color.RED);
55  mPaint.setStyle(Paint.Style.STROKE);
56  mPaint.setStrokeJoin(Paint.Join.ROUND);
57  mPaint.setStrokeCap(Paint.Cap.ROUND);
58  mPaint.setStrokeWidth(20);
59  this.mCanvas=new Canvas();
60  }
Paint mPaint
Definition: DrawingCanvas.java:31
Path mPath
Definition: DrawingCanvas.java:29
Integer c
Definition: DrawingCanvas.java:20
CuneiPainter context
Definition: DrawingCanvas.java:30

Member Function Documentation

void clearCanvas ( )
package

Clears the canvas.

References DrawingCanvas.paths.

135  {
136  for(Path p:this.paths){
137  p.reset();
138  }
139  this.paths.clear();
140  this.paleocodage="";
141  this.lines.clear();
142  stroketypeLength.clear();
143  invalidate();
144  }
List< Path > paths
Definition: DrawingCanvas.java:34
void moveTouch ( float  x,
float  y 
)
private

References DrawingCanvas.mX, DrawingCanvas.mY, and DrawingCanvas.TOLERANCE.

Referenced by DrawingCanvas.onTouchEvent().

122  {
123  float dx = Math.abs(x - mX);
124  float dy = Math.abs(y - mY);
125  if (dx >= TOLERANCE || dy >= TOLERANCE) {
126  mPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
127  mX = x;
128  mY = y;
129  }
130  }
static final float TOLERANCE
Definition: DrawingCanvas.java:33
float mX
Definition: DrawingCanvas.java:32
float mY
Definition: DrawingCanvas.java:32
void onDraw ( Canvas  canvas)
protected

References DrawingCanvas.mPaint, and DrawingCanvas.paths.

74  {
75  super.onDraw(canvas);
76  // draw the mPath with the mPaint on the canvas when onDraw
77  for(Path p:this.paths){
78  canvas.drawPath(p,mPaint);
79  }
80  }
Paint mPaint
Definition: DrawingCanvas.java:31
List< Path > paths
Definition: DrawingCanvas.java:34
void onSizeChanged ( int  w,
int  h,
int  oldw,
int  oldh 
)
protected
64  {
65  super.onSizeChanged(w, h, oldw, oldh);
66 
67  // your Canvas will draw onto the defined Bitmap
68  Bitmap mBitmap = Bitmap.createBitmap(w <= 0 ? 1 : w, h <= 0 ? 1 : h, Bitmap.Config.ARGB_8888);
69  this.mCanvas = new Canvas(mBitmap);
70  }
boolean onTouchEvent ( MotionEvent  event)

References DrawingCanvas.moveTouch(), DrawingCanvas.startTouch(), and DrawingCanvas.upTouch().

263  {
264  float x = event.getX();
265  float y = event.getY();
266 
267  switch (event.getAction()) {
268  case MotionEvent.ACTION_DOWN:
269  startTouch(x, y);
270  invalidate();
271  break;
272  case MotionEvent.ACTION_MOVE:
273  moveTouch(x, y);
274  invalidate();
275  break;
276  case MotionEvent.ACTION_UP:
277  upTouch();
278  invalidate();
279  break;
280  }
281  return true;
282  }
void moveTouch(float x, float y)
Definition: DrawingCanvas.java:122
void upTouch()
Definition: DrawingCanvas.java:147
void startTouch(float x, float y)
Definition: DrawingCanvas.java:83
void redoPath ( )

References DrawingCanvas.s, and DrawingCanvas.undonepaths.

113  {
114  if(!this.undonepaths.isEmpty()) {
115  paths.add(this.paths.remove(this.paths.size() - 1));
116  invalidate();
117  }
118  s++;
119  }
List< Path > undonepaths
Definition: DrawingCanvas.java:35
Integer s
Definition: DrawingCanvas.java:20
void setOnLongClickListener ( @Nullable OnLongClickListener  l)
256  {
257  super.setOnLongClickListener(l);
258  this.clearCanvas();
259  }
void startTouch ( float  x,
float  y 
)
private

References DrawingCanvas.mX, DrawingCanvas.mY, DrawingCanvas.startX, and DrawingCanvas.startY.

Referenced by DrawingCanvas.onTouchEvent().

83  {
84  undonepaths.clear();
85  mPath.reset();
86  mPath.moveTo(x, y);
87  mX = x;
88  mY = y;
89  startX=x;
90  startY=y;
91  }
float startX
Definition: DrawingCanvas.java:27
float mX
Definition: DrawingCanvas.java:32
float startY
Definition: DrawingCanvas.java:28
float mY
Definition: DrawingCanvas.java:32
void undoPath ( )

References StrokeType.A, DrawingCanvas.a, StrokeType.B, DrawingCanvas.b, StrokeType.C, DrawingCanvas.c, StrokeType.D, DrawingCanvas.d, DrawingCanvas.paths, DrawingCanvas.s, and DrawingCanvas.strokes.

93  {
94  if(!this.paths.isEmpty() && !strokes.isEmpty()) {
95  undonepaths.add(this.paths.remove(this.paths.size() - 1));
96  invalidate();
97  s--;
98  switch(strokes.get(strokes.size()-1)){
99  case "a":--a;stroketypeLength.get(StrokeType.A).remove(stroketypeLength.get(StrokeType.A).size()-1);break;
100  case "b":--b;stroketypeLength.get(StrokeType.B).remove(stroketypeLength.get(StrokeType.B).size()-1);break;
101  case "c":--c;stroketypeLength.get(StrokeType.C).remove(stroketypeLength.get(StrokeType.C).size()-1);break;
102  case "d":--d;stroketypeLength.get(StrokeType.D).remove(stroketypeLength.get(StrokeType.D).size()-1);break;
103  }
104  strokes.remove(strokes.size()-1);
105  this.lines.remove(lines.size()-1);
106  this.paleocodage=LocationCalc.calculateRelation(this.lines);
107  this.context.setStatusText();
108  this.context.lookUp();
109  }
110 
111  }
A
Definition: StrokeType.java:7
List< String > strokes
Definition: DrawingCanvas.java:22
Integer s
Definition: DrawingCanvas.java:20
Integer b
Definition: DrawingCanvas.java:20
C
Definition: StrokeType.java:7
Integer c
Definition: DrawingCanvas.java:20
B
Definition: StrokeType.java:7
D
Definition: StrokeType.java:7
Integer a
Definition: DrawingCanvas.java:20
List< Path > paths
Definition: DrawingCanvas.java:34
Integer d
Definition: DrawingCanvas.java:20
void upTouch ( )
private

References StrokeType.A, DrawingCanvas.a, StrokeType.B, DrawingCanvas.b, StrokeType.C, DrawingCanvas.c, StrokeType.D, DrawingCanvas.d, DrawingCanvas.down, StrokeType.E, StrokeType.F, StrokeType.INV_A, StrokeType.INV_B, DrawingCanvas.left, DrawingCanvas.lines, DrawingCanvas.mPaint, DrawingCanvas.mPath, DrawingCanvas.mX, DrawingCanvas.mY, DrawingCanvas.paleocodage, DrawingCanvas.right, DrawingCanvas.s, DrawingCanvas.startX, DrawingCanvas.startY, and DrawingCanvas.up.

Referenced by DrawingCanvas.onTouchEvent().

147  {
148  mPath.lineTo(mX, mY);
149  //mPath.moveTo(startX, startY);
150  float delta_x = mX - startX;
151  float delta_y = mY - startY;
152 
153  //
154 
155  double m=delta_y/delta_x;
156  double radius = Math.atan(m)*100;
157  System.out.println("Angle: "+radius);
158  ++s;
159  if(radius>140 && radius<200){
160  System.out.println("Detected: A");
161  ++a;
162  strokes.add("a");
163  if(startY>mY){
164  up++;
165 
166  this.lines.add(new LineParameters(startX,startY,mX,mY,delta_x,delta_y,StrokeType.INV_A)); paleocodage=LocationCalc.calculateRelation(lines);
167  //paleocodage+="!a-";
168 
169  }else{
170  down++;
171  this.lines.add(new LineParameters(startX,startY,mX,mY,delta_x,delta_y,StrokeType.A));
172  paleocodage=LocationCalc.calculateRelation(lines);
173  //paleocodage+="a-";
174 
175  }
176  this.context.setStatusText();
177  }else if(radius>-30 && radius<30){
178  System.out.println("Detected: B");
179  ++b;
180  strokes.add("b");
181  if(startX>mX){
182  left++;
183  //paleocodage+="!b-";
184  /*mPath.moveTo(startX+40, startY+50);
185  mPath.lineTo(startX+40, startY+50);
186  mPath.lineTo(startX, startY+45);
187  mPath.lineTo(startX+40, startY+50);*/
188  this.lines.add(new LineParameters(startX,startY,mX,mY,delta_x,delta_y,StrokeType.INV_B));
189  paleocodage=LocationCalc.calculateRelation(lines);
190 
191  }else{
192  //paleocodage+="b-";
193  this.lines.add(new LineParameters(startX,startY,mX,mY,delta_x,delta_y,StrokeType.B));
194  paleocodage=LocationCalc.calculateRelation(lines);
195  right++;
196  /*mPath.moveTo(startX-40, startY+50);
197  mPath.lineTo(startX-40, startY+45);
198  mPath.lineTo(startX, startY+45);
199  mPath.lineTo(startX+40, startY+40);*/
200 
201  }
202  this.context.setStatusText();
203  }else if(radius<-30 && radius>-170){
204  System.out.println("Detected: D");
205  ++d;
206  strokes.add("d");
207  if(startY>mY){
208  up++;
209  this.lines.add(new LineParameters(startX,startY,mX,mY,delta_x,delta_y,StrokeType.C));
210  paleocodage=LocationCalc.calculateRelation(lines);
211  //paleocodage+="c-";
212  /*mPath.moveTo(startX+50, startY+50);
213  mPath.lineTo(startX+50, startY);
214  mPath.lineTo(startX, startY+50);
215  mPath.lineTo(startX+50, startY+50);*/
216 
217  }else{
218  down++;
219  //paleocodage+="d-";
220  this.lines.add(new LineParameters(startX,startY,mX,mY,delta_x,delta_y,StrokeType.D));
221  paleocodage=LocationCalc.calculateRelation(lines);
222 
223  /*mPath.moveTo(startX, startY);
224  mPath.lineTo(startX, startY+50);
225  mPath.lineTo(startX-50, startY);
226  mPath.lineTo(startX, startY);*/
227  }
228  this.context.setStatusText();
229  }else if(radius>30 && radius<150){
230  System.out.println("Detected: C");
231  ++c;
232  strokes.add("c");
233  if(startY>mY){
234  //paleocodage+="e-";
235  this.lines.add(new LineParameters(startX,startY,mX,mY,delta_x,delta_y,StrokeType.E));
236  paleocodage=LocationCalc.calculateRelation(lines);
237  up++;
238  }else{
239  down++;
240  //paleocodage+="f-";
241  this.lines.add(new LineParameters(startX,startY,mX,mY,delta_x,delta_y,StrokeType.F));
242  paleocodage=LocationCalc.calculateRelation(lines);
243 
244  }
245  this.context.setStatusText();
246 
247  }
248  //System.out.println(LocationCalc.calculateRelation(lines,lines.get(lines.size()-1)));
249  this.context.lookUp();
250  this.mCanvas.drawPath(mPath,mPaint);
251  paths.add(mPath);
252  mPath=new Path();
253  }
float startX
Definition: DrawingCanvas.java:27
Integer right
Definition: DrawingCanvas.java:20
Integer up
Definition: DrawingCanvas.java:20
float mX
Definition: DrawingCanvas.java:32
Paint mPaint
Definition: DrawingCanvas.java:31
Integer s
Definition: DrawingCanvas.java:20
Integer b
Definition: DrawingCanvas.java:20
List< LineParameters > lines
Definition: DrawingCanvas.java:21
Integer left
Definition: DrawingCanvas.java:20
Path mPath
Definition: DrawingCanvas.java:29
float startY
Definition: DrawingCanvas.java:28
Integer c
Definition: DrawingCanvas.java:20
float mY
Definition: DrawingCanvas.java:32
String paleocodage
Definition: DrawingCanvas.java:24
Integer a
Definition: DrawingCanvas.java:20
Integer down
Definition: DrawingCanvas.java:20
Integer d
Definition: DrawingCanvas.java:20

Member Data Documentation

Integer a =0
package
Integer b =0
package
Integer c =0
package
CuneiPainter context
private
Integer d =0
package
Integer down =0
package

Referenced by DrawingCanvas.upTouch().

int height
Integer left =0
package

Referenced by DrawingCanvas.upTouch().

List<LineParameters> lines = new LinkedList<>()

Referenced by DrawingCanvas.upTouch().

Canvas mCanvas
private
Path mPath
private
String paleocodage =""
package

Referenced by DrawingCanvas.upTouch().

List<Path> paths
private
Integer right =0
package

Referenced by DrawingCanvas.upTouch().

float startX
private
float startY
private
List<String> strokes = new LinkedList<>()

Referenced by DrawingCanvas.undoPath().

final float TOLERANCE = 5
staticprivate

Referenced by DrawingCanvas.moveTouch().

List<Path> undonepaths
private

Referenced by DrawingCanvas.redoPath().

Integer up =0
package

Referenced by DrawingCanvas.upTouch().

int width