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

progmad

Uploaded by

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

progmad

Uploaded by

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

Practical 6

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

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

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

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

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<TableRow android:background="#00BCD4" android:padding="5dp">

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="Sr. No"

android:textColor="@color/white"

android:textStyle="bold"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="Roll No"

android:textColor="@color/white"

android:textStyle="bold"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="Name"

android:textColor="@color/white"

android:textStyle="bold"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="Percentage"

android:textColor="@color/white"
android:textStyle="bold"

android:textSize="16sp"

android:layout_weight="1"/>

</TableRow>

<TableRow android:background="#D2D2D2" android:padding="5dp">

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="1"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="3317"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="Prajwal Charthad"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="80.33%"

android:textSize="16sp"

android:layout_weight="1"/>

</TableRow>

<TableRow android:background="#D2D2D2" android:padding="5dp">

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="2"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView
android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="3323"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="Atharva Kshirsagar"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="93.11%"

android:textSize="16sp"

android:layout_weight="1"/>

</TableRow>

<TableRow android:background="#D2D2D2" android:padding="5dp">

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="3"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="3339"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="Shron Lande"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView
android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="70.00%"

android:textSize="16sp"

android:layout_weight="1"/>

</TableRow>

<TableRow android:background="#D2D2D2" android:padding="5dp">

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="4"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="3334"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="Samyak Kamble"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="86.11%"

android:textSize="16sp"

android:layout_weight="1"/>

</TableRow>

<TableRow android:background="#D2D2D2" android:padding="5dp">

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="5"

android:textSize="16sp"
android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="3336"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="Soham Deoghare"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="81.59%"

android:textSize="16sp"

android:layout_weight="1"/>

</TableRow>

<TableRow android:background="#D2D2D2" android:padding="5dp">

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="6"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="3313"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="Som Bhagat"

android:textSize="16sp"
android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="79.93%"

android:textSize="16sp"

android:layout_weight="1"/>

</TableRow>

<TableRow android:background="#D2D2D2" android:padding="5dp">

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="7"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="3311"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="Darshak Dholariya "

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="78.52%"

android:textSize="16sp"

android:layout_weight="1"/>

</TableRow>

<TableRow android:background="#D2D2D2" android:padding="5dp">

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"
android:text="8"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="3338"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="Abhishek Agasibagal"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="81.00%"

android:textSize="16sp"

android:layout_weight="1"/>

</TableRow>

<TableRow android:background="#D2D2D2" android:padding="5dp">

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="9"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="3332"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"
android:text="Sarang Bendre"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="79.00%"

android:textSize="16sp"

android:layout_weight="1"/>

</TableRow>

<TableRow android:background="#D2D2D2" android:padding="5dp">

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="10"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="3328"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="Samyak Gaikwad"

android:textSize="16sp"

android:layout_weight="1"/>

<TextView

android:layout_height="match_parent"

android:layout_width="wrap_content"

android:text="78.88%"

android:textSize="16sp"

android:layout_weight="1"/>

</TableRow>

</TableLayout>
2)

<?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="66dp"

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

android:textSize="25dp"

android:textStyle="bold" />

<TextView

android:id="@+id/pd"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="top|left|fill_vertical"

android:layout_marginTop="80dp"

android:text="Primitive"

android:textSize="20dp" />

<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:text="1) Integer" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="2) Float" />

<TextView

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

android:text="3) Characters" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="4) Boolean" />

</LinearLayout>

<TextView

android:layout_toRightOf="@+id/pd"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="right|fill_vertical"

android:layout_marginTop="80dp"

android:text="Non-Primitive"

android:textSize="20dp" />

<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:text="1) Class" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="2) Array" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="3) Interface" />


<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="4) Object" />

</LinearLayout>

</FrameLayout>

MainActivity.java

package com.example.practical62;

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

}}

Manifest.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.practical62">

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

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>
10 1)

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

<RelativeLayout

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

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

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

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Login"

android:textSize="50sp"

android:textStyle="bold"

android:textColor="@color/black"

android:layout_marginStart="150dp"

android:layout_marginTop="50dp” />

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginStart="20dp"

android:layout_marginEnd="20dp"

android:layout_marginTop="200dp"

android:hint="Enter your email"

android:inputType="textEmailAddress"/>

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginStart="20dp"

android:layout_marginEnd="20dp"

android:layout_marginTop="280dp"

android:hint="Enter your password"

android:inputType="textPassword"/>

<Button
android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Login"

android:textStyle="bold"

android:textSize="20dp"

android:layout_marginTop="400dp"

android:layout_marginStart="150dp"/>

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Prajwal Charthad"/>

</RelativeLayout>

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


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

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

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

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Student"

android:textSize="50sp"

android:textStyle="bold"

android:textColor="@color/black"

android:layout_marginStart="120dp"

android:layout_marginTop="50dp” />

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginStart="20dp"

android:layout_marginEnd="20dp"

android:layout_marginTop="200dp"
android:hint="Enter your name"

android:inputType="text"/>

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginStart="20dp"

android:layout_marginEnd="20dp"

android:layout_marginTop="280dp"

android:hint="Enter your email"

android:inputType="textEmailAddress"/>

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginStart="20dp"

android:layout_marginEnd="20dp"

android:layout_marginTop="360dp"

android:hint="Enter your Roll No."

android:inputType="number"/>

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginStart="20dp"

android:layout_marginEnd="20dp"

android:layout_marginTop="440dp"

android:hint="Enter your department"

android:inputType="text"/>

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginStart="20dp"

android:layout_marginEnd="20dp"

android:layout_marginTop="520dp"

android:hint="Enter your year"

android:inputType="text"/>

<Button
android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Register"

android:textStyle="bold"

android:textSize="20dp"

android:layout_marginTop="600dp"

android:layout_marginStart="150dp"/>

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Prajwal Charthad"/>

</RelativeLayout>
9) 1 <?xml version="1.0" encoding="utf-8"?>

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

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

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

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<TextView android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Bluetooth"

android:textSize="36sp"

android:layout_marginTop="250dp"

android:layout_marginStart="50dp"

android:textStyle="bold"/>

<ToggleButton android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="250dp"

android:layout_marginStart="250dp"/>

<TextView android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Prajwal Charthad"/>

</RelativeLayout>

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

<RelativeLayout

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

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

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

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<TextView android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Calculator:"

android:textSize="36sp"

android:layout_marginTop="30dp"

android:layout_marginStart="30dp"

android:textStyle="bold"/>

<TextView android:id="@+id/no1"
android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="1st No:"

android:paddingTop="5dp"

android:textSize="24sp"

android:layout_marginTop="150dp"/>

<EditText android:id="@+id/etxt1"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="150dp"

android:layout_toEndOf="@+id/no1"

android:hint="Enter First Number" />

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

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="2nd No:"

android:paddingTop="5dp"

android:textSize="24sp"

android:layout_marginTop="200dp"/>

<EditText android:id="@+id/etxt2"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="200dp"

android:layout_toEndOf="@+id/no2"

android:hint="Enter Second Number" />

<Button android:id="@+id/add"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Add"

android:layout_marginStart="50dp"/>

<Button android:id="@+id/sub"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Sub"

android:layout_marginStart="250dp"/>

<Button android:id="@+id/div"

android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="Div"

android:layout_marginStart="50dp"/>

<Button android:id="@+id/mul"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Mul"

android:layout_marginStart="250dp"/

<TextView android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Prajwal Charthad"/>

</RelativeLayout>

Java

import android.annotation.SuppressLint;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private Button add, sub, div, mul;

private EditText etxt1, etxt2;

@SuppressLint("MissingInflatedId")

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

add = findViewById(R.id.add);

sub = findViewById(R.id.sub);

div = findViewById(R.id.div);

mul = findViewById(R.id.mul);

etxt1 = findViewById(R.id.etxt1);

etxt2 = findViewById(R.id.etxt2);

add.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String value1 = etxt1.getText().toString();

String value2 = etxt2.getText().toString();


int num1 = Integer.parseInt(value1);

int num2 = Integer.parseInt(value2);

int Addition = num1 + num2;

Toast.makeText(MainActivity.this,"Addition: " + Addition,

Toast.LENGTH_SHORT).show(); } });

sub.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String value1 = etxt1.getText().toString();

String value2 = etxt2.getText().toString();

int num1 = Integer.parseInt(value1);

int num2 = Integer.parseInt(value2);

int Subtraction = num1 - num2;

Toast.makeText(MainActivity.this,"Subtraction: " + Subtraction,

Toast.LENGTH_SHORT).show(); } });

div.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String value1 = etxt1.getText().toString();

String value2 = etxt2.getText().toString();

int num1 = Integer.parseInt(value1);

int num2 = Integer.parseInt(value2);

int Division = num1 / num2;

Toast.makeText(MainActivity.this,"Division: " + Division,

Toast.LENGTH_SHORT).show(); } });

mul.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String value1 = etxt1.getText().toString();

String value2 = etxt2.getText().toString();

int num1 = Integer.parseInt(value1);

int num2 = Integer.parseInt(value2);

int Multiplication = num1 * num2;

Toast.makeText(MainActivity.this,"Multiplication: " + Multiplication,

Toast.LENGTH_SHORT).show(); }

); }

}
11) <?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">

<CheckBox

android:id="@+id/java"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Java"

android:textSize="25sp"

android:layout_marginTop="150dp"

android:layout_marginStart="150dp" />

<CheckBox

android:id="@+id/python"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Python"

android:textSize="25sp"

android:layout_marginTop="200dp"

android:layout_marginStart="150dp" />

<CheckBox

android:id="@+id/php"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="PHP"

android:textSize="25sp"

android:layout_marginTop="250dp"

android:layout_marginStart="150dp" />

<CheckBox

android:id="@+id/html"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="HTML"

android:textSize="25sp"
android:layout_marginTop="300dp"

android:layout_marginStart="150dp" />

<CheckBox

android:id="@+id/css"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="CSS"

android:textSize="25sp"

android:layout_marginTop="350dp"

android:layout_marginStart="150dp"/>

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Prajwal Charthad"/>

</RelativeLayout>

Java

MainActivity:

package com.example.mad;

import android.annotation.SuppressLint;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.CheckBox;

import android.widget.CompoundButton;

import android.widget.EditText;

import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private CheckBox java, python, php, html, css;

@SuppressLint("MissingInflatedId")

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

java = findViewById(R.id.java);

python = findViewById(R.id.python);

php = findViewById(R.id.php);
html = findViewById(R.id.html);

css = findViewById(R.id.css);

java.setOnCheckedChangeListener(new

CompoundButton.OnCheckedChangeListener() {

@Override

public void onCheckedChanged(CompoundButton buttonView, boolean

isChecked) {

if (isChecked) {

Toast.makeText(MainActivity.this, "Java",

Toast.LENGTH_SHORT).show(); }

});

php.setOnCheckedChangeListener(new

CompoundButton.OnCheckedChangeListener() {

@Override

public void onCheckedChanged(CompoundButton buttonView, boolean

isChecked) {

if (isChecked) {

Toast.makeText(MainActivity.this, "PHP",

Toast.LENGTH_SHORT).show();

});

python.setOnCheckedChangeListener(new

CompoundButton.OnCheckedChangeListener() {

@Override

public void onCheckedChanged(CompoundButton buttonView, boolean

isChecked) {

if (isChecked) {

Toast.makeText(MainActivity.this, "Python",

Toast.LENGTH_SHORT).show();

});

html.setOnCheckedChangeListener(new

CompoundButton.OnCheckedChangeListener() {

@Override

public void onCheckedChanged(CompoundButton buttonView, boolean


isChecked) {

if (isChecked) {

Toast.makeText(MainActivity.this, "HTML",

Toast.LENGTH_SHORT).show(); } }

});

css.setOnCheckedChangeListener(new

CompoundButton.OnCheckedChangeListener() {

@Override

public void onCheckedChanged(CompoundButton buttonView, boolean

isChecked) {

if (isChecked) {

Toast.makeText(MainActivity.this, "CSS",

Toast.LENGTH_SHORT).show(); } } });

}
12)

1) xml

<RelativeLayout

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

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

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

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Single Radio Buttons"

android:textSize="24sp"

android:layout_marginTop="20dp"

android:layout_marginStart="80dp"/>

<RadioButton

android:id="@+id/rb1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Radio Button 1"

android:textSize="20sp"

android:layout_marginTop="60dp"

android:layout_marginStart="20dp"/>

<RadioButton

android:id="@+id/rb2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Radio Button 2"

android:textSize="20sp"

android:layout_marginTop="100dp"

android:layout_marginStart="20dp"/>

<TextView

android:layout_width="match_parent"

android:layout_height="1dp"
android:background="@color/black"

android:layout_marginTop="150dp” />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Radio Button inside RadioGroup"

android:textSize="24sp"

android:layout_marginTop="160dp"

android:layout_marginStart="30dp"/>

<RadioGroup

android:id="@+id/rg"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="200dp"

android:layout_marginStart="20dp">

<RadioButton

android:id="@+id/male"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Male"

android:textSize="20sp"/>

<RadioButton

android:id="@+id/female"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Female"

android:textSize="20sp"/>

</RadioGroup>

<Button

android:id="@+id/btn"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="SHOW SELECTED"

android:textSize="20sp"

android:layout_marginTop="300dp"
android:layout_marginStart="100dp"/>

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Prajwal Charthad"/>

</RelativeLayout>

Java

import android.annotation.SuppressLint;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.RadioButton;

import android.widget.RadioGroup;

import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private RadioGroup radioGroup;

private RadioButton radioButton1, radioButton2;

private RadioButton radioButtonMale, radioButtonFemale;

private Button showSelectedButton;

@SuppressLint("MissingInflatedId")

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

radioGroup = findViewById(R.id.rg);

radioButton1 = findViewById(R.id.rb1);

radioButton2 = findViewById(R.id.rb2);

radioButtonMale = findViewById(R.id.male);

radioButtonFemale = findViewById(R.id.female);

showSelectedButton = findViewById(R.id.btn);

showSelectedButton.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {


int selectedRadioButtonId = radioGroup.getCheckedRadioButtonId();

if (selectedRadioButtonId != -1) {

RadioButton selectedRadioButton =

findViewById(selectedRadioButtonId);

String selectedText = selectedRadioButton.getText().toString();

Toast.makeText(MainActivity.this, "Selected: " + selectedText,

Toast.LENGTH_SHORT).show();

} else {

Toast.makeText(MainActivity.this, "No radio button selected",

Toast.LENGTH_SHORT).show(); }

});

}
13 1) <?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">

<ProgressBar
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="80dp"
android:layout_height="85dp"
android:layout_marginStart="160dp"
android:layout_marginTop="300dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Prajwal Charthad" />
</RelativeLayout>

2)
<?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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Download File"
android:layout_marginTop="300dp"
android:layout_marginStart="120dp"
android:id="@+id/btn"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Prajwal Charthad"/>

</RelativeLayout>

Java

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private Button button;
private ProgressDialog progressDialog;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.btn);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
progressDialog = new ProgressDialog(v.getContext());
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setProgress(0);
progressDialog.setMax(100);
progressDialog.setMessage("File Downloading...");
CountDownTimer countDownTimer = new
CountDownTimer(20000,1000) {
@Override
public void onTick(long millisUntilFinished) {
progressDialog.incrementProgressBy(5);
} @Override
public void onFinish() {
}
}.start();
progressDialog.show();
}
});
}
}
14)
1) activity_main:
<?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">
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>

list_item:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/txt_view"
android:textSize="18sp"
android:padding="10dp"/>

MainActivity:
package com.example.madpractical_atharva;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private ListView listView;
String Subjects[] =
{"Android","Java","PHP","Hadoop","Sap","Python","Ajax","C++","Ruby","Rails"
};
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = findViewById(R.id.list);
ArrayAdapter<String> arr;
arr = new
ArrayAdapter<String>(this,R.layout.list_item,R.id.txt_view,Subjects);
listView.setAdapter(arr);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
String selectedItem = Subjects[position];
Toast.makeText(MainActivity.this,selectedItem,Toast.LENGTH_SHORT).show();
}
});
}
2) Xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/Image1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"/>
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Image"
android:layout_marginTop="200dp"
android:layout_marginStart="150dp"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Prajwal Charthad" />
</RelativeLayout>

Java

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private ImageView imageView;
private Button button;
private boolean isImageDisplayed = true;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = findViewById(R.id.Image1);
button = findViewById(R.id.btn);
imageView.setImageResource(R.drawable.ic_launcher_background);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(isImageDisplayed){
imageView.setImageResource(R.drawable.ic_launcher_foreground);
}
else {
imageView.setImageResource(R.drawable.ic_launcher_foreground);
}
isImageDisplayed = !isImageDisplayed; }
});
}
}
3) activity_main:

<?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">
<GridView
android:id="@+id/GV"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:horizontalSpacing="6dp"
android:numColumns="2"
android:verticalSpacing="6dp" />
</RelativeLayout>

list_items:
<?xml version="1.0" encoding="utf-8"?>
<Button
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/txt_view"
android:textSize="18sp"
android:padding="10dp"/>

MainActivity:
package com.example.madpractical_atharva;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.GridView;
public class MainActivity extends AppCompatActivity {
private GridView gridView;
String items[] = {"Items 1","Items 2","Items 3","Items 4","Items 5","Items
6","Items 7","Items 8","Items 9","Items 10","Items 11","Items 12","Items
13","Items 14","Items 15"};
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
R.layout.list_item, items);
gridView = findViewById(R.id.GV);
gridView.setAdapter(adapter);
}
}
4]Program:

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

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

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Napoleon Bonaparte (born Napoleone di Buonaparte;[1][b]
15 August 1769 – 5 May 1821), later known by his regnal name Napoleon I,
was a French emperor and military commander who rose to prominence
during the French Revolution and led successful campaigns during the
Revolutionary Wars. He was the leader of the French Republic as First Consul
from 1799 to 1804, then of the French Empire as Emperor of the French from
1804 until 1814, and briefly again in 1815. His political and cultural legacy
endures as a celebrated and controversial leader. He initiated many enduring
reforms, but has been criticized for his authoritarian rule. He is considered one
of the greatest military commanders in history and his wars and campaigns are
still studied at military schools worldwide. However, historians still debate the
degree to which he was responsible for the Napoleonic Wars, in which
between three and six million people died."
android:textSize="30sp"/>

</ScrollView>

</RelativeLayout>
Pratical 15

1) xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World, Toast Example"
android:layout_marginTop="10dp"
android:layout_marginStart="20dp"/>
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Toast"
android:layout_marginTop="40dp"
android:layout_marginStart="20dp"
android:textSize="20dp"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Prajwal Charthad/>

</RelativeLayout>

Custom toast

<?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:background="#000"
android:padding="10dp"
android:id="@+id/custtoast"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Message for you:"
android:textSize="30sp"
android:textColor="#fff"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="You have got mail!"
android:textSize="20sp"
android:textColor="#fff"/>
</LinearLayout>

Java

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LayoutInflater li = getLayoutInflater();
View layout =
li.inflate(R.layout.layout,findViewById(R.id.custtoast));
Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.setGravity(Gravity.CENTER_HORIZONTAL |
Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
}
});
}
}
2)
<?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">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/pizza"
android:text="Pizza"
android:textSize="20sp"
android:layout_marginTop="100dp"
android:layout_marginStart="150dp"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/burger"
android:text="Burger"
android:textSize="20sp"
android:layout_marginTop="150dp"
android:layout_marginStart="150dp"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/coffee"
android:text="Coffee"
android:textSize="20sp"
android:layout_marginTop="200dp"
android:layout_marginStart="150dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn"
android:text="ORDER"
android:layout_marginTop="500dp"
android:layout_marginStart="150dp"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Prajwal Charthad" />

</RelativeLayout>
Java
package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
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 {
int total, pPrice=0, bPrice=0, cPrice=0;
boolean p=false, b=false, c=false;
String str = "Selected Items";
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final CheckBox pizza = findViewById(R.id.pizza);
final CheckBox burger = findViewById(R.id.burger);
final CheckBox coffee = findViewById(R.id.coffee);
Button btn = findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (pizza.isChecked()){
pPrice=100;
str += "\n Pizza : " +pPrice+" RS";
}
if (coffee.isChecked()){
cPrice=50;
str += "\n Coffee : "+cPrice+" RS";
}
if (burger.isChecked()){
bPrice=120;
str += "\n Burger : "+bPrice+" RS";
}
total = pPrice + bPrice + cPrice;
str += "\n\nTotal"+total;
pPrice = cPrice = bPrice = 0;
str += "\nSelected items: ";
Toast.makeText(getApplicationContext(),str,Toast.LENGTH_LONG).show();
}
});
16)
1)
<?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">
<TimePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TimePicker
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:timePickerMode="spinner"
android:layout_marginTop="400dp"/>
<TimePicker
android:id="@+id/timepicker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:timePickerMode="spinner"
android:layout_marginTop="550dp"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Prajwal Charthad" />

</RelativeLayout>

Java

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.TimePicker;
public class MainActivity extends AppCompatActivity {
TimePicker timePicker;

@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
timePicker = findViewById(R.id.timepicker);
timePicker.setIs24HourView(true);
}
}
18)
1) xml

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


<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText android:id="@+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:hint="Enter URL"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
/>
<Button
android:id="@+id/btnNavigate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Navigate"
android:layout_below="@+id/edittext"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Prajwal Charthad"/>
</RelativeLayout>

Java
package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
EditText editText;
Button btnNavigate;
String txt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnNavigate = findViewById(R.id.btnNavigate);
btnNavigate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
editText = findViewById(R.id.edittext);
txt=editText.getText().toString().trim();
if (txt.equals("www.youtube.com")){
go(); }
} });
}
private void go() {
Uri uri=Uri.parse("https://www.youtube.com");
Intent intent=new Intent(Intent.ACTION_VIEW,uri);
startActivity(intent); }
}

2) xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Open Dialer"
android:layout_centerHorizontal="true"
android:layout_marginTop="300dp"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Prajwal Charthad"/>
</RelativeLayout>

Java
package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
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.btn);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent((Intent.ACTION_DIAL));
startActivity(intent);
}
});
}
}

3) Activity_xml

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


<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:id="@+id/edittxt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="250dp"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"/>
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="400dp"
android:text="FACTORIAL"
android:layout_marginStart="150dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Prajwal Chathad"
android:textStyle="bold"
android:textSize="25dp"></TextView>

</RelativeLayout>

MainActivity .java

package com.example.myapplication;

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 editText1;
Button btn1;
int fact=1;
int num=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText1=findViewById(R.id.edittxt1);
btn1=findViewById(R.id.btn1);

btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
go();
}
});
}
private void go() {
num = Integer.parseInt(editText1.getText().toString().trim());
for (int i = 1 ; i <= num; i++){
fact = fact*i;
}
navigate();
}
private void navigate() {
Intent intent = new Intent(MainActivity.this, EmptyActivity.class);
intent.putExtra("Fact", fact);
intent.putExtra("Num", num);
startActivity(intent);
}
}

Activity_xml

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


<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".EmptyActivity">
<TextView
android:textSize="18sp"
android:textColor="@color/black"
android:id="@+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="250dp"
/>
<TextView
android:textSize="18sp"
android:textColor="@color/black"
android:id="@+id/txt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="350dp"
/>
</RelativeLayout>

EmptyActivity

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class EmptyActivity extends AppCompatActivity {
TextView textView1, textView2;
int num, fact;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_empty);
Intent intent = getIntent();
num = intent.getIntExtra("Num",0);
fact = intent.getIntExtra("Fact",0);
textView1 = findViewById(R.id.txt1);
textView2 = findViewById(R.id.txt2);
textView1.setText("Number="+num);
textView2.setText("Factorial="+fact);
}
}
19)
1) xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" tools:context=".MainActivity">
<EditText
android:id="@+id/editTextTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Title"
android:layout_margin="16dp" />
<EditText
android:id="@+id/editTextAuthor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Author"
android:layout_below="@id/editTextTitle"
android:layout_margin="16dp" />
<Button android:id="@+id/buttonInsert"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editTextAuthor"
android:layout_centerHorizontal="true"
android:text="Insert"
android:layout_marginTop="16dp" />
<ListView
android:id="@+id/listViewBooks"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/buttonInsert"
android:layout_marginTop="16dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Prajwal Chathad"
android:textSize="11dp"
android:gravity="bottom"></TextView>

</RelativeLayout>

Java

package com.example.myapplication;

import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
private EditText editTextTitle;
private EditText editTextAuthor;
private Button buttonInsert; private
ListView listViewBooks; private
ArrayAdapter<String> adapter;
private ArrayList<String> bookList;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextTitle = findViewById(R.id.editTextTitle);
editTextAuthor = findViewById(R.id.editTextAuthor);
buttonInsert = findViewById(R.id.buttonInsert);
listViewBooks = findViewById(R.id.listViewBooks);
buttonInsert.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {insertBook();
}
});
bookList = new ArrayList<>(); adapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, bookList); listViewBooks.setAdapter(adapter);
// Load books initially
loadBooks();
}
private void insertBook() {
String title = editTextTitle.getText().toString().trim();
String author = editTextAuthor.getText().toString().trim();
if (title.isEmpty() || author.isEmpty()) {
Toast.makeText(this, "Please enter both title and author",
Toast.LENGTH_SHORT).show();
return;
}
ContentValues values = new ContentValues();
values.put("title", title);
values.put("author", author);
Uri uri = Uri.parse("content://com.example.mad.provider/books");
Uri insertedUri = getContentResolver().insert(uri, values);
if (insertedUri != null) {
Toast.makeText(this, "Book inserted successfully", Toast.LENGTH_SHORT).show();
// Clear input fields after insertion
editTextTitle.getText().clear();
editTextAuthor.getText().clear();
// Reload books after insertion
loadBooks();
} else {
Toast.makeText(this, "Failed to insert book", Toast.LENGTH_SHORT).show(); }
}
private void loadBooks() {
bookList.clear();
Uri uri = Uri.parse("content://com.example.mad.provider/books");
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
do {
String title = cursor.getString(cursor.getColumnIndex("title"));
String author = cursor.getString(cursor.getColumnIndex("author"));
bookList.add(title + " by " + author); } while (cursor.moveToNext());
cursor.close();
}
adapter.notifyDataSetChanged();
}
}

Book provider
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
import com.example.myapplication.Book;
import java.util.ArrayList;
import java.util.List;
public class BookProvider extends ContentProvider {
private static final int BOOKS = 1;
private static final UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
private List<Book> books;
static {
uriMatcher.addURI("com.example.mad.provider", "books", BOOKS); }
@Override public boolean
onCreate() { books = new ArrayList<Book>();
return true; }
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
MatrixCursor cursor = new MatrixCursor(new String[]{"_id", "title", "author"});
switch (uriMatcher.match(uri)) {
case BOOKS:
for (Book book : books) { cursor.addRow(new Object[]{book.getId(), book.getTitle(), book.getAuthor()});
}
break;
default:
throw new IllegalArgumentException("Unsupported URI: " + uri);
}
return cursor;
}
@Override public String
getType(Uri uri) {
return null;
}
@Override public Uri insert(Uri uri,
ContentValues values) { switch
(uriMatcher.match(uri)) { case BOOKS:
String title = values.getAsString("title");
String author = values.getAsString("author");
long id = System.currentTimeMillis(); // Using current time as ID for simplicity Book; book = new Book(id, title,
author); books.add(book);
return Uri.withAppendedPath(uri, String.valueOf(id));
default:
throw new IllegalArgumentException("Unsupported URI: " + uri); }
}
@Override public int delete(Uri uri, String selection, String[]
selectionArgs)
{
throw new UnsupportedOperationException("Not yet implemented"); }
@Override public int update(Uri uri, ContentValues values, String selection, String[]
selectionArgs) { throw new UnsupportedOperationException("Not yet implemented");
}
}

Book
package com.example.myapplication;

public class Book {


private long id;
private String title;
private String author;

public Book(long id, String title, String author) {


this.id = id;
this.title = title;
this.author = author;
}

public long getId() {


return id;
} public String getTitle() {
return title;
}

public String getAuthor() {


return author; }
}

Book
package com.example.myapplication;

public class Book {


private long id;
private String title;
private String author;

public Book(long id, String title, String author) {


this.id = id;
this.title = title;
this.author = author;
}

public long getId() {


return id;
}

public String getTitle() {


return title;
}

public String getAuthor() {


return author; }
}

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">
<permission android:name=".BookProvider"
android:authorities="com.example.mad.provider"
android:exported="true" />

<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.MyApplication"
tools:targetApi="31">
<activity
android:name=".Book"
android:exported="false" />
<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>
20)
1) xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="150dp"
android:layout_marginTop="150dp"
android:text="Enable Wifi" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button1"
android:layout_marginTop="44dp"
android:text="Disable Wifi" />
</RelativeLayout>

2) java
package com.example.myapplication;

import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
Button enableButton,disableButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
enableButton=(Button)findViewById(R.id.button1);
disableButton=(Button)findViewById(R.id.button2);
enableButton.setOnClickListener(new OnClickListener(){
public void onClick(View v){
WifiManager wifi = (WifiManager)
getApplicationContext().getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(true);
}
});
disableButton.setOnClickListener(new OnClickListener(){
public void onClick(View v){
WifiManager wifi = (WifiManager)
getApplicationContext().getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(false);
}
});
}
}

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


<uses-permission android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.CHANGE_WIFI_STATE"/>
<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.MyApplication"
tools:targetApi="31">
<activity
android:name=".Book"
android:exported="false" />

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

21)
activity_main.xml:

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


<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
</RelativeLayout>

MainActivity.java:
package com.example.mad;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
AirplaneModeChangeReceiver airplaneModeChangeReceiver = new
AirplaneModeChangeReceiver();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onStart() {
super.onStart();
IntentFilter filter = new
IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
registerReceiver(airplaneModeChangeReceiver, filter);
}
@Override
protected void onStop() {
super.onStop();
unregisterReceiver(airplaneModeChangeReceiver);
}

AirplaneModeChangeReceiver.java:
package com.example.mad;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.widget.Toast;
public class AirplaneModeChangeReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
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();
}
}
private static boolean isAirplaneModeOn(Context context) {
return Settings.System.getInt(context.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
}
}
22)

1 ) activity_main.xml:

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

<RelativeLayout

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

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

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity" >

<TextView

android:id="@+id/textView"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:text="Shake to switch color" />

</RelativeLayout>

MainActivity.java:

package com.example.mad;

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

//overriding two methods of SensorEventListener

@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) //it will be executed if you shuffle

if (actualTime - lastUpdate < 200) {

return;

lastUpdate = actualTime;//updating lastUpdate for next shuffle

if (isColor) {

view.setBackgroundColor(Color.GREEN);

} else {

view.setBackgroundColor(Color.RED);

isColor = !isColor;
}

@Override

protected void onResume() {

super.onResume();

// register this class as a listener for the orientation and

// accelerometer sensors

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

TYPE_ACCELEROMETER),

SensorManager.SENSOR_DELAY_NORMAL);

@Override

protected void onPause() {

// unregister listener

super.onPause();

sensorManager.unregisterListener(this);

2]Program:

activity_main.xml:

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

<ScrollView

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

<!--Text View that shall display the sensor information list-->

<TextView

android:id="@+id/tv"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true" />

</ScrollView>

MainActivity.java:

package com.example.mad;

import android.content.Context;
import android.hardware.Sensor;

import android.hardware.SensorManager;

import android.os.Bundle;

import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import java.util.List;

public class MainActivity extends AppCompatActivity {

// Information about Sensors present in the

// device is supplied by Sensor Manager of the device

private SensorManager sensorManager;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// Initialize the variable sensorManager

sensorManager = (SensorManager)

getSystemService(Context.SENSOR_SERVICE);

// getSensorList(Sensor.TYPE_ALL) lists all the sensors present in the

device

List<Sensor> deviceSensors =

sensorManager.getSensorList(Sensor.TYPE_ALL);

// Text View that shall display this list

TextView textView = findViewById(R.id.tv);

// Converting List to String and displaying

// every sensor and its information on a new line

for (Sensor sensor : deviceSensors) {

textView.append(sensor.toString() + "\n\n");

You might also like