Struggling to understand the proper way to use Jungles...

I've recently released a DataField which aims to support quite a wide array of device layouts. After playing with different ways of defining the layout differences between screen sizes, I settled on a solution of using JSON resources - nice and elegant - then went to support the Forerunner 235 with it's 1.X SDK that doesn't support JSON resources. So I resorted to defining string resources, all of which are integers, and converting them to toInt() on initialization. I have about 7 different layout.xml files in resource folders containing my layout variables defined as strings, and whilst this technique absolutely does work, it is obviously not the proper way to describe a layout; it is (a) smelly because it is a perversion of the intended use of string resources, (b) causing build warnings about strings being defined multiple times for the same language and (c) probably not optimally efficient since it is performing an unnecessary type conversion and storing both the string keys and values in memory as well as the converted integers.

I figured I'd try creating several Layout.mc files instead and declare simple global variables in each, then get the the jungle to include the right one at build time. If that's what jungles are supposed to do, I can't figure out how to make it work. Depending on where I put the files I either get build errors because the variables are defined multiple times or not at all.

Anyway, rather than describing the solution I want, I'll describe the problem and ask if anyone can provide a memory-efficient solution that is better than using string resources. I have about 15 integer values that need to be different for each screen size. I need to retrieve those values once, at startup. I want the retrieval of those values to be as memory efficient as possible, and preferably, I'd like the place where they are defined to allow for either comments or descriptive variable names that make their intention clear without creating unwanted memory bloat.

If anyone can point me in the right direction I'd be very grateful.

  • So in my case, heartRateIconX is simply defined as a global variable - it's inherently available for use everywhere including inside my views. In normal programming this would be a foul code smell that I would be ashamed of, but Monkey C isn't normal programming because you're constrained to such harsh memory limits - especially on the Forerunner 235 etc.

    What I wanted to achieve here was the absolute minimum memory allocation possible, which means no unnecessary classes, no resources, no type conversions - just a raw value declared globally and referenced globally. So yeah, the examples you see above are "as is"; the Layout.mc files contain literally bare "var" statements not wrapped inside any class or anything. And it works Slight smile

    My project is open sourced at https://github.com/wwarby/walker if you're interested to see how it hangs together.