Giter Site home page Giter Site logo

msoftware / decor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chemouna/decor

0.0 2.0 0.0 1.67 MB

Android layout decorators : Injecting custom attributes in layout files, Using decorators to get rid of unnecessary class explosion with custom views

License: Apache License 2.0

Java 100.00%

decor's Introduction

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 functionnality.

Decor plugs into Android layout inflation and applies custom attributes to views. This library was inspired by Pretty https://github.com/madisp/pretty.

If you have written a custom view like AutofitTextViewWithFont : to make a textview resizes 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 seperate decorator for each functionality : : AutoFitDecorator , FontDecorator, AnimateDecorator (See decorators module for examples of how to create a decorator) and register them in attachBaseContext :

@Override
protected void attachBaseContext(Context newBase) {
   super.attachBaseContext(DecorContextWrapper.wrap(newBase)
           .with(Decorators.getAll()));
}
 <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="I'm a TextView"
        app:decorTypefaceAsset="Ubuntu-M.ttf"
        app:decorAutoFit="true"
        app:decorAnimate="true"/>

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<T> where T is the type of the view the decor will be applied on.

If you want to apply only a subset of decorators :

@Override
protected void attachBaseContext(Context newBase) {
    super.attachBaseContext(DecorContextWrapper.wrap(newBase)
            .with(new FontDecorator());
}

Check the samples for a working example :

Binaries

Binaries and dependency information for Maven, Ivy, Gradle and others can be found at http://search.maven.org.

for Gradle:

compile 'com.mounacheikhna:decor:0.2.3'
compile 'com.mounacheikhna:decorators:0.2.3'

and for Maven:

<dependency>
    <groupId>com.mounacheikhna</groupId>
    <artifactId>decor</artifactId>
    <version>0.2.3</version>
</dependency>
<dependency>
    <groupId>com.mounacheikhna</groupId>
    <artifactId>decorators</artifactId>
    <version>0.2.3</version>
</dependency>

and for Ivy:

<dependency org="com.mounacheikhna" name="decor" rev="0.2.3" />
<dependency org="com.mounacheikhna" name="decorators" rev="0.2.3" />

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 Cheikhna

Licensed 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 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 for the specific language governing permissions and
limitations under the License.

External code

This project includes code from third parties: pretty by Madis Pink. MIT licence.

decor's People

Contributors

chemouna avatar andreipop avatar

Watchers

Michael jentsch avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.