0% found this document useful (0 votes)
9 views36 pages

Mad1 10

The document is a laboratory manual for Mobile Application Development for B.E. Semester 6 students at Vishwakarma Government Engineering College. It includes a certification for a student who completed the practical work, an index of practical assignments, and detailed examples of Java and XML code for various applications. Each practical is assessed based on understanding of the problem, capability of writing the program, and documentation.

Uploaded by

patelvishw596
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)
9 views36 pages

Mad1 10

The document is a laboratory manual for Mobile Application Development for B.E. Semester 6 students at Vishwakarma Government Engineering College. It includes a certification for a student who completed the practical work, an index of practical assignments, and detailed examples of Java and XML code for various applications. Each practical is assessed based on understanding of the problem, capability of writing the program, and documentation.

Uploaded by

patelvishw596
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/ 36

A Laboratory Manual for

Mobile Application Development


(3161612)

B.E. Semester 6
(Information Technology)

Directorate of Technical Education, Gandhinagar


Gujarat
Vishwakarma Government Engineering College,
Chandkheda

Certificate

This is to certify that Mr. Rahil M Prajapati Enrollment No. 220170116052 of B.E. Semester
6th Information Technology of this Institute (GTU Code: 017) has satisfactorily completed the
Practical / Tutorial work for the subject Mobile Application Development (3161612) for the
academic year 2024-25.

Place: __________
Date: __________

Name and Sign of Faculty Member

Head of the Department


Bachelor of Engineering
Semester – VI
Subject Name: Mobile Application Development
Subject Code: 3161612
Practical File
Index

SR.NO PRACTICAL NAME MARKS

UNDERSTANDING CAPABILITY OF DOCUME TOTAL


OF PROBLEM WRITING PROGRAM NTATION

1. Implement Sign In using Linear Layout

2. Implement Options Menu


3. Implement Dialog Menu
4. Implement Spinner with CustomAdapter

5. Implement Navigation Drawer

6. Implement Alarm Manager Using


Broadcast Receiver and Services
7. Implement AsyncTask to load image from
internet
8. Implement AsyncTask to load JSON Data
from internet
9. Implement PHP Web service and get/store
the data using volley
10.
Implement Styles and Themes
PRACTICAL-01
Implement Sign In using Linear Layout
(220170116052)

1. OUT PUT:

2. JAVA CODE :

package com.prac.singin;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


EditText username;
EditText password;
Button signInButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
username = findViewById(R.id.username);
password = findViewById(R.id.password);
signInButton = findViewById(R.id.singInButton);
signInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (username.getText().toString().equals("rahil") &&
password.getText().toString().equals("1234")) {
Toast.makeText(MainActivity.this, "Sign-In Successful!",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Sign-In Failed!",
Toast.LENGTH_SHORT).show();
}
3. XML CODE :
<?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:card_view="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/porschebackground"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:background="@drawable/custom_edittext"
app:cardCornerRadius="30dp"
app:cardElevation="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#33000000"
android:orientation="vertical"
android:padding="24dp">

<TextView
android:id="@+id/SignInText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SignIn"
android:textAlignment="center"
android:textColor="@color/purple"
android:textSize="36sp"
android:textStyle="bold" />

<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="40dp"
android:background="@drawable/custom_edittext"
android:drawableLeft="@drawable/baseline_person_24"
android:drawablePadding="8dp"
android:hint="Username"
android:padding="8dp"
android:textColor="@color/black"
android:textColorHighlight="@color/cardview_dark_background" />

<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="20dp"
android:background="@drawable/custom_edittext"
android:drawableLeft="@drawable/baseline_lock_24"
android:drawablePadding="8dp"
android:hint="Password"
android:inputType="textPassword"
android:padding="8dp"
android:textColor="@color/black"
android:textColorHighlight="@color/cardview_dark_background" />

<Button
android:id="@+id/singInButton"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="30dp"
android:backgroundTint="@color/purple"
android:text="Sign In"
android:textSize="18sp"
app:cornerRadius="20dp" />

</LinearLayout>

</androidx.cardview.widget.CardView>

<TextView
android:id="@+id/signupText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:padding="8dp"
android:text="Not yet registered? SignUp Now"
android:textAlignment="center"
android:textColor="@color/purple"
android:textSize="14sp" />

</LinearLayout>

RUBRICS FOR ASSESMENT:

UNDERSTANDING OF CAPABILITY OF WRITING DOCUMENTATION TOTAL


PROBLEM (0-4) PROGRAM (0 – 3) (0 – 3) (10)
PRACTICAL-02
Implement Options Menu
(220170116052)

1. OUT PUT:
2. JAVA CODE :

package com.prac.practical1;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Set up the toolbar
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu
getMenuInflater().inflate(R.menu.options_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.view_attendance) {
Toast.makeText(this, "View Attendance selected",
Toast.LENGTH_SHORT).show();
return true;
} else if (id == R.id.profile) {
Toast.makeText(this, "Profile selected", Toast.LENGTH_SHORT).show();
return true;
} else if (id == R.id.results) {
Toast.makeText(this, "Results selected", Toast.LENGTH_SHORT).show();
return true;
} else if (id == R.id.exams) {
Toast.makeText(this, "Exams selected", Toast.LENGTH_SHORT).show();
return true;
} else if (id == R.id.fees) {
Toast.makeText(this, "Fees selected", Toast.LENGTH_SHORT).show();
return true;
} else {
return super.onOptionsItemSelected(item); }
3. XML 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:background="#000000">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#000000"
android:popupTheme="@null"
android:titleTextColor="#FFFFFF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Options Menu"
android:textSize="24sp"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:layout_gravity="center"
android:padding="16dp" />
</LinearLayout>

RUBRICS FOR ASSESMENT:

UNDERSTANDING OF CAPABILITY OF WRITING DOCUMENTATION TOTAL


PROBLEM (0-4) PROGRAM (0 – 3) (0 – 3) (10)
PRACTICAL-03
Implement Dialog Menu
(220170116052)

1. OUTPUT:

2. JAVA CODE :

package com.prac.practical_3;
import android.content.DialogInterface;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private EditText etName, etEnrollment, etBranch, etSemester;
private Button btnSubmit;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize views
etName = findViewById(R.id.etName);
etEnrollment = findViewById(R.id.etEnrollment);
etBranch = findViewById(R.id.etBranch);
etSemester = findViewById(R.id.etSemester);
btnSubmit = findViewById(R.id.btnSubmit);
btnSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (validateInputs()) {
showConfirmationDialog();
}
private boolean validateInputs() {
if (etName.getText().toString().isEmpty() ||
etEnrollment.getText().toString().isEmpty() ||
etBranch.getText().toString().isEmpty() ||
etSemester.getText().toString().isEmpty()) {
Toast.makeText(this, "Please fill all fields", Toast.LENGTH_SHORT).show();
private void showConfirmationDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Confirm Submission")
.setMessage("Are you sure you want to submit the following details?\n\n" +
"Name: " + etName.getText().toString() + "\n" +
"Enrollment: " + etEnrollment.getText().toString() + "\n" +
"Branch: " + etBranch.getText().toString() + "\n" +
"Semester: " + etSemester.getText().toString())
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
submitDetails();
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
private void submitDetails() {
Toast.makeText(this, "Details submitted successfully!", Toast.LENGTH_SHORT).show();
clearFields();
}
private void clearFields() {
etName.setText("");
etEnrollment.setText("");
etBranch.setText("");
etSemester.setText(""); }
3. XML 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="16dp">
<EditText
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Student Name"
android:layout_marginBottom="8dp"/>
<EditText
android:id="@+id/etEnrollment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Enrollment Number"
android:layout_marginBottom="8dp"/>
<EditText
android:id="@+id/etSemester"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Semester"
android:inputType="number"
android:layout_marginBottom="16dp"/>
<Button
android:id="@+id/btnSubmit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit Details"/>
</LinearLayout>

RUBRICS FOR ASSESMENT:

UNDERSTANDING OF CAPABILITY OF WRITING DOCUMENTATION TOTAL


PROBLEM (0-4) PROGRAM (0 – 3) (0 – 3) (10)
PRACTICAL-04
Implement Spinner with Custom-Adapter
(220170116052)

1. OUT PUT:

2. JAVA CODE :

package com.prac.practical_4;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Spinner;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {


private Spinner subjectSpinner;
private List<Subject> subjects;

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

subjectSpinner = findViewById(R.id.subjectSpinner);
subjects = new ArrayList<>();

// Add subjects
subjects.add(new Subject("Big Data Analytics", "BDA"));
subjects.add(new Subject("Mobile App Development", "MAD"));
subjects.add(new Subject("Computer Network Security", "CNS"));
subjects.add(new Subject("Software Engineering", "SE"));
subjects.add(new Subject("Advanced Web Programming", "AWP"));

SubjectAdapter adapter = new SubjectAdapter(this, subjects);


subjectSpinner.setAdapter(adapter);

subjectSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Subject selectedSubject = subjects.get(position);
Toast.makeText(MainActivity.this,
"Selected: " + selectedSubject.getName(),
Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}

//SubjectAdpater.java file :-
package com.prac.practical_4;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.List;

public class SubjectAdapter extends ArrayAdapter<Subject> {


private Context context;
private List<Subject> subjects;

public SubjectAdapter(Context context, List<Subject> subjects) {


super(context, 0, subjects);
this.context = context;
this.subjects = subjects;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
return createItemView(position, convertView, parent);
}

@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
return createItemView(position, convertView, parent);
}

private View createItemView(int position, View convertView, ViewGroup parent) {


if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(android.R.layout.simple_spinner_item,
parent, false);
}

TextView textView = convertView.findViewById(android.R.id.text1);


Subject subject = subjects.get(position);
textView.setText(subject.getName() + " (" + subject.getCode() + ")");

return convertView;
}
}

3. 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">

<Spinner
android:id="@+id/subjectSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

RUBRICS FOR ASSESMENT:

UNDERSTANDING OF CAPABILITY OF WRITING DOCUMENTATION TOTAL


PROBLEM (0-4) PROGRAM (0 – 3) (0 – 3) (10)
PRACTICAL-05
Implement Navigation Drawer
(220170116052)

1. OUTPUT:

2. JAVA CODE :

package com.prac.vsbfinal;

import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.navigation.NavigationView;
import com.prac.vsbfinal.adapters.ServiceAdapter;
import com.prac.vsbfinal.models.Service;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {


RecyclerView recyclerView;
List<Service> serviceList = new ArrayList<>();
DrawerLayout drawerLayout;
NavigationView navigationView;
Toolbar toolbar;

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

toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

drawerLayout = findViewById(R.id.drawer_layout);
navigationView = findViewById(R.id.navigation_view);

ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(


this, drawerLayout, toolbar, R.string.navigation_drawer_open,
R.string.navigation_drawer_close);
drawerLayout.addDrawerListener(toggle);
toggle.syncState();

recyclerView = findViewById(R.id.recyclerViewServices);
recyclerView.setLayoutManager(new LinearLayoutManager(this));

// Add multiple services with drawable resource IDs


serviceList.add(new Service("Oil Change", "Complete engine oil change",
R.drawable.vsbf));
serviceList.add(new Service("Tire Rotation", "Rotation of all tires", R.drawable.vsbf));
serviceList.add(new Service("Brake Inspection", "Complete brake system inspection",
R.drawable.vsbf));
serviceList.add(new Service("Battery Check", "Battery health check and replacement",
R.drawable.vsbf));
serviceList.add(new Service("Engine Tune-Up", "Engine performance tuning",
R.drawable.vsbf));
serviceList.add(new Service("Transmission Service", "Transmission fluid change",
R.drawable.vsbf));
serviceList.add(new Service("Air Filter Replacement", "Replacement of air filters",
R.drawable.vsbf));
serviceList.add(new Service("Coolant Flush", "Complete coolant system flush",
R.drawable.vsbf));
serviceList.add(new Service("Wheel Alignment", "Alignment of all wheels",
R.drawable.vsbf));
serviceList.add(new Service("Exhaust System Check", "Inspection of exhaust system",
R.drawable.vsbf));
serviceList.add(new Service("Suspension Check", "Inspection of suspension system",
R.drawable.vsbf));
serviceList.add(new Service("AC Service", "Air conditioning system service",
R.drawable.vsbf));

recyclerView.setAdapter(new ServiceAdapter(this, serviceList));


}

@Override
public void onBackPressed() {
if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
drawerLayout.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
}

3. XML 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="wrap_content"
android:orientation="vertical"
android:padding="16dp"
android:background="@color/primaryColor"
android:gravity="center">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher_foreground"
android:layout_marginBottom="16dp"/>

<TextView
android:id="@+id/nav_header_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name"
android:textColor="@color/white"
android:textSize="18sp"
android:textStyle="bold"
android:gravity="center"
android:layout_marginBottom="8dp"/>

<TextView
android:id="@+id/nav_header_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="[email protected]"
android:textColor="@color/white"
android:gravity="center"/>
</LinearLayout>

RUBRICS FOR ASSESMENT:

UNDERSTANDING OF CAPABILITY OF WRITING DOCUMENTATION TOTAL


PROBLEM (0-4) PROGRAM (0 – 3) (0 – 3) (10)
PRACTICAL-06
Implement Alarm Manager Using Broadcast Receiver and Services
(220170116052)

1. OUTPUT:

2. JAVA CODE :

package com.prac.practical_6;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TimePicker;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Calendar;

public class MainActivity extends AppCompatActivity {


private TimePicker timePicker;
private AlarmManager alarmManager;
private PendingIntent pendingIntent;

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

timePicker = findViewById(R.id.timePicker);
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

findViewById(R.id.setAlarmButton).setOnClickListener(v -> setAlarm());


findViewById(R.id.cancelAlarmButton).setOnClickListener(v -> cancelAlarm());
}
private void setAlarm() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, timePicker.getHour());
calendar.set(Calendar.MINUTE, timePicker.getMinute());
calendar.set(Calendar.SECOND, 0);

Intent intent = new Intent(this, AlarmReceiver.class);


pendingIntent = PendingIntent.getBroadcast(this, 0, intent,
PendingIntent.FLAG_IMMUTABLE);

alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
pendingIntent);
Toast.makeText(this, "Alarm Set", Toast.LENGTH_SHORT).show();
}

private void cancelAlarm() {


if (alarmManager != null && pendingIntent != null) {
alarmManager.cancel(pendingIntent);
Toast.makeText(this, "Alarm Cancelled", Toast.LENGTH_SHORT).show();
}
}
}

//AlarmService.java & AlarmReceiver.java

public class AlarmService extends Service {


private static final String CHANNEL_ID = "AlarmChannel";
private static final int NOTIFICATION_ID = 1;

@Override
public void onCreate() {
super.onCreate();
createNotificationChannel();
}
public int onStartCommand(Intent intent, int flags, int startId) {
showNotification();
return START_NOT_STICKY;
}
public IBinder onBind(Intent intent) {
return null;
}

private void createNotificationChannel() {


if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(
CHANNEL_ID,
"Alarm Channel",
NotificationManager.IMPORTANCE_HIGH
);
NotificationManager manager = getSystemService(NotificationManager.class);
manager.createNotificationChannel(channel);
}
}
private void showNotification() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(android.R.drawable.ic_dialog_alert)
.setContentTitle("Alarm")
.setContentText("Wake up!")
.setPriority(NotificationCompat.PRIORITY_HIGH);

NotificationManager manager = getSystemService(NotificationManager.class);


manager.notify(NOTIFICATION_ID, builder.build());
}

public class AlarmReceiver extends BroadcastReceiver {


@Override
public void onReceive(Context context, Intent intent) {
Intent serviceIntent = new Intent(context, AlarmService.class);
context.startService(serviceIntent);
}
}

3. XML 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="16dp">

<TimePicker
android:id="@+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<Button
android:id="@+id/setAlarmButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Set Alarm" />

<Button
android:id="@+id/cancelAlarmButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Cancel Alarm" />

</LinearLayout>

RUBRICS FOR ASSESMENT:

UNDERSTANDING OF CAPABILITY OF WRITING DOCUMENTATION TOTAL


PROBLEM (0-4) PROGRAM (0 – 3) (0 – 3) (10)
PRACTICAL-07
Implement AsyncTask to load image from internet
(220170116052)

1. OUTPUT:

2. JAVA CODE :

package com.prac.practical_7;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import java.io.InputStream;
import java.net.URL;

public class MainActivity extends AppCompatActivity {


private ImageView imageView;
private Button loadButton;

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

imageView = findViewById(R.id.imageView);
loadButton = findViewById(R.id.loadButton);

loadButton.setOnClickListener(v -> {
new ImageLoadTask().execute("https://picsum.photos/300/300");
});
}

private class ImageLoadTask extends AsyncTask<String, Void, Bitmap> {


@Override
protected void onPreExecute() {
Toast.makeText(MainActivity.this, "Image loading started...",
Toast.LENGTH_SHORT).show();
}

@Override
protected Bitmap doInBackground(String... params) {
try {
URL url = new URL(params[0]);
InputStream is = url.openStream();
return BitmapFactory.decodeStream(is);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

@Override
protected void onPostExecute(Bitmap bitmap) {
if (bitmap != null) {
imageView.setImageBitmap(bitmap);
Toast.makeText(MainActivity.this, "Image loaded successfully!",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Error loading image",
Toast.LENGTH_SHORT).show();
}
}
}
}

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

<Button
android:id="@+id/loadButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Load Image"
app:layout_constraintBottom_toTopOf="@+id/imageView"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/imageView"
android:layout_width="300dp"
android:layout_height="300dp"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/loadButton" />

</androidx.constraintlayout.widget.ConstraintLayout>

RUBRICS FOR ASSESMENT:

UNDERSTANDING OF CAPABILITY OF WRITING DOCUMENTATION TOTAL


PROBLEM (0-4) PROGRAM (0 – 3) (0 – 3) (10)
PRACTICAL-08
Implement AsyncTask to load JSON Data from internet
(220170116052)

1. OUTPUT:

2. JAVA CODE :

package com.prac.practical_8;

import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class MainActivity extends AppCompatActivity {


private TextView textView;
private Button loadButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

textView = findViewById(R.id.textView);
loadButton = findViewById(R.id.loadButton);

loadButton.setOnClickListener(v -> {
new JsonLoadTask().execute("https://jsonplaceholder.typicode.com/posts");
});
}

private class JsonLoadTask extends AsyncTask<String, Void, String> {


@Override
protected void onPreExecute() {
Toast.makeText(MainActivity.this, "Loading JSON data...",
Toast.LENGTH_SHORT).show();
}

@Override
protected String doInBackground(String... params) {
StringBuilder result = new StringBuilder();
try {
URL url = new URL(params[0]);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
BufferedReader reader = new BufferedReader(new
InputStreamReader(connection.getInputStream()));

String line;
while ((line = reader.readLine()) != null) {
result.append(line);
}
reader.close();
} catch (Exception e) {
e.printStackTrace();
return null;
}
return result.toString();
}

@Override
protected void onPostExecute(String json) {
if (json != null) {
try {
// Parse JSON and display the first item as an example
JSONArray jsonArray = new JSONArray(json);
JSONObject firstItem = jsonArray.getJSONObject(0);
String displayText = "Title: " + firstItem.getString("title") + "\nBody: " +
firstItem.getString("body");
textView.setText(displayText);
Toast.makeText(MainActivity.this, "JSON loaded successfully!",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(MainActivity.this, "Error parsing JSON",
Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(MainActivity.this, "Error loading JSON",
Toast.LENGTH_SHORT).show();
}

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

<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="16dp"
android:text="JSON data will appear here"
android:textSize="16sp"
app:layout_constraintTop_toBottomOf="@+id/loadButton"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

RUBRICS FOR ASSESMENT:

UNDERSTANDING OF CAPABILITY OF WRITING DOCUMENTATION TOTAL


PROBLEM (0-4) PROGRAM (0 – 3) (0 – 3) (10)
PRACTICAL-09
Implement PHP Web service and get/store the data using volley
(220170116052)

1. OUTPUT:

2. JAVA CODE(API Services Using Volley) :

package com.prac.vsbfinal.network;

import android.content.Context;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONObject;

public class ApiService {


private static ApiService instance;
private RequestQueue requestQueue;
private static Context ctx;

private ApiService(Context context) {


ctx = context.getApplicationContext();
requestQueue = getRequestQueue();
}

public static synchronized ApiService getInstance(Context context) {


if (instance == null) {
instance = new ApiService(context);
}
return instance;
}

public RequestQueue getRequestQueue() {


if (requestQueue == null) {
requestQueue = Volley.newRequestQueue(ctx);
}
return requestQueue;
}

public void getAvailableSlots(int year, int month, int day, Response.Listener<JSONArray>


listener, Response.ErrorListener errorListener) {
String url = "http://10.0.2.2/VSBFinal/show_available_slots.php?year=" + year +
"&month=" + month + "&day=" + day;
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, url,
null, listener, errorListener);
getRequestQueue().add(jsonArrayRequest);
}

public void getUserDetails(int userId, Response.Listener<JSONObject> listener,


Response.ErrorListener errorListener) {
String url = "http://10.0.2.2/VSBFinal/get_user_details.php?id=" + userId;
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,
url, null, listener, errorListener);
getRequestQueue().add(jsonObjectRequest);
}

public void getBookingsForUser(int userId, Response.Listener<JSONArray> listener,


Response.ErrorListener errorListener) {
String url = "http://10.0.2.2/VSBFinal/get_bookings_for_user.php?id=" + userId;
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, url,
null, listener, errorListener);
getRequestQueue().add(jsonArrayRequest);
}

public void cancelBooking(int bookingId, Response.Listener<String> listener,


Response.ErrorListener errorListener) {
String url = "http://10.0.2.2/VSBFinal/cancel_booking.php?id=" + bookingId;
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, listener,
errorListener);
getRequestQueue().add(stringRequest);
}

public void bookSlot(int slotId, int userId, String vehicleNumber, String vehicleType, String
details, Response.Listener<JSONObject> listener, Response.ErrorListener errorListener) {
String url = "http://10.0.2.2/VSBFinal/book_slot.php?slot_id=" + slotId + "&user_id=" +
userId + "&vehicle_number=" + vehicleNumber + "&vehicle_type=" + vehicleType +
"&details=" + details;
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST,
url, null, listener, errorListener);
getRequestQueue().add(jsonObjectRequest);
}
}

3. XML CODE(Login/SignUp) :
<?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="20dp"
android:background="@color/white">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sign Up"
android:textSize="24sp"
android:textStyle="bold"
android:textColor="@color/black"
android:gravity="center"
android:layout_marginBottom="20dp"/>

<EditText
android:id="@+id/et_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Full Name"
android:padding="12dp"
android:background="@drawable/input_border"/>

<EditText
android:id="@+id/et_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:inputType="textEmailAddress"
android:padding="12dp"
android:background="@drawable/input_border"
android:layout_marginTop="10dp"/>

<EditText
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:padding="12dp"
android:background="@drawable/input_border"
android:layout_marginTop="10dp"/>

<Button
android:id="@+id/btn_signup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign Up"
android:textStyle="bold"
android:backgroundTint="@color/primaryColor"
android:textColor="@color/white"
android:layout_marginTop="20dp"/>

<TextView
android:id="@+id/tv_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Already have an account? Login"
android:textColor="@color/primaryColor"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:clickable="true"
android:focusable="true"/>

</LinearLayout>

RUBRICS FOR ASSESMENT:

UNDERSTANDING OF CAPABILITY OF WRITING DOCUMENTATION TOTAL


PROBLEM (0-4) PROGRAM (0 – 3) (0 – 3) (10)
PRACTICAL-10
Implement Styles and Themes
(220170116052)

1. OUTPUT:

2. JAVA CODE :

package com.prac.vsbfinal;

import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.navigation.NavigationView;
import com.prac.vsbfinal.adapters.ServiceAdapter;
import com.prac.vsbfinal.models.Service;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {


RecyclerView recyclerView;
List<Service> serviceList = new ArrayList<>();
DrawerLayout drawerLayout;
NavigationView navigationView;
Toolbar toolbar;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

drawerLayout = findViewById(R.id.drawer_layout);
navigationView = findViewById(R.id.navigation_view);

ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(


this, drawerLayout, toolbar, R.string.navigation_drawer_open,
R.string.navigation_drawer_close);
drawerLayout.addDrawerListener(toggle);
toggle.syncState();

recyclerView = findViewById(R.id.recyclerViewServices);
recyclerView.setLayoutManager(new LinearLayoutManager(this));

// Add multiple services with drawable resource IDs


serviceList.add(new Service("Oil Change", "Complete engine oil change",
R.drawable.vsbf));
serviceList.add(new Service("Tire Rotation", "Rotation of all tires", R.drawable.vsbf));
serviceList.add(new Service("Brake Inspection", "Complete brake system inspection",
R.drawable.vsbf));
serviceList.add(new Service("Battery Check", "Battery health check and replacement",
R.drawable.vsbf));
serviceList.add(new Service("Engine Tune-Up", "Engine performance tuning",
R.drawable.vsbf));
serviceList.add(new Service("Transmission Service", "Transmission fluid change",
R.drawable.vsbf));
serviceList.add(new Service("Air Filter Replacement", "Replacement of air filters",
R.drawable.vsbf));
serviceList.add(new Service("Coolant Flush", "Complete coolant system flush",
R.drawable.vsbf));
serviceList.add(new Service("Wheel Alignment", "Alignment of all wheels",
R.drawable.vsbf));
serviceList.add(new Service("Exhaust System Check", "Inspection of exhaust system",
R.drawable.vsbf));
serviceList.add(new Service("Suspension Check", "Inspection of suspension system",
R.drawable.vsbf));
serviceList.add(new Service("AC Service", "Air conditioning system service",
R.drawable.vsbf));

recyclerView.setAdapter(new ServiceAdapter(this, serviceList));


}

@Override
public void onBackPressed() {
if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
drawerLayout.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
}

3. XML CODE :
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="4dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp"
android:background="@color/white">

<ImageView
android:id="@+id/serviceImage"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:layout_marginBottom="8dp"/>

<TextView
android:id="@+id/serviceName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Service Name"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
android:layout_marginBottom="4dp"/>

<TextView
android:id="@+id/serviceDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Service Description"
android:textSize="14sp"
android:textColor="@color/gray"
android:layout_marginBottom="8dp"/>

<Button
android:id="@+id/btnBookService"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Book Now"
android:textStyle="bold"
android:backgroundTint="@color/primaryColor"
android:textColor="@color/white"/>
</LinearLayout>
</androidx.cardview.widget.CardView>

//Activity_main.xml

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


<androidx.drawerlayout.widget.DrawerLayout
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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<!-- Main Content -->


<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerViewServices"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:clipToPadding="false" />
</LinearLayout>

<!-- Navigation Drawer -->


<com.google.android.material.navigation.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/drawer_menu"
app:headerLayout="@layout/nav_header" />
</androidx.drawerlayout.widget.DrawerLayout>

RUBRICS FOR ASSESMENT:

UNDERSTANDING OF CAPABILITY OF WRITING DOCUMENTATION TOTAL


PROBLEM (0-4) PROGRAM (0 – 3) (0 – 3) (10)

You might also like