exp 28
exp 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:
activity_main.xml:
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:
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: