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

Demo

Uploaded by

shahidhakim0992
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Demo

Uploaded by

shahidhakim0992
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

Write a program to display circular progress bar

activity_main.xml

<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<RelativeLayout
android:id="@+id/progress_layout"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="100dp">

<ProgressBar
android:id="@+id/progress_bar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/circular_shape"
android:indeterminate="false"
android:progressDrawable="@drawable/circular_progress_bar"
android:textAlignment="center" />

<TextView
android:id="@+id/progress_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center"
android:textSize="28sp"/>
</RelativeLayout>
</LinearLayout>

circular_progress_bar.xml

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


<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="270"
android:toDegrees="270">

<!--styling the progress bar-->


<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thickness="8dp"
android:useLevel="true">
<gradient
android:angle="0"
android:endColor="@color/purple_200"
android:startColor="#000000"
android:type="sweep"
android:useLevel="false" />
</shape>

</rotate>

circular_shape.xml

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


<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadiusRatio="2.5"
android:shape="ring"
android:useLevel="false">
<solid android:color="@color/purple_200" />
</shape>

MainActivity.java

package com.experiments.progressbarcircular;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private ProgressBar progressBar;
private TextView progressText; int i = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar = findViewById(R.id.progress_bar);
progressText = findViewById(R.id.progress_text);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@SuppressLint("SetTextI18n")
@Override
public void run() {
if (i <= 100) {
progressText.setText("" + i);
progressBar.setProgress(i); i++;
handler.postDelayed(this, 200);
} else {
handler.removeCallbacks(this);
}
}
}, 200);
}
}

Zoom (In/Out)

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">

<ImageView
android:id="@+id/image_View"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/image1" />

<ZoomControls
android:id="@+id/zoom_controls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_margin="10dp" />

</RelativeLayout>

MainActivity.java

package com.experiments.zoomcontrol;

import android.graphics.Color;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.ZoomControls;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {

ImageView imageView;
ZoomControls zoomControls;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = findViewById(R.id.image_View);
zoomControls = findViewById(R.id.zoom_controls);
zoomControls.setBackgroundColor(Color.BLACK); z
oomControls.show(); imageView.setOnTouchListener(
new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
zoomControls.show();
return false;
}
}
);

zoomControls.setOnZoomInClickListener( new View.OnClickListener() {


@Override
public void onClick(View view) {
float x = imageView.getScaleX();
float y = imageView.getScaleY();
imageView.setScaleX((float) (x + 0.5f));
imageView.setScaleY((float) (y + 0.5f));
zoomControls.hide();
}
}
);

zoomControls.setOnZoomOutClickListener( new View.OnClickListener() {


@Override
public void onClick(View view) {
float x = imageView.getScaleX();
float y = imageView.getScaleY();
if (x == 1 && y == 1) {
imageView.setScaleX((float) (x));
imageView.setScaleY((float) (y));
zoomControls.hide();
} else {
imageView.setScaleX((float) (x - 0.5f));
imageView.setScaleY((float) (y - 0.5f));
zoomControls.hide();
}
}
}
);
}
}
Develop an Android to send and receive SMS. (WRITE only .java and permission tag in
Manifest file)

MainActivity.java

package com.experiments.sendmessage;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
public class MainActivity extends AppCompatActivity {
EditText no, msg;
Button send; int code = 1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

no = findViewById(R.id.no);
msg = findViewById(R.id.msg);
send = findViewById(R.id.send);
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String num = no.getText().toString();
String sms = msg.getText().toString();
requestPermission();
if (!TextUtils.isEmpty(num) && !TextUtils.isEmpty((sms)))
{
if (checkPermission()) {
SmsManager mana = SmsManager.getDefault();
mana.sendTextMessage(num, null, sms, null, null);
no.setText("");
msg.setText("");
} else {
Toast.makeText(getApplicationContext(),
"permission not granted", Toast.LENGTH_SHORT).show();
}
}
}
});
}

private void requestPermission() {


ActivityCompat.requestPermissions(this, new String[]
{Manifest.permission.SEND_SMS}, code);
}

private boolean checkPermission() {


int result = ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.SEND_SMS);
if (result == PackageManager.PERMISSION_GRANTED) {
return true;
} else {
return false;
}
}
}

AndroidManifest.xml

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

Develop the registiration form using the following GUI

activity_main.xml
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_marginTop="40dp
android:src="@drawable/image1" />

<EditText
android:id="@+id/name"
android:layout_width="350dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:background="#E8E8E8"
android:drawableLeft="@drawable/person"
android:drawablePadding="10dp"
android:hint="Name" android:paddingLeft="10sp" />

<EditText
android:id="@+id/email"
android:layout_width="350dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#E8E8E8"
android:drawableLeft="@drawable/email"
android:drawablePadding="10dp"
android:hint="Email ID"
android:paddingLeft="10sp" />

<EditText
android:id="@+id/password"
android:layout_width="350dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#E8E8E8"
android:drawableLeft="@drawable/password"
android:drawablePadding="10dp"
android:hint="Password"
android:paddingLeft="10sp" />

<EditText
android:id="@+id/cpassword"
android:layout_width="350dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#E8E8E8"
android:drawableLeft="@drawable/cpassword"
android:drawablePadding="10dp"
android:hint="Confirm Password"/>
android:paddingLeft="10sp" />

<EditText
android:id="@+id/mobile"
android:layout_width="350dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#E8E8E8"
android:drawableLeft="@drawable/mobile"
android:drawablePadding="10dp"
android:hint="Enter Mobile"
android:paddingLeft="10sp" />

<RadioGroup
android:id="@+id/radiogroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:orientation="horizontal">

<RadioButton
android:id="@+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male" />
<RadioButton
android:id="@+id/female"
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:layout_marginTop="20dp"
android:text="Register" />

</LinearLayout>
MainActivity.java

package com.experiments.registerationform;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


EditText e1, e2, e3, e4, e5;
Button btn; RadioGroup radioGroup;
RadioButton r1, r2;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

e1 = findViewById(R.id.name);
e2 = findViewById(R.id.email);
e3 = findViewById(R.id.password);
e4 = findViewById(R.id.cpassword);
e5 = findViewById(R.id.mobile);
r1 = findViewById(R.id.male);
r2 = findViewById(R.id.female);
radioGroup = findViewById(R.id.radiogroup);
// r1 = findViewById(R.id.gender);
btn = findViewById(R.id.btn);

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

String gender = "";


if (r1.isChecked()) {
gender = "Male";
} else if (r2.isChecked()) {
gender = "Female";
}

String name = e1.getText().toString();


String email = e2.getText().toString();
String pass = e3.getText().toString();
String cpass = e4.getText().toString();
// String gender = (String) radioButton.getText();
String mobile = e5.getText().toString();

if (pass.equals(cpass)) {
String disp = "Name: " + name + "\n" + "Email: " + email + "\n" + "Gender: " + gender + "\n" +
"Mobile: " + mobile + "\n";

Toast.makeText(getApplicationContext(), disp, Toast.LENGTH_LONG).show();


} else {
Toast.makeText(getApplicationContext(), "Passwords do not Match",
Toast.LENGTH_SHORT).show();
}
}
});
}
}

Write a program to capture an image and display it

<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:text="Click to Capture" />

<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:text="Capture" />

<ImageView
android:id="@+id/img"
android:layout_width="400dp"
android:layout_height="400dp"
android:layout_gravity="center"
android:layout_marginTop="50dp" />

</LinearLayout>

Java-

package com.experiments.imagecapture;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.media.Image;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {


Button btn;
ImageView img;
int CAMERA_REQUEST = 1;

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

btn = findViewById(R.id.btn); img = findViewById(R.id.img);

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, CAMERA_REQUEST);
}
});
}

protected void onActivityResult(int requestCode, int resultCode,


@Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == CAMERA_REQUEST) {
Bitmap image = (Bitmap) data.getExtras().get("data");
img.setImageBitmap(image);
}
}
}

AndroidManifext.xml

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

Develop a program to send an email

activity_main.xml

<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:text="Email Example"
android:textSize="25dp" />

<EditText
android:id="@+id/ed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_marginRight="10dp"
android:hint="Enter E-mail" />

<EditText
android:id="@+id/ed1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_marginRight="10dp"
android:hint="Subject" />

<EditText
android:id="@+id/ed2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_marginRight="10dp"
android:hint="message" />
<Button
android:id="@+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_marginRight="10dp"
android:text="send" />
</LinearLayout>

MainActivity.java

package com.experiments.emailsender;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

Button snd; EditText ed,ed1,ed2; @Override


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

snd=findViewById(R.id.send);
ed=findViewById(R.id.ed);
ed1=findViewById(R.id.ed1);
ed2=findViewById(R.id.ed2);

snd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String to=ed.getText().toString();
String sub=ed1.getText().toString();
String msg=ed2.getText().toString();
Intent email= new Intent(Intent.ACTION_SEND);

email.putExtra(Intent.EXTRA_EMAIL, new String[] {to});


email.putExtra(Intent.EXTRA_SUBJECT,sub);
email.putExtra(Intent.EXTRA_TEXT,msg);
email.setType("message/rfc822"); startActivity(Intent.createChooser(email,"Choose an email
client"));

}
});

}
}

Develop an application to store student details like roll no., name, branch, marks, percentage,
and retrieve student information using roll no. in SQLite databases.
activity_main.xml

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


<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:orientation="vertical"
android:stretchColumns="0">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:text="Student Details" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:text="Enter Roll Number" />

<EditText
android:id="@+id/roll"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp" />

<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp" />
<TextView
android:id="@+id/marks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp" />

<TextView
android:id="@+id/percent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp" />

<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:text="View" />

</LinearLayout>

MainActivity.java

package com.experiments.sqliteexample;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
TextView t1, t2, t3;
EditText e1;
Button btn;

SQLiteDatabase db;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t1 = findViewById(R.id.name);
t2 = findViewById(R.id.marks);
t3 = findViewById(R.id.percent);
e1 = findViewById(R.id.roll);
btn = findViewById(R.id.btn);
db = openOrCreateDatabase("StudentDB", Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS studentmarks(rollno
VARCHAR,name VARCHAR,marks VARCHAR, percent VARCHAR);");
db.execSQL("INSERT INTO studentmarks(rollno, name, marks, percent)
VALUES ('49', 'Anurag', '94', '94%');");
db.execSQL("INSERT INTO studentmarks(rollno, name, marks, percent)
VALUES ('53', 'Maksud', '97', '97%');");

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Cursor c = db.rawQuery("SELECT * FROM studentmarks WHERE
rollno='" + e1.getText() + "'", null);
if (c.moveToFirst()) {
t1.setText("Name: " + c.getString(1));
t2.setText("Marks Obtained" + c.getString(2));
t3.setText("Percentile:" + c.getString(3));
} else {
Toast.makeText(getApplicationContext(), "Enter a Valid
Roll ID", Toast.LENGTH_SHORT).show();
}
}
});
}
}

Write a program to locate the user’s current location (Only .java and manifest file)

MainActivity.java
package com.experiments.currentlocation;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity implements LocationListener {


protected LocationManager locationManager;
protected LocationListener locationListener;
protected Context context;
TextView txtLat; String lat; String provider;
protected String latitude, longitude; protected boolean gps_enabled, network_enabled;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtLat = (TextView) findViewById(R.id.textview1);

locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);


locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 0, this);
}
@Override
public void onLocationChanged(Location location) {
txtLat = (TextView) findViewById(R.id.textview1);
txtLat.setText("Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude());
}}

AndroidManifest.xml

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

Develop a Simple Calculator using Table Layout

activity_main.xml

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


<TableLayout
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">

<TableRow>

<EditText
android:id="@+id/v1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginTop="50dp"
android:hint="Enter value 1" />

<EditText
android:id="@+id/v2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="50dp"
android:hint="Enter value 2" />

</TableRow>

<TableRow>

<Button
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginTop="40dp"
android:onClick="sum"
android:text="addition" />

<Button
android:id="@+id/sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="40dp"
android:onClick="sub"
android:text="subtract" />

</TableRow>

<TableRow>

<Button
android:id="@+id/mul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginTop="20dp"
android:onClick="mul"
android:text="multiply" />

<Button
android:id="@+id/div"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="20dp"
android:onClick="div"
android:text="division" />

</TableRow>

</TableLayout>

MainActivity.java

package com.experiments.calculatortablelayout;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


public void sum(View view){

EditText no1=findViewById(R.id.v1);
EditText no2=findViewById(R.id.v2);
Button add=findViewById(R.id.add);
String val1=no1.getText().toString();
String val2=no2.getText().toString();
Integer value1=Integer.parseInt(val1);
Integer value2=Integer.parseInt(val2);
Integer result= value1+value2;
Toast.makeText(getApplicationContext(),"Addition= "+result, Toast.LENGTH_SHORT).show();

public void sub(View view){

EditText no1=findViewById(R.id.v1);
EditText no2=findViewById(R.id.v2);
Button add=findViewById(R.id.sub);
String val1=no1.getText().toString();
String val2=no2.getText().toString();
Integer value1=Integer.parseInt(val1);
Integer value2=Integer.parseInt(val2);
Integer result= value1-value2;
Toast.makeText(getApplicationContext(),"Subtract= "+result, Toast.LENGTH_SHORT).show();

}
public void mul(View view){

EditText no1=findViewById(R.id.v1);
EditText no2=findViewById(R.id.v2);
Button add=findViewById(R.id.mul);
String val1=no1.getText().toString();
String val2=no2.getText().toString();
Integer value1=Integer.parseInt(val1);
Integer value2=Integer.parseInt(val2);
Integer result= value1*value2;
Toast.makeText(getApplicationContext(),"Multiplication= "+result,
Toast.LENGTH_SHORT).show();

}
public void div(View view){

EditText no1=findViewById(R.id.v1);
EditText no2=findViewById(R.id.v2);

Button add=findViewById(R.id.div);
String val1=no1.getText().toString();
String val2=no2.getText().toString();
Integer value1=Integer.parseInt(val1);
Integer value2=Integer.parseInt(val2);
Integer result= value1/value2;
Toast.makeText(getApplicationContext(),"division= "+result, Toast.LENGTH_SHORT).show();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

}
}

Write a program to convert temperature from Celsius to


Fahrenheit.

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


<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="50dp">
<EditText
android:id="@+id/ed1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter temperature in Celsius"
android:inputType="numberDecimal"
android:textSize="20sp" />
<Button
android:id="@+id/bt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Convert"
android:layout_below="@id/ed1"
android:layout_centerHorizontal="true" />

</RelativeLayout>

JAVA FILE:

package com.example.tempconverter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.app.Activity;
import android.widget.Toast;
public class MainActivity extends Activity {
private EditText ed1;
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1 = findViewById(R.id.ed1);
btn = findViewById(R.id.bt1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String celsiustext = ed1.getText().toString();
double cel= Double.parseDouble(celsiustext);
double fahrenheit = (cel * 9 / 5) + 32;
Toast.makeText(MainActivity.this, "Temp in
Fahrenheit : "+ fahrenheit, Toast.LENGTH_LONG).show();
}
});
}
}

Write a program to demonstrate Date and Time picker.

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


<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=".MainActivity">
<DatePicker
android:layout_marginTop="20dp"
android:id="@+id/dp"
android:layout_width="336dp"
android:layout_height="227dp"
android:calendarViewShown="false"
android:datePickerMode="spinner"
android:layout_centerHorizontal="true"/>
<Button
android:id="@+id/bt1"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/dp"
android:layout_centerHorizontal="true"
android:text="Set Date"/>
<TextView
android:id="@+id/tv1"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/bt1"
android:layout_centerHorizontal="true"/>
<TimePicker
android:id="@+id/tp"
android:layout_marginTop="40dp"
android:layout_width="184dp" android:layout_height="195dp"
android:layout_below="@+id/tv1"
android:layout_centerHorizontal="true"
android:timePickerMode="spinner" />
<Button
android:id="@+id/bt2"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tp"
android:layout_centerHorizontal="true"
android:text="Set Time"/>
<TextView
android:id="@+id/tv2"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/bt2"
android:layout_centerHorizontal="true"/>

</RelativeLayout>

JAVA FILE:

package com.example.datetime;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;
public class MainActivity extends AppCompatActivity {
TextView tv1,tv2;
DatePicker d1;
TimePicker t1;
Button b1,b2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1=findViewById(R.id.tv1);
tv2=findViewById(R.id.tv2);
b1=findViewById(R.id.bt1);
b2=findViewById(R.id.bt2);
d1=findViewById(R.id.dp);
t1=findViewById(R.id.tp);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
tv1.setText("Date : "+d1.getDayOfMonth()+"
"+d1.getMonth()+"-"+d1.getYear());
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
t1.setIs24HourView(false);

tv2.setText(t1.getCurrentHour()+":"+t1.getCurrentMinute());
}
});
}
}

Describe with example, how to create a simple database in SQLite (Assume


suitable data).

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">
<Button
android:text="Create SQLite Database"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="46dp"
android:id="@+id/button" />
</RelativeLayout>

MainActivity.java
package in.edu.vpt.insertusingasync;
import android.app.ProgressDialog;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;;

public class MainActivity extends AppCompatActivity {


SQLiteDatabase sqLiteDatabaseObj;
Button EnterData;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

createData = (Button)findViewById(R.id.button);
createData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sqLiteDatabaseObj = openOrCreateDatabase("AndroidJSonDataBase",
Context.MODE_PRIVATE, null);
} }); }
Write a program to demonstrate declaring and using permissions with any
relevant example.

AndroidManifest.xml

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

activity_main.xml
<?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:id="@+id/textView"
android:layout_width="81dp"
android:layout_height="41dp"
android:layout_marginEnd="268dp"
android:layout_marginBottom="576dp"
android:text="To :"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

<TextView
android:id="@+id/textView2"
android:layout_width="70dp"
android:layout_height="43dp"
android:layout_marginEnd="276dp"
android:layout_marginBottom="512dp"
android:text="Sms Text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<EditText
android:id="@+id/etPhno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="40dp"
android:layout_marginBottom="572dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<EditText
android:id="@+id/etmsg"
android:layout_width="193dp"
android:layout_height="51dp"
android:layout_marginEnd="56dp"
android:layout_marginBottom="504dp" android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:ignore="SpeakableTextPresentCheck" />

<Button
android:id="@+id/btnSms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="156dp"
android:layout_marginBottom="400dp"
android:text="SEND SMS"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java
package com.example.testreceivesms;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.Manifest;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


EditText et1,et2;
Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1=findViewById(R.id.etPhno);
et2=findViewById(R.id.etmsg);
b1=findViewById(R.id.btnSms);
if(ContextCompat.checkSelfPermission(MainActivity.this,Manifest.permission.SEN
D_SMS)!=
PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(MainActivity.this,new
String[]{Manifest.permission.SEND_SMS},100);
}
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
String phno= et1.getText().toString();
String msg=et2.getText().toString();
SmsManager smsManager= SmsManager.getDefault();
smsManager.sendTextMessage(phno,null,msg,null,null);
Toast.makeText(MainActivity.this,"Sms sent successfully",
Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
Toast.makeText(MainActivity.this,"Sms failed to send... try again",
Toast.LENGTH_LONG).show();
}
}
});
}
}

Develop an application to display Google map with user's current location.

act ivity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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=".MainActivity">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/google_map"
android:name="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>

MainActivity.Java

package com.example.location;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.FragmentActivity;
import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;

public class MainActivity extends FragmentActivity implements OnMapReadyCallback


{
Location currentlocation;
FusedLocationProviderClient fusedLocationProviderClient;
private static final int REQUEST_CODE = 101;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

fusedLocationProviderClient =
LocationServices.getFusedLocationProviderClient(this);
fetchLastLocation();
}

private void fetchLastLocation() {

if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,new
String[]{Manifest.permission.ACCESS_FINE_LOCATION},REQUEST_CODE);
return;
}
Task<Location> task = fusedLocationProviderClient.getLastLocation();
task.addOnSuccessListener(new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if(location!=null)
{
currentlocation=location;

Toast.makeText(getApplicationContext(),currentlocation.getLatitude()+""+current
location.getLongitude(), Toast.LENGTH_SHORT).show();
SupportMapFragment supportMapFragment =
(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.go
ogle_map);
supportMapFragment.getMapAsync(MainActivity.this);
}
}
});
}
@Override
public void onMapReady(@NonNull GoogleMap googleMap) {
LatLng latLng=new
LatLng(currentlocation.getLatitude(),currentlocation.getLongitude());
MarkerOptions markerOptions=new MarkerOptions().position(latLng)
.title("I am Here");
googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng,5));
googleMap.addMarker(markerOptions);

}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[]
permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case REQUEST_CODE:
if (grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
fetchLastLocation();
}
break;
}
}
}

Design an android application to show the list of paired devices by Bluetooth.

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"
android:transitionGroup="true">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="List all Paired devices"
android:onClick="list"
android:id="@+id/button1"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Paired devices:"
android:id="@+id/textView1"
android:textColor="#ff34ff06"
android:textSize="25dp"
android:layout_below="@+id/button1" />

<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listView" android:layout_alignParentBottom="true"
android:layout_below="@+id/textView1" />

</RelativeLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:androclass="http://schemas.android.com/apk/res/android"
package="com.example.bluetooth"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses
permission android:name="android.permission.BLUETOOTH_ADMIN" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=" in.org.msbte.bluetooth.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
package in.org.msbte.bluetooth;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Set;

public class MainActivity extends AppCompatActivity {


Button b1;
private BluetoothAdapter BA;
private Set<BluetoothDevice>pairedDevices;
ListView lv;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

b1 = (Button) findViewById(R.id.button1);

BA = BluetoothAdapter.getDefaultAdapter();
lv = (ListView)findViewById(R.id.listView);
}

public void list(View v){


pairedDevices = BA.getBondedDevices();

ArrayList list = new ArrayList();

for(BluetoothDevice bt : pairedDevices) list.add(bt.getName());


Toast.makeText(getApplicationContext(), "Showing Paired
Devices",Toast.LENGTH_SHORT).show();

final ArrayAdapter adapter = new


ArrayAdapter(this,android.R.layout.simple_list_item_1, list);

lv.setAdapter(adapter);
}
}

Explain Geocoding and Reverse Geocoding with suitable example.

Geocoding is the process of transforming a street address or other description of a


location into a (latitude, longitude) coordinate.
Reverse geocoding is the process of transforming a (latitude, longitude) coordinate into a
(partial) address.
The amount of detail in a reverse geocoded location description may vary, for example
one might contain the full street address of the closest building, while another might
contain only a city name and postal code.
The Geocoder class is used for handling geocoding and reverse geocoding.

activity_maps.xml

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="example.com.mapexample.MapsActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<EditText
android:layout_width="248dp"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:hint="Search Location" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="searchLocation"
android:text="Search" />

</LinearLayout>
</fragment>

AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
MapsActivity.java
package example.com.mapexample;

import android.location.Address;
import android.location.Geocoder;
import android.os.Build;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;

import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.location.LocationServices;

import android.location.Location;
import android.Manifest;
import android.content.pm.PackageManager;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;

import java.io.IOException;
import java.util.List;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback,


LocationListener,GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener{

private GoogleMap mMap;


Location mLastLocation;
Marker mCurrLocationMarker;
GoogleApiClient mGoogleApiClient;
LocationRequest mLocationRequest;

@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;

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {


if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
buildGoogleApiClient();
mMap.setMyLocationEnabled(true);
}
}
else {
buildGoogleApiClient();
mMap.setMyLocationEnabled(true);
}

}
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API).build();
mGoogleApiClient.connect();
}

@Override
public void onConnected(Bundle bundle) {

mLocationRequest = new LocationRequest();


mLocationRequest.setInterval(1000);
mLocationRequest.setFastestInterval(1000);

mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {

LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,
mLocationRequest, this);
}

@Override
public void onConnectionSuspended(int i) { }
@Override
public void onLocationChanged(Location location) {

mLastLocation = location;
if (mCurrLocationMarker != null) {
mCurrLocationMarker.remove();
}
//Place current location marker
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title("Current Position");

markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREE
N));
mCurrLocationMarker = mMap.addMarker(markerOptions);

//move map camera


mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(11));

//stop location updates


if (mGoogleApiClient != null) {

LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
}

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {

public void searchLocation(View view) {


EditText locationSearch = (EditText) findViewById(R.id.editText);
String location = locationSearch.getText().toString();
List<Address> addressList = null;

if (location != null || !location.equals("")) {


Geocoder geocoder = new Geocoder(this);
try {
addressList = geocoder.getFromLocationName(location, 1);

} catch (IOException e) {
e.printStackTrace();
} Address address = addressList.get(0);
LatLng latLng = new LatLng(address.getLatitude(), address.getLongitude());
mMap.addMarker(new MarkerOptions().position(latLng).title(location));
mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
Toast.makeText(getApplicationContext(),address.getLatitude()+"
"+address.getLongitude(),Toast.LENGTH_LONG).show();
}
} }
Develop an android application for taking student feedback with database
connectivity.

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"
tools:context=".MainActivity">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Student Feedback Form" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:id="@+id/editname"/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Roll No." android:id="@+id/editrollno"/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Class"
android:id="@+id/editclass"/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your Feedback"
android:lines="3"
android:id="@+id/editfeedback"/>

<Button
android:text="Submit Feedback"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:id="@+id/button" />
</LinearLayout>

MapsActivity.java

package com.example.feedback;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


SQLiteDatabase sqLiteDatabaseObj;
Button submitBtn;
EditText std_name, std_rollno, std_class, std_feedback;
String sname, srollno, sclass, sfeedback, sql_query;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
submitBtn = (Button)findViewById(R.id.button);
std_name = (EditText)findViewById(R.id.editname);
std_rollno = (EditText)findViewById(R.id.editrollno);
std_class = (EditText)findViewById(R.id.editclass);
std_class = (EditText)findViewById(R.id.editfeedback);

submitBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sqLiteDatabaseObj = openOrCreateDatabase("FeedbaseDataBase",
Context.MODE_PRIVATE, null);
sqLiteDatabaseObj.execSQL("CREATE TABLE IF NOT EXISTS
Student(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name
VARCHAR, rollno VARCHAR, class VARCHAR, feedback VARCHAR);");
sname = std_name.getText().toString();
srollno = std_rollno.getText().toString() ;
sclass = std_class.getText().toString();
sfeedback = std_class.getText().toString();
sql_query = "INSERT INTO Student (name, rollno, class, feedback)
VALUES('"+sname+"', '"+srollno+"', '"+sclass+"', '"+sfeedback+"')";
sqLiteDatabaseObj.execSQL(sql_query);
Toast.makeText(getApplicationContext(), "Feedback Submitted
Successfully", Toast.LENGTH_LONG).show();
}
});

}
}
Develop an android application to show current location of an user's car

activity_maps.xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="example.com.mapexample.MapsActivity" />

MapsActivity.java
import android.os.Build;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;

import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.location.LocationServices;

import android.location.Location;
import android.Manifest; import android.content.pm.PackageManager;
import android.support.v4.content.ContextCompat;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback,


LocationListener,GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener{

private GoogleMap mMap;


Location mLastLocation;
Marker mCurrLocationMarker;
GoogleApiClient mGoogleApiClient;
LocationRequest mLocationRequest;

@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;

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {


if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
buildGoogleApiClient();
mMap.setMyLocationEnabled(true);
}
}
else {
buildGoogleApiClient();
mMap.setMyLocationEnabled(true);
}

}
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API).build();
mGoogleApiClient.connect();
}

@Override
public void onConnected(Bundle bundle) {

mLocationRequest = new LocationRequest(); mLocationRequest.setInterval(1000);


mLocationRequest.setFastestInterval(1000);

mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY)
;
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,
mLocationRequest, this);
}

}
@Override
public void onConnectionSuspended(int i) {

@Override
public void onLocationChanged(Location location) {

mLastLocation = location;
if (mCurrLocationMarker != null) {
mCurrLocationMarker.remove();
}
//Place current location marker
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title("Current Position");
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREE
N)); mCurrLocationMarker = mMap.addMarker(markerOptions);

//move map camera


mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(11));

//stop location updates


if (mGoogleApiClient != null) {
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient,
this);
}
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
}
Add the following user-permission in AndroidManifest.xml file.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />

Explain property animation method to animate the properties of view object with example.

A property animation changes a property's (a field in an object) value over a specified length
of time. To animate something, you specify the object property that you want to animate,
such as an object's position on the screen, how long you want to animate it for, and what
values you want to animate between.
The property animation system lets you define the following characteristics of an animation:
Duration: You can specify the duration of an animation. The default length is 300 ms.
Time interpolation: You can specify how the values for the property are calculated as afunction of the
animation's current elapsed time.
Repeat count and behavior: You can specify whether or not to have an animation repeat
when it reaches the end of a duration and how many times to repeat the animation. You can
also specify whether you want the animation to play back in reverse. Setting it to reverse
plays the animation forwards then backwards repeatedly, until the number of repeats is
reached.
Animator sets: You can group animations into logical sets that play together or sequentially
or after specified delays.
Frame refresh delay: You can specify how often to refresh frames of your animation. The
default is set to refresh every 10 ms, but the speed in which your application can refresh
frames is ultimately dependent on how busy the system is overall and how fast the system
can service the underlying timer.

Strings.xml
<resources>
<string name="app_name">Animation</string>
<string name="blink">BLINK</string>
<string name="fade">FADE</string>
<string name="move">MOVE</string>
</resources>

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">

<ImageView
android:id="@+id/imageview"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:contentDescription="@string/app_name"
android:src="@drawable/image" />

<LinearLayout
android:id="@+id/linear1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/imageview"
android:layout_marginTop="30dp"
android:orientation="horizontal"
android:weightSum="3">

<Button
android:id="@+id/BTNblink"
style="@style/TextAppearance.AppCompat.Widget.Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:padding="3dp"
android:text="@string/blink"
android:textColor="@color/white" />
<Button
android:id="@+id/BTNfade"
style="@style/TextAppearance.AppCompat.Widget.Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:padding="3dp"
android:text="@string/fade"
android:textColor="@color/white" />

<Button
android:id="@+id/BTNmove"
style="@style/TextAppearance.AppCompat.Widget.Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:padding="3dp"
android:text="@string/move"
android:textColor="@color/white" />

</LinearLayout>

</RelativeLayout>

1) Blink Animation
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="500"
android:repeatMode="reverse"
android:repeatCount="infinite"/>
</set>
2) Fade Animation
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<alpha
android:duration="1000"
android:fromAlpha="0"
android:toAlpha="1" />
<alpha
android:duration="1000"
android:fromAlpha="1"
android:startOffset="2000"
android:toAlpha="0" />
</set>
3) Move Animation
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true"><translate
android:fromXDelta="0%p"
android:toXDelta="75%p"
android:duration="700" />
</set>
MainActivity.java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

ImageView imageView;
Button blinkBTN, fadeBTN, moveBTN;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = findViewById(R.id.imageview);
blinkBTN = findViewById(R.id.BTNblink);
fadeBTN = findViewById(R.id.BTNfade);
moveBTN = findViewById(R.id.BTNmove);blinkBTN.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
// To add blink animation
Animation animation =
AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blink_animation);
imageView.startAnimation(animation);
}
});

fadeBTN.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// To add fade animation
Animation animation =
AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_animation);
imageView.startAnimation(animation);
}
});
moveBTN.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// To add move animation
Animation animation =
AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move_animation);
imageView.startAnimation(animation);
}
});
}
}

text to speech program

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:layout_margin="30dp"
tools:context=".MainActivity">

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/Text"
android:layout_marginBottom="20dp"
android:hint="Enter your text"
android:gravity="center"
android:textSize="16dp"/><Button
android:layout_width="wrap_content"
android:id="@+id/btnText"
android:layout_height="wrap_content"
android:text="Click"
android:layout_gravity="center"/>

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="70dp"
android:gravity="center_horizontal"
android:text="MobileApplicationDevelopment"
android:textSize="36sp" />

</LinearLayout>

MainActivity.java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.util.Locale;public class MainActivity extends AppCompatActivity {

EditText Text;
Button btnText;
TextToSpeech textToSpeech;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Text = findViewById(R.id.Text);
btnText = findViewById(R.id.btnText);

textToSpeech = new TextToSpeech(getApplicationContext(), new


TextToSpeech.OnInitListener() {
@Override
public void onInit(int i) {
if(i!=TextToSpeech.ERROR){
// To Choose language of speech
textToSpeech.setLanguage(Locale.UK);
}
}
});

btnText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

textToSpeech.speak(Text.getText().toString(),TextToSpeech.QUEUE_FLUSH,null);
}});

}
}

You might also like