App
BrushToolTouchListener.java
Go to the documentation of this file.
1 package mhr.app.touchlisteners;
2 
3 import mhr.app.AppMainActivity;
4 import mhr.appcore.commands.AppCommand;
5 import mhr.appcore.commands.toolcommands.DrawBgnCommand;
6 import mhr.appcore.commands.toolcommands.DrawEndCommand;
7 import mhr.appcore.commands.toolcommands.DrawToCommand;
8 import android.view.MotionEvent;
9 import android.view.View;
10 import android.view.View.OnTouchListener;
11 
15 public class BrushToolTouchListener implements OnTouchListener {
16 
17  AppMainActivity activity;
18 
20  this.activity = activity;
21  }
22 
23  @Override
24  public boolean onTouch(View v, MotionEvent e) {
25  int action = e.getAction();
26  int x = activity.getBitmapDisplayer().translateCoordX(e.getX());
27  int y = activity.getBitmapDisplayer().translateCoordY(e.getY());
28 
29  AppCommand command = null;
30 
31  switch (action) {
32  case MotionEvent.ACTION_DOWN:
33  command = new DrawBgnCommand(x, y);
34  break;
35 
36  case MotionEvent.ACTION_MOVE:
37  command = new DrawToCommand(x, y);
38  break;
39 
40  case MotionEvent.ACTION_UP:
41  command = new DrawEndCommand(x, y);
42  break;
43 
44  }
45 
46  activity.addCommand(command);
47 
48  return true;
49  }
50 
51 }