I'm making a fife application. My fife has 6 holes, that I consider them as 6 buttons. As you know, in fifes, it makes difference if you hold one, two or more holes (here buttons) at once. I'm new in android, how can I manage it? for example I want to do this:
if button1 and button2 are touched at same time : play sound1
if button6 and button2 are touched at same time : play sound2
if button1 and button2 and buuton3 are touched at same time : play sound3
.
.
.
finally i used this trick:
one.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
is1t = true;
soundtoplay();
one.setBackgroundResource(R.drawable.hintedholes);
return true;
case MotionEvent.ACTION_UP:
is1t = false;
soundtoplay();
one.setBackgroundResource(R.drawable.holes);
return true;
}
return false;
}
});
two.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
is2t = true;
soundtoplay();
two.setBackgroundResource(R.drawable.hintedholes);
return true;
case MotionEvent.ACTION_UP:
is2t = false;
soundtoplay();
two.setBackgroundResource(R.drawable.holes);
return true;
}
return false;
}
});
three.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
is3t = true;
soundtoplay();
three.setBackgroundResource(R.drawable.hintedholes);
return true;
case MotionEvent.ACTION_UP:
is3t = false;
soundtoplay();
three.setBackgroundResource(R.drawable.holes);
return true;
}
return false;
}
});
...
public void soundtoplay(){
if(is1t == true && is2t == false && is3t == false && is4t == false && is5t == false && is6t == false){
mp = MediaPlayer.create(Playing.this, R.raw.b);
mp.start();
}else if(is1t == true && is2t == true && is3t == false && is4t == false && is5t == false && is6t == false){
mp = MediaPlayer.create(Playing.this, R.raw.a);
mp.start();
}else if(is1t == true && is2t == true && is3t == true && is4t == false && is5t == false && is6t == false){
mp = MediaPlayer.create(Playing.this, R.raw.g1);
mp.start();
}else if ...