20BCG1088 MAP Experiment 4

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Mobile Application Programming - LAB

Experiment-4

Student Name: Kriti Jain Semester: 5

UID: 20BCG1088 Branch: CSE - G&G

Section/Group: 20BCG/B

Date of Performance: 10-09-2022

Subject Name: Mobile Application Programming-LAB

Subject Code: 20CSG-331_20BCG-1_B


Problem:

Create and Login application as above. On successful login, open the


browser with any URL.

Algorithm:

Step 1: Design

1. Open the actual Project folder(app) in Android Studio IDE /


Eclipse IDE

2. Click res directory -> layout -> activity_main.xml -> Design

3. Add Two EditText and one button to make it center of the


screen.

4. Enter the corresponding ids for each component.

5. Layout(UI)
PROGRAM CODE:

MainActivity.java Code

1. package com.example.experiment4_kriti_jain;
2.
3. import androidx.appcompat.app.AppCompatActivity;
4. import android.content.Intent;
5. import android.net.Uri;
6. import android.os.Bundle;
7. import android.view.View;
8. import android.widget.Button;
9. import android.widget.EditText;
10. import android.widget.Toast;
11. public class MainActivity extends AppCompatActivity {
12. String user = "20BCG1088", pass = "1088";
13. EditText username, password;
14. Button button;
15. @Override
16. protected void onCreate(Bundle savedInstanceState) {
17. super.onCreate(savedInstanceState);
18. setContentView(R.layout.activity_main);
19. username = findViewById(R.id.username);
20. password = findViewById(R.id.passwd);
21. button = findViewById(R.id.login);
22. button.setOnClickListener(new View.OnClickListener() {
23.
24. @Override public void onClick(View view) {
25. if(username.getText().toString().isEmpty()){
26. Toast.makeText(MainActivity.this, "Enter the Username",
Toast.LENGTH_LONG);
27. }else if(password.getText().toString().isEmpty()){
28. Toast.makeText(MainActivity.this, "Enter the Password",
Toast.LENGTH_LONG);
29. }else{
30. if(username.getText().toString().equals(user) &&
password.getText().toString().equals(pass)) {
31. String url = "https://thispersondoesnotexist.com";
32. Intent i = new Intent(Intent.ACTION_VIEW);
33. i.setData(Uri.parse(url));
34. startActivity(i);}
35. else{
36. Toast.makeText(MainActivity.this, "Invalid username or
password.", Toast.LENGTH_LONG); }}}});}}

XML CODE
1. <?xml version="1.0" encoding="utf-8"?>
2. <androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
3. xmlns:app="http://schemas.android.com/apk/res-auto"
4. xmlns:tools="http://schemas.android.com/tools"
5. android:id="@+id/relativeLayout"
6. android:layout_width="match_parent"
7. android:layout_height="match_parent">
8. <EditText
9. android:id="@+id/username"
10. android:layout_width="262dp"
11. android:layout_height="71dp"
12. android:autofillHints=""
13. android:ems="10"
14. android:hint="Enter Username"
15. android:inputType="textPersonName"
16. app:layout_constraintBottom_toTopOf="@+id/passwd"
17. app:layout_constraintEnd_toEndOf="parent"
18. app:layout_constraintHorizontal_bias="0.503"
19. app:layout_constraintStart_toStartOf="parent"
20. app:layout_constraintTop_toTopOf="parent"
21. app:layout_constraintVertical_bias="0.813" />
22. <EditText
23. android:id="@+id/passwd"
24. android:layout_width="261dp"
25. android:layout_height="60dp"
26. android:autofillHints=""
27. android:ems="10"
28. android:hint="Enter Password"
29. android:inputType="textPassword"
30. app:layout_constraintBottom_toBottomOf="parent"
31. app:layout_constraintEnd_toEndOf="parent"
32. app:layout_constraintHorizontal_bias="0.506"
33. app:layout_constraintStart_toStartOf="parent"
34. app:layout_constraintTop_toTopOf="parent"
35. app:layout_constraintVertical_bias="0.427" />
36. <Button
37. android:id="@+id/login"
38. android:layout_width="wrap_content"
39. android:layout_height="wrap_content"
40. android:text="@string/login"
41. app:layout_constraintBottom_toBottomOf="parent"
42. app:layout_constraintEnd_toEndOf="parent"
43. app:layout_constraintHorizontal_bias="0.498"
44. app:layout_constraintStart_toStartOf="parent"
45. app:layout_constraintTop_toBottomOf="@+id/passwd"
46. app:layout_constraintVertical_bias="0.117" />
47.
48. </androidx.constraintlayout.widget.ConstraintLayout>
49.
OUTPUTS:

IDE Screen:
App Screenshots:

When correct credentials are entered, the login button redirects to a


specific url.
https://thispersondoesnotexist.com/
Evaluation Grid (To be created as per the SOP and Assessment
guidelines by the faculty):

Sr. No. Parameters Marks Obtained Maximum Marks

1.

2.

3.

Learning Outcomes:

● Understood the usage of Uri library


● Understood the usage of OnClickListener in Android Programming
● Learned how to redirect a button to a webpage.

You might also like