0% found this document useful (0 votes)
7 views

exp 28

The document outlines the implementation of a login form for an Android application, including necessary validations for username and password fields, as well as handling unsuccessful login attempts. It provides XML layouts for the main activity and a second activity, along with Java code for the login logic and user feedback through toast messages. The application structure is defined in the AndroidManifest.xml and includes string resources for UI text elements.

Uploaded by

dondanaitik
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)
7 views

exp 28

The document outlines the implementation of a login form for an Android application, including necessary validations for username and password fields, as well as handling unsuccessful login attempts. It provides XML layouts for the main activity and a second activity, along with Java code for the login logic and user feedback through toast messages. The application structure is defined in the AndroidManifest.xml and includes string resources for UI text elements.

Uploaded by

dondanaitik
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/ 7

MAD Experiment 28

1. Write a program to the login form with necessary validations like length of username
& password, empty text fields, count of unsuccessful login attempts. Display the login
Successful / Unsuccessful toast message.

AndroidMainfest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.exp_28">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Exp_28">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity2"/>
</application>
</manifest>

Strings.xml

resources>
<string name="app_name">Exp_28</string>
<string name="login">LOG IN</string>
<string name="login_title">Log in to Snapchat</string>
<string name="login_form_username">Username</string>
<string name="login_form_password">Password</string>
<string name="welcome">Welcome to Snapchat</string>
</resources>

rounded_login_button.xml:

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


<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<shape android:shape="rectangle">
<stroke
android:color="@color/colorBlue"
android:width="1dp"/>
<solid
android:color="@color/colorBlue"/>
<corners android:radius="24dp" />
</shape>
</item>
<item android:state_pressed="true">
<shape android:shape="rectangle">
<stroke
android:color="@color/colorBlueDark"
android:width="1dp"/>
<solid
android:color="@color/colorBlueDark"/>
<corners android:radius="24dp" />
</shape>
</item>
</selector>

activity_main.xml:

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


<RelativeLayout 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:orientation="vertical"
android:background="@color/colorPrimary"
tools:context=".MainActivity">
<ImageView
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_marginTop="70dp"
android:src="@drawable/snapchat"
android:layout_centerHorizontal="true"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="150dp">
<androidx.cardview.widget.CardView
android:layout_margin="64dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="8dp"
app:cardCornerRadius="15dp"
app:cardMaxElevation="12dp"
android:background="#fff">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="24dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/login_title"
android:textAlignment="center"
android:textColor="@color/colorBlack"
android:textSize="25sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="@string/login_form_username"
android:textSize="20sp" />
<EditText
android:id="@+id/e1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:hint="Enter Usename"
android:inputType="text" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/login_form_password"
android:textSize="20sp" />
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true">
<EditText
android:id="@+id/e2"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="Enter Password"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/activity_main_loginButton"
android:layout_width="200dp"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:onClick="login"
android:background="@drawable/rounded_login_button"
android:text="@string/login"
android:textColor="@color/colorWhite"
android:layout_marginTop="20dp"
android:textSize="18sp"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</RelativeLayout>

MainActivity.java:

package com.example.exp_27;
import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity2 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.package com.example.exp_28;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private int count=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void login(View view) {
TextView uid = (TextView)findViewById(R.id.e1);
TextView upass = (TextView)findViewById(R.id.e2);
if(TextUtils.isEmpty(uid.getText().toString()))
{
uid.setError("Enter UserName");
}
if(TextUtils.isEmpty(upass.getText().toString()))
{
upass.setError("Enter Password");
}
if
(TextUtils.isEmpty(uid.getText().toString())||TextUtils.isEmpty(upass.getText().to
String())) {
count+=1;
Toast.makeText(MainActivity.this, "Login Unsuccessful \n Attempt:
"+count,Toast.LENGTH_SHORT).show();
}
else
{
Intent i1 = new Intent(MainActivity.this, MainActivity2.class);
i1.putExtra("id", uid.getText().toString());
startActivity(i1);
Toast.makeText(MainActivity.this, "Login Successful",
Toast.LENGTH_SHORT).show();
}
}
}onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
TextView t3 = (TextView)findViewById(R.id.t3);
Bundle b = getIntent().getExtras();
String data_receive= b.getString("id");
t3.setText("Hi "+data_receive.toUpperCase());
}
}

activity_main2.xml:

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


<RelativeLayout 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/colorPrimary"
tools:context=".MainActivity2">
<ImageView
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_marginTop="70dp"
android:src="@drawable/snapchat"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/welcome"
android:layout_marginTop="200dp"
android:layout_centerHorizontal="true"
android:textSize="30sp"
android:textColor="@color/colorBlack"
android:textStyle="bold"/>
<TextView
android:id="@+id/t3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="300dp"
android:layout_centerHorizontal="true"
android:textSize="30sp"
android:textColor="@color/colorBlack"
android:textStyle="bold"/>
</RelativeLayout>

MainActivity2.java:

package com.example.exp_28;
import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity2 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
TextView t3 = (TextView)findViewById(R.id.t3);
Bundle b = getIntent().getExtras();
String data_receive= b.getString("id");
t3.setText("Hi "+data_receive.toUpperCase());
}
}
Output:

You might also like