I am creating an app for the blind, so I need to read the input of a button
I am creating an app for the blind. I need to read the input from a button, but before reading it, I want to play an audio about the button's content. So when my finger is over the button, I need to play the audio, that is, the word that is given to the button.
How can i do this?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().hide();// this is the code for the hide applicatoin name
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
//to hide the notification bar
Button speakButton = (Button) findViewById(R.id.bt1);
speakButton.setOnKeyListener(this);
tts = new TextToSpeech(this, this);
}
+3
source to share
1 answer
You can add a touch listener, then check the event type to see if its an ACTION_DOWN or ACTION_UP event.
speakButton.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == android.view.MotionEvent.ACTION_DOWN) {
//play sound
} else if (event.getAction() == android.view.MotionEvent.ACTION_UP) {
//do action
}
return true;
}
});
+4
source to share