Files
NativeScript/application-settings/application-settings.android.ts
Hristo Deshev 77838ae9c6 Change from "classic" TS 1.6 imports to the default resolution scheme.
- Use relative imports in place of most of our absolute ones.
- Add "private" ambient modules for modules that we need to import using
an absolute path (e.g. when app/.../test-something.ts needs to import
ui/styling/style-scope)
2015-09-29 16:25:49 +03:00

67 lines
1.9 KiB
TypeScript

import Common = require("./application-settings-common");
import utils = require("utils/utils");
var sharedPreferences = utils.ad.getApplicationContext().getSharedPreferences("prefs.db", 0);
export var hasKey = function (key: string): boolean {
Common.checkKey(key);
return sharedPreferences.contains(key);
}
// getters
export var getBoolean = function (key: string, defaultValue?: boolean): boolean {
Common.checkKey(key);
if (hasKey(key)) {
return sharedPreferences.getBoolean(key, false);
}
return defaultValue;
}
export var getString = function (key: string, defaultValue?: string): string {
Common.checkKey(key);
if (hasKey(key)) {
return sharedPreferences.getString(key, "");
}
return defaultValue;
}
export var getNumber = function (key: string, defaultValue?: number): number {
Common.checkKey(key);
if (hasKey(key)) {
return sharedPreferences.getFloat(key, float(0.0));
}
return defaultValue;
}
// setters
export var setBoolean = function (key: string, value: boolean): void {
Common.checkKey(key);
Common.ensureValidValue(value, "boolean");
var editor = sharedPreferences.edit();
editor.putBoolean(key, value);
editor.commit();
}
export var setString = function (key: string, value: string): void {
Common.checkKey(key);
Common.ensureValidValue(value, "string");
var editor = sharedPreferences.edit();
editor.putString(key, value);
editor.commit();
}
export var setNumber = function (key: string, value: number): void {
Common.checkKey(key);
Common.ensureValidValue(value, "number");
var editor = sharedPreferences.edit();
editor.putFloat(key, float(value));
editor.commit();
}
export var remove = function (key: string): void {
Common.checkKey(key);
var editor = sharedPreferences.edit();
editor.remove(key);
editor.commit();
}