[go: up one dir, main page]

0% found this document useful (0 votes)
33 views52 pages

Mobile Computing Record

Uploaded by

aadhis9633
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)
33 views52 pages

Mobile Computing Record

Uploaded by

aadhis9633
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/ 52

CMS COLLEGE OF SCIENCE AND COMMERCE

(AUTONOMOUS)
(Affiliated to Bharathiar University )

Accredited at the ‘A+ level by NAAC with 3.38 out of 4 (3 rd Cycle) College
with Potential For Excellence Conferred by UGC, New Delhi.

Chinnavedampatti, Coimbatore - 641 049

DEPARTMENT OF COMPUTER APPLICATIONS

PRACTICAL RECORD
MOBILE COMPUTING LAB
DECEMBER 2022

II-MCA
2021-2023 BATCH
CMS COLLEGE OF SCIENCE AND COMMERCE
(AUTONOMOUS)
(Affiliated to Bharathiar University )

Accredited at the ‘A+ level by NAAC with 3.38 out of 4 (3rd Cycle) College
with Potential For Excellence Conferred by UGC, New Delhi.

Chinnavedampatti, Coimbatore - 641 049

REGISTER NO: ________________

Certified that the Bonafide record of work done by

Mr./Ms.______________________

of ___________________ during the year 2021-2023

…………………………….. ...………………………….
Staff In charge HOD

Submitted for the Practical Examination held on __________________at


CMS College of Science & Commerce, Coimbatore-641 049.

…………………………….. ……………………………
Internal Examiner External Examiner
INDEX

S. No DATE NAME OF THE PROGRAM PAGE. SIGNATURE


NO
Design a screen and display the

1 input text in the screen when a 1


button is click

Develop an android application for


2 login windows 5
Create an image gallery for android
3 environment 10
Develop an android application for
4 simple calculator 14
Develop and android application to
5 send message from
22
one mobile phone to another
Develop and application to show the 27
6 google maps on the screen
Develop an application to access the
7 contact details of a mobile phone
36
using android
Develop an application to switch
8 on/off camera from the android 45
mobile phone
1.Design a screen and display the input text in the screen when a button is click
Ex:NO:1
Date:
Aim: To Design a screen and display the input text in the screen when a button is click.

Algorithm:

Step 1: Start the Android program

Step 2: create design view for using XML code

Step 3: Create button and text button for display in the page using java code

Step 4: Display the input when a button is click

Step 5: Stop the Program

1
Design view:

XML Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.toastexample.MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="displayToastMsg"</b>
android:text="Display Toast Message!" />
</RelativeLayout>

2
JAVA CODE:
package com.code2care.toast;

/**
*
* This is a simple example to display a
* toast message in Android when a button
* is being pressed.
*
*/

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

//Display toast on button click


public void displayToast(View view) {

Toast.makeText(MainActivity.this, "Hello Toast Message!",


Toast.LENGTH_LONG).show();

}
}

3
Output:

Result: Thus, the above program has been executed successfully

4
2.Develop an android application for login windows

Ex:NO:2

Date:

AIM: To Develop an android application for login windows.

Algorithm:

Step 1: Start the android program

Step 2: Create log in windows user name and password

Step 3: Create button for display the result

Step 4: Redirecting the login windows

Step 5: Stop the program

5
Design view:

XML Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="106dp"
android:layout_marginTop="32dp"
android:textSize="20dp"
android:text="Login Page" />

<ImageView
android:id="@+id/imageView1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:src="@drawable/penguins" />

6
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="62dp"
android:hint="User Name"
android:ems="10" />

<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:hint="Password"

android:layout_centerVertical="true"
android:ems="10" />

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/editText2"
android:layout_marginTop="34dp"
android:text="Login" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button1"
android:layout_toRightOf="@+id/textView1"
android:text="Reset" />

</RelativeLayout>
package com.example.moon;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
7
public class MainActivity extends Activity {
Button btn_login, btn_reset;
EditText edt_name, edt_pass;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_login = (Button) findViewById(R.id.button1);
btn_reset = (Button) findViewById(R.id.button2);
edt_name = (EditText) findViewById(R.id.editText1);
edt_pass = (EditText) findViewById(R.id.editText2);

btn_login.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
String name = edt_name.getText().toString();
String pass = edt_pass.getText().toString();
Toast.makeText(MainActivity.this, "Name :"+name + "\nPassword
: " + pass,
Toast.LENGTH_LONG).show();

}
});

btn_reset.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
edt_name.setText("");
edt_pass.setText(null);

}
});
}

8
Output:

Result: Thus, the above program has been executed successfully

9
3.Create an image gallery for android environment

Ex:NO:3

Date:

Aim: To Create an image gallery for android environment.

Algorithm:

Step 1: Start the Android program

Step 2: Create Linear layout for design view using XML code

Step 3: Insert the Picture using java code in to Gallery

Step 4: Display the result in Image gallery

Step 5: Stop the Program

10
Design view:

XML code:
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#FFFFFF"
android:layout_width="match_parent"
android:layout_height="wrap_content"&gt;
&lt;ImageView
android:id="@+id/img"
android:adjustViewBounds="true"
android:layout_width="match_parent" /&gt;
&lt;TextView
android:id="@+id/title"
android:layout_gravity="center"
android:textColor="#000"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /&gt;
&lt;/LinearLayout&gt;

11
JAVA code:
public class MyAdapter extends RecyclerView.Adapter&lt;MyAdapter.ViewHolder&gt; {
private ArrayList&lt;CreateList&gt; galleryList;
private Context context;

public MyAdapter(Context context, ArrayList&lt;CreateList&gt; galleryList) {


this.galleryList = galleryList;
this.context = context;
}
@Override
public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.cell_layout,
viewGroup, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(MyAdapter.ViewHolder viewHolder, int i) {
viewHolder.title.setText(galleryList.get(i).getImage_title());
viewHolder.img.setScaleType(ImageView.ScaleType.CENTER_CROP);
viewHolder.img.setImageResource((galleryList.get(i).getImage_ID()));
}
@Override
public int getItemCount() {
return galleryList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
private TextView title;
private ImageView img;
public ViewHolder(View view) {
super(view);

title = (TextView)view.findViewById(R.id.title);
img = (ImageView) view.findViewById(R.id.img);
}
}}

12
Output:

Result: Thus, the above program has been executed successfully

13
4. Develop an android application for simple calculator

Ex:NO:4

Date:

Aim: To Develop an android application for simple calculator.

Algorithm:

Step 1: Start the Android Program

Step 2: Create the Button and text box for design view

Step 3: Create Arithmetic operations for using calculator

Step 4: Display the result in the textbox

Step 5: Stop the Program

14
Design view

XML Code:

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


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="abhiandroid.com.calculater.MainActivity"
android:orientation="vertical"
android:gravity="top"
android:textAlignment="center"
android:background="@android:color/holo_blue_bright"
android:weightSum="1">

<TextView
android:text="@string/enter_two_numbers"
android:layout_width="match_parent"
android:id="@+id/textView"
android:layout_height="30dp"
android:gravity="center_horizontal"
android:textColorLink="?android:attr/editTextColor"
15
tools:textStyle="bold|italic"
android:textStyle="bold|italic"
android:fontFamily="serif"
android:visibility="visible"
android:textSize="24sp"
android:layout_weight="0.07" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/editOp1"
android:textSize="18sp"
android:gravity="center_horizontal"
android:layout_marginBottom="5dp"
android:visibility="visible" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/editOp2"
android:textSize="18sp"
android:gravity="center_horizontal"
android:elevation="1dp" />

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<Button
android:text="+"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:id="@+id/btnadd"
android:layout_weight="0.03" />

<Button
android:text="-"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:id="@+id/btnsub"
android:layout_weight="0.03" />

16
<Button
android:text="*"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:id="@+id/btnmul"
android:layout_weight="0.03"/>

<Button
android:text="/"
android:layout_height="wrap_content"
android:id="@+id/btndiv"
android:layout_width="78dp"
android:layout_weight="0.03" />

<Button
android:text="Clear"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:id="@+id/btnclr"
android:layout_weight="0.03" />
</LinearLayout>

<TextView
android:text="@string/result"
android:layout_width="332dp"
android:id="@+id/textView1"
android:layout_marginTop="10dp"
android:layout_height="50dp"
android:gravity="center_horizontal"
android:textColorLink="?android:attr/editTextColor"
tools:textStyle="bold|italic"
android:textStyle="bold|italic"
android:fontFamily="serif"
android:visibility="visible"
android:textSize="30sp" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/result"
android:textSize="18sp"
android:text="0.00"
android:gravity="center_horizontal" />
</LinearLayout>

17
JAVA CODE:
package abhiandroid.com.calculater;

import android.support.v7.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;

public class MainActivity extends AppCompatActivity {


private EditText opr1;
private EditText opr2;
private Button btnadd;
private Button btnsub;
private Button btnmul;
private Button btndiv;
private Button btnclr;
private TextView txtresult;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
opr1 = (EditText) findViewById(R.id.editOp1);
opr2 = (EditText) findViewById(R.id.editOp2);
btnadd = (Button) findViewById(R.id.btnadd);
btnsub = (Button) findViewById(R.id.btnsub);
btnmul = (Button) findViewById(R.id.btnmul);
btndiv = (Button) findViewById(R.id.btndiv);
btnclr = (Button) findViewById(R.id.btnclr);
txtresult= (TextView) findViewById(R.id.result);
// Addition
btnadd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if((opr1.getText().length()>0) && (opr2.getText().length()>0))
{
double oper1 = Double.parseDouble(opr1.getText().toString());
double oper2 = Double.parseDouble(opr2.getText().toString());
double result = oper1 + oper2;
txtresult.setText(Double.toString(result));
}
else{

18
Toast toast= Toast.makeText(MainActivity.this,"Enter The Required Numbers",Toas
t.LENGTH_LONG);
toast.show();
}
}
});
//Subtraction
btnsub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if((opr1.getText().length()>0) && (opr2.getText().length()>0))
{
double oper1 = Double.parseDouble(opr1.getText().toString());
double oper2 = Double.parseDouble(opr2.getText().toString());
double result = oper1 - oper2;
txtresult.setText(Double.toString(result));
}
else{
Toast toast= Toast.makeText(MainActivity.this,"Enter The Required Numbers",Toas
t.LENGTH_LONG);
toast.show();
}

}
});
// Multiplication
btnmul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if((opr1.getText().length()>0) && (opr2.getText().length()>0))
{
double oper1 = Double.parseDouble(opr1.getText().toString());
double oper2 = Double.parseDouble(opr2.getText().toString());
double result = oper1 * oper2;
txtresult.setText(Double.toString(result));
}
else{
Toast toast= Toast.makeText(MainActivity.this,"Enter The Required Numbers",Toas
t.LENGTH_LONG);
toast.show();
}
}
});
// Division
btndiv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
19
if((opr1.getText().length()>0) && (opr2.getText().length()>0))
{
double oper1 = Double.parseDouble(opr1.getText().toString());
double oper2 = Double.parseDouble(opr2.getText().toString());
double result = oper1 / oper2;
txtresult.setText(Double.toString(result));
}
else{
Toast toast= Toast.makeText(MainActivity.this,"Enter The Required Numbers",Toas
t.LENGTH_LONG);
toast.show();
}
}
});
// Reset Feilds
btnclr.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
opr1.setText("");
opr2.setText("");
txtresult.setText("0.00");
opr1.requestFocus();

}
});

}
}

20
Output

Result: Thus, the above program has been executed successfully

21
5.Develop and android application to send message from
one mobile phone to another

Ex:NO:5

Date:

Aim: To Develop and android application to send message from one mobile phone to another.

Algorithm:

Step 1: Start the Android Program

Step 2: Create the message in one mobile using xml

Step 3: Send the Message to another mobile using java code

Step 4: Display the result to send the message from one mobile to another mobile.

Step 5: Stop the Program

22
Design view:

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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_marginTop="140dp"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
23
android:ems="10"
android:hint="Enter number"
android:inputType="textPersonName" />

<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter message"
android:inputType="textPersonName" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:text="SEND" />
</LinearLayout>

Java code:
package com.example.gfg;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


EditText phonenumber,message;
Button send;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
send=findViewById(R.id.button);
phonenumber=findViewById(R.id.editText);
message=findViewById(R.id.editText2);
24
send.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String number=phonenumber.getText().toString();
String msg=message.getText().toString();
try {
SmsManager smsManager=SmsManager.getDefault();
smsManager.sendTextMessage(number,null,msg,null,null);
Toast.makeText(getApplicationContext(),"Message Sent",Toast.LENGTH_LONG).show();
}catch (Exception e)
{
Toast.makeText(getApplicationContext(),"Some fiedls is
Empty",Toast.LENGTH_LONG).show();
}
}
});
}
}

25
OUTPUT:

Result:
Thus, the above program has been executed successfully

26
6.Develop and application to show the google maps on the screen

Ex:NO:6

Date:

Aim: Develop and application to show the google maps on the screen.

Algorithm:

Step 1: Start the Android Program

Step 2: Create the location view for google maps

Step 3: Create android Map Route for location

Step 4: Find the location using Android Emulator

Step 5: Stop the Program

27
Design view:

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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.abhiandroid.MapRouteExample.MainActivity"
tools:showIn="@layout/activity_main">
<fragment
android:id="@+id/map"

28
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_gravity="center"
android:layout_height="match_parent"
/>
</RelativeLayout>
JAVA code:
package com.abhiandroid.MapRouteExample;
import android.app.ProgressDialog;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.PolylineOptions;

import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class MainActivity extends AppCompatActivity implements OnMapReadyCallback {
SupportMapFragment mapFragment;
GoogleMap mMap;
LatLng origin = new LatLng(30.739834, 76.782702);
LatLng dest = new LatLng(30.705493, 76.801256);
ProgressDialog progressDialog;
29
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
drawPolylines();

private void drawPolylines() {


progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Please Wait, Polyline between two locations is building.");
progressDialog.setCancelable(false);
progressDialog.show();

// Checks, whether start and end locations are captured


// Getting URL to the Google Directions API
String url = getDirectionsUrl(origin, dest);
Log.d("url", url + "");
DownloadTask downloadTask = new DownloadTask();
// Start downloading json data from Google Directions API
downloadTask.execute(url);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@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;
}
30
return super.onOptionsItemSelected(item);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.addMarker(new MarkerOptions()
.position(origin)
.title("LinkedIn")

.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
googleMap.addMarker(new MarkerOptions()
.position(dest));
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(origin, 15));
}
private class DownloadTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... url) {
String data = "";
try {
data = downloadUrl(url[0]);
} catch (Exception e) {
Log.d("Background Task", e.toString());
}
return data;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
ParserTask parserTask = new ParserTask();
parserTask.execute(result);
}
}
/**
* A class to parse the Google Places in JSON format
*/
private class ParserTask extends AsyncTask<String, Integer, List<List<HashMap<String,
String>>>> {
// Parsing the data in non-ui thread
@Override
protected List<List<HashMap<String, String>>> doInBackground(String... jsonData) {
31
JSONObject jObject;
List<List<HashMap<String, String>>> routes = null;
try {
jObject = new JSONObject(jsonData[0]);
DirectionsJSONParser parser = new DirectionsJSONParser();
routes = parser.parse(jObject);
} catch (Exception e) {
e.printStackTrace();
}
return routes;
}
@Override
protected void onPostExecute(List<List<HashMap<String, String>>> result) {
progressDialog.dismiss();
Log.d("result", result.toString());
ArrayList points = null;
PolylineOptions lineOptions = null;

for (int i = 0; i < result.size(); i++) {


points = new ArrayList();
lineOptions = new PolylineOptions();
List<HashMap<String, String>> path = result.get(i);

for (int j = 0; j < path.size(); j++) {


HashMap<String, String> point = path.get(j);

double lat = Double.parseDouble(point.get("lat"));


double lng = Double.parseDouble(point.get("lng"));
LatLng position = new LatLng(lat, lng);

points.add(position);
}

lineOptions.addAll(points);
lineOptions.width(12);
lineOptions.color(Color.RED);
lineOptions.geodesic(true);

// Drawing polyline in the Google Map for the i-th route


32
mMap.addPolyline(lineOptions);
}
}

private String getDirectionsUrl(LatLng origin, LatLng dest) {

// Origin of route
String str_origin = "origin=" + origin.latitude + "," + origin.longitude;

// Destination of route
String str_dest = "destination=" + dest.latitude + "," + dest.longitude;

// Sensor enabled
String sensor = "sensor=false";
String mode = "mode=driving";
// Building the parameters to the web service
String parameters = str_origin + "&" + str_dest + "&" + sensor + "&" + mode;

// Output format
String output = "json";

// Building the url to the web service


String url = "https://maps.googleapis.com/maps/api/directions/" + output + "?" +
parameters;

return url;
}

/**
* A method to download json data from url
*/
private String downloadUrl(String strUrl) throws IOException {
String data = "";
InputStream iStream = null;
HttpURLConnection urlConnection = null;
try {
URL url = new URL(strUrl);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.connect();
iStream = urlConnection.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(iStream));
33
StringBuffer sb = new StringBuffer();

String line = "";


while ((line = br.readLine()) != null) {
sb.append(line);
}
data = sb.toString();
br.close();
Log.d("data", data);

} catch (Exception e) {
Log.d("Exception", e.toString());
} finally {
iStream.close();
urlConnection.disconnect();
}
return data;
}
}

34
Output:

Result:
Thus, the above program has been executed successfully

35
7.Develop an application to access the contact details of a mobile phone
using android

Ex:NO:7

Date:

Aim: To Develop an application to access the contact details of a mobile phone using android

Algorithm:

Step 1: Start the Android Program

Step 2: Create the Relative Layout ,Contact RV Adapter for design view

Step 3: Insert the customer’s name and mobile number in the contact details

Step 4: Display the Contact details using android mobile phone

Step 5: Stop the Program

36
Design view:

XML CODING:

<?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"

android:orientation="vertical"

37
tools:context=".MainActivity">

<!--Recycler view for displaying list of contacts-->

<androidx.recyclerview.widget.RecyclerView

android:id="@+id/idRVContacts"

android:layout_width="match_parent"

android:layout_height="match_parent" />

<!--progress bar for displaying loading-->

<ProgressBar

android:id="@+id/idPBLoading"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true" />

<!--fab for adding a new contact-->

<com.google.android.material.floatingactionbutton.FloatingActionButton

android:id="@+id/idFABadd"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentEnd="true"

android:layout_alignParentBottom="true"

android:layout_margin="20dp"

android:src="@drawable/ic_account"

app:fabCustomSize="40dp"

app:tint="@color/white" />

</RelativeLayout>

38
JAVA CODING:

import android.content.Context;

import android.content.Intent;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.widget.ImageView;

import android.widget.TextView;

import androidx.annotation.NonNull;

import androidx.recyclerview.widget.RecyclerView;

import com.amulyakhare.textdrawable.TextDrawable;

import com.amulyakhare.textdrawable.util.ColorGenerator;

import java.util.ArrayList;

class ContactRVAdapter extends RecyclerView.Adapter<ContactRVAdapter.ViewHolder> {

// creating variables for context and array list.

private Context context;

private ArrayList<ContactsModal> contactsModalArrayList;

// creating a constructor

39
public ContactRVAdapter(Context context, ArrayList<ContactsModal>
contactsModalArrayList) {

this.context = context;

this.contactsModalArrayList = contactsModalArrayList;

@NonNull

@Override

public ContactRVAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup


parent, int viewType) {

// passing our layout file for displaying our card item

return new
ContactRVAdapter.ViewHolder(LayoutInflater.from(context).inflate(R.layout.contacts_rv_ite
m, parent, false));

// below method is use for filtering data in our array list

public void filterList(ArrayList<ContactsModal> filterlist) {

// on below line we are passing filtered

// array list in our original array list

contactsModalArrayList = filterlist;

notifyDataSetChanged();

40
@Override

public void onBindViewHolder(@NonNull ContactRVAdapter.ViewHolder holder, int


position) {

// getting data from array list in our modal.

ContactsModal modal = contactsModalArrayList.get(position);

// on below line we are setting data to our text view.

holder.contactTV.setText(modal.getUserName());

ColorGenerator generator = ColorGenerator.MATERIAL; // or use DEFAULT

// generate random color

int color = generator.getRandomColor();

// below text drawable is a circular.

TextDrawable drawable2 = TextDrawable.builder().beginConfig()

.width(100) // width in px

.height(100) // height in px

.endConfig()

/ as we are building a circular drawable

// we are calling a build round method.

// in that method we are passing our text and color.

.buildRound(modal.getUserName().substring(0, 1), color);

// setting image to our image view on below line.

41
holder.contactIV.setImageDrawable(drawable2);

// on below line we are adding on click listener to our item of recycler view.

holder.itemView.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

// on below line we are opening a new activity and passing data to it.

Intent i = new Intent(context, ContactDetailActivity.class);

i.putExtra("name", modal.getUserName());

i.putExtra("contact", modal.getContactNumber());

// on below line we are starting a new activity,

context.startActivity(i);

});

@Override

public int getItemCount() {

return contactsModalArrayList.size();

public class ViewHolder extends RecyclerView.ViewHolder {

42
// on below line creating a variable

// for our image view and text view.

private ImageView contactIV;

private TextView contactTV;

public ViewHolder(@NonNull View itemView) {

super(itemView);

// initializing our image view and text view.

contactIV = itemView.findViewById(R.id.idIVContact);

contactTV = itemView.findViewById(R.id.idTVContactName);

43
Output:

Result:

Thus, the above program has been executed successfully

44
8.Develop an application to switch on/off camera from the android mobile phone

Ex:NO:7

Date:

Aim: To Develop an application to switch on/off camera from the android mobile phone

Algorithm:

Step 1: Start the Android Program

Step 2: Create the button, text view, Relative layout for design view

Step 3: Insert Camera request for switch on /off using java code

Step 4: Develop the application from android mobile phone

Step 5: Stop the Program

45
Design view:

46
XML code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Take a Photo" >
</Button>

<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/button1"
android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher" >
</ImageView>

</RelativeLayout>

Java code:
package com.example.cam;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity {


private static final int CAMERA_REQUEST = 1888;
ImageView imageView;
Button photoButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
47
imageView = (ImageView) this.findViewById(R.id.imageView1);
photoButton = (Button) this.findViewById(R.id.button1);

photoButton.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});

protected void onActivityResult(int requestCode, int resultCode, Intent data) {


if (requestCode == CAMERA_REQUEST) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}

48
Output :

Result:
Thus, the above program has been executed successfully

49

You might also like