You are on page 1of 14

ANDROID STUDIO LAB ASSIGNMENT

SUBMITTED BY: SAJAL KUMAR MAITY

STUDENT ID: 211001271120

DEPT: MCA2B

SEM: 4TH
XML CODES:
activity_login.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
android:background="@color/_light_green"
android:backgroundTint="#AAF9CB"
tools:context=".Login">

<Button
android:id="@+id/Login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="76dp"
android:layout_marginEnd="72dp"
android:text="login"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.641"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/Log_Password" />

<TextView
android:id="@+id/textView2"
android:layout_width="119dp"
android:layout_height="44dp"
android:text="Login"
app:layout_constraintBottom_toTopOf="@+id/UserName2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.5"
tools:ignore="MissingConstraints" />

<EditText
android:id="@+id/Log_Password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/UserName2" />

<EditText
android:id="@+id/UserName2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="212dp"
android:ems="10"
android:hint="User Name"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />

</androidx.constraintlayout.widget.ConstraintLayout>
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
android:background="#CDFFFFFF"
android:backgroundTint="#AAF9CB"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView1"
android:layout_width="134dp"
android:layout_height="44dp"
android:text="Register Yourself"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.487"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.119" />

<EditText
android:id="@+id/Username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="52dp"
android:ems="10"
android:hint="Username"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="@+id/textView1"
app:layout_constraintTop_toBottomOf="@+id/textView1"
tools:ignore="MissingConstraints" />

<EditText
android:id="@+id/Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:ems="10"
android:hint="Full Name"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="@+id/Username"
app:layout_constraintTop_toBottomOf="@+id/Username"
tools:ignore="MissingConstraints" />

<EditText
android:id="@+id/EmailAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
android:ems="10"
android:hint="Email"
android:inputType="textEmailAddress"
app:layout_constraintEnd_toEndOf="@+id/Name"
app:layout_constraintTop_toBottomOf="@+id/Name"
tools:ignore="MissingConstraints" />

<EditText
android:id="@+id/Phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:ems="10"
android:hint="Contact No"
android:inputType="phone"
app:layout_constraintEnd_toEndOf="@+id/EmailAddress"
app:layout_constraintTop_toBottomOf="@+id/EmailAddress"
tools:ignore="MissingConstraints" />

<EditText
android:id="@+id/Password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="@+id/Phone"
app:layout_constraintTop_toBottomOf="@+id/Phone"
tools:ignore="MissingConstraints" />

<EditText
android:id="@+id/Conf_Password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="Confirm Password"
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="@+id/Password"
app:layout_constraintTop_toBottomOf="@+id/Password"
tools:ignore="MissingConstraints" />

<Button
android:id="@+id/button"
android:layout_width="137dp"
android:layout_height="52dp"
android:layout_marginTop="32dp"
android:background="@color/sea_green"
android:backgroundTint="@color/_light_green"
android:text="Register"
app:layout_constraintEnd_toEndOf="@+id/Conf_Password"
app:layout_constraintTop_toBottomOf="@+id/Conf_Password"
app:strokeColor="#C62828" />

</androidx.constraintlayout.widget.ConstraintLayout>

activity_edit_profile.xml:

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


<androidx.constraintlayout.widget.ConstraintLayout
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"
android:background="@color/_light_green"
tools:context=".EditProfile">

<TextView
android:id="@+id/editProfileTextview"
android:layout_width="188dp"
android:layout_height="31dp"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="111dp"
tools:layout_editor_absoluteY="80dp" />

<EditText
android:id="@+id/editText_Full_Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="36dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="@+id/editProfileTextview"

app:layout_constraintStart_toStartOf="@+id/editProfileTextview"

app:layout_constraintTop_toBottomOf="@+id/editProfileTextview" />

<EditText
android:id="@+id/editTText_Email_Address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:ems="10"
android:inputType="textEmailAddress"
app:layout_constraintEnd_toEndOf="@+id/editText_Full_Name"

app:layout_constraintStart_toStartOf="@+id/editText_Full_Name"
app:layout_constraintTop_toBottomOf="@+id/editText_Full_Name"
/>

<Button
android:id="@+id/buttonUpdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/brown"
android:text="Update"
tools:layout_editor_absoluteX="167dp"
tools:layout_editor_absoluteY="294dp" />

Java Code:

EditProfile.java
package com.example.aattisho;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;

public class EditProfile extends AppCompatActivity {

TextView uname3;
EditText name;
EditText email;
Button edit;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_profile);

Bundle bd=getIntent().getExtras();
String uname2=bd.getString("uname1");
String pwd4=bd.getString("pwd3");

uname3=(TextView) findViewById(R.id.editProfileTextview);
uname3.setText(uname2);
// Toast.makeText(getApplicationContext(), " Password is
"+pwd4, Toast.LENGTH_LONG).show();
UserDbHelper udb=new UserDbHelper(EditProfile.this);
ArrayList<String> al=udb.getUserDetail(uname2,pwd4);

name=(EditText) findViewById(R.id.editText_Full_Name);
email=(EditText) findViewById(R.id.editTText_Email_Address);

name.setText(al.get(1));
email.setText(al.get(2));
edit=(Button) findViewById(R.id.buttonUpdate);
edit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String name_text=name.getText().toString();
String email_text=email.getText().toString();
boolean
b=udb.update_user(uname2,pwd4,email_text,name_text);
if(b==true)
{
Toast.makeText(EditProfile.this, "Successfully
updated", Toast.LENGTH_LONG).show();
Intent intent=new
Intent(EditProfile.this,Profile.class);
startActivity(intent);
}else
{
Toast.makeText(EditProfile.this, "not
updated",Toast.LENGTH_LONG).show();
}
}
});

}
}

Login.java:

package com.example.aattisho;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import java.util.ArrayList;
public class Login extends AppCompatActivity {

Button signin = null;


String username_text=null;
String pwd_text=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);

signin= (Button) findViewById(R.id.Login);

signin.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
username_text=((EditText)
findViewById(R.id.UserName2)).getText().toString();
pwd_text=((EditText)
findViewById(R.id.Log_Password)).getText().toString();
UserDbHelper udb=new UserDbHelper(Login.this);
ArrayList<String>
al=udb.getUserDetail(username_text,pwd_text);
//Toast.makeText(getApplicationContext(), " Username
is " + username_text+" Password is "+pwd_text,
Toast.LENGTH_LONG).show();

if (al!=null)
{
Intent intent= new Intent(Login.this,
Profile.class);
intent.putExtra("pwd1",pwd_text);
intent.putExtra("al1",al);
startActivity(intent);
}

}
});
}
}

MainActivity.java:

package com.example.aattisho;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


Button reg=null;
EditText username=null;
EditText full_name=null;
EditText email=null;
EditText contact_no=null;
EditText pwd=null;
EditText cnf_pwd=null;

String username_txt=null;
String full_name_txt=null;
String email_txt=null;
String contact_no_txt=null;
String pwd_txt=null;
String cnf_pwd_txt=null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
reg= (Button) findViewById(R.id.button);
reg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
username=(EditText) findViewById(R.id.Username);
full_name=(EditText)findViewById(R.id.Name);
email=(EditText)findViewById(R.id.EmailAddress);
contact_no=(EditText)findViewById(R.id.Phone);
pwd=(EditText)findViewById(R.id.Password);
cnf_pwd=(EditText)findViewById(R.id.Conf_Password);

username_txt =username.getText().toString();
full_name_txt =full_name.getText().toString();
email_txt =email.getText().toString();
contact_no_txt =contact_no.getText().toString();
pwd_txt =pwd.getText().toString();
cnf_pwd_txt =cnf_pwd.getText().toString();
UserDbHelper udb=new UserDbHelper(MainActivity.this);
boolean
b=udb.add_user(username_txt,full_name_txt,email_txt,contact_no_txt,p
wd_txt,cnf_pwd_txt);
if(b==true) {
Toast.makeText(getApplicationContext(), "You have
successfully registered. You username is " + username_txt,
Toast.LENGTH_LONG).show();
startActivity(new Intent(MainActivity.this,
Login.class));
}
}
});

}
}

Profile.java:

package com.example.aattisho;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.ArrayList;

public class Profile extends AppCompatActivity {


TextView uname;
TextView fullname;
TextView email;
Button edit;

@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
Bundle bd=getIntent().getExtras();
String pwd2=bd.getString("pwd1");;

ArrayList<String> al2=bd.getStringArrayList("al1");

// Toast.makeText(getApplicationContext(), " Password is


"+pwd2, Toast.LENGTH_LONG).show();
TextView uname=(TextView) findViewById(R.id.u_name);
TextView fullname=(TextView) findViewById(R.id.name1);
TextView email=(TextView) findViewById(R.id.email1);

uname.setText(al2.get(0));
fullname.setText(al2.get(1));
email.setText(al2.get(2));

edit=(Button) findViewById(R.id.buttunEdit);

edit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent= new Intent(Profile.this,
EditProfile.class);
intent.putExtra("uname1",uname.getText().toString());
intent.putExtra("pwd3",pwd2);
startActivity(intent);
}
});
}
}

You might also like