Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (788)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (860)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Android: automagical PreferenceActivity generation  (Read 3824 times)
0 Members and 1 Guest are viewing this topic.
Offline ryanm

Senior Devvie

Projects: 1
Exp: 15 years

Used to be bleb

« Posted 2010-12-01 11:53:50 »

The android APIs are a strange and confusing place: onThis(), onThat(), onTheOther(), the ubiquitous Context and the multipurpose Intent, the lack of javadoc-style usage information in the docs, etc, etc. It all got too much for me, and so I scurried off through GLSurfaceView and android.opengl and pretended I was safe, back in nice familiar LWJGL.

However, I still need some kind of interface for user preferences and the like. I'm buggered if I'm going to write/integrate an OpenGL widget library when PreferenceActivity is right there, but:
  • Hand writing XML every time I add a variable is not my idea of fun
  • It's not clear how you get at the results of hierarchical preference structures
  • What if I want more than primitive and String types?

So I sallied forth into unknown territory and carved out an automagical PreferenceActivity generator. Annotate your object graph to form a tree structure of variables and call configure. Your variable tree will be reflectively extracted, encoded, and used to create a PreferenceActivity where you can change values and load and save configurations.
When you're done with the preferences, control will be returned to your activity and the configuration will be applied via the onActivityResult callback. There's also a mechanism to save and load configurations programmatically.
See here for an example of annotation usage, and here for launch and callback usage. The resulting gui looks like this

with nice appropriate widgets/input methods

Out of the box, it'll handle ints, floats, Strings, enums, packed-int colours, Points and trigger void-return/no-argument methods. It'll also handle encapsulated variables if you annotate the get and set methods.
You've got full control over the order and grouping of widgets

If you want to control a more complex datatype in a single widget, you'll have to create a VariableType implementation. For instance, here is a VariableType to control a Vector2f.

You can also override variable type for the purposes of widget selection: I store colours as packed integers, but it's not very helpful to edit them as such. Instead I use WidgetHint and ColourVarType to let me type in r,g,b,a quads.

Project is over here, javadoc is over here, BSD-licence-free to a good home.

In addition: the android libraries aren't so scary any more :-)

Edit: I've moved this project into its own repository, and named it. Tremble at the feet of Preflect!
Offline CommanderKeith
« Reply #1 - Posted 2010-12-04 23:10:34 »

I've got a friend who develops for android and he says the xml state saving is a massive headache. I'll let him know about this!

Pages: [1]
  ignore  |  Print  

hadezbladez (2081 views)
2018-11-16 13:46:03

hadezbladez (799 views)
2018-11-16 13:41:33

hadezbladez (2050 views)
2018-11-16 13:35:35

hadezbladez (414 views)
2018-11-16 13:32:03

EgonOlsen (3444 views)
2018-06-10 19:43:48

EgonOlsen (3666 views)
2018-06-10 19:43:44

EgonOlsen (2271 views)
2018-06-10 19:43:20

DesertCoockie (2993 views)
2018-05-13 18:23:11

nelsongames (3070 views)
2018-04-24 18:15:36

nelsongames (3786 views)
2018-04-24 18:14:32
Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!