2 * Copyright 2008 ZXing authors
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package com.google.zxing.client.rim.persistence;
\r
19 import net.rim.device.api.system.PersistentObject;
\r
20 import net.rim.device.api.system.PersistentStore;
\r
22 import java.util.Hashtable;
\r
25 * Singleton object that represents the persistent application settings data.
\r
27 * This code was contributed by LifeMarks.
\r
29 * @author Matt York (matt@lifemarks.mobi)
\r
31 public final class AppSettings {
\r
33 public static final String SETTING_CAM_RES_MSG = "setting_cam_res_msg";
\r
34 private static final long ID_LONG = 0x92ac4e8ac35b8aa0L;
\r
36 private static AppSettings instance;
\r
38 private final PersistentObject store;
\r
39 private final Hashtable settingsItems;
\r
41 private AppSettings() {
\r
42 store = PersistentStore.getPersistentObject(ID_LONG);
\r
43 Hashtable temp = (Hashtable) store.getContents();
\r
44 settingsItems = temp == null ? new Hashtable() : temp;
\r
47 public static AppSettings getInstance() {
\r
48 if (instance == null) {
\r
49 instance = new AppSettings();
\r
55 * Adds a setting object.
\r
57 public void addItem(String itemName, Object itemValue) {
\r
58 settingsItems.put(itemName, itemValue);
\r
62 * Returns all settings objects.
\r
64 public Hashtable getItems() {
\r
65 return settingsItems;
\r
69 * Gets a particular settings object by name.
\r
71 Object getItem(String itemName) {
\r
72 return settingsItems.get(itemName);
\r
76 * Gets a particular boolean type settings object by name.
\r
78 public Boolean getBooleanItem(String itemName) {
\r
79 Object value = getItem(itemName);
\r
80 return value instanceof Boolean ? (Boolean) value : Boolean.FALSE;
\r
84 * Returns the number of settings.
\r
86 public int getNumItems() {
\r
87 return settingsItems.size();
\r
91 * Persists the settings to the device.
\r
93 public void persist() {
\r
94 synchronized (store) {
\r
95 store.setContents(settingsItems);
\r