android-metadata


Source link: https://github.com/onehilltech/android-metadata

android-metadata

A utility library for Android designed to simplify reading meta-data values from AndroidManifest.xml.

  • Quickly access a meta-data values from anywhere with few lines of code.
  • Read individual meta-data values into type-specific variables.
  • Instantiate objects from meta-data values.
  • Read one or more meta-data values into annotated Java classes.
  • Use meta-data values to pass configuration parameters to third-party libraries.

Installation

Gradle

buildscript {

repositories {

  maven {
 url "https://jitpack.io" 
}

}
 
}
  dependencies {

compile com.github.onehilltech:android-metadata:x.y.z 
}
 

Getting Started

Here is the quickest and easiest way to load the metadata from AndroidManifest.xml and get a value. The value, by default, is a String value type.

ManifestMetadata metadata = ManifestMetadata.get (context);
  // <meta-data android:name="appid" android:value="32ba65ae723940" /> String value = metadata.getValue ("appid");

If the value is not a String type, then you can provide a hint:

ManifestMetadata metadata = ManifestMetadata.get (context);
  // <meta-data android:name="conn.timeout" android:value="60" /> Integer connTimeout = metadata.getValue ("conn.timeout", Integer.class);

You can even directly load a resource from the metadata:

ManifestMetadata metadata = ManifestMetadata.get (context);
  // <meta-data android:name="appname" android:resource="@string/app_name" /> String appName = metadata.getValue ("appname", true, String.class);

In some cases, you may need to provide additional information about the resource type since different resources types can have the same Java type:

ManifestMetadata metadata = ManifestMetadata.get (context);
  // <meta-data android:name="bgcolor" android:resource="@color/background" /> Integer bgColor = metadata.getValue ("bgcolor", true, Integer.class, ResourceType.Color);

Using Annotations to Load Metadata

Here is the simplest example of using an annotation to define what meta-data value in AndroidManifest.xml it should be initialized with:

public class MyData {

private String appid_;

@MetadataProperty (name="my.message")
public String message;

@MetadataMethod (name="appid")
public void setAppId (String appid) {

  this.appid_ = appid;

}
 
}

In the example above, the field message will be initialized with the value of meta-data tag named my.message. You initialize all values with the @Metadata annotation using a single line of code:

MyData myData = new MyData ();
 ManifestMetadata.get (context).initFromMetadata (myData);

This method will auto-detect the target type, and then assign the value. If the field is not assignable using the meta-data's value, then an exception will be thrown.

Reading from a Resource

In some cases, you will want to read the value from a resource (i.e., you use android:resource in the meta-data tag). You can use the @Metadata annotation to read resource values as well:

public class MyData {

private String appid_;

@MetadataProperty (name="my.message", fromResource=true)
public String message;
 @MetadataMethod (name="appid", fromResource=true)
public void setAppId (String appid) {

  this.appid_ = appid;

}
 
}

Giving Resource Type Hints

There are some resources that have the same field type, such as integer and color. This makes it hard to auto-detect the resources type. We can therefore provide a hint as follows:

public class MyData {

@MetadataProperty (name="my.message", fromResource=true, resourceType=ResourceType.Color)
public int backgroundColor; 
}

In the example above, the value for backgroundColor will be loaded from resources and interpreted as a color.

Resources

Deploy new features to a choosen percentage of uers before delivering it to everyone.

It's useful to see if the new feature is appreciated by users, and do some adjustment before the grand opening.

Panter Dialog is an stylish android library that helps users add cool features like adding header and header logos.

This project adds gradle setup for quality tools like CheckStyle, FindBugs, PMD and Lint to Android project via shell script. After adding this, we can easily increase quality of the project by static code analysis.

Android Auto Scroll ViewPager.

Memory Monitorб always monitor the actual physical memory (pss) or heap memory usage, like Memory Monitor in Android Studio.

Simple and flexible way to configuration RecyclerView using android data binding.

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