Decor


Source link: https://github.com/chemouna/decor

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.

Resources

This is an improved version of the original FragmentStatePagerAdapter with important changes that add support for changing the order and count of items.

Morphing play-pause animated drawable.

To solve database upgrade of greenDao and just need one line code.

Gradient-Artist library will allow you to use gradient overly on top of the image. It uses Glide for network image loading.

Google finally added a bottom tab bar as a recommended design pattern for Android, so we decided to realize one of our cute animations for the BottomTabBars.

Android component that solve the problem with not auto fitting content to the boundaries.

Working on scaling instead of font size changing. Can operate on any view inside the container.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes