• Stars
    star
    304
  • Rank 137,274 (Top 3 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 9 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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 :

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

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<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 :

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.

for Gradle:

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

and for Maven:

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

and for Ivy:

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

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.

More Repositories

1

frame-gradle-plugin

A gradle plugin to automate framing android screenshots with devices frames in multiple languages and with multiple screen sizes.
Groovy
131
star
2

HaskellResources

Compilation of useful resources for learning Haskell
113
star
3

ClojureResources

Compilation of useful resources for learning Clojure and generaly LISP
96
star
4

HarryPotterBooks

An app display all Harry potter books details (From a custom server and goodreads api) with lots of animations/transitions.
Java
91
star
5

Rx-Resources

To Aggregate resources to learn and understand RxJava, Rx Android (and Rx in general)
67
star
6

Kotlin-Resources

To Aggregate resources to learn and understand Kotlin
44
star
7

Nearby

Foursquare client written in kotlin.
Kotlin
38
star
8

FindForMe

An android application demonstrating usage of Dagger, Tape, RxAndroid , Otto, Picasso, Retrofit and some Android-L features
Java
9
star
9

til

My Today I Learned
8
star
10

AlgorithmsCatalog

Attempt to catalog algorithms by the problems they solve generaly
5
star
11

gbasic

A small interpreter for BASIC written in go.
Go
4
star
12

Computer-Science-Concepts

3
star
13

gradle-play-publish

Groovy
3
star
14

androiddocs

Android documentation tool
Haskell
3
star
15

AndroidCustomComponents

A set of android custom components
Java
2
star
16

EulerPlayground

Solving project Euler problems in various languages (Java, Groovy, Scala, Haskell, Clojure, Kotlin...) and with different paradigms (functional, Rx,...)
Java
2
star
17

AlgorithmsDesignManual

Some exercises solutions for The Algorithm Design Manual 2nd Edition
Python
2
star
18

99logic

Solving 99 Prolog Problems (https://sites.google.com/site/prologsite/prolog-problems) with core.logic
Clojure
1
star
19

RxJavaMagicSequenceProblem

Java
1
star
20

365papers

A paper a day
1
star
21

4clojure

My solutions to 4clojure exercices
Clojure
1
star
22

adb-gradle-plugin

Groovy
1
star
23

haskell30SecondsOfCode

Haskell
1
star
24

99Clojure

Clojure
1
star
25

algojs

JavaScript
1
star
26

AlgorithmsStudy

Hopefully more cleaner version than https://github.com/chemouna/AlgorithmsCatalog
1
star
27

ProgrammingPearls

Practicing with ProgrammingPearls book
Java
1
star
28

AlgorithmsPy

My solutions to some algorithms in Python
Python
1
star
29

StopWatchSample

Kotlin
1
star
30

android-release-plugin

Groovy
1
star
31

AlgorithmsInC

C++
1
star
32

365papers-1

List of Papers I read updated daily (or not so daily).
1
star
33

AlgorithmsRust

Rust
1
star
34

AndroidArchitectureComponents

Playing with Android Architecture Components
Kotlin
1
star
35

AndroidFontStateList

Apply custom font state list
Kotlin
1
star
36

algebra

Implementing some algebraic structures in Haskell
Haskell
1
star
37

AiResources

Resources for learning AI
1
star
38

.emacs.d

My personal emacs settings
Emacs Lisp
1
star
39

AlgorithmsProofs

1
star
40

AINotes

1
star
41

AlgorithmsInRuby

My implementation of some algorithms in Ruby
Ruby
1
star
42

RxJavaAndroidDemos

Learning RxJava on Android
Java
1
star
43

AlgorithmADay

Learn an algorithm a day
Java
1
star
44

99Haskell

My Solutions to haskell 99 Problems (https://wiki.haskell.org/H-99:_Ninety-Nine_Haskell_Problems)
Haskell
1
star