project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/SDLActivity.java
changeset 6839 2dd2c0f2c9d0
parent 6661 d16c898d1fe2
child 7006 6af78154dc62
equal deleted inserted replaced
6837:a137733c5776 6839:2dd2c0f2c9d0
   569 		return false;
   569 		return false;
   570 	}
   570 	}
   571 
   571 
   572 	// Touch events
   572 	// Touch events
   573 	public boolean onTouch(View v, MotionEvent event) {
   573 	public boolean onTouch(View v, MotionEvent event) {
   574 		{
   574 		final int action = event.getAction() & MotionEvent.ACTION_MASK;
   575 			final int touchDevId = event.getDeviceId();
   575 		final int actionPointerIndex = event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK;		
   576 			final int pointerCount = event.getPointerCount();
   576 
   577 			// touchId, pointerId, action, x, y, pressure
   577 		if (action == MotionEvent.ACTION_MOVE) {
   578 			int actionPointerIndex = event.getActionIndex();
   578 			// TODO send motion to every pointer if its position has
   579 			int pointerFingerId = event.getPointerId(actionPointerIndex);
   579 			// changed since prev event.
   580 			int action = event.getActionMasked();
   580 			for (int i = 0; i < event.getPointerCount(); i++) {
   581 
   581 				sendNativeTouch(event, action, i);
   582 			float x = event.getX(actionPointerIndex);
   582 			}
   583 			float y = event.getY(actionPointerIndex);
   583 		} else {
   584 			float p = event.getPressure(actionPointerIndex);
   584 			sendNativeTouch(event, action, actionPointerIndex);
   585 
       
   586 			if (action == MotionEvent.ACTION_MOVE && pointerCount > 1) {
       
   587 				// TODO send motion to every pointer if its position has
       
   588 				// changed since prev event.
       
   589 				for (int i = 0; i < pointerCount; i++) {
       
   590 					pointerFingerId = event.getPointerId(i);
       
   591 					x = event.getX(i);
       
   592 					y = event.getY(i);
       
   593 					p = event.getPressure(i);
       
   594 					SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
       
   595 				}
       
   596 			} else {
       
   597 				SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
       
   598 			}
       
   599 		}
   585 		}
   600 		return true;
   586 		return true;
   601 	} 
   587 	} 
       
   588 	
       
   589 	private static void sendNativeTouch(MotionEvent event, int action, int pointerIndex) {
       
   590 		int touchDevId = event.getDeviceId();
       
   591 		int pointerFingerId = event.getPointerId(pointerIndex);
       
   592 		float x = event.getX(pointerIndex);
       
   593 		float y = event.getY(pointerIndex);
       
   594 		float pressure = event.getPressure(pointerIndex);
       
   595 		SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, pressure);
       
   596 	}
   602 
   597 
   603 	// Sensor events
   598 	// Sensor events
   604 	public void enableSensor(int sensortype, boolean enabled) {
   599 	public void enableSensor(int sensortype, boolean enabled) {
   605 		// TODO: This uses getDefaultSensor - what if we have >1 accels?
   600 		// TODO: This uses getDefaultSensor - what if we have >1 accels?
   606 		if (enabled) {
   601 		if (enabled) {
   622 			SDLActivity.onNativeAccel(event.values[0] / SensorManager.GRAVITY_EARTH,
   617 			SDLActivity.onNativeAccel(event.values[0] / SensorManager.GRAVITY_EARTH,
   623 					event.values[1] / SensorManager.GRAVITY_EARTH,
   618 					event.values[1] / SensorManager.GRAVITY_EARTH,
   624 					event.values[2] / SensorManager.GRAVITY_EARTH);
   619 					event.values[2] / SensorManager.GRAVITY_EARTH);
   625 		}
   620 		}
   626 	}
   621 	}
   627 
       
   628 }
   622 }
   629 
   623