• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得cocoapythonrubywindowsphpgameguibathyscaphec翻訳omegatframework計画中(planning stage)twitterdombtronvb.nettestarduinodirectxpreviewerゲームエンジン

Commit MetaInfo

Revision2d17cd51826d22f7ae1025029aa1b2d809b872d7 (tree)
Time2014-05-28 03:56:15
AuthorMasahiko, SAWAI <say@user...>
CommiterMasahiko, SAWAI

Log Message

Refactored PreferenceUtils.java

Change Summary

Incremental Difference

--- a/simple-battery-logger/simple-battery-logger-app/src/org/routine_work/simple_battery_logger/util/PreferenceUtils.java
+++ b/simple-battery-logger/simple-battery-logger-app/src/org/routine_work/simple_battery_logger/util/PreferenceUtils.java
@@ -38,11 +38,39 @@ public class PreferenceUtils
3838
3939 private static final String LOG_TAG = "simple-battery-logger";
4040
41-
42- public static boolean isLoggingServiceEnabled(Context context)
41+ /**
42+ * Get private SharedPreferences
43+ *
44+ * @param context
45+ * @return
46+ */
47+ public static SharedPreferences getPrivateSharedPreferences(Context context)
4348 {
4449 String preferenceName = context.getPackageName() + "_preferences";
4550 SharedPreferences sharedPreferences = context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE);
51+ return sharedPreferences;
52+ }
53+
54+ /**
55+ * Get public SharedPreferences
56+ *
57+ * This SharedPreferences is referenced by Simple Battery Logger Dropbox
58+ * Uploader
59+ *
60+ * @param context
61+ * @return
62+ */
63+ public static SharedPreferences getExportedSharedPreference(Context context)
64+ {
65+ String exportedPreferenceName = context.getPackageName() + "_exported_preferences";
66+ SharedPreferences exportedSharedPreferences = context.getSharedPreferences(
67+ exportedPreferenceName, Context.MODE_WORLD_READABLE);
68+ return exportedSharedPreferences;
69+ }
70+
71+ public static boolean isLoggingServiceEnabled(Context context)
72+ {
73+ SharedPreferences sharedPreferences = getPrivateSharedPreferences(context);
4674 Resources resources = context.getResources();
4775
4876 String key = resources.getString(R.string.logging_service_enabled_key);
@@ -56,8 +84,7 @@ public class PreferenceUtils
5684 public static void putLoggingServiceEnabled(Context context, boolean enabled)
5785 {
5886 Log.v(LOG_TAG, "loggingServiceEnabled => " + enabled);
59- String preferenceName = context.getPackageName() + "_preferences";
60- SharedPreferences sharedPreferences = context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE);
87+ SharedPreferences sharedPreferences = getPrivateSharedPreferences(context);
6188 Resources resources = context.getResources();
6289
6390 String key = resources.getString(R.string.logging_service_enabled_key);
@@ -70,8 +97,7 @@ public class PreferenceUtils
7097 public static boolean isIgnoreVoltageChangeOnly(Context context)
7198 {
7299
73- String preferenceName = context.getPackageName() + "_preferences";
74- SharedPreferences sharedPreferences = context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE);
100+ SharedPreferences sharedPreferences = getPrivateSharedPreferences(context);
75101 Resources resources = context.getResources();
76102
77103 String key = resources.getString(R.string.ignore_voltage_change_only_key);
@@ -84,8 +110,7 @@ public class PreferenceUtils
84110
85111 public static int getDataKeepingPeriod(Context context)
86112 {
87- String preferenceName = context.getPackageName() + "_preferences";
88- SharedPreferences sharedPreferences = context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE);
113+ SharedPreferences sharedPreferences = getPrivateSharedPreferences(context);
89114 Resources resources = context.getResources();
90115
91116 String key = resources.getString(R.string.data_keeping_period_key);
@@ -99,8 +124,7 @@ public class PreferenceUtils
99124
100125 public static boolean isCsvAutoExportEnabled(Context context)
101126 {
102- String preferenceName = context.getPackageName() + "_preferences";
103- SharedPreferences sharedPreferences = context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE);
127+ SharedPreferences sharedPreferences = getPrivateSharedPreferences(context);
104128 Resources resources = context.getResources();
105129
106130 String key = resources.getString(R.string.csv_auto_export_enabled_key);
@@ -113,8 +137,7 @@ public class PreferenceUtils
113137
114138 public static String getCsvSortOrder(Context context)
115139 {
116- String preferenceName = context.getPackageName() + "_preferences";
117- SharedPreferences sharedPreferences = context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE);
140+ SharedPreferences sharedPreferences = getPrivateSharedPreferences(context);
118141 Resources resources = context.getResources();
119142
120143 String key = resources.getString(R.string.csv_sort_order_key);
@@ -127,8 +150,7 @@ public class PreferenceUtils
127150
128151 public static String getCsvExportDirectoryName(Context context)
129152 {
130- String preferenceName = context.getPackageName() + "_preferences";
131- SharedPreferences sharedPreferences = context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE);
153+ SharedPreferences sharedPreferences = getPrivateSharedPreferences(context);
132154 Resources resources = context.getResources();
133155
134156 String key = resources.getString(R.string.csv_export_directory_key);
@@ -139,18 +161,11 @@ public class PreferenceUtils
139161 return value;
140162 }
141163
142- public static SharedPreferences getExportedSharedPreference(Context context)
143- {
144- String exportedPreferenceName = context.getPackageName() + "_exported_preferences";
145- SharedPreferences exportedSharedPreferences = context.getSharedPreferences(
146- exportedPreferenceName, Context.MODE_WORLD_READABLE);
147- return exportedSharedPreferences;
148- }
149-
150164 /**
151- * Copy CSV Directory from private SharedPreferences to exported SharedPreferences
152- *
153- * @param context
165+ * Copy CSV Directory from private SharedPreferences to exported
166+ * SharedPreferences
167+ *
168+ * @param context
154169 */
155170 public static void exportCsvExportDirectoryName(Context context)
156171 {
@@ -172,8 +187,7 @@ public class PreferenceUtils
172187
173188 public static boolean isCsvMediaScanCompleted(Context context)
174189 {
175- String preferenceName = context.getPackageName() + "_preferences";
176- SharedPreferences sharedPreferences = context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE);
190+ SharedPreferences sharedPreferences = getPrivateSharedPreferences(context);
177191 Resources resources = context.getResources();
178192
179193 String key = resources.getString(R.string.csv_media_scan_completed_key);
@@ -187,14 +201,12 @@ public class PreferenceUtils
187201 public static void putCsvMediaScanCompleted(Context context, boolean value)
188202 {
189203 Log.v(LOG_TAG, "csvMediaScanCompleted => " + value);
190- String preferenceName = context.getPackageName() + "_preferences";
191- SharedPreferences sharedPreferences = context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE);
204+ SharedPreferences sharedPreferences = getPrivateSharedPreferences(context);
192205 Resources resources = context.getResources();
193206
194207 String key = resources.getString(R.string.csv_media_scan_completed_key);
195208 SharedPreferences.Editor editor = sharedPreferences.edit();
196209 editor.putBoolean(key, value);
197210 editor.commit();
198-
199211 }
200212 }