Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (497)
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 2361 times)
0 Members and 1 Guest are viewing this topic.
Offline ryanm

Senior Member


Projects: 1


Used to be bleb


« Posted 2010-12-01 12: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-05 00: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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (11 views)
2014-04-15 18:08:23

BurntPizza (10 views)
2014-04-15 03:46:01

UprightPath (23 views)
2014-04-14 17:39:50

UprightPath (10 views)
2014-04-14 17:35:47

Porlus (27 views)
2014-04-14 15:48:38

tom_mai78101 (49 views)
2014-04-10 04:04:31

BurntPizza (107 views)
2014-04-08 23:06:04

tom_mai78101 (207 views)
2014-04-05 13:34:39

trollwarrior1 (176 views)
2014-04-04 12:06:45

CJLetsGame (182 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org 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‑gaming.org
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!