diff --git a/android/res/layout/piano2.xml b/android/res/layout/piano2.xml
index 97e7ed4..65b412f 100644
--- a/android/res/layout/piano2.xml
+++ b/android/res/layout/piano2.xml
@@ -84,6 +84,16 @@
-->
+
+
+
= 0) {
+ redraw = onTouchDown(pointerId, event.getX());
+ }
+ } else if (actionCode == MotionEvent.ACTION_POINTER_DOWN) {
+ int pointerIndex = (action & MotionEvent.ACTION_POINTER_INDEX_MASK)
+ >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
+ int pointerId = event.getPointerId(pointerIndex);
+ if (pointerId < 2 && pointerId >= 0) {
+ redraw = onTouchDown(pointerId, event.getX(pointerIndex));
+ }
+ } else if (actionCode == MotionEvent.ACTION_UP) {
+ int pointerId = event.getPointerId(0);
+ if (pointerId < 2 && pointerId >= 0) {
+ onTouchUp(pointerId);
+ }
+ } else if (actionCode == MotionEvent.ACTION_POINTER_UP) {
+ int pointerIndex = (action & MotionEvent.ACTION_POINTER_INDEX_MASK)
+ >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
+ int pointerId = event.getPointerId(pointerIndex);
+ if (pointerId < 2 && pointerId >= 0) {
+ onTouchUp(pointerId);
+ }
+ } else if (actionCode == MotionEvent.ACTION_MOVE) {
+ for (int pointerIndex = 0; pointerIndex < event.getPointerCount(); pointerIndex++) {
+ int pointerId = event.getPointerId(pointerIndex);
+ if (pointerId < 2 && pointerId >= 0) {
+ touchx_[pointerId] = event.getX(pointerIndex);
+ }
+ }
+ if (touchDown_[0] && !touchDown_[1]) {
+ offset_ = touchx_[0] + deltaAtTouch_;
+ redraw = true;
+ } else if (!touchDown_[0] && touchDown_[1]) {
+ offset_ = touchx_[1] + deltaAtTouch_;
+ redraw = true;
+ } else if (touchDown_[0] && touchDown_[1]) {
+ zoom_ = scaleAtTouch_ * (touchx_[1] - touchx_[0]);
+ offset_ = touchx_[0] + zoom_ / zoomAtTouch_ * deltaAtTouch_;
+ redraw = true;
+ }
+ offset_ = Math.min(0, offset_);
+ // TODO: max offset
+ }
+ if (redraw) {
+ if (keyboardView_ != null) {
+ keyboardView_.setScrollZoom(offset_, zoom_);
+ }
+ invalidate();
+ }
+ return true;
+ }
+
+ /**
+ * Layout measurement for this widget.
+ * This method just sets a basic minimum size and makes the widget maximized otherwise.
+ */
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ int widthMode = MeasureSpec.getMode(widthMeasureSpec);
+ int widthSize = MeasureSpec.getSize(widthMeasureSpec);
+ int heightMode = MeasureSpec.getMode(heightMeasureSpec);
+ int heightSize = MeasureSpec.getSize(heightMeasureSpec);
+
+ int width = 0;
+ int height = 0;
+
+ float density = getResources().getDisplayMetrics().density;
+ int maxHeight = (int) (50.0f * density + 0.5f);
+
+ switch (widthMode) {
+ case MeasureSpec.EXACTLY:
+ width = widthSize;
+ break;
+ case MeasureSpec.AT_MOST:
+ width = widthSize;
+ break;
+ case MeasureSpec.UNSPECIFIED:
+ width = 10;
+ break;
+ }
+
+ switch (heightMode) {
+ case MeasureSpec.EXACTLY:
+ height = heightSize;
+ break;
+ case MeasureSpec.AT_MOST:
+ height = Math.min(maxHeight, heightSize);
+ break;
+ case MeasureSpec.UNSPECIFIED:
+ height = 10;
+ break;
+ }
+
+ setMeasuredDimension(width, height);
+ }
+
+ Rect drawingRect_;
+ Paint paint_;
+ float offset_;
+ float zoom_;
+
+ // touch state
+ boolean[] touchDown_;
+ float[] touchx_;
+ float deltaAtTouch_;
+ float zoomAtTouch_;
+ float scaleAtTouch_;
+
+ KeyboardView keyboardView_;
+}