Mobile Computing Practicles
Mobile Computing Practicles
03
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
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
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>