0% found this document useful (0 votes)
12 views26 pages

MAD Lab Short Program

The document outlines the development of various mobile applications using Android components, including GUI elements, event listeners, and database integration. Key applications include a simple input-output app, a calculator, an email sender, a graphics drawer, a database manager, a voice-to-text converter, an alert system for messages, and a Bluetooth-connected fitness tracker. Each application is accompanied by XML layout files and Java code demonstrating functionality.

Uploaded by

Jeevan Kishore
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)
12 views26 pages

MAD Lab Short Program

The document outlines the development of various mobile applications using Android components, including GUI elements, event listeners, and database integration. Key applications include a simple input-output app, a calculator, an email sender, a graphics drawer, a database manager, a voice-to-text converter, an alert system for messages, and a Bluetooth-connected fitness tracker. Each application is accompanied by XML layout files and Java code demonstrating functionality.

Uploaded by

Jeevan Kishore
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/ 26

1. Develop an application that uses GUI components, Font and Colors.

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

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:gravity="center"

android:background="#FFFDE7"

android:padding="20dp">

<EditText

android:id="@+id/nameInput"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Enter Name"

android:textColor="#000000"

android:textColorHint="#9E9E9E"

android:backgroundTint="#FF9800" />

<Button

android:id="@+id/btnShow"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Show"

android:textColor="#FFFFFF"

android:background="#FF5722"

android:layout_marginTop="16dp"/>

<TextView

android:id="@+id/outputText"
android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textSize="18sp"

android:textColor="#4CAF50"

android:layout_marginTop="20dp"/>

</LinearLayout>

package com.example.simpleapp;

import android.os.Bundle;

import android.view.View;

import android.widget.*;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

EditText nameInput;

TextView outputText;

Button btnShow;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

nameInput = findViewById(R.id.nameInput);

outputText = findViewById(R.id.outputText);

btnShow = findViewById(R.id.btnShow);

btnShow.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {


String name = nameInput.getText().toString();

outputText.setText("Welcome " + name + "!");

});

}
2. Develop an application that uses Layout Managers and event listeners

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

<RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:padding="24dp"

android:background="#E0F7FA">

<LinearLayout

android:id="@+id/inputLayout"

android:orientation="vertical"

android:layout_width="match_parent"

android:layout_height="wrap_content">

<EditText

android:id="@+id/num1"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Enter First Number"

android:inputType="number" />

<EditText

android:id="@+id/num2"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Enter Second Number"

android:inputType="number"

android:layout_marginTop="10dp"/>

</LinearLayout>
<Button

android:id="@+id/addButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Add"

android:layout_below="@id/inputLayout"

android:layout_marginTop="20dp"

android:layout_centerHorizontal="true"

android:background="#00796B"

android:textColor="#FFFFFF"/>

<TextView

android:id="@+id/resultText"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text=""

android:textSize="18sp"

android:textColor="#000000"

android:layout_below="@id/addButton"

android:layout_marginTop="20dp"

android:layout_centerHorizontal="true"/>

</RelativeLayout>

package com.example.layoutapp;

import android.os.Bundle;

import android.view.View;

import android.widget.*;

import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {

EditText num1, num2;

Button addButton;

TextView resultText;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

num1 = findViewById(R.id.num1);

num2 = findViewById(R.id.num2);

addButton = findViewById(R.id.addButton);

resultText = findViewById(R.id.resultText);

addButton.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

try {

int a = Integer.parseInt(num1.getText().toString());

int b = Integer.parseInt(num2.getText().toString());

int sum = a + b;

resultText.setText("Result: " + sum);

} catch (NumberFormatException e) {

resultText.setText("Please enter valid numbers.");

});

}
3. Develop a mobile application to send an email.

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

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:padding="20dp"

android:gravity="center"

android:background="#FFFDE7">

<EditText

android:id="@+id/emailInput"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Recipient Email"

android:inputType="textEmailAddress" />

<EditText

android:id="@+id/subjectInput"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Subject"

android:layout_marginTop="10dp"/>

<EditText

android:id="@+id/messageInput"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Message"
android:layout_marginTop="10dp"

android:minLines="5"

android:gravity="top"

android:inputType="textMultiLine" />

<Button

android:id="@+id/sendButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Send Email"

android:layout_marginTop="20dp"

android:background="#2196F3"

android:textColor="#FFFFFF"/>

</LinearLayout>

package com.example.sendemailapp;

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

import android.view.View;

import android.widget.*;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

EditText emailInput, subjectInput, messageInput;

Button sendButton;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

emailInput = findViewById(R.id.emailInput);

subjectInput = findViewById(R.id.subjectInput);

messageInput = findViewById(R.id.messageInput);

sendButton = findViewById(R.id.sendButton);

sendButton.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String email = emailInput.getText().toString();

String subject = subjectInput.getText().toString();

String message = messageInput.getText().toString();

Intent emailIntent = new Intent(Intent.ACTION_SENDTO);

emailIntent.setData(Uri.parse("mailto:" + email));

emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);

emailIntent.putExtra(Intent.EXTRA_TEXT, message);

try {

startActivity(Intent.createChooser(emailIntent, "Send email using..."));

} catch (Exception e) {

Toast.makeText(MainActivity.this, "No email app found", Toast.LENGTH_SHORT).show();

});

}
4. Write an application that draws basic graphical primitives on the screen.

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

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent">

<com.example.graphicsapp.MyCanvas

android:id="@+id/canvasView"

android:layout_width="match_parent"

android:layout_height="match_parent" />

</FrameLayout>

package com.example.graphicsapp;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

package com.example.graphicsapp;

import android.content.Context;

import android.graphics.*;
import android.util.AttributeSet;

import android.view.View;

public class MyCanvas extends View {

public MyCanvas(Context context, AttributeSet attrs) {

super(context, attrs);

@Override

protected void onDraw(Canvas canvas) {

super.onDraw(canvas);

Paint paint = new Paint();

// Draw a red line

paint.setColor(Color.RED);

paint.setStrokeWidth(8);

canvas.drawLine(100, 100, 500, 100, paint);

// Draw a green rectangle

paint.setColor(Color.GREEN);

paint.setStyle(Paint.Style.STROKE);

paint.setStrokeWidth(5);

canvas.drawRect(100, 150, 400, 300, paint);

// Draw a blue circle

paint.setColor(Color.BLUE);

paint.setStyle(Paint.Style.FILL);

canvas.drawCircle(250, 450, 70, paint);


// Draw black text

paint.setColor(Color.BLACK);

paint.setTextSize(40);

canvas.drawText("Basic Graphics", 130, 600, paint);

}
5. Develop an application that makes use of database

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical" android:layout_width="match_parent"

android:layout_height="match_parent" android:padding="16dp">

<EditText

android:id="@+id/name"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Enter Name"/>

<Button

android:id="@+id/save"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Save"/>

<TextView

android:id="@+id/output"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:paddingTop="10dp"/>

</LinearLayout>

package com.example.simpledb;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;
import android.widget.*;

import android.database.sqlite.*;

import android.database.Cursor;

import android.content.Context;

public class MainActivity extends Activity {

EditText name;

Button save;

TextView output;

DBHelper db;

@Override

protected void onCreate(Bundle b) {

super.onCreate(b);

setContentView(R.layout.activity_main);

name = findViewById(R.id.name);

save = findViewById(R.id.save);

output = findViewById(R.id.output);

db = new DBHelper(this);

save.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

db.addName(name.getText().toString());

output.setText(db.getAllNames());

});

// Inner DBHelper class


class DBHelper extends SQLiteOpenHelper {

public DBHelper(Context c) {

super(c, "mydb", null, 1);

public void onCreate(SQLiteDatabase db) {

db.execSQL("CREATE TABLE names(name TEXT)");

public void onUpgrade(SQLiteDatabase db, int oldV, int newV) {}

public void addName(String n) {

SQLiteDatabase db = getWritableDatabase();

db.execSQL("INSERT INTO names VALUES('" + n + "')");

public String getAllNames() {

SQLiteDatabase db = getReadableDatabase();

Cursor c = db.rawQuery("SELECT * FROM names", null);

StringBuilder s = new StringBuilder();

while (c.moveToNext())

s.append(c.getString(0)).append("\n");

return s.toString();

}
6. Develop a mobile Application "Voice-to-Text with External Audio Input Devices"

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent" android:layout_height="match_parent"

android:orientation="vertical" android:padding="20dp">

<Button android:id="@+id/speakBtn"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:text="Speak" />

<TextView android:id="@+id/resultText"

android:layout_width="match_parent" android:layout_height="wrap_content"

android:textSize="18sp" android:paddingTop="10dp" />

</LinearLayout>

package com.example.voicetotext;

import android.content.Intent;

import android.os.Bundle;

import android.speech.RecognizerIntent;

import android.widget.*;

import androidx.appcompat.app.AppCompatActivity;

import java.util.*;

public class MainActivity extends AppCompatActivity {

Button speakBtn;

TextView resultText;

protected void onCreate(Bundle b) {


super.onCreate(b);

setContentView(R.layout.activity_main);

speakBtn = findViewById(R.id.speakBtn);

resultText = findViewById(R.id.resultText);

speakBtn.setOnClickListener(v -> {

Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);

startActivityForResult(i, 1);

});

protected void onActivityResult(int r, int c, Intent data) {

super.onActivityResult(r, c, data);

if (r == 1 && c == RESULT_OK && data != null) {

ArrayList<String> res = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

resultText.setText(res.get(0));

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


7. Implement an application that creates an alert upon receiving a message

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent" android:layout_height="match_parent"

android:orientation="vertical" android:padding="20dp">

<Button android:id="@+id/sendBtn"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:text="Simulate Message" />

</LinearLayout>

package com.example.alertonmessage;

import android.content.*;

import android.os.Bundle;

import android.widget.Button;

import androidx.appcompat.app.AlertDialog;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

BroadcastReceiver receiver;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Button send = findViewById(R.id.sendBtn);


// BroadcastReceiver to receive the message

receiver = new BroadcastReceiver() {

public void onReceive(Context c, Intent i) {

String msg = i.getStringExtra("msg");

new AlertDialog.Builder(MainActivity.this)

.setTitle("Message Received")

.setMessage(msg)

.setPositiveButton("OK", null)

.show();

};

// Register the receiver

registerReceiver(receiver, new IntentFilter("MY_MESSAGE"));

// Send a fake message on button click

send.setOnClickListener(v -> {

Intent i = new Intent("MY_MESSAGE");

i.putExtra("msg", "Hello! You got a new message.");

sendBroadcast(i);

});

@Override

protected void onDestroy() {

super.onDestroy();

unregisterReceiver(receiver);

}
8. Develop a mobile app that connects to a wearable fitness tracker or a heart rate monitor
via Bluetooth

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent" android:layout_height="match_parent"

android:orientation="vertical" android:padding="20dp">

<Button android:id="@+id/connectBtn"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:text="Connect to Fitness Tracker" />

<TextView android:id="@+id/statusText"

android:layout_width="match_parent" android:layout_height="wrap_content"

android:textSize="18sp" android:paddingTop="10dp"/>

</LinearLayout>

package com.example.fitnessdemo;

import android.bluetooth.BluetoothAdapter;

import android.os.Bundle;

import android.widget.*;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

BluetoothAdapter btAdapter;

TextView statusText;

@Override
protected void onCreate(Bundle b) {

super.onCreate(b);

setContentView(R.layout.activity_main);

Button connectBtn = findViewById(R.id.connectBtn);

statusText = findViewById(R.id.statusText);

btAdapter = BluetoothAdapter.getDefaultAdapter();

connectBtn.setOnClickListener(v -> {

if (btAdapter != null && btAdapter.isEnabled()) {

statusText.setText("Connected to Fitness Tracker!");

} else {

statusText.setText("Please enable Bluetooth.");

});

AndroidManifest.xml

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


9. Design a mobile app to "Capturing and Processing Audio with External Microphones"

activity_main.xml

xml

Copy code

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent" android:layout_height="match_parent"

android:orientation="vertical" android:padding="20dp">

<Button android:id="@+id/recordBtn"

android:layout_width="match_parent" android:layout_height="wrap_content"

android:text="Start Recording" />

</LinearLayout>

MainActivity.java

java

Copy code

package com.example.audiorecord;

import android.Manifest;

import android.media.MediaRecorder;

import android.os.Bundle;

import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import androidx.core.app.ActivityCompat;

import java.io.IOException;

public class MainActivity extends AppCompatActivity {

MediaRecorder recorder;

boolean isRecording = false;


String filePath;

@Override

protected void onCreate(Bundle b) {

super.onCreate(b);

setContentView(R.layout.activity_main);

Button recordBtn = findViewById(R.id.recordBtn);

filePath = getExternalCacheDir().getAbsolutePath() + "/audio.3gp";

ActivityCompat.requestPermissions(this,

new String[]{Manifest.permission.RECORD_AUDIO,
Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);

recordBtn.setOnClickListener(v -> {

if (!isRecording) {

recorder = new MediaRecorder();

recorder.setAudioSource(MediaRecorder.AudioSource.MIC);

recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);

recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

recorder.setOutputFile(filePath);

try {

recorder.prepare();

recorder.start();

recordBtn.setText("Stop Recording");

isRecording = true;

} catch (IOException e) {

e.printStackTrace();

} else {
recorder.stop();

recorder.release();

recorder = null;

recordBtn.setText("Start Recording");

isRecording = false;

});

AndroidManifest.xml permissions:

xml

Copy code

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

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
10. . Electric Vehicle (EV) Charging Station Locator

activity_main.xml

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent" android:layout_height="match_parent"

android:orientation="vertical" android:gravity="center" android:padding="30dp">

<Button android:id="@+id/locateBtn"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:text="Find EV Charging Stations" />

</LinearLayout>

MainActivity.java

package com.example.evlocator;

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle b) {

super.onCreate(b);

setContentView(R.layout.activity_main);

Button locateBtn = findViewById(R.id.locateBtn);

locateBtn.setOnClickListener(v -> {
String query = "EV charging stations near me";

Uri gmmIntentUri = Uri.parse("geo:0,0?q=" + Uri.encode(query));

Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);

mapIntent.setPackage("com.google.android.apps.maps");

startActivity(mapIntent);

});

AndroidManifest.xml

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

You might also like