We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hopefully a quick question - As APWidgets is no longer compatible with Processing, any simple way to create an on-screen "save/export" button for Android Mode? There are a few threads about creating buttons, but I cannot use mousePressed on Android, and would prefer not to use the keyboard from, for example, the Ketai library.
Answers
@pdf197=== use the android button class + onClickListener() with your save/export method; as for mousePressed use motionEventClass.
Thanks for the tip @akenaton - so something like...? Except this doesn't work.
@PDF197=== yes, "something like this" BUT not really this!
a) import the android button class;
b) Button myButton; (declare the Button instance)
That's WAY too deep into Android for me, but thank you @akenaton I am always impressed by your knowledge, and speed of reply. I do need to become more familiar with Android in addition to Processing... I will add it to my list for 2016!!
@PDF197===
(you are right== learn android!!! + Android studio or eclipse) ; as i repeat processing3XX android, till now, is no more than a graphics library for android.
---- but try this code:::: (i can implement the motionEvent, but my goal is only to show you how to add a button== so, some imports does not matter here); not tested but it must work (i hope!!!!)
Merci beaucoup @akenaton -- yep, that works. It gives me somewhere to start.
I use mousePressed() on Android .. it does work ...
And the Ketai gestures are well worth trying ..
Yes, mousePressed() does work.
Ketai does of course allow the creation of on-screen buttons. So far I have found them less intuitive to code than with APWidgets because you have to set a "target area" to press/touch on the screen. If you have a lot of buttons, working these out becomes very tedious - though it is doable.
This isn't supposed to run, but does show the approach I used to code 6 buttons...
...
And this to render the buttons...
Here's how I do it ... or at least partially. I have used an array list here to hold 6 buttons based on my SimpleButton class. Just get rid of the size() in setup() for android use.
I see in your code you have some hard coded values like 51, 91 whereas I have set the width and height of my buttons based on display width. You may want to try this as it will make your buttons look the same size relative to display width on any phone.
Yes @hudson_m4000 that is a much neater, and more flexible, way of approaching buttons. The hard-coded way does indeed cause problems when switching between devices with different screen sizes.
Another 2 questions...
A StringList would be the best way to "name" the buttons something other than 0, 1, 2, 3 etc?
If I try to give each button a specific function, can I use something like:
void mousePressed() { for (int i=0; i<6; i++) { SimpleButton button = buttonList.get(0); v1 = v1 + 1; if (v1 > 3) { v1 = 3; } } }
This seems to not work. I am trying to tell the sketch to "get" the 1st button in the buttonList array...
Sorry, that piece of code ^ seems to not want to format as code :(
@PDF197 You are in a for loop but not testing for which button is pressed. Try this
For labelled buttons use a String array put at top of code before setup.
Then when making the buttons ...
:D