Skip to content

Commit ccbcd6c

Browse files
committed
Extracted resources and refactoring
1 parent f7502e1 commit ccbcd6c

18 files changed

Lines changed: 106 additions & 82 deletions

File tree

app/src/main/java/org/gnucash/android/ui/passcode/KeyboardFragment.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
*/
3535
public class KeyboardFragment extends SherlockFragment {
3636

37+
private static final int DELAY = 500;
38+
3739
private TextView pass1;
3840
private TextView pass2;
3941
private TextView pass3;
@@ -42,7 +44,7 @@ public class KeyboardFragment extends SherlockFragment {
4244
private int length = 0;
4345

4446
public interface OnPasscodeEnteredListener {
45-
public void onPasscodeEntered(String pass);
47+
void onPasscodeEntered(String pass);
4648
}
4749

4850
private OnPasscodeEnteredListener listener;
@@ -182,7 +184,7 @@ public void run() {
182184
pass4.setText(null);
183185
length = 0;
184186
}
185-
}, 500);
187+
}, DELAY);
186188
}
187189
}
188190

app/src/main/java/org/gnucash/android/ui/passcode/PasscodeLockScreenActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014 Oleksandr Tyshkovets <olexandr.tyshkovets@gmail.com>
2+
* Copyright (c) 2014 - 2015 Oleksandr Tyshkovets <olexandr.tyshkovets@gmail.com>
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,7 +49,7 @@ public void onPasscodeEntered(String pass) {
4949
.getString(UxArgument.PASSCODE, "");
5050
Log.d(TAG, "Passcode: " + passcode);
5151

52-
if (passcode.equals(pass)) {
52+
if (pass.equals(passcode)) {
5353
if (UxArgument.DISABLE_PASSCODE.equals(getIntent().getStringExtra(UxArgument.DISABLE_PASSCODE))) {
5454
setResult(RESULT_OK);
5555
finish();

app/src/main/java/org/gnucash/android/ui/passcode/PasscodePreferenceActivity.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014 Oleksandr Tyshkovets <olexandr.tyshkovets@gmail.com>
2+
* Copyright (c) 2014 - 2015 Oleksandr Tyshkovets <olexandr.tyshkovets@gmail.com>
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,25 +34,24 @@
3434
public class PasscodePreferenceActivity extends SherlockFragmentActivity
3535
implements KeyboardFragment.OnPasscodeEnteredListener {
3636

37-
private boolean reenter = false;
38-
private String passcode;
37+
private boolean mIsPassEnabled;
38+
private boolean mReenter = false;
39+
private String mPasscode;
3940

40-
private boolean checkOldPassCode;
41-
42-
private TextView passCodeTextView;
41+
private TextView mPassTextView;
4342

4443
@Override
4544
protected void onCreate(Bundle savedInstanceState) {
4645
super.onCreate(savedInstanceState);
4746
setContentView(R.layout.passcode_lockscreen);
4847

49-
passCodeTextView= (TextView) findViewById(R.id.passcode_label);
48+
mPassTextView = (TextView) findViewById(R.id.passcode_label);
5049

51-
checkOldPassCode = PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
50+
mIsPassEnabled = PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
5251
.getBoolean(UxArgument.ENABLED_PASSCODE, false);
5352

54-
if (checkOldPassCode) {
55-
passCodeTextView.setText("Enter your old passcode");
53+
if (mIsPassEnabled) {
54+
mPassTextView.setText(R.string.label_old_passcode);
5655
}
5756
}
5857

@@ -61,28 +60,27 @@ public void onPasscodeEntered(String pass) {
6160
String passCode = PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
6261
.getString(UxArgument.PASSCODE, "");
6362

64-
if (checkOldPassCode) {
63+
if (mIsPassEnabled) {
6564
if (pass.equals(passCode)) {
66-
checkOldPassCode = false;
67-
passCodeTextView.setText("Enter your new passcode");
65+
mIsPassEnabled = false;
66+
mPassTextView.setText(R.string.label_new_passcode);
6867
} else {
6968
Toast.makeText(this, R.string.toast_wrong_passcode, Toast.LENGTH_SHORT).show();
7069
}
7170
return;
7271
}
7372

74-
if (reenter) {
75-
if (passcode.equals(pass)) {
73+
if (mReenter) {
74+
if (mPasscode.equals(pass)) {
7675
setResult(RESULT_OK, new Intent().putExtra(UxArgument.PASSCODE, pass));
7776
finish();
7877
} else {
7978
Toast.makeText(this, R.string.toast_invalid_passcode_confirmation, Toast.LENGTH_LONG).show();
8079
}
8180
} else {
82-
passcode = pass;
83-
reenter = true;
84-
((TextView) findViewById(R.id.passcode_label)).setText(R.string.toast_confirm_passcode);
85-
Toast.makeText(this, R.string.toast_confirm_passcode, Toast.LENGTH_SHORT).show();
81+
mPasscode = pass;
82+
mReenter = true;
83+
mPassTextView.setText(R.string.label_confirm_passcode);
8684
}
8785
}
8886

app/src/main/java/org/gnucash/android/ui/settings/PasscodePreferenceFragment.java

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014 Oleksandr Tyshkovets <olexandr.tyshkovets@gmail.com>
2+
* Copyright (c) 2014 - 2015 Oleksandr Tyshkovets <olexandr.tyshkovets@gmail.com>
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,18 +46,18 @@ public class PasscodePreferenceFragment extends PreferenceFragment {
4646
/**
4747
* Request code for retrieving passcode to store
4848
*/
49-
public static final int PASSCODE_REQUEST_CODE = 2;
49+
public static final int PASSCODE_REQUEST_CODE = 0x2;
5050
/**
5151
* Request code for disabling passcode
5252
*/
53-
public static final int REQUEST_DISABLE_PASSCODE = 3;
53+
public static final int REQUEST_DISABLE_PASSCODE = 0x3;
5454
/**
5555
* Request code for changing passcode
5656
*/
57-
public static final int REQUEST_CHANGE_PASSCODE = 4;
57+
public static final int REQUEST_CHANGE_PASSCODE = 0x4;
5858

59-
private SharedPreferences.Editor editor;
60-
private CheckBoxPreference checkBoxPreference;
59+
private SharedPreferences.Editor mEditor;
60+
private CheckBoxPreference mCheckBoxPreference;
6161

6262
@Override
6363
public void onCreate(Bundle savedInstanceState) {
@@ -74,28 +74,26 @@ public void onCreate(Bundle savedInstanceState) {
7474
public void onResume() {
7575
super.onResume();
7676

77-
editor = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()).edit();
77+
mEditor = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()).edit();
7878
final Intent intent = new Intent(getActivity(), PasscodePreferenceActivity.class);
7979

80-
checkBoxPreference = (CheckBoxPreference) findPreference(getString(R.string.key_enable_passcode));
81-
final String passcodeEnabled = getString(R.string.title_passcode_enabled);
82-
final String passcodeDisabled = getString(R.string.title_passcode_disabled);
83-
checkBoxPreference.setTitle(checkBoxPreference.isChecked() ? passcodeEnabled : passcodeDisabled);
84-
checkBoxPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
85-
@Override
86-
public boolean onPreferenceChange(Preference preference, Object newValue) {
87-
if ((Boolean) newValue) {
88-
startActivityForResult(intent, PASSCODE_REQUEST_CODE);
89-
} else {
90-
Intent passIntent = new Intent(getActivity(), PasscodeLockScreenActivity.class);
91-
passIntent.putExtra(UxArgument.DISABLE_PASSCODE, UxArgument.DISABLE_PASSCODE);
92-
startActivityForResult(passIntent, REQUEST_DISABLE_PASSCODE);
93-
}
94-
// editor.putBoolean(UxArgument.ENABLED_PASSCODE, (Boolean) newValue);
95-
// editor.commit();
96-
return true;
97-
}
98-
});
80+
mCheckBoxPreference = (CheckBoxPreference) findPreference(getString(R.string.key_enable_passcode));
81+
mCheckBoxPreference.setTitle(mCheckBoxPreference.isChecked()
82+
? getString(R.string.title_passcode_enabled)
83+
: getString(R.string.title_passcode_disabled));
84+
mCheckBoxPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
85+
@Override
86+
public boolean onPreferenceChange(Preference preference, Object newValue) {
87+
if ((Boolean) newValue) {
88+
startActivityForResult(intent, PASSCODE_REQUEST_CODE);
89+
} else {
90+
Intent passIntent = new Intent(getActivity(), PasscodeLockScreenActivity.class);
91+
passIntent.putExtra(UxArgument.DISABLE_PASSCODE, UxArgument.DISABLE_PASSCODE);
92+
startActivityForResult(passIntent, REQUEST_DISABLE_PASSCODE);
93+
}
94+
return true;
95+
}
96+
});
9997
findPreference(getString(R.string.key_change_passcode))
10098
.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
10199
@Override
@@ -113,32 +111,32 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
113111
switch (requestCode) {
114112
case PASSCODE_REQUEST_CODE:
115113
if (resultCode == Activity.RESULT_OK && data != null) {
116-
editor.putString(UxArgument.PASSCODE, data.getStringExtra(UxArgument.PASSCODE));
117-
editor.putBoolean(UxArgument.ENABLED_PASSCODE, true);
114+
mEditor.putString(UxArgument.PASSCODE, data.getStringExtra(UxArgument.PASSCODE));
115+
mEditor.putBoolean(UxArgument.ENABLED_PASSCODE, true);
118116
Toast.makeText(getActivity(), R.string.toast_passcode_set, Toast.LENGTH_SHORT).show();
119-
checkBoxPreference.setTitle(getString(R.string.title_passcode_enabled));
117+
mCheckBoxPreference.setTitle(getString(R.string.title_passcode_enabled));
120118
}
121119
if (resultCode == Activity.RESULT_CANCELED) {
122-
editor.putBoolean(UxArgument.ENABLED_PASSCODE, false);
123-
checkBoxPreference.setChecked(false);
124-
checkBoxPreference.setTitle(getString(R.string.title_passcode_disabled));
120+
mEditor.putBoolean(UxArgument.ENABLED_PASSCODE, false);
121+
mCheckBoxPreference.setChecked(false);
122+
mCheckBoxPreference.setTitle(getString(R.string.title_passcode_disabled));
125123
}
126124
break;
127125
case REQUEST_DISABLE_PASSCODE:
128-
boolean flag = (resultCode == Activity.RESULT_OK) ? false : true;
129-
editor.putBoolean(UxArgument.ENABLED_PASSCODE, flag);
130-
checkBoxPreference.setChecked(flag);
126+
boolean flag = resultCode != Activity.RESULT_OK;
127+
mEditor.putBoolean(UxArgument.ENABLED_PASSCODE, flag);
128+
mCheckBoxPreference.setChecked(flag);
131129
break;
132130
case REQUEST_CHANGE_PASSCODE:
133131
if (resultCode == Activity.RESULT_OK && data != null) {
134-
editor.putString(UxArgument.PASSCODE, data.getStringExtra(UxArgument.PASSCODE));
135-
editor.putBoolean(UxArgument.ENABLED_PASSCODE, true);
132+
mEditor.putString(UxArgument.PASSCODE, data.getStringExtra(UxArgument.PASSCODE));
133+
mEditor.putBoolean(UxArgument.ENABLED_PASSCODE, true);
136134
Toast.makeText(getActivity(), R.string.toast_passcode_set, Toast.LENGTH_SHORT).show();
137-
checkBoxPreference.setTitle(getString(R.string.title_passcode_enabled));
135+
mCheckBoxPreference.setTitle(getString(R.string.title_passcode_enabled));
138136
}
139137
break;
140138
}
141-
editor.commit();
139+
mEditor.commit();
142140
}
143141

144142
}

app/src/main/res/layout/fragment_numeric_keyboard.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
android:layout_width="wrap_content"
4141
android:layout_height="wrap_content"
4242
android:gravity="center"
43-
android:text="Enter passcode"
43+
android:text="@string/label_passcode"
4444
android:textSize="25sp"
4545
android:layout_weight="0.1" />
4646

app/src/main/res/values-de/strings.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,7 @@
410410
<string name="label_passcode">Enter Passcode</string>
411411
<string name="toast_wrong_passcode">Wrong passcode, please try again</string>
412412
<string name="toast_passcode_set">Passcode set</string>
413-
<string name="toast_confirm_passcode">Please confirm your passcode</string>
414-
<string name="toast_invalid_passcode_confirmation">Invalid passcode confirmation. Please try again</string>
413+
<string name="toast_invalid_passcode_confirmation">Invalid passcode confirmation. Please try again</string>
415414
<string name="header_passcode_settings">Passcode</string>
416415
<string name="title_passcode_preferences">Passcode Preferences</string>
417416
<string name="title_passcode_enabled">Passcode Turned On</string>
@@ -492,4 +491,7 @@ No user-identifiable information will be collected as part of this process!</str
492491
<string name="label_report_currency">Select currency</string>
493492
<string name="title_use_account_color">Account color in reports</string>
494493
<string name="summary_use_account_color">Use account color in the pie chart</string>
494+
<string name="label_confirm_passcode">Please confirm your passcode</string>
495+
<string name="label_new_passcode">Enter your new passcode</string>
496+
<string name="label_old_passcode">Enter your old passcode</string>
495497
</resources>

app/src/main/res/values-el/strings.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,7 @@
428428
<string name="label_passcode">Enter Passcode</string>
429429
<string name="toast_wrong_passcode">Wrong passcode, please try again</string>
430430
<string name="toast_passcode_set">Passcode set</string>
431-
<string name="toast_confirm_passcode">Please confirm your passcode</string>
432-
<string name="toast_invalid_passcode_confirmation">Invalid passcode confirmation. Please try again</string>
431+
<string name="toast_invalid_passcode_confirmation">Invalid passcode confirmation. Please try again</string>
433432
<string name="header_passcode_settings">Passcode</string>
434433
<string name="title_passcode_preferences">Passcode Preferences</string>
435434
<string name="title_passcode_enabled">Passcode Turned On</string>
@@ -511,4 +510,7 @@ No user-identifiable information will be collected as part of this process!
511510
<string name="label_report_currency">Select currency</string>
512511
<string name="title_use_account_color">Account color in reports</string>
513512
<string name="summary_use_account_color">Use account color in the pie chart</string>
513+
<string name="label_confirm_passcode">Please confirm your passcode</string>
514+
<string name="label_new_passcode">Enter your new passcode</string>
515+
<string name="label_old_passcode">Enter your old passcode</string>
514516
</resources>

app/src/main/res/values-es-rMX/strings.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@
413413
<string name="label_passcode">Enter Passcode</string>
414414
<string name="toast_wrong_passcode">Wrong passcode, please try again</string>
415415
<string name="toast_passcode_set">Passcode set</string>
416-
<string name="toast_confirm_passcode">Please confirm your passcode</string>
417416
<string name="toast_invalid_passcode_confirmation">Invalid passcode confirmation. Please try again</string>
418417
<string name="header_passcode_settings">Passcode</string>
419418
<string name="title_passcode_preferences">Passcode Preferences</string>
@@ -496,4 +495,7 @@ No user-identifiable information will be collected as part of this process!
496495
<string name="label_report_currency">Select currency</string>
497496
<string name="title_use_account_color">Account color in reports</string>
498497
<string name="summary_use_account_color">Use account color in the pie chart</string>
498+
<string name="label_confirm_passcode">Please confirm your passcode</string>
499+
<string name="label_new_passcode">Enter your new passcode</string>
500+
<string name="label_old_passcode">Enter your old passcode</string>
499501
</resources>

app/src/main/res/values-es/strings.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,7 @@
403403
<string name="label_passcode">Introducir contrase&#241;a</string>
404404
<string name="toast_wrong_passcode">Contrase&#241;a incorrecta, intentar otra vez</string>
405405
<string name="toast_passcode_set">Contrase&#241;a establecida</string>
406-
<string name="toast_confirm_passcode">Confirme su contrase&#241;a</string>
407-
<string name="toast_invalid_passcode_confirmation">Confirmaci&#243;n de contrase&#241;a incorrecta. Int&#233;ntelo de nuevo</string>
406+
<string name="toast_invalid_passcode_confirmation">Confirmaci&#243;n de contrase&#241;a incorrecta. Int&#233;ntelo de nuevo</string>
408407
<string name="header_passcode_settings">Contrase&#241;a</string>
409408
<string name="title_passcode_preferences">Ajustes de contrase&#241;a</string>
410409
<string name="title_passcode_enabled">Contrase&#241;a activada</string>
@@ -426,7 +425,7 @@
426425
<string name="menu_group_smaller_slices">Agrupar porciones peque&#241;as</string>
427426
<string name="label_chart_no_data">Datos del gr&#225;fico no disponibles</string>
428427
<string name="label_chart_overall">Total</string>
429-
<string name="label_chart_total">Total\n</string>
428+
<string name="label_chart_total">Total</string>
430429
<string name="label_other_slice">Otros</string>
431430
<string name="toast_chart_percentage_mode_total">El porcentaje del valor seleccionado calculado sobre la cantidad total</string>
432431
<string name="toast_chart_percentage_mode_current_bar">El porcentaje del valor seleccionado calculado sobre la cantidad de la barra apilada actual</string>
@@ -493,4 +492,7 @@ Este proceso solo recoge informaci&#243;n que no permite identificar al usuario<
493492
<string name="label_report_currency">Select currency</string>
494493
<string name="title_use_account_color">Account color in reports</string>
495494
<string name="summary_use_account_color">Use account color in the pie chart</string>
495+
<string name="label_confirm_passcode">Confirme su contrase&#241;a</string>
496+
<string name="label_new_passcode">Enter your new passcode</string>
497+
<string name="label_old_passcode">Enter your old passcode</string>
496498
</resources>

app/src/main/res/values-fr/strings.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@
410410
<string name="label_passcode">Enter Passcode</string>
411411
<string name="toast_wrong_passcode">Wrong passcode, please try again</string>
412412
<string name="toast_passcode_set">Passcode set</string>
413-
<string name="toast_confirm_passcode">Please confirm your passcode</string>
414413
<string name="toast_invalid_passcode_confirmation">Invalid passcode confirmation. Please try again</string>
415414
<string name="header_passcode_settings">Passcode</string>
416415
<string name="title_passcode_preferences">Passcode Preferences</string>
@@ -493,4 +492,7 @@ No user-identifiable information will be collected as part of this process!
493492
<string name="label_report_currency">Select currency</string>
494493
<string name="title_use_account_color">Account color in reports</string>
495494
<string name="summary_use_account_color">Use account color in the pie chart</string>
495+
<string name="label_confirm_passcode">Please confirm your passcode</string>
496+
<string name="label_new_passcode">Enter your new passcode</string>
497+
<string name="label_old_passcode">Enter your old passcode</string>
496498
</resources>

0 commit comments

Comments
 (0)