0% found this document useful (0 votes)
11 views5 pages

Task 4

Andriod studio task 4

Uploaded by

chavhannaman2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views5 pages

Task 4

Andriod studio task 4

Uploaded by

chavhannaman2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

LoginActivity.

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;

public class LoginActivity extends AppCompatActivity {


EditText ETUserename, ETPassword;
Button BTLogin;

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

• <?xml version="1.0" encoding="utf-8"?>


<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LoginActivitymain"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".LoginActivity"
android:orientation="vertical"
android:background="@drawable/background">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo_of_app"
android:layout_gravity="center_horizontal"
android:layout_marginTop="45dp"
/>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/CVlogin"
app:cardCornerRadius="28sp"
app:cardBackgroundColor="#80FFFFFF"
app:cardElevation="16sp"
android:layout_marginTop="50dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/CVll"
android:layout_margin="8sp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="casual"
android:text="@string/login_here"
android:gravity="center_horizontal"
android:textColor="@color/Green"
android:textStyle="bold"
android:textSize="24dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/ETloginUsername"
android:hint="@string/enter_username"
android:textColorHint="@color/black"
android:textStyle="bold"
android:textSize="16sp"
android:inputType="text"
android:layout_margin="8sp"
android:background="@drawable/etshape"
android:paddingLeft="16sp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/ETloginpassword"
android:hint="@string/enter_password"
android:textColorHint="@color/black"
android:background="@drawable/etshape"
android:textStyle="bold"
android:textSize="16sp"
android:inputType="textPassword"
android:layout_margin="8sp"
android:paddingLeft="16sp"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show password"
android:checked="false"
android:textStyle="bold"
android:id="@+id/CBpassword"
android:textSize="16sp"/>
<androidx.appcompat.widget.AppCompatButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ButtonLogin"
android:text="@string/login"
android:background="@drawable/btshape"
android:layout_gravity="center"
android:textStyle="bold"
android:textSize="16sp"
android:textColor="@color/white"
android:fontFamily="monospace"
android:layout_marginTop="12sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/TVNewUser"
android:text="@string/new_user_login"
android:textSize="14sp"
android:textColor="@color/DarkBlue"
android:fontFamily="monospace"
android:textStyle="italic"
android:gravity="center"
android:layout_marginBottom="20sp"
android:layout_marginTop="12sp"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<TextView
android:id="@+id/TVSloganr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_marginBottom="20sp"
android:fontFamily="serif"
android:layout_gravity="right"
android:text="@string/good_food_great_mood"
android:textColor="@color/white"
android:textSize="28sp"
android:textStyle="italic" />
</LinearLayout>

• Output:-

You might also like