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

all practical final-1

Uploaded by

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

all practical final-1

Uploaded by

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

Practical No 4

Q 1 wirte a program display hello word in android application


XML Code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Java Code:
package com.example.first;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Output:
Practical No 5

X.1) Write a program to place Name ,Age and Mobile number linearly
(vertical) on the display screen using Linear layout

XML Code:
<?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">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name: Rutuja Satish Vathare" />

<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Age: 18" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Mobile No: 8830794008" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Java Code:
package com.example.linearlayout;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

Output

2) Write a program to place Name ,Age and Mobile number linearly (vertical) on the display
screen using Linear layout

XML Code:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout 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:paddingLeft="16dp"
android:paddingTop="16dp"
android:paddingRight="16dp"
tools:context=".MainActivity">

<TextView
android:id="@+id/student_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="125dp"
android:layout_y="280dp"
android:text="Name:Rutuja Vathare"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="125dp"
android:layout_y="304dp"
android:text="Age:18"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="125dp"
android:layout_y="328dp"
android:text="Mobile No:8830794008"
android:textSize="20dp"
android:textStyle="bold"/>
</AbsoluteLayout>

Java Code:
package com.example.linearlayout;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Output:
Practical No 6
X) 1) Write a program to display 10 students basic information in a table
from using Table layout.

XML Code:
<?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"
android:layout_margin="20dp"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Student Basic Information!"
android:textSize="24sp"
android:textStyle="bold"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText"/>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sr.No"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Student Name"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rutuja Vathare"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delhi"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Raj Patil"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pune"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>
</TableRow>

<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tanushree Patil"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Goa"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Aditya Khot"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sangli"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mohini Magdum"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mumbai"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rahual Chougule"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Thane"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sanjana Babar"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ichalkaranji"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rohan Deshmukh"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pune"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kartik Magdum"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Satara"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Neha Khot"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Karad"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>
</TableRow>
</TableLayout>

Java Code:
package com.example.myapplicationpr5a;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

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

Output:
2) Write a program to display all the data types in object-oriented programming using
Frame layout.

XML Code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:id="@+id/Frame_Layout"
tools:context=".MainActivity">

<Button
android:layout_width="187dp"
android:layout_height="334dp"
android:layout_gravity="top|start"
android:text="Datatype Name:Integer, Keyword:int,size:4byte"/>

<Button
android:layout_width="187dp"
android:layout_height="334dp"
android:layout_gravity="top|end"
android:text="Datatype Name:Floating point, Keyword:float,size:4byte"/>
<Button
android:layout_width="187dp"
android:layout_height="334dp"
android:layout_gravity="bottom|start"
android:text="Datatype Name:Character, Keyword:char,size:1byte"/>

<Button
android:layout_width="187dp"
android:layout_height="334dp"
android:layout_gravity="bottom|end"
android:text="Datatype Name:Double, Keyword:double,size:8byte" />
</FrameLayout>

Java Code:
package com.example.pr52;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

Output:
Practical No 7
X.1)Write a program to accept username and password from the end user
using Text View and Edit Text
XML Code:
<?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"
tools:context=".MainActivity"
android:layout_margin="20dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="24sp"
android:textStyle="bold"
android:layout_gravity="center"
android:layout_margin="20dp"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:layout_marginTop="30dp"
android:textAlignment="center"
android:textSize="22sp"
android:textColor="@color/black"
android:textStyle="bold"
tools:ignore="HardcodedText" />

<EditText
android:id="@+id/username1"
android:layout_width="match_parent"
android:layout_height="96dp"
android:hint="Username"
android:importantForAutofill="no"
android:inputType="text"
tools:ignore="HardcodedText" />

<EditText
android:id="@+id/pass2"
android:layout_width="match_parent"
android:layout_height="89dp"
android:hint="Password"
android:inputType="textPassword"
tools:ignore="Autofill,HardcodedText" />

<Button
android:layout_width="match_parent"
android:layout_marginTop="50dp"
android:layout_height="wrap_content"
android:text="Login"
android:id="@+id/loginbtn"
tools:ignore="HardcodedText"/>

<Button
android:layout_width="match_parent"
android:layout_marginTop="5dp"
android:layout_height="wrap_content"
android:text="Exit"
android:id="@+id/exitbtn"
tools:ignore="HardcodedText"/>

</LinearLayout>

Java Code:
package com.example.pr7;
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 {

private Button b1,b2;


EditText ed1,ed2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = findViewById(R.id.loginbtn);
b2 = findViewById(R.id.exitbtn);
ed1 = findViewById(R.id.username1);
ed2 = findViewById(R.id.pass2);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(ed1.getText().toString().equals("Admin")&&
ed2.getText().toString().equals("Admin@123")){
Toast.makeText(getApplicationContext(), "Login
Successful",Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(getApplicationContext(), "Something went
wrong",Toast.LENGTH_SHORT).show();
}
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
}
}
Output:
2) Write a program to accept and display personal information of the student.
XML Code:
<?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"
tools:context=".MainActivity"
android:layout_margin="20dp"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Personal Information!"
android:textAlignment="center"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText" />

<EditText
android:id="@+id/edName"
android:layout_width="match_parent"
android:layout_height="76dp"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="Enter your name"
android:inputType="textPersonName"
android:textSize="18sp"
tools:ignore="Autofill,HardcodedText" />

<EditText
android:id="@+id/eddob"
android:layout_width="match_parent"
android:layout_height="69dp"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="Enter Date Of Birth"
android:inputType="date"
android:textSize="18sp"
tools:ignore="Autofill,HardcodedText" />

<EditText
android:id="@+id/edaddress"
android:layout_width="match_parent"
android:layout_height="74dp"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="Enter your address"
android:inputType="textCapCharacters"
android:textSize="18sp"
tools:ignore="HardcodedText" />

<EditText
android:id="@+id/edEmail"
android:layout_width="match_parent"
android:layout_height="71dp"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="Enter Email Id"
android:inputType="textEmailAddress"
android:textSize="18sp"
tools:ignore="HardcodedText" />

<EditText
android:id="@+id/edcontact"
android:layout_width="match_parent"
android:layout_height="68dp"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="Enter Mobile Number"
android:inputType="date"
android:textSize="18sp"
tools:ignore="HardcodedText" />

<Button
android:id="@+id/submitbtn"
android:layout_width="match_parent"
android:layout_height="64dp"
android:layout_marginTop="50dp"
android:text="Submit"
android:textSize="18sp"
tools:ignore="HardcodedText" />

</LinearLayout>
Java Code:
package com.example.pr7_2;
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 {

private EditText name,dob,address,email,contact;


private Button submit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
submit=findViewById(R.id.submitbtn);
name=findViewById(R.id.edName);
dob=findViewById(R.id.eddob);
address=findViewById(R.id.edaddress);
email=findViewById(R.id.edEmail);
contact=findViewById(R.id.edcontact);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String n = name.getText().toString();
String d = dob.getText().toString();
String add = address.getText().toString();
String e = email.getText().toString();
String number = contact.getText().toString();
if(n.isEmpty() || d.isEmpty() || add.isEmpty() || e.isEmpty() ||number.isEmpty())
{
Toast.makeText(MainActivity.this, "Please fill all the fields",
Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(MainActivity.this, n +"\n" +d + "\n"+ add + "\n"+ e + "\n"+
number + "\n", Toast.LENGTH_SHORT).show();
}
}
});
}
}
Output:
Practical No:8
X.1) Write a program to create a first display screen of any search engine
using Auto Complete Text View.
XML File:
<?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"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_margin="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Search Engine"
android:textSize="20sp"
android:textAlignment="center"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="76dp"
android:layout_marginTop="20dp"
android:hint="Search....."
android:textColor="@color/black"
android:textSize="18sp"
tools:ignore="HardcodedText" />
</LinearLayout>
Java Code:
package com.example.pr8;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class MainActivity extends AppCompatActivity {
private AutoCompleteTextView autoCompleteTextView;
private String search_engine[]={"Google","Yahoo","Bing","Wiki"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
autoCompleteTextView =findViewById(R.id.autoCompleteTextView);
ArrayAdapter<String> adapter = new
ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,search_engine);
autoCompleteTextView.setAdapter(adapter);
}
}
Output:

2) Write a program to display all the subjects of sixth semester using Auto Complete
Text View.
XML code:
<?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"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_margin="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sixth Semester Subjects"
android:textSize="20sp"
android:textAlignment="center"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="76dp"
android:layout_marginTop="20dp"
android:hint="Subjects"
android:textColor="@color/black"
android:textSize="18sp"
tools:ignore="HardcodedText" />
</LinearLayout>
Java Code:
package com.example.pr8b;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class MainActivity extends AppCompatActivity {
private AutoCompleteTextView autoCompleteTextView;
private String subject[]={"PHP","Python","Android","EDI","EDE","MANAGEMENT"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
autoCompleteTextView =findViewById(R.id.autoCompleteTextView);
ArrayAdapter<String> adapter = new
ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,subject);
autoCompleteTextView.setAdapter(adapter);
}
}Output:
Practical No:9
X) 1. Write a program to create a toggle button to display ON/OFF
Bluetooth on the display screen.
XML code:
<?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"
tools:context=".MainActivity"
android:layout_margin="20dp"
android:orientation="vertical">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toggle Button Program"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
android:textAlignment="center"
tools:ignore="HardcodedText" />

<ToggleButton
android:id="@+id/toggleBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Toggle Button"
android:textOff="OFF"
android:textOn="ON"
android:textSize="18sp"
tools:ignore="HardcodedText" />
</LinearLayout>

Java Code:

package com.example.pr9togglebutton;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.ToggleButton;
public class MainActivity extends AppCompatActivity {
private ToggleButton toggleButton;
private TextView textView;

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

toggleButton=findViewById(R.id.toggleBtn);
textView=findViewById(R.id.textView);
toggleButton.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean
isChecked) {

if(isChecked){
textView.setText("Blutooth is"+toggleButton.getTextOn());
}
else{
textView.setText("Blutooth is"+toggleButton.getTextOff());
}

}
});}
Output:
Practical No: 10
X.) 1) Write a program to create a login form for social networking site.
XML Code:
<?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"
tools:context=".MainActivity"
android:orientation="vertical"
android:background="#49588F"
android:layout_margin="20dp">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="F A C E B O O K"
android:textAlignment="center"
android:layout_marginTop="40dp"
android:textSize="40sp"
android:textColor="@color/white"
tools:ignore="HardcodedText"/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email or phone number"
android:padding="10dp"
android:textSize="22sp"
android:fontFamily="monospace"
android:layout_marginTop="30dp"
android:background="@color/white"
tools:ignore="Autofill,HardcodedText,TextFields"/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:textSize="22sp"
android:background="@color/white"
android:layout_marginTop="15dp"
android:padding="10dp"
android:fontFamily="monospace"
tools:ignore="HardcodedText"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Forgot Password ??"
android:layout_marginTop="10dp"
android:textColor="@color/white"
android:textSize="18sp"
android:textAlignment="textEnd"
tools:ignore="HardcodedText"/>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="35dp"
android:padding="5dp"
android:text="Log In"
android:textSize="18sp"
android:textColor="@color/white"
tools:ignore="HardcodedText"/>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Create New Account"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="18sp"
tools:ignore="HardcodedText"/>
</LinearLayout>

Java Code:

package com.example.a10socialnetworkingsite;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Output:

2) Write a program to create a login form for student registration system.

XML Code:
<?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"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_margin="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Student Registration Form"
android:textSize="24sp"
android:textStyle="bold"
android:layout_marginTop="50dp"
android:textColor="@color/black"
android:textAlignment="center"
tools:ignore="HardcodedText"/>

<EditText
android:layout_width="match_parent"
android:layout_height="63dp"
android:layout_marginTop="30dp"
android:fontFamily="monospace"
android:hint="Enrollment number"
android:padding="10dp"
android:textColor="@color/black"
android:textSize="18sp"
tools:ignore="Autofill,HardcodedText,TextFields" />

<EditText
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginTop="20dp"
android:fontFamily="monospace"
android:hint="Password"
android:textColorHint="#757575"
android:minHeight="48dp"
android:padding="10dp"
android:textColor="@color/black"
android:textSize="18sp"
tools:ignore="HardcodedText" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Log In"
android:textColor="@color/white"
android:layout_marginTop="40dp"
android:textSize="22sp"
tools:ignore="HardcodedText"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Forgot Password ??"
android:textSize="16sp"
android:layout_marginTop="10dp"
android:textAlignment="center"
android:textColor="@color/black"
tools:ignore="HardcodedText"/>
</LinearLayout>

Java Code:
package com.example.a10loginformstudent;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {

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

Output:
Practical No: 11
X) 1) Write a program to show five checkboxes and toast selected
checkboxes.
XML Code:
<?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"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_margin="20dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My Favourite Programming Languages"
android:textSize="18sp"
android:textStyle="bold"
android:textAlignment="center"
android:layout_marginTop="30dp"
android:layout_marginBottom="20dp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chkAndroid"
android:text="@string/android"
android:textSize="18sp"
android:textColor="@color/black"/>

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chkAndroid1"
android:text="@string/python"
android:textSize="18sp"
android:textColor="@color/black"/>

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chkAndroid2"
android:text="@string/java"
android:textSize="18sp"
android:textColor="@color/black"/>

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chkAndroid3"
android:text="@string/php"
android:textSize="18sp"
android:textColor="@color/black"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chkAndroid4"
android:text="@string/css"
android:textSize="18sp"
android:textColor="@color/black"/>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/submit"
android:text="Submit"
android:layout_marginTop="20dp"
android:textSize="18sp"
android:textStyle="bold"
tools:ignore="HardcodedText"/>
</LinearLayout>

String.XML Code
<resources>
<string name="app_name">11(checkbox)</string>
<string name="android">Android</string>
<string name="python">Python</string>
<string name="java">JAVA</string>
<string name="php">PHP</string>
<string name="css">CSS</string>
</resources>

Java Code:
package com.example.a11checkbox;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private CheckBox ch1,ch2,ch3,ch4,ch5;
private Button submit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ch1=findViewById(R.id.chkAndroid);
ch2=findViewById(R.id.chkAndroid1);
ch3=findViewById(R.id.chkAndroid2);
ch4=findViewById(R.id.chkAndroid3);
ch5=findViewById(R.id.chkAndroid4);
submit=findViewById(R.id.submit);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String showSelected = "You Selected: \n";
if(ch1.isChecked())
showSelected+= "Android";
if(ch1.isChecked())
showSelected+= "Python";
if(ch1.isChecked())
showSelected+= "JAVA";
if(ch1.isChecked())
showSelected+= "PHP";
if(ch1.isChecked())
showSelected+= "CSS";

Toast.makeText(MainActivity.this, "showSelected",
Toast.LENGTH_SHORT).show();
}
});
}
}

Output:
Practical No 12

X 1) Write a program to show the following output. First two radio buttons
are without using radio group and text two radio buttons are using radio
group.
Output:

Code:
Xml File:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Single Radio Buttons"

android:textSize="25dp" />

<RadioButton
android:id="@+id/rb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio Button 1" />

<RadioButton
android:id="@+id/rb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio Button 2" />

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/black" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Radio Button inside RadioGroup"
android:paddingTop="20dp"
android:textSize="25dp" />

<RadioGroup
android:id="@+id/rg"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<RadioButton
android:id="@+id/rbmale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male" />

<RadioButton
android:id="@+id/rbfemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />
</RadioGroup>

<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:text="Show Selected"
android:textSize="25dp" />
</LinearLayout>

Java File:
package com.example.a12radiobutton;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.RadioButton;

import android.widget.RadioGroup;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


RadioButton rb1, rb2, rg1;
RadioGroup rg;
Button b;
StringBuffer sb;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sb = new StringBuffer("You Selected: ");
b = findViewById(R.id.btn);
rb1 = findViewById(R.id.rb1);
rb2 = findViewById(R.id.rb2);
rg = findViewById(R.id.rg);
b.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
rg1 = findViewById(rg.getCheckedRadioButtonId());
if (rb1.isChecked())
sb.append("\n"+rb1.getText());
if (rb2.isChecked())
sb.append("\n"+rb2.getText());
if (rg1.isChecked())
sb.append("\n"+rg1.getText());
Toast.makeText(getApplicationContext(), sb, Toast.LENGTH_SHORT).show();
sb.delete(13, sb.length() - 1);
}
});
}
}
Practical No 13
X1) Write a program to display circular progress bar.
Code:
Xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"
tools:context=".MainActivity"
android:weightSum="1">
<Button
android:id="@+id/start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="START"/>

<Button
android:id="@+id/stop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="STOP"/>

<ProgressBar
android:id="@+id/progressbar"
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:progress="50"
android:layout_height="wrap_content"
android:layout_weight="1.00"/>

</LinearLayout>

Java File:
package com.example.pr13progressbar;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button start=(Button)findViewById(R.id.start);
Button stop=(Button)findViewById(R.id.stop);
final ProgressBar progressBar=(ProgressBar) findViewById(R.id.progressbar);
start.setOnClickListener((v)->{
progressBar.setVisibility(View.VISIBLE);
});
stop.setOnClickListener((v)->{
progressBar.setVisibility(View.INVISIBLE);
});

}
}
Output:

2) Write a program to show the following output:


Output:
Code:
Xml file:
<?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">

<Button
android:id="@+id/bt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Download"
android:layout_centerVertical="true"/>
</RelativeLayout>

Java File:
package com.example.pr13downloadfile;
import androidx.appcompat.app.AppCompatActivity;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;

public class MainActivity extends AppCompatActivity {


ProgressDialog progressDialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button bt1 = (Button) findViewById(R.id.bt1);
bt1.setOnClickListener(new View.OnClickListener() {
Handler handle = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
progressDialog.incrementProgressBy(2);
}
};

@Override
public void onClick(View view) {
progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Your file is downloading....");
progressDialog.setTitle("Progressdilog");
progressDialog.setProgressStyle(progressDialog.STYLE_HORIZONTAL);
progressDialog.show();
progressDialog.setCancelable(false);
new Thread((Runnable) () -> {
try {
while (progressDialog.getProgress() <= progressDialog.getMax()) {
Thread.sleep(200);
handle.sendMessage(handle.obtainMessage());
if (progressDialog.getProgress() == progressDialog.getMax()) {
}
}
} catch (Exception e) {
e.printStackTrace();
}
}).start();
}
});
}
Practical No 14
X1) Write a program to show the following output.
Output:

Code:
Xml file:
<?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">

<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listview"/>
</LinearLayout>

Java File:
package com.example.pr14listview;

import android.app.ListActivity;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView l=(ListView)findViewById(R.id.listview);
final ArrayList<String> arrayList=new ArrayList<>();
arrayList.add("Android");
arrayList.add("Java");
arrayList.add("PHP");
arrayList.add("Hadop");
arrayList.add("SAP");
arrayList.add("Ajax");
arrayList.add("C++");
arrayList.add("Ruby");
arrayList.add("Rails");
arrayList.add("Pascal");

ArrayAdapter<String>arrayAdapter=new
ArrayAdapter<>(this,android.R.layout.simple_list_item_1,arrayList);
l.setAdapter(arrayAdapter);
l.setOnItemClickListener((parent,view,position,id)->{
Toast.makeText(MainActivity.this,arrayList.get(position),
Toast.LENGTH_SHORT).show();
});

}
}

2) Write a program to display an image using Image view and button named as
“Change Image”, Once you click on button another image should get displayed.
Code:
Xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="50dp"
tools:context=".MainActivity"
android:weightSum="1">

<ImageView
android:id="@+id/imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="@drawable/micky2"
android:layout_weight="0.38"/>
<Button
android:layout_marginTop="50dp"
android:id="@+id/button"
android:layout_width="299dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Button"/>

</LinearLayout>

Java file:
package com.example.pr14imageview;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {


ImageView iv;
Button b1;
int count = 1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView) findViewById(R.id.imageview);
b1 = (Button) findViewById(R.id.button);
b1.setOnClickListener((v) -> {
if (count == 1) {
iv.setImageResource(R.drawable.teddy);
count = 2;
} else if (count == 2) {
iv.setImageResource(R.drawable.micky2);
count = 1;
}
});
}
}

Output:

3) Write a program to display a text view using vertical scroll view.


Code:
Xml file:
<?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"
tools:context=".MainActivity">

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="“DaanPunya” is a website which enables the donors to use a new
platform to donate
their unused medicines to the respective organization/NGO. This idea of donating the
unused medicines is unusual
and might have a great impact on the society wherein the needy people will get help in
form of the medicines they
require through the respective organization. The website works like this, first the donor
can register themselves
and then proceed to donate their medicines which are unused."
android:textSize="40sp"
android:textColor="#00944a"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:id="@+id/textview"/>
</ScrollView>
</LinearLayout>

Java File:
package com.example.pr14verticalscrollview;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Output:
Horizontal scrollview
XML file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Horizontal ScrollView Example"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="25dp">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="@+id/horizontalScrollView">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:text="New Button1"
android:id="@+id/button1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:text="New Button2"
android:id="@+id/button2" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:text="New Button3"
android:id="@+id/button3" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:text="New Button4"
android:id="@+id/button4" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button5"
android:id="@+id/button5" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:text="New Button6"
android:id="@+id/button6" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:text="New Button7"
android:id="@+id/button7" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:text="New Button8"
android:id="@+id/button8"/>
</LinearLayout>

</HorizontalScrollView>
</LinearLayout>
</RelativeLayout>

Java file
package com.stormsofts.horizontalscrollview;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

}
}
output
Practical No 15
X1) Write a program to display following toast message.
Output:

Code:
Xml file:
<?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="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!Toast Example"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/button"
android:layout_width="162dp"
android:layout_height="wrap_content"
android:text="Show Toast" />

</LinearLayout>

Toast_layout.xml file:
<?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:background="#000"
android:orientation="vertical"
android:id="@+id/LL"
tools:context=".MainActivity">

<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Message for you:\n You have got a mail!"
android:textColor="#ffffff"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</LinearLayout>

Java File:
package com.example.pr15checkbox;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.Layout;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


Button b1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button) findViewById(R.id.button);
b1.setOnClickListener((v) -> {
showtoast();
});
}
public void showtoast(){
LayoutInflater inflater=getLayoutInflater();
View layout=inflater.inflate(R.layout.toast_layout,(ViewGroup)
findViewById(R.id.LL));
Toast toast=new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER,0,0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}

2) Write a program to display three checkboxes and one button named “order “ as
shown below.
Code:
Xml File:
<?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">

<CheckBox
android:id="@+id/checkbox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="PIZZA"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintVertical_bias="0.063"
app:layout_constraintHorizontal_bias="0.502"/>
<CheckBox
android:id="@+id/checkbox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="COFFEE"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintVertical_bias="0.307"
app:layout_constraintHorizontal_bias="0.502"/>
<CheckBox
android:id="@+id/checkbox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="BURGER"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintVertical_bias="0.544"
app:layout_constraintHorizontal_bias="0.502"/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ORDER"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintVertical_bias="0.798"/>

</androidx.constraintlayout.widget.ConstraintLayout>

Java File:
package com.example.pr15displaytoastmsg;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


CheckBox c1, c2, c3;
Button b1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
c1 = (CheckBox) findViewById(R.id.checkbox1);
c2 = (CheckBox) findViewById(R.id.checkbox2);
c3 = (CheckBox) findViewById(R.id.checkbox3);
b1 = (Button) findViewById(R.id.button);
b1.setOnClickListener((v) -> {
int total = 0;
StringBuilder bill = new StringBuilder();
bill.append("Selected Item:");
if (c1.isChecked()) {
bill.append("\n Pizza=100rs");
total += 100;
}
if (c2.isChecked()) {
bill.append("\n Burger=120rs");
total += 120;
}
if (c3.isChecked()) {
bill.append("\n Coffee=50rs");
total += 50;
}
bill.append("\nTotal bill=" + total + "Rs");
Toast.makeText(MainActivity.this, bill, Toast.LENGTH_SHORT).show();

});
}
}

Output:
Practical No 16
X 1) Write a program to display following output. Use TimePicker with
Sppinnermode.
Output:

XML File
<?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"
android:orientation="vertical"
tools:context=".MainActivity">

<TimePicker
android:id="@+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/timePicker1"
android:layout_marginTop="10dp"
android:layout_marginLeft="160dp"
android:text="Get Date" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_marginLeft="120dp"
android:layout_marginTop="10dp"
android:textStyle="bold"
android:textSize="18dp"/>
</RelativeLayout>

Java File:
package com.example.pr16timepicker;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;

public class MainActivity extends AppCompatActivity {


TimePicker picker;
Button btnGet;
TextView tvw;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvw=(TextView)findViewById(R.id.textView1);
picker=(TimePicker)findViewById(R.id.timePicker1);
picker.setIs24HourView(true);
btnGet=(Button)findViewById(R.id.button1);
btnGet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int hour, minute;
String am_pm;
if (Build.VERSION.SDK_INT >= 23 ){
hour = picker.getHour();
minute = picker.getMinute();
}
else{
hour = picker.getCurrentHour();
minute = picker.getCurrentMinute();
}
if(hour > 12) {
am_pm = "PM";
hour = hour - 12;
}
else
{
am_pm="AM";
}
tvw.setText("Selected Date: "+ hour +":"+ minute+" "+am_pm);
}
});
}
}

2) Write a program to display following output. Select and display date and time on
click of select date, select time buttons respectively.
Output:
XML File:
<?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"
android:orientation="vertical"
tools:context=".MainActivity">

<EditText
android:id="@+id/in_date"
android:layout_width="229dp"
android:layout_height="64dp"
android:hint="date"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="82dp" />

<Button
android:id="@+id/btn_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/in_date"
android:layout_marginStart="41dp"
android:layout_marginLeft="41dp"
android:layout_marginBottom="-16dp"
android:layout_toEndOf="@+id/in_date"
android:layout_toRightOf="@+id/in_date"
android:text="SELECT DATE" />

<EditText
android:id="@+id/in_time"
android:layout_width="235dp"
android:layout_height="76dp"
android:layout_below="@+id/in_date"
android:hint="time"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginStart="1dp"
android:layout_marginLeft="1dp"
android:layout_marginTop="53dp" />

<Button
android:id="@+id/btn_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_date"
android:layout_alignStart="@+id/btn_date"
android:layout_alignLeft="@+id/btn_date"
android:layout_marginStart="7dp"
android:layout_marginLeft="7dp"
android:layout_marginTop="51dp"
android:text="SELECT TIME" />

</RelativeLayout>

Java File:
package com.example.pr16datetime;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TimePicker;

import java.util.Calendar;

public class MainActivity extends AppCompatActivity implements


View.OnClickListener {

Button btnDatePicker, btnTimePicker;


EditText txtDate, txtTime;
private int mYear, mMonth, mDay, mHour, mMinute;

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

btnDatePicker=(Button)findViewById(R.id.btn_date);
btnTimePicker=(Button)findViewById(R.id.btn_time);
txtDate=(EditText)findViewById(R.id.in_date);
txtTime=(EditText)findViewById(R.id.in_time);

btnDatePicker.setOnClickListener(this);
btnTimePicker.setOnClickListener(this);
}

@Override
public void onClick(View v) {

if (v == btnDatePicker) {

// Get Current Date


final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);

DatePickerDialog datePickerDialog = new DatePickerDialog(this,


new DatePickerDialog.OnDateSetListener() {

@Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {

txtDate.setText(dayOfMonth + "-" + (monthOfYear + 1) + "-" + year);

}
}, mYear, mMonth, mDay);
datePickerDialog.show();
}
if (v == btnTimePicker) {

// Get Current Time


final Calendar c = Calendar.getInstance();
mHour = c.get(Calendar.HOUR_OF_DAY);
mMinute = c.get(Calendar.MINUTE);

// Launch Time Picker Dialog


TimePickerDialog timePickerDialog = new TimePickerDialog(this,
new TimePickerDialog.OnTimeSetListener() {

@Override
public void onTimeSet(TimePicker view, int hourOfDay,
int minute) {

txtTime.setText(hourOfDay + ":" + minute);


}
}, mHour, mMinute, false);
timePickerDialog.show();
}
}
}
Practical no 17
X 1) Write a Program to create a HELLO WORLD Activity using all
lifecycles methods to display message using Log.d
XML File:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Java File:
package com.example.pr17helloworldlifecycle;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("lifecycle","onCreate invoked");
}
@Override
protected void onStart() {
super.onStart();
Log.d("lifecycle","onStart invoked");
}
@Override
protected void onResume() {
super.onResume();
Log.d("lifecycle","onResume invoked");
}
@Override
protected void onPause() {
super.onPause();
Log.d("lifecycle","onPause invoked");
}
@Override
protected void onStop() {
super.onStop();
Log.d("lifecycle","onStop invoked");
}
@Override
protected void onRestart() {
super.onRestart();
Log.d("lifecycle","onRestart invoked");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d("lifecycle","onDestroy invoked");
}
}

Output logcat
Practical No 21
X. 1) Write a program to demonstrate all the system broadcast meassage .
Sender File:
XML file:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="384dp"
android:text="Send brodcast Message"
android:onClick="onBroadcastSendBtnCicked"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

Java File:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="384dp"
android:text="Send brodcast Message"
android:onClick="onBroadcastSendBtnCicked"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

Receiver File
XML File:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BroadCast Receiver"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Java File:
package com.example.pr18broadcastreciver2;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
IntentFilter intentFilter=new IntentFilter("com.codingpursuits.myBroadcastMessage");
MyBroadcastReceiver objReciver=new MyBroadcastReceiver();
registerReceiver(objReciver,intentFilter);
}
}
Mainfeast File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Pr18BroadcastReciver2"
tools:targetApi="31">
<receiver
android:name=".MyBroadcastReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.codingpursuits.myBroadcastMessage">

</action>
</intent-filter>
</receiver>

<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
</application>

</manifest>

Broadcast Receiver File:


package com.example.pr18broadcastreciver2;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
public class MyBroadcastReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
// TODO: This method is called when the BroadcastReceiver is receiving
// an Intent broadcast.
Log.i("BroadcastReceiver","Broadcast message is received");
Toast.makeText(context, "Broadcast message is received",
Toast.LENGTH_SHORT).show();
}
}

Output:
Practical No: 22
X.1) Write a program to change the background color when device is
shuffled.
XML File:
<?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"
android:id="@+id/linearlayout">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Background Color Change"
android:textSize="25sp" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RED"
tools:layout_editor_absoluteX="227dp"
tools:layout_editor_absoluteY="93dp"
/>

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GREEN"
tools:layout_editor_absoluteX="58dp"
tools:layout_editor_absoluteY="93dp" />

</LinearLayout>

Java File:
package com.example.pr22backgroundcolorchange;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
public class MainActivity extends AppCompatActivity {
Button b1,b2;
LinearLayout layout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button) findViewById(R.id.button);
b2=(Button) findViewById(R.id.button1);
layout=(LinearLayout) findViewById(R.id.linearlayout);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
layout.setBackgroundColor(Color.RED);

}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
layout.setBackgroundColor(Color.GREEN);
}
});
}
}

Output:
2) Write a program to display the list of sensors supported by the mobile device.
XML File:
<?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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="68dp"
android:text="List of Sensors Supported by this Device"
android:textColor="@color/design_default_color_error"
android:textSize="20dp"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Java File:
package com.example.pr22sensor;

import android.os.Bundle;
import android.widget.TextView;
import android.hardware.Sensor;
import android.hardware.SensorManager;

import androidx.appcompat.app.AppCompatActivity;

import java.util.List;
public class MainActivity extends AppCompatActivity {
TextView t1;
SensorManager msensormanager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t1=(TextView) findViewById(R.id.text);
msensormanager=(SensorManager) getSystemService(SENSOR_SERVICE);
List<Sensor>mlist=msensormanager.getSensorList(Sensor.TYPE_ALL);
for (int i=1;i<mlist.size();i++){

t1.append("\n"+mlist.get(i).getName()+"\n"+mlist.get(i).getVersion()+"\n"+mlist.get(i).getVe
ndor());
}

}
}
Output:
Practical No 23
X. 1) Write a program to capture an image and display it using image view.
XML File:
<?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:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FFF9C4"
tools:context=".MainActivity">
<ImageView
android:layout_width="fill_parent"
android:layout_height="300dp"
android:layout_centerHorizontal="true"
android:id="@+id/imageView" />
<Button
android:text="Click here to capture image using camera"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button" />
</LinearLayout>

Java File:
package com.example.pr23captureimagedisplay;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
public class MainActivity extends AppCompatActivity {
Button ;
ImageView ;
Intent ;
public static final int RequestPermissionCode = 1
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button)findViewById(R.id.button);
imageView = (ImageView)findViewById(R.id.imageView);
EnableRuntimePermission();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 7)
}
});
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {


super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 7 && resultCode == RESULT_OK) {
Bitmap = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(bitmap);
}
}

public void EnableRuntimePermission(){


if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,
Manifest.permission.CAMERA))
{
Toast.makeText(MainActivity.this,"CAMERA permission allows us to Access
CAMERA app", Toast.LENGTH_LONG).show();

} else {
ActivityCompat.requestPermissions(MainActivity.this,new String[]{
Manifest.permission.CAMERA}, RequestPermissionCode);

}
}

@Override
public void onRequestPermissionsResult(int RC, String per[], int[] PResult) {
super.onRequestPermissionsResult(RC, per, PResult);
switch (RC) {
case RequestPermissionCode:
if (PResult.length > 0 && PResult[0] ==
PackageManager.PERMISSION_GRANTED) {
Toast.makeText(MainActivity.this, "Permission Granted, Now your application
can access CAMERA.", Toast.LENGTH_LONG).show();
} else {

Toast.makeText(MainActivity.this, "Permission Canceled, Now your application


cannot access CAMERA.", Toast.LENGTH_LONG).show();

}
break;
}
}

Mainfest.Xml File:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.CAMERA" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Pr23captureImageDisplay"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
</application>

</manifest>
Output:
2) Write a program to record a video using various camera methods.
XML File:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Record Video"
android:onClick="recordVideoButtonPressed"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.516"/>
</androidx.constraintlayout.widget.ConstraintLayout>

Java File:
package com.example.pr23recordingvideoimageapp;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.Manifest;

public class MainActivity extends AppCompatActivity implements MainActivity1 {


private static int CAMERA_PERMISSION_CODE = 100;
private static int VIDEO_RECORD_CODE = 101;
private Uri videoPath;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (isCameraPresentInPhone()) {
Log.i("VIDEO_RECORD_TAG", "Camera is detected");
getCameraPermission();
} else {
Log.i("VIDEO_RECORD_TAG", " NoCamera is detected");
}
}

public void recordVideoButtonPressed(View view) {


recordVideo();

}
private boolean isCameraPresentInPhone() {
if
(getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)) {
return true;
} else {
return false;
}
}

private void getCameraPermission() {


Context;
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) ==
PackageManager.PERMISSION_DENIED) {
Activity;
ActivityCompat.requestPermissions(this, new
String[]{Manifest.permission.CAMERA}, CAMERA_PERMISSION_CODE);
}
}

private void recordVideo() {


Intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(intent, VIDEO_RECORD_CODE);

@Override
public void onActivityResult(int resultCode, @Nullable Intent data) {
super.onActivityResult(resultCode, resultCode, data);
int requestCode = 0;
if (requestCode == VIDEO_RECORD_CODE) {
if (resultCode == RESULT_OK) {
if (videoPath == data.getData()) {
Log.i("VIDEO_RECORD_TAG", " Video is recorded and available at path"
+videoPath);
}
else if (resultCode==RESULT_CANCELED){
Log.i( "VIDEO_RECORD_TAG", " recorded video is cancelled");
}
else {
Log.i("VIDEO_RECORD_TAG", " Recording video has got some error");
}
}
}
}
}

Mainfest.Xml File:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA"/>

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Pr23RecordingVideoimageApp"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
</application>

</manifest>
Output:
Practical No: 24
Write a program to turn on, get visible, list devices and turnoff Bluetooth
with the help of GUI.
XML File:
<?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">

<TextView android:text="Bluetooth Example"


android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textview"
android:textSize="35dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tutorials point"
android:id="@+id/textView"
android:layout_below="@+id/textview"
android:layout_centerHorizontal="true"
android:textColor="#ff7aff24"
android:textSize="35dp" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/sample"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:theme="@style/Base.TextAppearance.AppCompat" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Turn On"
android:id="@+id/button"
android:layout_below="@+id/imageView"
android:layout_toStartOf="@+id/imageView"
android:layout_toLeftOf="@+id/imageView"
android:clickable="true"
android:onClick="on" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get visible"
android:onClick="visible"
android:id="@+id/button2"
android:layout_alignBottom="@+id/button"
android:layout_centerHorizontal="true" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="List devices"
android:onClick="list"
android:id="@+id/button3"
android:layout_below="@+id/imageView"
android:layout_toRightOf="@+id/imageView"
android:layout_toEndOf="@+id/imageView" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="turn off"
android:onClick="off"
android:id="@+id/button4"
android:layout_below="@+id/button"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:layout_alignParentBottom="true"
android:layout_alignLeft="@+id/button"
android:layout_alignStart="@+id/button"
android:layout_below="@+id/textView2" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Paired devices:"
android:id="@+id/textView2"
android:textColor="#FB1563"
android:textSize="25dp"
android:layout_below="@+id/button4"
android:layout_alignLeft="@+id/listView"
android:layout_alignStart="@+id/listView" />

</RelativeLayout>

Java File:
package com.example.blutooth;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;

import android.content.Intent;
import android.os.Bundle;
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 Activity {


Button b1,b2,b3,b4;
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.button);
b2=(Button)findViewById(R.id.button2);
b3=(Button)findViewById(R.id.button3);
b4=(Button)findViewById(R.id.button4);

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

public void on(View v){


if (!BA.isEnabled()) {
Intent turnOn = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(turnOn, 0);
Toast.makeText(getApplicationContext(), "Turned
on",Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Already on",
Toast.LENGTH_LONG).show();
}
}

public void off(View v){


BA.disable();
Toast.makeText(getApplicationContext(), "Turned off"
,Toast.LENGTH_LONG).show();
}

public void visible(View v){


Intent getVisible = new
Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
startActivityForResult(getVisible, 0);
}

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);
}
}

Manifeast File:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Blutooth"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
</application>

</manifest>

Output:
Practical No: 25
Write a program to rotate the image in clockwise/anticlockwise, Zoom
In/Zoom OUT, Fade In/ Fade Out by using the GUI.
Xml File:
<?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" >

<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="373dp"
app:srcCompat="@drawable/abc2" />

<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="match_parent"
android:layout_height="71dp"
android:background="#FA0404"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="Zoom anticlockwise" />

<ToggleButton
android:id="@+id/toggleButton2"
android:layout_width="match_parent"
android:layout_height="64dp"
android:background="#FA0404"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="zoom in" />

</LinearLayout>

Java File:
package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
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;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;

import static android.bluetooth.BluetoothAdapter.getDefaultAdapter;

public class MainActivity extends AppCompatActivity {


ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img = (ImageView) findViewById(R.id.imageView);
final ToggleButton tglbtn=(ToggleButton)findViewById(R.id.toggleButton);
final ToggleButton tglbtn1=(ToggleButton) findViewById(R.id.toggleButton2);
final ImageView img=(ImageView)findViewById(R.id.imageView);
tglbtn1.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{
Animation anim = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.zoomin);
img.startAnimation(anim);
}
});
tglbtn1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
Animation animZoomOut =
AnimationUtils.loadAnimation(getApplicationContext(), R.anim.zoomout);
img.startAnimation(animZoomOut);
}
});
tglbtn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
Animation animRotateAnticlockwise =
AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotateanticlockwise);
img.startAnimation(animRotateAnticlockwise);
}
});
tglbtn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
Animation animRotateClockwise =
AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotateclockwise);
img.startAnimation(animRotateClockwise);
}
});
}
}

RoateAntiClockWise:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="@android:anim/cycle_interpolator">
<rotate android:fromDegrees="360"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="5000"/>

</set>

RoateClockWise:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/cycle_interpolator">
<rotate android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="5000"/>

</set>

Zoom Out:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:duration="2500"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale=".2"
android:toYScale=".2"/>
</set>

Output:
Practical No: 26
X.1) Write a program to insert data in SQLite databse using AsyncTask
XML File:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="@+id/idEdtCourseName"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="10dp"
android:hint="Enter course Name" />
<EditText
android:id="@+id/idEdtCourseDuration"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="10dp"
android:hint="Enter Course Duration" />
<EditText
android:id="@+id/idEdtCourseTracks"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="10dp"
android:hint="Enter Course Tracks" />
<EditText
android:id="@+id/idEdtCourseDescription"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="10dp"
android:hint="Enter Course Description" />
<Button
android:id="@+id/idBtnAddCourse"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="10dp"
android:text="Add Course"
android:textAllCaps="false" />
</LinearLayout>
DBhandler.java
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DBHandler extends SQLiteOpenHelper {
private static final String DB_NAME = "coursedb";
private static final int DB_VERSION = 1;
private static final String TABLE_NAME = "mycourses";
private static final String ID_COL = "id";
private static final String NAME_COL = "name";
private static final String DURATION_COL = "duration";
private static final String DESCRIPTION_COL = "description";
private static final String TRACKS_COL = "tracks";
public DBHandler(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String query = "CREATE TABLE " + TABLE_NAME + " ("
+ ID_COL + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ NAME_COL + " TEXT,"
+ DURATION_COL + " TEXT,"
+ DESCRIPTION_COL + " TEXT,"
+ TRACKS_COL + " TEXT)";
db.execSQL(query);
}
public void addNewCourse(String courseName, String courseDuration, String
courseDescription, String
courseTracks) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(NAME_COL, courseName);
values.put(DURATION_COL, courseDuration);
values.put(DESCRIPTION_COL, courseDescription);
values.put(TRACKS_COL, courseTracks);
db.insert(TABLE_NAME, null, values);
db.close();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
}
Java File:
package com.example.pr26database;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private EditText courseNameEdt, courseTracksEdt, courseDurationEdt,
courseDescriptionEdt;
private Button addCourseBtn;
private DBHandler dbHandler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
courseNameEdt = findViewById(R.id.idEdtCourseName);
courseTracksEdt = findViewById(R.id.idEdtCourseTracks);
courseDurationEdt = findViewById(R.id.idEdtCourseDuration);
courseDescriptionEdt = findViewById(R.id.idEdtCourseDescription);
addCourseBtn = findViewById(R.id.idBtnAddCourse);
dbHandler = new DBHandler(MainActivity.this);
addCourseBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String courseName = courseNameEdt.getText().toString();
String courseTracks = courseTracksEdt.getText().toString();
String courseDuration = courseDurationEdt.getText().toString();
String courseDescription = courseDescriptionEdt.getText().toString();
if (courseName.isEmpty() && courseTracks.isEmpty() && courseDuration.isEmpty() &&
courseDescription.isEmpty()) {
Toast.makeText(MainActivity.this, "Please enter all the data..",
Toast.LENGTH_SHORT).show();
return;
}
dbHandler.addNewCourse(courseName, courseDuration, courseDescription, courseTracks);
Toast.makeText(MainActivity.this, "Course has been added.",
Toast.LENGTH_SHORT).show();
courseNameEdt.setText("");
courseDurationEdt.setText("");
courseTracksEdt.setText("");
courseDescriptionEdt.setText("");
}
});
}
}
Mainfest File:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Pr26database"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Output:
Practical No: 27

X) 1. Write a program to create the login form and display login


successful/Unsuccessful toastmessage.

XML Code:

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


<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LOGIN FORM"
android:textSize="18dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.101"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.05" />
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="User-name"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.317" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.556" />
<TextView
android:id="@+id/textView"
android:layout_width="121dp"
android:layout_height="21dp"
android:text="USERNAME"
android:textSize="18dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.341"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.225" />
<TextView
android:id="@+id/textView2"
android:layout_width="121dp"
android:layout_height="21dp"
android:text="PASSWORD"
android:textSize="18dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.341"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.439" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="submit"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.742" />
</androidx.constraintlayout.widget.ConstraintLayout>

Java Code:

package com.example.loginformpg143p1;
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 {
EditText uname,password;
Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
uname=findViewById(R.id.editText);
password=findViewById(R.id.editText2);
b1=findViewById(R.id.button);
}
public void submit(View view) {
if (uname.getText().toString().equals("manasi")){
if (password.getText().toString().equals("manasi@123")){
Toast.makeText(getApplicationContext(),"Login
Successful",Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(getApplicationContext(),"Login
Unsuccessful",Toast.LENGTH_SHORT).show();
}
}
}
}
Output:
Practical No: 28

X) 1. Write a program to create the login form with necessary validations


like length of username and password, empty text fields, count of
unsuccessful login attempts. Display the login Successful/Unsuccessful
toastmessage.

XML CODE:
<?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="wrap_content"
android:layout_height="wrap_content"
android:text="LOGIN FORM"
android:textSize="18dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.182"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.057" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="USERNAME"
android:textSize="18dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.187"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.216" />
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="username"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.282"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.306" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PASSWORD"
android:textSize="18dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.173"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.435" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.297"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.542" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SUBMIT"
android:textSize="18dp"
android:onClick="submit"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.188"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.689" />
</androidx.constraintlayout.widget.ConstraintLayout>

JAVA CODE:
package com.example.loginvalidationspg148p1;

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 {

EditText uname,password;

Button b1;

String userin,passin;

int count;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

uname=findViewById(R.id.editText);

password=findViewById(R.id.editText2);

public void submit(View view) {

userin=uname.getText().toString();

passin=password.getText().toString();

if(!userin.isEmpty()){

if (userin.length()>=5){

if (userin.equals("manasi")){

if (!passin.isEmpty()){
if (passin.length()>=8){

if (passin.equals("manasi22")){

count+=1;

Toast.makeText(getApplicationContext(),"Login successful\n After


number of attempts:"+count,Toast.LENGTH_SHORT).show();

else {

count+=1;

Toast.makeText(getApplicationContext(),"Login unsuccessful\n Invalid


password\n Number of attempts:"+count,Toast.LENGTH_SHORT).show();

else {

count+=1;

Toast.makeText(getApplicationContext(),"Login unsuccessful\n Password


must be atleast 8 length\n Number of attempts:"+count,Toast.LENGTH_SHORT).show();

else {

count+=1;

Toast.makeText(getApplicationContext(),"Login unsuccessful\n Enter


password\n Number of attempts:"+count,Toast.LENGTH_SHORT).show();

else {
count+=1;

Toast.makeText(getApplicationContext(),"Login unsuccessful\n Enter valid


username\n number of attempts:"+count,Toast.LENGTH_SHORT).show();

else {

count+=1;

Toast.makeText(getApplicationContext(),"Login unsuccessful\n User name must be


atleast 5 length\n number of attempts:"+count,Toast.LENGTH_SHORT).show();

else {

count+=1;

Toast.makeText(getApplicationContext(),"Login unsuccessful\n Enter username\n


number of attempts:"+count,Toast.LENGTH_SHORT).show();

}
OUTPUTS:
Practical No: 29
Xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/fstTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="150dp"
android:text="Mobile No" />
<EditText
android:id="@+id/mblTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:ems="10"/>

<TextView
android:id="@+id/secTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Message"
android:layout_marginLeft="100dp" />
<EditText
android:id="@+id/msgTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:ems="10" />
<Button
android:id="@+id/btnSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:text="Send SMS" />
</LinearLayout>

Java
package com.example.sendsms;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private EditText txtMobile;


private EditText txtMessage;
private Button btnSms;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtMobile = (EditText)findViewById(R.id.mblTxt);
txtMessage = (EditText)findViewById(R.id.msgTxt);
btnSms = (Button)findViewById(R.id.btnSend);
btnSms.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try{
SmsManager smgr = SmsManager.getDefault();

smgr.sendTextMessage(txtMobile.getText().toString(),null,txtMessage.getText().toString(),
null,null);
Toast.makeText(MainActivity.this, "SMS Sent Successfully",
Toast.LENGTH_SHORT).show();
}
catch (Exception e){
Toast.makeText(MainActivity.this, "SMS Failed to Send, Please try again",
Toast.LENGTH_SHORT).show();
}
}
});
}
}

Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

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

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.SendSMS"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>

<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>

</manifest>
OUTPUT:
Practical No: 30

X 1) Write a program to send mail.


XML File:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:id="@+id/editText1"
android:layout_width="272dp"
android:layout_height="105dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="18dp"
android:layout_marginRight="7dp"
android:hint="Subject" />
<EditText
android:id="@+id/editText2"
android:layout_width="272dp"
android:layout_height="96dp"
android:layout_below="@+id/editText1"
android:layout_alignLeft="@+id/editText1"
android:layout_marginTop="20dp"
android:hint="Send to" />
<EditText
android:id="@+id/editText3"
android:layout_width="269dp"
android:layout_height="88dp"
android:layout_below="@+id/editText2"
android:layout_alignLeft="@+id/editText2"
android:layout_marginTop="30dp"
android:hint="Body" />
<TextView
android:id="@+id/textView1"
android:layout_width="88dp"
android:layout_height="45dp"
android:layout_alignBaseline="@+id/editText1"
android:layout_alignBottom="@+id/editText1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="-6dp"
android:text="Send To:"
android:textColor="#0F9D58" />
<TextView
android:id="@+id/textView2"
android:layout_width="107dp"
android:layout_height="45dp"
android:layout_alignBaseline="@+id/editText2"
android:layout_alignBottom="@+id/editText2"
android:layout_alignParentLeft="true"
android:layout_marginBottom="-7dp"
android:text="Email Subject:"
android:textColor="#0F9D58" />
<TextView
android:id="@+id/textView3"
android:layout_width="104dp"
android:layout_height="42dp"
android:layout_alignBaseline="@+id/editText3"
android:layout_alignBottom="@+id/editText3"
android:layout_marginBottom="-4dp"
android:text="Email Body:"
android:textColor="#0F9D58" />

<Button
android:id="@+id/button"
android:layout_width="412dp"
android:layout_height="232dp"
android:layout_below="@+id/editText3"
android:layout_alignLeft="@+id/editText3"
android:layout_alignParentStart="true"
android:layout_marginStart="0dp"
android:layout_marginLeft="-323dp"
android:layout_marginTop="20dp"
android:text="Send email!!" />
</RelativeLayout>
Java File:
package com.example.pr30sendemail;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
Button button;
EditText sendto, subject, body;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sendto = findViewById(R.id.editText1);
subject = findViewById(R.id.editText2);
body = findViewById(R.id.editText3);
button = findViewById(R.id.button);
button.setOnClickListener(view -> {
String emailsend = sendto.getText().toString();
String emailsubject = subject.getText().toString();
String emailbody = body.getText().toString();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{emailsend});
intent.putExtra(Intent.EXTRA_SUBJECT, emailsubject);
intent.putExtra(Intent.EXTRA_TEXT, emailbody);
intent.setType("message/rfc822");
startActivity(Intent.createChooser(intent, "Choose an Email client :"));
}); }}
Output:

You might also like