https://github.com/lizhangqu/vitamin
vitamin is an universal config library in android.
https://github.com/lizhangqu/vitamin
adnroid config ini json properties sharedpreferences universal xml yaml
Last synced: 3 months ago
JSON representation
vitamin is an universal config library in android.
- Host: GitHub
- URL: https://github.com/lizhangqu/vitamin
- Owner: lizhangqu
- License: bsd-3-clause
- Created: 2017-07-18T09:28:32.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-20T05:00:25.000Z (almost 8 years ago)
- Last Synced: 2025-01-08T07:40:22.226Z (5 months ago)
- Topics: adnroid, config, ini, json, properties, sharedpreferences, universal, xml, yaml
- Language: Java
- Homepage:
- Size: 207 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
## Vitamin
vitamin is an universal config library in android.
## Changelog
See details in [CHANGELOG](https://github.com/lizhangqu/vitamin/blob/master/CHANGELOG.md).
## Examples
I have provided a sample.
See sample [here on Github](https://github.com/lizhangqu/vitamin/tree/master/app).
To run the sample application, simply clone this repository and use android studio to compile, install it on a connected device.
## Usage
### Dependency
**latest version**
[  ](https://bintray.com/lizhangqu/maven/vitamin/_latestVersion)
**gradle**
```
dependencies {
//noinspection GradleCompatible
compile "io.github.lizhangqu:vitamin:${latest_version}"
}
```**maven**
```
io.github.lizhangqu
vitamin
${latest_version}
```
### Third Party
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")**.
### Config Type
- yaml
- ini
- json
- xml
- properties
- SharedPreferences
### Set Global Config Type If Needed```
Vitamin.getInstance().setConfigType(ConfigType configType)
```
It's not must be required.
### Get ReadableConfig```
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.
### Get config
```
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 getList(String key, List defaultValue);//may return null if not support
List getList(String key);//may return null if not support
//may ignore key if needed
Map getMap(String key, Map defaultValue);//may return null if not support
//may ignore key if needed
Map getMap(String key);//may return null if not support
T get(String key, Class clazz);
```## License
vitamin is under the BSD license. See the [LICENSE](https://github.com/lizhangqu/vitamin/blob/master/LICENSE) file for details.