I’m aware of all the arguments against conditional compilation in Java. In this specific case, I’d only want to have a small IF in order to be able to test whether the code runs in Eclipse or not. The reason for this is that when I override a View to use my special processing, Eclipse in some cases cannot compile the modified View and display it in the IDE (there are many cases resulting in this behavior but a specific one is when the code refers to a JNI library that Eclipse, obviously, cannot execute).
Right now I’m using
if (!Build.DEVICE.startsWith("generic"))
// do something
and it works but I don’t really like doing a string comparison every single time in an onDraw(), for instance. I’d need a simpler way, a cheaper condition to see if I’m in Eclipse and avoid some actions then.
Edit: To be clearer, I’m looking for a possible Java/Android/Eclipse equivalent of C#’s Component.DesignMode property.
The best I could come up with so far is:
This is a singleton class that encapsulates the check and can be queried as: