0% found this document useful (0 votes)
65 views19 pages

Practical No.1: UI Code

The document describes an Android application that gets the device's location and determines if it is within a specified area. The UI layout contains text views and a button. The source code implements location listener methods to get latitude and longitude on button click. It checks if the coordinates are within the bounds of 36-38 latitude and 118-122 longitude, and displays the result in a text view. The app requires location permissions defined in the manifest file.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
0% found this document useful (0 votes)
65 views19 pages

Practical No.1: UI Code

The document describes an Android application that gets the device's location and determines if it is within a specified area. The UI layout contains text views and a button. The source code implements location listener methods to get latitude and longitude on button click. It checks if the coordinates are within the bounds of 36-38 latitude and 118-122 longitude, and displays the result in a text view. The app requires location permissions defined in the manifest file.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
You are on page 1/ 19

Practical No.

1
UI Code :-

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


<RelativeLayoutxmlns: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.prashant.locationmsg.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/textView3"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="96dp" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Longitude and Latitude"
android:id="@+id/button"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/textView2"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/button"
android:layout_alignEnd="@+id/button" />
</RelativeLayout>

Source Code:-
package com.example.prashant.locationmsg;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;

public class
MainActivityextendsAppCompatActivityimplementsLocationListener {

TextViewt1, t2, t3;


Button b1;
protected LocationManagerlocationManager;
protected LocationListenerlocationListener;
double lat, longg;

private GoogleApiClientclient;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

t1 = (TextView) findViewById(R.id.textView);
t2 = (TextView) findViewById(R.id.textView3);
t3 = (TextView) findViewById(R.id.textView2);
b1 = (Button) findViewById(R.id.button);

b1.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {


t1.setText("Latitude = " + lat);
t2.setText("Longitude = " + longg);
if (lat<38 &&lat>36 &&longg<122 &&longg>118) {
t3.setText("In-Side The Area");
} else {
t3.setText("Out-Side The Area");
}
}
});

locationManager= (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED&&ActivityCompat.checkSelfPermi
ssion(this, Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
return;
}
locationManager.requestLocationUpdates(LocationManager.GPS_PROVI
DER, 0, 0, this);
client = new
GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}

public void onLocationChanged(Location location) {


lat= location.getLatitude();
longg= location.getLongitude();
Log.d("" + lat, "" + lat);
Log.d("" + longg, "" + longg);

if (lat== 38 &&longg== 118) {


t3.setText("You Are at Perfect Place !!!!");
} else {
t3.setText("You are not at Perfect Place !!!!");
}
public void onProviderDisabled(String provider) {
Log.d("Latitude", "disable");
}

public void onProviderEnabled(String provider) {


Log.d("Latitude", "enable");
}

public void onStatusChanged(String provider, intstatus, Bundle


extras) {
Log.d("Latitude", "status");
}

public void onStart() {


super.onStart();

client.connect();
Action viewAction = Action.newAction(
Action.TYPE_VIEW,
“Main Page",
Uri.parse("http://host/path"),
Uri.parse("android-
app://com.example.prashant.locationmsg/http/host/path")
);
AppIndex.AppIndexApi.start(client, viewAction);
}

public void onStop() {


super.onStop();

Action viewAction = Action.newAction(


Action.TYPE_VIEW,
"Main Page",
Uri.parse("http://host/path"),
Uri.parse("android-
app://com.example.prashant.locationmsg/http/host/path")
);
AppIndex.AppIndexApi.end(client, viewAction);
client.disconnect();
}
}

Output:-

Permission :-
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.prashant.locationmsg">
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION" />

<uses-permission android:name="android.permission.INTERNET" />


<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>

</manifest>
Practical No.2
UI Code:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayoutxmlns: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.prashant.gpstrace.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/textView3"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="96dp" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Longitude and Latitude"
android:id="@+id/button"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/textView2"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/button"
android:layout_alignEnd="@+id/button" />
</RelativeLayout>

Source Code:-
package com.example.prashant.gpstrace;
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class
MainActivityextendsAppCompatActivityimplementsLocationListener {

TextViewt1, t2, t3;


Button b1;
protected LocationManagerlocationManager;
protected LocationListenerlocationListener;
double lat, longg;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

t1 = (TextView) findViewById(R.id.textView);
t2 = (TextView) findViewById(R.id.textView3);
t3 = (TextView) findViewById(R.id.textView2);
b1 = (Button) findViewById(R.id.button);

b1.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {


t1.setText("Latitude = " + lat);
t2.setText("Longitude = "+ longg);

if(lat<38 &&lat>36 &&longg<122 &&longg>118)


{
t3.setText("In-Side The Area");
}
else
{
t3.setText("Out-Side The Area");
}
}
});

locationManager= (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED&&ActivityCompat.checkSelfPermi
ssion(this, Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
return; }
locationManager.requestLocationUpdates(LocationManager.GPS_PROVI
DER, 0, 0, this);
}

@Override
public void onLocationChanged(Location location) {
lat=location.getLatitude();
longg= location.getLongitude();
Log.d(""+lat,""+lat);
Log.d(""+longg,""+longg);

if(lat<38 &&lat>36 &&longg<122 &&longg>118)


{
t3.setText("In-Side The Area");
}
else
{
t3.setText("Out-Side The Area");
}

@Override
public void onProviderDisabled(String provider) {
Log.d("Latitude","disable");
}

@Override
public void onProviderEnabled(String provider) {
Log.d("Latitude","enable");
}

@Override
public void onStatusChanged(String provider, intstatus, Bundle
extras) {
Log.d("Latitude","status");
}
}

Output:-

Permission :-
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.prashant.gpstrace">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION" />

<uses-permission android:name="android.permission.INTERNET" />


</manifest>
Practical No.3
Required Software:-
1) JDK 1.6

2) XAMPP Server

3) Mysql-java connector

4) OpenGTS application.

http://www.opengts.org/

Set Environment Variables:-

5) Open command Prompt and go to D:\OpenGTS_2.6.2


6) Type command ant all
7) Type command ant track
8) Type command ant track.deploy
9) Type command initdb.bat –rootUser=root –pass=123456789
10) Type Command admin.bat Account –account:admin –pass:123456 –create
11) Type url 127.0.0.0:8080/track/Track and login with admin and 123456
Practical No.4

Context-awareness is a key concept in ubiquitous computing. The Java Context-


Awareness Framework (JCAF) is a Java-based context-awareness infrastructure and
programming API for creating context-aware applications
https://sourceforge.net/projects/jcaf/
Practical No.5
Code :-
import java.awt.*;
importjava.awt.event.*;

public class CloseableSimpleWarning extends Frame implements


WindowListener
{

static private final intframe_height = 150;


static private final intframe_width = 250;

publicCloseableSimpleWarning()
{
//setBackground(Color.red);
//setForeground(Color.black);
setTitle("Warning");
setSize(frame_width, frame_height);
addWindowListener(this);
}
public void windowClosing (WindowEvent e)
{
System.exit(0);
}
public void windowClosed (WindowEvent e)
{
System.exit(0);
}
public void windowIconified (WindowEvent e)
{
System.exit(0);
}
public void windowDeiconified (WindowEvent e)
{
System.exit(0);
}
public void windowOpened (WindowEvent e)
{
System.exit(0);
}
public void windowActivated (WindowEvent e)
{
System.exit(0);
}

public void windowDeactivated (WindowEvent e)


{
System.exit(0);
}
public static void main(String [] args)
{
CloseableSimpleWarning f = new CloseableSimpleWarning();

f.show();
}
}

Reference :-
http://www.dcs.gla.ac.uk/~johnson/teaching/hci-java/course.html
http://www.paneurouni.com/files/sk/projektesf/hci-design-gui-
programming-java-vyber.pdf
Practical No.6
Download Java Card Sdk from
http://www.oracle.com/technetwork/java/embedded/javacard/downloa
ds/javacard-sdk-2043229.html
Install in Netbeans as plugin :-
Tools -> Plugin

Create an application
Code:-
package classicapplet2;
importjavacard.framework.*;

public class ClassicApplet2 extends Applet {

private byte[] received;


private static final short MAX_LENGTH = 256;
private static final byte[] helloFidesmo =
{(byte)'H',(byte)'e',(byte)'l',(byte)'l',(byte)'o',(byte)'
',(byte)'F',(byte)'i',(byte)'d',(byte)'e',(byte)'s',(byte)'m',(b
yte)'o',(byte)'!'};

public static void install(byte[] bArray, short bOffset, byte


bLength) {
new ClassicApplet2();
}

protected ClassicApplet2() {
received = new byte[MAX_LENGTH];
register();
}

public void process(APDU apdu) {


//Insert your code here
byte buffer[] = apdu.getBuffer();
short length = (short) helloFidesmo.length;

Util.arrayCopyNonAtomic(helloFidesmo, (short)0, buffer,


(short)0, (short)length);
apdu.setOutgoingAndSend((short)0, length);
}
}
s

You might also like