Multipreference

Download Build Status

Multipreference provides an annotation-based Key-Value store for Android development.

Usage

You need to create a class which will have Key-Value definitions, and prepare each Key-Value definitions which are represented by fields.

import com.github.jmatsu.multipreference.Key;
import com.github.jmatsu.multipreference.Preference;

@Preference
class KeyValueDefinitions {
    @Key
    static final int value = 0x01;
}

This library will generates a class KeyValueDefinitionsPreference and Key-Value API like below.

private static final String VALUE = "value";

public int getValue() {
    return dataStore.getInt(VALUE, KeyValueDefinitions.value);
}

public void setValue(int value) {
    dataStore.setInt(VALUE, value);
}

You can use this class by calling KeyValueDefinitionsPreference.inMemory() or KeyValueDefinitionsPreference.sharedPreference(context, preferencesName).

You can see more examples in sample module’s source and testcases.

Especially for flavor-based configurations, you can check from:

Please visit https://github.com/jmatsu/multipreference for the more details.