Merge lp:~tlnd/financisto/pin-protection into lp:~financisto-dev/financisto/trunk

Proposed by Denis Solonenko
Status: Merged
Merged at revision: 206
Proposed branch: lp:~tlnd/financisto/pin-protection
Merge into: lp:~financisto-dev/financisto/trunk
Diff against target: 651 lines (+244/-61)
18 files modified
AndroidManifest.xml (+2/-1)
src/ru/orangesoftware/financisto/activity/AbstractActivity.java (+13/-0)
src/ru/orangesoftware/financisto/activity/AbstractExportActivity.java (+12/-2)
src/ru/orangesoftware/financisto/activity/AbstractListActivity.java (+13/-1)
src/ru/orangesoftware/financisto/activity/AttributeActivity.java (+13/-0)
src/ru/orangesoftware/financisto/activity/CurrencyActivity.java (+12/-0)
src/ru/orangesoftware/financisto/activity/MainActivity.java (+9/-47)
src/ru/orangesoftware/financisto/activity/MonthlyViewActivity.java (+12/-1)
src/ru/orangesoftware/financisto/activity/MyEntityActivity.java (+12/-0)
src/ru/orangesoftware/financisto/activity/PinActivity.java (+5/-1)
src/ru/orangesoftware/financisto/activity/PreferencesActivity.java (+13/-0)
src/ru/orangesoftware/financisto/activity/RecurActivity.java (+12/-0)
src/ru/orangesoftware/financisto/activity/Report2DChartActivity.java (+12/-0)
src/ru/orangesoftware/financisto/activity/ReportActivity.java (+13/-0)
src/ru/orangesoftware/financisto/activity/ReportPreferencesActivity.java (+12/-0)
src/ru/orangesoftware/financisto/activity/ReportsListActivity.java (+12/-0)
src/ru/orangesoftware/financisto/utils/MyPreferences.java (+7/-8)
src/ru/orangesoftware/financisto/utils/PinProtection.java (+60/-0)
To merge this branch: bzr merge lp:~tlnd/financisto/pin-protection
Reviewer Review Type Date Requested Status
Financisto Developers Pending
Review via email: mp+66923@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Denis Solonenko (denis-solonenko) wrote :

I modified PinProtection class to make the states more explicit

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'AndroidManifest.xml'
2--- AndroidManifest.xml 2011-06-18 10:38:16 +0000
3+++ AndroidManifest.xml 2011-07-05 15:54:36 +0000
4@@ -79,7 +79,8 @@
5 </intent-filter>
6 </activity>
7
8- <activity android:name=".activity.PinActivity" android:label="@string/enter_pin"/>
9+ <activity android:name=".activity.PinActivity" android:label="@string/enter_pin"
10+ android:launchMode="singleTop"/>
11
12 <activity android:name=".activity.BlotterActivity" android:label="@string/blotter"/>
13
14
15=== modified file 'src/ru/orangesoftware/financisto/activity/AbstractActivity.java'
16--- src/ru/orangesoftware/financisto/activity/AbstractActivity.java 2011-02-20 19:39:08 +0000
17+++ src/ru/orangesoftware/financisto/activity/AbstractActivity.java 2011-07-05 15:54:36 +0000
18@@ -15,6 +15,7 @@
19 import ru.orangesoftware.financisto.db.DatabaseAdapter;
20 import ru.orangesoftware.financisto.db.MyEntityManager;
21 import ru.orangesoftware.financisto.model.MultiChoiceItem;
22+import ru.orangesoftware.financisto.utils.PinProtection;
23 import ru.orangesoftware.financisto.view.NodeInflater;
24 import android.app.Activity;
25 import android.content.Context;
26@@ -43,6 +44,18 @@
27 }
28
29 @Override
30+ protected void onPause() {
31+ super.onPause();
32+ PinProtection.lock(this);
33+ }
34+
35+ @Override
36+ protected void onResume() {
37+ super.onResume();
38+ PinProtection.unlock(this);
39+ }
40+
41+ @Override
42 public void onClick(View v) {
43 int id = v.getId();
44 onClick(v, id);
45
46=== modified file 'src/ru/orangesoftware/financisto/activity/AbstractExportActivity.java'
47--- src/ru/orangesoftware/financisto/activity/AbstractExportActivity.java 2011-02-20 19:39:08 +0000
48+++ src/ru/orangesoftware/financisto/activity/AbstractExportActivity.java 2011-07-05 15:54:36 +0000
49@@ -20,6 +20,7 @@
50 import ru.orangesoftware.financisto.blotter.WhereFilter;
51 import ru.orangesoftware.financisto.blotter.WhereFilter.DateTimeCriteria;
52 import ru.orangesoftware.financisto.utils.DateUtils;
53+import ru.orangesoftware.financisto.utils.PinProtection;
54 import ru.orangesoftware.financisto.utils.DateUtils.Period;
55 import ru.orangesoftware.financisto.utils.DateUtils.PeriodType;
56
57@@ -125,7 +126,16 @@
58 updatePeriod();
59 }
60 }
61-
62-
63
64+ @Override
65+ protected void onPause() {
66+ super.onPause();
67+ PinProtection.lock(this);
68+ }
69+
70+ @Override
71+ protected void onResume() {
72+ super.onResume();
73+ PinProtection.unlock(this);
74+ }
75 }
76
77=== modified file 'src/ru/orangesoftware/financisto/activity/AbstractListActivity.java'
78--- src/ru/orangesoftware/financisto/activity/AbstractListActivity.java 2011-02-20 19:39:08 +0000
79+++ src/ru/orangesoftware/financisto/activity/AbstractListActivity.java 2011-07-05 15:54:36 +0000
80@@ -17,6 +17,7 @@
81 import ru.orangesoftware.financisto.db.DatabaseAdapter;
82 import ru.orangesoftware.financisto.db.MyEntityManager;
83 import ru.orangesoftware.financisto.utils.MenuItemInfo;
84+import ru.orangesoftware.financisto.utils.PinProtection;
85 import android.app.ListActivity;
86 import android.content.Intent;
87 import android.database.Cursor;
88@@ -98,6 +99,18 @@
89 db.close();
90 super.onDestroy();
91 }
92+
93+ @Override
94+ protected void onPause() {
95+ super.onPause();
96+ PinProtection.lock(this);
97+ }
98+
99+ @Override
100+ protected void onResume() {
101+ super.onResume();
102+ PinProtection.unlock(this);
103+ }
104
105 @Override
106 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
107@@ -192,5 +205,4 @@
108 requeryCursor();
109 }
110 }
111-
112 }
113
114=== modified file 'src/ru/orangesoftware/financisto/activity/AttributeActivity.java'
115--- src/ru/orangesoftware/financisto/activity/AttributeActivity.java 2011-02-20 19:39:08 +0000
116+++ src/ru/orangesoftware/financisto/activity/AttributeActivity.java 2011-07-05 15:54:36 +0000
117@@ -14,6 +14,7 @@
118 import ru.orangesoftware.financisto.db.DatabaseAdapter;
119 import ru.orangesoftware.financisto.db.DatabaseHelper.AttributeColumns;
120 import ru.orangesoftware.financisto.model.Attribute;
121+import ru.orangesoftware.financisto.utils.PinProtection;
122 import ru.orangesoftware.financisto.utils.Utils;
123 import android.app.Activity;
124 import android.content.Intent;
125@@ -126,6 +127,18 @@
126 }
127
128 @Override
129+ protected void onPause() {
130+ super.onPause();
131+ PinProtection.lock(this);
132+ }
133+
134+ @Override
135+ protected void onResume() {
136+ super.onResume();
137+ PinProtection.unlock(this);
138+ }
139+
140+ @Override
141 public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
142 boolean showDefaultCheck = Attribute.TYPE_CHECKBOX - position == 1;
143 findViewById(R.id.default_value_layout1).setVisibility(!showDefaultCheck ? View.VISIBLE : View.GONE);
144
145=== modified file 'src/ru/orangesoftware/financisto/activity/CurrencyActivity.java'
146--- src/ru/orangesoftware/financisto/activity/CurrencyActivity.java 2011-06-20 15:01:29 +0000
147+++ src/ru/orangesoftware/financisto/activity/CurrencyActivity.java 2011-07-05 15:54:36 +0000
148@@ -25,6 +25,7 @@
149 import ru.orangesoftware.financisto.db.MyEntityManager;
150 import ru.orangesoftware.financisto.model.Currency;
151 import ru.orangesoftware.financisto.utils.CurrencyCache;
152+import ru.orangesoftware.financisto.utils.PinProtection;
153
154 import java.text.DecimalFormatSymbols;
155
156@@ -153,5 +154,16 @@
157 db.close();
158 super.onDestroy();
159 }
160+
161+ @Override
162+ protected void onPause() {
163+ super.onPause();
164+ PinProtection.lock(this);
165+ }
166
167+ @Override
168+ protected void onResume() {
169+ super.onResume();
170+ PinProtection.unlock(this);
171+ }
172 }
173
174=== modified file 'src/ru/orangesoftware/financisto/activity/MainActivity.java'
175--- src/ru/orangesoftware/financisto/activity/MainActivity.java 2011-06-21 16:47:12 +0000
176+++ src/ru/orangesoftware/financisto/activity/MainActivity.java 2011-07-05 15:54:36 +0000
177@@ -62,16 +62,15 @@
178 import ru.orangesoftware.financisto.utils.EntityEnum;
179 import ru.orangesoftware.financisto.utils.EnumUtils;
180 import ru.orangesoftware.financisto.utils.MyPreferences;
181+import ru.orangesoftware.financisto.utils.PinProtection;
182
183 import java.io.IOException;
184 import java.util.ArrayList;
185 import java.util.HashMap;
186 import java.util.List;
187-import java.util.concurrent.TimeUnit;
188
189 public class MainActivity extends TabActivity implements TabHost.OnTabChangeListener {
190
191- private static final int ACTIVITY_PIN = 1;
192 private static final int ACTIVITY_CSV_EXPORT = 2;
193 private static final int ACTIVITY_QIF_EXPORT = 3;
194
195@@ -90,25 +89,12 @@
196
197 private final HashMap<String, Boolean> started = new HashMap<String, Boolean>();
198
199- private boolean shouldAskForPinOnResume = false;
200- private long activityPausedAtTime = 0;
201-
202 @Override
203 protected void onCreate(Bundle savedInstanceState) {
204 super.onCreate(savedInstanceState);
205 requestWindowFeature(Window.FEATURE_NO_TITLE);
206-
207- Boolean isPinProtected = (Boolean)getLastNonConfigurationInstance();
208- if (isPinProtected == null) {
209- isPinProtected = true;
210- }
211
212- if (isPinProtected && MyPreferences.shouldAskForPin(this)) {
213- shouldAskForPinOnResume = false;
214- askForPin();
215- } else {
216- initialLoad();
217- }
218+ initialLoad();
219
220 if (MyPreferences.isSendErrorReport(this)) {
221 ExceptionHandler.register(this, "http://orangesoftware.ru/bugs/server.php");
222@@ -125,45 +111,27 @@
223 tabHost.setOnTabChangedListener(this);
224 }
225
226- private void askForPin() {
227- Intent intent = new Intent(this, PinActivity.class);
228- startActivityForResult(intent, ACTIVITY_PIN);
229- }
230-
231 @Override
232 protected void onResume() {
233 super.onResume();
234- if (shouldAskForPinOnResume && MyPreferences.isPinLockEnabled(this)) {
235- long deltaTimeMs = TimeUnit.MILLISECONDS.convert(MyPreferences.getLockTimeSeconds(this), TimeUnit.SECONDS);
236- if (deltaTimeMs > 0 && System.currentTimeMillis() - activityPausedAtTime > deltaTimeMs) {
237- askForPin();
238- }
239- }
240+ PinProtection.unlock(this);
241 }
242
243 @Override
244 protected void onPause() {
245 super.onPause();
246- shouldAskForPinOnResume = true;
247- activityPausedAtTime = System.currentTimeMillis();
248- MyPreferences.setPinRequired(true);
249+ PinProtection.lock(this);
250 }
251-
252+
253 @Override
254- public Object onRetainNonConfigurationInstance() {
255- return MyPreferences.shouldAskForPin(this);
256+ protected void onDestroy() {
257+ super.onDestroy();
258+ PinProtection.immediateLock(this);
259 }
260
261 @Override
262 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
263- if (requestCode == ACTIVITY_PIN) {
264- if (resultCode == RESULT_OK && data != null && data.hasExtra(PinActivity.SUCCESS)) {
265- initialLoad();
266- } else {
267- finish();
268- System.exit(-1);
269- }
270- } else if (requestCode == ACTIVITY_CSV_EXPORT) {
271+ if (requestCode == ACTIVITY_CSV_EXPORT) {
272 if (resultCode == RESULT_OK) {
273 WhereFilter filter = WhereFilter.fromIntent(data);
274 Currency currency = new Currency();
275@@ -231,12 +199,6 @@
276 }
277
278 @Override
279- protected void onStop() {
280- super.onStop();
281- MyPreferences.setPinRequired(true);
282- }
283-
284- @Override
285 public void onTabChanged(String tabId) {
286 if (started.containsKey(tabId)) {
287 Context c = getTabHost().getCurrentView().getContext();
288
289=== modified file 'src/ru/orangesoftware/financisto/activity/MonthlyViewActivity.java'
290--- src/ru/orangesoftware/financisto/activity/MonthlyViewActivity.java 2011-02-23 12:53:52 +0000
291+++ src/ru/orangesoftware/financisto/activity/MonthlyViewActivity.java 2011-07-05 15:54:36 +0000
292@@ -12,6 +12,7 @@
293 import ru.orangesoftware.financisto.model.Account;
294 import ru.orangesoftware.financisto.model.AccountType;
295 import ru.orangesoftware.financisto.model.Currency;
296+import ru.orangesoftware.financisto.utils.PinProtection;
297 import ru.orangesoftware.financisto.utils.Utils;
298 import android.app.ListActivity;
299 import android.content.Intent;
300@@ -102,8 +103,18 @@
301 dbAdapter.close();
302 super.onDestroy();
303 }
304+
305+ @Override
306+ protected void onPause() {
307+ super.onPause();
308+ PinProtection.lock(this);
309+ }
310
311-
312+ @Override
313+ protected void onResume() {
314+ super.onResume();
315+ PinProtection.unlock(this);
316+ }
317
318 /**
319 * Initialize data and GUI elements.
320
321=== modified file 'src/ru/orangesoftware/financisto/activity/MyEntityActivity.java'
322--- src/ru/orangesoftware/financisto/activity/MyEntityActivity.java 2011-02-20 19:39:08 +0000
323+++ src/ru/orangesoftware/financisto/activity/MyEntityActivity.java 2011-07-05 15:54:36 +0000
324@@ -22,6 +22,7 @@
325 import ru.orangesoftware.financisto.db.DatabaseHelper;
326 import ru.orangesoftware.financisto.db.MyEntityManager;
327 import ru.orangesoftware.financisto.model.MyEntity;
328+import ru.orangesoftware.financisto.utils.PinProtection;
329
330 public abstract class MyEntityActivity<T extends MyEntity> extends Activity {
331
332@@ -99,4 +100,15 @@
333 super.onDestroy();
334 }
335
336+ @Override
337+ protected void onPause() {
338+ super.onPause();
339+ PinProtection.lock(this);
340+ }
341+
342+ @Override
343+ protected void onResume() {
344+ super.onResume();
345+ PinProtection.unlock(this);
346+ }
347 }
348
349=== modified file 'src/ru/orangesoftware/financisto/activity/PinActivity.java'
350--- src/ru/orangesoftware/financisto/activity/PinActivity.java 2011-02-20 19:39:08 +0000
351+++ src/ru/orangesoftware/financisto/activity/PinActivity.java 2011-07-05 15:54:36 +0000
352@@ -39,11 +39,15 @@
353
354 @Override
355 public void onSuccess(String pinBase64) {
356- MyPreferences.setPinRequired(false);
357+ MyPreferences.setPinLockEnabled(this, false);
358 Intent data = new Intent();
359 data.putExtra(SUCCESS, true);
360 setResult(RESULT_OK, data);
361 finish();
362 }
363
364+ @Override
365+ public void onBackPressed() {
366+ }
367+
368 }
369
370=== modified file 'src/ru/orangesoftware/financisto/activity/PreferencesActivity.java'
371--- src/ru/orangesoftware/financisto/activity/PreferencesActivity.java 2011-02-20 19:39:08 +0000
372+++ src/ru/orangesoftware/financisto/activity/PreferencesActivity.java 2011-07-05 15:54:36 +0000
373@@ -12,6 +12,7 @@
374
375 import ru.orangesoftware.financisto.R;
376 import ru.orangesoftware.financisto.utils.MyPreferences;
377+import ru.orangesoftware.financisto.utils.PinProtection;
378 import android.content.ComponentName;
379 import android.content.Intent;
380 import android.content.Intent.ShortcutIconResource;
381@@ -75,4 +76,16 @@
382 return intent;
383 }
384
385+ @Override
386+ protected void onPause() {
387+ super.onPause();
388+ PinProtection.lock(this);
389+ }
390+
391+ @Override
392+ protected void onResume() {
393+ super.onResume();
394+ PinProtection.unlock(this);
395+ }
396+
397 }
398
399=== modified file 'src/ru/orangesoftware/financisto/activity/RecurActivity.java'
400--- src/ru/orangesoftware/financisto/activity/RecurActivity.java 2011-02-20 19:39:08 +0000
401+++ src/ru/orangesoftware/financisto/activity/RecurActivity.java 2011-07-05 15:54:36 +0000
402@@ -16,6 +16,7 @@
403 import ru.orangesoftware.financisto.R;
404 import ru.orangesoftware.financisto.utils.DateUtils;
405 import ru.orangesoftware.financisto.utils.LocalizableEnum;
406+import ru.orangesoftware.financisto.utils.PinProtection;
407 import ru.orangesoftware.financisto.utils.RecurUtils;
408 import ru.orangesoftware.financisto.utils.Utils;
409 import ru.orangesoftware.financisto.utils.RecurUtils.DayOfWeek;
410@@ -422,5 +423,16 @@
411 }
412 return selected;
413 }
414+
415+ @Override
416+ protected void onPause() {
417+ super.onPause();
418+ PinProtection.lock(this);
419+ }
420
421+ @Override
422+ protected void onResume() {
423+ super.onResume();
424+ PinProtection.unlock(this);
425+ }
426 }
427
428=== modified file 'src/ru/orangesoftware/financisto/activity/Report2DChartActivity.java'
429--- src/ru/orangesoftware/financisto/activity/Report2DChartActivity.java 2011-02-20 19:39:08 +0000
430+++ src/ru/orangesoftware/financisto/activity/Report2DChartActivity.java 2011-07-05 15:54:36 +0000
431@@ -13,6 +13,7 @@
432 import ru.orangesoftware.financisto.report.*;
433 import ru.orangesoftware.financisto.utils.CurrencyCache;
434 import ru.orangesoftware.financisto.utils.MyPreferences;
435+import ru.orangesoftware.financisto.utils.PinProtection;
436 import ru.orangesoftware.financisto.utils.Utils;
437 import ru.orangesoftware.financisto.view.Report2DChartView;
438 import android.app.Activity;
439@@ -482,4 +483,15 @@
440 super.onDestroy();
441 }
442
443+ @Override
444+ protected void onPause() {
445+ super.onPause();
446+ PinProtection.lock(this);
447+ }
448+
449+ @Override
450+ protected void onResume() {
451+ super.onResume();
452+ PinProtection.unlock(this);
453+ }
454 }
455
456=== modified file 'src/ru/orangesoftware/financisto/activity/ReportActivity.java'
457--- src/ru/orangesoftware/financisto/activity/ReportActivity.java 2011-04-18 14:37:21 +0000
458+++ src/ru/orangesoftware/financisto/activity/ReportActivity.java 2011-07-05 15:54:36 +0000
459@@ -36,6 +36,7 @@
460 import ru.orangesoftware.financisto.report.PeriodReport;
461 import ru.orangesoftware.financisto.report.Report;
462 import ru.orangesoftware.financisto.report.ReportData;
463+import ru.orangesoftware.financisto.utils.PinProtection;
464
465 public class ReportActivity extends ListActivity implements RequeryCursorActivity {
466
467@@ -83,6 +84,18 @@
468 showOrRemoveTotals();
469 }
470
471+ @Override
472+ protected void onPause() {
473+ super.onPause();
474+ PinProtection.lock(this);
475+ }
476+
477+ @Override
478+ protected void onResume() {
479+ super.onResume();
480+ PinProtection.unlock(this);
481+ }
482+
483 private void showOrRemoveTotals() {
484 if (!currentReport.shouldDisplayTotal()) {
485 findViewById(R.id.labelTotal).setVisibility(View.GONE);
486
487=== modified file 'src/ru/orangesoftware/financisto/activity/ReportPreferencesActivity.java'
488--- src/ru/orangesoftware/financisto/activity/ReportPreferencesActivity.java 2011-02-20 19:39:08 +0000
489+++ src/ru/orangesoftware/financisto/activity/ReportPreferencesActivity.java 2011-07-05 15:54:36 +0000
490@@ -18,6 +18,7 @@
491 import ru.orangesoftware.financisto.model.Currency;
492 import ru.orangesoftware.financisto.utils.CurrencyCache;
493 import ru.orangesoftware.financisto.utils.MyPreferences;
494+import ru.orangesoftware.financisto.utils.PinProtection;
495 import android.app.AlertDialog;
496 import android.app.Dialog;
497 import android.content.DialogInterface;
498@@ -107,5 +108,16 @@
499 dialog.cancel();
500 return true;
501 }
502+
503+ @Override
504+ protected void onPause() {
505+ super.onPause();
506+ PinProtection.lock(this);
507+ }
508
509+ @Override
510+ protected void onResume() {
511+ super.onResume();
512+ PinProtection.unlock(this);
513+ }
514 }
515
516=== modified file 'src/ru/orangesoftware/financisto/activity/ReportsListActivity.java'
517--- src/ru/orangesoftware/financisto/activity/ReportsListActivity.java 2011-02-20 19:39:08 +0000
518+++ src/ru/orangesoftware/financisto/activity/ReportsListActivity.java 2011-07-05 15:54:36 +0000
519@@ -16,6 +16,7 @@
520 import ru.orangesoftware.financisto.graph.Report2DChart;
521 import ru.orangesoftware.financisto.report.Report;
522 import ru.orangesoftware.financisto.report.ReportType;
523+import ru.orangesoftware.financisto.utils.PinProtection;
524 import android.app.ListActivity;
525 import android.content.Context;
526 import android.content.Intent;
527@@ -47,8 +48,19 @@
528 setContentView(R.layout.reports_list);
529 setListAdapter(new ReportListAdapter(this, reports));
530 }
531+
532+ @Override
533+ protected void onPause() {
534+ super.onPause();
535+ PinProtection.lock(this);
536+ }
537
538 @Override
539+ protected void onResume() {
540+ super.onResume();
541+ PinProtection.unlock(this);
542+ }
543+ @Override
544 protected void onListItemClick(ListView l, View v, int position, long id) {
545 if (reports[position].isConventionalBarReport()) {
546 // Conventional Bars reports
547
548=== modified file 'src/ru/orangesoftware/financisto/utils/MyPreferences.java'
549--- src/ru/orangesoftware/financisto/utils/MyPreferences.java 2011-06-21 16:47:12 +0000
550+++ src/ru/orangesoftware/financisto/utils/MyPreferences.java 2011-07-05 15:54:36 +0000
551@@ -78,10 +78,6 @@
552 return sharedPreferences.getBoolean("use_my_location", true);
553 }
554
555- public static boolean shouldAskForPin(Context context) {
556- return isPinProtected(context) && isPinRequired;
557- }
558-
559 public static boolean isPinProtected(Context context) {
560 SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
561 return sharedPreferences.getBoolean("pin_protection", false);
562@@ -92,6 +88,13 @@
563 return isPinProtected(context) && sharedPreferences.getBoolean("pin_protection_lock", true);
564 }
565
566+ public static void setPinLockEnabled(Context context, boolean enabled) {
567+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
568+ SharedPreferences.Editor editor = sharedPreferences.edit();
569+ editor.putBoolean("pin_protection_lock", enabled);
570+ editor.commit();
571+ }
572+
573 public static int getLockTimeSeconds(Context context) {
574 SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
575 return isPinLockEnabled(context) ? 60*Integer.parseInt(sharedPreferences.getString("pin_protection_lock_time", "5")) : 0;
576@@ -101,10 +104,6 @@
577 SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
578 return sharedPreferences.getString("pin", null);
579 }
580-
581- public static void setPinRequired(boolean isPinRequired) {
582- MyPreferences.isPinRequired = isPinRequired;
583- }
584
585 public static AccountSortOrder getAccountSortOrder(Context context) {
586 SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
587
588=== added file 'src/ru/orangesoftware/financisto/utils/PinProtection.java'
589--- src/ru/orangesoftware/financisto/utils/PinProtection.java 1970-01-01 00:00:00 +0000
590+++ src/ru/orangesoftware/financisto/utils/PinProtection.java 2011-07-05 15:54:36 +0000
591@@ -0,0 +1,60 @@
592+/*******************************************************************************
593+ * Copyright (c) 2011 Timo Lindhorst
594+ * All rights reserved. This program and the accompanying materials
595+ * are made available under the terms of the GNU Public License v2.0
596+ * which accompanies this distribution, and is available at
597+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
598+ *
599+ * Contributors:
600+ * Timo Lindhorst - Initial implementation
601+ ******************************************************************************/
602+package ru.orangesoftware.financisto.utils;
603+
604+
605+import java.util.concurrent.TimeUnit;
606+
607+import android.content.Context;
608+import android.content.Intent;
609+import ru.orangesoftware.financisto.activity.PinActivity;
610+
611+public class PinProtection {
612+ private static long lockTime = 0;
613+ private static boolean unlocked = false;
614+ private static final int MIN_DELTA_TIME_MS = 3000;
615+
616+ private static void askForPin(Context c) {
617+ Intent intent = new Intent(c, PinActivity.class);
618+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
619+ c.startActivity(intent);
620+ }
621+
622+ public static void lock(Context c) {
623+ if (unlocked) {
624+ lockTime = System.currentTimeMillis();
625+ }
626+ }
627+
628+ public static void unlock(Context c) {
629+ long curTime = System.currentTimeMillis();
630+ long deltaTimeMs = TimeUnit.MILLISECONDS.convert(MyPreferences.getLockTimeSeconds(c), TimeUnit.SECONDS);
631+ if (deltaTimeMs < MIN_DELTA_TIME_MS)
632+ deltaTimeMs = MIN_DELTA_TIME_MS;
633+ if ((curTime - lockTime) < deltaTimeMs) {
634+ unlocked = true;
635+ } else if (! MyPreferences.isPinProtected(c)) {
636+ unlocked = true;
637+ lockTime = System.currentTimeMillis();
638+ } else if (! MyPreferences.isPinLockEnabled(c)) {
639+ unlocked = true;
640+ lockTime = System.currentTimeMillis();
641+ MyPreferences.setPinLockEnabled(c, true);
642+ } else {
643+ askForPin(c);
644+ }
645+ }
646+
647+ public static void immediateLock(Context c) {
648+ lockTime = 0;
649+ unlocked = false;
650+ }
651+}