Preference wrappers for primitive types for Android

Overview

Travis build status Maven Central Apache License Methods count

Typed Preferences

Typed Preferences Icon

This library for Android provides classes which allow to store and retrieve settings from the preferences. There is an individual class for each native type:

Each class comes with two constructors - one of them allows to ommit the default value.

All classes declare the same methods: get(), isSet(), set() and delete(). Here are the method signatures as definied in the StringPreference class.

public class StringPreference {
    public String get() { ... }
    public boolean isSet() { ... }
    public void set(String value) { ... }
    public void delete() { ... }
}

Wrappers for frequently used classes can be found and added in the wiki. Take a look!

How to get the thing running?

Add the library as a dependency to your build.gradle in case you use Gradle:

dependencies {
    compile "info.metadude.android:typed-preferences:{$version}"
}

Or if you use Maven you should be looking for this:

<dependency>
    <groupId>info.metadude.android</groupId>
    <artifactId>typed-preferences</artifactId>
    <version>{$version}</version>
</dependency>

For anything else, go to Maven Central - or just build the library yourself.

Minimum SDK version / API level

The library is available in two different versions. If you need to support API level 8 in your project you must include the latest 1.x.x version. This library version persists the settings synchronously using the commit method of the SharedPreferences.Editor. If the minimum SDK version you need to support is API level 9 you can choose the latest 2.x.x version which relies on the apply method of the SharedPreferences.Editor. Thereby settings are persisted asynchronously.

For further information please stick to documentation of the SharedPreferences.Editor interface.

Demo project

Check out the demo project TypedPreferencesDemo which shows how to use the library.

Tests

Run ./gradlew clean test to execute the tests.

Feedback

If you use this library and you are happy with it please send a tweet to @tbsprs and feel free to announce your app. I will be happy to list it here.

In case you do not like the library please do not hesitate to open an issue and let me know what can be improved.

Which applications are using this library?

Reference

This library is mainly inspired by the classes which have been published by Jake Wharton in the u2020 project.

Authors

Contributors

License

Copyright 2014-2018 Tobias Preuss

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...
a simple cache for android and java

ASimpleCache ASimpleCache 是一个为android制定的 轻量级的 开源缓存框架。轻量到只有一个java文件(由十几个类精简而来)。 1、它可以缓存什么东西? 普通的字符串、JsonObject、JsonArray、Bitmap、Drawable、序列化的java对象,和 b

gRPC and protocol buffers for Android, Kotlin, and Java.

Wire “A man got to have a code!” - Omar Little See the project website for documentation and APIs. As our teams and programs grow, the variety and vol

✔️ Secure, simple key-value storage for Android
✔️ Secure, simple key-value storage for Android

Hawk 2.0 Secure, simple key-value storage for android Important Note This version has no backward compatibility with Hawk 1+ versions. If you still wa

A robust native library loader for Android.
A robust native library loader for Android.

ReLinker A robust native library loader for Android. More information can be found in our blog post Min SDK: 9 JavaDoc Overview The Android PackageMan

A lightning fast, transactional, file-based FIFO for Android and Java.

Tape by Square, Inc. Tape is a collection of queue-related classes for Android and Java. QueueFile is a lightning-fast, transactional, file-based FIFO

Joda-Time library with Android specialization

joda-time-android This library is a version of Joda-Time built with Android in mind. Why Joda-Time? Android has built-in date and time handling - why

a SharedPreferences replacement for Android with multiprocess support
a SharedPreferences replacement for Android with multiprocess support

DEPRECATED - no longer actively maintained Tray - a SharedPreferences replacement for Android If you have read the documentation of the SharedPreferen

OpenKeychain is an OpenPGP implementation for Android.
OpenKeychain is an OpenPGP implementation for Android.

OpenKeychain (for Android) OpenKeychain is an OpenPGP implementation for Android. For a more detailed description and installation instructions go to

UPnP/DLNA library for Java and Android

Cling EOL: This project is no longer actively maintained, code may be outdated. If you are interested in maintaining and developing this project, comm

Comments
  • Modify the preferences asynchronously

    Modify the preferences asynchronously

    Using SharedPreferences.Editor#commit() saves the preferences synchronously. Using SharedPreferences.Editor#apply() is asynchronous. The documentation points out that it's safe to replace calls to #commit() with calls to #apply() if already ignoring the return value.

    Enhancement 
    opened by MariusVolkhart 9
  • Working Tests

    Working Tests

    This configures the project to make the tests run again. Several changes are included.

    Test plugin

    Rather than using the deprecated Novoda plugin, the plugin distributed by the Robolectric team is used. There are two big changes here. The first is that the robolectric task has been replaced with the test task. The second is that the source files can be put in src/androidTest/java directory. This is good because the IDE then picks them up without needing the addTests task in the build file.

    Test Files

    Robolectric does not work with version 19 or 20 of Android. To work around this, all the tests have been marked as targeting Android 18.

    Build File Updates

    • Version numbers have been fully defined. This eliminates all the lint and compiler warnings.
    • The demo project references the local library rather than a SNAPSHOT which is technically a development version behind. This means the sonatype snapshot repo no longer needs to be included.
    • The new robolectric gradle plugin is on maven central, so maven local is no longer needed.
    • Android tool versions bumped to latest.

    Travis CI

    A configuration has been added for Travis CI to run the tests. You just have to go enable it at https://travis-ci.org/

    Bug report 
    opened by MariusVolkhart 4
  • the library as a JAR instead of aar

    the library as a JAR instead of aar

    I saw that the library is deployed to maven central as a AAR and not as a normal JAR.

    Since the project has no res folder this is not needed and should be just a JAR which can be downloaded and used in normal non-gradle projects.

    Enhancement 
    opened by darko1002001 3
  • Broken test setup

    Broken test setup

    Broken tests

    Since the latest release v.1.1.0 of TypedPreferences Gradle, the Android Studio plugin and the Android SDK have evolved. For some reason the tests do no longer work. I got them running at some point in the past with Gradle 0.11 and also noticed the final release of novoda/robolectric-plugin 0.0.3-SNAPSHOT. However I cannot get them running now.

    Updating the project

    I already experimented with updating the project (Gradle plugin, Gradle wrapper, SDK, ...) on the feature/update-project branch. Without success with regards to running the tests. Note, that this work relies on a locally deployed version of the novoda/robolectric-plugin as mentioned here. Finally, before merging, this branch will be rebased or rewritten. Anyways, feel free to experiment with what I started off with.

    Changing the test architecture

    It might be worth looking into other test setup such as malmstein/testingarchitecture or novoda/gradle-android-test-plugin or something else since novoda/robolectric-plugin has been deprecated as of August 6, 2014.

    Bug report 
    opened by johnjohndoe 1
Owner
Tobias Preuss
I 💟 open source.
Tobias Preuss
Android Shared preference wrapper than encrypts the values of Shared Preferences. It's not bullet proof security but rather a quick win for incrementally making your android app more secure.

Secure-preferences - Deprecated Please use EncryptedSharedPreferences from androidx.security in preferenced to secure-preference. (There are no active

Scott Alexander-Bown 1.5k Dec 24, 2022
Secure Preference Manager for android. It uses various Encryption to protect your application's Shared Preferences.

Secure-Pref-Manager ##Secure Preference Manager is a simple Library to help you protect your Shared Preferences. Secure Preference Manager for android

Prashant Solanki 72 Nov 25, 2022
Access and process various types of personal data in Android with a set of easy, uniform, and privacy-friendly APIs.

PrivacyStreams PrivacyStreams is an Android library for easy and privacy-friendly personal data access and processing. It offers a functional programm

null 269 Dec 1, 2022
Android library which makes it easy to handle the different obstacles while calling an API (Web Service) in Android App.

API Calling Flow API Calling Flow is a Android library which can help you to simplify handling different conditions while calling an API (Web Service)

Rohit Surwase 19 Nov 9, 2021
Gesture detector framework for multitouch handling on Android, based on Android's ScaleGestureDetector

Android Gesture Detectors Framework Introduction Since I was amazed Android has a ScaleGestureDetector since API level 8 but (still) no such thing as

null 1.1k Nov 30, 2022
Use Android as Rubber Ducky against another Android device

Use Android as Rubber Ducky against another Android device

null 1.4k Jan 9, 2023
Android Utilities Library build in kotlin Provide user 100 of pre defined method to create advanced native android app.

Android Utilities Library build in kotlin Provide user 100 of pre defined method to create advanced native android app.

Shahid Iqbal 4 Nov 29, 2022
A util for setting status bar style on Android App.

StatusBarUtil A util for setting status bar style on Android App. It can work above API 19(KitKat 4.4). 中文版点我 Sample Download StatusBarUtil-Demo Chang

Jaeger 8.8k Jan 6, 2023
A logger with a small, extensible API which provides utility on top of Android's normal Log class.

This is a logger with a small, extensible API which provides utility on top of Android's normal Log class. I copy this class into all the little apps

Jake Wharton 9.8k Dec 30, 2022
Java implementation of a Disk-based LRU cache which specifically targets Android compatibility.

Disk LRU Cache A cache that uses a bounded amount of space on a filesystem. Each cache entry has a string key and a fixed number of values. Each key m

Jake Wharton 5.7k Dec 31, 2022