Download as pdf or txt
Download as pdf or txt
You are on page 1of 87

1 Write a program to display student name and marks.

<?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=".studentnameandmarks">

<TextView

android:id="@+id/textView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginStart="40dp"

android:layout_marginTop="64dp"

android:layout_marginEnd="70dp"

android:fontFamily="cursive"

android:text="Student Name:"

android:textColor="@color/white"

android:textSize="25dp"

app:layout_constraintEnd_toStartOf="@+id/textView2"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent" />

<TextView

android:id="@+id/textView3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginStart="40dp"

android:layout_marginTop="20dp"

android:fontFamily="cursive"

android:text="Aditi Pal"

android:textSize="25dp"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/textView" />

<TextView

android:id="@+id/textView2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:layout_marginStart="70dp"

android:layout_marginTop="64dp"

android:fontFamily="cursive"

android:text="Marks:"

android:textColor="@color/white"

android:textSize="25dp"

app:layout_constraintStart_toEndOf="@+id/textView"

app:layout_constraintTop_toTopOf="parent" />

<TextView

android:id="@+id/textView5"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginStart="33dp"

android:layout_marginTop="12dp"

android:layout_marginEnd="54dp"

android:fontFamily="cursive"

android:text="90/100"

android:textSize="25dp"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="1.0"

app:layout_constraintStart_toEndOf="@+id/textView3"

app:layout_constraintTop_toBottomOf="@+id/textView2" />

</androidx.constraintlayout.widget.ConstraintLayout>
2 Write a program to place Name, Age and mobile number linearly (Vertical) on the display screen
using Linear layout.
<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

<TextView

android:id="@+id/name"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Name: Aditi"

android:textSize="25dp"/>

<TextView

android:id="@+id/age"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Age: 19"

android:textSize="25dp"/>

<TextView

android:id="@+id/mobile"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Mobile: 123-456-7890"

android:textSize="25dp"/>

</LinearLayout>
3 Write a program to place Name, Age and mobile number centrally on the display screen using
Absolute layout.
<?xml version="1.0" encoding="utf-8"?>

<AbsoluteLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

<TextView

android:id="@+id/textviewName"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="50dp"

android:layout_y="300dp"

android:text=" Name:"

android:textStyle="bold"

android:textColor="@color/black"

android:textSize="30dp" />

<TextView

android:id="@+id/textViewName2"

android:layout_width="137dp"

android:layout_height="wrap_content"

android:layout_x="164dp"

android:layout_y="299dp"

android:text=" Aditi"

android:textColor="@color/black"

android:textSize="30dp" />

<TextView

android:id="@+id/textViewAge"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="66dp"

android:layout_y="349dp"

android:text="Age: "

android:textColor="@color/black"

android:textSize="30dp"

android:textStyle="bold" />

<TextView
android:id="@+id/textView3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="188dp"

android:layout_y="347dp"

android:text="19"

android:textColor="@color/black"

android:textSize="30dp" />

<TextView

android:id="@+id/textView4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="54dp"

android:layout_y="399dp"

android:text="Mobile Number:"

android:textColor="@color/black"

android:textSize="30dp"

android:textStyle="bold" />

<TextView

android:id="@+id/textView5"

android:layout_width="188dp"

android:layout_height="wrap_content"

android:layout_x="70dp"

android:layout_y="450dp"

android:text="1234567890"

android:textColor="@color/black"

android:textSize="30dp" />

</AbsoluteLayout>
4 Write a program to display 10 students basic information in a table form using Table layout.
<TableLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent">

<TableRow>

<TextView

android:text="Name"

android:textStyle="bold"

android:padding="10dp"/>

<TextView

android:text="Age"

android:textStyle="bold"

android:padding="10dp"/>

<TextView

android:text="Roll no"

android:textStyle="bold"

android:padding="10dp"/>

<TextView

android:text="Mobile"

android:textStyle="bold"

android:padding="10dp"/>

</TableRow>

<TableRow>

<TextView

android:padding="10dp"

android:text="Aditi" />

<TextView

android:padding="10dp"

android:text="18" />

<TextView

android:text="1"

android:padding="10dp"/>

<TextView

android:text="123-456-7890"

android:padding="10dp"/>

</TableRow>

<TableRow>
<TextView

android:padding="10dp"

android:text="Mansi" />

<TextView

android:padding="10dp"

android:text="30" />

<TextView

android:text="2"

android:padding="10dp"/>

<TextView

android:text="234-567-8901"

android:padding="10dp"/>

</TableRow>

<TableRow>

<TextView

android:padding="10dp"

android:text="Sejal" />

<TextView

android:padding="10dp"

android:text="45" />

<TextView

android:text="3"

android:padding="10dp"/>

<TextView

android:text="696-696-6969"

android:padding="10dp"/>

</TableRow>

<TableRow>

<TextView

android:padding="10dp"

android:text="Aditya" />

<TextView

android:padding="10dp"

android:text="33" />

<TextView

android:text="4"

android:padding="10dp"/>
<TextView

android:text="234-567-8901"

android:padding="10dp"/>

</TableRow>

<TableRow>

<TextView

android:padding="10dp"

android:text="Aditi" />

<TextView

android:padding="10dp"

android:text="46" />

<TextView

android:text="5"

android:padding="10dp"/>

<TextView

android:text="123-456-7890"

android:padding="10dp"/>

</TableRow>

</TableLayout>
5 Write a program to display all the data types in object-oriented programming using Frame layout.
<?xml version="1.0" encoding="utf-8"?>

<FrameLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="wrap_content"

android:layout_height="match_parent"

tools:context=".MainActivity">

<TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@color/black"

android:fontFamily="sans-serif-smallcaps"

android:text="Data Types in Object Oriented Programming"

android:textAlignment="center"

android:textColor="@color/white"

android:textSize="30dp"

android:textStyle="bold|italic" />

<TextView

android:id="@+id/pd"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="top|left|fill_vertical"

android:layout_marginStart="10dp"

android:layout_marginTop="80dp"

android:layout_marginBottom="20dp"

android:fontFamily="sans-serif-smallcaps"

android:text="Primitive"

android:textSize="25dp"

android:textStyle="bold|italic" />

<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="20dp"

android:layout_marginTop="110dp"

android:foregroundGravity="fill_horizontal|top"

android:orientation="vertical">

<TextView
android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:fontFamily="sans-serif-smallcaps"

android:text="1) Integer"

android:textColor="@color/white"

android:textSize="20dp"

android:textStyle="bold" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:fontFamily="sans-serif-smallcaps"

android:text="2) Float"

android:textColor="@color/white"

android:textSize="20dp"

android:textStyle="bold" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:fontFamily="sans-serif-smallcaps"

android:text="3) Characters"

android:textColor="@color/white"

android:textSize="20dp"

android:textStyle="bold" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:fontFamily="sans-serif-smallcaps"

android:text="4) Boolean"

android:textColor="@color/white"

android:textSize="20dp"

android:textStyle="bold" />

</LinearLayout>

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="right|fill_vertical"

android:layout_marginTop="80dp"

android:layout_marginEnd="10dp"
android:layout_toRightOf="@+id/pd"

android:fontFamily="sans-serif-smallcaps"

android:text="Non-Primitive"

android:textSize="25dp"

android:textStyle="bold|italic" />

<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="right"

android:layout_marginTop="110dp"

android:layout_marginRight="20dp"

android:orientation="vertical">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:fontFamily="sans-serif-smallcaps"

android:text="1) Class"

android:textColor="@color/white"

android:textSize="20dp"

android:textStyle="bold" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:fontFamily="sans-serif-smallcaps"

android:text="2) Array"

android:textColor="@color/white"

android:textSize="20dp"

android:textStyle="bold" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:fontFamily="sans-serif-smallcaps"

android:text="3) Interface"

android:textColor="@color/white"

android:textSize="20dp"

android:textStyle="bold" />

<TextView

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:fontFamily="sans-serif-smallcaps"

android:text="4) Object"

android:textColor="@color/white"

android:textSize="20dp"

android:textStyle="bold" />

</LinearLayout</FrameLayout>
6 Write a program to accept username and password from the end user using Text View and Edit
Text.

<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:layout_marginLeft="0dp"

android:layout_marginRight="0dp"

android:orientation="vertical"

tools:context=".MainActivity">

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="200dp"

android:layout_marginBottom="30dp"

android:fontFamily="cursive"

android:paddingLeft="150dp"

android:text="Username:"

android:background="@color/purple_200"

android:textColor="@color/black"

android:textSize="25dp"

android:textStyle="bold" />

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="30dp"

android:layout_marginBottom="30dp"

android:fontFamily="cursive"

android:paddingLeft="150dp"

android:text="Password:"

android:background="@color/purple_200"

android:textColor="@color/black"

android:textSize="25dp"

android:textStyle="bold" />
<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="130dp"

android:layout_marginTop="50dp"

android:layout_marginRight="0dp"

android:layout_marginBottom="30dp"

android:backgroundTint="@color/white"

android:fontFamily="cursive"

android:text="Submit"

android:textColor="@color/black"

android:textSize="30dp" />

</LinearLayout>
7 Write a program to accept and display personal information of the student
<AbsoluteLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/absoluteLayout1"

android:layout_width="fill_parent"

android:layout_height="fill_parent">

<TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_x="0px"

android:layout_y="0px"

android:background="@color/black"

android:fontFamily="cursive"

android:text=" Student Registration Form "

android:textColor="@color/white"

android:textSize="30dp"

android:textStyle="bold|italic" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="30px"

android:layout_y="150px"

android:fontFamily="cursive"

android:text="Name:"

android:textSize="25dp"

android:textStyle="bold|italic" />

<EditText

android:layout_width="300dp"

android:layout_height="wrap_content"

android:width="100px"

android:layout_x="250px"

android:layout_y="150px"

/>

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="30px"

android:layout_y="350px"
android:fontFamily="cursive"

android:text="Address:"

android:textSize="25dp"

android:textStyle="bold|italic" />

<EditText

android:layout_width="270dp"

android:layout_height="wrap_content"

android:layout_x="123dp"

android:layout_y="126dp"

android:width="100px"

/>

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="30px"

android:layout_y="550px"

android:fontFamily="cursive"

android:text="Mobile no.:"

android:textSize="25dp"

android:textStyle="bold|italic" />

<EditText

android:layout_width="240dp"

android:layout_height="wrap_content"

android:layout_x="154dp"

android:layout_y="200dp"

android:width="100px"

/>

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="30px"

android:layout_y="750px"

android:fontFamily="cursive"

android:text="Mother's name:"

android:textSize="25dp"

android:textStyle="bold|italic" />

<EditText
android:layout_width="200dp"

android:layout_height="wrap_content"

android:layout_x="194dp"

android:layout_y="280dp"

android:width="100px"

/>

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="30px"

android:layout_y="950px"

android:fontFamily="cursive"

android:text="Father's name:"

android:textSize="25dp"

android:textStyle="bold|italic" />

<EditText

android:layout_width="200dp"

android:layout_height="wrap_content"

android:layout_x="194dp"

android:layout_y="350dp"

android:width="100px"

/>

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="30px"

android:layout_y="1150px"

android:fontFamily="cursive"

android:text="Gender:"

android:textSize="25dp"

android:textStyle="bold|italic" />

<RadioButton

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="130dp"

android:layout_y="430dp"

android:fontFamily="cursive"

android:text="Male"
android:textSize="25dp"

android:textStyle="bold|italic" />

<RadioButton

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="234dp"

android:layout_y="428dp"

android:fontFamily="cursive"

android:text="Female"

android:textSize="25dp"

android:textStyle="bold|italic" />

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="143dp"

android:layout_y="542dp"

android:fontFamily="cursive"

android:text="Submit"

android:textSize="25dp" />

</AbsoluteLayout>
8 Write a program to create a toggle button to display ON / OFF Bluetooth on the display screen.
<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">

<ToggleButton

android:id="@+id/toggleButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true"

android:textOff="Bluetooth Disabled"

android:textOn="Bluetooth Enabled"

android:textSize="25dp"/>

<TextView

android:id="@+id/textView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@id/toggleButton"

android:layout_centerHorizontal="true"

android:layout_marginTop="16dp"

android:text="Bluetooth is OFF"

android:textSize="25sp"/>

</RelativeLayout>

package com.begula.all_practicalsmad;

import android.os.Bundle;

import android.widget.CompoundButton;

import android.widget.TextView;

import android.widget.ToggleButton;

import androidx.appcompat.app.AppCompatActivity;

public class prac9_1 extends AppCompatActivity {

ToggleButton toggleButton;

TextView textView;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_prac91);

toggleButton = findViewById(R.id.toggleButton);

textView = findViewById(R.id.textView);
toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

if (isChecked) {

textView.setText("Toggle button is ON");

} else {

textView.setText("Toggle button is OFF");

});

}
9 Write a program to create a simple calculator.

<?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=".Calculator9_2">

<TextView

android:id="@+id/textView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:fontFamily="sans-serif-smallcaps"

android:text="Calculator"

android:textSize="35sp"

android:textStyle="bold"

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.09" />

<TextView

android:id="@+id/text1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:fontFamily="sans-serif-smallcaps"

android:text="Num 1 -"

android:textSize="25sp"

android:textStyle="bold|italic"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.04"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.248"></TextView>
<EditText

android:id="@+id/EditText1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:fontFamily="sans-serif-smallcaps"

android:hint="Enter your second number"

android:inputType="number"

android:textSize="23sp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.755"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/textView"

app:layout_constraintVertical_bias="0.096"></EditText>

<TextView

android:id="@+id/text2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:fontFamily="sans-serif-smallcaps"

android:text="Num 2 -"

android:textSize="25sp"

android:textStyle="bold|italic"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.04"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.352"></TextView>

<EditText

android:id="@+id/EditText2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:fontFamily="sans-serif-smallcaps"

android:hint="Enter your second number"

android:inputType="number"

android:textSize="23sp"
app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.948"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/textView"

app:layout_constraintVertical_bias="0.222"></EditText>

<Button

android:id="@+id/button1"

android:layout_width="205dp"

android:layout_height="50dp"

android:layout_marginBottom="20dp"

android:onClick="btnsum"

android:text="+"

android:textSize="30sp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.0"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.559"></Button>

<Button

android:id="@+id/button2"

android:layout_width="205dp"

android:layout_height="50dp"

android:layout_marginBottom="20dp"

android:onClick="btnsub"

android:text="-"

android:textSize="30sp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="1.0"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.559"></Button>

<Button

android:id="@+id/button3"
android:layout_width="205dp"

android:layout_height="50dp"

android:text="*"

android:onClick="btnmul"

android:textColor="@color/white"

android:textSize="30sp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.0"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.634"></Button>

<Button

android:id="@+id/button4"

android:layout_width="205dp"

android:layout_height="50dp"

android:onClick="btndiv"

android:text="/"

android:textColor="@color/white"

android:textSize="30sp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="1.0"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.634" />"

<TextView

android:id="@+id/result"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:fontFamily="sans-serif-smallcaps"

android:text="Result-"

android:textSize="30dp"

android:textStyle="bold|italic"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.18"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.829" />

<EditText

android:id="@+id/EditText3"

android:layout_width="140dp"

android:layout_height="wrap_content"

android:inputType="number"

android:textSize="23sp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.619"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/textView"

app:layout_constraintVertical_bias="0.812"></EditText>

</androidx.constraintlayout.widget.ConstraintLayout>

package com.example.mypracticalsofmad;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.CompoundButton;

import android.widget.EditText;

import android.widget.TextView;

import android.widget.ToggleButton;

public class MainActivity extends AppCompatActivity {

EditText firstnum, secnum, result;

@Override protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

firstnum = findViewById(R.id.editTextNumber);

secnum = findViewById(R.id.editTextNumber2);

result = findViewById(R.id.editTextNumber3); }

public void addition(View view){

int n = Integer.parseInt(String.valueOf(firstnum.getText()));
int n1 = Integer.parseInt(String.valueOf(secnum.getText()));

int res = n + n1; result.setText(String.valueOf(res)); }

public void substraction(View view){

int n = Integer.parseInt(String.valueOf(firstnum.getText()));

int n1 = Integer.parseInt(String.valueOf(secnum.getText()));

int res = n - n1; result.setText(String.valueOf(res)); }

public void multiplication(View view){

int n = Integer.parseInt(String.valueOf(firstnum.getText()));

int n1 = Integer.parseInt(String.valueOf(secnum.getText()));

int res = n * n1; result.setText(String.valueOf(res)); }

public void division(View view){

int n = Integer.parseInt(String.valueOf(firstnum.getText()));

int n1 = Integer.parseInt(String.valueOf(secnum.getText()));

int res = n / n1; result.setText(String.valueOf(res)); } }


10 Write a program to create a login form for a social networking site

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

<EditText

android:id="@+id/editText"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="103dp"

android:ems="10"

android:hint="Enter URL"

android:inputType="textPersonName"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.5"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent" />

<Button

android:id="@+id/button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="84dp"

android:text="Navigate"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/editText" />

</androidx.constraintlayout.widget.ConstraintLayout>

package com.example.practical18;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;
import android.view.View;

import android.widget.Button;

import android.widget.EditText;

public class MainActivity extends

AppCompatActivity {

EditText editText;

Button button;

@Override

protected void onCreate(Bundle

savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

editText = findViewById(R.id.editText);

button = findViewById(R.id.button);

button.setOnClickListener(new

View.OnClickListener() {

@Override

public void onClick(View v) {

String str =

"http://"+editText.getText();

Intent intent = new Intent();

intent.setAction(Intent.ACTION_VIEW);

intent.addCategory(Intent.CATEGORY_BROWSABLE);

intent.setData(Uri.parse(str));

startActivity(intent);

});

}
11 Write a program to create a login form for student registration system

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:padding="16dp">

<TextView

android:id="@+id/title_text_view"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:text="Student Registration Form"

android:textSize="24sp"

android:textStyle="bold" />

<TextView

android:id="@+id/name_text_view"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Name" />

<EditText

android:id="@+id/name_edit_text"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:inputType="textPersonName" />

<TextView

android:id="@+id/roll_no_text_view"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Roll no." />

<EditText

android:id="@+id/roll_no_edit_text"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:inputType="number" />

<TextView
android:id="@+id/gender_text_view"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Gender" />

<RadioGroup

android:id="@+id/gender_radio_group"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">

<RadioButton

android:id="@+id/male_radio_button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Male" />

<RadioButton

android:id="@+id/female_radio_button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Female" />

<RadioButton

android:id="@+id/other_radio_button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Other" />

</RadioGroup>

<TextView

android:id="@+id/phone_no_text_view"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Phone no." />

<EditText

android:id="@+id/phone_no_edit_text"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:inputType="phone" />

<TextView
android:id="@+id/date_of_birth_text_view"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Date of birth" />

<EditText

android:id="@+id/date_of_birth_edit_text"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:inputType="date" />

<TextView

android:id="@+id/email_text_view"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Email" />

<EditText

android:id="@+id/email_edit_text"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:inputType="textEmailAddress" />

<Button

android:id="@+id/submit_button"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Submit" />

</LinearLayout>
12 Write a program to show five checkboxes and toast selected checkboxes.

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

<androidx.constraintlayout.widget.ConstraintLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@color/white"

tools:context=".MainActivity">

<LinearLayout

android:id="@+id/linearLayout"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:padding="60dp"

android:layout_marginLeft="2dp"

tools:layout_editor_absoluteX="0dp"

tools:layout_editor_absoluteY="0dp">

<CheckBox

android:id="@+id/checkBox"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginLeft="120dp"

android:text="Java"

android:textColor="#3F51B5"

android:textSize="25dp"

android:textStyle="bold" />

<CheckBox

android:id="@+id/checkBox2"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginLeft="120dp"

android:text="Ruby"

android:textColor="#3F51B5"

android:textSize="25dp"
android:textStyle="bold" />

<CheckBox

android:id="@+id/checkBox3"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginLeft="120dp"

android:text="Java Script"

android:textColor="#3F51B5"

android:textSize="25dp"

android:textStyle="bold" />

<CheckBox

android:id="@+id/checkBox4"

android:layout_width="match_parent

android:layout_height="wrap_content"

android:layout_marginLeft="120dp"

android:text="Python"

android:textColor="#3F51B5"

android:textSize="25dp"

android:textStyle="bold" />

<CheckBox

android:id="@+id/checkBox5"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginLeft="120dp"

android:text="HTML"

android:textColor="#3F51B5"

android:textSize="25dp"

android:textStyle="bold" />

</LinearLayout>

<TextView

android:id="@+id/textView2"

android:layout_width="376dp"

android:layout_height="55dp"

android:fontFamily="times"

android:text="Select a Language"

android:textColor="@color/black"
android:textSize="30dp"

android:textStyle="bold"

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

tools:ignore="MissingConstraints" />

</androidx.constraintlayout.widget.ConstraintLayout>
13 Write a program to display circular progress bar

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

<ProgressBar

android:id="@+id/progress_bar"

android:layout_width="179dp"

android:layout_height="183dp"

android:indeterminate="true"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.474"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.076" />

<TextView

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginStart="110dp"

android:layout_marginTop="28dp"

android:layout_marginEnd="111dp"

android:background="@color/design_default_color_secondary"

android:text="Circular Progress Bar"

android:textColor="@color/black"

android:textSize="20dp"

android:fontFamily="sans-serif"

android:textStyle="bold"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/progress_bar" />
<ProgressBar

android:id="@+id/progressBar"

style="?android:attr/progressBarStyleHorizontal"

android:layout_width="match_parent"

android:layout_height="77dp"

android:layout_marginTop="20dp"

android:indeterminate="true"

android:max="100"

android:progress="50"

android:progressBackgroundTint="@color/purple_200"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/textView2" />

<TextView

android:id="@+id/textView2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginStart="100dp"

android:layout_marginTop="126dp"

android:layout_marginEnd="100dp"

android:background="@color/design_default_color_secondary"

android:text="Horizontal Progress Bar"

android:fontFamily="sans-serif"

android:textColor="@color/black"

android:textSize="20dp"

android:textStyle="bold"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/textView1"/>

</androidx.constraintlayout.widget.ConstraintLayout>
14 WAP to display an image using image view and a button named as

changed image once you click on button another image should get

dsiplayed

<?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=".prac14_2">

<TextView

android:id="@+id/t1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="T.O.P_G"

android:textSize="45dp"

android:textColor="@color/black"

android:fontFamily="serif"

android:textStyle="bold"

app:layout_constraintBottom_toBottomOf="@+id/imageview1"

app:layout_constraintEnd_toEndOf="@+id/imageview1"

app:layout_constraintStart_toStartOf="@+id/imageview1"

app:layout_constraintTop_toTopOf="@+id/imageview1"/>

<ImageView

android:id="@+id/imageview1"

android:layout_width="388dp"

android:layout_height="482dp"

android:layout_margin="20dp"

android:contentDescription="Img1"

android:padding="5dp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.703"

app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.103" />

<Button

android:id="@+id/btn1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Change Image"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.498"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/imageview1"

app:layout_constraintVertical_bias="0.602" />

</androidx.constraintlayout.widget.ConstraintLayout>

package com.begula.all_practicalsmad;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.ImageView;

public class prac14_2 extends AppCompatActivity {

Button b1;

ImageView iv;

int[] image = {R.mipmap.img1,R.mipmap.img2,R.mipmap.img3};

int i = 0;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_prac142);

b1 = findViewById(R.id.btn1);

iv = findViewById(R.id.imageview1);

b1.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

iv.setImageResource(image[i]);

i++;
if(i==3)

i=0;

});

}
15 WAP to display fifteen buttons using grid view

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

<android.support.constraint.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">

<GridView

android:id="@+id/gridview1"

android:layout_width="409dp"

android:layout_height="729dp"

android:numColumns="3"

android:padding="5dp"

android:layout_margin="10dp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

package com.begula.javafrom14_3toall;

import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

import android.view.View;

import android.widget.AdapterView;

import android.widget.ArrayAdapter;

import android.widget.Button;

import android.widget.GridView;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

private GridView gridView;

private String[] buttonLabels = {"Button 1", "Button 2", "Button 3", "Button 4", "Button 5",

"Button 6", "Button 7", "Button 8", "Button 9", "Button 10",

"Button 11", "Button 12", "Button 13", "Button 14", "Button 15"};

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// Get a reference to the GridView

gridView = findViewById(R.id.gridview1);

// Create an ArrayAdapter to hold the button labels

ArrayAdapter<String> adapter = new ArrayAdapter<>(this,

android.R.layout.simple_list_item_1, buttonLabels);

// Set the adapter for the GridView

gridView.setAdapter(adapter);

// Set the onItemClickListener for the GridView

gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override

public void onItemClick(AdapterView<?> adapterView, View view, int position, long

id) {

// Get the text of the button that was clicked

String buttonText = buttonLabels[position];

// Display a toast message with the text of the button that was clicked

Toast.makeText(MainActivity.this, buttonText, Toast.LENGTH_SHORT).show();

});

}
16. WAP to display a text view using vertical scroll view

17 WAP to display date and time on click of select date, select time buttons respectively

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

<androidx.constraintlayout.widget.ConstraintLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@color/white"

tools:context=".MainActivity">

<EditText

android:id="@+id/editText1"

android:layout_width="200dp"

android:layout_height="wrap_content"

android:backgroundTint="@color/white"

android:textColor="@color/white"

android:textColorHighlight="@color/white"

android:textColorHint="@color/white"

android:textSize="20dp"

android:textStyle="bold|italic"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.075"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.306" />

<EditText

android:id="@+id/editText"

android:layout_width="200dp"

android:layout_height="wrap_content"

android:backgroundTint="@color/white"

android:textColor="@color/white"
android:textColorHighlight="@color/white"

android:textColorHint="@color/white"

android:textSize="20dp"

android:textStyle="bold|italic"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.075"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.499" />

<Button

android:id="@+id/button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginEnd="41dp"

android:backgroundTint="@color/black"

android:onClick="opendateandtime"

android:text="SELECT DATE"

android:textColor="@color/white"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="1.0"

app:layout_constraintStart_toEndOf="@+id/editText1"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.306" />

<Button

android:id="@+id/button2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:backgroundTint="@color/black"

android:onClick="opendateandtime"

android:text="SELECT TIME"

android:textColor="@color/white"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.849"
app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.499" />

</androidx.constraintlayout.widget.ConstraintLayout>

package com.begula.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.app.DatePickerDialog;

import android.app.TimePickerDialog;

import android.icu.util.Calendar;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.DatePicker;

import android.widget.EditText;

import android.widget.TimePicker;

public class MainActivity extends

AppCompatActivity {

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.button);

btnTimePicker=(Button)findViewById(R.id.button2);

txtDate=(EditText)findViewById(R.id.editText1);

txtTime=(EditText)findViewById(R.id.editText);

public void opendateandtime(View view){

if (view == btnDatePicker) {

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 (view == btnTimePicker) {

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

}
18 WAP to display Time Picker with spinner mode

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

<ScrollView

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent">

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

android:background="@color/purple_200">

<TimePicker

android:id="@+id/tp1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:timePickerMode="spinner"

android:background="@color/purple_200"

android:numbersInnerTextColor="@color/white"/>

<TimePicker

android:id="@+id/tp3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:timePickerMode="spinner"

android:format24Hour="true" />

<TimePicker

android:id="@+id/tp2"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:timePickerMode="clock"

android:background="@color/purple_200"/>

</LinearLayout>

</ScrollView>

package com.example. practical16;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.TimePicker;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

TimePicker tp3 = findViewById(R.id.tp3);

tp3.setIs24HourView(true); }

}
19 Write a program to create a HelloWorld Activity using all lifecycles methods to display messages
using Log.d.

package com.example.mad_practical_17;

import androidx.appcompat.app.AppCompatActivity;

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

public class MainActivity extends AppCompatActivity {

private void showLog(String text){

Log.d("HOME_ACTIVITY_TAG",text); }

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main); }

@Override

protected void onRestart(){

super.onRestart();

showLog("Activity restarted"); }

@Override

protected void onStart() {

super.onStart();

showLog("Activity started"); }

@Override

protected void onResume() {

super.onResume();

showLog("Activity resumed"); }

@Override

protected void onPause() {

super.onPause();

showLog("Activity paused"); }

@Override

protected void onStop() {

super.onStop();

showLog("Activity stopped"); }

@Override

protected void onDestroy() {

super.onDestroy();

showLog("Activity is being destroyed"); } }


20 Write a program to create a text field and a button “Navigate”. When you enter
“www.google.com” and press navigate button it should open google page

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

<EditText

android:id="@+id/editText"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="103dp"

android:ems="10"

android:hint="Enter URL"

android:inputType="textPersonName"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.5"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent" />

<Button

android:id="@+id/button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="84dp"

android:text="Navigate"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/editText" />

</androidx.constraintlayout.widget.ConstraintLayout>

package com.example.practical18;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;

import android.net.Uri;
import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

public class MainActivity extends

AppCompatActivity {

EditText editText;

Button button;

@Override

protected void onCreate(Bundle

savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

editText = findViewById(R.id.editText);

button = findViewById(R.id.button);

button.setOnClickListener(new

View.OnClickListener() {

@Override

public void onClick(View v) {

String str =

"http://"+editText.getText();

Intent intent = new Intent();

intent.setAction(Intent.ACTION_VIEW);

intent.addCategory(Intent.CATEGORY_BROWSABLE);

intent.setData(Uri.parse(str));

startActivity(intent);

});

}
21. Write a program to create button “Start Dialer”. When u click on this button it should open the
phone diale

<?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/button2"

android:layout_width="190dp"

android:layout_height="70dp"

android:text="@string/show_dialer"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.547"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.397" />

</androidx.constraintlayout.widget.ConstraintLayout>

JAVA CODE:

package com.example.pract181;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity { Button button;

@Override

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main); button = findViewById(R.id.button2);

button.setOnClickListener(new View.OnClickListener() { @Override

public void onClick(View v) {


Intent inte = new Intent(Intent.ACTION_DIAL); try {

startActivity(inte);

} catch (Exception e){

Toast.makeText(MainActivity.this, "An error occurred", Toast.LENGTH_LONG).show();

});

}
22. Write a program to demonstrate all the system broadcast messages.

Activity_main.xml

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

<androidx.constraintlayout.widget.ConstraintLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@color/black"

android:orientation="vertical"

tools:context=".MainActivity">

<Button

android:id="@+id/button1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@color/purple_200"

android:fontFamily="casual"

android:onClick="onBroadcastSendBtnClicked"

android:text="send data"

android:textColor="@color/black"

android:textSize="20sp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

AndroidManifest.xml

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

package="com.example.practical_21">

<application

android:allowBackup="true"

android:dataExtractionRules="@xml/data_extraction_rules"

android:fullBackupContent="@xml/backup_rules"
android:icon="@drawable/iii"

android:label="@string/app_name"

android:supportsRtl="true"

android:theme="@style/Theme.Practical_21"

tools:targetApi="31">

<receiver

android:name="MyBroadcastReceiver"

android:enabled="true"

android:exported="true">

<intent-filter>

<action android:name="android.intent.action.AIRPLANE_MODE">

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

MainActivity.java

package com.example.practical_21;

import android.content.Intent;

import android.content.IntentFilter;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import

androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends

AppCompatActivity {

private MyBroadcastReceiver receiver;


@Override

protected void onCreate(Bundle

savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

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

receiver = new MyBroadcastReceiver();

@Override

protected void onStart () {

super.onStart();

IntentFilter filter = new IntentFilter();

filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);

filter.addAction(Intent.ACTION_BOOT_COMPLETED);

filter.addAction(Intent.ACTION_SCREEN_ON);

filter.addAction(Intent.ACTION_SCREEN_OFF);

filter.addAction(Intent.ACTION_POWER_CONNECTED);

filter.addAction(Intent.ACTION_POWER_DISCONNECTED);

filter.addAction(Intent.ACTION_HEADSET_PLUG);

registerReceiver(receiver, filter);

@Override

protected void onStop () {

super.onStop();

unregisterReceiver(receiver);

public void onBroadcastSendBtnClicked(View view) {

MyBroadcastReceiver.java

package com.example.practical_21;

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

import android.provider.Settings;

import android.widget.Toast;
public class MyBroadcastReceiver extends

BroadcastReceiver {

@Override

public void onReceive(Context context, Intent

intent) {

String action = intent.getAction();

switch (action) {

case

Intent.ACTION_AIRPLANE_MODE_CHANGED:

if

(isAirplaneModeOn(context.getApplicationContext

())) {

Toast.makeText(context, "AirPlane mode is on", Toast.LENGTH_SHORT).show();

} else {

Toast.makeText(context, "AirPlane mode is off", Toast.LENGTH_SHORT).show();

case

Intent.ACTION_BOOT_COMPLETED:

Toast.makeText(context, "Device boot completed", Toast.LENGTH_SHORT).show();

break;

case Intent.ACTION_SCREEN_ON:

Toast.makeText(context, "Screen is ON",

Toast.LENGTH_SHORT).show();

break;

case Intent.ACTION_SCREEN_OFF:

Toast.makeText(context, "Screen is OFF", Toast.LENGTH_SHORT).show();

break;

case

Intent.ACTION_POWER_CONNECTED:

Toast.makeText(context, "Power connected", Toast.LENGTH_SHORT).show();

break;

case

Intent.ACTION_POWER_DISCONNECTED:

Toast.makeText(context, "Power disconnected", Toast.LENGTH_SHORT).show();

break;

case Intent.ACTION_HEADSET_PLUG:
int state = intent.getIntExtra("state", -1);

if (state == 0) {

Toast.makeText(context, "Headset unplugged", Toast.LENGTH_SHORT).show();

} else if (state == 1) {

Toast.makeText(context, "Headset plugged", Toast.LENGTH_SHORT).show();

break;

private boolean isAirplaneModeOn(Context applicationContext) {

return

Settings.System.getInt(applicationContext.getContentResolver(),

Settings.Global.AIRPLANE_MODE_ON, 0) != 0;

}
23. Write a program to display the list of sensors supported by the mobile device.

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

<TextView

android:id="@+id/textView"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:text="Shake to switch color"

android:textColor="@color/black"

android:textSize="24sp"

android:textStyle="bold" />

</RelativeLayout>

package com.example.practical22;

import android.app.Activity;

import android.graphics.Color;

import android.hardware.Sensor;

import android.hardware.SensorEvent;

import android.hardware.SensorEventListener;

import android.hardware.SensorManager;

import android.os.Bundle;

import android.view.View;

import android.widget.Toast;

public class MainActivity extends Activity implements SensorEventListener{

private SensorManager sensorManager;

private boolean isColor = false;

private View view;

private long lastUpdate;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

view = findViewById(R.id.textView);
view.setBackgroundColor(Color.GREEN);

sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

lastUpdate = System.currentTimeMillis();

@Override

public void onAccuracyChanged(Sensor sensor, int accuracy) {}

@Override

public void onSensorChanged(SensorEvent event) {

if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {

getAccelerometer(event);

private void getAccelerometer(SensorEvent event) {

float[] values = event.values;

// Movement

float x = values[0];

float y = values[1];

float z = values[2];

float accelationSquareRoot = (x * x + y * y + z * z)

/ (SensorManager.GRAVITY_EARTH * SensorManager.GRAVITY_EARTH);

long actualTime = System.currentTimeMillis();

Toast.makeText(getApplicationContext(),String.valueOf(accelationSquareRoot)+" "+

SensorManager.GRAVITY_EARTH,Toast.LENGTH_SHORT).show();

if (accelationSquareRoot >= 2)

if (actualTime - lastUpdate < 200) {

return;

lastUpdate = actualTime;

if (isColor) {

view.setBackgroundColor(Color.BLACK);

} else {

view.setBackgroundColor(Color.YELLOW);

isColor = !isColor;

}
}

@Override

protected void onResume() {

super.onResume();

sensorManager.registerListener(this,sensorManager.getDefaultSensor(Sensor.TYPE_ACCELER

OMETER),

SensorManager.SENSOR_DELAY_NORMAL);

@Override

protected void onPause() {

super.onPause();

sensorManager.unregisterListener(this);

}
24 Write a program to capture an image and display it using image view.

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


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

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#45EC1F"
tools:context="MainActivity">

<Button
android:id="@+id/camera_button"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_marginLeft="140dp"
android:text="Camera" />

<ImageView
android:id="@+id/click_image"
android:layout_width="350dp"
android:layout_height="450dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="70dp"
android:layout_marginBottom="10dp" />
</RelativeLayout>

Java

package com.example.myapplication;
import android.content.Intent;

import android.graphics.Bitmap;
import android.provider.MediaStore;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {

private static final int pic_id = 123;

Button camera_open_id;

ImageView click_image_id;

@Override

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

camera_open_id = (Button)findViewById(R.id.camera_button);

click_image_id = (ImageView)findViewById(R.id.click_image);
camera_open_id.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v)

Intent camera_intent = new Intent (MediaStore.ACTION_IMAGE_CAPTURE);

startActivityForResult(camera_intent, pic_id);

});

protected void onActivityResult(int requestCode,

int resultCode, Intent data) {


super.onActivityResult(requestCode, resultdata);

if (requestCode == pic_id) {

Bitmap photo = (Bitmap) data.getExtras().get("data");

click_image_id.setImageBitmap(photo);}

}
25. Write a program to turn on, get visible, list devices and turnoff Bluetooth

Activity_main.xml

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

<RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="#FFEB3B"

tools:context=".MainActivity">

<TextView

android:id="@+id/textview1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginStart="15dp"

android:layout_marginTop="15dp"

android:layout_marginEnd="15dp"

android:layout_marginBottom="15dp"

android:fontFamily="casual"

android:text="Bluetooth"

android:textColor="#087785"

android:textSize="34sp"

android:textStyle="bold" />

<Button

android:id="@+id/TurnOn"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/textview1"

android:layout_marginStart="15dp"

android:layout_marginTop="15dp"

android:layout_marginBottom="10dp"

android:backgroundTint="#FF5722"

android:fontFamily="casual"

android:onClick="on"

android:text="Turn On"
android:textSize="16sp"

android:textStyle="bold" />

<Button

android:id="@+id/GetVisible"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/TurnOn"

android:layout_marginStart="15dp"

android:backgroundTint="#FF5722"

android:fontFamily="casual"

android:onClick="visible"

android:text="Get Visible"

android:textSize="16sp"

android:textStyle="bold" />

<Button

android:id="@+id/ListDevices"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/GetVisible"

android:layout_marginStart="15dp"

android:layout_marginTop="10dp"

android:backgroundTint="#FF5722"

android:fontFamily="casual"

android:onClick="list"

android:text="List Devices"

android:textSize="16sp"

android:textStyle="bold" />

<Button

android:id="@+id/TurnOff"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/ListDevices"

android:layout_marginStart="15dp"

android:layout_marginTop="10dp"

android:backgroundTint="#FF5722"

android:fontFamily="casual"
android:onClick="off"

android:text="Turn Off"

android:textSize="16sp"

android:textStyle="bold" />

<TextView

android:id="@+id/paired"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@id/TurnOff"

android:layout_marginStart="15dp"

android:layout_marginTop="15dp"

android:fontFamily="casual"

android:text="Paired Devices :"

android:textColor="#087785"

android:textSize="34sp"

android:textStyle="bold" />

<ListView

android:id="@+id/pairedDevice1"

android:layout_width="match_parent"

android:layout_height="200dp"

android:layout_below="@+id/paired"

android:layout_marginStart="17dp"

android:layout_marginTop="17dp"

android:outlineAmbientShadowColor="@color/black"

android:layout_marginEnd="17dp"

android:layout_marginBottom="17dp"

android:scrollbarSize="?android:attr/scrollbarSize" />

</RelativeLayout>

MainActivity.java

package com.example.practical24;

import androidx.appcompat.app.AppCompatActivity;

import androidx.core.app.ActivityCompat;

import android.bluetooth.BluetoothAdapter;

import android.bluetooth.BluetoothDevice;

import android.content.Intent;

import android.content.pm.PackageManager;
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 AppCompatActivity {

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.TurnOn);

b2 = (Button) findViewById(R.id.GetVisible);

b3 = (Button) findViewById(R.id.ListDevices);

b4 = (Button) findViewById(R.id.TurnOff);

BA = BluetoothAdapter.getDefaultAdapter();

lv = (ListView) findViewById(R.id.pairedDevice1);

public void on(View v) {

if (!BA.isEnabled()) {

Intent turnOn = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);

if (ActivityCompat.checkSelfPermission(this,

android.Manifest.permission.BLUETOOTH_CONNECT) !=

PackageManager.PERMISSION_GRANTED) {

return;

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) {

if (ActivityCompat.checkSelfPermission(this,

android.Manifest.permission.BLUETOOTH_CONNECT) !=

PackageManager.PERMISSION_GRANTED) {

return;

BA.disable();

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

public void visible(View v) {

Intent getVisible = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);

if (ActivityCompat.checkSelfPermission(this,

android.Manifest.permission.BLUETOOTH_ADVERTISE) !=

PackageManager.PERMISSION_GRANTED) {

return;

startActivityForResult(getVisible, 0);

public void list(View v) {

if (ActivityCompat.checkSelfPermission(this,

android.Manifest.permission.BLUETOOTH_CONNECT) !=

PackageManager.PERMISSION_GRANTED) {

return;

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

AndroidManifest.xml

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

<manifest

xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.mad_practical_24">

<uses-permission

android:name="android.permission.BLUETOOTH"/>

<uses-permission

android:name="android.permission.BLUETOOTH_ADMIN"/>

<uses-permission

android:name="android.permission.BLUETOOTH_ADVERTISE" />

<uses-permission

android:name="android.permission.BLUETOOTH_CONNECT" />

<application

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"

android:theme="@style/Theme.Practical24">

<activity

android:name="com.example.practical24.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>
26 Write a program to create the login form and display login successful/ Unsuccessful
toastmessage.

XML:

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

<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="#4CAF50"

tools:context=".MainActivity">

<TextView

android:id="@+id/textView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:fontFamily="sans-serif-condensed-light"

android:text="LOGIN"

android:textColor="#273898"

android:textSize="30sp"

android:textStyle="bold"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintHorizontal_bias="0.134"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toRightOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.134" />

<EditText

android:id="@+id/edt1"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_marginBottom="74dp"

android:background="#ECECEC"

android:ems="10"
android:hint="Username"

android:inputType="textPersonName"

android:padding="12dp"

app:layout_constraintBottom_toTopOf="@+id/edt2"

app:layout_constraintEnd_toEndOf="@+id/edt2"

app:layout_constraintStart_toStartOf="@+id/edt2"

app:layout_constraintTop_toBottomOf="@+id/textView" />

<EditText

android:id="@+id/edt2"

android:layout_width="300dp"

android:layout_height="wrap_content"

android:layout_marginStart="44dp"

android:layout_marginBottom="90dp"

android:background="#ECECEC"

android:ems="10"

android:hint="Password"

android:inputType="textPassword"

android:padding="12dp"

app:layout_constraintBottom_toTopOf="@+id/button"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/edt1" />

<Button

android:id="@+id/button"

android:layout_width="140dp"

android:layout_height="wrap_content"

android:layout_marginBottom="204dp"

android:backgroundTint="#03A9F4"

android:onClick="formLogin"

android:text="Login"

app:cornerRadius="8dp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/edt2" />
<TextView

android:id="@+id/textView2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginBottom="78dp"

android:textColor="#000000"

android:textSize="20sp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/button"

app:layout_constraintVertical_bias="0.828" />

</androidx.constraintlayout.widget.ConstraintLayout>

JAVA:

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

EditText ed1, ed2;

TextView tv;

Button b1;

int count;

@Override

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

ed1 = findViewById(R.id.edt1);

ed2 = findViewById(R.id.edt2);
tv = findViewById(R.id.textView2);

b1 = findViewById(R.id.button);

count = 3;

tv.setText("You have only "+count+" Attempts");

public void formLogin(View view){

String uname, passwd;

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

passwd = ed2.getText().toString();

count--;

tv.setText("Attempts left: "+count);

if (count == 0){

b1.setEnabled(false);

if (uname.equals("") && passwd.equals("")){

Toast.makeText(MainActivity.this, "Please enter username and password",

Toast.LENGTH_SHORT).show();

} else if (passwd.length() < 8){

Toast.makeText(MainActivity.this, "Password should be 8 charecter long",

Toast.LENGTH_SHORT).show();

} else if (uname.equals("Admin") &&

passwd.equals("12345678")){

Toast.makeText(MainActivity.this, "Login successful", Toast.LENGTH_SHORT).show();

tv.setText("");

}
27 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 version="1.0" encoding="utf-8"?>


<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C81717"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed-light"
android:text="LOGIN"
android:textColor="#273898"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.134"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.134" />

<EditText
android:id="@+id/edt1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="74dp"
android:background="#1E1D1D"
android:ems="10"
android:hint="Username"
android:inputType="textPersonName"
android:padding="12dp"
app:layout_constraintBottom_toTopOf="@+id/edt2"
app:layout_constraintEnd_toEndOf="@+id/edt2"
app:layout_constraintStart_toStartOf="@+id/edt2"
app:layout_constraintTop_toBottomOf="@+id/textView" />

<EditText
android:id="@+id/edt2"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginStart="44dp"
android:layout_marginBottom="90dp"
android:background="#151515"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
android:padding="12dp"
app:layout_constraintBottom_toTopOf="@+id/button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edt1" />

<Button
android:id="@+id/button"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginBottom="204dp"
android:backgroundTint="#03A9F4"
android:onClick="formLogin"
android:text="Login"
app:cornerRadius="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edt2" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="78dp"
android:textColor="#000000"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button"
app:layout_constraintVertical_bias="0.828" />
</androidx.constraintlayout.widget.ConstraintLayout>

Java

package com.example.practica16;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

import android.widget.Toast;
public class MainActivity extends AppCompatActivity {

EditText ed1, ed2;

TextView tv;

Button b1;

int count;

@Override

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

ed1 = findViewById(R.id.edt1);

ed2 = findViewById(R.id.edt2);

tv = findViewById(R.id.textView2);

b1 = findViewById(R.id.button);

count = 3;

tv.setText("You have only "+count+" Attempts");

public void formLogin(View view){

String uname, passwd;

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

passwd = ed2.getText().toString();

count--;
tv.setText("Attempts left: "+count);

if (count == 0){

b1.setEnabled(false);

if (uname.equals("") && passwd.equals("")){

Toast.makeText(MainActivity.this, "Please enter username and password",

Toast.LENGTH_SHORT).show();

} else if (passwd.length() < 8){

Toast.makeText(MainActivity.this, "Password should be 8 charecter long",


Toast.LENGTH_SHORT).show();

} else if (uname.equals("Aditi") &&

passwd.equals("12345678")){

Toast.makeText(MainActivity.this, "Login successful", Toast.LENGTH_SHORT).show();

tv.setText("");

}
28. WAP to send and receive SMS

Activity_main.xml

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

<androidx.constraintlayout.widget.ConstraintLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="#CDDC39"

tools:context=".MainActivity">

<EditText

android:id="@+id/editTextPhoneNumber"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:fontFamily="sans-serif-condensed-medium"

android:hint="@string/phone_number"

android:inputType="phone"

android:textColor="@color/black"

android:textColorHighlight="@color/black"

android:textColorHint="@color/black"

android:textSize="20sp"

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.1" />

<EditText

android:id="@+id/editTextMessage"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:fontFamily="sans-serif-condensed-medium"

android:hint="@string/message"

android:inputType="text"

android:textColor="@color/black"

android:textColorHighlight="@color/black"
android:textColorHint="@color/black"

android:textSize="20sp"

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.3" />

<Button

android:id="@+id/buttonSendSMS"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:fontFamily="sans-serif-condensed-medium"

android:text="@string/send_sms"

android:textColor="@color/black"

android:textSize="24sp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.451"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.733" />

</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java

package com.example.prac29;

import androidx.annotation.NonNull;

import androidx.appcompat.app.AppCompatActivity;

import androidx.appcompat.app.WindowDecorActionBar;

import androidx.core.app.ActivityCompat;

import androidx.core.content.ContextCompat;

import android.content.pm.PackageManager;

import android.os.Bundle;

import android.telephony.SmsManager;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;
public class MainActivity extends AppCompatActivity {

EditText editText1, editText2;

Button button;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

editText1=findViewById(R.id.editTextPhoneNumber);

editText2=findViewById(R.id.editTextMessage);

button=findViewById(R.id.buttonSendSMS);

button.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

try {

SmsManager sms=SmsManager.getDefault();

((SmsManager)

sms).sendTextMessage(editText1.getText().toString(),null,editText2.getText().toString(),null,null);

Toast.makeText(getApplicationContext(), "sms sent successfully",

Toast.LENGTH_SHORT).show();

catch (Exception e)

Toast.makeText(getApplicationContext(), "sms failed to send",

Toast.LENGTH_SHORT).show();

});

//

// Source code recreated from a .class file by IntelliJ IDEA

// (powered by FernFlower decompiler)

//

SmsReceiver.java

package android.widget;
import android.content.Context;

import android.text.Editable;

import android.text.TextUtils;

import android.text.method.MovementMethod;

import android.util.AttributeSet;

public class EditText extends TextView {

public EditText(Context context) {

super((Context)null);

throw new RuntimeException("Stub!");

public EditText(Context context, AttributeSet attrs) {

super((Context)null);

throw new RuntimeException("Stub!");

public EditText(Context context, AttributeSet attrs, int defStyleAttr) {

super((Context)null);

throw new RuntimeException("Stub!");

public EditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {

super((Context)null);

throw new RuntimeException("Stub!");

public boolean getFreezesText() {

throw new RuntimeException("Stub!");

protected boolean getDefaultEditable() {

throw new RuntimeException("Stub!");

protected MovementMethod getDefaultMovementMethod() {

throw new RuntimeException("Stub!");

public Editable getText() {

throw new RuntimeException("Stub!");

public void setText(CharSequence text, TextView.BufferType type) {

throw new RuntimeException("Stub!");


}

public void setSelection(int start, int stop) {

throw new RuntimeException("Stub!");

public void setSelection(int index) {

throw new RuntimeException("Stub!");

public void selectAll() {

throw new RuntimeException("Stub!");

public void extendSelection(int index) {

throw new RuntimeException("Stub!");

public void setEllipsize(TextUtils.TruncateAt ellipsis) {

throw new RuntimeException("Stub!");

public CharSequence getAccessibilityClassName() {

throw new RuntimeException("Stub!");

protected void onSizeChanged(int w, int h, int oldw, int oldh) {

throw new RuntimeException("Stub!");

}
29. WAP to locate user current location

<?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:background="@color/black"
android:orientation="vertical"
android:paddingVertical="2dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/black"
android:fontFamily="sans-serif"
android:paddingVertical="15dp"
android:text="Send Email"
android:textColor="@color/white"
android:textSize="34sp"
android:textStyle="bold" />

<EditText
android:id="@+id/edit1"
android:layout_width="331dp"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:hint="To"
android:paddingVertical="15dp"
android:textColor="@color/white"
android:textColorHighlight="@color/white"
android:textColorHint="@color/white"
android:textSize="20sp" />

<EditText
android:id="@+id/edit2"
android:layout_width="331dp"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:hint="Subject"
android:paddingVertical="15dp"
android:textColor="@color/white"
android:textColorHighlight="@color/white"
android:textColorHint="@color/white"
android:textSize="20sp" />

<EditText
android:id="@+id/edit3"
android:layout_width="331dp"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:hint="Message"
android:paddingVertical="15dp"
android:textColor="@color/white"
android:textColorHighlight="@color/white"
android:textColorHint="@color/white"
android:textSize="20sp" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:text="Send email"
android:textColor="@color/black"
android:textColorHint="@color/black"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
30. Write a program to send email

Activity_main.xml

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

<androidx.constraintlayout.widget.ConstraintLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="#CDDC39"

android:orientation="vertical"

android:paddingVertical="2dp">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="#CDDC39"

android:fontFamily="sans-serif-condensed-medium"

android:paddingVertical="15dp"

android:text="Send Email"

android:textColor="@color/black"

android:textSize="34sp"

android:textStyle="bold" />

<EditText

android:id="@+id/edit1"

android:layout_width="331dp"

android:layout_height="wrap_content"

android:fontFamily="sans-serif-condensed-medium"

android:hint="To"

android:paddingVertical="15dp"

android:textColor="@color/black"

android:textColorHighlight="@color/black"

android:textColorHint="@color/black"
android:textSize="20sp" />

<EditText

android:id="@+id/edit2"

android:layout_width="331dp"

android:layout_height="wrap_content"

android:fontFamily="sans-serif-condensed-medium"

android:hint="Subject"

android:paddingVertical="15dp"

android:textColor="@color/black"

android:textColorHighlight="@color/black"

android:textColorHint="@color/black"

android:textSize="20sp" />

<EditText

android:id="@+id/edit3"

android:layout_width="331dp"

android:layout_height="wrap_content"

android:fontFamily="sans-serif-condensed-medium"

android:hint="Message"

android:paddingVertical="15dp"

android:textColor="@color/black"

android:textColorHighlight="@color/black"

android:textColorHint="@color/black"

android:textSize="20sp" />

<Button

android:id="@+id/button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:fontFamily="sans-serif-condensed-medium"

android:text="Send email"

android:textColor="@color/black"

android:textColorHint="@color/black"

android:textSize="24sp"

android:textStyle="bold" />

</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java
package com.example.prac30;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

EditText e1,e2,e3;

Button b;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

e1=findViewById(R.id.edit1);

e2=findViewById(R.id.edit2);

e3=findViewById(R.id.edit3);

b=findViewById(R.id.button);

b.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

Intent intent = new Intent(Intent.ACTION_SEND);

intent.putExtra(Intent.EXTRA_EMAIL,new

String[]{e1.getText().toString()});

intent.putExtra(Intent.EXTRA_SUBJECT,e2.getText().toString());

intent.putExtra(Intent.EXTRA_TEXT,e3.getText().toString());

intent.setType("message/rfc822");

startActivity(Intent.createChooser(intent,"choose mail app"));

});

You might also like