Chameleon


Source link: https://github.com/KNOLSKAPE/chameleon

Chameleon


Motivation

Have you ever stumbled upon a situation where you want to show completely different themes of the same app for different sets of your app users? If yes, you must have definitely worried about the clutter it adds in your code to maintain different drawables for different cohorts of users; this also includes updating your code for every new theme that has to be added.

Chameleon is here to save you from that hassle!

Introduction

Chameleon is a CSS like framework for Android. Chameleon can read styles in JSON format and apply them on views in Android. This way you can skip all the painful steps involved in creating drawables etc.. As of now, Chamelon is limited to only changing the appearence of the views and not the positioning.

Not only can you choose from the variety of styles provided by the library but also add your own styles by changing just one file.

The icing on the cake is, once set up, themes can be updated without pushing a new version of your app to the playstore. So, your users can see your changes on the fly, just by changing the style JSON files on your server.


Steps

In build.gradle

// Your gradle file should look something like this  buildscript {

repositories {

  jcenter()

}

dependencies {

  classpath 'com.android.tools.build:gradle:2.3.2'  
}
  allprojects {

repositories {

  jcenter()
  maven {
 url 'https://jitpack.io' 
}

}
 
}
 

Inside your Application class file

ThemeManagerBuilder

.getInstance()

.withUrl("https://knolskape.s3.amazonaws.com/MLS/ktm1/1495780632_sample_theme_1.json")

.withAsset("sample_theme_1.json", context);
 

Inside your Activity

@Override protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_main);

OnLoadResourceListener listener = new OnLoadResourceListener() {

  @Override public void onLoadFinished(ThemeManager themeManager) {

 themeManager.applyTheme((ViewGroup) findViewById(android.R.id.content), MainActivity.this);

  
}

}
;

 ThemeManagerBuilder

 .getInstance()

 .addListener(listener);
  
}
 

Create your style JSON file under the assets folder or give a remote link

{

"sampleStyle1":{

  "borderRadius":"10",
  "borderWidth":"3",
  "borderColor":"#3F9C35",
  "bgGradientColors":"#0075B0, #3F9C35",
  "textColor":"#FFFFFF",
  "bgGradientType":"BL_TR",
  "textSize":"16"

}
,
"sampleStyle2":{

  "borderRadius":"15",
  "textColor":"#000000",
  "borderWidth":"3",
  "textSize":"16",
  "borderColor":"#0075B0"

}
 
}
  

Inside XML

<?xml version="1.0" encoding="utf-8"?> <LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context="com.knolskape.chameleon.MainActivity"
  android:orientation="vertical"
  > <!-- Note how we supplied the style name from the json in the tag here-->
<TextView

 android:layout_width="match_parent"

 android:gravity="center"

 android:layout_height="70dp"

 android:layout_margin="10dp"

 android:text="Sample Style 1"

 android:tag="sampleStyle1"

 /> </LinearLayout>  

WIP

  • Suport drawable tint for API < 21
  • Exception handling

Resources

This Library automatically search for permission in android manifest file and request for the same.

Also, if request is cancelled it shows a popup window with alert to grant permission. If the app can no longer request permission due to "Don't ask again" on permission it will toast a message to grant permission from settings.

All the action performed after grant or deny can be customized by overriding method shown below. Custom permission can be checked instead of all permission in android manifest file.

PrivacyStreams is an Android library for easy and privacy-friendly personal data access and processing. It offers a functional programming model for various types of personal data, including locations, photos, audios, sensors, contacts, messages, and more.

A simple library that provides utilities to use Firebase SDK in a reactive fashion.

Round Korner Layouts is an Android library create to build a layout with the round corners.

FunnyLoader is an android library which can be used for showing random messages while your app is loading something.

Rapidly fast implementation of SharedPreferences which stores each preference in files separately, performs disk IO via NIO with memory mapped byte buffers and works IPC (between processes).

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