Mad Lab Manual
Mad Lab Manual
Manual
CSE506
CT UNIVERSITY
UID: 71912086
Contents
Exp. Page
Problem Statement
No. No.
Part A
Create an application to design a Visiting Card. The Visiting card should have a company logo
at the top right corner. The company name should be displayed in Capital letters, aligned to
1. the center. Information like the name of the employee, job title, phone number, address, email, 1
fax and the website address is to be displayed. Insert a horizontal line between the job title and
the phone number.
Develop an Android application using controls like Button, TextView, EditText for designing a
2. calculator having basic functionality like Addition, Subtraction, Multiplication, and Division. 3
Create a SIGN Upton activity with Username and Password. Validation of password should
3. 7
happen
Develop an application to set an image as wallpaper. On click of a button, the wallpaper image
4. 12
should start to change randomly every 30 seconds.
Write a program to create an activity with two buttons START and STOP. On pressing of the
5. START button, the activity must start the counter by displaying the numbers from One and the 13
counter must keep on counting until the STOP button is pressed. Display the counter
Create two files of XML and JSON type with values for City_Name, Latitude, Longitude,
Temperature, and Humidity. Develop an application to create an activity with two buttons to
6. 17
parse the XML and JSON files which when clicked should display the data in their respective
layouts side by side.
MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
Program-1
Create an application to design a Visiting Card. The Visiting card should have a company logo at the
top right corner. The company name should be displayed in Capital letters, aligned to the center.
Information like the name of the employee, job title, phone number, address, email, fax and the
website address is to be displayed. Insert a horizontal line between the job title and the phone number.
XML-CODE
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="17dp"
android:layout_marginLeft="17dp"
android:layout_marginTop="17dp"
android:layout_marginEnd="244dp"
android:layout_marginRight="244dp"
android:layout_marginBottom="486dp"
android:text="SJCIT"
android:textSize="38dp" />
<ImageView
android:id="@+id/imageView"
android:layout_width="231dp"
android:layout_height="174dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-14dp"
android:layout_marginRight="-14dp"
android:layout_marginBottom="481dp"
SJCIT, Department of Information Science and Engineering 1
MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
app:srcCompat="@drawable/logo" />
<View android:id="@+id/view"
android:layout_width="wrap_content"
android:layout_height="4dp"
android:layout_alignParentBottom="true"
android:background="#4444"
android:layout_marginBottom="466dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="117dp"
android:layout_marginRight="117dp"
android:layout_marginBottom="394dp"
android:text="Amar Akbar Anthony"
android:textSize="30dp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="64dp"
android:layout_marginRight="64dp"
android:layout_marginBottom="343dp"
android:text="Assistant Professor-ISE"
android:textSize="25dp" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="127dp"
android:layout_marginRight="127dp"
android:layout_marginBottom="294dp"
android:text="Ph No: 9988776655"
android:textSize="20dp" />
<TextView
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="44dp"
android:layout_marginRight="44dp"
android:layout_marginBottom="189dp" android:text="Email:
[email protected]" android:textSize="20dp" />
</RelativeLayout>
JAVA-CODE
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle; public class MainActivity
extends AppCompatActivity { protected void
onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
OUTPUT:
Program-2
Develop an Android application using controls like Button, TextView, EditText for designing a
calculator having basic functionality like Addition, Subtraction, Multiplication, and Division.
XML-CODE
<?xml version="1.0" encoding="utf-8"?>
<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" tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="98dp"
android:layout_marginBottom="653dp"
android:text="SIMPLE CALCI" android:textSize="38dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.042" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="115dp"
android:layout_marginBottom="547dp"
android:ems="10"
android:hint="Enter the First Number"
android:inputType="textPersonName"
SJCIT, Department of Information Science and Engineering 4
MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
android:text="" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="111dp"
android:layout_marginBottom="455dp"
android:ems="10"
android:inputType="textPersonName"
android:hint="Enter the Second Number"
android:text="" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="203dp"
android:layout_marginBottom="350dp"
android:text="0"
android:textSize="40dp" />
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="274dp"
android:layout_marginBottom="237dp"
android:onClick="doAdd"
android:text="ADD" />
<Button android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="68dp"
android:layout_marginBottom="233dp"
android:onClick="doSub"
android:text="SUB" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
SJCIT, Department of Information Science and Engineering 5
MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
android:layout_alignParentBottom="true"
android:layout_marginEnd="277dp"
android:layout_marginBottom="115dp"
android:onClick="doMul"
android:text="MUL" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="63dp"
android:layout_marginBottom="104dp" android:onClick="doDiv"
android:text="DIV" />
</RelativeLayout>
JAVA-CODE
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle; import
android.view.View; import
android.widget.EditText;
import android.widget.TextView;
OUTPUT:
Program-3
Create a SIGN Up activity with Username and Password. Validation of password should happen based
on the following rules:
- Password should contain uppercase and lowercase letters.
- Password should contain letters and numbers.
- Password should contain special characters.
- Minimum length of the password (the default value is 8).
import.AppCompatActivity;
import.Intent;
import.Bundle;
import.View; import.Button;
import.EditText;
import.Toast;
//SignUpActivity.java
import.Pattern;
public class SignUpActivity extends AppCompatActivity {
EditText emailEditText, passwordEditText;
Button signUpBtn; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup); emailEditText =
findViewById(R.id.emailEditText); passwordEditText =
findViewById(R.id.passwordEditText); signUpBtn =
findViewById(R.id.signUpBtn);
signUpBtn.setOnClickListener(new View.OnClickListener() {
@Override public
void onClick(View v) {
String email = emailEditText.getText().toString(); String
password = passwordEditText.getText().toString(); if (!
isValidPassword(password))
{ Toast.makeText(SignUpActivity.this, "Password doesn't
match rules",
Toast.LENGTH_SHORT).show();
return;
}
//LoginActivity.java
import.AppCompatActivity;
import.Intent;
import.Bundle;
import.View; import.Button;
import.EditText;
import.Toast;
public class LoginActivity extends AppCompatActivity {
EditText emailEditText, passwordEditText;
Button loginBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login); emailEditText =
findViewById(R.id.emailEditText); passwordEditText =
//LoginSuccessActivity.java
import .AppCompatActivity;
import .Bundle;
public class LoginSuccessActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_success);
}
}
OUTPUT:
Develop an application to set an image as wallpaper. On click of a button, the wallpaper image should
start to change randomly every 30 seconds.
//First, create the android application as discussed in “Create your First Android Application”. Copy the
//images and save the images in the drawable folder. Following is the content of the modified
//res/layout/activity_main.xml.
//Save five images (jpg format) in the drawable folder. In this example one.jpg, two.jpg,three.jpg, four.jpg
and //five.jpg images are saved in drawable folder.
//MainActivity.java package com.example.lab4a;
import androidx.appcompat.app.AppCompatActivity;
import android.app.WallpaperManager; import
android.graphics.Bitmap; import
android.graphics.BitmapFactory; import
android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import
android.os.Bundle; import android.view.View; import
android.widget.Button; import android.widget.Toast;
import java.io.IOException; import java.util.Timer;
import java.util.TimerTask;
public class MainActivity extends AppCompatActivity {
Button changewallpaper;
Timer mytimer;
Drawable drawable;
WallpaperManager wpm;
int prev=1; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); mytimer
= new Timer();
wpm = WallpaperManager.getInstance(this);
changewallpaper = findViewById(R.id.button); changewallpaper.setOnClickListener(new
View.OnClickListener() {
@Override public void onClick(View view)
{ setWallpaper();
}
});
}
OUTPUT:
Program - 5
Write a program to create an activity with two buttons START and STOP. On pressing of the START
button, the activity must start the counter by displaying the numbers from One and the counter must
keep on counting until the STOP button is pressed.
//MainActivity.java
package com.example.a5a;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle; import
android.os.Handler; import
android.view.View; import
android.widget.Button;
import android.widget.TextView;
OUTPUT:
Program-6
Create two files of XML and JSON type with values for City_Name, Latitude, Longitude,
Temperature, and Humidity. Develop an application to create an activity with two buttons to parse the
XML and JSON files which when clicked should display the data in their respective layouts side by
side.
//MainActivity.java
import android.os.Bundle;
import android.util.Log; import
android.util.Xml; import android.view.View;
import android.widget.Button; import
android.widget.TextView; import
android.widget.Toast; import
org.json.JSONArray; import
org.json.JSONException; import
org.json.JSONObject; import
org.w3c.dom.Document; import
org.w3c.dom.Element; import
org.w3c.dom.Node; import
org.w3c.dom.NodeList; import
org.xml.sax.SAXException; import
org.xmlpull.v1.XmlPullParser; import
org.xmlpull.v1.XmlPullParserException; import
java.io.IOException; import
java.io.InputStream;
import java.nio.charset.StandardCharsets; import
javax.xml.parsers.DocumentBuilder; import
javax.xml.parsers.DocumentBuilderFactory; import
javax.xml.parsers.ParserConfigurationException;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
parseJsonBtn = findViewById(R.id.parseJsonBtn);
parseXmlBtn = findViewById(R.id.parseXmlBtn);
displayTextView = findViewById(R.id.displayTextView);
parseXmlBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
InputStream is = getAssets().open("city.xml");
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(MainActivity.this, "Error Parsing XML", Toast.LENGTH_SHORT).show();
}
}
});
parseJsonBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String json;
StringBuilder stringBuilder = new StringBuilder();
try {
InputStream is = getAssets().open("city.json");
int size = is.available(); byte[] buffer =
new byte[size]; is.read(buffer);
json = new String(buffer, StandardCharsets.UTF_8);
JSONArray jsonArray = new JSONArray(json);
stringBuilder.append("JSON Data");
stringBuilder.append("\n----------");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
stringBuilder.append("\nName: ").append(jsonObject.getString("name"));
stringBuilder.append("\nLatitude: ").append(jsonObject.getString("lat"));
stringBuilder.append("\nLongitude: ").append(jsonObject.getString("long"));
stringBuilder.append("\nTemperature:").append(jsonObject.getString("temperature"));
stringBuilder.append("\nHumidity: ").append(jsonObject.getString("humidity"));
stringBuilder.append("\n----------");
}
SJCIT, Department of Information Science and Engineering 17
MOBILE APPLICATION DEVELOPMENT LABORATORY - 18CSMP68
displayTextView.setText(stringBuilder.toString());
is.close();
} catch (IOException | JSONException e) {
e.printStackTrace();
Toast.makeText(MainActivity.this, "Error in parsing JSON data
from!",Toast.LENGTH_SHORT) .show();
}
}
});
}