From b3a267fb47f69bef697e9daa014b26ad7126e1c0 Mon Sep 17 00:00:00 2001 From: dtvv Date: Wed, 24 Oct 2018 02:59:42 -0500 Subject: [PATCH] When the PATTERN is typed 4 wrong times, it has to block 15 seconds before make new tries --- .../activities/PatternRequestActivity.java | 74 ++++++++++++++++++- .../fragments/PatternSecurityFragment.java | 6 +- .../res/layout/activity_pattern_request.xml | 11 +++ app/src/main/res/values/strings.xml | 2 +- 4 files changed, 88 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/PatternRequestActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/PatternRequestActivity.java index ec51e2f..56ec8b1 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/PatternRequestActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/PatternRequestActivity.java @@ -36,6 +36,19 @@ public class PatternRequestActivity extends AppCompatActivity { @BindView(R.id.tvPatternText) TextView tvPatternText; + @BindView(R.id.txtBadtry) + TextView txtBadtry; + + /* + * Contains the bad tries + * */ + private int tries = 0; + + /* + * Seconds counter + * */ + private int seconds = 15; + @@ -111,10 +124,69 @@ public class PatternRequestActivity extends AppCompatActivity { private void incorrect(){ + /* + * One more bad try + * */ + ++tries; + + final Activity activity = this; + + /* + * User can not go more up to 5 bad tries + * */ + if(tries==4) { + tries = 0; + + patternLockView.setEnabled(false); + txtBadtry.setVisibility(View.VISIBLE); + txtBadtry.setText(txtBadtry.getText().toString().replace("%%",String.valueOf(seconds))); + + final Timer t = new Timer(); + //Set the schedule function and rate + t.scheduleAtFixedRate(new TimerTask() { + + @Override + public void run() { + + --seconds; + + if(seconds==0){ + t.cancel(); + + seconds = 15; + + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + patternLockView.setEnabled(true); + txtBadtry.setVisibility(View.INVISIBLE); + patternLockView.clearPattern(); + patternLockView.requestFocus(); + } + }); + } + else{ + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + txtBadtry.setText(activity.getResources().getString(R.string.wrong_pin_wait).replace("%%",String.valueOf(seconds))); + } + }); + } + } + + }, + //Set how long before to start calling the TimerTask (in milliseconds) + 1000, + //Set the amount of time between each execution (in milliseconds) + 1000); + + return; + } + /* * Show error * */ - final Activity activity = this; tvPatternText.setText(activity.getResources().getString(R.string.Incorrect_pattern)); tvPatternText.setTextColor(Color.RED); tvPatternText.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/PatternSecurityFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/PatternSecurityFragment.java index 070b1b8..e98d883 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/PatternSecurityFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/PatternSecurityFragment.java @@ -193,8 +193,8 @@ public class PatternSecurityFragment extends Fragment { * */ tvPatternText.setText(getActivity().getResources().getString(R.string.Pattern_set_correctly)); tvPatternText.setTextColor(Color.GREEN); - final Timer t = new Timer(); - t.scheduleAtFixedRate(new TimerTask() { + final Timer t_ = new Timer(); + t_.scheduleAtFixedRate(new TimerTask() { @Override public void run() { @@ -203,7 +203,7 @@ public class PatternSecurityFragment extends Fragment { @Override public void run() { - t.cancel(); + t_.cancel(); showNewPatternUI(); } }); diff --git a/app/src/main/res/layout/activity_pattern_request.xml b/app/src/main/res/layout/activity_pattern_request.xml index 1bd30ed..1f9e119 100644 --- a/app/src/main/res/layout/activity_pattern_request.xml +++ b/app/src/main/res/layout/activity_pattern_request.xml @@ -21,4 +21,15 @@ android:layout_centerInParent="true" android:background="@drawable/gradient"/> + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fc1bd08..02263a8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -220,7 +220,7 @@ Fee OK - Wrong PIN you have to wait %% seconds ... + Wrong match you have to wait %% seconds ... Loading... Pay to