JavierVera
asked on
Override android volume keys
Good day, i've got a mission to do.
First, we had an Android application developed for devices with TRACKPAD (yes, that square that several blackberrys have).
Now, we only have devices that doesn't have this key on. This way the user is FORCED to touch the screen.
Im searching for alternatives to navigate the device WITHOUT touching the screen.
I wonder what were those guys thinking when offering a hardware keyboard with no trackpad or way to move around the phone but touching the screen.....
Here it is what i've done:
This works PERFECT for overriding the volume keys on this activity.
Also, i am trying to fire the KeyEvent.KEYCODE_DPAD_DOWN event and i have NO SUCCESS. What am i missing??
In other words, what i am trying to do is to execute the KEYCODE_DPAD_DOWN when pressed the volume key, with this code i posted i am trying to do so however, i only get the overriden volume key and STILL need the execute of the KEYCODE_DPAD_DOWN :/
First, we had an Android application developed for devices with TRACKPAD (yes, that square that several blackberrys have).
Now, we only have devices that doesn't have this key on. This way the user is FORCED to touch the screen.
Im searching for alternatives to navigate the device WITHOUT touching the screen.
I wonder what were those guys thinking when offering a hardware keyboard with no trackpad or way to move around the phone but touching the screen.....
Here it is what i've done:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) {
if (event.getAction() == KeyEvent.ACTION_DOWN){
super.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_DPAD_UP));
super.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP,KeyEvent.KEYCODE_DPAD_UP));
return true;
}}
if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) {
if (event.getAction() == KeyEvent.ACTION_DOWN){
super.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_DPAD_DOWN));
super.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP,KeyEvent.KEYCODE_DPAD_DOWN));
return true;
}}
return super.dispatchKeyEvent(event);
};
This works PERFECT for overriding the volume keys on this activity.
Also, i am trying to fire the KeyEvent.KEYCODE_DPAD_DOWN
In other words, what i am trying to do is to execute the KEYCODE_DPAD_DOWN when pressed the volume key, with this code i posted i am trying to do so however, i only get the overriden volume key and STILL need the execute of the KEYCODE_DPAD_DOWN :/
ASKER
Thing i want to emulate is the focus change with the DPAD.
I have a layout with 3 textboxes. I can easily move around them with the TRACKPAD.
I want the same functionality with the volume keys. UP and DOWN that's it.
This is why i want to intercept the event and change it to this purpose. If you have any aproach like this please tell.
There is no TabIndex in Android as for use it as event as you state on the snippet you are showing.
I've tryed the following with no success....
and
any idea please ?
I have a layout with 3 textboxes. I can easily move around them with the TRACKPAD.
I want the same functionality with the volume keys. UP and DOWN that's it.
This is why i want to intercept the event and change it to this purpose. If you have any aproach like this please tell.
There is no TabIndex in Android as for use it as event as you state on the snippet you are showing.
I've tryed the following with no success....
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
// TODO Auto-generated method stub
int keyCode = event.getKeyCode();
boolean result = false;
if(keyCode == KeyEvent.KEYCODE_VOLUME_UP){
super.onKeyDown(KeyEvent.KEYCODE_DPAD_UP, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_UP));
return true;
} else if(keyCode == KeyEvent.KEYCODE_VOLUME_DOWN){
super.onKeyDown(KeyEvent.KEYCODE_DPAD_DOWN, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_DOWN));
return true;
}
return false;
//return super.dispatchKeyEvent(event);
}
and
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
boolean result = false;
// Detectar y manejar el uso del botón HOME
if (keyCode == KeyEvent.KEYCODE_HOME) {
setQuitStartTime();
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
result = true;
}
if(keyCode == KeyEvent.KEYCODE_VOLUME_UP){
super.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_UP));
result = true;
} else if(keyCode == KeyEvent.KEYCODE_VOLUME_DOWN){
super.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_DOWN));
result = true;
}
else {
result = super.onKeyDown(keyCode, event);
}
return result;
}
any idea please ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This approach with the BaseInputConnection is what i really wanted. Thank you very much.
Open in new window