-
-
Notifications
You must be signed in to change notification settings - Fork 239
Expand file tree
/
Copy pathSettings.java
More file actions
115 lines (89 loc) · 4.07 KB
/
Settings.java
File metadata and controls
115 lines (89 loc) · 4.07 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package protect.card_locker.preferences;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import androidx.annotation.IntegerRes;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.preference.PreferenceManager;
import java.util.Locale;
import protect.card_locker.R;
import protect.card_locker.Utils;
public class Settings {
private static final String TAG = "Catima";
private final Context mContext;
private final SharedPreferences mSettings;
public Settings(Context context) {
mContext = context.getApplicationContext();
mSettings = PreferenceManager.getDefaultSharedPreferences(context);
}
private String getResString(@StringRes int resId) {
return mContext.getString(resId);
}
private int getResInt(@IntegerRes int resId) {
return mContext.getResources().getInteger(resId);
}
private String getString(@StringRes int keyId, String defaultValue) {
return mSettings.getString(getResString(keyId), defaultValue);
}
private int getInt(@StringRes int keyId, @IntegerRes int defaultId) {
return mSettings.getInt(getResString(keyId), getResInt(defaultId));
}
private boolean getBoolean(@StringRes int keyId, boolean defaultValue) {
return mSettings.getBoolean(getResString(keyId), defaultValue);
}
@Nullable
public Locale getLocale() {
String value = getString(R.string.settings_key_locale, "");
if (value.isEmpty()) {
return null;
}
return Utils.stringToLocale(value);
}
public int getTheme() {
String value = getString(R.string.settings_key_theme, getResString(R.string.settings_key_system_theme));
if (value.equals(getResString(R.string.settings_key_light_theme))) {
return AppCompatDelegate.MODE_NIGHT_NO;
} else if (value.equals(getResString(R.string.settings_key_dark_theme))) {
return AppCompatDelegate.MODE_NIGHT_YES;
}
return AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
}
public boolean useMaxBrightnessDisplayingBarcode() {
return getBoolean(R.string.settings_key_display_barcode_max_brightness, true);
}
public boolean getKeepScreenOn() {
return getBoolean(R.string.settings_key_keep_screen_on, true);
}
public boolean getDisableLockscreenWhileViewingCard() {
return getBoolean(R.string.settings_key_disable_lockscreen_while_viewing_card, true);
}
public boolean getDisableNfcWhileViewingCard() {
return getBoolean(R.string.settings_key_disable_nfc_while_viewing_card, false);
}
public boolean getAllowContentProviderRead() {
return getBoolean(R.string.settings_key_allow_content_provider_read, true);
}
public boolean getOledDark() {
return getBoolean(R.string.settings_key_oled_dark, false);
}
public int getPreferredColumnCount() {
var defaultSymbol = mContext.getResources().getString(R.string.settings_key_automatic_column_count);
var defaultColumnCount = mContext.getResources().getInteger(R.integer.main_view_card_columns);
var orientation = mContext.getResources().getConfiguration().orientation;
var columnCountPrefKey = orientation == ORIENTATION_PORTRAIT ? R.string.setting_key_column_count_portrait : R.string.setting_key_column_count_landscape;
var columnCountSetting = getString(columnCountPrefKey, defaultSymbol);
try {
// the pref may be unset or explicitly set to default
return columnCountSetting.equals(defaultSymbol) ? defaultColumnCount : Integer.parseInt(columnCountSetting);
} catch (NumberFormatException nfe) {
Log.e(TAG, "Failed to parseInt the column count pref", nfe);
return defaultColumnCount;
}
}
public boolean useVolumeKeysForNavigation() {
return getBoolean(R.string.settings_key_use_volume_keys_navigation, false);
}
}