I have a custom AlertDialog with an EditText for the PIN. OnClick of positive button the PIN in the editText is checked with the SharedPreferences. If it matches I want to close the dialog or else It should remain open. At the moment when the PIN is correct the dialog closes and re appears and I do not want it to re appear. Thanks for your help in advance.
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
// TODO Auto-generated method stub
if ((System.currentTimeMillis() - mainScreenActivity.lastLoggedIn) / 1000 >= 120) {
//startActivity(pinVarificationActivity);
//Toast.makeText(getApplicationContext(),"Session has timed out, please enter your PIN",Toast.LENGTH_LONG).show();
LayoutInflater inflaterPinVerificationDialog = this.getLayoutInflater();
final View inflatorPinVerificationDialog = inflaterPinVerificationDialog.inflate(R.layout.dialog_pin_verification, null);
final AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AlertDialogCustom));
builder.setTitle("Session timed out. Please enter PIN");
builder.setView(inflatorPinVerificationDialog);
pinFromDialog = (EditText) inflatorPinVerificationDialog.findViewById(R.id.etDialogPin);
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
String dialogPinValue = pinFromDialog.getText().toString();
String sharedPrefPinVal = loginData.getString("pin", "not found");
if (sharedPrefPinVal.equals(dialogPinValue)) {
Toast.makeText(getApplicationContext(), "login successful",
Toast.LENGTH_SHORT).show();
mainScreenActivity.lastLoggedIn = System.currentTimeMillis();
alertDialogPinVerification.dismiss();
} else {
Toast.makeText(getApplicationContext(),
"Incorrect pin - Please try again",
Toast.LENGTH_LONG).show();
}
}
});
builder.setNegativeButton("Forgot PIN", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
alertDialogPinVerification = builder.create();
alertDialogPinVerification.show();
} else {
mainScreenActivity.lastLoggedIn = System.currentTimeMillis();
}
return super.dispatchTouchEvent(ev);
}