Here a solution for the weird behavior of the buttons from controlP5 on Android/adpe where you have to click twice to actually click the button.
This solution works with a single click and also with sliding the finger onto the Button and releasing.
The Button highlight is still a problem since if have no clue how to use the setColor() for the Button.
I’d appreciate any help on that one…
edit: figured out how to use the clor optionand added that to the first button
But when using an image for the button its not visible
here’s the code:
/*
controlP5 button workaround for android/adpe
by AmyS3
*/
import controlP5.*;
ControlP5 cp5;
CallbackListener cb;
String pbp=null;// we use those tho hold the button name
String pbp2=null;
color btncolor = color(#123456);
void setup()
{
fullScreen();
background(255);
cp5 = new ControlP5(this);
// make a few buttons to test
cp5.addButton("b1")// that's the name we use to know which button is pressed
.setCaptionLabel("Button 1")
.setPosition(100, 100)
.setSize(200, 50)
.setColorBackground(btncolor)
.setColorForeground(btncolor)
.setColorActive(btncolor)
;
cp5.addButton("b2")
.setCaptionLabel("Button 2")
.setPosition(100, 160)
.setSize(200, 50)
;
cp5.addButton("b3")
.setCaptionLabel("Button 3")
.setPosition(100, 220)
.setSize(200, 50)
;
//create a custom callbacklistener
cb = new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
switch(theEvent.getAction()) {
case(ControlP5.ACTION_ENTER):
// here we get the Button name when sliding in, or first click on this button
pbp=theEvent.getController().getName();
break;
case(ControlP5.ACTION_CLICK):
pbp2=theEvent.getController().getName();
if (pbp==null)
{// this gets fired when clicking the same button twice
click(pbp2);
}
break;
case(ControlP5.ACTION_LEAVE):
// clear the pbp when sliding out, so we don't click outside the button
pbp=null;
break;
}
}
};
// add the above callback to controlP5
cp5.addCallback(cb);
}
void draw()
{
// this is for a first click or sliding in
// and it needs to be in the draw() or it won't work
// when using the mouseReleased() its not working
if (!mousePressed&&pbp!=null)
{
click(pbp);
}
}
void click(String btn)
{
// here you can put your actual clicking code
// you get the button name (eg. b1) and use that to discern
// with if's or switch case.. etc.
/*
for example:
if(btn=="b1")
{
awesomefunction()
}
*/
pbp=null;// clear the name holder's
pbp2=null;
println(btn);// and action...
}