Popularity
0.7
Stable
Activity
0.0
Stable
4
4
0

Code Quality Rank: L4
Programming language: Java
License: GNU General Public License v3.0 or later
Tags: Utility    
Latest version: v1.0.4

Android-ConfigIO alternatives and similar packages

Based on the "Utility" category.
Alternatively, view Android-ConfigIO alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of Android-ConfigIO or a related project?

Add another 'Utility' Package

README

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.


*Note that all licence references and agreements mentioned in the Android-ConfigIO README section above are relevant to that project's source code only.