Skip to content

Commit

Permalink
MultiTouchController test
Browse files Browse the repository at this point in the history
  • Loading branch information
napthats committed Nov 6, 2012
1 parent fa5d4e5 commit f5b3ee0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
31 changes: 30 additions & 1 deletion src/main/scala/BoardView.scala
Expand Up @@ -11,15 +11,25 @@ import _root_.android.graphics.Color
import _root_.android.view.MotionEvent
import _root_.android.widget.Toast

import _root_.org.metalev.multitouch.controller.MultiTouchController;
import _root_.org.metalev.multitouch.controller.MultiTouchController.MultiTouchObjectCanvas;
import _root_.org.metalev.multitouch.controller.MultiTouchController.PointInfo;
import _root_.org.metalev.multitouch.controller.MultiTouchController.PositionAndScale;


class Page(var x: Int, var y: Int, val size: Int, title: String) {
}

class BoardView(context: Context, attrs:AttributeSet) extends View(context, attrs) {
class BoardView(context: Context, attrs:AttributeSet) extends View(context, attrs) with MultiTouchObjectCanvas[Page]{
/*
var prev_touch_x = 0
var prev_touch_y = 0
*/
var page = new Page(200, 100, 20, "test")

val multiTouchController = new MultiTouchController[Page](this)


override def onDraw(canvas: Canvas) {
super.onDraw(canvas)

Expand All @@ -29,6 +39,24 @@ class BoardView(context: Context, attrs:AttributeSet) extends View(context, attr
canvas.drawRect(page.x, page.y, page.x + page.size, page.y + page.size, paint)
}

override def selectObject(page: Page, point: PointInfo) {
Toast.makeText(context, "touch!", Toast.LENGTH_SHORT).show()
}

override def setPositionAndScale(page: Page, pos_scale: PositionAndScale, point: PointInfo): Boolean = {
return true
}

override def getPositionAndScale(page: Page, pos_scale: PositionAndScale) {
}

override def getDraggableObjectAtPoint(point: PointInfo): Page = {
page
}

override def onTouchEvent(event: MotionEvent): Boolean = multiTouchController.onTouchEvent(event)

/*
def onTouch(v: View, event: MotionEvent): Boolean = {
val x: Int = event.getX.toInt
val y: Int = event.getY.toInt
Expand All @@ -51,4 +79,5 @@ class BoardView(context: Context, attrs:AttributeSet) extends View(context, attr
this.invalidate()
return true
}
*/
}
2 changes: 1 addition & 1 deletion src/main/scala/MainActivity.scala
Expand Up @@ -25,7 +25,7 @@ class MainActivity extends Activity with TypedActivity {
findView(TR.boardview).setOnTouchListener(new View.OnTouchListener() {
override def onTouch(v: View, event: MotionEvent): Boolean = {
//Toast.makeText(MainActivity.this, "test", Toast.LENGTH_SHORT).show()
findView(TR.boardview).onTouch(v, event)
findView(TR.boardview).onTouchEvent(event)
}
})
}
Expand Down

0 comments on commit f5b3ee0

Please sign in to comment.