Task 4
Task 4
java
package com.example.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatButton;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
TextView TVNewUser;
CheckBox CBSHow;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_login);
setTitle("Login Activity");
ETUserename = findViewById(R.id.ETloginUsername);
ETPassword = findViewById(R.id.ETloginpassword);
BTLogin = findViewById(R.id.ButtonLogin);
TVNewUser = findViewById(R.id.TVNewUser);
CBSHow = findViewById(R.id.CBpassword);
CBSHow.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean
b) {
if(CBSHow.isChecked())
{
ETPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance())
;
}
else
{
ETPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
}
});
BTLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(ETUserename.getText().toString().isEmpty())
{
ETUserename.setError("UserName is Required");
}
else if(ETPassword.getText().toString().isEmpty())
{
ETPassword.setError("Password is Required");
}
else if (ETUserename.getText().toString().length()<8)
{
ETUserename.setError("At least 8 Character is required ");
}
else if (ETPassword.getText().toString().length()<8)
{
ETPassword.setError("Password should 8 character long");
}
else if(!ETUserename.getText().toString().matches("^(?=.*[A-
Z]).+$"))
{
ETUserename.setError("one Uppercase is required");
}
else if(!ETUserename.getText().toString().matches("^(?=.*[a-
z]).+$"))
{
ETUserename.setError("one Lowercase is required");
}
else if(!ETUserename.getText().toString().matches("^(?=.*[0-
9]).+$"))
{
ETUserename.setError("one number is required");
}
else
if(!ETUserename.getText().toString().matches("^(?=.*[@,#,$,%,!]).+$"))
{
ETUserename.setError("one Special Symbol is required");
}
else
{
Toast.makeText(LoginActivity.this,"Login Done
Successfully",Toast.LENGTH_LONG).show();
}
}
});
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.LoginActivitymain),
(v, insets) -> {
Insets systemBars =
insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right,
systemBars.bottom);
return insets;
});
}
}
• Activity_Login.xml
• Output:-