Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy pathPasscodePreferenceFragment.java
More file actions
Latest commit
130 lines (108 loc) · 4.8 KB
/
Copy pathPasscodePreferenceFragment.java
File metadata and controls
130 lines (108 loc) · 4.8 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
packageorg.wordpress.passcodelock;
importandroid.content.Intent;
importandroid.os.Bundle;
importandroid.preference.Preference;
importandroid.preference.PreferenceFragment;
importandroid.preference.SwitchPreference;
publicclassPasscodePreferenceFragmentextendsPreferenceFragment
implementsPreference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener {
publicstaticfinalStringKEY_SHOULD_INFLATE = "should-inflate";
publicstaticfinalintENABLE_PASSLOCK = 0;
publicstaticfinalintDISABLE_PASSLOCK = 1;
publicstaticfinalintCHANGE_PASSWORD = 2;
privatePreferencemTogglePasscodePreference;
privatePreferencemChangePasscodePreference;
@Override
publicvoidonCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
Bundleargs = getArguments();
if (args != null && args.getBoolean(KEY_SHOULD_INFLATE, true)) {
addPreferencesFromResource(R.xml.passcode_preferences);
mTogglePasscodePreference = findPreference(getString(R.string.pref_key_passcode_toggle));
mChangePasscodePreference = findPreference(getString(R.string.pref_key_change_passcode));
}
refreshPreferenceState();
}
@Override
publicbooleanonPreferenceClick(Preferencepreference) {
StringpreferenceKey = preference.getKey() != null ? preference.getKey() : "";
if (preferenceKey.equals(getString(R.string.pref_key_change_passcode))) {
returnhandleChangePasscodeClick();
}
returnfalse;
}
@Override
publicbooleanonPreferenceChange(Preferencepreference, ObjectnewValue) {
if (newValue == null) returnfalse;
StringpreferenceKey = preference.getKey() != null ? preference.getKey() : "";
if (!preferenceKey.equals(getString(R.string.pref_key_passcode_toggle))) {
// Make sure we're updating the correct preference item.
// Actually this check is not even required, since we've one item only that has set the
// OnPreferenceChangeListener.
returnfalse;
}
BooleannewValueBool = (Boolean) newValue;
booleanoldValue = ((SwitchPreference)mTogglePasscodePreference).isChecked();
if (newValueBool == oldValue) {
// Already updated. Do not call the setup activity.
// This method get called twice if the click is on the row (not on the toggle visual item)
// on devices Pre-Lollip.
returntrue;
}
handlePasscodeToggleClick();
returntrue;
}
/**
* When the preferences are nested in a parent apps xml layout the inflated preferences will
* need to be set.
*/
publicvoidsetPreferences(PreferencetogglePreference, PreferencechangePreference) {
mTogglePasscodePreference = togglePreference;
mChangePasscodePreference = changePreference;
refreshPreferenceState();
}
/**
* Called when user requests to turn the passlock on or off.
*
* @return
* always true to indicate that the request was handled
*/
privatebooleanhandlePasscodeToggleClick() {
inttype = AppLockManager.getInstance().getAppLock().isPasswordLocked()
? DISABLE_PASSLOCK : ENABLE_PASSLOCK;
Intenti = newIntent(getActivity(), PasscodeManagePasswordActivity.class);
i.putExtra(PasscodeManagePasswordActivity.KEY_TYPE, type);
startActivityForResult(i, type);
returntrue;
}
/**
* Called when user requests to change passcode.
*
* @return
* always true to indicate that the request was handled
*/
privatebooleanhandleChangePasscodeClick() {
Intenti = newIntent(getActivity(), PasscodeManagePasswordActivity.class);
i.putExtra(PasscodeManagePasswordActivity.KEY_TYPE, CHANGE_PASSWORD);
i.putExtra(AbstractPasscodeKeyboardActivity.KEY_MESSAGE,
getString(R.string.passcode_enter_old_passcode));
startActivityForResult(i, CHANGE_PASSWORD);
returntrue;
}
/**
* Helper method to setup preference properties
*/
privatevoidrefreshPreferenceState() {
if (mTogglePasscodePreference != null && mChangePasscodePreference != null) {
mChangePasscodePreference.setOnPreferenceClickListener(this);
mTogglePasscodePreference.setOnPreferenceChangeListener(this);
if (AppLockManager.getInstance().getAppLock().isPasswordLocked()) {
mTogglePasscodePreference.setTitle(R.string.passcode_turn_off);
mChangePasscodePreference.setEnabled(true);
} else {
mTogglePasscodePreference.setTitle(R.string.passcode_turn_on);
mChangePasscodePreference.setEnabled(false);
}
}
}
}