Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chemouna/decor
Android layout decorators : Injecting custom attributes in layout files, Using decorators to get rid of unnecessary class explosion with custom views
https://github.com/chemouna/decor
Last synced: 14 days ago
JSON representation
Android layout decorators : Injecting custom attributes in layout files, Using decorators to get rid of unnecessary class explosion with custom views
- Host: GitHub
- URL: https://github.com/chemouna/decor
- Owner: chemouna
- License: apache-2.0
- Created: 2015-04-12T10:52:59.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-07-29T13:36:41.000Z (over 3 years ago)
- Last Synced: 2024-07-31T07:17:21.553Z (3 months ago)
- Language: Java
- Homepage:
- Size: 1.59 MB
- Stars: 302
- Watchers: 11
- Forks: 23
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- -awesome-android-ui - Decor - 2.0) | <img src="/art/decor.png" width="49%"> (Index `(light-weight pages)`)
- awesome-android-ui - Decor - 2.0) | <img src="/art/decor.png" width="49%"> (Index `(light-weight pages)`)
- awesome-android-ui - Decor - 2.0) | <img src="/art/decor.png" width="49%"> (Index)
README
Decor
======*Decor* is a library that applies decorators to Android layout with additional attributes
without the need to extend and create a custom View for each functionality.Decor plugs into Android's layout inflation and applies custom attributes to Views.
If you have written a custom View like AutofitTextViewWithFont : to make a TextView resize it's text and have a specific font
and if you want to animate it you can write a custom View like AnimatedAutofitTextViewWithFont and if there's another runtime
custom attribute you want to add you will have to yet create another custom View.
Decor comes to the rescue to solve this unnecessary class explosion by using a separate decorator for each functionality :
: AutoFitDecorator , FontDecorator, AnimateDecorator (See decorators module for examples of how to create a decorator)
and register them in attachBaseContext :
```java
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(DecorContextWrapper.wrap(newBase)
.with(Decorators.getAll()));
}
```
```xml
```
or with an ImageView :
This has the advantage of reusing these decorators in other Views.
The module decorators contains some examples of useful decorators that you can start using now,
or write your own by extending ``` AttrsDecorator``` where T is the type of the View the decor will be applied on.If you want to apply only a subset of decorators :
```java
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(DecorContextWrapper.wrap(newBase)
.with(new FontDecorator());
}
```Check the samples for a working example :
![](images/decor_sample.png)
Android Studio (lint) will likely mark this XML with a warning despite being correct. You may want to add tools:ignore="MissingPrefix" to either the View itself or its parent ViewGroup to get rid of it. Also add tools namespace xmlns:tools="http://schemas.android.com/tools" to have access to "ignore" attribute.
Binaries
========Binaries and dependency information for Maven, Ivy, Gradle and others can be found at [http://search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Ccom.mounacheikhna).
for Gradle:
```groovy
compile 'com.mounacheikhna:decor:0.2.4'
compile 'com.mounacheikhna:decorators:0.2.4'
```and for Maven:
```xml
com.mounacheikhna
decor
0.2.4com.mounacheikhna
decorators
0.2.4```
and for Ivy:
```xml
```
Want to help?
=============File new issues to discuss specific aspects of the API or the implementation and to propose new
features or add new decorators.Licence
=======
Copyright (c) 2013 Madis Pink
Copyright (c) 2015 Mouna CheikhnaLicensed 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.External code
=======
This project includes code from third parties:
[pretty](https://github.com/madisp/pretty) by [Madis Pink](https://github.com/madisp). MIT licence.