Android-ConfigIO - A small and encapsulation library for creating, accessing, and modifying Key-Value configuration file in XML / JSON format

Related tags

App Android-ConfigIO
Overview

Android-ConfigIO

A small and encapsulation library for creating, accessing, and modifying configuration file with Xml and Json format

Build Status Download

Features

  • Read/Write configruation with json format

  • Read/Write configuration with xml format

  • Rx support

Usage

Binary / Import to your build.gradle

	repositories {
		maven {
			url 'https://dl.bintray.com/tzutalin/maven'
		}
	}

	dependencies {
		compile 'com.tzutalin.configio:configio:1.0.3'
	}

Use in code

If you would like to read and write in external storage, you need to decalre permissions in Manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

Sample

// Assign the target path
File sdcard = Environment.getExternalStorageDirectory();
String targetPath = sdcard.getAbsolutePath() + File.separator + "config.json";

// Instantiate ConfigIO
ConfigIO configIO = ConfigIO.newInstance(targetPath);
// === Write ===
ConfigIO.Writer writer = configIO.getWriter();
writer.putString("test_str", "12345678")
      .putBoolean("test_bool", true)
      .putInt("test_int", 10)
      .putFloat("test_float", 0.5f)
      .putLong("test_long", 100000000L);
// Blocking method. You can use writer.apply() to save it async
writer.commit();

// === Read ====
// It will load config from the file
configIO.loadFromFile();
String test_str = configIO.getString("test_str", "default_str");
boolean test_bool = configIO.getBoolean("test_bool", false);
int test_int = configIO.getInt("test_int", 0);
float test_float = configIO.getFloat("test_float", 0);
long test_long = configIO.getLong("test_long", 0);

Result: It will save to /sdcard/config.json

{
   "test_str":"12345678",
   "test_int":10,
   "test_long":100000000,
   "test_bool":true,
   "test_float":0.5,
}

Rx support

String targetPath = sdcard.getAbsolutePath() + File.separator + "config.xml";
final ConfigIO configIO = ConfigIO.newInstance(targetPath);
// Using RxJava to subscribe on io thread
configIO.loadFromFileWithRx().subscribeOn(Schedulers.io()).subscribe(new Action1<Boolean>() {
    @Override
    public void call(Boolean isSuccess) {
         String test_str = configIO.getString("test_str", "default_str");
         boolean test_bool = configIO.getBoolean("test_bool", false);
         int test_int = configIO.getInt("test_int", 0);
         float test_float = configIO.getFloat("test_float", 0);
         long test_long = configIO.getLong("test_long", 0);
    }
 });

For more example, you can check the sample code

LICNESE

Copyright 2016 Tzutalin

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

You might also like...
CRUD Note taking app built for Android with Kotlin and XML.
CRUD Note taking app built for Android with Kotlin and XML.

Android Note Keeping App An offline android app that can be used to write notes on the fly to be retrieved later. Libraries Room Database. Lifecycle C

Android library for Tesla Authentication based on Tesla JSON API (Unofficial)

TeslaAndroidAuth Lightweight Android library for Tesla SSO Authentication based

Spantastic - an Android library that provides a simple and Kotlin fluent API for creating Android Spannable
Spantastic - an Android library that provides a simple and Kotlin fluent API for creating Android Spannable

Spantastic is an Android library that provides a simple and Kotlin fluent API for creating Android Spannable. This library wrappers SpannableStringBuilder and add methods to easily decorate the text with multiple spans.

A Android Web IDE supports code auto-completion and highlight, plugin (Supports Html, Css, JS, Json, Php etc)

WebDevOps A Android Web IDE supports code auto-completion and highlight, plugin (Supports Html, Css, JS, Json, Php etc) Join us QQ group number: 10314

Restaurants - A simple app which displays a list of restaurants from a stored JSON, ordered by opening status, favorites and filter chosen from the dropdown

Restaurants - A simple app which displays a list of restaurants from a stored JSON, ordered by opening status, favorites and filter chosen from the dropdown

An easy way to create and access JSON Files!
An easy way to create and access JSON Files!

JsonFile This is the JsonFile API, this class is meant to facilitate the process of creating and accessing a JSON file UPDATES Updates Version About C

News-App - A news app Which displays news with the help of JSON data
News-App - A news app Which displays news with the help of JSON data

News-App This is a news app Which displays news with the help of JSON data

An Open-Source Android app for creating training plans and tracking progress
An Open-Source Android app for creating training plans and tracking progress

GymRoutines noahjutz.codeberg.page/gymroutines An Open-Source Android app for creating training plans and tracking progress. Screenshots Contributing

Loop Habit Tracker, a mobile app for creating and maintaining long-term positive habits

Loop is a mobile app that helps you create and maintain good habits, allowing you to achieve your long-term goals. Detailed graphs and statistics show you how your habits improved over time.

Owner
darrenl
darrenl
Dynamic-UI-From-JSON - A Sample Android app to show dynamic UI generation from Json

Dynamic UI from JSON Functionality The app's functionality includes: The app gen

Rafsan Ahmad 12 Dec 16, 2022
Quote-App-Kotlin - Quote App Based on MVVM clean architecture getting quote from json file stored in assets

Quotify - Simple Quotes App This app shows the use of ViewModel and ViewModelFac

Ali Ahmad 2 Apr 14, 2022
Small library that allows the application to display a small troubleshooting guide in case of repeated app startup crashes.

AppSalvager What is it? AppSalvager allows you to combat the issue of repeating crashes on app startup. Failed data migration, SDKs not handling their

Alexander Leontev 29 Aug 31, 2022
Show worldwide headline. API/Glide library/recycler view/volley library/kotlin/xml/ chrome custom tabs

Show worldwide headline. API/Glide library/recycler view/volley library/kotlin/xml/ chrome custom tabs. -> you can click on headline and it will open an article of that news in the app(no need to go to chrome or any browser)

SUMIT KUMAR 5 Nov 28, 2022
simple-flank is a Gradle plugin to use Flank in Android projects with no configuration needed

simple-flank simple-flank is a new gradle plugin with a clear focus: make the setup as simple as possible. Applied to any application or library modul

Flank 8 May 10, 2022
⌨️ A tool that gives you a massive head start when building Compose based apps. It saves you from time-consuming setup and configuration

⌨️ A tool that gives you a massive head start when building Compose based apps. It saves you from time-consuming setup and configuration

theapache64 467 Dec 23, 2022
Sharkur is a fork of Purpur which adds more configuration and also some optimalization.

Sharkur Sharkur is a fork of Purpur which adds more configuration and also some optimization. API Javadoc Dependency Information Maven <repository>

SharkurMC 8 Aug 1, 2022
A simple command line parser that takes different kind and format of inputs

CLI Parser Kata Introduction This is a simple command line parser that takes different kind and format of inputs and exports them to other format and

Victor Grycuk 0 Oct 5, 2021
Helps to find your surrounding's light value (for android only) using device light sensor

react-native-ambient-light-sensor Helps to find your surrounding's light value (in lux unit) (for android only) using device light sensor Installation

Shayan Chatterjee 4 Aug 26, 2022
An E-Commerce android App whose frontend is implemented using Kotlin & XML files and backend/database is implemented using My SQL & PHP files

An E-Commerce android App whose frontend is implemented using Kotlin & XML files and backend/database is implemented using My SQL & PHP files

null 4 Aug 25, 2022