ControlP5 Icon Example not running in android

edited June 2016 in Android Mode

Hi I was trying to run the following example in android mode using the ControlP5 Icon which I extracted from the example folder:

import controlP5.*;

ControlP5 cp5;

void setup() {
  size(800,400);
  cp5 = new ControlP5(this);
  cp5.addIcon("icon",10)
     .setPosition(100,100)
     .setSize(70,50)
     .setRoundedCorners(20)
     .setFont(createFont("fontawesome-webfont.ttf", 40))
     .setFontIcons(0x00f205,0x00f204)
     //.setScale(0.9,1)
     .setSwitch(true)
     .setColorBackground(color(255,100))
     .hideBackground()
     ;  
}

void draw() {
  background(220);
}

void icon(boolean theValue) {
  println("got an event for icon", theValue);
} 

It works well in java mode. In android mode, it fails to load the font file located in the data folder. Is there a way to make it work in android mode? I like this toggle button. Or if you have ideas of any other round toggle button that you could share here, it will be very welcome.

Thanks and cheers,

Kf

Answers

  • ControlP5 does not support Android mode AFAIK. You have some options however, you can use native android gui elements, or this library or that. They may not have an icon element, but I'm sure you can choose something.

  • @Ater=== APWidgets lib does not work with P3;not tried with Guido but i think that it does not support android mode P3 @kfrager=== android has its own tooglebutton class which is easy to use

  • How do you quote somebody here? Anyways thxs @Ater and @Akenaton. The toggle button was my first kick at the cat per say and I was forced to use the ControlP5 toggle button which worked but it was less aesthetically pleasing. I think I could make it work but from reading some posts, it looks like I have to switch into eclipse. I would be interested to explore the android togglebutton class. Could you show me an example or point me to an example please? Could I call it from processing?

    Thanks again,

    Kf

  • edited May 2016 Answer ✓

    @kfrager===

    see here for android tb (or switch)

    https://developer.android.com/guide/topics/ui/controls/togglebutton.html

    of course in your code dont forget to import::

    import android.widget.CompoundButton;//for listener
    
    import android.graphics.Color;//for changing the bg color of the tb
    
    import android.widget.ToggleButton;//or switch
    
  • Thanks @Akenaton. I will give it a try

  • Both look great. The Switch is very neat and I will say outperform the ControlP5 icon example. ControlP5 icon was a great way to start...

    I still need to manage setting up size and positions and working with events.

    Thank you,

    Kf

  • I have a quick follow up question in regards to the toggle button. Is there a method to hide/show the toggle or switch objects? My idea is to have two pages, one where I have a blinking LED and a second page where I can setup the rate.

    Kf

  • Answer ✓

    @kfrager=== with native android this is very easy because switch button is a subclass of button which is a subclass of view: so you can write b.setVisibility(View.VISIBLE) or b.setVisibility(View.gone) or b.setVisibility(View.INVISIBLE); ; with processing (i never tried) but when you create the button you have to addView, so you can get the button view and probably code as i said. Another solution could be to change the background color of the button to transparent:: b.setBackgroundColor(Color......);

  • Hi @akenaton

    When you mean addView, would it be something like this, from a previous post of yours?:

      fl = (FrameLayout)act.findViewById(0x1000);
      fl.addView(editA); //an EditText object 
      fl.addView(swt);   // a switch object
    

    I am calling this OnStart(). However I can't make it work on Draw(). I do not understand the life cycle of these elements in P3, or the proper way to call the setVisibility() function. Could you provide me some more guidance? I am almost there.

    Kf

    P.S. Set visibility works in OnStart() !

  • Answer ✓

    Ok, I got it working. To modify the visibility, I had to do it in the following way:

    void removeUIitems() {
      act = this.getActivity();
      act.runOnUiThread(new Runnable() {
        public void run() {
          fl = (FrameLayout)act.findViewById(0x1000);
          editA.setVisibility(View.INVISIBLE); //View.VISIBLE //View.gone //View.INVISIBLE
          swt.setVisibility(View.INVISIBLE);
        }
      });
    }
    

    I was making this call in keyPressed() function. Thanks for your comments.

    Kf

Sign In or Register to comment.