-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathSimplePreferences.java
More file actions
82 lines (64 loc) · 2.79 KB
/
SimplePreferences.java
File metadata and controls
82 lines (64 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package org.anddev.andengine.util;
import org.anddev.andengine.util.constants.Constants;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:55:12 - 02.08.2010
*/
public class SimplePreferences implements Constants {
// ===========================================================
// Constants
// ===========================================================
// ===========================================================
// Fields
// ===========================================================
private static SharedPreferences INSTANCE;
private static Editor EDITORINSTANCE;
// ===========================================================
// Constructors
// ===========================================================
private SimplePreferences() {}
public static SharedPreferences getInstance(final Context pContext) {
if(SimplePreferences.INSTANCE == null) {
SimplePreferences.INSTANCE = PreferenceManager.getDefaultSharedPreferences(pContext);
}
return SimplePreferences.INSTANCE;
}
public static Editor getEditorInstance(final Context pContext) {
if(SimplePreferences.EDITORINSTANCE == null) {
SimplePreferences.EDITORINSTANCE = SimplePreferences.getInstance(pContext).edit();
}
return SimplePreferences.EDITORINSTANCE;
}
// ===========================================================
// Getter & Setter
// ===========================================================
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
// ===========================================================
// Methods
// ===========================================================
public static int incrementAccessCount(final Context pContext, final String pKey) {
return SimplePreferences.incrementAccessCount(pContext, pKey, 1);
}
public static int incrementAccessCount(final Context pContext, final String pKey, final int pIncrement) {
final SharedPreferences prefs = SimplePreferences.getInstance(pContext);
final int accessCount = prefs.getInt(pKey, 0);
final int newAccessCount = accessCount + pIncrement;
prefs.edit().putInt(pKey, newAccessCount).commit();
return newAccessCount;
}
public static int getAccessCount(final Context pCtx, final String pKey) {
return SimplePreferences.getInstance(pCtx).getInt(pKey, 0);
}
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}