ConfigDroid


Source link: https://github.com/mb-14/ConfigDroid

ConfigDroid

ConfigDroid is a gradle plugin for Android Projects which lets you access configuration properties defined in your build.gradle file in the form of constants generated in a java class.

Download and setup

Add these dependencies to your build.gradle:

buildscript {

  repositories {

jcenter()

maven {

 url  "http://dl.bintray.com/mb-14/ConfigDroid"

}

  
}

  dependencies {

classpath 'com.android.tools.build:gradle:2.3.1'

classpath 'com.mb14:configdroid:1.1.0'
  
}
 
}
 apply plugin: 'com.mb14.configdroid'  configdroid {

  // Define properties here 
}

Usage

Basic Usage

Global properties can be defined in the configdroid closure. You also need to define the class name, package name and output directory for the generated java class.

configdroid {

  className "ConfigDroid"
  packageName "com.mb14.configdroid"
  access "public" // Options: public, package-private

 prop "API_ENDPOINT", "https://api.twitter.com"
  prop "ENABLE_LOGGING", true
  prop "DATABASE_VERSION", 3
  prop "API_KEY", TWITTER_API_KEY //Property defined in gradle.properties 
}

This generates the following source code in ConfigDroid.java

package com.mb14.configdroid;  import java.lang.Boolean; import java.lang.Integer; import java.lang.String;  public class ConfigDroid {

public static final String API_ENDPOINT = "https://api.twitter.com";
 public static final Boolean ENABLE_LOGGING = true;

public static final Integer DATABASE_VERSION = 3;
 public static final String API_KEY = "hvtcOOoFM4"; 
}
  

Build Variant Specific Config

You can define config properties specific to product flavors and build variants as well. You can use the same key in different variants and ConfigDroid will override the values in the following order: global < product flavor < build type

configdroid {

  className "Constants"
  packageName "com.example.utils"
  access "public"
  prop "DATABASE_VERSION", 3

 productFlavors {

pro {

 prop "ENABLE_FEATURE_X", true

}

free {

 prop "ENABLE_FEATURE_X", false

}

  
}

 buildTypes {

debug {

 prop "API_ENDPOINT", "http://localhost:3000/twitterapi"

 prop "ENABLE_LOGGING", true

}

release {

 prop "API_ENDPOINT", "https://api.twitter.com"

 prop "ENABLE_LOGGING", false

}

  
}
 
}

Embed file contents as String constants

configdroid {

  file "JS_SCRIPT", file('webview_inject.js') 
}

Possible property types

configdroid {

  // Primitives
  prop "API_ENDPOINT", "http://api.twitter.com"
  prop "ENABLE_LOGGING", true
  prop "DATABASE_VERSION", 3
  prop "API_TOKEN", TWITTER_API_TOKEN //Property defined in gradle.properties
  prop "FLOAT_CONSTANT", 9.8f
  prop "DOUBLE_CONSTANT", 9.8d
  prop "LONG_CONSTANT", 122424343535l
  prop "CHAR_CONSTANT", 'a' as char
  prop "BYTE_CONSTANT", 0b11 as byte
  prop 'BUILD_UNIXTIME', System.currentTimeMillis()

// Arrays
  prop "STRING_ARRAY", ["hello", "world"]
  prop "INT_ARRAY", [1,2,3,4]
  prop "DOUBLE_ARRAY", [9.8d, 24.34d, 44.44d]

// Custom objects and initializations
  prop 'java.util.Date', 'BUILD_DATE', 'new Date(' + System.currentTimeMillis() + 'L)'
  prop 'boolean', "REQUEST_RUNTIME_PERM", 'android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M'
  prop 'int', 'THEME_COLOR', 'android.graphics.Color.parseColor(\"ff0000\")' 
}

Resources

This library is meant to offer a wrapper around the standard Android Log.x methods in few distinct flavours. It gives you the possibility to have one logger that will use the same logging tag for the whole app and also the ability to quickly change the logging level for the whole app - you can go from debug to release by changing just one constant.

Simple drawee spannable text view based on Fresco.

An android socializing SDK that supports to share text/image/web page/video/audio to qq/qzone/wechat/moment/sina platforms.

Blueteeth is a simple, lightweight library intended to take away some of the cruft and tediousness of using the Android BLE API.

Response logging interceptor for OkHttp. Logs a url link with url-encoded response for every OkHttp call.

restafari is an android library mostly oriented to facilitate REST API calls to a server and storing the server API response to a local SQLite database.

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