Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/RomainPiel/Michelangelo
Layout inflation library for Android based on annotations
https://github.com/RomainPiel/Michelangelo
Last synced: 2 months ago
JSON representation
Layout inflation library for Android based on annotations
- Host: GitHub
- URL: https://github.com/RomainPiel/Michelangelo
- Owner: romainpiel
- Archived: true
- Created: 2014-01-22T10:24:37.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-01-23T21:44:01.000Z (almost 11 years ago)
- Last Synced: 2024-08-01T22:43:01.634Z (5 months ago)
- Language: Java
- Homepage:
- Size: 328 KB
- Stars: 142
- Watchers: 7
- Forks: 7
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- android-awesome-libraries - Michelangelo - Layout inflation library for Android based on annotations (Uncategorized / Uncategorized)
README
# Michelangelo
Layout inflation library for Android which uses annotation processing to write the code you don't want to write and simplify your compound views.
## How to use
An example of use:
```java
@InflateLayout(R.layout.custom_view)
public class MyCustomView extends FrameLayout {public MyCustomView(Context context) {
super(context);
}@AfterInflate
public void updateTextView() {
((TextView) findViewById(R.id.my_text_view)).setText("hey!");
}
}
````R.layout.custom_view`:
```xml
```
Inflating that View is pretty straightforward:
```java
MyCustomView view = Michelangelo.build(this, MyCustomView.class);
```## Post inflate methods
Use the annotation `@AfterInflate` on your compound view's methods you want to run straight after the layout is inflated with Michelangelo.
## Michelangelo and ButterKnife
Michelangelo plays very well with Jake Wharton's library [ButterKnife](https://github.com/JakeWharton/butterknife). Just add the annotation `@InjectViews` to your `ViewGroup` and Michelangelo will do the rest.
Example using ButterKnife:
```java
@InflateLayout(R.layout.item_painting)
@InjectViews
public class PaintingItemView extends LinearLayout {@InjectView(R.id.image) ImageView image;
@InjectView(R.id.title) TextView title;public PaintingItemView(Context context) {
super(context);
setOrientation(HORIZONTAL);
}public void bind(Painting painting) {
image.setImageResource(painting.getDrawableResId());
title.setText(painting.getTitle());
}
}
```## Order of events
When you call `Michelangelo.build()`:
1. The view gets inflated
2. If specified, the injector is applied (`ButterKnife.inject(view)`)
3. If exist, methods annotated with `@AfterInflate` are run.## Sample
See the [sample](https://github.com/RomainPiel/Michelangelo/tree/master/michelangelo-sample/src/main) for a common use of this library with `ListView` adapters.
## License
```
Copyright 2014 Romain PielLicensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://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 for the specific language governing permissions and
limitations under the License.
```