Reputation: 881
I'm having zxing app for barcode scanning
. It's having auto-focus but i need to set zoom in/out in my app.
It will be better if i can override volume control buttons in android device for zooming in the app.
How can i implement zooming in my app using volume control buttons?
Please share your thoughts..
Upvotes: 0
Views: 1184
Reputation: 902
Try to use dispatchKeyEvent by putting the following code in your activity.
public boolean dispatchKeyEvent(KeyEvent event) {
int keyCode = event.getKeyCode();
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
addIntensityLvl();
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
subtractIntensityLvl();
return true;
default:
return super.dispatchKeyEvent(event);
}
}
Upvotes: 0
Reputation: 34775
public boolean onKeyUp(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
// increase your zoom
return true;
} else if(keyCode == KeyEvent.KEYCODE_VOLUME_UP){
// decrease your zoom
return true;
}
return super.onKeyUp(keyCode, event);
}
you can use the above onKeyUp() event to do you task:::
Upvotes: 1