This library for HMOS provides classes which allow to store and retrieve settings from the preferences. There is an individual class for each native type:
- [
BooleanPreference
][boolean-pref] for aboolean
value - [
DoublePreference
][double-pref] for adouble
value - [
FloatPreference
][float-pref] for afloat
value - [
IntPreference
][int-pref] for anint
value - [
LongPreference
][long-pref] for along
value - [
ShortPreference
][short-pref] for ashort
value - [
StringPreference
][string-pref] for aString
value
Inspired by https://github.com/johnjohndoe/TypedPreferences - v2.1.0 version
- For using typedpreferences module in sample app, include the source code and add the below dependencies in entry/build.gradle to generate hap/support.har.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
implementation project(path: ':typedpreferences')
testImplementation 'junit:junit:4.13'
ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100'
}
- For using typedpreferences in separate application using har file, add the har file in the entry/libs folder and add the dependencies in entry/build.gradle file.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.har'])
testImplementation 'junit:junit:4.13'
}
- For using TypedPreferences from a remote repository in separate application, add the below dependencies in entry/build.gradle file.
dependencies {
implementation ('dev.applibgroup:typedpreferences:1.0.0')
testCompile 'junit:junit:4.13'
}
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() { }
}
Copyright 2014-2021 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.