Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I was a little bored with this subject and i made an handler class for leading with multitouch buttons. Feel free to use and/or update that.</p> <p><code></p> <pre><code>//CLASS TO HANDLE THE EVENT public class MultitouchButtonHandler { ArrayList&lt;View&gt; views_info = new ArrayList&lt;View&gt;(); public MultitouchButtonHandlerResult onTouchEvent(View v, MotionEvent ev) { //GET EVENT INFO final int action = ev.getAction(); int action_masked = action &amp; MotionEvent.ACTION_MASK; if(action_masked==MotionEvent.ACTION_MOVE){ return null; } //GET ABSOLUTE SIZE AND CHECK IF THIS ANY VIEW ATTACHED TO THIS POSITION final int original_location[] = { 0, 0 }; v.getLocationOnScreen(original_location); final int actionPointerIndex = ev.getActionIndex(); float rawX = (int) ev.getX(actionPointerIndex) + original_location[0]; float rawY = (int) ev.getY(actionPointerIndex) + original_location[1]; View eventView = getViewByLocation((int)rawX, (int)rawY); if(eventView==null) return null; MultitouchButtonHandlerResult result = new MultitouchButtonHandlerResult(); result.view = eventView; //CHECK WHAT KIND OF EVENT HAPPENED switch (action_masked) { case MotionEvent.ACTION_DOWN: { result.event_type = MotionEvent.ACTION_DOWN; return result; } case MotionEvent.ACTION_UP: { result.event_type = MotionEvent.ACTION_UP; return result; } case MotionEvent.ACTION_CANCEL: { result.event_type = MotionEvent.ACTION_CANCEL; return result; } case MotionEvent.ACTION_POINTER_UP: { result.event_type = MotionEvent.ACTION_UP; return result; } case MotionEvent.ACTION_POINTER_DOWN: { result.event_type = MotionEvent.ACTION_DOWN; return result; } default: break; } return null; } public void addMultiTouchView(View v){ views_info.add(v);; } public void removeMultiTouchView(View v){ views_info.remove(v);; } public View getViewByLocation(int x, int y){ for(int key=0; key!= views_info.size(); key++){ View v = views_info.get(key); //GET BUTTON ABSOLUTE POSITION ON SCREEN int[] v_location = { 0, 0 }; v.getLocationOnScreen(v_location); //FIND THE BOUNDS Point min = new Point(v_location[0], v_location[1]); Point max = new Point(min.x + v.getWidth(), min.y + v.getHeight()); if(x&gt;=min.x &amp;&amp; x&lt;=max.x &amp;&amp; y&gt;=min.y &amp;&amp; y&lt;=max.y){ //Log.d("mylog", "***Found a view: " + v.getId()); return v; } } //Log.d("mylog", "Searching: " + x +", " + y + " but not found!"); return null; } } </code></pre> <p></code></p> <p><code></p> <pre><code>//CLASS TO FULLFILL WITH RESULT public class MultitouchButtonHandlerResult { public View view; public int event_type; } </code></pre> <p></code></p> <p><code></p> <pre><code>//In your view private OnTouchListener listener_touch_button = new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { MultitouchButtonHandlerResult result=multitouch_handler.onTouchEvent(v, event); if(result==null) return true; switch(result.event_type){ case MotionEvent.ACTION_DOWN: Log.d("mylog", "DOWN"); break; case MotionEvent.ACTION_UP: Log.d("mylog", "UP"); break; case MotionEvent.ACTION_CANCEL: Log.d("mylog", "CANCEL"); break; } Log.d("mylog", "View ID: " + result.view.getId()); return false; } }; </code></pre> <p></code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload