Я создал (-а) информацию о попытке входа. Но я хочу поставить продолжительность, если попытки исчезнут: «Ваша попытка достигает 0, повторите попытку через 3 минуты».Длительность входа для входа в систему
ВЫПУСКА
Проблема в моем коде, когда я сжег 1 попытка всплывающее сообщение. Предположительно, это произойдет, если все попытки исчезнут.
JAVA
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mobile__grocery);
ocLogin();
}
public void ocLogin() {
email = (EditText) findViewById(R.id.Email);
password = (EditText) findViewById(R.id.Password);
attempts = (TextView) findViewById(R.id.number);
login_btn = (ImageButton) findViewById(R.id.Login);
attempts.setText(Integer.toString(attempt_counter));
login_btn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!allowedtoLogin) {
Toast.makeText(Mobile_Grocery.this, "Your attempt reach 0, please wait 3 minutes to log again", Toast.LENGTH_SHORT).show();
}
if (email.getText().toString().equals("admin") &&
password.getText().toString().equals("pass")) {
Toast.makeText(Mobile_Grocery.this, "Email and Password is correct",
Toast.LENGTH_SHORT).show();
Intent intent = new Intent("com.example.admin.mobile_grocery.Method");
startActivity(intent);
} else {
allowedtoLogin = false;
Toast.makeText(Mobile_Grocery.this, "Email and Password is incorrect",
Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
allowedtoLogin = true;
}
},WAIT_TIME);
attempt_counter--;
attempts.setText(Integer.toString(attempt_counter));
if (attempt_counter == 0) {
login_btn.setEnabled(false);
}
}
}
}
);
}
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context=".Mobile_Grocery"
android:id="@+id/mobile_grocery"
>
<ImageView
android:id="@+id/mobile_grocery_bckgrnd"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/mobile_grocery"
android:scaleType="centerCrop"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mobile_grocery_main"
android:id="@+id/mobilegrocery"
android:layout_marginTop="40dp"
android:textSize="50dp"
android:textColor="#000000"
android:textStyle="bold|italic"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/Email"
android:hint="@string/email_text"
android:textColorHint="#000000"
android:layout_above="@+id/Password"
android:layout_alignLeft="@+id/Password"
android:layout_alignStart="@+id/Password" />
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/Password"
android:hint="@string/password_text"
android:textColorHint="#000000"
android:layout_marginBottom="119dp"
android:layout_alignParentBottom="true"
android:layout_alignLeft="@+id/mobilegrocery"
android:layout_alignStart="@+id/mobilegrocery"
android:layout_marginLeft="37dp"
android:layout_marginStart="37dp"
android:password="true" />
<ImageButton
android:layout_width="100dp"
android:layout_height="45dp"
android:id="@+id/Login"
android:layout_marginTop="43dp"
android:layout_below="@+id/Email"
android:layout_alignLeft="@+id/Password"
android:layout_alignStart="@+id/Password"
android:src="@drawable/login_button"
android:scaleType="centerCrop"
android:layout_marginLeft="48dp"
android:layout_marginStart="48dp"
android:onClick="ocLogin"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/attempt_text"
android:id="@+id/attleft"
android:textSize="20dp"
android:textColor="#000000"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="100dp"
android:layout_height="45dp"
android:id="@+id/register"
android:src="@drawable/register"
android:scaleType="centerCrop"
android:layout_below="@+id/Login"
android:layout_alignLeft="@+id/Login"
android:layout_alignStart="@+id/Login" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/number"
android:textColor="#000000"
android:textSize="20dp"
android:layout_alignParentBottom="true"
android:layout_alignLeft="@+id/register"
android:layout_alignStart="@+id/register"
android:password="false" />
Everytime Я нажал на кнопку Войти с неправильными учетными данными, попытка уменьшить 1, и так далее ...... .
дубликат - http://stackoverflow.com/questions/33063251/login-attempt-with-duration – Vishal