Working with Android Studio

Hello,

I am probably missing a very simple thing but I’ve been struggling for a while now without finding a solution. I am very new to android Studio so it may be a dumb question but is there a way, in Android Studio, to work with tabs as on the processing IDE?

On the processing IDE, I can create tabs for different functions or classes used by the sketch.
Once I run the sketch, the different functions and classes are somehow linked to the sketch that uses them. And everything works OK.

With android Studio, I can also create classes that appears in the project view and as tabs if I open them :

If I want the projetc to compile, I also have to declare these classes (for example the class “slider” like that:
public class slider extends PApplet {
I then have a little green triangle sympol on the class icon:
image

Apparently there is no problem when I create an object from that class in the sketch, but as soon as this object uses a processing function like colormode(), stroke(), rect() or line(), the app crashes without any error messages.

If I declare the same class inside the “sketch extends PApplet{” like this:
public class slider {
then everything works ok and the application doesn’t crash.
But it is not handy at all to have the whole code at the same place…

as you are no longer working in the native pde environment you will probably have to redeclare your imports in each class you create.

Its the same concept in eclipse when working with java classes as opposed to sketch files. Sketch files normally wrap everything for you so you dont have to however android studio doesnt as its a different operating environment and is meant to cater for general purpose building.

Again you are going to want to redeclare your dependencies.

ie

import processing.core.PApplet;
import processing.core.PConstants;
import processing.core.PGraphics;
import processing.core.PVector;

among a few you could be using depending on what your program is doing.

or you will have to import your PApplet element and reference it when you are making use of PApplet specific code. IE when you are calling color you can now no longer use color and this is now replaced by int, in your class header file, as it will give you an error. You can no longer instance color in your class header variables and this has to be done withing your constructor or your functions, when doing so you have to call the PApplet element you are making use of and call the color function within that element.

PApplet creates an applet → you pass the applet into your class, in the constructor, and store it as a variable, then call, applet.color to assign color values.

Its now good you can use processing within your application, downside is many of the simplifications which make processing great now disappear as you have to be explicit with your code.

here are some but not all functions and variables which have to call a PApplet instance

color,fill,stroke,strokeWeight,rect,ellipse,beginShape,mouseX,mouseY,pow…

then you have some static functions, whch will just require you import them, such as
atan,atan2,abs…

1 Like