Overriding default button behaviour
in
Android Processing
•
1 year ago
Hi there,
I am just starting with Android + Processing + Eclipse (yes it's evil I know, still...). Ive got a simple android app running, with one activity and a simple sketch inside that lets me draw colored ellipses. I can send it to my HTC Wildfire S with no problem.
Now I have 2 questions that I am having a tough time answering:
How do I use Toasts within the processing code? Is it even possible? Crashes my app instantly.
How do I override the default key behaviour? I want to use the volume keys to change some variables, and it works, but still they change the volume at the same time.
I have set the keyCode to 0 as described in the wiki, does not work, also not on the BACK button:
<code>
public void keyPressed() {
background(255); // clear canvas
if (key == CODED && keyCode == KeyEvent.KEYCODE_BACK) {
keyCode = 0;
Log.i("App_ButtonPressed", "Back Button pressed!");
}
if (key == CODED && keyCode == KeyEvent.KEYCODE_MENU) {
Log.i("App_ButtonPressed", "Menu Button pressed!");
}
if (key == CODED && keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
keyCode = 0;
Log.i("App_ButtonPressed", "Volume Down Button pressed!");
}
if (key == CODED && keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
keyCode = 0;
Log.i("App_ButtonPressed", "Volume UP Button pressed!");
}
}
}
</code>
I am glad for any advice or pointing in the right direction! One thing: is there a code-context for this forum to colorize code?
Cheers
I am just starting with Android + Processing + Eclipse (yes it's evil I know, still...). Ive got a simple android app running, with one activity and a simple sketch inside that lets me draw colored ellipses. I can send it to my HTC Wildfire S with no problem.
Now I have 2 questions that I am having a tough time answering:
How do I use Toasts within the processing code? Is it even possible? Crashes my app instantly.
How do I override the default key behaviour? I want to use the volume keys to change some variables, and it works, but still they change the volume at the same time.
I have set the keyCode to 0 as described in the wiki, does not work, also not on the BACK button:
<code>
public void keyPressed() {
background(255); // clear canvas
if (key == CODED && keyCode == KeyEvent.KEYCODE_BACK) {
keyCode = 0;
Log.i("App_ButtonPressed", "Back Button pressed!");
}
if (key == CODED && keyCode == KeyEvent.KEYCODE_MENU) {
Log.i("App_ButtonPressed", "Menu Button pressed!");
}
if (key == CODED && keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
keyCode = 0;
Log.i("App_ButtonPressed", "Volume Down Button pressed!");
}
if (key == CODED && keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
keyCode = 0;
Log.i("App_ButtonPressed", "Volume UP Button pressed!");
}
}
}
</code>
I am glad for any advice or pointing in the right direction! One thing: is there a code-context for this forum to colorize code?
Cheers
1