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

This commit is contained in:
dtvv 2018-10-17 04:14:43 -05:00
parent c554471115
commit 3941585740
3 changed files with 93 additions and 2 deletions

View file

@ -12,6 +12,7 @@ import android.text.Editable;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -41,6 +42,19 @@ public class PinRequestActivity extends AppCompatActivity {
@BindView(R.id.btnOK) @BindView(R.id.btnOK)
Button btnOK; Button btnOK;
@BindView(R.id.txtBadtry)
TextView txtBadtry;
/*
* Contains the bad tries
* */
private int tries = 0;
/*
* Seconds counter
* */
private int seconds = 15;
@ -97,11 +111,74 @@ public class PinRequestActivity extends AppCompatActivity {
} }
else{ else{
/*
* One more bad try
* */
++tries;
final Activity activity = this;
etPassword.setTextColor(Color.RED);
/*
* User can not go more up to 5 bad tries
* */
if(tries==4){
tries = 0;
btnOK.setEnabled(false);
etPassword.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() {
btnOK.setEnabled(true);
etPassword.setEnabled(true);
txtBadtry.setVisibility(View.INVISIBLE);
etPassword.setText("");
etPassword.setTextColor(Color.WHITE);
}
});
}
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;
}
/* /*
* Set in red the rext and reset the password after a period of time * Set in red the rext and reset the password after a period of time
* */ * */
final Activity activity = this;
etPassword.setTextColor(Color.RED);
final Timer t = new Timer(); final Timer t = new Timer();
//Set the schedule function and rate //Set the schedule function and rate
t.scheduleAtFixedRate(new TimerTask() { t.scheduleAtFixedRate(new TimerTask() {

View file

@ -45,4 +45,16 @@
android:textSize="18dp" android:textSize="18dp"
android:layout_alignParentRight="true"/> android:layout_alignParentRight="true"/>
<TextView
android:id="@+id/txtBadtry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btnOK"
android:text="@string/wrong_pin_wait"
android:layout_marginTop="5dp"
android:layout_alignParentRight="true"
android:textColor="@color/red"
android:layout_marginRight="10dp"
android:visibility="invisible"/>
</RelativeLayout> </RelativeLayout>

View file

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