OnTouchListener irregular on Android 4.1.1 JellyBean
===

I am suffering a really weird problem with my OnTouchListener. I upgraded my Galaxy Nexus to 4.1.1 last night and the following code which is still working on all previous android OS version does not work at all. I guess there is some problem with the calling of this listener. Following is the code and please ignore the logic if you find it complex just see the placement of logs and the output: -

    private OnTouchListener drag = new OnTouchListener() {
		private float error_x = 0;
		private float error_y = 0;
		private int c = 0;

		@Override
		public boolean onTouch(View v, MotionEvent event) {
			Log.i("branch", "onTouch called " + ++c);
			if (event.getAction() == MotionEvent.ACTION_DOWN) {
				Log.i("branch", "1");
				error_x = event.getX();
				error_y = event.getY();
			} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
				Log.i("branch", "2");
				refreshTriangleColor(v);
				root_layout.removeView(v);
				root_layout.addView(v);
				Point position = getViewPosition(v);
				if (position != null) {
					Log.i("branch", "3");
					if (triangle_red
							.pointLiesInTriangle(position.x, position.y)) {
						Log.i("branch", "4");
						int x = Math.round(event.getRawX());
						int y = Math.round(event.getRawY());
						if (triangle_red.pointLiesInTriangle(x, y)) {
							Log.i("branch", "5");
							setViewPosition(v,
									Math.round(event.getRawX() - error_x),
									Math.round(event.getRawY() - error_y));
						} else {
							Log.i("branch", "6");
							long d = 0;
							d = Math.round(android.util.FloatMath.sqrt((((position.x - event
									.getRawX()) * (position.x - event.getRawX())) - ((position.y - event
									.getRawY()) * (position.y - event.getRawY())))));
							if (d >= Util.convertDip2Pixels(MAX_RESISTANCE,
									MelodyTriangle_AppActivity.this)) {
								Log.i("branch", "7");
								setViewPosition(v,
										Math.round(event.getRawX() - error_x),
										Math.round(event.getRawY() - error_y));
								vibrate();
							} else {
								Log.i("branch", "8");
								Point nearest_point = triangle_red
										.getNearestPointOnLine(new Point(x, y));
								if (nearest_point != null) {
									Log.i("branch", "9");
									setViewPosition(
											v,
											Math.round(nearest_point.x
													- error_x),
											Math.round(nearest_point.y
													- error_y));
								}
							}
						}
					} else {
						Log.i("branch", "10");
						setViewPosition(v,
								Math.round(event.getRawX() - error_x),
								Math.round(event.getRawY() - error_y));
					}
				}
			} else if (event.getAction() == MotionEvent.ACTION_UP) {
				Log.i("branch", "11");
				Point position = getViewPosition(v);
				if (position != null) {
					Log.i("branch", "12");
					if (!triangle_red.pointLiesInTriangle(position.x,
							position.y)) {
						Log.i("branch", "13");
						if (api.voices[0].isPlaying()) {
							Log.i("branch", "14");
							api.voices[0].stopPlaying();
						}
						animateToLayout(v, red_layout);
					} else {
						Log.i("branch", "15");
						playVoice(v, position.x, position.y);
					}
				}
			}
			return true;
		}
	};

The above code gives the following output when I try to drag: -

    07-18 16:28:53.897: I/branch(31176): onTouch called 1
    07-18 16:28:53.897: I/branch(31176): 1
    07-18 16:28:54.007: I/branch(31176): onTouch called 2
    07-18 16:28:54.007: I/branch(31176): 2
    07-18 16:28:54.007: I/branch(31176): onTouch called 3
    07-18 16:28:54.007: I/branch(31176): 3
    07-18 16:28:54.007: I/branch(31176): 10
    07-18 16:28:56.077: I/branch(31176): onTouch called 4
    07-18 16:28:56.077: I/branch(31176): 1
    07-18 16:28:56.124: I/branch(31176): onTouch called 5
    07-18 16:28:56.124: I/branch(31176): 2
    07-18 16:28:56.124: I/branch(31176): onTouch called 6
    07-18 16:28:56.124: I/branch(31176): 3
    07-18 16:28:56.124: I/branch(31176): 10
    07-18 16:29:00.764: I/branch(31176): onTouch called 7
    07-18 16:29:00.764: I/branch(31176): 1
    07-18 16:29:00.803: I/branch(31176): onTouch called 8
    07-18 16:29:00.803: I/branch(31176): 2
    07-18 16:29:00.803: I/branch(31176): onTouch called 9
    07-18 16:29:00.803: I/branch(31176): 3
    07-18 16:29:00.803: I/branch(31176): 10

The problems noticed are:-

1. touch is not being called regularly due to which the dragging is not smooth. You have to smudge the view to move it slightly from its position hence not moving along with the touch. Whereas, it is regular in the previous versions.

2.  event.getAction() == MotionEvent.ACTION_UP is only true when you touch and release the view. Whereas it is being called almost every time on previous version as the view moves along the touch and whenever you release this is true. 


Any idea whats going on wrong?

Thanks
