Professional Documents
Culture Documents
.java file
package com.example.practical_15;
import
android.content.BroadcastReceiver
;import android.content.Context;
import
android.content.Intent;
import
android.content.IntentFilter
;import
android.graphics.Color;
import android.os.Bundle;
import
android.widget.LinearLayout
;import
android.widget.TextView;
import
android.widget.Toast;
import
androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends
AppCompatActivity {
private LinearLayout
mainLayout;private TextView
textView; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
)
mainLayout = (LinearLayout) findViewById(R.id.main_layout);
textView = (TextView) findViewById(R.id.textview);
registerReceiver(shutdownReceiver,
new IntentFilter(Intent.ACTION_SHUTDOWN));
}
private BroadcastReceiver shutdownReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:layout_marginLeft="15dp"
android:layout_marginTop="50dp"
android:layout_gravity="center"
android:textColor="#171717"
android:layout_marginRight="15dp"
android:text="Shuffle your device
to change the background color"
/>
</LinearLayout>
Output:
lOM oA R c P S D| 35 59 439 5
Practical No: 21
Develop a program to implement broadcast receiver.
Exercise:
1. Write a program to demonstrate all the system broadcast messages.
AndroidManifest.xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/andr
oid"xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACTION_POWER_CONNECTED" />
<uses-permission
android:name="android.permission.ACTION_POWER_DISCONNECTED"/>
<uses-permission android:name="android.permission.BATTERY_CHANGED" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_ru
les" android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="Practical_21"
android:supportsRtl="true"
android:theme="@style/Theme.Practical_15"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
.java file
package com.example.practical_15;
import
android.content.BroadcastRec
eiver;import
android.content.Context;
import
android.content.Intent;
import
android.content.IntentF
ilter;import
android.os.BatteryManag
er; import
android.os.Bundle;
import android.widget.TextView;
import
androidx.appcompat.app.AppCompatActivity
; public class MainActivity extends
AppCompatActivity {
private TextView
textView;
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
l
O
M
o
A
R
c
P
S
D
|
3
5
5
9
4
3
9
5
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textview);
// Register broadcast receivers for various system broadcasts
registerReceiver(ne
w BootReceiver(), new
IntentFilter(Intent.ACTION_
BOOT_COMPLETED));
registerReceiver(new
PowerConnectedReceiver(), new
IntentFilter(Intent.ACTION_POWER_CONNECTED));
registerReceiver(new
PowerDisconnectedReceiver(), new
IntentFilter(Intent.ACTION_POWER_DISCONNECTED));
registerReceiver(new
BatteryChangedReceiver(), new
IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}
private class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent)
{String message = "System boot
completed";
textView.setText(message);}
}
private class PowerConnectedReceiver
extendsBroadcastReceiver
{@Override
public void onReceive(Context context, Intent intent)
{String message = "Power
connected";
textView.setText(message);}
}
private class PowerDisconnectedReceiver
extendsBroadcastReceiver {@Override
public void onReceive(Context context, Intent intent)
{String message = "Power
disconnected";
textView.setText(message);}
}
private class BatteryChangedReceiver
extendsBroadcastReceiver
{@Override
public void onReceive(Context context, Intent
intent) { int level =
intent.getIntExtra(BatteryManager.EXTRA_LEVEL,
0);String message = "Battery level: " + level;
textView.setText(message);}
}
}
.xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/and
roid"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
>
<TextView
android:id="@+id/textview"
android:layout_width="wrap_
content"
android:layout_height="wrap_
content"
android:textSize="24sp"
android:textStyle="bold"
android:layout_centerInPare
nt="true"
android:textColor="#B02D
C6"
/>
</RelativeLayout>
Output:
M oA Rc P S D| 35 59 439 5
Practical No. 10 : Write a program to create login form for student registration
system.
activity_main.xml code :
<EditText
android:id="@+id/editTextUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username" android:inputType="text"
android:padding="8dp" android:layout_marginTop="16dp"/>
<EditText
android:id="@+id/Enroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enrollment No.: " android:inputType="text"
android:padding="8dp" android:layout_marginTop="16dp"/>
<EditText
android:id="@+id/CRN"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="CRN
No.: " android:inputType="text" android:padding="8dp"
android:layout_marginTop="16dp"/>
<EditText
android:id="@+id/cla" android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="class :
" android:inputType="text" android:padding="8dp"
android:layout_marginTop="16dp"/>
<EditText
android:id="@+id/Roll" android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="Roll No
: " android:inputType="text" android:padding="8dp"
android:layout_marginTop="16dp"/>
<EditText
android:id="@+id/dept" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Department: " android:inputType="text"
android:padding="8dp" android:layout_marginTop="16dp"/>
<EditText
android:id="@+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password" android:inputType="textPassword"
android:padding="8dp" android:layout_marginTop="16dp"/>
<Button
android:id="@+id/buttonLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Login"
android:textSize="18sp" android:layout_marginTop="16dp"/>
</LinearLayout>
MainActivity.java code:
}
else {
} else {
Toast.makeText(getApplicationContext(), "Invalid username or password",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
Output:
lOM oA R c P S D| 35 59 439 5
lOM oA R c P S D| 35 59 439 5
practical no:23
X. Exercise
1. Write a program to capture an image and display it using image view.
activity_main.xml </LinearLayout>
xmlns:app="http://schemas.android.com/apk/r
es-auto"
xmlns:tools="http://schemas.android.com/tools
"android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
<ImageView
android:id="@+id/click_image"
android:layout_width="match_parent"
android:layout_height="530dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="70dp"
android:layout_marginBottom="10dp"
/>
<Button
android:id="@+id/camera_button"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:gravity="center"
android:text="Camera" />
MainActivity.java
package com.example.ex2301;
import
androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.Bitmap;
import
android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import
android.widget.ImageView;
import android.os.Bundle;
Button camera_open_id;
ImageView click_image_id;
@Override
protected void
onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
camera_open_id
=
(Button)findViewById(R.id.camera_button);
click_image_id
=
(ImageView)findViewById(R.id.click_image);
camera_open_id.setOnClickListener(new
lO M o AR cP S D| 3 5 5 9 4 3 9 5
@Override
public void onClick(View v)
{
Intent camera_intent
= new Intent(MediaStore
.ACTION_IMAGE_CAPTURE);
startActivityForResult(camera_intent, pic_id);
}
});
}
Intent data) {
super.onActivityResult(requestCode, resultCode,
click_image_id.setImageBitmap(photo);
}
}
}
lOM oA R c P S D| 35 59 439 5
Output:
cP S D| 355 94 395
lOM oA R c P S D| 35 59 439 5
Practical No: 18
Develop a program to implement new activity using explicit intent and implicit intent.
Exercise:
1. Write a program to create a create text field and a button “Navigate”. When you enter
www.google.com and press navigate it should open google page.
.java file
package com.example.practical_15;
import android.annotation.SuppressLint;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private Button mSearchButton;
private EditText mEnterText;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSearchButton = (Button) findViewById(R.id.searchbutton);
mEnterText = (EditText) findViewById(R.id.enteredtext);
mSearchButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
String etxt = mEnterText.getText().toString();
if(!etxt.isEmpty()) {
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY,etxt);
startActivity(intent);
}
else {
Toast.makeText(MainActivity.this,"Not entered
anything",Toast.LENGTH_LONG).show();
}
}
});
}
}
.xml file
<?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"
tools:context=".MainActivity"
android:orientation="vertical"
>
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="Search here"
android:id="@+id/enteredtext"
lOM oA R c P S D| 35 59 439 5
android:textColor="@color/black"
android:layout_marginTop="150dp"
android:layout_marginLeft="35dp"
android:layout_marginRight="35dp"
android:paddingLeft="20dp"
android:background="@drawable/shape"
/>
<Button
android:layout_width="150dp"
android:layout_height="wrap_content"
android:id="@+id/searchbutton"
android:text="SEARCH"
android:layout_marginTop="30dp"
android:layout_below="@+id/enteredtext"
android:layout_gravity="center"
/>
</LinearLayout>
Output:
Practical No.4
1. Write a program to display HelloWorld.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
O/P:-
2. Write a program to display student name and marks.
O/P
Practical No.5
1. Write a program to place Name, Age and mobile number linearly (Vertical) on the display
screen using Linear layout.
O/P
2. Write a program to place Name, Age and mobile number centrally on the display screen
using Absolute layout.
android:textColor="#000"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Student 1:"
android:textColor="#86AD33"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
/>
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:text="Student 2:"
android:textColor="#86AD33"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:text="Student 3:"
android:textColor="#86AD33"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:text="Student 4:"
android:textColor="#86AD33"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:text="Student 5:"
android:textColor="#86AD33"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:text="Student 6:"
android:textColor="#86AD33"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:text="Student 7:"
android:textColor="#86AD33"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:text="Student 8:"
android:textColor="#86AD33"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:text="Student 9:"
android:textColor="#86AD33"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:text="Student 10:"
android:textColor="#86AD33"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
O/P
2. Write a program to display all the data types in object-oriented programming
using Frame layout.
O/P
Practical No.12
1. Write a program to show the following output. First two radio buttons are without using radio
group and next two radio buttons are using radio group. Note the changes between these two.
Also toast which radio button has been selected.
activity_main.xml:
<?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:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Single Radio Buttons"
android:textSize="25dp" />
<RadioButton
android:id="@+id/rb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio Button 1" />
<RadioButton
android:id="@+id/rb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio Button 2" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/black" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Radio Button inside RadioGroup"
android:paddingTop="20dp"
android:textSize="25dp" />
<RadioGroup
android:id="@+id/rg"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/rbmale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male" />
<RadioButton
android:id="@+id/rbfemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />
</RadioGroup>
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:text="Show Selected"
android:textSize="25dp" />
</LinearLayout>
MainActivity.java:
package com.blogspot.codingatharva.manualprograms;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
RadioButton rb1, rb2, rg1;
RadioGroup rg;
Button b;
StringBuffer sb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sb = new StringBuffer("You Selected: ");
b = findViewById(R.id.btn);
rb1 = findViewById(R.id.rb1);
rb2 = findViewById(R.id.rb2);
rg = findViewById(R.id.rg);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
rg1 = findViewById(rg.getCheckedRadioButtonId());
if (rb1.isChecked())
sb.append("\n"+rb1.getText());
if (rb2.isChecked())
sb.append("\n"+rb2.getText());
if (rg1.isChecked())
sb.append("\n"+rg1.getText());
Toast.makeText(getApplicationContext(), sb, Toast.LENGTH_SHORT).show();
sb.delete(13, sb.length() - 1);
}
});
}
}
Practical No.13
1. Write a program to display circular progress bar.
activity_main.xml:
<div style="white-space: normal; height: auto; visibility: visible; font-size: 14px;">
<?xml version= "1.0" encoding= "utf-8" ?>
<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:layout_margin= "16dp"
tools:context= ".MainActivity" >
<ProgressBar
android:id= "@+id/progressBar"
style= "?android:attr/progressBarStyleHorizontal"
android:layout_width= "200dp"
android:layout_height= "200dp"
android:layout_centerInParent= "true"
android:background= "@drawable/circular_shape"
android:indeterminate= "false"
android:max= "100"
android:progress= "0"
android:progressDrawable= "@drawable/circular_progress_bar" />
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_below="@+id/progressBar"
android:text="Start"/>
</RelativeLayout></div>
MainActivity.java:
package com.blogspot.codingatharva.manualprograms;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
public class MainActivity extends AppCompatActivity {
Button b;
ProgressBar pb;
private int progressStatus = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b = findViewById(R.id.btn);
pb = findViewById(R.id.progressBar);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startProgress(v);
}
});
}
public void startProgress(View view) {
pb.setProgress(0);
new Thread(new Task()).start();
}
class Task implements Runnable {
@Override
public void run() {
for (int i = 0; i <= 10; i++) {
final int value = i;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
pb.setProgress(value);
}
}
}
}
O/P
Practical No.14
Write a program to display 15 buttons using grid view.
activity_main.xml:
<?xml version= "1.0" encoding= "utf-8" ?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/gridview"
android:layout_width="fill_parent" O/P
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp"
tools:context=".MainActivity"></GridView>
MainActivity.java:
package com.blogspot.codingatharva.manualprograms;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
GridView gridview;
String arr[] = new String[15];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridview = findViewById(R.id.gridview);
for (int i = 0; i < 15; i++) {
arr[i] = Integer.toString(i + 1);
}
ArrayAdapter<String> ad = new ArrayAdapter<String>(this, R.layout.activity_listview, R.id.btn, arr);
gridview.setAdapter(ad);
}
}
Write a program to display a text view using vertical scroll view.
activity_main.xml:
<?xml version= "1.0" encoding= "utf-8" ?>
<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">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Vertical ScrollView example In computer displays, filmmaking, television
production, and other kinetic \n
displays, scrolling is sliding text, images or video across a monitor or display, vertically or
horizontally. Scrolling \n,
as such, does not change the layout of the text or pictures but moves (pans or tilts) the user's
view across what is \n
apparently a larger image that is not wholly seen.[1] A common television and movie special
effect is to scroll credits, \n
while leaving the background stationary. Scrolling may take place completely without user
intervention (as in film credits) \n
or, on an interactive device, be triggered by touchscreen or a keypress and continue without
further intervention until a \n
further user action, or be entirely controlled by input devices. Scrolling may take place in discrete
increments \n
(perhaps one or a few lines of text at a time), or continuously (smooth scrolling). Frame rate is the
speed at which an \n
entire image is redisplayed. It is related to scrolling in that changes to text and image position can
only happen as often \n
as the image can be redisplayed. When frame rate is a limiting factor, one smooth scrolling
technique is to blur images during \n
movement that would otherwise appear to jump \b
Scrolling texts, also referred to as scrolltexts or scrollers, played an important part in the birth of
the computer demo culture.
The software crackers often used their deep knowledge of computer platforms to transform the
information that accompanied their releases
into crack intros. The sole role of these intros was to scroll the text on the screen in an impressive
way.
Many scrollers were plain horizontal scrollers, but demo coders also paid a lot of attention to
creating new and different types of scrolling.
The characters could, for example, continuously alter their shape, take unusual flying paths or
incorporate color effects such as raster bars.
Sometimes it makes the text nearly unreadable.
" />
</ScrollView>
</RelativeLayout>
MainActivity.java:
package com.blogspot.codingatharva.manualprograms;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
O/P
Practical No.15
1. Write a program to display following toast message.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="143dp"
android:layout_height="73dp"
android:text="Click Here"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java:
package com.blogspot.codingatharva.toastprogram;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle; import
android.view.View; import
android.widget.Button;import
android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
onClick(View v) {
MainActivity.java:
package com.blogspot.codingatharva.manualprograms;import
android.os.Bundle;
import android.widget.TimePicker;
import androidx.appcompat.app.AppCompatActivity; public class MainActivity
extends AppCompatActivity {
TimePicker tp;
@Override
protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tp = findViewById(R.id.tp1);
tp.setIs24HourView(true);
}
}
activity_main.xml:
<TimePicker
android:id="@+id/tp1" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv"
android:timePickerMode="spinner" />
<TimePicker
android:id="@+id/tp2" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tp1" android:timePickerMode="clock"
/>
</RelativeLayout>
PRACTICAL NO 17. PROGRAM TO CREATE A HELLO WORLD ACTIVITY USING
ALL LIFE CYCLES METHOD TO DISPLAY MESSAGES USING LOG.D IN ANDROID
STUDIO
MainActivity.java:
package com.blogspot.codingatharva.manualprograms;import
android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity; public class MainActivity
extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); Log.d("Activity:",
"Created");
}
@Override
protected void onStart() { super.onStart();
Log.d("Activity:", "Started");
}
@Override
protected void onResume() { super.onResume();
Log.d("Activity:", "Resume");
}
@Override
protected void onPause() {
super.onPause();
Log.d("Activity:", "Pause");
}
@Override
protected void onStop() { super.onStop();
Log.d("Activity:", "Stop");
}
@Override
protected void onRestart() { super.onRestart();
Log.d("Activity:", "Restart");
}
@Override
protected void onDestroy() { super.onDestroy();
Log.d("Activity:", "Destroy");
}
}
activity_main.xml:
<?xml version= "1.0" encoding= "utf-8" ?>
<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:paddingTop="80dp"
tools:context=".MainActivity">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World"/>
</RelativeLayout
Practical No.26: write a program to insert data in sqlite database using
asynctask
Practical No 27: write a program to create the login form and display login successful/unsuccrssful
toastmessage.
activity_main.xml
<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"
tools:context="com.onlinetutorialspoint.official.simplelogin.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_centerInParent="true">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"android:hint="UserName"
android:id="@+id/username"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="password" android:id="@+id/password"
android:inputType="textPassword"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"android:text="Login"
android:background="#3f76ff" android:textColor="#fff"
android:id="@+id/login"/>
</LinearLayout>
</RelativeLayout>
MainActivity.java
package com.onlinetutorialspoint.official.simplelogin;
import java.util.Objects;
}else
{
Toast.makeText(MainActivity.this,"AuthenticationFailed",Toast.LENGTH_LONG).show();
}
}
});
}
}
Giving invalid credentials:
Practical No 9: write a program to create a simple calculator in android
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:background="#8BC34A"
android:backgroundTint="@android:color/darker_gray"
tools:context=".MainActivity">
<TextView
android:layout_width="194dp"
android:layout_height="43dp"
android:layout_marginStart="114dp"
android:layout_marginLeft="114dp"
android:layout_marginTop="58dp"
android:layout_marginEnd="103dp"
android:layout_marginRight="103dp"
android:layout_marginBottom="502dp"
android:scrollbarSize="30dp"
android:text=" Calculator"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="30dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/num1"
android:layout_width="364dp"
android:layout_height="28dp"
android:layout_marginStart="72dp"
android:layout_marginTop="70dp"
android:layout_marginEnd="71dp"
android:layout_marginBottom="416dp"
android:background="@android:color/white"
android:ems="10"
android:onClick="clearTextNum1"
android:inputType="number"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /
<EditText
android:id="@+id/num2"
android:layout_width="363dp"
android:layout_height="30dp"
android:layout_marginStart="72dp"
android:layout_marginTop="112dp"
android:layout_marginEnd="71dp"
android:layout_marginBottom="374dp"
android:background="@android:color/white"
android:ems="10"
android:onClick="clearTextNum2"
android:inputType="number"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/result"
android:layout_width="356dp"
android:layout_height="71dp"
android:layout_marginStart="41dp"
android:layout_marginTop="151dp"
android:layout_marginEnd="48dp"
android:layout_marginBottom="287dp"
android:background="@android:color/white"
android:text="result"
android:textColorLink="#673AB7"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/sum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="292dp"
android:layout_marginEnd="307dp"
android:layout_marginBottom="263dp"
android:backgroundTint="@android:color/holo_red_light
android:onClick="doSum"
android:text="+"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="210dp"
android:layout_marginTop="292dp"
android:layout_marginEnd="113dp"
android:layout_marginBottom="263dp"
android:backgroundTint="@android:color/holo_red_light"
android:onClick="doSub"
android:text="-"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.507" />
<Button
android:id="@+id/div"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="307dp"
android:layout_marginTop="292dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="263dp"
android:backgroundTint="@android:color/holo_red_light"
android:onClick="doDiv"
android:text="/"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/mul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="356dp"
android:layout_marginEnd="307dp"
android:layout_marginBottom="199dp"
android:backgroundTint="@android:color/holo_red_light"
android:onClick="doMul"
android:text="x"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="103dp"
android:layout_height="46dp"
android:layout_marginStart="113dp"
android:layout_marginTop="356dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="356dp"
android:layout_marginEnd="307dp"
android:layout_marginBottom="199dp"
android:backgroundTint="@android:color/holo_red_light"
android:onClick="doMul"
android:text="x"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="103dp"
android:layout_height="46dp"
android:layout_marginStart="113dp"
android:layout_marginTop="356dp"
android:layout_marginEnd="206dp"
android:layout_marginBottom="199dp"
android:backgroundTint="@android:color/holo_red_light"
android:onClick="doMod"
android:text="%(mod)"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.515" />
<Button
android:id="@+id/pow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="113dp"
android:layout_marginTop="292dp"
android:layout_marginEnd="210dp"
android:layout_marginBottom="263dp"
android:backgroundTint="@android:color/holo_red_light"
android:onClick="doPow"
android:text="n1^n2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.507" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.calculator2;
import android.os.Bundle;
import com.google.android.material.snackbar.Snackbar;
import androidx.appcompat.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import com.example.calculator2.databinding.ActivityMainBinding;
import android.view.Menu;
import android.view.MenuItem;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
return false;
}
if((s1.equals(null) && !s2.equals(null))|| (s1.equals("") && !s2.equals("")) ){
//checkAndClear();
String result = "Please enter value 1";
e1.setText(result);
return false;
}
if((s1.equals(null) && s2.equals(null))|| (s1.equals("") && s2.equals("")) ){
//checkAndClear();
String result1 = "Please enter value 1";
e1.setText(result1);
String result2 = "Please enter value 2";
e2.setText(result2);
return false;
}
else {
// converting string to int.
num1 = Integer.parseInt(s1);
// converting string to int.
num2 = Integer.parseInt(s2);
}
return true;
}
public void doSum(View v) {
// get the input numbers
if (getNumbers()) {
int sum = num1 + num2;
t1.setText(Integer.toString(sum));
}
else
{
t1.setText("Error Please enter Required Values");
}
}
public void clearTextNum1(View v) {
// get the input numbers
e1.getText().clear();
}
public void clearTextNum2(View v) {
// get the input numbers
e2.getText().clear();
}
public void doPow(View v) {
//checkAndClear();
// get the input numbers
if (getNumbers()) {
}
t1.setText(Double.toString(sum));
else
}
// a public method to perform subtraction
public void doSub(View v) {
//checkAndClear();
// get the input numbers
if (getNumbers()) {
int sum = num1 - num2;
t1.setText(Integer.toString(sum));
else
else
}
// a public method to perform Division
public void doDiv(View v) {
//checkAndClear();
// get the input numbers
if (getNumbers()) {
// displaying the text in text view assigned as t1
double sum = num1 / (num2 * 1.0);
t1.setText(Double.toString(sum));
else
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e1 = (EditText) findViewById(R.id.num1);
// defining the edit text 2 to e2
e2 = (EditText) findViewById(R.id.num2);
}
@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;
}
return super.onOptionsItemSelected(item);
}
@Override
activity_main.xml:
MainActivity.java:
package com.tutlane.bluetoothexample;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
package="com.tutlane.bluetoothexample">
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
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>
</manifest>
Output of Android Bluetooth Turn ON / OFF Example:
Practical No 30: Write a program to send email
<?xml version="1.0" encoding="utf-8"?>
<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">
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="18dp"
android:layout_marginRight="22dp" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_alignLeft="@+id/editText1"
android:layout_marginTop="20dp" />
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_alignLeft="@+id/editText2"
android:layout_marginTop="30dp" />
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText1"
android:layout_alignBottom="@+id/editText1"
android:layout_alignParentLeft="true" android:text="Send
To:" android:textColor="#0F9D58" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText2"
android:layout_alignBottom="@+id/editText2"
android:layout_alignParentLeft="true" android:text="Email
Subject:" android:textColor="#0F9D58" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText3"
android:layout_alignBottom="@+id/editText3"
android:text="Email Body:" android:textColor="#0F9D58" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText3"
android:layout_alignLeft="@+id/editText3"
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText2"
android:layout_alignBottom="@+id/editText2"
android:layout_alignParentLeft="true" android:text="Email
Subject:" android:textColor="#0F9D58" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText3"
android:layout_alignBottom="@+id/editText3"
android:text="Email Body:" android:textColor="#0F9D58" />
<!-- Button to send email -->
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText3"
android:layout_alignLeft="@+id/editText3"
android:layout_marginLeft="76dp"
android:layout_marginTop="20dp"
android:text="Send email!!" />
</RelativeLayout>
MainActivity Java:
import android.content.Intent;
import android.os.Bundle; import
android.widget.Button; import
android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity; public
class MainActivity extends AppCompatActivity {
// define objects for edit text and button
Button button;
EditText sendto, subject, body;
@Override
});
}
Practical No 32: Write a program To draw a route between two locations.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is
ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng sydney = new LatLng(-34, 151);
//mMap.addMarker(new
MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 16));
mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
if (markerPoints.size() > 1) {
markerPoints.clear();
mMap.clear();
}
// Creating MarkerOptions
MarkerOptions options = new MarkerOptions();
if (markerPoints.size() == 1) {
options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory
.HUE_GREEN));
} else if (markerPoints.size() == 2) {
options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory
.HUE_RED));
}
}
});
@Override
protected String doInBackground(String... url) {
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.execute(result);
}
}
JSONObject jObject;
List<List<HashMap>> 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>> result) {
ArrayList points = null;
PolylineOptions lineOptions = null;
MarkerOptions markerOptions = new MarkerOptions();
points.add(position);
}
lineOptions.addAll(points);
lineOptions.width(12);
lineOptions.color(Color.RED);
lineOptions.geodesic(true);
// Destination of route
String str_dest = "destination=" + dest.latitude + "," +
dest.longitude;
// Sensor enabled
String sensor = "sensor=false";
String mode = "mode=driving";
// Output format
String output = "json";
return url;
}
urlConnection.connect();
iStream = urlConnection.getInputStream();
data = sb.toString();
br.close();
} catch (Exception e) {
Log.d("Exception", e.toString());
} finally {
iStream.close();
urlConnection.disconnect();
}
return data;
}
}