Annotation-based Layout Engine (AbLE)
AbLE is a layout engine for the Android
platform that allows
developers to write layouts using Java
code and XML
interchangeably.
There are 9 annotations that are currently used: Layout, LayoutAdapter, XMLLayout, Invisible, Binding, Variable, Embed, Setter and Getter.
View
classes in the layout. Variables
can be handy for things that need to be modified before assigned.
These modifications can happen in a static block. @Variable
, if it exists.There is also a View
Object called AbLE_Annotation. This can be set in XML
and, using custom XML
parameters, can point to an annotated layout file to be handled by AbLE. This class is currently in beta, and should not be relied on as-is.
The benefits of using a code-based layout system include the ability to declare types and parameters programmatically, and use complex types (any Object).
There are downsides as well. For example, there is no validation of attributes. It is also not directly cross-platform compatible, but it requires less set up in Android than an XML-based architecture.
The layout inflater recursively creates all the layouts and set their attributes using reflection. Other features that improve speed of coding include the ability to define the layout file in activity meta-data
.
Currently available meta-data
tags are as follows:
At the Application level:
x
MUST be lower-case, and W
and H
MUST be integer
values.contentSize
is set. To use a background resource, set the
android:resource
attribute. Otherwise, if a String
is used, use a color, such as "red" or "blue".
A hex color should be preceded with an escape character ("\"). See Stack Overflow.At the Activity level:
Finally, there are many useful functions for logging, debugging, and gathering information about the device and screen size available in both the AbLEActivity
and AbLEUtil
classes.
Much more detailed information is included in the javadocs, and a simple example is provided as a test project.
Copyright 2013 Phil Brown
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. The license text is printed below, and you may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License (online or below) for the specific language governing permissions and limitations under the License.
For the redistribution section of the license, there is a Java annotation available on GitHub (and already within AbLE) that is meant for annotating changes to source code.
Feel free to use this for annotating changes to AbLE. You can find this code at https://github.com/phil-brown/Modified or in the model package.