When the PATTERN is typed 4 wrong times, it has to block 15 seconds before make new tries

This commit is contained in:
dtvv 2018-10-24 02:59:42 -05:00
parent c3c6677faa
commit b3a267fb47
4 changed files with 88 additions and 5 deletions

View file

@ -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);

View file

@ -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();
}
});

View file

@ -21,4 +21,15 @@
android:layout_centerInParent="true"
android:background="@drawable/gradient"/>
<TextView
android:id="@+id/txtBadtry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/patternLockView"
android:text="@string/wrong_pin_wait"
android:layout_marginTop="5dp"
android:layout_centerHorizontal="true"
android:textColor="@color/red"
android:visibility="invisible"/>
</RelativeLayout>

View file

@ -220,7 +220,7 @@
<string name="fee_capital">Fee</string>
<string name="ok">OK</string>
<string name="wrong_pin_wait">Wrong PIN you have to wait %% seconds ...</string>
<string name="wrong_pin_wait">Wrong match you have to wait %% seconds ...</string>
<string name="loading">Loading...</string>
<string name="pay_to">Pay to</string>