project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/UserInput/TouchInterface.java
changeset 10017 de822cd3df3a
parent 7584 7831c84cc644
equal deleted inserted replaced
10015:4feced261c68 10017:de822cd3df3a
    26 import android.view.View;
    26 import android.view.View;
    27 import android.view.View.OnTouchListener;
    27 import android.view.View.OnTouchListener;
    28 
    28 
    29 public class TouchInterface{
    29 public class TouchInterface{
    30 
    30 
    31 	public static OnTouchListener getTouchInterface(){
    31     public static OnTouchListener getTouchInterface(){
    32 		OnTouchListener toucher;
    32         OnTouchListener toucher;
    33 		if(Build.VERSION.SDK_INT < 5){//8 == Build.VERSION_CODES.FROYO
    33         if(Build.VERSION.SDK_INT < 5){//8 == Build.VERSION_CODES.FROYO
    34 			toucher = new TouchInterfaceST();
    34             toucher = new TouchInterfaceST();
    35 		}else{
    35         }else{
    36 			toucher = new TouchInterfaceMT();
    36             toucher = new TouchInterfaceMT();
    37 		}
    37         }
    38 
    38 
    39 		return toucher;
    39         return toucher;
    40 	}
    40     }
    41 }
    41 }
    42 /**
    42 /**
    43  * Touch interface with multitouch
    43  * Touch interface with multitouch
    44  */
    44  */
    45 class TouchInterfaceMT implements OnTouchListener {
    45 class TouchInterfaceMT implements OnTouchListener {
    46 	
       
    47 	private boolean firstEvent = true;
       
    48 	
       
    49 	public boolean onTouch(View v, MotionEvent event) {
       
    50 		//dumpEvent(event);
       
    51 		
       
    52 		int action = event.getAction();
       
    53 		int actionCode = action & MotionEvent.ACTION_MASK;
       
    54 		
       
    55 		for (int i = 0; i < event.getPointerCount(); i++) {
       
    56 			SDLActivity.onNativeTouch(event.getDeviceId(),  event.getPointerId(i), actionCode, (int)event.getX(i), (int)event.getY(i), event.getPressure(i));
       
    57 //			Log.d("Android", String.format("x=%f, y=%f, pntr=%d", event.getX(i), event.getY(i), event.getPointerId(i)));
       
    58 		   }
       
    59 		return true;
       
    60 	}
       
    61 
    46 
    62 	/** Show an event in the LogCat view, for debugging */
    47     private boolean firstEvent = true;
    63 	private void dumpEvent(MotionEvent event) {
    48 
    64 	   String names[] = { "DOWN" , "UP" , "MOVE" , "CANCEL" , "OUTSIDE" ,
    49     public boolean onTouch(View v, MotionEvent event) {
    65 	      "POINTER_DOWN" , "POINTER_UP" , "7?" , "8?" , "9?" };
    50         //dumpEvent(event);
    66 	   StringBuilder sb = new StringBuilder();
    51 
    67 	   int action = event.getAction();
    52         int action = event.getAction();
    68 	   int actionCode = action & MotionEvent.ACTION_MASK;
    53         int actionCode = action & MotionEvent.ACTION_MASK;
    69 	   sb.append("event ACTION_" ).append(names[actionCode]);
    54 
    70 	   if (actionCode == MotionEvent.ACTION_POINTER_DOWN
    55         for (int i = 0; i < event.getPointerCount(); i++) {
    71 	         || actionCode == MotionEvent.ACTION_POINTER_UP) {
    56             SDLActivity.onNativeTouch(event.getDeviceId(),  event.getPointerId(i), actionCode, (int)event.getX(i), (int)event.getY(i), event.getPressure(i));
    72 	      sb.append("(pid " ).append(
    57 //          Log.d("Android", String.format("x=%f, y=%f, pntr=%d", event.getX(i), event.getY(i), event.getPointerId(i)));
    73 	      action >> MotionEvent.ACTION_POINTER_ID_SHIFT);
    58            }
    74 	      sb.append(")" );
    59         return true;
    75 	   }
    60     }
    76 	   sb.append("[" );
    61 
    77 	   for (int i = 0; i < event.getPointerCount(); i++) {
    62     /** Show an event in the LogCat view, for debugging */
    78 	      sb.append("#" ).append(i);
    63     private void dumpEvent(MotionEvent event) {
    79 	      sb.append("(pid " ).append(event.getPointerId(i));
    64        String names[] = { "DOWN" , "UP" , "MOVE" , "CANCEL" , "OUTSIDE" ,
    80 	      sb.append(")=" ).append((int) event.getX(i));
    65           "POINTER_DOWN" , "POINTER_UP" , "7?" , "8?" , "9?" };
    81 	      sb.append("," ).append((int) event.getY(i));
    66        StringBuilder sb = new StringBuilder();
    82 	      if (i + 1 < event.getPointerCount())
    67        int action = event.getAction();
    83 	         sb.append(";" );
    68        int actionCode = action & MotionEvent.ACTION_MASK;
    84 	   }
    69        sb.append("event ACTION_" ).append(names[actionCode]);
    85 	   sb.append("]" );
    70        if (actionCode == MotionEvent.ACTION_POINTER_DOWN
    86 	   Log.d("HW_APP_TOUCH", sb.toString());
    71              || actionCode == MotionEvent.ACTION_POINTER_UP) {
    87 	}
    72           sb.append("(pid " ).append(
       
    73           action >> MotionEvent.ACTION_POINTER_ID_SHIFT);
       
    74           sb.append(")" );
       
    75        }
       
    76        sb.append("[" );
       
    77        for (int i = 0; i < event.getPointerCount(); i++) {
       
    78           sb.append("#" ).append(i);
       
    79           sb.append("(pid " ).append(event.getPointerId(i));
       
    80           sb.append(")=" ).append((int) event.getX(i));
       
    81           sb.append("," ).append((int) event.getY(i));
       
    82           if (i + 1 < event.getPointerCount())
       
    83              sb.append(";" );
       
    84        }
       
    85        sb.append("]" );
       
    86        Log.d("HW_APP_TOUCH", sb.toString());
       
    87     }
    88 
    88 
    89 }
    89 }
    90 
    90 
    91 /**
    91 /**
    92  * Touch interface without multitouch
    92  * Touch interface without multitouch
    93  */
    93  */
    94 class TouchInterfaceST implements OnTouchListener {
    94 class TouchInterfaceST implements OnTouchListener {
    95 
    95 
    96 	public boolean onTouch(View v, MotionEvent event) {
    96     public boolean onTouch(View v, MotionEvent event) {
    97 		return false;
    97         return false;
    98 	}
    98     }
    99 
    99 
   100 
   100 
   101 
   101 
   102 }
   102 }
   103 
   103