0% found this document useful (0 votes)
11 views

Mobile Computing Practicles

Uploaded by

manasishivarkar
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)
11 views

Mobile Computing Practicles

Uploaded by

manasishivarkar
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/ 9

Practical No.

03

Write an application that draws basic graphical primitives on the screen.

Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView" />
</RelativeLayout>

MainActivity.java:
package com.example.exno3;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.widget.ImageView;
public class MainActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Creating a Bitmap
Bitmap bg = Bitmap.createBitmap(720, 1280, Bitmap.Config.ARGB_8888);
//Setting the Bitmap as background for the ImageView
ImageView i = (ImageView) findViewById(R.id.imageView);
i.setBackgroundDrawable(new BitmapDrawable(bg));
//Creating the Canvas Object
Canvas canvas = new Canvas(bg);
//Creating the Paint Object and set its color & TextSize
Paint paint = new Paint();
paint.setColor(Color.BLUE);
paint.setTextSize(50);
//To draw a Rectangle
canvas.drawText("Rectangle", 420, 150, paint);
canvas.drawRect(400, 200, 650, 700, paint);
//To draw a Circle
canvas.drawText("Circle", 120, 150, paint);
canvas.drawCircle(200, 350, 150, paint);
//To draw a Square
canvas.drawText("Square", 120, 800, paint);
canvas.drawRect(50, 850, 350, 1150, paint);
//To draw a Line canvas.drawText("Line", 480, 800, paint);
canvas.drawLine(520, 850, 520, 1150, paint);
}}
Practical No. 04

Develop a native application that uses GPS location information.

main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/show_Location"
android:layout width="wrap_content"
android:layout height="wrap_content"
android:text="Show_Location"
android:layout_centerVertical="true"
android:layout centerHorizontal="true"/>
</RelativeLayout>

GPStrace.java
package gps.location;
import android.app.AlertDialog;
import android.app.Service;
import android.content.Context; import android.content.DialogInterface;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle; import android.os.IBinder;
import android.provider.Settings;
public class GPStrace extends Service implements LocationListener{
private final Context context;
boolean isGPSEnabled=false;
boolean canGetLocation-false;
boolean isNetworkEnabled=false;
Location location:
double latitude:
double longtitude;
private static final long
MIN DISTANCE CHANGE FOR UPDATES-10;
private static final long MIN_TIME_BW_UPDATES-1000*60*1;
protected LocationManager locationManager:
public GPStrace (Context context)
{
this.context=context; getLocation();
}
public Location getLocation()
{
try{ locationManager=(LocationManager) context.getSystemService(LOCATION_SERVICE);
isGPSEnabled=locationManager.isProviderEnabled (Location Manager.GPS PROVIDER);
isNetworkEnabled=locationManager.isProviderEnabled (Locat ionManager.NETWORK PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) (
}else{
this.canGetLocation=true;
if(isNetworkEnabled) { locationManager.requestLocationUpdates ( LocationManager.NETWORK
PROVIDER, MIN
TIME BW UPDATES,
MIN DISTANCE CHANGE FOR UPDATES,this);
if(locationManager!=null){
location=locationManager.getLast KnownLocation (LocationMa nager.NETWORK PROVIDER);
if(location!=null)(
latitude=location.getLatitude();
longtitude-location.getLongitude();
if(isGPSEnabled) {
if(location==null){
locationManager.requestLocationUpdates (LocationManager.G
PS_PROVIDER, MIN_TIME_BW_UPDATES, MIN DISTANCE CHANGE FOR UPDATES, this);
if (locationManager!=null){
location=locationManager.getLastKnownLocation (LocationMa nager.GPS_PROVIDER);
if (location!=null) {
latitude-location.getLatitude();
longtitude=location.getLongitude();
}
catch (Exception e)
e.printStackTrace();
return location;
}
public void stopUsingGPS () {
if (locationManager!=null) {
locationManager.removeUpdates (GPStrace.this);
}
public double getLatitude () {
if (location!=null){
latitude=location.getLatitude();
return latitude;
public double getLongtiude(){
if (location!=null) (
longtitude=location.getLatitude();
} return longtitude;
public boolean canGetLocation()(
return this.canGetLocation:
public void showSettingAlert(){
AlertDialog.Builder alertDialog=new AlertDialog.Builder(context);
alertDialog.setTitle("GPS is settings");
alertDialog.setMessage("GPS is not enabled. Do you want to go to setting menu?");
alertDialog.setPositiveButton("settings", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) (Intent intent-new Intent (Settings.ACTION
LOCATION SOURCE SETTINGS); context.startActivity(intent);
}});
alertDialog.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int
which) {
alertDialog.show();
@Override
public void onLocationChanged (Location location) {
@Override
public void onProviderDisabled(String provider)
}
@Override
public void onProviderEnabled(String provider) {
@Override
public void onStatusChanged (String provider, int status,
Bundle extras) f
@override
public Binder onBind(Intent intent)
// TODO Auto-generated method stub
return null
}
}
Practical No. 05

Design an android application for frame animation

animation_list.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="@drawable/blank" android:duration="210" />
<item android:drawable="@drawable/logo" android:duration="210" />
<item android:drawable="@drawable/logo1" android:duration="210" />
<item android:drawable="@drawable/logo2" android:duration="210" />
<item android:drawable="@drawable/logo3" android:duration="210" />
<item android:drawable="@drawable/logo4" android:duration="210" />
<item android:drawable="@drawable/logo5" android:duration="210" />
<item android:drawable="@drawable/logo6" android:duration="210" />
<item android:drawable="@drawable/logofinal" android:duration="210" />
</animation-list>

activity_main.xml
<span style="font-size: 13px; text-align: center;">Here we are done with the xml part, see the image below
for reference :-
</span>
<p style="text-align: center;"><a href="<a href="https://www.edureka.co/blog/frame-animation-
inandroid/">https://www.edureka.co/blog/frame-animation-in-android/</a>" target="_blank"><img
class="aligncenter sizefull wp-image-2382" title="XML part in Frame animation" alt="XML part in Frame
animation" src="<a
href="https://d1jnx9ba8s6j9r.cloudfront.net/blog/wpcontent/uploads/2013/02/Project.jpg">https://d1jnx9ba8
s6j9r.cloudfront.net/blog/wpcontent/uploads/2013/02/Project.jpg</a>" width="845" height="603"
/></a></p>
<strong> </strong>
<h2><span style="font-size: large;"><strong>

Outside the onCreate method :</strong></span></h2>


<strong></strong>

Declare the Image View and Animation Drawable


[code lang="java"]
// Declaring an Image View and an Animation Drawable
ImageView view;
AnimationDrawable frameAnimation;

Step 3- Inside the OnCreate method:


• Typecast the Image view
• Typecast the Animation Drawable
• Set the drawable background on the image view
// Typecasting the Image View
view = (ImageView) findViewById(R.id.imageAnimation);
// Setting animation_list.xml as the background of the image view
view.setBackgroundResource(R.drawable.animation_list);
// Typecasting the Animation Drawable
frameAnimation = (AnimationDrawable) view.getBackground();

Step 4- After the onCreate method :


The animation should only run when it is in focus that is when it is visible to the user. Hence define this
method after the
onCreate method.
// Called when Activity becomes visible or invisible to the user
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
// Starting the animation when in Focus
frameAnimation.start();
} else {
// Stoping the animation when not in Focus
frameAnimation.stop();
}
}

You might also like