Tutorial 3 - Login Page

 



This is Sample Project Which you can improve UI design & Coding skills .

You need to Download and paste these files to your "res" folder.  

If you get any trouble. Please Contact me on WhatsApp!!

Download full Tutorial

activity_login

LoginActivity

<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".LoginActivity"
android:orientation="vertical"
>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/top_gradient" />

<TextView

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Covid Tracker"
android:textStyle="bold"
android:layout_marginTop="-40dp"
android:height="30dp"
android:fontFamily="sans-serif-smallcaps"
android:textAlignment="center"
android:textSize="25dp"
android:textColor="@color/white"
android:gravity="center_horizontal" />

<ScrollView

android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical">

<com.airbnb.lottie.LottieAnimationView
android:id="@+id/lottie"
android:layout_width="match_parent"
android:layout_height="300dp"
android:scaleType="fitCenter"
android:layout_marginTop="20dp"
android:elevation="2dp"
app:lottie_repeatMode="restart"
app:lottie_repeatCount="1000"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.25"
app:lottie_autoPlay="true"
app:lottie_rawRes="@raw/newlogin" />

<TextView
android:id="@+id/welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome To Login"
android:textAlignment="center"
android:fontFamily="@font/baloo"
android:textSize="35dp"
android:textStyle="bold"
android:layout_marginTop="5dp"
android:layout_gravity="center"/>


<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="@string/first_slide_desc"
android:gravity="center_horizontal" />

<EditText
android:id="@+id/email"
android:layout_width="350dp"
android:layout_height="45dp"
android:background="@drawable/input_style"
android:hint="Email"
android:drawableRight="@drawable/ic_email"
android:paddingRight="15dp"
android:layout_gravity="center"
android:inputType="textEmailAddress"
android:textColor="#0d6e6a"
android:textStyle="bold"
android:textSize="18dp"
android:layout_marginTop="30dp"
android:paddingLeft="20dp"
/>

<EditText
android:id="@+id/password"
android:layout_width="350dp"
android:layout_height="45dp"
android:background="@drawable/input_style"
android:hint="Password"
android:drawableRight="@drawable/ic_password"
android:layout_gravity="center"
android:textColor="#0d6e6a"
android:paddingRight="15dp"
android:textStyle="bold"
android:inputType="textPassword"
android:textSize="18dp"
android:layout_marginTop="10dp"
android:paddingLeft="20dp"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forget Password?"
android:textStyle="bold"
android:layout_gravity="end"
android:layout_marginTop="5dp"
android:layout_marginRight="21dp"/>

<Button
android:id="@+id/btn_login"
android:layout_width="350dp"
android:layout_height="50dp"
android:background="@drawable/button_style"
android:text="Login"
android:textSize="18dp"
android:textStyle="bold"
android:textColor="#FFF"
android:layout_gravity="center"
android:layout_marginTop="20dp"/>

<TextView
android:id="@+id/do_not_have_acc_btn"
android:layout_width="match_parent"
android:layout_height="22dp"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="Don't have an account? Register."
android:onClick="registerText"
android:textColor="#F78D46"
android:textStyle="bold"
/>

<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="invisible"
android:layout_marginTop="10dp"/>



</LinearLayout>


</ScrollView>

</LinearLayout>

package com.rrmchathura.myfirstapp;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.annotations.NotNull;

public class LoginActivity extends AppCompatActivity {

private EditText mEmail,mPassword;
private Button mLoginBtn;
private FirebaseAuth fAuth;
ProgressBar progressBar;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);

mEmail = findViewById(R.id.email);
mPassword = findViewById(R.id.password);
mLoginBtn = findViewById(R.id.btn_login);
progressBar = findViewById(R.id.progressBar);
fAuth = FirebaseAuth.getInstance();

mLoginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String email = mEmail.getText().toString().trim();
String password = mPassword.getText().toString().trim();

if (TextUtils.isEmpty(email)){
mEmail.setError("Email is Required");
return;

}
if (TextUtils.isEmpty(password)){
mPassword.setError("Password is Required");
return;
}
if (password.length() < 6){
mPassword.setError("Password Must be >= 6 Characters");
}

progressBar.setVisibility(View.VISIBLE);

//authenticate the user

fAuth.signInWithEmailAndPassword(email,password).
addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull @NotNull Task<AuthResult> task) {
if (task.isSuccessful()){
Toast.makeText(LoginActivity.this,
"Logged in Successfully",Toast.LENGTH_SHORT).show();
startActivity(new Intent(LoginActivity.this,HomeActivity.class));
}else {
Toast.makeText(LoginActivity.this,
"Error !" + task.getException().getMessage(),Toast.LENGTH_SHORT)
.show();
progressBar.setVisibility(View.GONE);

}
}
});
}
});


}

public void Logintext(View view) {
startActivity(new Intent(LoginActivity.this,RegisterActivity.class));
finish();
}

public void registerText(View view) {
startActivity(new Intent(LoginActivity.this,RegisterActivity.class));
finish();
}
}


Post a Comment

0 Comments

Youtube Channel Image
Coding With Chathura Subscribe To watch more Project Tutorials
Subscribe
Do you have any doubts? chat with us on WhatsApp
Hello, How can I help you? ...
Click me to start the chat...

Welcome to freesourcecodelk

X