Vous êtes sur la page 1sur 65

MEFGI Wireless Communication

Practical: 1

Write a program to simulate Fixed TDM. Take 12 stations. Every station has time slice of
417 microseconds. Delay should be 10ms. Also show the uplink and downlink concept.

Program code in NS2:-

#Create a simulator object set ns [new


Simulator]

#Define different colors for data flows (for NAM) $ns color 1 Blue
$ns color 2 Green

#Open the NAM trace file set nf [open


out.nam w] $ns namtrace-all $nf

#Define a 'finish' procedure proc finish {}


{
global ns nf $ns flush-trace
#Close the NAM trace file close $nf
#Execute NAM on the trace file exec nam out.nam &
exit 0
}

#Create four nodes set n0 [$ns node]


set n1 [$ns node] set n2 [$ns node]
set n3 [$ns node] set n4 [$ns node]
set n5 [$ns node]

#Create links between the nodes


$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 1.7Mb 20ms DropTail
$ns duplex-link $n3 $n4 1.7Mb 20ms DropTail
$ns duplex-link $n3 $n5 1.7Mb 20ms DropTail

#Set Queue Size of link (n2-n3) to 10


$ns queue-limit $n2 $n3 10

#Give node position (for NAM)


$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $n3 $n4 orient right-up
$ns duplex-link-op $n3 $n5 orient right-down

Roll No. 1507002009 1|Page


MEFGI Wireless Communication

#Monitor the queue for link (n2-n3). (for NAM)


$ns duplex-link-op $n2 $n3 queuePos 0.5

#Setup a TCP connection set tcp [new


Agent/TCP] $tcp set class_ 2
$ns attach-agent $n0 $tcp set sink [new
Agent/TCPSink] $ns attach-agent $n4 $sink $ns
connect $tcp $sink
$tcp set fid_ 1

#Setup a FTP over TCP connection set ftp [new


Application/FTP] $ftp attach-agent $tcp
$ftp set type_ FTP

#Setup a UDP connection set udp [new


Agent/UDP] $ns attach-agent $n1 $udp set null
[new Agent/Null] $ns attach-agent $n5 $null
$ns connect $udp $null $udp set fid_ 2

#Setup a CBR over UDP connection


set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000 $cbr set rate_ 1mb
$cbr set random_ false

#Schedule events for the CBR and FTP agents $ns at 0.0 "$cbr start"
$ns at 1.0 "$ftp start" $ns at 4.0 "$ftp stop"
$ns at 4.5 "$cbr stop"

#Detach tcp and sink agents (not really necessary)


$ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n4 $sink"

#Call the finish procedure after 5 seconds of simulation time $ns at 3.0 "finish"

#Print CBR packet size and interval


puts "CBR packet size = [$cbr set packet_size_]" puts "CBR interval = [$cbr
set interval_]"

#Run the simulation $ns run

Roll No. 1507002009 2|Page


MEFGI Wireless Communication

Output:

Roll No. 1507002009 3|Page


MEFGI Wireless Communication

Roll No. 1507002009 4|Page


MEFGI Wireless Communication

Practical: 2

Implement AODV protocol.

Program code in NS2:-

# A 100-node example for ad-hoc simulation with AODV

# Define options
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type

set val(mac) Mac/802_11 ;# MAC type


set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 3 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 500 ;# X dimension of topography
set val(y) 400 ;# Y dimension of topography
set val(stop) 150 ;# time of simulation end

#-------Event scheduler object creation--------#

set ns [new Simulator]


#Creating trace file and nam file
set tracefd [open dsr.tr w]
set windowVsTime2 [open win.tr w]
set namtrace [open dsr.nam w]

$ns trace-all $tracefd


$ns namtrace-all-wireless $namtrace $val(x) $val(y)

# set up topography object


set topo [new Topography]

$topo load_flatgrid $val(x) $val(y)

create-god $val(nn)

# configure the nodes


$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \

Roll No. 1507002009 5|Page


MEFGI Wireless Communication

-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace ON

for {set i 0} {$i < $val(nn) } { incr i }


{
set node_($i) [$ns node]
}

# Provide initial location of mobilenodes


$node_(0) set X_ 5.0
$node_(0) set Y_ 5.0
$node_(0) set Z_ 0.0

$node_(1) set X_ 490.0


$node_(1) set Y_ 285.0
$node_(1) set Z_ 0.0

$node_(2) set X_ 150.0


$node_(2) set Y_ 240.0
$node_(2) set Z_ 0.0

# Generation of movements
$ns at 10.0 "$node_(0) setdest 250.0 250.0 3.0"
$ns at 15.0 "$node_(1) setdest 45.0 285.0 5.0"
$ns at 110.0 "$node_(0) setdest 480.0 300.0 5.0"

# Set a TCP connection between node_(0) and node_(1)


set tcp [new Agent/TCP/Newreno]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $node_(0) $tcp
$ns attach-agent $node_(1) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 10.0 "$ftp start"

# Printing the window size


proc plotWindow {tcpSource file} {
global ns

Roll No. 1507002009 6|Page


MEFGI Wireless Communication

set time 0.01


set now [$ns now]
set cwnd [$tcpSource set cwnd_]
puts $file "$now $cwnd"
$ns at [expr $now+$time] "plotWindow $tcpSource $file" }
$ns at 10.1 "plotWindow $tcp $windowVsTime2"

# Define node initial position in nam


for {set i 0} {$i < $val(nn)} { incr i }
{
# 30 defines the node size for nam
$ns initial_node_pos $node_($i) 30
}

# Telling nodes when the simulation ends


for {set i 0} {$i < $val(nn) } { incr i }
{
$ns at $val(stop) "$node_($i) reset";
}

# ending nam and the simulation


$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "stop"
$ns at 150.01 "puts \"end simulation\" ; $ns halt"
proc stop {}
{
global ns tracefd namtrace
$ns flush-trace
close $tracefd
close $namtrace
exec nam dsr.nam &
exit 0
}

$ns run

Roll No. 1507002009 7|Page


MEFGI Wireless Communication

Output:-

Roll No. 1507002009 8|Page


MEFGI Wireless Communication

Roll No. 1507002009 9|Page


MEFGI Wireless Communication

Roll No. 1507002009 10 | P a g e


MEFGI Wireless Communication

Roll No. 1507002009 11 | P a g e


MEFGI Wireless Communication

Roll No. 1507002009 12 | P a g e


MEFGI Wireless Communication

Practical: 3
Implement DSDV protocol.

Program code in NS2:-

# A 100-node example for ad-hoc simulation with AODV

# Define options
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type

set val(mac) Mac/802_11 ;# MAC type


set val(ifq) CMUPriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 3 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(x) 500 ;# X dimension of topography
set val(y) 400 ;# Y dimension of topography
set val(stop) 150 ;# time of simulation end

#-------Event scheduler object creation--------#

set ns [new Simulator]


#Creating trace file and nam file
set tracefd [open dsr.tr w]
set windowVsTime2 [open win.tr w]
set namtrace [open dsr.nam w]

$ns trace-all $tracefd


$ns namtrace-all-wireless $namtrace $val(x) $val(y)

# set up topography object


set topo [new Topography]

$topo load_flatgrid $val(x) $val(y)

create-god $val(nn)

# configure the nodes


$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \

Roll No. 1507002009 13 | P a g e


MEFGI Wireless Communication

-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace ON

for {set i 0} {$i < $val(nn) } { incr i }


{
set node_($i) [$ns node]
}

# Provide initial location of mobilenodes


$node_(0) set X_ 5.0
$node_(0) set Y_ 5.0
$node_(0) set Z_ 0.0

$node_(1) set X_ 490.0


$node_(1) set Y_ 285.0
$node_(1) set Z_ 0.0

$node_(2) set X_ 150.0


$node_(2) set Y_ 240.0
$node_(2) set Z_ 0.0

# Generation of movements
$ns at 10.0 "$node_(0) setdest 250.0 250.0 3.0"
$ns at 15.0 "$node_(1) setdest 45.0 285.0 5.0"
$ns at 110.0 "$node_(0) setdest 480.0 300.0 5.0"

# Set a TCP connection between node_(0) and node_(1)


set tcp [new Agent/TCP/Newreno]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $node_(0) $tcp
$ns attach-agent $node_(1) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 10.0 "$ftp start"

# Printing the window size


proc plotWindow {tcpSource file}
{
global ns

Roll No. 1507002009 14 | P a g e


MEFGI Wireless Communication

set time 0.01


set now [$ns now]
set cwnd [$tcpSource set cwnd_]
puts $file "$now $cwnd"
$ns at [expr $now+$time] "plotWindow $tcpSource $file" }
$ns at 10.1 "plotWindow $tcp $windowVsTime2"

# Define node initial position in nam


for {set i 0} {$i < $val(nn)} { incr i }
{
# 30 defines the node size for nam
$ns initial_node_pos $node_($i) 30
}

# Telling nodes when the simulation ends


for {set i 0} {$i < $val(nn) } { incr i }
{
$ns at $val(stop) "$node_($i) reset";
}

# ending nam and the simulation


$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "stop"
$ns at 150.01 "puts \"end simulation\" ; $ns halt"
proc stop {}
{
global ns tracefd namtrace
$ns flush-trace
close $tracefd
close $namtrace
exec nam dsr.nam &
exit 0
}

$ns run

Roll No. 1507002009 15 | P a g e


MEFGI Wireless Communication

Output:-

Roll No. 1507002009 16 | P a g e


MEFGI Wireless Communication

Roll No. 1507002009 17 | P a g e


MEFGI Wireless Communication

Roll No. 1507002009 18 | P a g e


MEFGI Wireless Communication

Practical: 4

Implement DSR protocol.


Program code in NS2:-

# A 100-node example for ad-hoc simulation with AODV

# Define options
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type

set val(mac) Mac/802_11 ;# MAC type


set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 100 ;# number of mobilenodes
set val(rp) DSR ;# routing protocol
set val(x) 500 ;# X dimension of topography
set val(y) 400 ;# Y dimension of topography
set val(stop) 150 ;# time of simulation end

set ns [new Simulator]


set tracefd [open testAODV.tr w]
set windowVsTime2 [open win.tr w]
set namtrace [open testAODV.nam w]

$ns trace-all $tracefd


$ns namtrace-all-wireless $namtrace $val(x) $val(y)

# set up topography object


set topo [new Topography]

$topo load_flatgrid $val(x) $val(y)

create-god $val(nn)

#
# Create nn mobilenodes [$val(nn)] and attach them to the channel.
#

# configure the nodes


$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \

Roll No. 1507002009 19 | P a g e


MEFGI Wireless Communication

-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace ON

for {set i 0} {$i < $val(nn) } { incr i }


{
set node_($i) [$ns node]
$node_($i) set X_ [ expr 10+round(rand()*480) ]
$node_($i) set Y_ [ expr 10+round(rand()*380) ]
$node_($i) set Z_ 0.0
}

for {set i 0} {$i < $val(nn) } { incr i }


{
$ns at [ expr 15+round(rand()*60) ] "$node_($i) setdest [ expr 10+round(rand()*480) ] [ expr
10+round(rand()*380) ] [ expr 2+round(rand()*15) ]"

# Generation of movements
# $ns at 10.0 "$node_(0) setdest 250.0 250.0 3.0"
# $ns at 15.0 "$node_(1) setdest 45.0 285.0 5.0"
# $ns at 70.0 "$node_(2) setdest 480.0 300.0 5.0"
# $ns at 20.0 "$node_(3) setdest 200.0 200.0 5.0"
# $ns at 25.0 "$node_(4) setdest 50.0 50.0 10.0"
# $ns at 60.0 "$node_(5) setdest 150.0 70.0 2.0"
# $ns at 90.0 "$node_(6) setdest 380.0 150.0 8.0"
# $ns at 42.0 "$node_(7) setdest 200.0 100.0 15.0"
# $ns at 55.0 "$node_(8) setdest 50.0 275.0 5.0"
# $ns at 19.0 "$node_(9) setdest 250.0 250.0 7.0"
# $ns at 90.0 "$node_(10) setdest 150.0 150.0 20.0"
# $ns at 75.0 "$node_(11) setdest 75.0 100.0 5.0"

# Set a TCP connection between node_(2) and node_(11)


set tcp [new Agent/TCP/Newreno]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $node_(2) $tcp
$ns attach-agent $node_(11) $sink
$ns connect $tcp $sink

Roll No. 1507002009 20 | P a g e


MEFGI Wireless Communication

set ftp [new Application/FTP]


$ftp attach-agent $tcp
$ns at 10.0 "$ftp start"

# Printing the window size


proc plotWindow {tcpSource file}
{
global ns
set time 0.01
set now [$ns now]
set cwnd [$tcpSource set cwnd_]
puts $file "$now $cwnd"
$ns at [expr $now+$time] "plotWindow $tcpSource $file"
}
$ns at 10.1 "plotWindow $tcp $windowVsTime2"

# Define node initial position in nam


for {set i 0} {$i < $val(nn)} { incr i }
{
# 30 defines the node size for nam
$ns initial_node_pos $node_($i) 30
}

# Telling nodes when the simulation ends


for {set i 0} {$i < $val(nn) } { incr i }
{
$ns at $val(stop) "$node_($i) reset";
}

# ending nam and the simulation


$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "stop"
$ns at 150.01 "puts \"end simulation\" ; $ns halt"
proc stop {}
{
global ns tracefd namtrace
$ns flush-trace
close $tracefd
close $namtrace
}

$ns run

Roll No. 1507002009 21 | P a g e


MEFGI Wireless Communication

Output:-

Roll No. 1507002009 22 | P a g e


MEFGI Wireless Communication

Roll No. 1507002009 23 | P a g e


MEFGI Wireless Communication

Roll No. 1507002009 24 | P a g e


MEFGI Wireless Communication

Roll No. 1507002009 25 | P a g e


MEFGI Wireless Communication

Practical: 5

Write a program that identifies the devices in the wireless range.

Program code in NS2:-

set ns [new Simulator]


set tracefile [open out.tr w]
$ns trace-all $tracefile
set nf [open out.nam w]
$ns namtrace-all $nf
proc finish {}
{
global ns tracefile nf
$ns flush-trace
close $nf
close $tracefile
exec nam out.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
$ns simplex-link $n0 $n1 1Mb 10ms DropTail
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set cbr[new Application/Traffic/CBR]
$cbr attach-agent $udp0
set null0 [new Agent/Null]
$ns attach-agent $n1 $null0
$ns connect $udp0 $null0
$ns at 1.0 "$cbr start"
$ns at 3.0 "finish"
$ns run

Output:-
Roll No. 1507002009 26 | P a g e
MEFGI Wireless Communication

Roll No. 1507002009 27 | P a g e


MEFGI Wireless Communication

Roll No. 1507002009 28 | P a g e


MEFGI Wireless Communication

Practical: 6
Implement an Android application that converts Fahrenheit to Celsius and Celsius to
Fahrenheit.

MyActivity.java
package com.example.sairam.myapplication;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MyActivity extends ActionBarActivity
{
EditText e1,e2;
Button b1;
String str;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
b1=(Button) findViewById(R.id.convert);
e1=(EditText) findViewById(R.id.fahernhit);
e2=(EditText) findViewById(R.id.celsius);
final Float[] num = new Float[1];
b1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)

Roll No. 1507002009 29 | P a g e


MEFGI Wireless Communication

{
if("".equals(e1.getText().toString()))
{
num[0] = Float.parseFloat(e2.getText().toString());
num[0] = new Float((num[0]*1.8)+32);
str=String.valueOf(num[0]);
e1.setText(str);
}
else if("".equals(e2.getText().toString()))
{
num[0] = Float.parseFloat(e1.getText().toString());
num[0] = new Float((num[0] - 32.0) / 1.8);
str=String.valueOf(num[0]);
e2.setText(str);

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

activity_my.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

Roll No. 1507002009 30 | P a g e


MEFGI Wireless Communication

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MyActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="29dp"
android:text="Fahernhit"
android:id="@+id/textview1"
android:layout_weight="0.92"
android:autoText="false"
android:textSize="20dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/fahernhit"
android:layout_below="@+id/textview1"
android:layout_alignParentStart="true"
android:layout_alignEnd="@+id/textview1"
android:autoText="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="29dp"
android:text="Celsius"
android:id="@+id/textView2"

Roll No. 1507002009 31 | P a g e


MEFGI Wireless Communication

android:layout_below="@+id/fahernhit"
android:layout_alignParentStart="true"
android:layout_alignEnd="@+id/fahernhit"
android:textSize="20dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/celsius"
android:layout_below="@+id/textView2"
android:layout_alignParentStart="true"
android:layout_alignEnd="@+id/textView2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Convert"
android:id="@+id/convert"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>

Roll No. 1507002009 32 | P a g e


MEFGI Wireless Communication

Output:-

Roll No. 1507002009 33 | P a g e


MEFGI Wireless Communication

Practical: 7
Implement an Android application that takes name as input. It gives radio buttons with
list of subjects. User need to choose 1 subject. Then there are list of books user has to
choose. Then display name, choice of subject and selected subjects.
MyActivity.java
package com.example.sairam.prc2;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
public class MyActivity extends ActionBarActivity {
RadioButton rb;
RadioGroup rg;
Spinner sp1;
EditText e1;
TextView t1;
Button b1;

@Override

Roll No. 1507002009 34 | P a g e


MEFGI Wireless Communication

protected void onCreate(Bundle savedInstanceState)


{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
rg=(RadioGroup) findViewById(R.id.radioGroup1);
e1=(EditText)findViewById(R.id.Name);
t1=(TextView) findViewById(R.id.disp);
b1=(Button)findViewById(R.id.submit);
sp1=(Spinner) findViewById(R.id.Bookname);
List<String> Book = new ArrayList<String>();
Book.add("Mobile Computing");
Book.add("Mobile communication");
Book.add("Android wireless application development");
Book.add("The complete reference of java");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, Book);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
sp1.setAdapter(dataAdapter);
final String[] item = new String[1];
sp1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l)
{
item[0] = adapterView.getItemAtPosition(i).toString();
}

@Override

Roll No. 1507002009 35 | P a g e


MEFGI Wireless Communication

public void onNothingSelected(AdapterView<?> adapterView)


{
}
});
b1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
String str="NAME:" +e1.getText().toString();
int selectedId=rg.getCheckedRadioButtonId();
rb=(RadioButton)findViewById(selectedId);
str=str+"\nSUBJECT:"+rb.getText();
str=str+"\nBOOK:"+item[0];
t1.setVisibility(View.VISIBLE);
t1.setText(str);
}
}
);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.my, menu);
return true;
}
}

Roll No. 1507002009 36 | P a g e


MEFGI Wireless Communication

activity_my.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/SCROLLER_ID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MyActivity"
android:id="@+id/rel1">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/Name"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:hint="Enter Name" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"

Roll No. 1507002009 37 | P a g e


MEFGI Wireless Communication

android:text="Choose Subject"
android:id="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="20dp"
android:layout_below="@+id/Name"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:id="@+id/radioGroup1"
android:layout_below="@+id/textView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Wireless Communication"
android:id="@+id/radioButton1"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android"
android:id="@+id/radioButton2"

Roll No. 1507002009 38 | P a g e


MEFGI Wireless Communication

android:layout_below="@+id/radioButton1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Java"
android:id="@+id/radioButton3"
android:layout_below="@+id/radioButton2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Choose Book"
android:id="@+id/textView2"
android:textSize="20dp"
android:layout_below="@+id/radioGroup1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/Bookname"
android:layout_below="@+id/textView2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button

Roll No. 1507002009 39 | P a g e


MEFGI Wireless Communication

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="submit"
android:id="@+id/submit"
android:layout_below="@+id/Bookname"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/disp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/submit"
android:textSize="20dp"
android:visibility="invisible" />
</RelativeLayout>
</ScrollView>

Roll No. 1507002009 40 | P a g e


MEFGI Wireless Communication

Output :-

Roll No. 1507002009 41 | P a g e


MEFGI Wireless Communication

Practical: 8
Implement Multiple Row Scrolling Application.
MyActivity.java
package com.example.sairam.practical3;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MyActivity extends ActionBarActivity
{
String[] mobileArray = {"Wireless Communication","Computer Algorithm","Artifical
Inteligence","Research Skill","Numerical Method","Distributed Operating System",
"Data warehousing and Data Mining","Android","Image processing",".NET","Advance Java","Computer
Network","Data File Structure"
};
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.listview_layout, mobileArray);

ListView listView = (ListView) findViewById(R.id.mobile_list);


listView.setAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
Roll No. 1507002009 42 | P a g e
MEFGI Wireless Communication

getMenuInflater().inflate(R.menu.my, menu);
return true;
}
}

activity_my.xml
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MyActivity">
<ListView
android:id="@+id/mobile_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</RelativeLayout>
listview_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Single List Item Design -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"

Roll No. 1507002009 43 | P a g e


MEFGI Wireless Communication

android:textSize="16dip"
android:textStyle="bold" >
</TextView>

Output :-

Roll No. 1507002009 44 | P a g e


MEFGI Wireless Communication

Practical: 9
Implement an Android Application that creates a menu with following options. 

(a)Display menu items for example – List the choice of food items. Display list of selected
items. Calculate the bill.


Activity_Main.xml
<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:background="@drawable/bg"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.namaskarrestaurent.South_Indian" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Menu"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/button1"

Roll No. 1507002009 45 | P a g e


MEFGI Wireless Communication

android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TableRow
android:layout_margin="1dp"
android:id="@+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Items"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

Roll No. 1507002009 46 | P a g e


MEFGI Wireless Communication

android:text="Price”
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Quantity”
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
<TableRow
android:layout_margin="1dp"
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:text="Sada Dhosa" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rs.80"

android:textAppearance="?android:attr/textAppearanceMedium" />

Roll No. 1507002009 47 | P a g e


MEFGI Wireless Communication

<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="28dp" />
</TableRow>
<TableRow
android:layout_margin="1dp"
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:text="Masala Dhosa" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rs.100"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="@+id/spinner2"
android:layout_width="wrap_content"
android:layout_height="28dp" />
</TableRow>

<TableRow

Roll No. 1507002009 48 | P a g e


MEFGI Wireless Communication

android:layout_margin="1dp"
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<CheckBox
android:id="@+id/checkBox3”
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:text="Butter Dhosa" />
<TextView
android:id="@+id/textView”
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rs. 120"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="@+id/spinner3"
android:layout_width="wrap_content"
android:layout_height="28dp" />
</TableRow>
<TableRow
android:id="@+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp" >
<CheckBox
android:id="@+id/checkBox4"
android:layout_width="wrap_content"

Roll No. 1507002009 49 | P a g e


MEFGI Wireless Communication

android:layout_height="wrap_content"
android:textSize="18dp"
android:text="Spring Dhosa" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rs. 150"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="@+id/spinner4"
android:layout_width="wrap_content"
android:layout_height="22dp" />
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView9"
android:layout_centerHorizontal="true"
android:text="Calculate" />
<TextView
android:id="@+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"

Roll No. 1507002009 50 | P a g e


MEFGI Wireless Communication

android:layout_alignParentBottom="true"
android:layout_marginBottom="66dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
Activity_Main.java
package com.example.namaskarrestaurent;
import java.util.ArrayList;
import java.util.List;
import android.R.integer;
import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class South_Indian extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_south__indian);

Roll No. 1507002009 51 | P a g e


MEFGI Wireless Communication

final Spinner s1 = (Spinner)findViewById(R.id.spinner1);


final Spinner s2 = (Spinner)findViewById(R.id.spinner2);
final Spinner s3 = (Spinner)findViewById(R.id.spinner3);
final Spinner s4 = (Spinner)findViewById(R.id.spinner4);
final CheckBox c1 = (CheckBox)findViewById(R.id.checkBox1);
final CheckBox c2 = (CheckBox)findViewById(R.id.checkBox2);
final CheckBox c3 = (CheckBox)findViewById(R.id.checkBox3);
final CheckBox c4 = (CheckBox)findViewById(R.id.checkBox4);
List<Integer> ls = new ArrayList<Integer>();
ls.add(1);
ls.add(2);
ls.add(3);
ls.add(4);
ls.add(5);
ls.add(6);
ls.add(7);
ls.add(8);
ls.add(9);
ls.add(10);
ls.add(11);
ls.add(12);
ls.add(13);
ls.add(14);
ArrayAdapter<Integer> ad = new
ArrayAdapter<Integer>(this,android.R.layout.simple_spinner_dropdown_item,ls);
ad.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(ad);
s2.setAdapter(ad);
s3.setAdapter(ad);
s4.setAdapter(ad);

Roll No. 1507002009 52 | P a g e


MEFGI Wireless Communication

Button b1 = (Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
int i = 0;
if (c1.isChecked()){
i = i+(80 * Integer.parseInt(s1.getSelectedItem().toString()));
}
if (c2.isChecked()){
i = i+(100 * Integer.parseInt(s2.getSelectedItem().toString()));
}
if (c3.isChecked()){
i = i+(120 * Integer.parseInt(s3.getSelectedItem().toString()));
}
if (c4.isChecked()){
i = i+(150 * Integer.parseInt(s4.getSelectedItem().toString()));
}
Intent in = new Intent(South_Indian.this,Namaskar.class);
in.putExtra("Data",String.valueOf(i));
//startActivity(in);
TextView t = (TextView)findViewById(R.id.textView9);
t.setText("Total bill is "+String.valueOf(i));
i = 0;
}
});
}

@Override

Roll No. 1507002009 53 | P a g e


MEFGI Wireless Communication

public boolean onCreateOptionsMenu(Menu menu) {


// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.south__indian, 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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}}

Output:-

Roll No. 1507002009 54 | P a g e


MEFGI Wireless Communication

Practical: 10
Use Table Layout to display the buttons with images on them. When you click on that
image it should be displayed in large area.

Main Activity_multiple.java
package com.example.prac10i;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity_multiple extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity_multiple);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_activity_multiple, menu);
return true;
}
}
Main Activity_multiple.xml
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="@+id/tableRow4"
android:layout_weight="1" >
<ImageButton
android:id="@+id/button_one"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
Roll No. 1507002009 55 | P a g e
MEFGI Wireless Communication

android:adjustViewBounds="true"
android:background="@drawable/ic_launcher"
android:scaleType="fitCenter"
android:src="@drawable/ic_launcher" />
<ImageButton
android:id="@+id/button_two"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="@drawable/ic_launcher"
android:scaleType="fitCenter"
android:src="@drawable/ic_launcher" />
</TableRow>
<TableRow
android:id="@+id/tableRow4"
android:layout_weight="1" >
<ImageButton
android:id="@+id/button_three"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="@drawable/ic_launcher"
android:scaleType="fitCenter"
android:src="@drawable/ic_launcher" />
</TableRow>
</TableLayout>

Output:-

Roll No. 1507002009 56 | P a g e


MEFGI Wireless Communication

Practical: 11
Create a table with student information. Apply the operations add, modify, delete.
MainActivity.java
package com.example.prac11;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener{
EditText name, phone_no, id;
Button addButton, deleteButton;
TextView tv;
List<StudentsModel> list = new ArrayList<StudentsModel>();
DatabaseHelper db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = new DatabaseHelper(getApplicationContext());
name = (EditText) findViewById(R.id.editText1);
phone_no = (EditText) findViewById(R.id.editText2);
id = (EditText) findViewById(R.id.editText3);
addButton = (Button) findViewById(R.id.add);
deleteButton = (Button) findViewById(R.id.delete);
tv = (TextView) findViewById(R.id.tv);
addButton.setOnClickListener(this);
deleteButton.setOnClickListener(this);

//add some students


StudentsModel student = new StudentsModel();
student.name = "Rajat";
student.phone_number = "999999999";
db.addStudentDetail(student);
student.name = "Eric";
student.phone_number = "8888888888";
db.addStudentDetail(student);
list = db.getAllStudentsList();
print(list);

Roll No. 1507002009 57 | P a g e


MEFGI Wireless Communication

private void print(List<StudentsModel> list) {


// TODO Auto-generated method stub
String value = "";
for(StudentsModel sm : list){
value = value+"id: "+sm.id+", name: "+sm.name+" Ph_no:
"+sm.phone_number+"\n";
}
tv.setText(value);
}
public void onClick(View v) {
// TODO Auto-generated method stub
if(v == findViewById(R.id.delete)){
tv.setText("");
String student_id = id.getText().toString();
db.deleteEntry(Integer.parseInt(student_id));
list = db.getAllStudentsList();
print(list);
}
if(v == findViewById(R.id.add)){
tv.setText("");
StudentsModel student = new StudentsModel();
student.name = name.getText().toString();
student.phone_number = phone_no.getText().toString();
db.addStudentDetail(student);
list = db.getAllStudentsList();
print(list);
}
}
}
StudentsModel.java
package com.example.prac11;

public class StudentsModel {

public int id;


public String name;
public String phone_number;

public StudentsModel(int id, String name, String phone_number) {


// TODO Auto-generated constructor stub
this.id = id;
this.name = name;
this.phone_number = phone_number;
}

Roll No. 1507002009 58 | P a g e


MEFGI Wireless Communication

public StudentsModel(){

}
}
DatabaseHelper.java
package com.example.prac11;

import android.content.Context;
import java.util.ArrayList;
import java.util.List;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DatabaseHelper extends SQLiteOpenHelper {


public static String DATABASE_NAME = "student_database";
private static final int DATABASE_VERSION = 1;
private static final String TABLE_STUDENTS = "students";
private static final String KEY_ID = "id";
private static final String KEY_NAME = "name";
private static final String KEY_PHONENUMBER = "phone_number";
public static String TAG = "tag";
private static final String CREATE_TABLE_STUDENTS = "CREATE TABLE "
+ TABLE_STUDENTS + "(" + KEY_ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_NAME + " TEXT,"
+ KEY_PHONENUMBER + " TEXT );";

public DatabaseHelper(Context context) {


super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

public void onCreate(SQLiteDatabase db) {


db.execSQL(CREATE_TABLE_STUDENTS); // create students table
}

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {


db.execSQL("DROP TABLE IF EXISTS " + CREATE_TABLE_STUDENTS);
onCreate(db);
}

public long addStudentDetail1(StudentsModel student) {


SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_NAME, student.name);

Roll No. 1507002009 59 | P a g e


MEFGI Wireless Communication

values.put(KEY_PHONENUMBER, student.phone_number);
long insert = db.insert(TABLE_STUDENTS, null, values);

return insert;
}
public int updateEntry(StudentsModel student) {
SQLiteDatabase db = this.getWritableDatabase();

ContentValues values = new ContentValues();


values.put(KEY_NAME, student.name);
values.put(KEY_PHONENUMBER, student.phone_number);

// update row in students table base on students.is value


return db.update(TABLE_STUDENTS, values, KEY_ID + " = ?",
new String[] { String.valueOf(student.id) });
}
public void deleteEntry(long id) {

// delete row in students table based on id


SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_STUDENTS, KEY_ID + " = ?",
new String[] { String.valueOf(id) });
}
public StudentsModel getStudent(long id) {
SQLiteDatabase db = this.getReadableDatabase();

String selectQuery = "SELECT * FROM " + TABLE_STUDENTS + " WHERE


+ KEY_ID + " = " + id;
Log.d(TAG, selectQuery);

Cursor c = db.rawQuery(selectQuery, null);

if (c != null)
c.moveToFirst();

StudentsModel students = new StudentsModel();


students.id = c.getInt(c.getColumnIndex(KEY_ID));
students.phone_number=c.getString(c.getColumnIndex(KEY_PHONENUMBER));
students.name = c.getString(c.getColumnIndex(KEY_NAME));

return students;
}
public List<StudentsModel> getAllStudentsList() {
List<StudentsModel> studentsArrayList = new ArrayList<StudentsModel>();

String selectQuery = "SELECT * FROM " + TABLE_STUDENTS;


Log.d(TAG, selectQuery);

Roll No. 1507002009 60 | P a g e


MEFGI Wireless Communication

SQLiteDatabase db = this.getReadableDatabase();
Cursor c = db.rawQuery(selectQuery, null);

if (c.moveToFirst()) {
do {
StudentsModel students = new StudentsModel();
students.id = c.getInt(c.getColumnIndex(KEY_ID));
students.phone_number =
c.getString(c.getColumnIndex(KEY_PHONENUMBER));
students.name = c.getString(c.getColumnIndex(KEY_NAME));
studentsArrayList.add(students);
}
while (c.moveToNext());
}

return studentsArrayList;
}

public void addStudentDetail(StudentsModel student) {

}
}

Output:-

Roll No. 1507002009 61 | P a g e


MEFGI Wireless Communication

Practical: 12
Implement an Android Application that rotates a cube in clockwise direction for 1 minute
and after that cube in the anticlockwise direction.

MainActivity.java

package com.example.prac12;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.Window;
import android.view.WindowManager;

public class MainActivity extends Activity {


private Runnable runnable;

public void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_CONTEXT_MENU);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
final GLSurfaceView view = new GLSurfaceView(this);
view.setRenderer(new OpenGLRenderer());
setContentView(view);

runnable =new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub
try
{
view.setRenderer(new OpenGLRenderer());
Thread.sleep(10);
finish();

}
catch(Exception e)
{
e.printStackTrace();
}
}
};
try
{
Thread t=new Thread(null,runnable);

Roll No. 1507002009 62 | P a g e


MEFGI Wireless Communication

t.start();
view.setRenderer(new OpenGLRenderer1());
// Intent i=new Intent(this,OpenGLRenderer.class);
// startActivity(i);
}
catch(Exception e)
{
}
}
}

OpenGLRenderer.java
package com.example.prac12;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLSurfaceView.Renderer;
import android.opengl.GLU;
public class OpenGLRenderer implements Renderer {
private Square square;
private float angle = 0;
public OpenGLRenderer() {
square = new Square();
}
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glTranslatef(0, 0, -10);
gl.glPushMatrix();
gl.glRotatef(angle, 0, 0, 1);
square.draw(gl);
. gl.glPopMatrix();
square.draw(gl);
gl.glPopMatrix();
angle++;

Roll No. 1507002009 63 | P a g e


MEFGI Wireless Communication

}
public void onSurfaceChanged(GL10 gl, int width, int height) {
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL10.GL_PROJECTION);
// Reset the projection matrix
gl.glLoadIdentity();
GLU.gluPerspective(gl, 45.0f, (float) width / (float) height, 0.1f, 100.0f);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
}
Public void onSurfaceCreated(GL10 gl, EGLConfig config) {
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
gl.glShadeModel(GL10.GL_SMOOTH);
gl.glClearDepthf(1.0f);
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glDepthFunc(GL10.GL_LEQUAL);
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST); }
}

Output:-

Roll No. 1507002009 64 | P a g e


MEFGI Wireless Communication

Roll No. 1507002009 65 | P a g e

Vous aimerez peut-être aussi