Quantcast
Channel: Philosophy on Software
Viewing all articles
Browse latest Browse all 29

Android UI framework

$
0
0
Android's UI framework looks quite nice when you start. But with projects of increasing complexities and complex views, you end up wondering if Android tools developer team has not gone far enough.

So what's the issue with this?

First of all the things that they done right. the R.java generation and automatic ID generation is marvellous. Why Swing doesn’t have XML UI building blocks and resource reference generation is beyond me...
But then you get into more complex elements. When your views contain a lot of elements, you can look at your basic Swing builder in NetBeans and wonder
"Why is is simpler to attach an event processor for a button click?"
So the UI designer in Android SDK is geared towards designers not caring about what developers do. But most of the time designers work closely with developers. So there is this gap between them in Android.


Now, because Android is supposed to run on constrained hardware dynamically creating structures at runtime is not the most optimal solution. Specially when those structures are XML DOM based.
On the other hand, manually searching for objects using findViewById() is a tedious task.

Now enter the extension to the Android R.java generator.

The simple generator generates a simple static Java structure. Like a Static Metamodel in JPA 2.0 . The major benefit of that, is that you can navigate through the view, using a predefined verifiable structure that is populated on first call or lazily loaded.
That is no more lines like this:
       setContentView(R.layout.main);
      TextView tv = (TextView) findViewById(R.id.textView);

But you do it something along the lines of:
      MainLayout root = MainLayout.populate(this);
      TextView tv = root.linearLayout.textView.get();

This may seem too complex in the second sample, but when you have 10 text elements on the screen it pays off. Why?
Because you only add one single instance variable(a.k.a field) root and operate on it. Accessing a view multiple times does not require you to define a field for each of those views or do a findViewById() every time you need to set some value on that view.

The operation of the generator is pretty simple.
  • It takes the layouts
  • Parses the XML in them
  • Generates a static hierarchy of classes, something similar to generated R.java but for each layout.
  • It does not inherit from anything, so no dependencies are created
  • And it contains the code to differentiate the type of layout applied
  • Call the setContentView() on the activity.

Viewing all articles
Browse latest Browse all 29

Latest Images

Trending Articles





Latest Images