darkhah1
چهارشنبه 03 تیر 1394, 07:50 صبح
سلام من اين كد رو قبلا استفاده كردم ولي براي تاچ كردن يك دكمه چطوري ميشه اون را براي چهار دكمه به كار برد ؟؟؟ امكانش هست؟؟؟
package com.darkhah1.guns;
import java.io.IOException;
import android.app.Activity;
import android.content.Intent;
import android.drm.DrmStore.Playback;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
public class G36C extends Activity implements OnTouchListener {
private MediaPlayer mp;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.g36c);
final Button zero = (Button) this.findViewById(R.id.g36c);
zero.setOnTouchListener(this);
mp = MediaPlayer.create(this, R.raw.g36cringtone);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
mp = MediaPlayer.create(getApplicationContext(), R.raw.g36cringtone);
mp.start();
mp.setLooping(true);
mp.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp1) {
// TODO Auto-generated method stub
mp1.release();
}
});
Log.i("Action", "Down");
break;
case MotionEvent.ACTION_MOVE:
Log.i("Action", "Move");
Log.i("On Long", "On Long");
break;
case MotionEvent.ACTION_CANCEL:
mp.pause();
Log.i("Action", "Cancel");
break;
case MotionEvent.ACTION_UP:
mp.setLooping(false);
//mp1.stop();
Log.i("Action", "up");
break;
default:
break;
}
return true;
}
public void shareData(View view) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
String my_string = getResources().getString(R.string.my_text);
intent.putExtra(Intent.EXTRA_TEXT, my_string);
startActivity(Intent.createChooser(intent, "Share this text via"));
}
public void onBackPressed() {
// TODO Auto-generated method stub
startActivity(new Intent(G36C.this, MainActivity.class));
}
}
package com.darkhah1.guns;
import java.io.IOException;
import android.app.Activity;
import android.content.Intent;
import android.drm.DrmStore.Playback;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
public class G36C extends Activity implements OnTouchListener {
private MediaPlayer mp;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.g36c);
final Button zero = (Button) this.findViewById(R.id.g36c);
zero.setOnTouchListener(this);
mp = MediaPlayer.create(this, R.raw.g36cringtone);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
mp = MediaPlayer.create(getApplicationContext(), R.raw.g36cringtone);
mp.start();
mp.setLooping(true);
mp.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp1) {
// TODO Auto-generated method stub
mp1.release();
}
});
Log.i("Action", "Down");
break;
case MotionEvent.ACTION_MOVE:
Log.i("Action", "Move");
Log.i("On Long", "On Long");
break;
case MotionEvent.ACTION_CANCEL:
mp.pause();
Log.i("Action", "Cancel");
break;
case MotionEvent.ACTION_UP:
mp.setLooping(false);
//mp1.stop();
Log.i("Action", "up");
break;
default:
break;
}
return true;
}
public void shareData(View view) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
String my_string = getResources().getString(R.string.my_text);
intent.putExtra(Intent.EXTRA_TEXT, my_string);
startActivity(Intent.createChooser(intent, "Share this text via"));
}
public void onBackPressed() {
// TODO Auto-generated method stub
startActivity(new Intent(G36C.this, MainActivity.class));
}
}