Thanks for your answer.
I tried what you mentioned and put this on my onTouch method:
this.aRect = new Rect();
this.aBtn.getLocalVisibleRect(aRect);
if(aRect.contains((int)event.getRawX(), (int)event.getRawY())){
Log.i(TAG, "inA");
if(action == MotionEvent.ACTION_DOWN){
updateAState(true);
}else if(action == MotionEvent.ACTION_UP){
updateAState(false);
}
}else ....
but unfortunately, it seems i got wrong infos from
getLocalVisibleRect... Do you have any idea ?
On 29 nov, 10:38, al <[email protected]> wrote:
> There are some basic "principles" in android regarding multi-touch
> that you should be aware of. Especially, wrt. your code these two come
> to my mind:
> 1) If the first "finger" touches view A, all other touches will be
> directed to view A as long as the first finger is still there, even if
> the subsequent touches touch another view. I think, the reason to
> implement it this way, was to ease implementation of gestures like
> pinch&zoom.
> 2) The action codes you will typically see during a multitouch
> "gesture" are:
> - ACTION_DOWN: this signals that the first finger touches the
> display
> - ACTION_POINTER_DOWN: the second, third, ... finger touches the
> display
> - ACTION_POINTER_UP: a finger was lifted, but there are still
> fingers on the display
> - ACTION_UP: the last finger was lifted
> Of course, you may also see ACTION_MOVE events in between and after
> a POINTER_UP, another POINTER_DOWN event may occur, if another finger
> touches the display before all fingers are lifted, etc.
>
> Regarding your code:
> 1) means that you have to capture the events at a view that is an
> ancestor to all the buttons that should be part of the multi-touch.
> I.e. put both buttons into a common parent and listen for the touch
> events at the parent. You can then analyze the event to determine the
> coordinates of the new touch point and use the coordinates to
> determine the touched button. Be aware though, that some devices have
> terrible hardware "limitations" (i.e. problems).
> Seehttp://androidandme.com/2010/03/news/is-multitouch-broken-on-the-nexu...
> for an example. I.e. the code has to take some strange behaviour into
> account.
>
> Regarding analyzing the event, don't confuse pointer id's with pointer
> indizes. That's a problem that can be seen in various code examples
> online.
>
> 2) means, you have to listen for ACTION_POINTER_DOWN and
> ACTION_POINTER_UP (as well as ACTION_CANCEL) too.
>
> On 28 Nov., 15:13, ColletJb <[email protected]> wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > I'm facing an very simple (and stupid) issue and I hope someone will
> > be able to provide me an explanation...
>
> > I'm trying to develop an Activity with 2 buttons (let's call them btnA
> > and btnB), they are in my xml layout. My goal is to be able to handle
> > click on both button (easy), even on the same time with multi-touch.
>
> > First, I retrieve them on the onCreate method and I set them the
> > OnTouchListener to this (my Activity implements OnTouchListener):
>
> > @Override
> > public void onCreate(Bundle savedInstanceState) {
> > super.onCreate(savedInstanceState);
> > setContentView(R.layout.main);
>
> > this.btnA = (ImageButton) this.findViewById(R.id.btnA);
> > this.btnB = (ImageButton) this.findViewById(R.id.btnB);
>
> > this.btnA.setOnTouchListener(this);
> > this.btnB.setOnTouchListener(this);
> > }
>
> > I did override the onTouch method that way :
> > @Override
> > public boolean onTouch(View v, MotionEvent event) {
> > int action = event.getAction() & MotionEvent.ACTION_MASK;
> > if(v.equals((View)this.btnA)){
> > if(action == MotionEvent.ACTION_DOWN){
> > updateAState(true);
> > }else if(action == MotionEvent.ACTION_UP){
> > updateAState(false);
> > }
> > }else if(v.equals((View)this.btnB)){
> > if(action == MotionEvent.ACTION_DOWN){
> > updateBState(true);
> > }else if(action == MotionEvent.ACTION_UP){
> > updateBState(false);
> > }
> > }
> > return true;
> > }
>
> > With this implementation, I can capture the DOWN and UP event on both
> > buttons, but not with multi-touch (ex: btnA DOWN, btnB DOWN, btnB UP,
> > btnB DOWN, btnB UP, btnA UP).
>
> > Who can tell me how I can fix my onTouch method to support such
> > feature ?
>
> > Thanks a lot.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en