Pressing the green key in blackberry - java

I want to know when the user presses the green button in the device to initiate a phonecall from the app directly. What event is fired when the green key is pressed?
Thanks

You need to implement KeyListener
import net.rim.device.api.system.KeyListener;
override the function
public boolean keyDown(int keycode, int time)
and inside it catch the event of pressing buttons.
How do you check which button was pressed?
if (Keypad.KEY_SEND == Keypad.key(keycode)) {//your code}
find the API DOC here : http://www.blackberry.com/developers/docs/4.0.2api/net/rim/device/api/ui/Keypad.html

I found the answer to be something similar to this.
Override keyDown:
public boolean keyDown(int keycode, int time)
{
if (keycode == Keypad.SEND)
{
//handle your event
return true;
}
return super.keyDown(keycode, time);
}

Related

keyCode == KeyEvent.KEYCODE_BUTTON_Y freezing the focus and not able to navigate after that

For Nvidia joystick trying to associate this event to go to search button on the grid view, it is working but it is getting frozen and nothing is happening after that. Suggest me something
#Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
Log.i(TAG, " :: keyCode ::"+keyCode);
if (keyCode == KeyEvent.KEYCODE_BUTTON_Y) {
searchTop.performClick();
return true;
}
return super.onKeyUp(keyCode,event);
}
Try to call the super.onKeyUp(keyCode,event) anyway, even after your event handling.

libgdx in Android: how to handle escape key?

In Android. I implement an InputProcessor and:
#override public boolean keyDown(int keycode)
When I press escape, no key is checked and the app exits. How do I check Escape key?
ps: in PC/MAC ,I can check Escape directly, and it works.
This works for me:
public boolean keyDown(int keycode){
switch (keycode){
case Keys.ESCAPE:
Gdx.app.log("Monles", "ESC pressed");
break;
...
Also, my app doesn't quit when I press ESCAPE, but if yours do, this will probably fix it:
Gdx.input.setCatchBackKey(true);
First create an InputProcessor to handle the back key actions and then add it to a multiplexer so that other components still receive similar events.
InputProcessor backProcessor = new InputAdapter() {
#Override
public boolean keyDown(int keycode) {
if ((keycode == Keys.ESCAPE) || (keycode == Keys.BACK) )
// Maybe perform other operations before exiting
Gdx.app.exit();
return false;
}
};
InputMultiplexer multiplexer = new InputMultiplexer(mStage,
backProcessor);
Gdx.input.setInputProcessor(multiplexer);
And enable catching the back key.
Gdx.input.setCatchBackKey(true);
That's all there is. Good luck!

Override Delete button of soft keyboard

I am trying to override the delete button of my soft keyboard. I am able to detect the delete button being pressed but only if the EditText is empty. Is there a way of detecting if it has been pressed when there is text in my EditText? What i want to do is override the delete button to make it delete the entire contents of the EditText instead of just letter by letter. Below is the code I am using:
mEtCoupon.setOnKeyListener(new View.OnKeyListener() {
#Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// You can identify which key pressed buy checking keyCode value
// with KeyEvent.KEYCODE_
if (keyCode == KeyEvent.KEYCODE_DEL) {
// this is for backspace
Log.e("IME_TEST", "DEL KEY");
}
return false;
}
});
Is it possible to do this?

Hold down volume button on android?

I'm trying to make an app where if you hold down the volume down button, an action occurs. How would I go abouts doing this? I'm a noob for java, so an example would be excellent.
Override onKeyLongPress in your Activity
#Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
{
// to your stuff here
return true;
}
return super.onKeyLongPress(keyCode, event);
}
how to capture long press volume down key in android?

Android: How can I set a listener to the MenuButton?

I want to do a custom action when pressing on the Menu button on the phone.
Is it possible to set an onClickListener (or similar) on the button and if so, how?
onCreateOptionsMenu is only called the first time the button is pressed - I've already tried this.
Usually you shouldn't override MENU behavior as users expect menu to appear, however you can use something along these lines:
/* (non-Javadoc)
* #see android.app.Activity#onKeyDown(int, android.view.KeyEvent)
*/
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ( keyCode == KeyEvent.KEYCODE_MENU ) {
Log.d(TAG, "MENU pressed");
return true;
}
return super.onKeyDown(keyCode, event);
}
But onPrepareOptionsMenu(..) is called each time. :)
Updated for AppCompat v.22.+
As mentioned in this forum, KeyDown is not called for KEYCODE_MENU button pressed.
The solution is to override dispatchKeyEvent to this way:
#Override
public boolean dispatchKeyEvent(KeyEvent event) {
int keyCode = event.getKeyCode();
int action = event.getAction();
boolean isDown = action == KeyEvent.ACTION_DOWN;
if (keyCode == KeyEvent.KEYCODE_MENU) {
return isDown ? this.onKeyDown(keyCode, event) : this.onKeyUp(keyCode, event);
}
return super.dispatchKeyEvent(event);
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ( keyCode == KeyEvent.KEYCODE_MENU ) {
// do what you want to do here
return true;
}
return super.onKeyDown(keyCode, event);
}
It works until Google developers release a fix for this (or maybe it is not a bug and it works this way from now on).
You could probably hack something in using "OnMenuOpened" or some such, but I really wouldn't recommend it. The menu button is only supposed to be used to show menus, so there is consistency between applications.

Categories

Resources