jberkel/android-plugin — pull request #188 by taku0 (2013-08-12 14:52:01+00:00)
Title: Add another typed resources task

I wrote another typed resources task. This utilize lazy val for more natural interface. For example, suppose we have the following layout:
login.xml:
```xml

```

An activity using conventional typed resources may be like this:
```scala
class LoginActivity extends Activity {
var usernameField: EditText = _
var passwordField: EditText = _

protected override def onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState)

setContentView(R.layout.login)

usernameField = findView(TR.layout.username)
passwordField = findView(TR.layout.password)

findView(TR.layout.loginButton).setOnClickListener(
new View.OnClickListener {
override def onClick(view: View) {
doLogin()
}
}
)
}

def doLogin() {
val username = usernameField.getText
val password = passwordField.getText

...
}
}
```

With new typed resources, we can write it more concisely:
```scala
class LoginActivity extends typed_resource.layout.Login.Activity {
protected override def onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState)

views.loginButton.setOnClickListener(
new View.OnClickListener {
override def onClick(view: View) {
doLogin()
}
}
)
}

def doLogin() {
val username = views.username.getText
val password = views.password.getText

...
}
}
```

Note that we do not have to call `setContentView`.

Views such as `views.loginButton` are defined with `lazy val`.

Since `typed_resource.layout.Login.Activity` is a trait rather than a class, we can use custom base activities:
```scala
class LoginActivity extends MyBaseActivity with typed_resource.layout.Login.Activity {
...
}
```

We can also define dialogs in a similar way:
```scala
class LoginDialog extends with typed_resource.layout.Login.Dialog {
...
}
```

Moreover, we also have wrappers suitable for use with `LayoutInflater` or `SimplerAdapter.ViewBinder`:
```scala
val layout = typed_resource.layout.Login(layoutInflater.inflate(R.layout.login, container))

layout.views.username.setText(username)
...
```

I will enhance this task to generate other value resources (e.g. strings, ints, colors).

I named it `TypedResources2` provisionally, but more appropriate name is wanted. Are there any better names?