We are about to switch to a new forum software. Until then we have removed the registration on this forum.
How do people run code that is only relevant when running on a phone?
For example I want my sketch look the same in Java and in Android mode. For this I have to use a strokeWeight that is proportional to displayDensity. Problem is the this variable is only available in Android mode. Similarly I only want to call size(width, height) in Java mode.
I can check for Android ...
if (System.getProperty("java.vendor") == "The Android Project") { strokeWeight(3*displayDensity) }
... but this will not compile because Java. In Javascript/Python this would just work because lazy evaluation and in C++ this could be done with #defines.
How do you do that in Processing/Java. Anybody knows a trick to make it work? Reflection module (looks crazy verbose)?
Let me know, Best,
Answers
Ok, figured it out, semi-elegantly ...
I am using the settings method so I can run code before size():
Then in other locations I do:
getValue is my method that uses Refection to access the field dynamically:
I have some similar methods for doing dynamic method calls:
thanks for sharing your solution, i was searching for that kind of stuff for a long time