0% found this document useful (0 votes)
13 views31 pages

Updated MAD LAB ALL Programs

MAD

Uploaded by

Santhosh Y M
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)
13 views31 pages

Updated MAD LAB ALL Programs

MAD

Uploaded by

Santhosh Y M
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/ 31

MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

1 Create an application to design a Digital Business Card. The card should have a company logo, the
company name, and information like the name of the employee, job title, phone number, address,
email, fax, GitHub Profile, LinkedIn Profile links and the website address. Design the application
by using different fonts, colours, and with professional UI design outlook.

Solution: XML file

<?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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"> Note: Text
Highlighted in Blue
<RelativeLayout – is to be written in
android:layout_width="match_parent" Test/Exam - Writeup
android:layout_height="167dp">

<TextView
android:id="@+id/textView"
android:layout_width="185dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="210dp"
android:layout_marginBottom="68dp"
android:text="Company Name"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#F61010"

© Santhosh Y M 1
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

android:textSize="24sp"
android:textStyle="italic" />

<ImageView
android:id="@+id/imageView"
android:layout_width="140dp"
android:layout_height="76dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="24dp"
android:layout_marginBottom="43dp"
app:srcCompat="@drawable/img" />
</RelativeLayout>

<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="@color/black" />

<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name"
android:textAlignment="center"
android:textColor="#673AB7"
android:textSize="34sp"
android:textStyle="italic" />

<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Job Title"
android:textAlignment="center"
android:textColor="#673AB7"
android:textSize="34sp"
android:textStyle="italic" />

<View
android:id="@+id/divider2"
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="@android:color/holo_green_dark"/>

<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Phone"

© Santhosh Y M 2
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

android:textAlignment="center"
android:textColor="#673AB7"
android:textSize="34sp"
android:textStyle="italic" />

<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Address"
android:textAlignment="center"
android:textColor="#673AB7"
android:textSize="34sp"
android:textStyle="italic" />

<TextView
android:id="@+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Email"
android:textAlignment="center"
android:textColor="#673AB7"
android:textSize="34sp"
android:textStyle="italic" />
</LinearLayout>

Java Code:
package com.example.mybussi;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

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

2 Develop an Android application using controls like Button, TextView, EditText for designing a
native calculator having basic functionality like Addition, Subtraction, Multiplication, and
Division. Also learn the different ways of handling button events.
Solution: XML Code:

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


<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android=http://schemas.android.com/apk/res/android

© Santhosh Y M 3
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="213dp"
android:layout_height="44dp"
android:text="Calculator"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#673AB7"
android:textSize="24sp"
android:textStyle="bold|italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.049" />

<EditText
android:id="@+id/editTextText"
android:layout_width="260dp"
android:layout_height="70dp"
android:layout_marginEnd="76dp"
android:layout_marginBottom="548dp"
android:ems="10"
android:hint="1st number"
android:inputType="text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

© Santhosh Y M 4
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

<EditText
android:id="@+id/editTextText2"
android:layout_width="252dp"
android:layout_height="63dp"
android:layout_marginEnd="84dp"
android:layout_marginBottom="456dp"
android:ems="10"
android:hint="2nd number"
android:inputType="text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="79dp"
android:layout_marginBottom="42dp"
android:onClick="toAdd"
android:text="+"
app:layout_constraintBottom_toTopOf="@+id/button3"
app:layout_constraintEnd_toStartOf="@+id/button2" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="84dp"
android:layout_marginBottom="35dp"
android:onClick="toSub"
android:text="_"
app:layout_constraintBottom_toTopOf="@+id/button4"
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="77dp"
android:layout_marginBottom="73dp"
android:onClick="toMul"
android:text="*"
app:layout_constraintBottom_toTopOf="@+id/textView"
app:layout_constraintEnd_toStartOf="@+id/button4" />

<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="81dp"
android:layout_marginBottom="78dp"
android:onClick="toDiv"

© Santhosh Y M 5
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

android:text="/"
app:layout_constraintBottom_toTopOf="@+id/textView"
app:layout_constraintEnd_toEndOf="parent" />

<TextView
android:id="@+id/textView"
android:layout_width="185dp"
android:layout_height="57dp"
android:layout_marginEnd="111dp"
android:layout_marginBottom="153dp"
android:text="Result"
android:textAlignment="center"
android:textColor="#C80B0B"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Java Code:

package com.example.cal890;

import android.annotation.SuppressLint;
import android.os.Bundle; Note: Write any 2
import android.view.View;
import Statements of
import android.widget.EditText;
your choice.
import android.widget.TextView;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {


EditText e1,e2;
TextView t1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this); Note: Text Highlighted
setContentView(R.layout.activity_main); in Green – is Auto
e1 = findViewById(R.id.editTextText); Generated Code in
e2 = findViewById(R.id.editTextText2); MainActivity.java and
t1 = findViewById(R.id.textView); Need to written in
} Test/Exam
public void toAdd(View view) {
int a1 = Integer.parseInt(e1.getText().toString());
int a2 = Integer.parseInt(e2.getText().toString());
int result = a1+a2;

© Santhosh Y M 6
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

t1.setText("" +result);
}
public void toSub(View view) {
int a1 = Integer.parseInt(e1.getText().toString());
int a2 = Integer.parseInt(e2.getText().toString());
int result = a1-a2;
t1.setText("" +result);
}
public void toMul(View view) {
int a1 = Integer.parseInt(e1.getText().toString());
int a2 = Integer.parseInt(e2.getText().toString());
int result = a1*a2;
t1.setText("" +result);
}
public void toDiv(View view) {
int a1 = Integer.parseInt(e1.getText().toString());
int a2 = Integer.parseInt(e2.getText().toString());
int result = a1/a2;
t1.setText("" +result);
}
}

3 Develop an application to set an image as wallpaper. On click of a button, the wallpaper image
should start to change randomly every 30 seconds.

Solution: XML Code:

<?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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

© Santhosh Y M 7
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

<TextView
android:layout_width="265dp"
android:layout_height="56dp"
android:text="WallPaper Change"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#EF1A1A"
android:textSize="24sp"
android:textStyle="bold|italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.443"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.224" />

</androidx.constraintlayout.widget.ConstraintLayout>

Java Code:
Note: Write any 2
package com.example.walpa123; import Statements of
import android.annotation.SuppressLint; your choice.
import android.app.WallpaperManager;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.Button;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.Insets; Note: Text
import androidx.core.view.ViewCompat; Highlighted in Green
import androidx.core.view.WindowInsetsCompat; – is Auto Generated
import java.io.IOException; Code in
import java.util.Timer; MainActivity.java
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity {


WallpaperManager wpm;
Timer mytimer;
Drawable dw;
int prev = 1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);

© Santhosh Y M 8
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

mytimer = new Timer();


wpm = WallpaperManager.getInstance(this);
setwallpaper();

ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main),
(v, insets) -> {
Insets systemBars =
insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top,
systemBars.right, systemBars.bottom);
return insets;
}); Note: Text
} Highlighted in Red –
not to be written in
private void setwallpaper() { Test/Exam - Writeup
mytimer.schedule(new TimerTask() {
@Override
public void run() {
if (prev==1) {
dw = getDrawable(R.drawable.img);
prev = 2;
} else if (prev==2) {
dw = getDrawable(R.drawable.img_1);
prev = 1;
}
Bitmap bitmap = ((BitmapDrawable)dw).getBitmap();
try {
wpm.setBitmap(bitmap);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}, 0, 30000);
}
}

4 Design an application for a simple alarm clock that includes features for setting a repeating
alarm and cancelling the alarm to stop it.

Solution: XML code

<?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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

© Santhosh Y M 9
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

<TextView
android:layout_width="145dp"
android:layout_height="43dp"
android:text="Alarm"
android:textAlignment="center"
android:textColor="#D51010"
android:textSize="24sp"
android:textStyle="bold|italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.023" />

<TimePicker
android:id="@+id/time"
android:layout_width="382dp"
android:layout_height="359dp"
android:layout_marginEnd="13dp"
android:layout_marginBottom="287dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/button"
android:layout_width="120dp"
android:layout_height="51dp"
android:layout_marginEnd="44dp"

© Santhosh Y M 10
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

android:layout_marginBottom="156dp"
android:text="Set Alarm"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/button2" />

<Button
android:id="@+id/button2"
android:layout_width="107dp"
android:layout_height="53dp"
android:layout_marginEnd="84dp"
android:layout_marginBottom="156dp"
android:text="Cancel"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Java Code:

package com.example.alarm00;

import android.annotation.SuppressLint;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TimePicker;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets; Note: Text
import androidx.core.view.ViewCompat; Highlighted in Green
import androidx.core.view.WindowInsetsCompat; – is Auto Generated
Code in
import java.util.Calendar; MainActivity.java

public class MainActivity extends AppCompatActivity implements


View.OnClickListener {
TimePicker tp;
Button b1,b2;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);

tp = findViewById(R.id.time);
tp.setIs24HourView(true);

© Santhosh Y M 11
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

b1 = findViewById(R.id.button);
b2 = findViewById(R.id.button2);
b1.setOnClickListener(this);
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.exit(0);
}
});

ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main),
(v, insets) -> {
Insets systemBars =
insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top,
systemBars.right, systemBars.bottom);
return insets;
}); Note: Text
} Highlighted in Red –
not to be written in
@Override Test/Exam - Writeup
public void onClick(View v) {
Calendar cal = Calendar.getInstance();

cal.set(cal.get(Calendar.YEAR),cal.get(Calendar.MONTH),cal.get(Cale
ndar.DAY_OF_MONTH),tp.getHour(),tp.getMinute());
Alarm_set(cal.getTimeInMillis());
}

private void Alarm_set(long timeInMillis) {


AlarmManager alarmManager = (AlarmManager)
getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this,Alarm.class);
PendingIntent pendingIntent =
PendingIntent.getBroadcast(this,0,intent,PendingIntent.FLAG_IMMUTAB
LE);

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,timeInMillis,Alar
mManager.INTERVAL_DAY,pendingIntent);
Toast.makeText(this, "alarm is set",
Toast.LENGTH_SHORT).show();
}
}

Alarm.java:
package com.example.alarm00;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;

© Santhosh Y M 12
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

import android.provider.Settings;
import android.widget.Toast;

public class Alarm extends BroadcastReceiver {


@Override
public void onReceive(Context context, Intent intent) {
MediaPlayer mp = MediaPlayer.create(context,
Settings.System.DEFAULT_ALARM_ALERT_URI);
mp.start();
Toast.makeText(context, "Wake-up",
Toast.LENGTH_SHORT).show();
}
}
Note: This code not to be
AndroidManifest.xml: written in Test/Exam –
Writeup.
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Alarm00"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<receiver android:name="com.example.alarm00.Alarm" />

</application>
</manifest>

© Santhosh Y M 13
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

Q5 Develop a simple application with one EditText so that the user can write some text in it.
Create a button called “Convert Text to Speech” that converts the user input text into voice.

XML Code:

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


<androidx.constraintlayout.widget.ConstraintLayout Note: Text
xmlns:android="http://schemas.android.com/apk/res/android" Highlighted in Blue
xmlns:app="http://schemas.android.com/apk/res-auto" – is to be written in
xmlns:tools="http://schemas.android.com/tools" Test/Exam - Writeup
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="286dp"
android:layout_height="49dp"
android:text="TEXT TO SPEECH"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#FB8C00"
android:textSize="34sp"
android:textStyle="normal|bold|italic"

© Santhosh Y M 14
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.456"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.134" />

<EditText
android:id="@+id/editTextText"
android:layout_width="274dp"
android:layout_height="74dp"
android:layout_marginEnd="68dp"
android:layout_marginBottom="428dp"
android:ems="10"
android:hint="Enter the Text"
android:inputType="text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/button"
android:layout_width="120dp"
android:layout_height="58dp"
android:layout_marginEnd="136dp"
android:layout_marginBottom="308dp"
android:text="Convert"
android:onClick="Convert"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

JAVA Code:

package com.example.tts;

import android.annotation.SuppressLint; Note: Write any 2


import android.os.Bundle; import Statements of
import android.speech.tts.TextToSpeech; your choice.
import android.view.View;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Locale;

© Santhosh Y M 15
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

public class MainActivity extends AppCompatActivity {


EditText input;
TextToSpeech tts;
Note: Text Highlighted
@SuppressLint("MissingInflatedId") in Green – is Auto
@Override Generated Code in
protected void onCreate(Bundle savedInstanceState) { MainActivity.java and
super.onCreate(savedInstanceState); Need to written in
setContentView(R.layout.activity_main); Test/Exam

input = findViewById(R.id.editTextText);
tts = new TextToSpeech(this, status -> {
if (status != TextToSpeech.ERROR) {
tts.setLanguage(Locale.UK);
}
});
}

public void Convert(View view) {


String text = input.getText().toString();
if (!text.isEmpty()) {
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null, null);
}
}
}

Q6 Design an application for SMS application using Intent. Design a simple layout which shows
a text called message in the top and followed by the header called mobile number and
an input field which allows the user to enter the mobile number to which the message has to
be sent. And also, a big input field where the user is going to write the text message and a
send button. A toast message that shows success/failure of SMS sending.

XML Code:

© Santhosh Y M 16
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

<?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" Note: Text
xmlns:tools="http://schemas.android.com/tools" Highlighted in Blue
android:layout_width="match_parent" – is to be written in
android:layout_height="match_parent" Test/Exam - Writeup
tools:context=".MainActivity">

<TextView
android:layout_width="130dp"
android:layout_height="35dp"
android:text="SMS APP"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#EA870B"
android:textSize="24sp"
android:textStyle="normal|bold|italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.119" />

<EditText
android:id="@+id/editTextTextMultiLine"
android:layout_width="299dp"
android:layout_height="131dp"
android:layout_marginEnd="48dp"
android:layout_marginBottom="420dp"
android:ems="10"
android:gravity="start|top"
android:hint="Type a Message"
android:inputType="textMultiLine"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<EditText
android:id="@+id/editTextText2"
android:layout_width="295dp"
android:layout_height="60dp"
android:layout_marginEnd="52dp"
android:layout_marginBottom="312dp"

© Santhosh Y M 17
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

android:ems="10"
android:hint="Enter the Ph No"
android:inputType="phone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="224dp"
android:layout_marginBottom="176dp"
android:text="Validate"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/button"
android:layout_width="102dp"
android:layout_height="50dp"
android:layout_marginEnd="68dp"
android:layout_marginBottom="176dp"
android:onClick="SENDSMS"
android:text="Send"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

JAVA Code:

package com.example.sms;
import android.annotation.SuppressLint;
import android.content.pm.PackageManager;
import android.os.Bundle; Note: Write any 2
import android.telephony.SmsManager; import Statements of
import android.widget.Button; your choice.
import android.widget.EditText;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.Manifest;

© Santhosh Y M 18
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

public class MainActivity extends AppCompatActivity {


@Override Note: Text Highlighted
protected void onCreate(Bundle savedInstanceState) { in Green – is Auto
Generated Code in
super.onCreate(savedInstanceState);
MainActivity.java and
EdgeToEdge.enable(this); Need to written in
setContentView(R.layout.activity_main); Test/Exam

EditText e1 = (EditText) findViewById(R.id.editTextText2);


EditText e2 = (EditText) findViewById(R.id.editTextTextMultiLine);

@SuppressLint({"MissingInflatedId", "LocalSuppress"})

Button btn = (Button) findViewById(R.id.button);

ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.SEND_SMS


}, PackageManager.PERMISSION_GRANTED);

btn.setOnClickListener(v -> {
SmsManager sm = SmsManager.getDefault();
sm.sendTextMessage(e1.getText().toString(), null, e2.getText().toString(),null,null);
Toast.makeText(MainActivity.this, "Message Sent", Toast.LENGTH_SHORT).show();
});
} Note: In this Program we are not
} Using the Validate Button In Java
Code.

ANDROID MANIFEST CODE:

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
Note: This code should not
be written in the test or
<uses-feature exam write-up, but it should
android:name="android.hardware.telephony" be added before running the
android:required="false"/> app.

<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"

android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.SMS"

© Santhosh Y M 19
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
</application>

</manifest>

Q7 Create an activity like a phone dialer with CALL and SAVE buttons. On pressing the CALL
button, it must call the phone number and on pressing the SAVE button it must save the
number to the phone contacts.

XML Code:

© Santhosh Y M 20
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

<?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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent" Note: Text
android:onClick="OnSave" Highlighted in Blue
– is to be written in
tools:context=".MainActivity">
Test/Exam - Writeup

<TextView
android:layout_width="197dp"
android:layout_height="39dp"
android:text="Call Save App"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#FB8C00"
android:textSize="24sp"
android:textStyle="normal|bold|italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.439"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.173" />

<EditText
android:id="@+id/editTextText"
android:layout_width="220dp"
android:layout_height="54dp"
android:layout_marginEnd="112dp"
android:layout_marginBottom="428dp"
android:ems="10"
android:hint="Phone Number"
android:inputType="phone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="260dp"

© Santhosh Y M 21
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

android:layout_marginBottom="316dp"
android:onClick="OnCall"
android:text="Call"
android:textColor="#FDD835"
android:textSize="20sp"
android:textStyle="normal|bold|italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="72dp"
android:layout_marginBottom="316dp"
android:onClick="OnSave"
android:text="Save"
android:textColor="#81F10A"
android:textSize="20sp"
android:textStyle="bold|italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="156dp"
android:layout_marginBottom="200dp"
android:onClick="OnClear"
android:text="Clear"
android:textColor="#ED0B0B"
android:textSize="20sp"
android:textStyle="normal|bold|italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

JAVA Code:

package com.example.callsave;
import android.annotation.SuppressLint;
import android.content.Intent;

© Santhosh Y M 22
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

import android.net.Uri;
import android.os.Bundle; Note: Write any 2
import android.provider.ContactsContract; import Statements of
import android.view.View; your choice.
import android.widget.EditText;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {


EditText e1;

@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);

e1 = findViewById(R.id.editTextText);

ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {


Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
} Note: Text
Highlighted in Red –
public void OnCall(View view) { not to be written in
String number = e1.getText().toString(); Test/Exam - Writeup
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + number));
startActivity(intent);
} Note: Text
public void OnSave(View view) { Highlighted in Blue
String number = e1.getText().toString(); – is to be written in
Intent intent = new Intent(Intent.ACTION_INSERT); Test/Exam - Writeup
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
intent.putExtra(ContactsContract.Intents.Insert.PHONE, number);
startActivity(intent);
}

© Santhosh Y M 23
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

public void OnClear(View view) {


e1.setText("");
}
}

Q8 Create a SIGN-Up activity with Username and Password. Validation of passwords should
happen based on the following rules:
● Password should contain uppercase and lowercase letters.
● Password should contain letters and numbers.
● Password should contain special characters.
● Minimum length of the password (the default value is 8).
On successful SIGN UP proceed to the next Login activity.
Here the user should SIGN IN using the Username and Password created during the signup
activity. If the Username and Password are matched then navigate to the next activity which
displays a message saying “Successful Login” or else displays a toast message saying “Login
Failed”. The user is given only two attempts and after that displays a toast message saying
“Failed Login Attempts” and disable the SIGN IN button. Use Bundle to transfer information
from one activity to another.

XML Code: (activity_main.xml)

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


<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" Note: Text
xmlns:app="http://schemas.android.com/apk/res-auto" Highlighted in Blue
xmlns:tools="http://schemas.android.com/tools" – is to be written in
android:id="@+id/main" Test/Exam - Writeup
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

© Santhosh Y M 24
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sign-Up"
android:textAlignment="center"
android:textColor="#9C27B0"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.425"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.165" />

<EditText
android:id="@+id/EmailidEditText"
android:layout_width="258dp"
android:layout_height="59dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="94dp"
android:layout_marginBottom="26dp"
android:height="48dp"
android:ems="10"
android:hint="Email ID"
android:inputType="textEmailAddress"
app:layout_constraintBottom_toTopOf="@+id/PasswordEditText"
app:layout_constraintEnd_toEndOf="parent" />

<EditText
android:id="@+id/PasswordEditText"
android:layout_width="262dp"
android:layout_height="72dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="88dp"
android:layout_marginBottom="41dp"
android:height="48dp"
android:ems="10"
android:hint="Pasword"
android:inputType="textPassword"
app:layout_constraintBottom_toTopOf="@+id/SignBtn"
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/SignBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"

© Santhosh Y M 25
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

android:layout_marginEnd="159dp"
android:layout_marginBottom="276dp"
android:text="Signup"
android:textSize="20sp"
android:textStyle="bold|italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Java Code: (MainActivity.java)

package com.example.signup;
Note: Write any 2
import Statements of
import android.os.Bundle;
your choice.
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import java.util.regex.Pattern;

public class MainActivity extends AppCompatActivity {


private EditText emailEditText, passwordEditText;
Note: Text Highlighted
private Button signUpBtn;
in Green – is Auto
Generated Code in
@Override MainActivity.java and
protected void onCreate(Bundle savedInstanceState) { Need to written in
super.onCreate(savedInstanceState); Test/Exam
setContentView(R.layout.activity_main);
emailEditText = findViewById(R.id.EmailidEditText);
passwordEditText = findViewById(R.id.PasswordEditText);
signUpBtn = findViewById(R.id.SignBtn);
signUpBtn.setOnClickListener(view -> {
String email = emailEditText.getText().toString();
String password = passwordEditText.getText().toString();
if (!isValidPassword(password)) {
Toast.makeText(MainActivity.this, "Password does not meet the requirements",
Toast.LENGTH_LONG).show();
return;
}

© Santhosh Y M 26
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

Intent intent = new Intent(MainActivity.this, MainActivity2.class);


intent.putExtra("email", email);
intent.putExtra("password", password);
Note: Text
startActivity(intent); Highlighted in Blue
}); – is to be written in
} Test/Exam - Writeup

private boolean isValidPassword(String password) {


return password.length() >= 8 &&
Pattern.compile("[a-z]").matcher(password).find() &&
Pattern.compile("[A-Z]").matcher(password).find() &&
Pattern.compile("[0-9]").matcher(password).find() &&
Pattern.compile("[^a-zA-Z0-9]").matcher(password).find();
}
}

XML Code: (activity_main2.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" Note: Text
xmlns:tools="http://schemas.android.com/tools" Highlighted in Blue
android:id="@+id/main" – is to be written in
android:layout_width="match_parent" Test/Exam - Writeup
android:layout_height="match_parent"
tools:context=".MainActivity2">

© Santhosh Y M 27
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

<TextView
android:id="@+id/textView"
android:layout_width="109dp"
android:layout_height="47dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="164dp"
android:layout_marginBottom="52dp"
android:text="Login"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#E42323"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/EmaileditText"
app:layout_constraintEnd_toEndOf="parent" />

<EditText
android:id="@+id/EmaileditText"
android:layout_width="252dp"
android:layout_height="74dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="80dp"
android:layout_marginBottom="36dp"
android:ems="10"
android:hint="Email ID"
android:inputType="textEmailAddress"
app:layout_constraintBottom_toTopOf="@+id/passwoededit"
app:layout_constraintEnd_toEndOf="parent" />

<EditText
android:id="@+id/passwoededit"
android:layout_width="253dp"
android:layout_height="74dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="80dp"
android:layout_marginBottom="64dp"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
app:layout_constraintBottom_toTopOf="@+id/loginBtn"
app:layout_constraintEnd_toEndOf="parent" />

© Santhosh Y M 28
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

<Button
android:id="@+id/loginBtn"
android:layout_width="155dp"
android:layout_height="64dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="128dp"
android:layout_marginBottom="212dp"
android:text="Login"
android:textSize="24sp"
android:textStyle="bold|italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Java Code: (MainActivity2.java)

package com.example.signup;

import android.os.Bundle; Note: Write any 2


import android.content.Intent; import Statements of
import android.view.View; your choice.
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity2 extends AppCompatActivity {


private EditText emailEditText, passwordEditText;
private Button loginBtn;
private int counter = 2;
private String registeredEmail, registeredPassword; Note: Text Highlighted
in Green – is Auto
@Override Generated Code in
protected void onCreate(Bundle savedInstanceState) { MainActivity.java and
Need to written in
super.onCreate(savedInstanceState);
Test/Exam
setContentView(R.layout.activity_main2);

emailEditText = findViewById(R.id.EmaileditText);
passwordEditText = findViewById(R.id.passwoededit); Note: Text
loginBtn = findViewById(R.id.loginBtn); Highlighted in Blue
registeredEmail = getIntent().getStringExtra("email"); – is to be written in
Test/Exam - Writeup
registeredPassword = getIntent().getStringExtra("password");

© Santhosh Y M 29
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

loginBtn.setOnClickListener(view -> attemptLogin());


}

private void attemptLogin() {


String email = emailEditText.getText().toString();
String password = passwordEditText.getText().toString();
if (email.equals(registeredEmail) && password.equals(registeredPassword)) {
startActivity(new Intent(MainActivity2.this, MainActivity3.class));

} else {
Toast.makeText(this, "Invalid Credentials", Toast.LENGTH_LONG).show();
if (--counter == 0) {
Toast.makeText(this, "FAILED LOGIN ATTEMPTS",
Toast.LENGTH_LONG).show();
loginBtn.setEnabled(false);
}
}
}
}

XML Code: (activity_main3.xml)

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


Note: Text
<androidx.constraintlayout.widget.ConstraintLayout
Highlighted in Blue
xmlns:android="http://schemas.android.com/apk/res/android" – is to be written in
xmlns:app="http://schemas.android.com/apk/res-auto" Test/Exam - Writeup
xmlns:tools="http://schemas.android.com/tools"

© Santhosh Y M 30
MOBLIE APPLICATION DEVELOPMENT LABORATORY – 21CSL69C Date: 04/08/2024

android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity3">

<TextView
android:id="@+id/textView2"
android:layout_width="284dp"
android:layout_height="83dp"
android:layout_marginEnd="48dp"
android:layout_marginBottom="372dp"
android:text="Login sucessful"
android:textColor="#0CCD13"
android:textSize="34sp"
android:textStyle="bold|italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Java Code: (MainActivity3.java)

package com.example.signup;
Note: Write any 2
import android.os.Bundle; import Statements of
your choice.
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity3 extends AppCompatActivity {

Note: Text Highlighted


@Override
in Green – is Auto
Generated Code in
protected void onCreate(Bundle savedInstanceState) { MainActivity.java and
super.onCreate(savedInstanceState); Need to written in
EdgeToEdge.enable(this); Test/Exam
setContentView(R.layout.activity_main3);
}
}

© Santhosh Y M 31

You might also like