Firstmergetest Removed
Firstmergetest Removed
11 JAVA CODE:
XML CODE: package com.example.pr8e2_simplecalculator;
<?xml version="1.0" encoding="utf-8"?> import androidx.appcompat.app.AppCompatActivity;
<LinearLayout import android.annotation.SuppressLint;
import android.os.Bundle;
xmlns:android="http://schemas.android.com/apk/res/a import android.view.View;
ndroid" import android.widget.Toast;
android:layout_width="match_parent" import android.widget.Button;
android:layout_height="match_parent" import android.widget.CheckBox;
android:orientation="vertical">
<CheckBox
android:id="@+id/checkBox1" public class MainActivity extends AppCompatActivity
android:layout_width="match_parent" {
android:layout_height="wrap_content" Button btn;
android:text="Mango" /> CheckBox c1,c2,c3,c4,c5;
<CheckBox
android:id="@+id/checkBox2" @SuppressLint("MissingInflatedId")
android:layout_width="match_parent" @Override
android:layout_height="wrap_content" protected void onCreate(Bundle savedInstanceState)
android:text="Orange" /> {
<CheckBox super.onCreate(savedInstanceState);
android:id="@+id/checkBox3" setContentView(R.layout.activity_main);
android:layout_width="match_parent"
android:layout_height="wrap_content" c1 = (CheckBox) findViewById(R.id.checkBox1);
android:text="Grape" /> c2 = (CheckBox) findViewById(R.id.checkBox2);
<CheckBox c3 = (CheckBox) findViewById(R.id.checkBox3);
android:id="@+id/checkBox4" c4 = (CheckBox) findViewById(R.id.checkBox4);
android:layout_width="match_parent" c5 = (CheckBox) findViewById(R.id.checkBox5);
android:layout_height="wrap_content" btn = (Button) findViewById(R.id.button);
android:text="Watermelon" /> btn.setOnClickListener(new
<CheckBox View.OnClickListener() {
android:id="@+id/checkBox5" @Override
android:layout_width="match_parent" public void onClick(View view) {
android:layout_height="wrap_content" String val = "Selected Items:";
android:text="Strawberry" /> if(c1.isChecked()){
val += ", Mango";
<Button } else if (c2.isChecked()) {
android:id="@+id/button" val += ", Orange";
android:layout_width="120dp" } else if (c3.isChecked()) {
android:layout_height="wrap_content" val += ", Grape";
android:layout_gravity="center" } else if (c4.isChecked()) {
android:text="CLick" /> val += ", Watermelon";
</LinearLayout> } else if (c5.isChecked()) {
val += ", Strawberry";
}
Toast.makeText(MainActivity.this,val.toString(),
Toast.LENGTH_LONG).show();
}
});
}
}
PRACTICAL NO. 12 android:layout_gravity="center"
android:text="Submit" />
XML CODE:
<?xml version="1.0" encoding="utf-8"?> </LinearLayout>
<LinearLayout
JAVA CODE:
xmlns:android="http://schemas.android.com/apk/res/a
ndroid" package com.example.pr8e2_simplecalculator;
android:layout_width="match_parent" import androidx.appcompat.app.AppCompatActivity;
android:layout_height="match_parent" import android.annotation.SuppressLint;
android:orientation="vertical"> import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
<TextView import android.widget.Button;
android:id="@+id/textView" import android.widget.RadioButton;
android:layout_width="match_parent" import android.widget.RadioGroup;
android:layout_height="wrap_content"
android:text="Single Radio Buttons" /> public class MainActivity extends AppCompatActivity
{
<RadioButton Button btn;
android:id="@+id/radioButton" RadioButton r1,r2,r3,r4;
android:layout_width="match_parent"
android:layout_height="wrap_content" @SuppressLint("MissingInflatedId")
android:text="Boy" /> @Override
protected void onCreate(Bundle savedInstanceState)
<RadioButton {
android:id="@+id/radioButton2" super.onCreate(savedInstanceState);
android:layout_width="match_parent" setContentView(R.layout.activity_main);
android:layout_height="wrap_content"
android:text="Girl" /> r1 = (RadioButton)
findViewById(R.id.radioButton);
<RadioGroup r2 = (RadioButton)
android:layout_width="match_parent" findViewById(R.id.radioButton2);
android:layout_height="131dp"> r3 = (RadioButton)
findViewById(R.id.radioButton3);
<TextView r4 = (RadioButton)
android:id="@+id/textView2" findViewById(R.id.radioButton4);
android:layout_width="match_parent" btn = (Button) findViewById(R.id.button3);
android:layout_height="wrap_content" btn.setOnClickListener(new
android:text="Radio Buttons inside View.OnClickListener() {
RadioGroup" /> @Override
public void onClick(View view) {
<RadioButton String val = "";
android:id="@+id/radioButton3" if(r1.isChecked()){
android:layout_width="match_parent" val +=", Boy";
android:layout_height="wrap_content" }
android:text="Male" /> if(r2.isChecked()){
val +=", Girl";
<RadioButton }
android:id="@+id/radioButton4" if(r3.isChecked()){
android:layout_width="match_parent" val +=", Male";
android:layout_height="wrap_content" }
android:text="Femal" /> if(r4.isChecked()){
val +=", Female";
</RadioGroup> }
<Button Toast.makeText(getApplicationContext(),"Selected
android:id="@+id/button3" Items: "+val,Toast.LENGTH_LONG).show();
android:layout_width="wrap_content" }});}}
android:layout_height="wrap_content"
PRACTICAL NO. 13
E1: XML CODE: OUTPUT:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/a
ndroid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:layout_height="152dp" />
</LinearLayout>
JAVA CODE:
package com.example.pr8e2_simplecalculator;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
p = (ProgressBar)
findViewById(R.id.progressBar);
p.setProgress(50);
}
}
E2: XML CODE:
Main_Activity.xml JAVA CODE:
<?xml version="1.0" encoding="utf-8"?> package com.example.progress_bar_demo; import
<RelativeLayout xmlns:android androidx.appcompat.app.AppCompatActivity; import
android.app.ProgressDialog; import
="http://schemas.android.com/apk/res/android"
android.os.Bundle; import android.view.View; import
xmlns:app="http://schemas.android.com/apk/res-auto"
android.widget.Button;
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" public class MainActivity extends AppCompatActivity
android:layout_height="match_parent" {
tools:context=".MainActivity">
Button bt; ProgressDialog progressDialog; @Override
<Button
protected void onCreate(Bundle savedInstanceState)
android:layout_width="wrap_content" { super.onCreate(savedInstanceState);
android:layout_height="wrap_content" setContentView(R.layout.activity_main);
android:id="@+id/down" android:text="Download" bt=(Button)findViewById(R.id.down);
android:layout_centerHorizontal="true" ></Button>
bt.setOnClickListener(new View.OnClickListener()
</RelativeLayout> { @Override public void onClick(View v)
{ progressDialog=new ProgressDialog(MainActivity.
Pro_dailog.xml
this);
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android progressDialog.show();
progressDialog.setContentView(R.layout.pro_dailog);
="http://schemas.android.com/apk/res/android"
} }); }
android:orientation="vertical"
android:layout_width="match_parent" @Override public void onBackPressed()
android:layout_height="match_parent"> { super.onBackPressed(); progressDialog.dismiss();
<LinearLayout android:layout_width="match_parent"
}}
android:layout_height="wrap_content"
android:orientation="vertical" OUTPUT:
android:padding="25dp"
android:background="@drawable/rg_round" >
<ProgressBar android:layout_width="wrap_content"
android:layout_height="wrap_content"></ProgressBar
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:textSize="20dp" android:text="Loading......"
></TextView>
</LinearLayout> </RelativeLayout>
Rg_round.xml
<?xml version="1.0" encoding="utf-8"?> <shape
xmlns:android
="http://schemas.android.com/apk/res/android">
<solid
android:color="@android:color/holo_blue_bright"
></solid> <corners android:radius="25dp"></corners>
</shape>
PRACTICAL NO. 14
E2: XML CODE: iv.setImageResource(R.drawable.img1);
bt.setOnClickListener(new
<?xml version="1.0" encoding="utf-8"?>
View.OnClickListener() {
<RelativeLayout
@Override
xmlns:android="http://schemas.android.com/apk/res/a
public void onClick(View view) {
ndroid"
cnt++;
xmlns:app="http://schemas.android.com/apk/res-
if(cnt>2){
auto"
cnt = 1;
xmlns:tools="http://schemas.android.com/tools"
}
android:layout_width="match_parent"
switch (cnt){
android:layout_height="match_parent"
case 1:
android:padding="16dp">
iv.setImageResource(R.drawable.img1);
break;
<ImageButton
case 2:
android:id="@+id/imageButton2"
iv.setImageResource(R.drawable.img2);
android:layout_width="298dp"
break;
android:layout_height="233dp"
}
android:layout_centerInParent="true"
}
tools:ignore="SpeakableTextPresentCheck"
});
tools:srcCompat="@drawable/img1" />
<Button
}
android:id="@+id/buttonChangeImage"
}
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
OUTPUT:
android:layout_marginTop="16dp"
android:text="Change Image" />
</RelativeLayout>
JAVA CODE:
package com.example.pr8e2_simplecalculator;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity
{
ImageView iv;
Button bt;
int cnt = 1;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView)
findViewById(R.id.imageButton2);
bt = (Button)
findViewById(R.id.buttonChangeImage);
E3: XML CODE: R.id.btn, arr);
gridview.setAdapter(ad);
Main_activity.xml
}
<?xml version= "1.0" encoding= "utf-8" ?>
<GridView
xmlns:android="http://schemas.android.com/apk/res/a OUTPUT:
ndroid"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/gridview"
android:layout_width="fill_parent"
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>
Activity_listview.xml
<Button
android:id="@+id/btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</LinearLayout>
JAVA CODE:
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,
PRACTICAL NO. 15
E1 XML CODE: JAVA CODE:
package com.example.myapplication11;
<?xml version="1.0" encoding="utf-8"?> import android.os.Bundle;
<RelativeLayout import android.view.View;
import android.widget.Button;
xmlns:android="http://schemas.android.com/apk/res/a import android.widget.CheckBox;
ndroid" import android.widget.Toast;
xmlns:app="http://schemas.android.com/apk/res-auto" import androidx.appcompat.app.AppCompatActivity;
xmlns:tools="http://schemas.android.com/tools" public class MainActivity extends AppCompatActivity
android:layout_width="match_parent" {
android:layout_height="match_parent" CheckBox pizza,coffe,burger;
tools:context=".MainActivity"> Button buttonOrder;
<TextView @Override
android:layout_width="wrap_content" protected void onCreate(Bundle savedInstanceState) {
android:layout_height="wrap_content" super.onCreate(savedInstanceState);
android:id="@+id/tv" setContentView(R.layout.activity_main);
android:layout_marginTop="10dp" addListenerOnButtonClick();
android:layout_marginLeft="10dp" }
android:text="Hello World, Toast Example"> public void addListenerOnButtonClick(){
</TextView> buttonOrder=(Button)findViewById(R.id.button);
<Button buttonOrder.setOnClickListener(new
android:id="@+id/button" View.OnClickListener(){
android:layout_width="wrap_content" @Override
android:layout_height="wrap_content" public void onClick(View view) {
android:layout_below="@+id/tv" Toast.makeText(MainActivity.this, "Message for you:
android:layout_marginLeft="14dp" You
android:text="Show Toast" /> have got mail!", Toast.LENGTH_LONG).show();
</RelativeLayout> }
});
}
}
OUTPUT:
E2 XML CODE: JAVA CODE:
package com.example.myapplication11;
<?xml version="1.0" encoding="utf-8"?> import android.os.Bundle;
<android.support.constraint.ConstraintLayout import android.view.View;
import android.widget.Button;
xmlns:android="http://schemas.android.com/apk/res/a import android.widget.CheckBox;
ndroid" import android.widget.Toast;
xmlns:app="http://schemas.android.com/apk/res-auto" import androidx.appcompat.app.AppCompatActivity;
xmlns:tools="http://schemas.android.com/tools" public class MainActivity extends AppCompatActivity
android:layout_width="match_parent" {
android:layout_height="match_parent" CheckBox pizza,coffe,burger;
Button buttonOrder;
tools:context="example.javatpoint.com.checkbox.Mai @Override
nActivity"> protected void onCreate(Bundle savedInstanceState) {
<CheckBox super.onCreate(savedInstanceState);
android:id="@+id/checkBox" setContentView(R.layout.activity_main);
android:layout_width="wrap_content" addListenerOnButtonClick(); }
android:layout_height="wrap_content" public void addListenerOnButtonClick(){
android:layout_marginLeft="144dp" pizza=(CheckBox)findViewById(R.id.checkBox);
android:layout_marginTop="68dp" coffe=(CheckBox)findViewById(R.id.checkBox2);
android:text="Pizza" burger=(CheckBox)findViewById(R.id.checkBox3);
app:layout_constraintStart_toStartOf="parent" buttonOrder=(Button)findViewById(R.id.button);
app:layout_constraintTop_toTopOf="parent" /> buttonOrder.setOnClickListener(new
<CheckBox View.OnClickListener(){
android:id="@+id/checkBox2" @Override
android:layout_width="wrap_content" public void onClick(View view) {
android:layout_height="wrap_content" int totalamount=0;
android:layout_marginLeft="144dp" StringBuilder result=new StringBuilder();
android:layout_marginTop="28dp" result.append("Selected Items:");
android:text="Coffee" if(pizza.isChecked()){ result.append("\nPizza
app:layout_constraintStart_toStartOf="parent" 100Rs");
app:layout_constraintTop_toBottomOf="@+id/checkB totalamount+=100; }
ox" /> if(coffe.isChecked()){ result.append("\nCoffe 50Rs");
<CheckBox totalamount+=50; }
android:id="@+id/checkBox3" if(burger.isChecked()){ result.append("\nBurger
android:layout_width="wrap_content" 120Rs");
android:layout_height="wrap_content" totalamount+=120; }
android:layout_marginLeft="144dp" result.append("\nTotal: "+totalamount+"Rs");
android:layout_marginTop="28dp" Toast.makeText(getApplicationContext(),result.toStrin
android:text="Burger" g(),Toast.LENGTH_LONG)
app:layout_constraintStart_toStartOf="parent" .show(); } }); }}
app:layout_constraintTop_toBottomOf="@+id/checkB
ox2" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="144dp"
android:layout_marginTop="184dp"
android:text="Order"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkB
ox3" />
</android.support.constraint.ConstraintLayout>
PRACTICAL NO. 16
E1 JAVA CODE: XML CODE:
package com.example.myapplication11;
import android.os.Bundle; <?xml version="1.0" encoding="utf-8"?>
import android.view.View; <RelativeLayout
import android.widget.Button; xmlns:android="http://schemas.android.com/apk/res/android"
import android.widget.TextView; xmlns:app="http://schemas.android.com/apk/res-auto"
import android.widget.TimePicker; xmlns:tools="http://schemas.android.com/tools"
import androidx.appcompat.app.AppCompatActivity; android:layout_width="match_parent"
android:layout_height="match_parent"
public class MainActivity extends AppCompatActivity { tools:context="example.javatpoint.com.timepicker.MainActivit
TextView textview1; y">
TimePicker timepicker; <TextView
Button changetime; android:id="@+id/textView1"
android:layout_width="wrap_content"
@Override android:layout_height="wrap_content"
protected void onCreate(Bundle savedInstanceState) { android:layout_above="@+id/button1"
super.onCreate(savedInstanceState); android:layout_alignParentLeft="true"
setContentView(R.layout.activity_main); android:layout_alignParentStart="true"
textview1 = (TextView) findViewById(R.id.textView1); android:layout_marginBottom="102dp"
timepicker = (TimePicker) findViewById(R.id.timePicker); android:layout_marginLeft="30dp"
timepicker.setIs24HourView(true); android:layout_marginStart="30dp" android:text="" />
changetime = (Button) findViewById(R.id.button1);
textview1.setText(getCurrentTime()); <Button
changetime.setOnClickListener(new View.OnClickListener() android:id="@+id/button1"
{ android:layout_width="wrap_content"
@Override android:layout_height="wrap_content"
public void onClick(View view) { android:layout_alignParentBottom="true"
textview1.setText(getCurrentTime()); android:layout_centerHorizontal="true"
} android:layout_marginBottom="20dp"
}); android:text="Change Time" />
}
<TimePicker
public String getCurrentTime(){ String android:id="@+id/timePicker"
currentTime="Current Time: android:layout_width="wrap_content"
"+timepicker.getCurrentHour()+":"+timepicker.getCurrentMinute android:layout_height="wrap_content"
(); return currentTime; android:layout_above="@+id/textView1"
} android:layout_centerHorizontal="true"
android:layout_marginBottom="36dp" />
} </RelativeLayout>
Output:
E2 JAVA CODE: @Override
package com.example.myapplication11; public void onTimeSet(TimePicker view, int
import android.app.DatePickerDialog; hourOfDay, int minute) {
import android.app.TimePickerDialog; txtTime.setText(hourOfDay + ":" + minute);
import android.os.Bundle; }
import android.view.View; }, mHour, mMinute, false);
import android.widget.Button; timePickerDialog.show();
import android.widget.DatePicker; }
import android.widget.EditText; }
import android.widget.TimePicker; }
import androidx.appcompat.app.AppCompatActivity;
import java.util.Calendar;
public class MainActivity extends AppCompatActivity XML CODE:
implements
View.OnClickListener {
<?xml version="1.0" encoding="utf-8"?>
Button btnDatePicker, btnTimePicker;
EditText txtDate, txtTime;
<RelativeLayout
private int mYear, mMonth, mDay, mHour, mMinute; xmlns:android="http://schemas.android.com/apk/res/and
@Override roid"
protected void onCreate(Bundle savedInstanceState) { xmlns:app="http://schemas.android.com/apk/res-auto"
super.onCreate(savedInstanceState); xmlns:tools="http://schemas.android.com/tools"
setContentView(R.layout.activity_main); android:layout_width="match_parent"
btnDatePicker = (Button) findViewById(R.id.btn_date); android:layout_height="match_parent"
btnTimePicker = (Button) findViewById(R.id.btn_time); tools:context=".MainActivity">
txtDate = (EditText) findViewById(R.id.in_date);
txtTime = (EditText) findViewById(R.id.in_time); <EditText android:layout_width="200dp"
btnDatePicker.setOnClickListener(this); android:layout_height="wrap_content"
btnTimePicker.setOnClickListener(this); android:id="@+id/in_date"
}
android:layout_marginTop="82dp"
@Override
public void onClick(View v) {
android:layout_alignParentTop="true"
if (v == btnDatePicker) { android:layout_alignParentStart="true" />
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR); <Button android:layout_width="wrap_content"
mMonth = c.get(Calendar.MONTH); android:layout_height="wrap_content"
mDay = c.get(Calendar.DAY_OF_MONTH); android:text="SELECT DATE"
DatePickerDialog datePickerDialog = new android:id="@+id/btn_date"
DatePickerDialog(this, new android:layout_alignBottom="@+id/in_date"
DatePickerDialog.OnDateSetListener() { android:layout_toEndOf="@+id/in_date" />
@Override
public void onDateSet(DatePicker view, int year, int <EditText android:layout_width="200dp"
monthOfYear, int dayOfMonth) { android:layout_height="wrap_content"
txtDate.setText(dayOfMonth + "-" + (monthOfYear +
android:id="@+id/in_time"
1) + "-" + year);
android:layout_below="@+id/in_date"
}
}, mYear, mMonth, mDay);
android:layout_alignParentStart="true" />
datePickerDialog.show();
} <Button android:layout_width="wrap_content"
if (v == btnTimePicker) { android:layout_height="wrap_content"
final Calendar c = Calendar.getInstance(); android:text="SELECT TIME"
mHour = c.get(Calendar.HOUR_OF_DAY); android:id="@+id/btn_time"
mMinute = c.get(Calendar.MINUTE); android:layout_below="@+id/btn_date"
TimePickerDialog timePickerDialog = new android:layout_alignLeft="@+id/btn_date"
TimePickerDialog(this, new android:layout_alignStart="@+id/btn_date" />
TimePickerDialog.OnTimeSetListener() { </RelativeLayout>
PRACTICAL NO. 18
E1 XML CODE: import android.view.View;
import android.widget.Button;
<?xml version="1.0" encoding="utf-8"?> import android.widget.EditText;
<RelativeLayout import androidx.appcompat.app.AppCompatActivity;
xmlns:android="http://schemas.android.com/apk/res/a
ndroid" public class MainActivity extends
xmlns:tools="http://schemas.android.com/tools" AppCompatActivity {
xmlns:app="http://schemas.android.com/apk/res- private EditText urlEditText;
auto" private Button navigateButton;
android:layout_width="match_parent"
android:layout_height="match_parent" @Override
tools:context=".MainActivity"> protected void onCreate(Bundle savedInstanceState)
<EditText android:id="@+id/urlEditText" {
android:layout_width="match_parent" super.onCreate(savedInstanceState);
android:layout_height="wrap_content" setContentView(R.layout.activity_main);
android:layout_marginTop="20sp" urlEditText = findViewById(R.id.urlEditText);
android:layout_marginLeft="5sp" navigateButton =
android:hint="Enter URL" findViewById(R.id.navigateButton);
android:inputType="textUri" /> navigateButton.setOnClickListener(new
<Button android:id="@+id/navigateButton" View.OnClickListener() {
android:layout_width="wrap_content" @Override
android:layout_height="wrap_content" public void onClick(View v) {
android:layout_below="@id/urlEditText" String url = urlEditText.getText().toString();
android:layout_marginTop="32dp" if (!url.isEmpty()) {
android:text="Navigate" /> if (!url.startsWith("http://") &&
</RelativeLayout> !url.startsWith("https://")) {
url = "http://" + url;
}
Intent intent = new
Intent(Intent.ACTION_VIEW, Uri.parse(url));
JAVA CODE: startActivity(intent);
package com.example.pr_18_01; }
import androidx.appcompat.app.AppCompatActivity; }
import android.os.Bundle; });
import android.content.Intent; }
import android.net.Uri; }
import android.os.Bundle;
OUTPUT:
E2 XML CODE:
JAVA CODE:
package com.example.pr_18_02;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startDialerButton = findViewById(R.id.startDialerButton);
startDialerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:"));
startActivity(intent);
}
});
}
}
OUTPUT:
/* Java code for Broadcast receiver to handle System Intent head
phone */
package com.example.lifecycle;
import androidx.appcompat.app.AppCompatActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int iii;
if(Intent.ACTION_HEADSET_PLUG.equals(intent.getAction()))
iii = intent.getIntExtra("state",-1);
if (iii == 0) {
// Microphone_Plugged_in = false;
Toast.makeText(getApplicationContext(),
"microphone not plugged in", Toast.LENGTH_LONG).show();
}
if (iii == 1) {
}
}; // End of broadcast Receiver
JAVA CODE:
package com.example.text_bt_demo;
import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText edt1, edt2;
Button btt;
int counter = 3;
@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edt1=(EditText)findViewById(R.id.et1); edt2=(EditText)findViewById(R.id.et2);
btt=(Button)findViewById(R.id.bt1);
btt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v)
{ validate(edt1.getText().toString() ,edt2.getText().toString()
); } }); }
OUTPUT:
PRACTICAL NO. 28
XML CODE:
<?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">
<TextView android: id="@+id/tv1" android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#E91E63" android:freezesText="false" android:text="@string/user_name"
android:textSize="24sp" app:fontFamily="@font/asul" android:layout_marginLeft="6mm"
android:layout_marginTop="4mm"></TextView>
<EditText android:id="@+id/et1" android:layout_width="200dp" android:layout_height="40dp"
android:layout_toRightOf="@id/tv1" android:background="#FFEB3B" android:inputType="text"
android:layout_marginLeft="4mm" android:layout_marginTop="4mm"></EditText>
<TextView android:id="@+id/tv2" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:background="#E91E63"
android:freezesText="false" android:text="@string/password" android:textSize="24sp"
app:fontFamily="@font/asul" android:layout_marginLeft="6mm" android:layout_marginTop="12mm"
android:layout_marginStart="6mm"></TextView>
<EditText android:id="@+id/et2" android:layout_width="200dp" android:layout_height="40dp"
android:layout_toRightOf="@id/tv2" android:background="#FFEB3B"
android:inputType="textPassword" android:layout_marginLeft="6mm"
android:layout_marginTop="12mm" android:autofillHints="" android:layout_toEndOf="@id/tv2"
android:layout_marginStart="6mm"></EditText>
<Button android:id="@+id/b1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Login" android:layout_marginTop="22mm"
android:layout_marginLeft="30mm" />
</RelativeLayout>
JAVA CODE:
package com.example.login2;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
OUTPUT:
PRACTICAL NO. 30
XML CODE:
<?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"
android:padding="16dp"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="To:"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:id="@+id/edit_text_to"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Subject:"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:id="@+id/edit_text_subject"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailSubject" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Message:"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:id="@+id/edit_text_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start|top"
android:lines="10" />
<Button
android:id="@+id/button_send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="send" />
</LinearLayout>
JAVA CODE:
package com.example.progress_test; @Override
import androidx.appcompat.app.AppCompatActivity; public void onClick(View v) {
import android.content.Intent; sendMail();
import android.os.Bundle; }
import android.view.View; });
import android.widget.Button; }
import android.widget.EditText; private void sendMail() {
public class MainActivity extends AppCompatActivity String recipientList =
{ mEditTextTo.getText().toString();
private EditText String[] recipients = recipientList.split(",");
mEditTextTo,mEditTextSubject,mEditTextMessage; String subject =
@Override mEditTextSubject.getText().toString();
protected void onCreate(Bundle savedInstanceState) String message =
{ mEditTextMessage.getText().toString();
super.onCreate(savedInstanceState); Intent intent = new
setContentView(R.layout.activity_main); Intent(Intent.ACTION_SEND);
mEditTextTo = findViewById(R.id.edit_text_to); intent.putExtra(Intent.EXTRA_EMAIL,
mEditTextSubject = recipients);
findViewById(R.id.edit_text_subject); intent.putExtra(Intent.EXTRA_SUBJECT,
mEditTextMessage = subject);
findViewById(R.id.edit_text_message); intent.putExtra(Intent.EXTRA_TEXT, message);
Button buttonSend = intent.setType("message/rfc822");
findViewById(R.id.button_send); startActivity(Intent.createChooser(intent,
buttonSend.setOnClickListener(new "Choose an email client"));
View.OnClickListener() { }
}
OUTPUT:
PRACTICAL NO. 31
XML CODE:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapsactivity">
<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"
/>
<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">
<meta-data android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyBmVKWtO8pRNWj2bGAvKUD1wRNMbri_2s" />
<activity android:name=".MapsActivity" android:label="@string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN"
/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
JAVA CODE:
package com.example.mapsactivity;
import androidx.fragment.app.FragmentActivity;
import android.os.Bundle;
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;
@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);
}
/** * Manipulates the map once available. * This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia. * If Google Play services is not installed on the device, the user will
be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app. */
@Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap;// Add a marker in Sydney
and move the camera LatLng sandip = new LatLng(19.9631228, 73.6645247); mMap.addMarker(new
MarkerOptions().position(sandip).title("Sandip Polytechnic,Nashik"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sandip));
}
}
OUTPUT: