Mad Lab Manual
Mad Lab Manual
Certificate
This is to certify that Mr. / Ms. ___________________________________
________ Enrollment No. _______________of B.E. Semester _____
Information Technology of this Institute (GTU Code: 016) has satisfactorily
completed the Practical / Tutorial work for the subject Mobile App. Dev. for the
academic year 2024-25.
Place: __________
Date: __________
1 Calculator App
2 Currency Converter App (INR to
USD)
3 Library Overdue Counter App
4 Ball Size and Color Animation
5 Mark Daily Route on Map
6 Record and Play Audio/Video
(Topic: Intent)
7 Hello World Android App
8 Activity Navigation Using Intents
9 Fragment Example
10 Using AutoCompleteTextView
11 Orientation Change Handling
12 Handling Button Click
13 Creating Options Menu
14 Internal Storage
15 External Storage
16 SQLite Database Example
1. Calculator App
What: Simple calculator that performs addition, subtraction, multiplication, and
division.
// MainActivity.java
public class MainActivity extends AppCompatActivity {
EditText num1, num2;
TextView result;
Button add, sub, mul, div;
num1 = findViewById(R.id.num1);
num2 = findViewById(R.id.num2);
result = findViewById(R.id.result);
add = findViewById(R.id.add);
sub = findViewById(R.id.sub);
mul = findViewById(R.id.mul);
div = findViewById(R.id.div);
switch (op) {
case "+": res = a + b; break;
case "-": res = a - b; break;
case "*": res = a * b; break;
case "/": res = a / b; break;
}
result.setText("Result: " + res);
}
}
2. Currency Converter App (INR to USD)
// MainActivity.java
public class MainActivity extends AppCompatActivity {
EditText inr;
TextView usd;
Button convert;
inr = findViewById(R.id.inr);
usd = findViewById(R.id.usd);
convert = findViewById(R.id.convert);
convert.setOnClickListener(v -> {
double rupee = Double.parseDouble(inr.getText().toString());
double dollar = rupee / 83.0;
usd.setText("USD: $" + String.format("%.2f", dollar));
});
}
}
3. Library Overdue Counter App
What: Calculate overdue days and fine (e.g., ₹5 per day).
// MainActivity.java
public class MainActivity extends AppCompatActivity {
EditText issueDate, returnDate;
TextView result;
Button calc;
@SuppressLint("SimpleDateFormat")
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
issueDate = findViewById(R.id.issueDate);
returnDate = findViewById(R.id.returnDate);
result = findViewById(R.id.result);
calc = findViewById(R.id.calc);
calc.setOnClickListener(v -> {
try {
Date issue = sdf.parse(issueDate.getText().toString());
Date ret = sdf.parse(returnDate.getText().toString());
animateBall();
}
fusedLocationClient =
LocationServices.getFusedLocationProviderClient(this);
}
fusedLocationClient.getLastLocation().addOnSuccessListener(this,
location -> {
if (location != null) {
LatLng current = new LatLng(location.getLatitude(),
location.getLongitude());
mMap.addMarker(new MarkerOptions().position(current).title("Start
Point"));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(current,
15));
}
});
}
}
6. Record and Play Audio/Video (Topic: Intent)
What: Record and playback audio/video using intents.
// Start recording video
Intent takeVideoIntent = new
Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(takeVideoIntent, 101);
MainActivity.java
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val buttonFragmentOne =
findViewById<Button>(R.id.button_fragment_one)
val buttonFragmentTwo =
findViewById<Button>(R.id.button_fragment_two)
buttonFragmentOne.setOnClickListener {
supportFragmentManager.beginTransaction()
.replace(R.id.fragment_container, FragmentOne())
.commit()
}
buttonFragmentTwo.setOnClickListener {
supportFragmentManager.beginTransaction()
.replace(R.id.fragment_container, FragmentTwo())
.commit()
}
}
}
<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">
<Button
android:id="@+id/button_fragment_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Load Fragment One" />
<Button
android:id="@+id/button_fragment_two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Load Fragment Two" />
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp"/>
</LinearLayout>
10. Using AutoCompleteTextView
What: Implement AutoCompleteTextView with suggestions.
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"
android:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Country Name:"
android:textSize="16sp"/>
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Type here..."
android:textSize="16sp"/>
</LinearLayout>
MainActivity.java:
package com.example.autocompletetextviewexample;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize AutoCompleteTextView
AutoCompleteTextView autoCompleteTextView =
findViewById(R.id.autoCompleteTextView);
<Button
android:id="@+id/button_show_toast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Toast" />
</LinearLayout>
package com.example.toastmessageexample;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select an option from the menu"
android:textSize="18sp"/>
</LinearLayout>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_option_one"
android:title="Option One"/>
<item
android:id="@+id/menu_option_two"
android:title="Option Two"/>
<item
android:id="@+id/menu_option_three"
android:title="Option Three"/>
</menu>
package com.example.optionsmenuexample;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
<EditText
android:id="@+id/editTextData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your data here" />
<Button
android:id="@+id/buttonSave"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Save Data" />
<Button
android:id="@+id/buttonLoad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Load Data"
android:layout_marginTop="8dp"/>
<TextView
android:id="@+id/textViewData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Loaded data will appear here"
android:paddingTop="16dp"
android:textSize="16sp"/>
</LinearLayout>
package com.example.internalstorageexample;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextData = findViewById(R.id.editTextData);
textViewData = findViewById(R.id.textViewData);
buttonSave = findViewById(R.id.buttonSave);
buttonLoad = findViewById(R.id.buttonLoad);
<EditText
android:id="@+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Name" />
<EditText
android:id="@+id/editTextAge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Age"
android:inputType="number" />
<Button
android:id="@+id/buttonInsert"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Insert Data"
android:layout_marginTop="8dp"/>
<Button
android:id="@+id/buttonView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="View Data"
android:layout_marginTop="8dp"/>
<TextView
android:id="@+id/textViewResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Data will appear here"
android:textSize="16sp"
android:paddingTop="16dp"/>
</LinearLayout>
package com.example.sqliteexample;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME + " (ID INTEGER
PRIMARY KEY AUTOINCREMENT, NAME TEXT, AGE INTEGER)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
// Method to Insert Data
public boolean insertData(String name, int age) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_2, name);
contentValues.put(COL_3, age);
long result = db.insert(TABLE_NAME, null, contentValues);
return result != -1; // If result is -1, insertion failed
}
package com.example.sqliteexample;
import androidx.appcompat.app.AppCompatActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize UI Components
editTextName = findViewById(R.id.editTextName);
editTextAge = findViewById(R.id.editTextAge);
buttonInsert = findViewById(R.id.buttonInsert);
buttonView = findViewById(R.id.buttonView);
textViewResult = findViewById(R.id.textViewResult);
// Insert Data
buttonInsert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = editTextName.getText().toString();
String ageText = editTextAge.getText().toString();
if (name.isEmpty() || ageText.isEmpty()) {
Toast.makeText(MainActivity.this, "Please enter all details",
Toast.LENGTH_SHORT).show();
return;
}
// View Data
buttonView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Cursor cursor = databaseHelper.getAllData();
if (cursor.getCount() == 0) {
textViewResult.setText("No Data Found");
return;
}