- 1ST MAD LAB JAVA CODE
package com.example.lab1;
import android.os.;
import android.view.;
import android.widget.;
import androidx.appcompat.app.;
import androidx.core.content.;
import java.util.;
public class MainActivity extends AppCompatActivity {
int[] imgs = {R.drawable.a, R.drawable.b, R.drawable.c};
Timer t = new Timer();
@Override
protected void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.activity_main);
Button btn = findViewById(R.id.button1);
View w = findViewById(R.id.wallView);
btn.setOnClickListener(v -> {
t.scheduleAtFixedRate(new TimerTask() {
Random r = new Random();
public void run() {
int i = r.nextInt(imgs.length);
runOnUiThread(() ->
w.setBackground(
ContextCompat.getDrawable(getApplicationContext(), imgs[i])
));
}
}, 0, 3000);
});
}
}
1ST XML FILE
<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="@drawable/a" android:id="@+id/wallView" tools:context="MainActivity">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="CHANGING WALLPAPER APPLICATION" android:layout_marginTop="50sp" android:textSize="20sp" android:textStyle="bold" android:background="@color/black" android:textColor="@color/white" android:layout_centerHorizontal="true" android:id="@+id/text1"/>
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="350sp" android:layout_centerHorizontal="true" android:layout_centerInParent="true" android:text="CLICK HERE TO CHANGE WALLPAPER" android:textSize="25sp" android:background="@color/black" android:layout_marginLeft="50sp" android:layout_marginRight="50sp" android:id="@+id/button1"/>
</RelativeLayout>
2ND MAD LAB JAVA CODE
package com.example.hello;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
TextView a;
boolean b;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle c) {
super.onCreate(c);
setContentView(R.layout.activity_main);
a = findViewById(R.id.counter);
findViewById(R.id.startbtn).setOnClickListener(v -> {
b = true;
new Thread(() -> {
int d = 0;
while (b) {
int e = d++;
a.post(() -> a.setText(String.valueOf(e)));
try {
Thread.sleep(500);
} catch (InterruptedException ignored) {}
}
}).start();
});
findViewById(R.id.stopbtn).setOnClickListener(v -> b = false);
}
}
2ND 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:layout_width="match_parent" android:layout_height="match_parent" tools:context="MainActivity" android:orientation="vertical" android:background="#0C0A10">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Counter Application" android:textAllCaps="true" android:layout_marginLeft="40dp" android:layout_marginTop="50dp" android:layout_marginBottom="40dp" android:textSize="30dp" android:textColor="#109AD9" />
<TextView android:id="@+id/counter" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Counter Value" android:layout_marginLeft="120dp" android:layout_marginTop="50dp" android:layout_marginBottom="40dp" android:textSize="30dp" android:textColor="#B507E0" />
<Button android:id="@+id/startbtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="START" android:layout_marginLeft="145dp" android:layout_marginTop="20dp" android:layout_marginBottom="40dp" android:textSize="30dp" android:textColor="#0B0A0D" android:background="#EDB308" android:padding="10dp"/>
<Button android:id="@+id/stopbtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="STOP" android:layout_marginLeft="150dp" android:layout_marginTop="20dp" android:layout_marginBottom="40dp" android:textSize="30dp" android:textColor="#0B0A0D" android:background="#EDB308" android:padding="10dp"/>
</LinearLayout>
3 MAD PROGRAM JAVA CODE
package com.example.lab3;
import android.os.;
import android.speech.tts.;
import android.widget.;
import androidx.appcompat.app.;
import java.util.*;
public class MainActivity extends AppCompatActivity {
EditText t;
Button b;
TextToSpeech s;
@Override
protected void onCreate(Bundle c) {
super.onCreate(c);
setContentView(R.layout.activity_main);
t = findViewById(R.id.editText);
b = findViewById(R.id.btnSpeak);
s = new TextToSpeech(getApplicationContext(), set -> {
s.setLanguage(Locale.US);
});
b.setOnClickListener(v -> {
String x = t.getText().toString();
s.speak(x, TextToSpeech.QUEUE_FLUSH, null, null);
});
}
}
3RD XML FILE
<?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:padding="16dp" android:gravity="center" android:orientation="vertical">
<EditText android:id="@+id/editText" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="48dp" android:padding="12dp" android:hint="Enter text here" android:textSize="18sp"/>
<Button android:id="@+id/btnSpeak" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Convert Text to Speech" android:layout_marginTop="20dp"/>
</LinearLayout>
4)LOGIN / SIGNUP APP
MainActivity.java
package com.example.labbb4;
import android.content.;
import android.os.;
import android.widget.;
import androidx.appcompat.app.;
public class MainActivity extends AppCompatActivity {
EditText u, p;
Button up, in;
String su = "", sp = "";
@Override
protected void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.activity_main);
u = findViewById(R.id.etUsername);
p = findViewById(R.id.etPassword);
up = findViewById(R.id.btnSignUp);
in = findViewById(R.id.btnSignIn);
up.setOnClickListener(v -> {
String un = u.getText().toString();
String pw = p.getText().toString();
if (pwCheck(pw)) {
su = un;
sp = pw;
Toast.makeText(this, "Sign Up Successful!", Toast.LENGTH_SHORT).show();
u.setText("");
p.setText("");
}
});
in.setOnClickListener(v -> {
String un = u.getText().toString();
String pw = p.getText().toString();
if (un.equals(su) && pw.equals(sp)) {
Toast.makeText(this, "Successful Login", Toast.LENGTH_SHORT).show();
startActivity(new Intent(this, NextActivity.class));
finish();
} else {
Toast.makeText(this, "Login Failed", Toast.LENGTH_SHORT).show();
}
});
}
boolean pwCheck(String pw) {
return pw.length() >= 8 &&
pw.matches(".[A-Z].") &&
pw.matches(".[a-z].") &&
pw.matches(".\d.") &&
pw.matches(".[!@#$%^&(),.?":{}|<>].*");
}
}
NextActivity.java
package com.example.labbb4;
import android.os.;
import android.widget.;
import androidx.appcompat.app.*;
public class NextActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.activity_next);
TextView t = findViewById(R.id.tvSuccessMessage);
t.setText("Successful Login!");
}
}
AndroidManifest.xml
(add this line inside application)
<activity android:name=".NextActivity"/>
Full file:
<?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.Lab1" tools:targetApi="31">
<activity android:name=".NextActivity"/>
<activity android:name=".MainActivity" android:exported="true" tools:ignore="MissingClass">
<intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
activity_next.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:padding="16dp" android:orientation="vertical" android:gravity="center">
<TextView android:id="@+id/tvSuccessMessage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Welcome!" android:textSize="24sp" android:textColor="@android:color/holo_green_dark" />
</LinearLayout>
activity_main.xml
<?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="16dp">
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical">
<EditText android:id="@+id/etUsername" android:layout_width="match_parent" android:layout_height="59dp" android:hint="Username" android:inputType="text" />
<EditText android:id="@+id/etPassword" android:layout_width="match_parent" android:layout_height="68dp" android:hint="Password" android:inputType="textPassword" />
<Button android:id="@+id/btnSignUp" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Sign Up" />
<Button android:id="@+id/btnSignIn" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Sign In" />
<TextView android:id="@+id/textView" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="@android:color/holo_green_dark" android:textSize="18sp" android:visibility="gone" />
</LinearLayout> </RelativeLayout>
5)SEND SMS APP
JAVA FILE
package com.example.lab5;
import android.Manifest;
import android.os.;
import android.telephony.;
import android.widget.;
import androidx.appcompat.app.;
import androidx.core.app.*;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.activity_main);
ActivityCompat.requestPermissions(
this,
new String[]{Manifest.permission.SEND_SMS},
1
);
findViewById(R.id.buttonSendSMS).setOnClickListener(v -> {
String n = "1234567890";
String m = "Hello from app!";
SmsManager.getDefault().sendTextMessage(n, null, m, null, null);
Toast.makeText(this, "SMS Sent!", Toast.LENGTH_SHORT).show();
});
}
}
AndroidManifest.xml
(Add this permission)
<uses-permission android:name="android.permission.SEND_SMS"/>
(Full file:)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<uses-feature android:name="android.hardware.telephony" android:required="false" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<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.Lab5" 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>
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:padding="16dp" android:gravity="center">
<Button android:id="@+id/buttonSendSMS" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Send SMS" android:layout_gravity="center" android:layout_marginTop="100dp"/>
</LinearLayout>
6)PARSING XML & JSON
MAINACTIVITY.java
package com.example.lab6mad;
import android.os.Bundle;
import android.widget.;
import androidx.appcompat.app.AppCompatActivity;
import org.json.;
import org.xmlpull.v1.;
import java.io.;
public class MainActivity extends AppCompatActivity {
TextView xml, json;
@Override
protected void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.activity_main);
xml = findViewById(R.id.xmlData);
json = findViewById(R.id.jsonData);
findViewById(R.id.btnParseXML).setOnClickListener(v -> parseXML());
findViewById(R.id.btnParseJSON).setOnClickListener(v -> parseJSON());
}
void parseXML() {
try {
InputStream i = getResources().openRawResource(R.raw.city_data);
XmlPullParser x = XmlPullParserFactory
.newInstance()
.newPullParser();
x.setInput(i, null);
x.nextTag(); x.next(); String n = x.getText();
x.nextTag(); x.next(); String la = x.getText();
x.nextTag(); x.next(); String lo = x.getText();
x.nextTag(); x.next(); String te = x.getText();
x.nextTag(); x.next(); String hu = x.getText();
String r =
"name: " + n +
"\nlat: " + la +
"\nlon: " + lo +
"\ntemp: " + te +
"\nhumid: " + hu;
xml.setText(r);
} catch (Exception e) {
xml.setText("XML Error");
}
}
void parseJSON() {
try (InputStream i = getResources()
.openRawResource(R.raw.city_data_json)) {
byte[] b = new byte[i.available()];
i.read(b);
JSONObject o = new JSONObject(new String(b));
String r =
"name: " + o.getString("name") +
"\nlat: " + o.getDouble("latitude") +
"\nlon: " + o.getDouble("longitude") +
"\ntemp: " + o.getDouble("temperature") +
"\nhumid: " + o.getInt("humidity");
json.setText(r);
} catch (Exception e) {
json.setText("JSON Error");
}
}
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.lab6mad">
<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.LAB6MAD">
<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>
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
<LinearLayout style="?android:attr/buttonBarStyle" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center" android:padding="10dp">
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<TextView android:id="@+id/xmlData" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="XML Data" android:padding="10dp" android:background="#FFEBEE" />
<TextView android:id="@+id/jsonData" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="JSON Data" android:padding="10dp" android:background="#E3F2FD" />
</LinearLayout>
<Button android:id="@+id/btnParseXML" style="?android:attr/buttonBarButtonStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Parse XML" />
<Button android:id="@+id/btnParseJSON" style="?android:attr/buttonBarButtonStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="16dp" android:text="Parse JSON" />
</LinearLayout>
city_data.xml
<city> <name>New York</name> <latitude>40.7128</latitude> <longitude>-74.0060</longitude> <temperature>22.5</temperature> <humidity>60</humidity> </city>
city_data_json.json
{
"name": "New York",
"latitude": 40.7128,
"longitude": -74.0060,
"temperature": 22.5,
"humidity": 60
}
7)DIALER — CALL & SAVE CONTACT
MainActivity.java
package com.example.madlab7;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
EditText e;
@Override
protected void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.activity_main);
e = findViewById(R.id.editTextPhone);
}
public void d(View v) {
e.append(((Button) v).getText());
}
public void call(View v) {
String n = e.getText().toString();
Intent i = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + n));
startActivity(i);
}
public void save(View v) {
String n = e.getText().toString();
Intent i = new Intent(Intent.ACTION_INSERT);
i.setType(ContactsContract.RawContacts.CONTENT_TYPE);
i.putExtra(ContactsContract.Intents.Insert.PHONE, n);
startActivity(i);
}
}
activity_main.xml
<?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/editTextPhone" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Enter phone number" android:inputType="phone" android:textSize="24sp" />
<GridLayout android:layout_width="389dp" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:columnCount="3">
<Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_columnWeight="1" android:onClick="d" android:text="1" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_columnWeight="1" android:onClick="d" android:text="2" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_columnWeight="1" android:onClick="d" android:text="3" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_columnWeight="1" android:onClick="d" android:text="4" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_columnWeight="1" android:onClick="d" android:text="5" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_columnWeight="1" android:onClick="d" android:text="6" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_columnWeight="1" android:onClick="d" android:text="7" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_columnWeight="1" android:onClick="d" android:text="8" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_columnWeight="1" android:onClick="d" android:text="9" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_columnWeight="1" android:onClick="d" android:text="*" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_columnWeight="1" android:onClick="d" android:text="0" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_columnWeight="1" android:onClick="d" android:text="#" /> </GridLayout>
<Button android:text="CALL" android:onClick="call" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" />
<Button android:text="SAVE" android:onClick="save" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" />
</LinearLayout>
(Remember — every keypad button must include)
android:onClick="d"
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.example.madlab7">
<uses-feature android:name="android.hardware.telephony" android:required="false" />
<uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.WRITE_CONTACTS" /> <uses-permission android:name="android.permission.READ_CONTACTS" />
<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.MADLAB7" tools:targetApi="31">
<activity android:name=".MainActivity" android:exported="true" tools:ignore="MissingClass">
<intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
(Additional required lines — already included above)
<uses-feature android:name="android.hardware.telephony" android:required="false" /> <uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.WRITE_CONTACTS" /> <uses-permission android:name="android.permission.READ_CONTACTS" />
8)MEDICINE REMAINDER APP
MainActivity.java
package com.example.lab9;
import android.os.Bundle;
import android.widget.;
import androidx.appcompat.app.AppCompatActivity;
import java.util.;
public class MainActivity extends AppCompatActivity {
EditText n, d;
Spinner s;
TextView o;
List<M> l = new ArrayList<>();
String[] t = {"Morning", "Afternoon", "Evening", "Night"};
@Override
protected void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.activity_main);
n = findViewById(R.id.medicineName);
d = findViewById(R.id.medicineDate);
s = findViewById(R.id.timeOfDay);
o = findViewById(R.id.outputText);
s.setAdapter(
new ArrayAdapter<>(
this,
android.R.layout.simple_spinner_dropdown_item,
t
)
);
findViewById(R.id.saveBtn).setOnClickListener(v -> {
String x = n.getText().toString();
String y = d.getText().toString();
String z = s.getSelectedItem().toString();
l.add(new M(x, y, z));
});
findViewById(R.id.checkAlarmBtn).setOnClickListener(v -> showMeds());
}
String getSlot() {
int h = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
return h < 12 ? "Morning"
: h < 17 ? "Afternoon"
: h < 21 ? "Evening"
: "Night";
}
void showMeds() {
String today = java.time.LocalDate.now().toString();
String tm = getSlot();
StringBuilder b = new StringBuilder(tm + " " + today + "\nTake:\n");
boolean found = false;
for (M m : l) {
if (m.d.equals(today) && m.t.equals(tm)) {
b.append(m.n).append("\n");
found = true;
}
}
if (found)
o.setText(b.toString());
else
o.setText("No medicine scheduled.");
}
static class M {
String n, d, t;
M(String a, String b, String c) {
n = a;
d = b;
t = c;
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:padding="20dp" android:layout_width="match_parent" android:layout_height="match_parent">
<EditText android:id="@+id/medicineName" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="medicine_name" android:layout_marginTop="58dp" android:minHeight="48dp" />
<EditText android:id="@+id/medicineDate" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="date_yyyy_mm_dd" android:minHeight="48dp" />
<Spinner android:id="@+id/timeOfDay" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="48dp" />
<Button android:id="@+id/saveBtn" android:text="save_medicine" android:layout_width="match_parent" android:layout_height="wrap_content" />
<Button android:id="@+id/checkAlarmBtn" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="check_alarm" />
<TextView android:id="@+id/outputText" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="" android:textSize="16sp" />
</LinearLayout>
9)MEDIA PLAYER APP
activity_main.xml
<?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="#FAFAFA">
<TextView android:id="@+id/titleText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="MEDIA PLAYER APPLICATION" android:textStyle="bold" android:textSize="20sp" android:layout_centerHorizontal="true" android:layout_marginTop="16dp" />
<TextView android:id="@+id/audioName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Audio Name" android:layout_below="@id/titleText" android:layout_centerHorizontal="true" android:layout_marginTop="40dp" />
<SeekBar android:id="@+id/seekBar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/audioName" android:layout_marginTop="20dp" android:layout_marginStart="16dp" android:layout_marginEnd="16dp" />
<LinearLayout android:id="@+id/buttonLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/seekBar" android:layout_marginTop="40dp" android:gravity="center" android:orientation="horizontal" android:weightSum="4">
<Button android:id="@+id/btnBackward" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="⏪" android:textSize="24sp" /> <Button android:id="@+id/btnPlay" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="▶" android:textSize="24sp" /> <Button android:id="@+id/btnPause" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="⏸" android:textSize="24sp" /> <Button android:id="@+id/btnForward" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="⏩" android:textSize="24sp" /> </LinearLayout> </RelativeLayout>
MainActivity.java
package com.example.lab9;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.widget.Button;
import android.widget.SeekBar;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private MediaPlayer mediaPlayer;
private SeekBar seekBar;
private Handler handler = new Handler();
private Runnable updateSeekBar;
@Override
protected void onCreate(Bundle c) {
super.onCreate(c);
setContentView(R.layout.activity_main);
seekBar = findViewById(R.id.seekBar);
Button play = findViewById(R.id.btnPlay);
Button pause = findViewById(R.id.btnPause);
Button forward = findViewById(R.id.btnForward);
Button backward = findViewById(R.id.btnBackward);
mediaPlayer = MediaPlayer.create(this, R.raw.sample_audio);
seekBar.setMax(mediaPlayer.getDuration());
updateSeekBar = () -> {
seekBar.setProgress(mediaPlayer.getCurrentPosition());
handler.postDelayed(updateSeekBar, 1000);
};
play.setOnClickListener(v -> {
mediaPlayer.start();
handler.postDelayed(updateSeekBar, 0);
});
pause.setOnClickListener(v -> {
if (mediaPlayer.isPlaying()) mediaPlayer.pause();
});
forward.setOnClickListener(v -> {
int pos = mediaPlayer.getCurrentPosition() + 5000;
mediaPlayer.seekTo(Math.min(pos, mediaPlayer.getDuration()));
});
backward.setOnClickListener(v -> {
int pos = mediaPlayer.getCurrentPosition() - 5000;
mediaPlayer.seekTo(Math.max(pos, 0));
});
}
}
10)EMI CALCULATOR APP
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:padding="16dp" android:layout_width="match_parent" android:layout_height="match_parent">
<EditText android:id="@+id/etPrincipal" android:hint="Principal amount" android:inputType="numberDecimal" android:layout_width="match_parent" android:layout_height="wrap_content" />
<EditText android:id="@+id/etRate" android:hint="Annual Interest Rate (%)" android:inputType="numberDecimal" android:layout_width="match_parent" android:layout_height="wrap_content" />
<EditText android:id="@+id/etTenure" android:hint="Tenure (months)" android:inputType="number" android:layout_width="match_parent" android:layout_height="wrap_content" />
<EditText android:id="@+id/etDownPayment" android:hint="Down Payment" android:inputType="numberDecimal" android:layout_width="match_parent" android:layout_height="wrap_content" />
<Button android:id="@+id/btnCalculate" android:text="Calculate EMI" android:layout_width="match_parent" android:layout_height="wrap_content" />
<TextView android:id="@+id/tvResult" android:textSize="18sp" android:paddingTop="16dp" android:layout_width="match_parent" android:layout_height="wrap_content" />
</LinearLayout>
MainActivity.java
package com.example.lab10;
import android.os.Bundle;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
EditText pri, rate, time, dp;
Button calc;
TextView res;
@Override
protected void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.activity_main);
pri = findViewById(R.id.etPrincipal);
rate = findViewById(R.id.etRate);
time = findViewById(R.id.etTenure);
dp = findViewById(R.id.etDownPayment);
calc = findViewById(R.id.btnCalculate);
res = findViewById(R.id.tvResult);
calc.setOnClickListener(v -> {
double P = Double.parseDouble(pri.getText().toString());
double R = Double.parseDouble(rate.getText().toString());
int N = Integer.parseInt(time.getText().toString());
double Dp = Double.parseDouble(dp.getText().toString());
double principal = P - Dp;
double r = R / (12 * 100);
double emi = (principal * r * Math.pow(1 + r, N)) /
(Math.pow(1 + r, N) - 1);
res.setText("EMI: " + String.format("%.2f", emi));
});
}
}