OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.blimp.preferences; | 5 package org.chromium.blimp.app.preferences; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 | 8 |
9 import org.chromium.base.ContextUtils; | 9 import org.chromium.base.ContextUtils; |
10 import org.chromium.blimp.R; | 10 import org.chromium.blimp.app.R; |
11 | 11 |
12 /** | 12 /** |
13 * Provides helper methods for storing and retrieving values in android shared p
references. | 13 * Provides helper methods for storing and retrieving values in android shared p
references. |
14 */ | 14 */ |
15 public class PreferencesUtil { | 15 public class PreferencesUtil { |
16 /** | 16 /** |
17 * Preference that stores the last used assigner URL. | 17 * Preference that stores the last used assigner URL. |
18 */ | 18 */ |
19 private static final String PREF_LAST_USED_ASSIGNER = "last_known_assigner"; | 19 private static final String PREF_LAST_USED_ASSIGNER = "last_known_assigner"; |
20 private static final String DEFAULT_EMPTY_STRING = ""; | 20 private static final String DEFAULT_EMPTY_STRING = ""; |
21 | 21 |
22 /** | 22 /** |
23 * Finds the assigner to be used from user's last preference. If the app is
being used for the | 23 * Finds the assigner to be used from user's last preference. If the app is
being used for the |
24 * first time, the first entry from the assigner array would be used. | 24 * first time, the first entry from the assigner array would be used. |
25 * @return assigner to use. | 25 * @return assigner to use. |
26 */ | 26 */ |
27 public static String findAssignerUrl(Context context) { | 27 public static String findAssignerUrl(Context context) { |
28 String lastAssigner = getLastUsedAssigner(context); | 28 String lastAssigner = getLastUsedAssigner(context); |
29 if (lastAssigner.isEmpty()) { | 29 if (lastAssigner.isEmpty()) { |
30 String[] assignerUrls = context.getResources().getStringArray( | 30 String[] assignerUrls = |
31 R.array.blimp_assigner_urls); | 31 context.getResources().getStringArray(R.array.blimp_assigner
_urls); |
32 assert assignerUrls != null && assignerUrls.length > 0; | 32 assert assignerUrls != null && assignerUrls.length > 0; |
33 lastAssigner = assignerUrls[0]; | 33 lastAssigner = assignerUrls[0]; |
34 setLastUsedAssigner(context, lastAssigner); | 34 setLastUsedAssigner(context, lastAssigner); |
35 } | 35 } |
36 return lastAssigner; | 36 return lastAssigner; |
37 } | 37 } |
38 | 38 |
39 /** | 39 /** |
40 * Reads the last used assigner from shared preference. | 40 * Reads the last used assigner from shared preference. |
41 * @param context The current Android context | 41 * @param context The current Android context |
(...skipping 25 matching lines...) Expand all Loading... |
67 /** | 67 /** |
68 * Writes the given string into shared preference. | 68 * Writes the given string into shared preference. |
69 * @param context The current Android context | 69 * @param context The current Android context |
70 * @param key The name of the preference to modify | 70 * @param key The name of the preference to modify |
71 * @param value The new value for the preference | 71 * @param value The new value for the preference |
72 */ | 72 */ |
73 private static void writeString(Context context, String key, String value) { | 73 private static void writeString(Context context, String key, String value) { |
74 ContextUtils.getAppSharedPreferences().edit().putString(key, value).appl
y(); | 74 ContextUtils.getAppSharedPreferences().edit().putString(key, value).appl
y(); |
75 } | 75 } |
76 } | 76 } |
OLD | NEW |