Painter


Source link: https://github.com/agrosner/Painter

Painter

Why use different colors of the same asset when you can include one color and change it to fit your needs? Also how do you handle dynamic changes such as when you use a drawer and want to do some really neat effects?
This library enables you to color a view, image icons, and text in a very simple way.

Usage

PreRequisites

  1. This project includes android support-v4:20.+ and appcompat-v7:20.+. I will make sure to make a version using only native dependencies or without appcompat.
  2. This project currently compiles with API 20 and buildToolsVersion 20.0.0, hopefully there will be a way to use project level in the future.
  3. MinSdk is 5, however with appcompat and support that is upped to 8. I will try to make it lower for non-support libraries.
  4. This project is currently in active development. Using the development branch has no guarantees of working functionality and or/breaking changes to code. The best bet is the master branch for all stable releases, or by using a remote aar dependency.

Including in your project

  1. Clone this repo
  2. Go to your build.gradle file
dependencies{

compile 'com.github.agrosner:library:1.0.+'

//or locally in the a folder named "Libraries"
compile project(':Libraries:Painter');
 
}
 

Painting

Painting is the simple way of changing the color of an object (ActionBar, MenuItem, or Views) without much hassle.
Let Painter handle coloring your wonderful visual elements.

Icon Painting

Icon painting is a very simple way to change the color of any Imaged-backed object you want. Note: this works well on small icons, but larger images I would refrain from using.
Example 1:

  // "object" applies to a MenuItem, ImageView image, or TextView compound drawable. 
// this is a varg param
// "cloneDrawable" specifies we want to mutate the drawable so that any changes to it will not be globally saved
IconPainter iconPainter = new IconPainter(cloneDrawable, Color.BLACK);

iconPainter.paint(object);

//specify a PorterDuff Mode for different effects
iconPainter.withMode(mode);

 //can reuse object for different paints if you wish
iconPainter.paintColor(cloneDrawable, Color.Black, object1, object2, objectn);

Background Painting

Background painting will take the background of the item you pass in (namely it's background drawable) and change the color as well. It is strongly advised you do not paint the actionbar background more than once on first load as this is extremely inefficient due to the fact we cannot easily retrieve the background drawable once it is set on the actionbar.


Example 1:
```java

//we can use many View, MenuItem's action view, or ActionBars new BackgroundPainter(cloneDrawable, Color.BLUE).paint(view, actionView, actionBar);

//can use different paints if you want new BackgroundPainter().paintColor(cloneDrawable, Color.Blue, objects);

 ### Sliders  Sliders describe mutating a property from one value to the next based on a ratio from 0 to 1.  <br /> Supported Sliders include: * AlphaSlider * ColorSlider * Create your own *PropertySlider* class  #### Alpha Slider  This will set the background alpha on the object you pass in whether its an ActionBar, MenuItem, or View.  ```java
 //"slideOffset" is a number from 0...1 and "myObjects" is a varg param that operates on multiple objects
new AlphaSlider(startFullAlpha).onSlide(slideOffset, myObjects);

//this will set the color of the actionbar and begin sliding.
 // this required for an actionbar as there is no easy way to acquire the ActionBar drawable background
new ActionBarAlphaSlider(startFullAlpha, actionBar, startColor);
  

Color Slider

This will slide from one color to another, displaying all colors in between to create a nice "blending" effect. You pass in the correct Painter you want to paint with so it knows which property to look for.

  new ColorSlider(Color.Black, Color.WHITE).with(new BackgroundPainter()).onSlide(slideOffset, object1, object2,objectn);

new ColorSlider(getResources().getColor(R.color.my_color), getResources().getColor(R.color.my_color_2)).with(new IconPainter()).onSlide(slideOffset, icon1, icon2, icon3, iconn);

ActionBarColorSlider slider = new ActionBarColorSlider(actionBar, startColor, endColor);

...
slider.onSlide(slideOffset);
 

Open Source

I will love and appreciate all merge requests. Here are some basic rules on them:

  1. Try to match my coding style.
  2. If they require any breaking changes, they must be on development branch, otherwise I will reject them.
  3. Please leave a summary of what you changed/added.

Thank you!

License

The MIT License (MIT)

Copyright (c) 2014 Andrew Grosner

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Resources

Glass-break effect for views.

A view to draw Bezier curves.

A simple wheel view for Android.

An Android library to make thumbs +1 effect. It supports text and images.

A pretty Music Player demo created by Anish Chandran and coded by André Mion

VirtualApp is an open platform for Android that allows you to create a Virtual Space, you can install and run apk inside. Beyond that, VirtualApp is also a Plugin Framework.

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