vitamin is an universal config library in android.
See details in CHANGELOG.
I have provided a sample.
See sample here on Github.
To run the sample application, simply clone this repository and use android studio to compile, install it on a connected device.
latest version
gradle
dependencies {
//noinspection GradleCompatible
compile "io.github.lizhangqu:vitamin:${latest_version}"
}
maven
<dependencies>
<dependency>
<groupId>io.github.lizhangqu</groupId>
<artifactId>vitamin</artifactId>
<version>${latest_version}</version>
</dependency>
</dependencies>
Add third party support if you need to use.
compile("org.ini4j:ini4j:0.5.4")
compile("org.yaml:snakeyaml:1.18")
compile("dom4j:dom4j:1.6.1")
// you should add this for dom4j in android extension
// dexOptions {
// //fix for dom4j
// additionalParameters = ['--core-library']
// }
compile("com.alibaba:fastjson:1.1.59.android")
compile("com.google.code.gson:gson:2.8.0")
For example, if you need use ini config, you should add compile("org.ini4j:ini4j:0.5.4").
- yaml
- ini
- json
- xml
- properties
- SharedPreferences
Vitamin.getInstance().setConfigType(ConfigType configType)
It's not must be required.
ReadableConfig config = Vitamin.getInstance().getReadableConfig(ConfigType configType, String filePathOrName)
ReadableConfig config = Vitamin.getInstance().getReadableConfig(ConfigType configType, InputStream inputStream)
ReadableConfig config = Vitamin.getInstance().getReadableConfig(String filePathOrName)
ReadableConfig config = Vitamin.getInstance().getReadableConfig(InputStream inputStream)
If you not pass config param, it will get the global type first and then according to the extension about the file.
String getString(String key, String defaultValue);
String getString(String key);
boolean getBoolean(String key, boolean defaultValue);
short getShort(String key, short defaultValue);
int getInt(String key, int defaultValue);
long getLong(String key, long defaultValue);
float getFloat(String key, float defaultValue);
double getDouble(String key, double defaultValue);
//may return null if not support
List<String> getList(String key, List<String> defaultValue);
//may return null if not support
List<String> getList(String key);
//may return null if not support
//may ignore key if needed
Map<String, ?> getMap(String key, Map<String, ?> defaultValue);
//may return null if not support
//may ignore key if needed
Map<String, ?> getMap(String key);
//may return null if not support
<T> T get(String key, Class<T> clazz);
vitamin is under the BSD license. See the LICENSE file for details.