Mobile Application Development Laboratory
Mobile Application Development Laboratory
Mobile Application Development Laboratory
LABORATORY
INDEX
Ex No Experiment Name
1 Develop an application that uses GUI components, Font
and Colours.
2 Develop an application that uses Layout Managers and
event listeners.
3 Develop a native calculator application.
1.activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TableLayout
android:layout_width="395dp"
android:layout_height="715dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
tools:layout_editor_absoluteX="157dp"
tools:layout_editor_absoluteY="54dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Font"
tools:layout_editor_absoluteX="108dp"
tools:layout_editor_absoluteY="60dp"
android:onClick="change_font"/>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Color"
tools:layout_editor_absoluteX="149dp"
tools:layout_editor_absoluteY="112dp"
android:onClick="change_color"/>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
</TableLayout>
</android.support.constraint.ConstraintLayout>
2.MainActivity.java
package com.example.exno1_cseb_bi;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
int font_size=5;
int color_option=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void change_font(View view)
{
TextView tv=(TextView)findViewById(R.id.name);
tv.setTextSize(font_size);
font_size=font_size+1;
if(font_size==15)
{
font_size=5;
}
}
public void change_color(View view)
{
TextView tv=(TextView)findViewById(R.id.name);
if(color_option==0)
{
tv.setTextColor(Color.BLUE);
}
if(color_option==1)
{
tv.setTextColor(Color.YELLOW);
}
if(color_option==2)
{
tv.setTextColor(Color.GREEN);
}
if(color_option==3)
{
tv.setTextColor(Color.GRAY);
}
if(color_option==4)
{
tv.setTextColor(Color.MAGENTA);
}
color_option=color_option+1;
if(color_option==4)
{
color_option=0;
}
}
}
2.Develop an application that uses Layout Managers and event listeners
1.activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TableLayout
android:layout_width="395dp"
android:layout_height="715dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter the Name"
tools:layout_editor_absoluteX="176dp"
tools:layout_editor_absoluteY="34dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
tools:layout_editor_absoluteX="78dp"
tools:layout_editor_absoluteY="60dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click"
tools:layout_editor_absoluteX="161dp"
tools:layout_editor_absoluteY="102dp"
android:onClick="display"/>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
</TableLayout>
</android.support.constraint.ConstraintLayout>
2.activity_display.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Display">
<TableLayout
android:layout_width="395dp"
android:layout_height="715dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
tools:layout_editor_absoluteX="176dp"
tools:layout_editor_absoluteY="30dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
</TableLayout> </android.support.constraint.ConstraintLayout>
3.MainActivity.java
package com.example.cse_b_i_ex_2;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
1.activity_main.xml
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number1"
tools:layout_editor_absoluteX="149dp"
tools:layout_editor_absoluteY="28dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<EditText
android:id="@+id/no1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
tools:layout_editor_absoluteX="86dp"
tools:layout_editor_absoluteY="41dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number2"
tools:layout_editor_absoluteX="134dp"
tools:layout_editor_absoluteY="86dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<EditText
android:id="@+id/no2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
tools:layout_editor_absoluteX="75dp"
tools:layout_editor_absoluteY="119dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Result @android:string/defaultMsisdnAlphaTag"
tools:layout_editor_absoluteX="158dp"
tools:layout_editor_absoluteY="158dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<EditText
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
tools:layout_editor_absoluteX="98dp"
tools:layout_editor_absoluteY="167dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add"
tools:layout_editor_absoluteX="132dp"
tools:layout_editor_absoluteY="230dp"
android:onClick="add"/>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subtract"
tools:layout_editor_absoluteX="141dp"
tools:layout_editor_absoluteY="259dp"
android:onClick="subtract" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Divide"
tools:layout_editor_absoluteX="277dp"
tools:layout_editor_absoluteY="318dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
</TableLayout>
</android.support.constraint.ConstraintLayout>
2.MainActivity.java
package com.example.exno3_b_ii;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void add(View view)
{
EditText tv1=(EditText)findViewById(R.id.no1);
EditText tv2=(EditText)findViewById(R.id.no2);
String number1=tv1.getText().toString();
String number2=tv2.getText().toString();
int result=Integer.parseInt(number1)+Integer.parseInt(number2);
TextView txt1=(TextView)findViewById(R.id.result);
txt1.setText(String.valueOf(result));
}
public void subtract(View view)
{
EditText tv1=(EditText)findViewById(R.id.no1);
EditText tv2=(EditText)findViewById(R.id.no2);
String number1=tv1.getText().toString();
String number2=tv2.getText().toString();
int result=Integer.parseInt(number1)-Integer.parseInt(number2);
TextView txt1=(TextView)findViewById(R.id.result);
txt1.setText(String.valueOf(result));
}
public void mul(View view)
{
EditText tv1=(EditText)findViewById(R.id.no1);
EditText tv2=(EditText)findViewById(R.id.no2);
String number1=tv1.getText().toString();
String number2=tv2.getText().toString();
int result=Integer.parseInt(number1)-Integer.parseInt(number2);
TextView txt1=(TextView)findViewById(R.id.result);
txt1.setText(String.valueOf(result));
}
public void div(View view)
{
EditText tv1=(EditText)findViewById(R.id.no1);
EditText tv2=(EditText)findViewById(R.id.no2);
String number1=tv1.getText().toString();
String number2=tv2.getText().toString();
int result=Integer.parseInt(number1)-Integer.parseInt(number2);
TextView txt1=(TextView)findViewById(R.id.result);
txt1.setText(String.valueOf(result));
}
}
1.activity_main.xml
2.MainActivity.java
package com.example.exno_4_b_i;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setContentView(new tss_view(this));
//setContentView();
}
}
3.tss_view.java
package com.example.exno_4_b_i;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
public class tss_view extends View
{
1.activity_main.xml
2.MainActivity.java
package com.example.cse_bii_exno5;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void insert_data(View view)
{
SQLiteDatabase db=this.openOrCreateDatabase("student",MODE_PRIVATE,null);
db.execSQL("CREATE TABLE IF NOT EXISTS biodata(rollno VARCHAR,name
VARCHAR)");
EditText rollno1=(EditText)findViewById(R.id.rollno);
EditText name1=(EditText)findViewById(R.id.name);
TextView tv=(TextView)findViewById(R.id.result);
String txt_rollno;
String txt_name;
txt_rollno=rollno1.getText().toString();
txt_name=name1.getText().toString();
db.execSQL("INSERT INTO biodata(rollno,name) values('"+ txt_rollno +"','"+ txt_name
+"')");
Cursor c=db.rawQuery("select * from biodata",null);
tv.setText("\n DETAILS AFTER INSERTING :\n");
while(c.moveToNext())
{
tv.append("RollNO: "+c.getString(0) + " Name: " + c.getString(1) + "\n");
tv.append("-------------------------\n");
}
}
public void delete_data(View view)
{
SQLiteDatabase db=this.openOrCreateDatabase("student",MODE_PRIVATE,null);
db.execSQL("CREATE TABLE IF NOT EXISTS biodata(rollno VARCHAR,name
VARCHAR)");
EditText rollno1=(EditText)findViewById(R.id.rollno);
EditText name1=(EditText)findViewById(R.id.name);
TextView tv=(TextView)findViewById(R.id.result);
String txt_rollno;
String txt_name;
txt_rollno=rollno1.getText().toString();
txt_name=name1.getText().toString();
db.execSQL("delete from biodata where rollno='"+ txt_rollno +"'");
Cursor c=db.rawQuery("select * from biodata",null);
tv.setText("\n DETAILS AFTER DELETING :\n");
while(c.moveToNext())
{
tv.append("RollNO: "+c.getString(0) + " Name: " + c.getString(1) + "\n");
tv.append("-------------------------\n");
}
}
public void update_data(View view)
{
SQLiteDatabase db=this.openOrCreateDatabase("student",MODE_PRIVATE,null);
db.execSQL("CREATE TABLE IF NOT EXISTS biodata(rollno VARCHAR,name
VARCHAR)");
EditText rollno1=(EditText)findViewById(R.id.rollno);
EditText name1=(EditText)findViewById(R.id.name);
TextView tv=(TextView)findViewById(R.id.result);
String txt_rollno;
String txt_name;
txt_rollno=rollno1.getText().toString();
txt_name=name1.getText().toString();
db.execSQL("update biodata set name='"+ txt_name + "' where rollno='"+ txt_rollno +"'");
Cursor c=db.rawQuery("select * from biodata",null);
tv.setText("\n DETAILS AFTER DELETING :\n");
while(c.moveToNext())
{
tv.append("RollNO: "+c.getString(0) + " Name: " + c.getString(1) + "\n");
tv.append("-------------------------\n");
}
}
}
6.Develop an application that makes use of RSS Feed
1.activity_main.xml
2.arrays.xml
3.MainActivity.java
package com.example.cse_bii_exno_6;
import android.content.res.Resources;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources res=getResources();
String[] rssfeed=res.getStringArray(R.array.rssfeed);
ListView list=(ListView)findViewById(R.id.listview);
list.setAdapter(new
ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,rssfeed));
}
}
7.Implement an application that implements Multi threading
1.activity_main.xml
2.MainActivity.java
package com.example.bii_exno_7;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
Handler tss_handler=new Handler();
EditText tss_tv1,tss_tv2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tss_tv1=(EditText)findViewById(R.id.no1);
tss_tv2=(EditText)findViewById(R.id.no2);
}
public void thread1()
{
tss_tv1.setText(String.valueOf(Integer.parseInt(tss_tv1.getText().toString())+1));
tss_handler.postDelayed(run,500);
}
public void thread2()
{
tss_tv2.setText(String.valueOf(Integer.parseInt(tss_tv2.getText().toString())+1));
tss_handler.postDelayed(run,500);
}
public void start(View view)
{
tss_handler.postDelayed(run,500);
}
Runnable run=new Runnable() {
@Override
public void run() {
thread1();
thread2();
}
};
}
8.Implement an application that writes data to the SD card
1.activity_main.xml
2.MainActivity.java
package com.example.bii_exno_8;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText text=(EditText) findViewById(R.id.write);
}
public void write(View view)
{
try
{
FileOutputStream fout=openFileOutput("CSE-B.txt",MODE_PRIVATE);
OutputStreamWriter writer1=new OutputStreamWriter(fout);
EditText text=(EditText) findViewById(R.id.write);
writer1.write(text.getText().toString());
writer1.close();
Toast.makeText(getBaseContext(),"File saved
sucessfully",Toast.LENGTH_LONG).show();
}
catch (Exception e)
{
}
}
public void read(View view)
{
try {
FileInputStream filein = openFileInput("CSE-B.txt");
InputStreamReader reader=new InputStreamReader(filein);
char[] inputbuffer=new char[1000];
String txt="";
int charread;
while((charread=reader.read(inputbuffer))>0)
{
String read=String.copyValueOf(inputbuffer,0,charread);
txt+=read;
}
reader.close();
Toast.makeText(getBaseContext(),txt,Toast.LENGTH_LONG).show();
}
catch (Exception e)
{
}
}
}
9.Implement an application that creates an alert upon receiving a message
1.activity_main.xml
package com.example.bii_exno_9;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.app.Notification;
import android.app.NotificationManager;
import android.widget.Button;
1.activity_main.xml
2.MainActivity.java
package com.example.student.maps;
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
LocationManager locationManager;
LocationListener locationListener;
TextView latitude;
TextView longitude;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
latitude = (TextView) findViewById(R.id.lat);
longitude = (TextView) findViewById(R.id.lon);
locationManager = (LocationManager)
this.getSystemService(Context.LOCATION_SERVICE);
locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
latitude.setText("Latitude :"+location.getLatitude());
longitude.setText("Longitude :"+location.getLongitude());
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
};
1.activity_main.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set the time"
android:id="@+id/textView"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/alarm_time"
android:layout_below="@+id/textView"
android:layout_marginTop="33dp"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:id="@+id/button"
android:layout_marginTop="38dp"
android:layout_below="@+id/alarm_time"
android:layout_alignStart="@+id/textView"
android:onClick="start_alarm"/>
</RelativeLayout>
2.Broadcast_receiver.java
package com.example.student.alarm_iiicse_b_ii;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
public class Broadcast_receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context,"alarm is on",Toast.LENGTH_LONG).show();
}
}
3.MainActivity.java
package com.example.student.alarm_iiicse_b_ii;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}