How to know within the code if I'm targeting android or java?

Ello

Really enjoying Processing and how quickly I can realise and play with my ideas on my phone! I’m used to Unity which in comparison takes ages to build and deploy to handset.

Buuuuuuuuut I really do prefer the immediate feedback of playing in java mode.
So, how can I write a conditional based on the current environment mode?
I want the editor to change things for me if I’m expecting mouse input or touch input, rather than manually change a boolean every time I switch between java and android. I know I’ll forget and it will get irritating!

I’m working on an instrument for making visuals instead of sound, but that’s for another post :wink:

Thanks

Hi @Nicholas.
Could you be more specific?
mousePressed() and keyPressed() stay the same. Only when you use multi touches things are different.
The most problematic issue I found in P4A that you are dealing with a large variety of devices, each with different display densities and pixel screen sizes.
Therefore I am forcing myself to place every object or text related to width and height.
For instance, when you want to specify a font size, using; textSize * pixel density(), will still give problems.
On my android repo, I have a file showing the best way I found until now how to deal with this.
Maybe this will interest you.

Hi @noel

I’m making an app for my phone, but to make manual testing and debugging easier I have my mode in the Processing IDE set to Java. (I don’t want to have to deploy to handset every time I want to run it).

So I want to do something like:

if(onAndroid)
{
// handle input with touches
}
else
{
// handle input with mousePressed etc
}

I just want to know if it’s possible to find the value of onAndroid somewhere rather than setting it manually. I need to turn one system of input off when the other is in use.

Thanks for responding btw

I am not aware of such a constant.
The only thing I know is, that the preferences file keeps track of the last mode used.
So you could trace that with something like:

 String[] str = loadStrings("C://Users/Noel/AppData/Roaming/Processing/preferences.txt");
 String str2 = join(str, ",");
 int p = str2.indexOf("mode.last=processing.mode.java.JavaMode");
 if (p == -1) println("last mode was android mode");

But I think this won’t help you any further.

Wow thanks @noel, that was exactly what I was looking for!

:hugs: