0% found this document useful (0 votes)
9 views60 pages

MAD Practical Codes

The document contains multiple XML layout files and Java activity classes for an Android application. It includes user interface elements such as TextViews, EditTexts, Buttons, and ProgressBars, along with their corresponding Java code to handle user interactions. The code demonstrates basic functionalities like displaying messages, handling button clicks, and updating progress bars.

Uploaded by

anushkajoshi7531
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views60 pages

MAD Practical Codes

The document contains multiple XML layout files and Java activity classes for an Android application. It includes user interface elements such as TextViews, EditTexts, Buttons, and ProgressBars, along with their corresponding Java code to handle user interactions. The code demonstrates basic functionalities like displaying messages, handling button clicks, and updating progress bars.

Uploaded by

anushkajoshi7531
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

​ .


2
​Activity_main.xml​
​<?xml version="1.0" encoding="utf-8"?>​
​<LinearLayout​
​xmlns:android="[Link]
​android:layout_width="match_parent"​
​android:layout_height="match_parent"​
​android:gravity="center"​
​android:orientation="vertical">​
​<TextView​
​android:id="@+id/textView"​
​android:layout_width="wrap_content"​
​android:layout_height="wrap_content"​
​android:text="Hello World"​
​android:textSize="24sp"/>​
​</LinearLayout>​

​ [Link]​
M
​package [Link];​
​import [Link];​
​import [Link];​
​public class MainActivity extends AppCompatActivity {​
​@Override​
​protected void onCreate(Bundle savedInstanceState) {​
​[Link](savedInstanceState);​
​setContentView([Link].activity_main);​
​}}​
​ .​
4 i​mport [Link];​
​Activity_main.xml​ ​import [Link];​
​<?xml version="1.0" encoding="utf-8"?>​ ​import [Link];​
​<[Link]​ ​import [Link];​
​xmlns:android="[Link] ​public class MainActivity extends AppCompatActivity {​
​xmlns:app="[Link] ​EditText editText;​
​android:layout_width="match_parent"​ ​@Override​
​android:layout_height="match_parent">​ ​protected void onCreate(Bundle savedInstanceState) {​
​<!-- TextView -->​ ​[Link](savedInstanceState);​
​<TextView​ ​setContentView([Link].activity_main);​
​android:id="@+id/textView"​ ​editText = findViewById([Link]);​
​android:layout_width="wrap_content"​ ​// When user presses Enter key​
​android:layout_height="wrap_content"​ ​[Link](new [Link]()​
​android:text="enter your name"​ ​{​
​android:textSize="20sp"​ ​@Override​
​app:layout_constraintTop_toTopOf="parent"​ ​public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {​
​app:layout_constraintBottom_toTopOf="@+id/editText"​ ​if (actionId == EditorInfo.IME_ACTION_DONE ||​
​app:layout_constraintStart_toStartOf="parent"​ ​(event != null && [Link]() == KeyEvent.KEYCODE_ENTER)) {​
​app:layout_constraintEnd_toEndOf="parent"​ ​String name = [Link]().toString();​
​app:layout_constraintVertical_bias="0.3"/>​ ​if ([Link]()) {​
​<!-- EditText -->​ ​[Link]([Link],​
​<EditText​ ​"Please enter your name",​
​android:id="@+id/editText"​ ​Toast.LENGTH_SHORT).show();​
​android:layout_width="250dp"​ ​} else {​
​android:layout_height="wrap_content"​ ​[Link]([Link],​
​android:hint="type name here"​ ​"Hello " + name,​
​android:inputType="text"​ ​Toast.LENGTH_SHORT).show();​
​app:layout_constraintTop_toBottomOf="@id/textView"​ ​}​
​app:layout_constraintStart_toStartOf="parent"​ ​return true;​
​app:layout_constraintEnd_toEndOf="parent"/>​ ​}​
​</[Link]>​ ​return false;​
​}​
​ [Link]​
M ​});​
​package [Link];​ ​}​
​import [Link];​ ​}​
​import [Link];​
​import [Link];​
​ ndroid:layout_width="wrap_content"​
a
​ .​
5 ​android:layout_height="wrap_content"​
​Activity_main.xml​ ​android:text="submit"​
​<?xml version="1.0" encoding="utf-8"?>​ ​app:layout_constraintTop_toBottomOf="@id/toggleButton"​
​<[Link]​ ​app:layout_constraintStart_toStartOf="parent"​
​xmlns:android="[Link] ​app:layout_constraintEnd_toEndOf="parent"​
​xmlns:app="[Link] ​app:layout_constraintVertical_bias="0.1"/>​
​android:layout_width="match_parent"​
​android:layout_height="match_parent">​ ​</[Link]>​

​ !-- Image Button -->​


<
​<ImageButton​ ​[Link]​
​android:id="@+id/imageButton"​
​android:layout_width="200dp"​ ​package [Link].a5thpractical;​
​android:layout_height="200dp"​
​android:src="@drawable/ic_launcher_background"​ i​mport [Link];​
​android:scaleType="centerCrop"​ ​import [Link];​
​app:layout_constraintTop_toTopOf="parent"​ ​import [Link];​
​app:layout_constraintBottom_toTopOf="@+id/toggleButton"​ ​import [Link];​
​app:layout_constraintStart_toStartOf="parent"​ ​import [Link];​
​app:layout_constraintEnd_toEndOf="parent"​ ​import [Link];​
​app:layout_constraintVertical_bias="0.2"/>​ ​import [Link];​

​ !-- Toggle Button -->​


< ​public class MainActivity extends AppCompatActivity {​
​<ToggleButton​
​android:id="@+id/toggleButton"​ I​mageButton imageButton;​
​android:layout_width="wrap_content"​ ​ToggleButton toggleButton;​
​android:layout_height="wrap_content"​ ​Button submitButton;​
​android:textOn="ON"​
​android:textOff="OFF"​ ​ Override​
@
​app:layout_constraintTop_toBottomOf="@id/imageButton"​ ​protected void onCreate(Bundle savedInstanceState) {​
​app:layout_constraintStart_toStartOf="parent"​ ​[Link](savedInstanceState);​
​app:layout_constraintEnd_toEndOf="parent"/>​ ​setContentView([Link].activity_main);​

​ !-- Submit Button -->​


< i​mageButton = findViewById([Link]);​
​<Button​ ​toggleButton = findViewById([Link]);​
​android:id="@+id/submitButton"​ ​submitButton = findViewById([Link]);​
​}​
/​/ Image Button Click​
​[Link](new [Link]() {​
​@Override​
​public void onClick(View v) {​
​[Link]([Link],​
​"Image Button Pressed",​
​Toast.LENGTH_SHORT).show();​
​}​
​});​

/​/ Toggle Button Click​


​[Link](new [Link]() {​
​@Override​
​public void onClick(View v) {​
​if ([Link]()) {​
​[Link]([Link],​
​"Toggle ON",​
​Toast.LENGTH_SHORT).show();​
​} else {​
​[Link]([Link],​
​"Toggle OFF",​
​Toast.LENGTH_SHORT).show();​
​}​
​}​
​});​

/​/ Submit Button Click​


​[Link](new [Link]() {​
​@Override​
​public void onClick(View v) {​
​[Link]([Link],​
​"Submitted Successfully",​
​Toast.LENGTH_SHORT).show();​
​}​
​});​
​}​
​ !-- Button -->​
<
​ .​
7 ​<Button​
​Activity_main.xml​ ​android:id="@+id/startButton"​
​android:layout_width="wrap_content"​
​ ?xml version="1.0" encoding="utf-8"?>​
< ​android:layout_height="wrap_content"​
​<[Link]​ ​android:text="start progress"​
​xmlns:android="[Link] ​app:layout_constraintTop_toBottomOf="@id/progressBar"​
​xmlns:app="[Link] ​app:layout_constraintStart_toStartOf="parent"​
​android:layout_width="match_parent"​ ​app:layout_constraintEnd_toEndOf="parent"​
​android:layout_height="match_parent">​ ​app:layout_constraintVertical_bias="0.2"/>​

​ !-- Title -->​


< ​</[Link]>​
​<TextView​
​android:id="@+id/textView"​ ​[Link]​
​android:layout_width="wrap_content"​
​android:layout_height="wrap_content"​ ​package [Link].practical7;​
​android:text="Progress Bar Demo"​
​android:textSize="22sp"​ i​mport [Link];​
​android:textStyle="bold"​ ​import [Link];​
​app:layout_constraintTop_toTopOf="parent"​ ​import [Link];​
​app:layout_constraintBottom_toTopOf="@+id/progressBar"​ ​import [Link];​
​app:layout_constraintStart_toStartOf="parent"​ ​import [Link];​
​app:layout_constraintEnd_toEndOf="parent"​ ​import [Link];​
​app:layout_constraintVertical_bias="0.2"/>​
​public class MainActivity extends AppCompatActivity {​
​ !-- Progress Bar -->​
<
​<ProgressBar​ ​ rogressBar progressBar;​
P
​android:id="@+id/progressBar"​ ​Button startButton;​
​style="?android:attr/progressBarStyleHorizontal"​ ​int progressStatus = 0;​
​android:layout_width="250dp"​ ​Handler handler = new Handler();​
​android:layout_height="wrap_content"​
​android:max="100"​ ​ Override​
@
​android:progress="0"​ ​protected void onCreate(Bundle savedInstanceState) {​
​app:layout_constraintTop_toBottomOf="@id/textView"​ ​[Link](savedInstanceState);​
​app:layout_constraintStart_toStartOf="parent"​ ​setContentView([Link].activity_main);​
​app:layout_constraintEnd_toEndOf="parent"/>​
​progressBar = findViewById([Link]);​
​startButton = findViewById([Link]);​

​[Link](new [Link]() {​
​@Override​
​public void onClick(View v) {​

​progressStatus = 0;​

​new Thread(new Runnable() {​


​@Override​
​public void run() {​

​while (progressStatus < 100) {​


​progressStatus += 5;​

​[Link](new Runnable() {​
​@Override​
​public void run() {​
​[Link](progressStatus);​
​}​
​});​

​try {​
​[Link](200);​
​} catch (InterruptedException e) {​
​[Link]();​
​}​
​}​
​}​
​}).start();​
​}​
​});​
​}​
​}​
​<EditText​
​ .​
8 ​android:id="@+id/password"​
​Activity_main.xml​ ​android:layout_width="250dp"​
​android:layout_height="wrap_content"​
​ ?xml version="1.0" encoding="utf-8"?>​
< ​android:hint="password"​
​<[Link]​ ​android:inputType="textPassword"​
​xmlns:android="[Link] ​app:layout_constraintTop_toBottomOf="@id/username"​
​xmlns:app="[Link] ​app:layout_constraintStart_toStartOf="parent"​
​android:layout_width="match_parent"​ ​app:layout_constraintEnd_toEndOf="parent"/>​
​android:layout_height="match_parent">​
​ !-- Remember Me -->​
<
​ !-- Title -->​
< ​<CheckBox​
​<TextView​ ​android:id="@+id/checkBox"​
​android:id="@+id/title"​ ​android:layout_width="wrap_content"​
​android:layout_width="wrap_content"​ ​android:layout_height="wrap_content"​
​android:layout_height="wrap_content"​ ​android:text="Remember me"​
​android:text="login"​ ​app:layout_constraintTop_toBottomOf="@id/password"​
​android:textSize="24sp"​ ​app:layout_constraintStart_toStartOf="@id/password"/>​
​android:textStyle="bold"​
​app:layout_constraintTop_toTopOf="parent"​ ​ !-- Login As Text -->​
<
​app:layout_constraintStart_toStartOf="parent"​ ​<TextView​
​app:layout_constraintEnd_toEndOf="parent"​ ​android:id="@+id/loginAs"​
​app:layout_constraintVertical_bias="0.1"/>​ ​android:layout_width="wrap_content"​
​android:layout_height="wrap_content"​
​ !-- Username -->​
< ​android:text="Login as"​
​<EditText​ ​app:layout_constraintTop_toBottomOf="@id/checkBox"​
​android:id="@+id/username"​ ​app:layout_constraintStart_toStartOf="@id/password"/>​
​android:layout_width="250dp"​
​android:layout_height="wrap_content"​ ​ !-- Radio Group -->​
<
​android:hint="username"​ ​<RadioGroup​
​android:inputType="text"​ ​android:id="@+id/radioGroup"​
​app:layout_constraintTop_toBottomOf="@id/title"​ ​android:layout_width="wrap_content"​
​app:layout_constraintStart_toStartOf="parent"​ ​android:layout_height="wrap_content"​
​app:layout_constraintEnd_toEndOf="parent"​ ​app:layout_constraintTop_toBottomOf="@id/loginAs"​
​app:layout_constraintVertical_bias="0.1"/>​ ​app:layout_constraintStart_toStartOf="@id/password">​

​<!-- Password -->​ ​<RadioButton​


​ ndroid:id="@+id/admin"​
a ​ ditText username, password;​
E
​android:layout_width="wrap_content"​ ​CheckBox checkBox;​
​android:layout_height="wrap_content"​ ​RadioGroup radioGroup;​
​android:text="admin"/>​ ​Button submit;​

​<RadioButton​ ​ Override​
@
​android:id="@+id/user"​ ​protected void onCreate(Bundle savedInstanceState) {​
​android:layout_width="wrap_content"​ ​[Link](savedInstanceState);​
​android:layout_height="wrap_content"​ ​setContentView([Link].activity_main);​
​android:text="user"/>​
​ /RadioGroup>​
< ​ sername = findViewById([Link]);​
u
​password = findViewById([Link]);​
​ !-- Submit Button -->​
< ​checkBox = findViewById([Link]);​
​<Button​ ​radioGroup = findViewById([Link]);​
​android:id="@+id/submit"​ ​submit = findViewById([Link]);​
​android:layout_width="wrap_content"​
​android:layout_height="wrap_content"​ ​[Link](new [Link]() {​
​android:text=""Submit"​ ​@Override​
​app:layout_constraintTop_toBottomOf="@id/radioGroup"​ ​public void onClick(View v) {​
​app:layout_constraintStart_toStartOf="parent"​
​app:layout_constraintEnd_toEndOf="parent"​ ​ tring user = [Link]().toString();​
S
​app:layout_constraintVertical_bias="0.2"/>​ ​String pass = [Link]().toString();​

​</[Link]>​ ​int selectedId = [Link]();​

​if ([Link]() || [Link]()) {​


​[Link]​ ​[Link]([Link],​
​"Please enter username and password",​
​package [Link];​ ​Toast.LENGTH_SHORT).show();​
​}​
i​mport [Link];​ ​else if (selectedId == -1) {​
​import [Link];​ ​[Link]([Link],​
​import [Link].*;​ ​"Please select login type",​
​import [Link];​ ​Toast.LENGTH_SHORT).show();​
​}​
​public class MainActivity extends AppCompatActivity {​ ​else {​
​RadioButton selectedRadio =​
​findViewById(selectedId);​

​String role = [Link]().toString();​

​String message = "Login Successful\n"​


​+ "User: " + user​
​+ "\nRole: " + role;​

​if ([Link]()) {​
​message += "\nRemembered";​
​}​

​[Link]([Link],​
​message,​
​Toast.LENGTH_LONG).show();​
​}​
}​ ​
​});​
​}​
​}​
​android:layout_marginBottom="15dp"/>​
​ .​
9
​Activity_main.xml​ ​ !-- Password -->​
<
​<EditText​
​ ?xml version="1.0" encoding="utf-8"?>​
< ​android:id="@+id/editPassword"​
​<LinearLayout​ ​android:layout_width="match_parent"​
​xmlns:android="[Link] ​android:layout_height="wrap_content"​
​android:layout_width="match_parent"​ ​android:hint="Enter Password"​
​android:layout_height="match_parent"​ ​android:inputType="textPassword"​
​android:orientation="vertical"​ ​android:layout_marginBottom="20dp"/>​
​android:padding="24dp"​
​android:gravity="center">​ ​ !-- Register Button -->​
<
​<Button​
​ !-- Title -->​
< ​android:id="@+id/registerBtn"​
​<TextView​ ​android:layout_width="match_parent"​
​android:layout_width="wrap_content"​ ​android:layout_height="wrap_content"​
​android:layout_height="wrap_content"​ ​android:text="Register"/>​
​android:text="Registration Form"​
​android:textSize="22sp"​ ​</LinearLayout>​
​android:textStyle="bold"​
​android:layout_marginBottom="20dp"/>​ ​[Link]​

​ !-- Name -->​


< ​package [Link];​
​<EditText​
​android:id="@+id/editName"​ i​mport [Link];​
​android:layout_width="match_parent"​ ​import [Link];​
​android:layout_height="wrap_content"​ ​import [Link].*;​
​android:hint="Enter Name"​ ​import [Link];​
​android:layout_marginBottom="15dp"/>​
​public class MainActivity extends AppCompatActivity {​
​ !-- Email -->​
<
​<EditText​ ​ ditText name, email, password;​
E
​android:id="@+id/editEmail"​ ​Button registerBtn;​
​android:layout_width="match_parent"​
​android:layout_height="wrap_content"​ ​ Override​
@
​android:hint="Enter Email"​ ​protected void onCreate(Bundle savedInstanceState) {​
​android:inputType="textEmailAddress"​ ​[Link](savedInstanceState);​
​setContentView([Link].activity_main);​

​ ame = findViewById([Link]);​
n
​email = findViewById([Link]);​
​password = findViewById([Link]);​
​registerBtn = findViewById([Link]);​

​[Link](new [Link]() {​
​@Override​
​public void onClick(View v) {​

​ tring userName = [Link]().toString();​


S
​String userEmail = [Link]().toString();​
​String userPassword = [Link]().toString();​

i​f ([Link]() || [Link]() ||​


​[Link]()) {​
​[Link]([Link],​
​"All fields are required",​
​Toast.LENGTH_SHORT).show();​
​}​
​else if ([Link]() < 6) {​
​[Link]([Link],​
​"Password must be at least 6 characters",​
​Toast.LENGTH_SHORT).show();​
​}​
​else {​
​[Link]([Link],​
​"Registration Successful",​
​Toast.LENGTH_LONG).show();​
​}​
​}​
​});​
​}​
​}​
​<TextView​
​ 0.​
1 ​android:text="Samsung"/>​
​Activity_main.xml​ ​ /TableRow>​
<
​<?xml version="1.0" encoding="utf-8"?>​
​<TableLayout​ ​ !-- Rating -->​
<
​xmlns:android="[Link] ​<TableRow>​
​android:layout_width="match_parent"​ ​<TextView​
​android:layout_height="match_parent"​ ​android:text="Rating:"​
​android:stretchColumns="1"​ ​android:textStyle="bold"/>​
​android:padding="20dp">​
​<TextView​
​ !-- Product Name -->​
< ​android:text="4.5 ★"/>​
​<TableRow>​ ​ /TableRow>​
<
​<TextView​
​android:text="Product Name:"​ ​ !-- Button Row -->​
<
​android:textStyle="bold"/>​ ​<TableRow>​
​<Button​
​<TextView​ ​android:id="@+id/addToCart"​
​android:text="Smartphone"/>​ ​android:layout_span="2"​
​ /TableRow>​
< ​android:text="Add to Cart"​
​android:layout_marginTop="20dp"/>​
​ !-- Price -->​
< ​</TableRow>​
​<TableRow>​
​<TextView​ ​</TableLayout>​
​android:text="Price:"​
​android:textStyle="bold"/>​ ​[Link]​

​<TextView​ ​package [Link].practical10;​


​android:text="$500"/>​
​ /TableRow>​
< i​mport [Link];​
​import [Link];​
​ !-- Brand -->​
< ​import [Link];​
​<TableRow>​ ​import [Link];​
​<TextView​ ​import [Link];​
​android:text="Brand:"​
​android:textStyle="bold"/>​ ​public class MainActivity extends AppCompatActivity {​
​Button addToCart;​ ​ !-- Offer Text -->​
<
​<TextView​
​ Override​
@ ​android:id="@+id/offerText"​
​protected void onCreate(Bundle savedInstanceState) {​ ​android:layout_width="120dp"​
​[Link](savedInstanceState);​ ​android:layout_height="40dp"​
​setContentView([Link].activity_main);​ ​android:layout_gravity="top|end"​
​android:layout_margin="10dp"​
​addToCart = findViewById([Link]);​ ​android:background="#FF0000"​
​android:gravity="center"​
​[Link](new [Link]() {​ ​android:text="30% OFF"​
​@Override​ ​android:textColor="#FFFFFF"​
​public void onClick(View v) {​ ​android:textStyle="bold"​
​[Link]([Link],​ ​android:textSize="16sp"/>​
​"Product Added to Cart",​
​Toast.LENGTH_SHORT).show();​ ​</FrameLayout>​
​}​
​});​
​}​ ​[Link]​
​}​
​package [Link];​
​Activity_main.xml​
i​mport [Link];​
​ ?xml version="1.0" encoding="utf-8"?>​
< ​import [Link];​
​<FrameLayout​
​xmlns:android="[Link] ​public class MainActivity extends AppCompatActivity {​
​android:id="@+id/main"​
​android:layout_width="match_parent"​ ​ Override​
@
​android:layout_height="match_parent">​ ​protected void onCreate(Bundle savedInstanceState) {​
​[Link](savedInstanceState);​
​ !-- Product Image -->​
< ​setContentView([Link].activity_main);​
​<ImageView​ ​}​
​android:id="@+id/productImage"​ ​}​
​android:layout_width="match_parent"​
​android:layout_height="250dp"​
​android:src="@drawable/abc"​ ​Activity_main.xml​
​android:scaleType="centerCrop" />​
​<?xml version="1.0" encoding="utf-8"?>​
​ RelativeLayout​
< ​<Button​
​xmlns:android="[Link] ​android:id="@+id/btnLogin"​
​android:id="@+id/main"​ ​android:layout_width="120dp"​
​android:layout_width="match_parent"​ ​android:layout_height="wrap_content"​
​android:layout_height="match_parent"​ ​android:text="Login"​
​android:padding="20dp">​ ​android:layout_below="@id/etPassword"​
​android:layout_marginTop="25dp"​
​ !-- Title -->​
< ​android:layout_centerHorizontal="true"/>​
​<TextView​
​android:id="@+id/tvTitle"​ ​</RelativeLayout>​
​android:layout_width="wrap_content"​
​android:layout_height="wrap_content"​ ​Main [Link]​
​android:text="Login Form"​
​android:textSize="22sp"​ ​package [Link];​
​android:textStyle="bold"​
​android:layout_centerHorizontal="true"/>​ i​mport [Link];​
​import [Link];​
​ !-- Username -->​
< ​import [Link];​
​<EditText​ ​import [Link];​
​android:id="@+id/etUsername"​ ​import [Link];​
​android:layout_width="match_parent"​ ​import [Link];​
​android:layout_height="wrap_content"​
​android:hint="Enter Username"​ ​public class MainActivity extends AppCompatActivity {​
​android:layout_below="@id/tvTitle"​
​android:layout_marginTop="20dp"/>​ ​ ditText etUsername, etPassword;​
E
​Button btnLogin;​
​ !-- Password -->​
<
​<EditText​ ​ Override​
@
​android:id="@+id/etPassword"​ ​protected void onCreate(Bundle savedInstanceState) {​
​android:layout_width="match_parent"​ ​[Link](savedInstanceState);​
​android:layout_height="wrap_content"​ ​setContentView([Link].activity_main);​
​android:hint="Enter Password"​
​android:inputType="textPassword"​ ​ tUsername = findViewById([Link]);​
e
​android:layout_below="@id/etUsername"​ ​etPassword = findViewById([Link]);​
​android:layout_marginTop="15dp"/>​ ​btnLogin = findViewById([Link]);​

​<!-- Login Button -->​ ​[Link](new [Link]() {​


​ Override​
@
​public void onClick(View v) {​

​ tring username = [Link]().toString();​


S
​String password = [Link]().toString();​

​if([Link]("admin") && [Link]("1234")) {​


​[Link]([Link],​
​"Login Successful",​
​Toast.LENGTH_SHORT).show();​
​} else {​
​[Link]([Link],​
​"Invalid Username or Password",​
​Toast.LENGTH_SHORT).show();​
​}​
}​ ​
​});​
​}​
​}​
​ 1.​
1 ​ ndroid:text="Available Books:"​
a
​Activity_main.xml​ ​android:textSize="18sp"​
​<?xml version="1.0" encoding="utf-8"?>​ ​android:textStyle="bold"​
​<ScrollView xmlns:android="[Link] ​android:paddingBottom="5dp"/>​
​android:layout_width="match_parent"​
​android:layout_height="match_parent">​ ​<ListView​
​android:id="@+id/listView"​
​<LinearLayout​ ​android:layout_width="match_parent"​
​android:layout_width="match_parent"​ ​android:layout_height="200dp"​
​android:layout_height="wrap_content"​ ​android:dividerHeight="2dp"/>​
​android:orientation="vertical"​
​android:padding="16dp">​ ​ !-- GridView -->​
<
​<TextView​
​ !-- Title -->​
< ​android:layout_width="wrap_content"​
​<TextView​ ​android:layout_height="wrap_content"​
​android:layout_width="match_parent"​ ​android:text="Book Covers:"​
​android:layout_height="wrap_content"​ ​android:textSize="18sp"​
​android:text="Library Management System"​ ​android:textStyle="bold"​
​android:textSize="22sp"​ ​android:paddingTop="15dp"​
​android:textStyle="bold"​ ​android:paddingBottom="5dp"/>​
​android:gravity="center"​
​android:paddingBottom="10dp"/>​ ​<GridView​
​android:id="@+id/gridView"​
​ !-- ImageView -->​
< ​android:layout_width="match_parent"​
​<ImageView​ ​android:layout_height="250dp"​
​android:id="@+id/libraryImage"​ ​android:numColumns="2"​
​android:layout_width="200dp"​ ​android:verticalSpacing="10dp"​
​android:layout_height="200dp"​ ​android:horizontalSpacing="10dp"​
​android:layout_gravity="center"​ ​android:gravity="center"/>​
​android:src="@drawable/book1"​
​android:scaleType="centerCrop"​ ​</LinearLayout>​
​android:layout_marginBottom="20dp"/>​
​</ScrollView>​
​ !-- ListView -->​
<
​<TextView​ ​ [Link]​
M
​android:layout_width="wrap_content"​ ​package [Link];​
​android:layout_height="wrap_content"​
i​mport [Link];​ ​ArrayAdapter<String> adapter = new ArrayAdapter<>(​
​import [Link];​ ​this,​
​import [Link];​ ​[Link].simple_list_item_1,​
​import [Link];​ ​books​
​import [Link];​ ​);​
​import [Link];​ ​[Link](adapter);​
​import [Link];​
​import [Link];​ /​/ GridView Implementation​
​GridView gridView = findViewById([Link]);​
​import [Link];​ ​[Link](new ImageAdapter());​
​}​
​public class MainActivity extends AppCompatActivity {​
/​/ GridView Adapter​
/​/ Book Names​ ​class ImageAdapter extends BaseAdapter {​
​String[] books = {​
​"Java Programming",​ ​ Override​
@
​"Android Development",​ ​public int getCount() {​
​"Data Structures",​ ​return [Link];​
​"Operating System",​ ​}​
​"Computer Networks"​
​};​ ​ Override​
@
​public Object getItem(int position) {​
/​/ Book Images (Add these images in drawable folder)​ ​return images[position];​
​int[] images = {​ ​}​
​[Link].book1,​
​[Link].book2,​ ​ Override​
@
​[Link].book3,​ ​public long getItemId(int position) {​
​[Link].book4​ ​return position;​
​};​ ​}​

​ Override​
@ ​ Override​
@
​protected void onCreate(Bundle savedInstanceState) {​ ​public View getView(int position, View convertView, ViewGroup​
​[Link](savedInstanceState);​ ​parent) {​
​setContentView([Link].activity_main);​
I​mageView imageView = new ImageView([Link]);​
/​/ ListView Implementation​ ​[Link](images[position]);​
​ListView listView = findViewById([Link]);​
​[Link](new [Link](300,​
​300));​
​[Link]([Link].CENTER_CROP);​

​return imageView;​
​}​
​}​
​}​
​ 2.​
1 ​ Button android:text="3"/>​
<
​Activity_main.xml​ ​<Button android:text="-"/>​
​<?xml version="1.0" encoding="utf-8"?>​
​<GridLayout xmlns:android="[Link] ​ !-- Row 4 -->​
<
​android:layout_width="match_parent"​ ​<Button android:text="0"/>​
​android:layout_height="match_parent"​ ​<Button android:text="C"/>​
​android:columnCount="4"​ ​<Button android:text="="/>​
​android:rowCount="6"​ ​<Button android:text="+"/>​
​android:padding="10dp">​
​</GridLayout>​
​ !-- Display Screen -->​
<
​<EditText​ ​ [Link]​
M
​android:id="@+id/display"​ ​package [Link];​
​android:layout_width="match_parent"​
​android:layout_height="80dp"​ i​mport [Link];​
​android:layout_columnSpan="4"​ ​import [Link];​
​android:gravity="end"​ ​import [Link];​
​android:textSize="28sp"​ ​import [Link];​
​android:background="@android:color/darker_gray"​
​android:enabled="false"​ ​import [Link];​
​android:padding="10dp"/>​
​public class MainActivity extends AppCompatActivity {​
​ !-- Row 1 -->​
<
​<Button android:text="7"/>​ ​ ditText display;​
E
​<Button android:text="8"/>​ ​String currentInput = "";​
​<Button android:text="9"/>​
​<Button android:text="/"/>​ ​ Override​
@
​protected void onCreate(Bundle savedInstanceState) {​
​ !-- Row 2 -->​
< ​[Link](savedInstanceState);​
​<Button android:text="4"/>​ ​setContentView([Link].activity_main);​
​<Button android:text="5"/>​
​<Button android:text="6"/>​ ​display = findViewById([Link]);​
​<Button android:text="*"/>​
/​/ Set Click Listener for All Buttons​
​ !-- Row 3 -->​
< ​for (int i = 0; i <​
​<Button android:text="1"/>​ ​((ViewGroup)findViewById([Link])).getChildCount(); i++) {​
​<Button android:text="2"/>​
​View view =​ }​ ​
​((ViewGroup)findViewById([Link])).getChildAt(i);​ ​else if ([Link]("=")) {​
​}​ ​try {​
​double result = evaluateExpression(currentInput);​
i​nt childCount =​ ​[Link]([Link](result));​
​((GridLayout)findViewById([Link]).getRootView()​ ​currentInput = [Link](result);​
​.findViewById([Link])).getChildCount();​ ​} catch (Exception e) {​
​[Link]("Error");​
/​/ Manual approach for clarity (recommended for practical)​ ​}​
​setButtonClickListeners();​ ​}​
​}​ ​else {​
​currentInput += value;​
​private void setButtonClickListeners() {​ ​[Link](currentInput);​
​}​
​int gridChildCount = (([Link])​ ​});​
​findViewById([Link])​ ​}​
​.getRootView()​ ​}​
​.findViewById([Link])).getChildCount();​ ​}​

​[Link] grid =​ /​/ Simple expression evaluator​


​([Link]) findViewById([Link])​ ​private double evaluateExpression(String input) {​
​.getRootView()​
​.findViewById([Link]);​ ​if ([Link]("+")) {​
​String[] parts = [Link]("\\+");​
​for (int i = 1; i < [Link](); i++) {​ ​return [Link](parts[0]) +​
​[Link](parts[1]);​
​View view = [Link](i);​ ​}​
​else if ([Link]("-")) {​
​if (view instanceof Button) {​ ​String[] parts = [Link]("\\-");​
​Button btn = (Button) view;​ ​return [Link](parts[0]) -​
​[Link](parts[1]);​
​[Link](v -> {​ ​}​
​String value = [Link]().toString();​ ​else if ([Link]("*")) {​
​String[] parts = [Link]("\\*");​
​if ([Link]("C")) {​ ​return [Link](parts[0]) *​
​currentInput = "";​ ​[Link](parts[1]);​
​[Link]("");​ ​}​
​else if ([Link]("/")) {​
​String[] parts = [Link]("\\/");​
​return [Link](parts[0]) /​
​[Link](parts[1]);​
​}​

​return 0;​
​}​
​}​
​ 3.​
1 ​ ndroid:orientation="vertical"​
a
​Activity_main.xml​ ​android:gravity="center"​
​<?xml version="1.0" encoding="utf-8"?>​ ​android:visibility="gone">​
​<FrameLayout​
​xmlns:android="[Link] ​<TextView​
​android:layout_width="match_parent"​ ​android:layout_width="wrap_content"​
​android:layout_height="match_parent">​ ​android:layout_height="wrap_content"​
​android:text="Welcome to the Application"​
​ !-- Splash Layout -->​
< ​android:textSize="22sp"​
​<LinearLayout​ ​android:textStyle="bold"/>​
​android:id="@+id/splashLayout"​
​android:layout_width="match_parent"​ ​</LinearLayout>​
​android:layout_height="match_parent"​
​android:orientation="vertical"​ ​</FrameLayout>​
​android:gravity="center"​
​android:background="#3F51B5">​ ​ [Link]​
M
​package [Link];​
​<ImageView​
​android:layout_width="150dp"​ i​mport [Link];​
​android:layout_height="150dp"​ ​import [Link];​
​android:src="@drawable/ic_launcher_foreground"​ ​import [Link];​
​android:layout_marginBottom="20dp"/>​ ​import [Link];​
​import [Link];​
​<TextView​
​android:layout_width="wrap_content"​ ​import [Link];​
​android:layout_height="wrap_content"​
​android:text="Library Management App"​ ​public class MainActivity extends AppCompatActivity {​
​android:textSize="22sp"​
​android:textColor="#FFFFFF"​ ​private static final int SPLASH_TIME = 3000; // 3 seconds​
​android:textStyle="bold"/>​
​ /LinearLayout>​
< ​ Override​
@
​protected void onCreate(Bundle savedInstanceState) {​
​ !-- Main Content Layout (Initially Hidden) -->​
< ​[Link](savedInstanceState);​
​<LinearLayout​ ​setContentView([Link].activity_main);​
​android:id="@+id/mainLayout"​
​android:layout_width="match_parent"​ ​ inearLayout splashLayout = findViewById([Link]);​
L
​android:layout_height="match_parent"​ ​LinearLayout mainLayout = findViewById([Link]);​
/​/ Delay for splash screen​
​new Handler([Link]()).postDelayed(() -> {​

​ [Link]([Link]);​
s
​[Link]([Link]);​

​}, SPLASH_TIME);​
​}​
​}​
​ 4.​
1 ​ ndroid:layout_height="wrap_content"​
a
​Activity_main.xml​ ​android:text="Fahrenheit to Celsius"​
​<?xml version="1.0" encoding="utf-8"?>​ ​android:layout_marginBottom="15dp"/>​
​<LinearLayout​
​xmlns:android="[Link] ​<TextView​
​android:layout_width="match_parent"​ ​android:id="@+id/resultText"​
​android:layout_height="match_parent"​ ​android:layout_width="wrap_content"​
​android:orientation="vertical"​ ​android:layout_height="wrap_content"​
​android:padding="20dp"​ ​android:text="Result:"​
​android:gravity="center">​ ​android:textSize="18sp"​
​android:textStyle="bold"/>​
​<TextView​
​android:layout_width="wrap_content"​ ​</LinearLayout>​
​android:layout_height="wrap_content"​
​android:text="Temperature Converter"​ ​ [Link]​
M
​android:textSize="22sp"​ ​package [Link];​
​android:textStyle="bold"​
​android:layout_marginBottom="20dp"/>​ i​mport [Link];​
​import [Link];​
​<EditText​ ​import [Link];​
​android:id="@+id/inputTemp"​ ​import [Link];​
​android:layout_width="match_parent"​ ​import [Link];​
​android:layout_height="wrap_content"​ ​import [Link];​
​android:hint="Enter Temperature"​
​android:inputType="numberDecimal"​ ​import [Link];​
​android:layout_marginBottom="15dp"/>​
​public class MainActivity extends AppCompatActivity {​
​<Button​
​android:id="@+id/btnCtoF"​ ​ ditText inputTemp;​
E
​android:layout_width="match_parent"​ ​Button btnCtoF, btnFtoC;​
​android:layout_height="wrap_content"​ ​TextView resultText;​
​android:text="Celsius to Fahrenheit"​
​android:layout_marginBottom="10dp"/>​ ​ Override​
@
​protected void onCreate(Bundle savedInstanceState) {​
​<Button​ ​[Link](savedInstanceState);​
​android:id="@+id/btnFtoC"​ ​setContentView([Link].activity_main);​
​android:layout_width="match_parent"​
i​nputTemp = findViewById([Link]);​
​btnCtoF = findViewById([Link]);​ ​[Link]("Result: " + celsius + " °C");​
​btnFtoC = findViewById([Link]);​ ​}​
​resultText = findViewById([Link]);​ ​}​

​ [Link](v -> convertCtoF());​


b
​[Link](v -> convertFtoC());​
​}​

​private void convertCtoF() {​

​String value = [Link]().toString();​

​if ([Link]()) {​
​[Link](this, "Please enter temperature",​
​Toast.LENGTH_SHORT).show();​
​return;​
​}​

​ ouble celsius = [Link](value);​


d
​double fahrenheit = (celsius * 9/5) + 32;​

​[Link]("Result: " + fahrenheit + " °F");​


​}​

​private void convertFtoC() {​

​String value = [Link]().toString();​

​if ([Link]()) {​
​[Link](this, "Please enter temperature",​
​Toast.LENGTH_SHORT).show();​
​return;​
​}​

​ ouble fahrenheit = [Link](value);​


d
​double celsius = (fahrenheit - 32) * 5/9;​
​ 5.​
1 ​ ndroid:id="@+id/btnStart"​
a
​Activity_main.xml​ ​android:layout_width="match_parent"​
​<?xml version="1.0" encoding="utf-8"?>​ ​android:layout_height="wrap_content"​
​<LinearLayout​ ​android:text="Start Timer"​
​xmlns:android="[Link] ​android:layout_marginBottom="10dp"/>​
​android:layout_width="match_parent"​
​android:layout_height="match_parent"​ ​<Button​
​android:orientation="vertical"​ ​android:id="@+id/btnReset"​
​android:gravity="center"​ ​android:layout_width="match_parent"​
​android:padding="20dp">​ ​android:layout_height="wrap_content"​
​android:text="Reset Timer"/>​
​<TextView​
​android:layout_width="wrap_content"​ ​</LinearLayout>​
​android:layout_height="wrap_content"​
​android:text="Countdown Timer"​ ​ [Link]​
M
​android:textSize="24sp"​ ​package [Link];​
​android:textStyle="bold"​
​android:layout_marginBottom="20dp"/>​ i​mport [Link];​
​import [Link];​
​<EditText​ ​import [Link];​
​android:id="@+id/inputSeconds"​ ​import [Link];​
​android:layout_width="match_parent"​ ​import [Link];​
​android:layout_height="wrap_content"​ ​import [Link];​
​android:hint="Enter time in seconds"​
​android:inputType="number"​ ​import [Link];​
​android:layout_marginBottom="20dp"/>​
​public class MainActivity extends AppCompatActivity {​
​<TextView​
​android:id="@+id/timerText"​ ​ ditText inputSeconds;​
E
​android:layout_width="wrap_content"​ ​TextView timerText;​
​android:layout_height="wrap_content"​ ​Button btnStart, btnReset;​
​android:text="00"​
​android:textSize="40sp"​ ​ ountDownTimer countDownTimer;​
C
​android:textStyle="bold"​ ​long timeLeftInMillis;​
​android:layout_marginBottom="20dp"/>​
​ Override​
@
​<Button​ ​protected void onCreate(Bundle savedInstanceState) {​
​ [Link](savedInstanceState);​
s ​}​
​setContentView([Link].activity_main);​
​private void resetTimer() {​
i​nputSeconds = findViewById([Link]);​
​timerText = findViewById([Link]);​ ​if (countDownTimer != null) {​
​btnStart = findViewById([Link]);​ ​[Link]();​
​btnReset = findViewById([Link]);​ ​}​

​ [Link](v -> startTimer());​


b t​[Link]("00");​
​[Link](v -> resetTimer());​ ​[Link]("");​
​}​ ​}​
​}​
​private void startTimer() {​

​String value = [Link]().toString();​

​if ([Link]()) {​
​[Link](this, "Enter time in seconds",​
​Toast.LENGTH_SHORT).show();​
​return;​
​}​

​timeLeftInMillis = [Link](value) * 1000;​

​countDownTimer = new CountDownTimer(timeLeftInMillis, 1000) {​

​ Override​
@
​public void onTick(long millisUntilFinished) {​
​long secondsRemaining = millisUntilFinished / 1000;​
​[Link]([Link](secondsRemaining));​
​}​

​ Override​
@
​public void onFinish() {​
​[Link]("Done!");​
​}​
​}.start();​
​ 6.​
1 ​ [Link]​
M
​Activity_main.xml​ ​package [Link];​
​<?xml version="1.0" encoding="utf-8"?>​
​<LinearLayout​ i​mport [Link];​
​xmlns:android="[Link] ​import [Link];​
​android:layout_width="match_parent"​ ​import [Link];​
​android:layout_height="match_parent"​ ​import [Link];​
​android:orientation="vertical"​
​android:gravity="center"​ ​import [Link];​
​android:padding="20dp">​
​import [Link];​
​<TextView​
​android:layout_width="wrap_content"​ ​public class MainActivity extends AppCompatActivity {​
​android:layout_height="wrap_content"​
​android:text="Date Picker Application"​ ​ ditText editTextDate;​
E
​android:textSize="22sp"​ ​Button btnPickDate;​
​android:textStyle="bold"​
​android:layout_marginBottom="20dp"/>​ ​ Override​
@
​protected void onCreate(Bundle savedInstanceState) {​
​<EditText​ ​[Link](savedInstanceState);​
​android:id="@+id/editTextDate"​ ​setContentView([Link].activity_main);​
​android:layout_width="match_parent"​
​android:layout_height="wrap_content"​ ​ ditTextDate = findViewById([Link]);​
e
​android:hint="Select Date"​ ​btnPickDate = findViewById([Link]);​
​android:focusable="false"​
​android:clickable="true"​ ​[Link](v -> showDatePicker());​
​android:layout_marginBottom="20dp"/>​
/​/ Also open picker when EditText is clicked​
​<Button​ ​[Link](v -> showDatePicker());​
​android:id="@+id/btnPickDate"​ ​}​
​android:layout_width="match_parent"​
​android:layout_height="wrap_content"​ ​private void showDatePicker() {​
​android:text="Pick Date"/>​
​Calendar calendar = [Link]();​
​</LinearLayout>​
i​nt year = [Link]([Link]);​
​int month = [Link]([Link]);​
​int day = [Link](Calendar.DAY_OF_MONTH);​

​DatePickerDialog datePickerDialog = new DatePickerDialog(​


​this,​
​(view, selectedYear, selectedMonth, selectedDay) -> {​

/​/ Month starts from 0, so add 1​


​String date = selectedDay + "/" + (selectedMonth + 1) + "/" +​
​selectedYear;​
​[Link](date);​
​},​
​year, month, day​
​);​

​[Link]();​
​}​
​}​
​ 7.​
1 ​ [Link]​
M
​Activity_main.xml​ ​package [Link];​
​<?xml version="1.0" encoding="utf-8"?>​
​<LinearLayout​ i​mport [Link];​
​xmlns:android="[Link] ​import [Link];​
​android:layout_width="match_parent"​ ​import [Link];​
​android:layout_height="match_parent"​ ​import [Link];​
​android:orientation="vertical"​
​android:gravity="center"​ ​import [Link];​
​android:padding="20dp">​
​import [Link];​
​<TextView​
​android:layout_width="wrap_content"​ ​public class MainActivity extends AppCompatActivity {​
​android:layout_height="wrap_content"​
​android:text="Time Picker Application"​ ​ ditText editTextTime;​
E
​android:textSize="22sp"​ ​Button btnPickTime;​
​android:textStyle="bold"​
​android:layout_marginBottom="20dp"/>​ ​ Override​
@
​protected void onCreate(Bundle savedInstanceState) {​
​<EditText​ ​[Link](savedInstanceState);​
​android:id="@+id/editTextTime"​ ​setContentView([Link].activity_main);​
​android:layout_width="match_parent"​
​android:layout_height="wrap_content"​ ​ ditTextTime = findViewById([Link]);​
e
​android:hint="Select Time"​ ​btnPickTime = findViewById([Link]);​
​android:focusable="false"​
​android:clickable="true"​ ​ [Link](v -> showTimePicker());​
b
​android:layout_marginBottom="20dp"/>​ ​[Link](v -> showTimePicker());​
​}​
​<Button​
​android:id="@+id/btnPickTime"​ ​private void showTimePicker() {​
​android:layout_width="match_parent"​
​android:layout_height="wrap_content"​ ​Calendar calendar = [Link]();​
​android:text="Pick Time"/>​
i​nt hour = [Link](Calendar.HOUR_OF_DAY);​
​</LinearLayout>​ ​int minute = [Link]([Link]);​

​TimePickerDialog timePickerDialog = new TimePickerDialog(​


t​his,​
​(view, selectedHour, selectedMinute) -> {​

​String formattedTime = selectedHour + ":" +​


​(selectedMinute < 10 ? "0" + selectedMinute :​
​selectedMinute);​

​[Link](formattedTime);​
}​ ,​
​hour,​
​minute,​
​true // true = 24-hour format​
​);​

​[Link]();​
​}​
​}​
​ 8.​
1 ​ ndroid:layout_height="wrap_content"​
a
​Activity_main.xml​ ​android:text="Login"/>​
​<?xml version="1.0" encoding="utf-8"?>​
​<LinearLayout​ ​</LinearLayout>​
​xmlns:android="[Link]
​android:layout_width="match_parent"​ ​ [Link]​
M
​android:layout_height="match_parent"​ ​package [Link];​
​android:orientation="vertical"​
​android:gravity="center"​ i​mport [Link];​
​android:padding="20dp">​ ​import [Link];​
​import [Link];​
​<TextView​ ​import [Link];​
​android:layout_width="wrap_content"​ ​import [Link];​
​android:layout_height="wrap_content"​ ​import [Link];​
​android:text="Login Application"​
​android:textSize="22sp"​ ​import [Link];​
​android:textStyle="bold"​
​android:layout_marginBottom="20dp"/>​ /​* ---------------------- */​
​/* Activity 1 : Login */​
​<EditText​ ​/* ---------------------- */​
​android:id="@+id/username"​ ​public class MainActivity extends AppCompatActivity {​
​android:layout_width="match_parent"​
​android:layout_height="wrap_content"​ ​ ditText username, password;​
E
​android:hint="Enter Username"​ ​Button btnLogin;​
​android:layout_marginBottom="15dp"/>​
​ Override​
@
​<EditText​ ​protected void onCreate(Bundle savedInstanceState) {​
​android:id="@+id/password"​ ​[Link](savedInstanceState);​
​android:layout_width="match_parent"​ ​setContentView([Link].activity_main);​
​android:layout_height="wrap_content"​
​android:hint="Enter Password"​ ​ sername = findViewById([Link]);​
u
​android:inputType="textPassword"​ ​password = findViewById([Link]);​
​android:layout_marginBottom="20dp"/>​ ​btnLogin = findViewById([Link]);​

​<Button​ ​[Link](v -> {​


​android:id="@+id/btnLogin"​
​android:layout_width="match_parent"​ ​String user = [Link]().toString();​
​String pass = [Link]().toString();​

/​/ Simple validation​


​if ([Link]("admin") && [Link]("1234")) {​

I​ntent intent = new Intent([Link], [Link]);​


​[Link]("USERNAME", user);​
​startActivity(intent);​

​} else {​
​[Link](this, "Invalid Credentials",​
​Toast.LENGTH_SHORT).show();​
​}​
​});​
​}​
​}​

/​* ---------------------- */​


​/* Activity 2 : Welcome */​
​/* ---------------------- */​
​class SecondActivity extends AppCompatActivity {​

​ Override​
@
​protected void onCreate(Bundle savedInstanceState) {​
​[Link](savedInstanceState);​

​ extView textView = new TextView(this);​


T
​[Link](22);​
​[Link](50, 200, 50, 50);​

​ tring user = getIntent().getStringExtra("USERNAME");​


S
​[Link]("Welcome " + user);​

​setContentView(textView);​
​}​
​}​
​ 9.​
1 ​ [Link]​
M
​Activity_main.xml​ ​package [Link];​
​<?xml version="1.0" encoding="utf-8"?>​
​<LinearLayout​ i​mport [Link];​
​xmlns:android="[Link] ​import [Link];​
​android:layout_width="match_parent"​ ​import [Link];​
​android:layout_height="match_parent"​ ​import [Link];​
​android:orientation="vertical"​ ​import [Link];​
​android:gravity="center"​
​android:padding="20dp">​ ​import [Link];​

​<TextView​ /​* ----------------------------- */​


​android:layout_width="wrap_content"​ ​/* Activity 1 : Main Activity */​
​android:layout_height="wrap_content"​ ​/* ----------------------------- */​
​android:text="Intent Demonstration"​ ​public class MainActivity extends AppCompatActivity {​
​android:textSize="22sp"​
​android:textStyle="bold"​ ​Button btnExplicit, btnImplicit;​
​android:layout_marginBottom="30dp"/>​
​ Override​
@
​<Button​ ​protected void onCreate(Bundle savedInstanceState) {​
​android:id="@+id/btnExplicit"​ ​[Link](savedInstanceState);​
​android:layout_width="match_parent"​ ​setContentView([Link].activity_main);​
​android:layout_height="wrap_content"​
​android:text="Open Second Activity (Explicit Intent)"​ ​ tnExplicit = findViewById([Link]);​
b
​android:layout_marginBottom="20dp"/>​ ​btnImplicit = findViewById([Link]);​

​<Button​ /​/ Explicit Intent​


​android:id="@+id/btnImplicit"​ ​[Link](v -> {​
​android:layout_width="match_parent"​ ​Intent intent = new Intent([Link], [Link]);​
​android:layout_height="wrap_content"​ ​startActivity(intent);​
​android:text="Open Website (Implicit Intent)"/>​ ​});​

​</LinearLayout>​ /​/ Implicit Intent (Open Website)​


​[Link](v -> {​
​Intent intent = new Intent(Intent.ACTION_VIEW);​
​[Link]([Link]("[Link]
​startActivity(intent);​
​});​
​}​
​}​

/​* ----------------------------- */​


​/* Activity 2 : Second Activity */​
​/* ----------------------------- */​
​class SecondActivity extends AppCompatActivity {​

​ Override​
@
​protected void onCreate(Bundle savedInstanceState) {​
​[Link](savedInstanceState);​

​ extView textView = new TextView(this);​


T
​[Link](22);​
​[Link](50, 200, 50, 50);​
​[Link]("This is Second Activity\nOpened using Explicit​
​Intent");​

​setContentView(textView);​
​}​
​}​
​ 0.​
2 ​android:text="Turn OFF Bluetooth"/>​
​Activity_main.xml​
​<?xml version="1.0" encoding="utf-8"?>​ ​</LinearLayout>​
​<LinearLayout​
​xmlns:android="[Link] ​ [Link]​
M
​android:layout_width="match_parent"​ ​package [Link];​
​android:layout_height="match_parent"​
​android:orientation="vertical"​ i​mport [Link];​
​android:gravity="center"​ ​import [Link];​
​android:padding="20dp">​ ​import [Link];​
​import [Link];​
​<TextView​ ​import [Link];​
​android:layout_width="wrap_content"​
​android:layout_height="wrap_content"​ ​import [Link];​
​android:text="Bluetooth Service Application"​
​android:textSize="22sp"​ ​public class MainActivity extends AppCompatActivity {​
​android:textStyle="bold"​
​android:layout_marginBottom="30dp"/>​ ​ luetoothAdapter bluetoothAdapter;​
B
​Button btnStatus, btnOn, btnOff;​
​<Button​
​android:id="@+id/btnStatus"​ ​ Override​
@
​android:layout_width="match_parent"​ ​protected void onCreate(Bundle savedInstanceState) {​
​android:layout_height="wrap_content"​ ​[Link](savedInstanceState);​
​android:text="Check Bluetooth Status"​ ​setContentView([Link].activity_main);​
​android:layout_marginBottom="15dp"/>​
​bluetoothAdapter = [Link]();​
​<Button​
​android:id="@+id/btnOn"​ ​ tnStatus = findViewById([Link]);​
b
​android:layout_width="match_parent"​ ​btnOn = findViewById([Link]);​
​android:layout_height="wrap_content"​ ​btnOff = findViewById([Link]);​
​android:text="Turn ON Bluetooth"​
​android:layout_marginBottom="15dp"/>​ ​ [Link](v -> checkStatus());​
b
​[Link](v -> turnOnBluetooth());​
​<Button​ ​[Link](v -> turnOffBluetooth());​
​android:id="@+id/btnOff"​ ​}​
​android:layout_width="match_parent"​
​android:layout_height="wrap_content"​ ​private void checkStatus() {​
​[Link](this, "Bluetooth turned OFF",​
​if (bluetoothAdapter == null) {​ ​Toast.LENGTH_SHORT).show();​
​[Link](this, "Bluetooth not supported",​ ​} else {​
​Toast.LENGTH_SHORT).show();​ ​[Link](this, "Bluetooth already OFF",​
​}​ ​Toast.LENGTH_SHORT).show();​
​else if ([Link]()) {​ ​}​
​[Link](this, "Bluetooth is ON",​ ​}​
​Toast.LENGTH_SHORT).show();​ ​}​
​}​
​else {​
​[Link](this, "Bluetooth is OFF",​
​Toast.LENGTH_SHORT).show();​
​}​
​}​

​private void turnOnBluetooth() {​

​if (bluetoothAdapter == null) {​


​[Link](this, "Bluetooth not supported",​
​Toast.LENGTH_SHORT).show();​
​return;​
​}​

​if (![Link]()) {​
​Intent intent = new​
​Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);​
​startActivity(intent);​
​} else {​
​[Link](this, "Bluetooth already ON",​
​Toast.LENGTH_SHORT).show();​
​}​
​}​

​private void turnOffBluetooth() {​

​if (bluetoothAdapter != null && [Link]()) {​


​[Link]();​
​ 1.​
2 ​ extView txtStatus;​
T
​Activity_main.xml​ ​ModeReceiver modeReceiver;​
​<?xml version="1.0" encoding="utf-8"?>​
​<LinearLayout​ ​ Override​
@
​xmlns:android="[Link] ​protected void onCreate(Bundle savedInstanceState) {​
​android:layout_width="match_parent"​ ​[Link](savedInstanceState);​
​android:layout_height="match_parent"​ ​setContentView([Link].activity_main);​
​android:gravity="center"​
​android:orientation="vertical"​ ​txtStatus = findViewById([Link]);​
​android:padding="20dp">​
​modeReceiver = new ModeReceiver();​
​<TextView​ ​}​
​android:id="@+id/txtStatus"​
​android:layout_width="wrap_content"​ ​ Override​
@
​android:layout_height="wrap_content"​ ​protected void onResume() {​
​android:text="Current Mode Status"​ ​[Link]();​
​android:textSize="20sp"​
​android:textStyle="bold" />​ I​ntentFilter filter = new IntentFilter();​
​[Link](Intent.ACTION_AIRPLANE_MODE_CHANGED);​
​</LinearLayout>​
​[Link](AudioManager.RINGER_MODE_CHANGED_ACTION);​
​ [Link]​
M
​package [Link];​ ​registerReceiver(modeReceiver, filter);​
​}​
i​mport [Link];​
​import [Link];​ ​ Override​
@
​import [Link];​ ​protected void onPause() {​
​import [Link];​ ​[Link]();​
​import [Link];​ ​unregisterReceiver(modeReceiver);​
​import [Link];​ ​}​
​import [Link];​
​import [Link];​ /​/ Broadcast Receiver Class​
​public class ModeReceiver extends BroadcastReceiver {​
​import [Link];​
​ Override​
@
​public class MainActivity extends AppCompatActivity {​ ​public void onReceive(Context context, Intent intent) {​
​if​
(​ Intent.ACTION_AIRPLANE_MODE_CHANGED.equals([Link]()))​
​{​

​boolean isOn = [Link]("state", false);​

​if (isOn) {​
​[Link]("Airplane Mode ON");​
​} else {​
​[Link]("Airplane Mode OFF");​
​}​
​}​

i​f​
​(AudioManager.RINGER_MODE_CHANGED_ACTION.equals([Link]​
​tion())) {​

​AudioManager audioManager =​
​(AudioManager)​
​getSystemService(Context.AUDIO_SERVICE);​

​int mode = [Link]();​

​if (mode == AudioManager.RINGER_MODE_SILENT) {​


​[Link]("Silent Mode");​
​}​
​else if (mode == AudioManager.RINGER_MODE_VIBRATE) {​
​[Link]("Vibrate Mode");​
​}​
​else {​
​[Link]("Loud Mode");​
​}​
​}​
​}​
​}​
​}​
​ 2.​
2 ​ ndroid:layout_height="wrap_content"​
a
​Activity_main.xml​ ​android:text="Insert"​
​<?xml version="1.0" encoding="utf-8"?>​ ​android:layout_marginTop="15dp"/>​
​<ScrollView xmlns:android="[Link]
​android:layout_width="match_parent"​ ​<Button​
​android:layout_height="match_parent">​ ​android:id="@+id/btnView"​
​android:layout_width="match_parent"​
​<LinearLayout​ ​android:layout_height="wrap_content"​
​android:layout_width="match_parent"​ ​android:text="View Data"​
​android:layout_height="wrap_content"​ ​android:layout_marginTop="10dp"/>​
​android:orientation="vertical"​
​android:padding="20dp">​ ​<TextView​
​android:id="@+id/tvResult"​
​<TextView​ ​android:layout_width="match_parent"​
​android:layout_width="wrap_content"​ ​android:layout_height="wrap_content"​
​android:layout_height="wrap_content"​ ​android:layout_marginTop="20dp"​
​android:text="Student Registration"​ ​android:textSize="16sp"/>​
​android:textSize="22sp"​
​android:textStyle="bold"​ ​ /LinearLayout>​
<
​android:layout_marginBottom="20dp"/>​ ​ /ScrollView>​
<

​<EditText​ ​ [Link]​
M
​android:id="@+id/etName"​ ​package [Link];​
​android:layout_width="match_parent"​
​android:layout_height="wrap_content"​ i​mport [Link];​
​android:hint="Enter Name"/>​ ​import [Link];​
​import [Link];​
​<EditText​ ​import [Link];​
​android:id="@+id/etEmail"​ ​import [Link];​
​android:layout_width="match_parent"​ ​import [Link];​
​android:layout_height="wrap_content"​ ​import [Link].*;​
​android:hint="Enter Email"​
​android:layout_marginTop="10dp"/>​ ​import [Link];​

​<Button​ ​public class MainActivity extends AppCompatActivity {​


​android:id="@+id/btnInsert"​
​android:layout_width="match_parent"​ ​EditText etName, etEmail;​
​ utton btnInsert, btnView;​
B ​[Link](this, "Insertion Failed",​
​TextView tvResult;​ ​Toast.LENGTH_SHORT).show();​
​DBHelper dbHelper;​
​ [Link]("");​
e
​ Override​
@ ​[Link]("");​
​protected void onCreate(Bundle savedInstanceState) {​ ​}​
​[Link](savedInstanceState);​
​setContentView([Link].activity_main);​ ​private void viewData() {​
​Cursor cursor = [Link]();​
​ tName = findViewById([Link]);​
e ​StringBuilder builder = new StringBuilder();​
​etEmail = findViewById([Link]);​
​btnInsert = findViewById([Link]);​ ​while([Link]()) {​
​btnView = findViewById([Link]);​ ​[Link]("ID: ").append([Link](0)).append("\n");​
​tvResult = findViewById([Link]);​ ​[Link]("Name: ").append([Link](1)).append("\n");​
​[Link]("Email:​
​dbHelper = new DBHelper(this);​ ​").append([Link](2)).append("\n\n");​
​}​
​ [Link](v -> insertData());​
b
​[Link](v -> viewData());​ ​[Link]([Link]());​
​}​ ​}​

​private void insertData() {​ /​/ SQLite Helper Class​


​String name = [Link]().toString();​ ​public class DBHelper extends SQLiteOpenHelper {​
​String email = [Link]().toString();​
​ rivate static final String DB_NAME = "StudentDB";​
p
​if([Link]() || [Link]()) {​ ​private static final String TABLE_NAME = "students";​
​[Link](this, "Enter all fields",​
​Toast.LENGTH_SHORT).show();​ ​public DBHelper(MainActivity context) {​
​return;​ ​super(context, DB_NAME, null, 1);​
​}​ ​}​

​boolean inserted = [Link](name, email);​ ​ Override​


@
​public void onCreate(SQLiteDatabase db) {​
​if(inserted)​ ​[Link]("CREATE TABLE " + TABLE_NAME +​
​[Link](this, "Data Inserted",​ ​"(id INTEGER PRIMARY KEY AUTOINCREMENT, " +​
​Toast.LENGTH_SHORT).show();​ ​"name TEXT, email TEXT)");​
​else​ ​}​
​ Override​
@
​public void onUpgrade(SQLiteDatabase db, int oldVersion, int​
​newVersion) {​
​[Link]("DROP TABLE IF EXISTS " + TABLE_NAME);​
​onCreate(db);​
​}​

​public boolean insertData(String name, String email) {​

​ QLiteDatabase db = [Link]();​
S
​ContentValues values = new ContentValues();​
​[Link]("name", name);​
​[Link]("email", email);​

​long result = [Link](TABLE_NAME, null, values);​

​return result != -1;​


​}​

​public Cursor getAllData() {​

​ QLiteDatabase db = [Link]();​
S
​return [Link]("SELECT * FROM " + TABLE_NAME, null);​
​}​
​}​
​}​
​ 3.​
2 ​ ndroid:layout_width="match_parent"​
a
​Activity_main.xml​ ​android:layout_height="wrap_content"​
​<?xml version="1.0" encoding="utf-8"?>​ ​android:text="Register"​
​<ScrollView xmlns:android="[Link] ​android:layout_marginTop="15dp"/>​
​android:layout_width="match_parent"​
​android:layout_height="match_parent">​ ​<Button​
​android:id="@+id/btnLogin"​
​<LinearLayout​ ​android:layout_width="match_parent"​
​android:layout_width="match_parent"​ ​android:layout_height="wrap_content"​
​android:layout_height="wrap_content"​ ​android:text="Login"​
​android:orientation="vertical"​ ​android:layout_marginTop="10dp"/>​
​android:padding="20dp">​
​<TextView​
​<TextView​ ​android:id="@+id/tvResult"​
​android:layout_width="wrap_content"​ ​android:layout_width="match_parent"​
​android:layout_height="wrap_content"​ ​android:layout_height="wrap_content"​
​android:text="User Authentication"​ ​android:textSize="16sp"​
​android:textSize="22sp"​ ​android:layout_marginTop="20dp"/>​
​android:textStyle="bold"​
​android:layout_marginBottom="20dp"/>​ ​</LinearLayout>​
​</ScrollView>​
​<EditText​
​android:id="@+id/etUsername"​ ​ [Link]​
M
​android:layout_width="match_parent"​ ​package [Link];​
​android:layout_height="wrap_content"​
​android:hint="Enter Username"/>​ i​mport [Link];​
​import [Link];​
​<EditText​ ​import [Link];​
​android:id="@+id/etPassword"​ ​import [Link];​
​android:layout_width="match_parent"​ ​import [Link];​
​android:layout_height="wrap_content"​ ​import [Link].*;​
​android:hint="Enter Password"​
​android:inputType="textPassword"​ ​import [Link];​
​android:layout_marginTop="10dp"/>​
​public class MainActivity extends AppCompatActivity {​
​<Button​
​android:id="@+id/btnRegister"​ ​EditText etUsername, etPassword;​
​ utton btnRegister, btnLogin;​
B ​}​
​TextView tvResult;​
​DBHelper dbHelper;​ ​private void loginUser() {​

​ Override​
@ ​ tring username = [Link]().toString();​
S
​protected void onCreate(Bundle savedInstanceState) {​ ​String password = [Link]().toString();​
​[Link](savedInstanceState);​
​setContentView([Link].activity_main);​ ​boolean valid = [Link](username, password);​

​ tUsername = findViewById([Link]);​
e ​if(valid)​
​etPassword = findViewById([Link]);​ ​[Link]("Login Successful");​
​btnRegister = findViewById([Link]);​ ​else​
​btnLogin = findViewById([Link]);​ ​[Link]("Invalid Username or Password");​
​tvResult = findViewById([Link]);​ ​}​

​dbHelper = new DBHelper(this);​ /​/ SQLite Helper Class​


​public class DBHelper extends SQLiteOpenHelper {​
​ [Link](v -> registerUser());​
b
​[Link](v -> loginUser());​ ​ rivate static final String DB_NAME = "AuthDB";​
p
​}​ ​private static final String TABLE_NAME = "users";​

​private void registerUser() {​ ​public DBHelper(MainActivity context) {​


​super(context, DB_NAME, null, 1);​
​ tring username = [Link]().toString();​
S ​}​
​String password = [Link]().toString();​
​ Override​
@
​if([Link]() || [Link]()) {​ ​public void onCreate(SQLiteDatabase db) {​
​[Link]("Enter all fields");​ ​[Link]("CREATE TABLE " + TABLE_NAME +​
​return;​ ​"(id INTEGER PRIMARY KEY AUTOINCREMENT, " +​
​}​ ​"username TEXT, password TEXT)");​
​}​
​boolean inserted = [Link](username, password);​
​ Override​
@
​if(inserted)​ ​public void onUpgrade(SQLiteDatabase db, int oldVersion, int​
​[Link]("Registration Successful");​ ​newVersion) {​
​else​ ​[Link]("DROP TABLE IF EXISTS " + TABLE_NAME);​
​[Link]("Registration Failed");​ ​onCreate(db);​
​}​

​public boolean insertUser(String username, String password) {​

​ QLiteDatabase db = [Link]();​
S
​ContentValues values = new ContentValues();​
​[Link]("username", username);​
​[Link]("password", password);​

​long result = [Link](TABLE_NAME, null, values);​

​return result != -1;​


​}​

​public boolean checkUser(String username, String password) {​

​SQLiteDatabase db = [Link]();​

​Cursor cursor = [Link](​


​"SELECT * FROM " + TABLE_NAME +​
​" WHERE username=? AND password=?",​
​new String[]{username, password});​

​return [Link]() > 0;​


​}​
​}​
​}​
​ 4.​
2 ​ ndroid:layout_width="match_parent"​
a
​Activity_main.xml​ ​android:layout_height="wrap_content"​
​<?xml version="1.0" encoding="utf-8"?>​ ​android:text="Add Contact"​
​<ScrollView xmlns:android="[Link] ​android:layout_marginTop="15dp"/>​
​android:layout_width="match_parent"​
​android:layout_height="match_parent">​ ​<Button​
​android:id="@+id/btnView"​
​<LinearLayout​ ​android:layout_width="match_parent"​
​android:layout_width="match_parent"​ ​android:layout_height="wrap_content"​
​android:layout_height="wrap_content"​ ​android:text="View Contacts"​
​android:orientation="vertical"​ ​android:layout_marginTop="10dp"/>​
​android:padding="20dp">​
​<TextView​
​<TextView​ ​android:id="@+id/tvResult"​
​android:layout_width="wrap_content"​ ​android:layout_width="match_parent"​
​android:layout_height="wrap_content"​ ​android:layout_height="wrap_content"​
​android:text="My Contacts"​ ​android:textSize="16sp"​
​android:textSize="22sp"​ ​android:layout_marginTop="20dp"/>​
​android:textStyle="bold"​
​android:layout_marginBottom="20dp"/>​ ​</LinearLayout>​
​</ScrollView>​
​<EditText​
​android:id="@+id/etName"​ ​ [Link]​
M
​android:layout_width="match_parent"​ ​<?xml version="1.0" encoding="utf-8"?>​
​android:layout_height="wrap_content"​ ​<ScrollView xmlns:android="[Link]
​android:hint="Enter Contact Name"/>​ ​android:layout_width="match_parent"​
​android:layout_height="match_parent">​
​<EditText​
​android:id="@+id/etPhone"​ ​<LinearLayout​
​android:layout_width="match_parent"​ ​android:layout_width="match_parent"​
​android:layout_height="wrap_content"​ ​android:layout_height="wrap_content"​
​android:hint="Enter Phone Number"​ ​android:orientation="vertical"​
​android:inputType="phone"​ ​android:padding="20dp">​
​android:layout_marginTop="10dp"/>​
​<TextView​
​<Button​ ​android:layout_width="wrap_content"​
​android:id="@+id/btnAdd"​ ​android:layout_height="wrap_content"​
​ ndroid:text="My Contacts"​
a ​ ndroid:textSize="16sp"​
a
​android:textSize="22sp"​ ​android:layout_marginTop="20dp"/>​
​android:textStyle="bold"​
​android:layout_marginBottom="20dp"/>​ ​</LinearLayout>​
​</ScrollView>​
​<EditText​
​android:id="@+id/etName"​
​android:layout_width="match_parent"​
​android:layout_height="wrap_content"​
​android:hint="Enter Contact Name"/>​

​<EditText​
​android:id="@+id/etPhone"​
​android:layout_width="match_parent"​
​android:layout_height="wrap_content"​
​android:hint="Enter Phone Number"​
​android:inputType="phone"​
​android:layout_marginTop="10dp"/>​

​<Button​
​android:id="@+id/btnAdd"​
​android:layout_width="match_parent"​
​android:layout_height="wrap_content"​
​android:text="Add Contact"​
​android:layout_marginTop="15dp"/>​

​<Button​
​android:id="@+id/btnView"​
​android:layout_width="match_parent"​
​android:layout_height="wrap_content"​
​android:text="View Contacts"​
​android:layout_marginTop="10dp"/>​

​<TextView​
​android:id="@+id/tvResult"​
​android:layout_width="match_parent"​
​android:layout_height="wrap_content"​
​ 5.​
2 i​mport [Link];​
​Activity_main.xml​ ​import [Link];​
​<?xml version="1.0" encoding="utf-8"?>​ ​import [Link];​
​<LinearLayout​ ​import [Link];​
​xmlns:android="[Link] ​import [Link];​
​android:layout_width="match_parent"​ ​import [Link];​
​android:layout_height="match_parent"​ ​import [Link];​
​android:orientation="vertical"​ ​import [Link];​
​android:gravity="center"​ ​import [Link];​
​android:padding="20dp">​
i​mport [Link];​
​<TextView​ ​import [Link];​
​android:layout_width="wrap_content"​ ​import [Link];​
​android:layout_height="wrap_content"​ ​import [Link];​
​android:text="Camera Application"​
​android:textSize="22sp"​ ​public class MainActivity extends AppCompatActivity {​
​android:textStyle="bold"​
​android:layout_marginBottom="20dp"/>​ ​ rivate static final int CAMERA_REQUEST = 100;​
p
​private static final int CAMERA_PERMISSION_CODE = 101;​
​<ImageView​
​android:id="@+id/imageView"​ I​mageView imageView;​
​android:layout_width="250dp"​ ​Button btnCamera;​
​android:layout_height="250dp"​
​android:background="@android:color/darker_gray"​ ​ Override​
@
​android:layout_marginBottom="20dp"/>​ ​protected void onCreate(Bundle savedInstanceState) {​
​[Link](savedInstanceState);​
​<Button​ ​setContentView([Link].activity_main);​
​android:id="@+id/btnCamera"​
​android:layout_width="match_parent"​ i​mageView = findViewById([Link]);​
​android:layout_height="wrap_content"​ ​btnCamera = findViewById([Link]);​
​android:text="Open Camera"/>​
​[Link](v -> {​
​</LinearLayout>​
​if ([Link](this,​
​ [Link]​
M ​[Link])​
​package [Link];​ ​!= PackageManager.PERMISSION_GRANTED) {​
​[Link](this,​ ​ & [Link] > 0​
&
​new String[]{[Link]},​ ​&& grantResults[0] ==​
​CAMERA_PERMISSION_CODE);​ ​PackageManager.PERMISSION_GRANTED) {​
​} else {​
​openCamera();​ ​ penCamera();​
o
​}​ ​} else {​
​});​ ​[Link](this,​
​}​ ​"Camera Permission Denied",​
​Toast.LENGTH_SHORT).show();​
​private void openCamera() {​ ​}​
​Intent cameraIntent = new​ ​}​
​Intent(MediaStore.ACTION_IMAGE_CAPTURE);​ ​}​
​startActivityForResult(cameraIntent, CAMERA_REQUEST);​
​}​

​ Override​
@
​protected void onActivityResult(int requestCode,​
​int resultCode,​
​@Nullable Intent data) {​
​[Link](requestCode, resultCode, data);​

i​f (requestCode == CAMERA_REQUEST && resultCode ==​


​RESULT_OK) {​

​ itmap photo = (Bitmap) [Link]().get("data");​


B
​[Link](photo);​
​}​
​}​

​ Override​
@
​public void onRequestPermissionsResult(int requestCode,​
​String[] permissions,​
​int[] grantResults) {​
​[Link](requestCode,​
​permissions, grantResults);​

​if (requestCode == CAMERA_PERMISSION_CODE​


​ 6.​
2 ​ ndroid:id="@+id/btnSend"​
a
​Activity_main.xml​ ​android:layout_width="match_parent"​
​<?xml version="1.0" encoding="utf-8"?>​ ​android:layout_height="wrap_content"​
​<ScrollView xmlns:android="[Link] ​android:text="Send SMS"​
​android:layout_width="match_parent"​ ​android:layout_marginTop="15dp"/>​
​android:layout_height="match_parent">​
​ /LinearLayout>​
<
​<LinearLayout​ ​ /ScrollView>​
<
​android:layout_width="match_parent"​
​android:layout_height="wrap_content"​ ​ [Link]​
M
​android:orientation="vertical"​ ​<?xml version="1.0" encoding="utf-8"?>​
​android:padding="20dp">​ ​<ScrollView xmlns:android="[Link]
​android:layout_width="match_parent"​
​<TextView​ ​android:layout_height="match_parent">​
​android:layout_width="wrap_content"​
​android:layout_height="wrap_content"​ ​<LinearLayout​
​android:text="SMS Application"​ ​android:layout_width="match_parent"​
​android:textSize="22sp"​ ​android:layout_height="wrap_content"​
​android:textStyle="bold"​ ​android:orientation="vertical"​
​android:layout_marginBottom="20dp"/>​ ​android:padding="20dp">​

​<EditText​ ​<TextView​
​android:id="@+id/etNumber"​ ​android:layout_width="wrap_content"​
​android:layout_width="match_parent"​ ​android:layout_height="wrap_content"​
​android:layout_height="wrap_content"​ ​android:text="SMS Application"​
​android:hint="Enter Mobile Number"​ ​android:textSize="22sp"​
​android:inputType="phone"/>​ ​android:textStyle="bold"​
​android:layout_marginBottom="20dp"/>​
​<EditText​
​android:id="@+id/etMessage"​ ​<EditText​
​android:layout_width="match_parent"​ ​android:id="@+id/etNumber"​
​android:layout_height="wrap_content"​ ​android:layout_width="match_parent"​
​android:hint="Enter Message"​ ​android:layout_height="wrap_content"​
​android:layout_marginTop="10dp"​ ​android:hint="Enter Mobile Number"​
​android:inputType="textMultiLine"/>​ ​android:inputType="phone"/>​

​<Button​ ​<EditText​
​ ndroid:id="@+id/etMessage"​
a
​android:layout_width="match_parent"​
​android:layout_height="wrap_content"​
​android:hint="Enter Message"​
​android:layout_marginTop="10dp"​
​android:inputType="textMultiLine"/>​

​<Button​
​android:id="@+id/btnSend"​
​android:layout_width="match_parent"​
​android:layout_height="wrap_content"​
​android:text="Send SMS"​
​android:layout_marginTop="15dp"/>​

​</LinearLayout>​
​</ScrollView>​
​ 7.​
2 ​ ndroid:layout_height="wrap_content"​
a
​Activity_main.xml​ ​android:hint="Message"​
​<?xml version="1.0" encoding="utf-8"?>​ ​android:layout_marginTop="10dp"​
​<ScrollView xmlns:android="[Link] ​android:inputType="textMultiLine"/>​
​android:layout_width="match_parent"​
​android:layout_height="match_parent">​ ​<Button​
​android:id="@+id/btnSend"​
​<LinearLayout​ ​android:layout_width="match_parent"​
​android:layout_width="match_parent"​ ​android:layout_height="wrap_content"​
​android:layout_height="wrap_content"​ ​android:text="Send Email"​
​android:orientation="vertical"​ ​android:layout_marginTop="15dp"/>​
​android:padding="20dp">​
​ /LinearLayout>​
<
​<TextView​ ​ /ScrollView>​
<
​android:layout_width="wrap_content"​
​android:layout_height="wrap_content"​ ​ [Link]​
M
​android:text="Email Application"​ ​package [Link];​
​android:textSize="22sp"​
​android:textStyle="bold"​ i​mport [Link];​
​android:layout_marginBottom="20dp"/>​ ​import [Link];​
​import [Link];​
​<EditText​ ​import [Link];​
​android:id="@+id/etTo"​ ​import [Link];​
​android:layout_width="match_parent"​
​android:layout_height="wrap_content"​ ​import [Link];​
​android:hint="Recipient Email"/>​
​public class MainActivity extends AppCompatActivity {​
​<EditText​
​android:id="@+id/etSubject"​ ​ ditText etTo, etSubject, etMessage;​
E
​android:layout_width="match_parent"​ ​Button btnSend;​
​android:layout_height="wrap_content"​
​android:hint="Subject"​ ​ Override​
@
​android:layout_marginTop="10dp"/>​ ​protected void onCreate(Bundle savedInstanceState) {​
​[Link](savedInstanceState);​
​<EditText​ ​setContentView([Link].activity_main);​
​android:id="@+id/etMessage"​
​android:layout_width="match_parent"​ ​etTo = findViewById([Link]);​
​ tSubject = findViewById([Link]);​
e
​etMessage = findViewById([Link]);​
​btnSend = findViewById([Link]);​

​[Link](v -> sendEmail());​


​}​

​private void sendEmail() {​

​ tring to = [Link]().toString();​
S
​String subject = [Link]().toString();​
​String message = [Link]().toString();​

​if([Link]() || [Link]() || [Link]()) {​


​[Link](this,​
​"Enter all fields",​
​Toast.LENGTH_SHORT).show();​
​return;​
​}​

I​ntent intent = new Intent(Intent.ACTION_SEND);​


​[Link]("message/rfc822");​
​[Link](Intent.EXTRA_EMAIL, new String[]{to});​
​[Link](Intent.EXTRA_SUBJECT, subject);​
​[Link](Intent.EXTRA_TEXT, message);​

​try {​
​startActivity([Link](intent, "Send Email"));​
​} catch (Exception e) {​
​[Link](this,​
​"No Email App Found",​
​Toast.LENGTH_SHORT).show();​
​}​
​}​
​}​
​ 8.​
2
​Activity_main.xml​ i​mport [Link];​
​<?xml version="1.0" encoding="utf-8"?>​ ​import [Link];​
​<LinearLayout​ ​import [Link];​
​xmlns:android="[Link] ​import [Link];​
​android:layout_width="match_parent"​ ​import [Link];​
​android:layout_height="match_parent"​ ​import [Link];​
​android:orientation="vertical"​ ​import [Link];​
​android:gravity="center"​ ​import [Link];​
​android:padding="20dp">​ ​import [Link];​

​<TextView​ i​mport [Link];​


​android:layout_width="wrap_content"​ ​import [Link];​
​android:layout_height="wrap_content"​ ​import [Link];​
​android:text="Location Service Application"​ ​import [Link];​
​android:textSize="22sp"​
​android:textStyle="bold"​ ​public class MainActivity extends AppCompatActivity {​
​android:layout_marginBottom="20dp"/>​
​private static final int LOCATION_PERMISSION_CODE = 100;​
​<TextView​
​android:id="@+id/tvLocation"​ ​ ocationManager locationManager;​
L
​android:layout_width="wrap_content"​ ​TextView tvLocation;​
​android:layout_height="wrap_content"​ ​Button btnGetLocation;​
​android:text="Location not available"​
​android:textSize="18sp"​ ​ Override​
@
​android:layout_marginBottom="20dp"/>​ ​protected void onCreate(Bundle savedInstanceState) {​
​[Link](savedInstanceState);​
​<Button​ ​setContentView([Link].activity_main);​
​android:id="@+id/btnGetLocation"​
​android:layout_width="match_parent"​ t​vLocation = findViewById([Link]);​
​android:layout_height="wrap_content"​ ​btnGetLocation = findViewById([Link]);​
​android:text="Get Location"/>​
l​ocationManager = (LocationManager)​
​</LinearLayout>​ ​getSystemService(LOCATION_SERVICE);​

​ [Link]​
M ​[Link](v -> checkPermission());​
​package [Link];​ ​}​
​}​
​private void checkPermission() {​ ​});​
​}​
​if ([Link](this,​
​[Link].ACCESS_FINE_LOCATION)​ ​ Override​
@
​!= PackageManager.PERMISSION_GRANTED) {​ ​public void onRequestPermissionsResult(int requestCode,​
​@NonNull String[] permissions,​
​[Link](this,​ ​@NonNull int[] grantResults) {​
​new​
​String[]{[Link].ACCESS_FINE_LOCATION},​ ​[Link](requestCode,​
​LOCATION_PERMISSION_CODE);​ ​permissions, grantResults);​
​} else {​
​getLocation();​ ​if (requestCode == LOCATION_PERMISSION_CODE​
​}​ ​&& [Link] > 0​
​}​ ​&& grantResults[0] ==​
​ ackageManager.PERMISSION_GRANTED) {​
P
​private void getLocation() {​
​getLocation();​
​if ([Link](this,​ ​} else {​
​[Link].ACCESS_FINE_LOCATION)​ ​[Link](this,​
​!= PackageManager.PERMISSION_GRANTED) {​ ​"Location Permission Denied",​
​return;​ ​Toast.LENGTH_SHORT).show();​
​}​ ​}​
​}​
​[Link](​ ​}​
​LocationManager.GPS_PROVIDER,​
​0,​
​0,​
​new LocationListener() {​
​@Override​
​public void onLocationChanged(@NonNull Location location) {​

​ ouble latitude = [Link]();​


d
​double longitude = [Link]();​

​[Link]("Latitude: " + latitude +​


​"\nLongitude: " + longitude);​
​ 9.​
2 ​</[Link]>​
​Activity_main.xml​
​<?xml version="1.0" encoding="utf-8"?>​ ​Nav_menu.xml​
​<[Link]​
​xmlns:android="[Link] ​ ?xml version="1.0" encoding="utf-8"?>​
<
​xmlns:app="[Link] ​<menu xmlns:android="[Link]
​android:id="@+id/drawerLayout"​
​android:layout_width="match_parent"​ ​<item​
​android:layout_height="match_parent">​ ​android:id="@+id/nav_home"​
​android:title="Home"/>​
​ !-- Main Content -->​
<
​<LinearLayout​ ​<item​
​android:layout_width="match_parent"​ ​android:id="@+id/nav_about"​
​android:layout_height="match_parent"​ ​android:title="About"/>​
​android:orientation="vertical">​
​</menu>​
​<[Link]​
​android:id="@+id/toolbar"​ ​ [Link]​
H
​android:layout_width="match_parent"​ ​package [Link];​
​android:layout_height="wrap_content"​
​android:background="@color/purple_500"​ i​mport [Link];​
​android:minHeight="?attr/actionBarSize"/>​ ​import [Link];​
​import [Link];​
​<FrameLayout​ ​import [Link];​
​android:id="@+id/fragmentContainer"​ ​import [Link];​
​android:layout_width="match_parent"​
​android:layout_height="match_parent"/>​ ​import [Link];​
​ /LinearLayout>​
<
​public class HomeFragment extends Fragment {​
​ !-- Navigation Drawer -->​
<
​<[Link]​ ​ Override​
@
​android:id="@+id/navigationView"​ ​public View onCreateView(LayoutInflater inflater,​
​android:layout_width="wrap_content"​ ​ViewGroup container,​
​android:layout_height="match_parent"​ ​Bundle savedInstanceState) {​
​android:layout_gravity="start"​
​app:menu="@menu/nav_menu"/>​ ​ extView textView = new TextView(getContext());​
T
​[Link]("Home Fragment");​
​[Link](22);​ i​mport [Link];​
​import [Link];​
​return textView;​ ​import [Link];​
​}​ ​import [Link];​
​}​ ​import [Link];​

​ [Link]​
A ​import [Link];​
​package [Link];​
​import [Link];​
i​mport [Link];​
​import [Link];​ ​public class MainActivity extends AppCompatActivity {​
​import [Link];​
​import [Link];​ ​ rawerLayout drawerLayout;​
D
​import [Link];​ ​NavigationView navigationView;​
​Toolbar toolbar;​
​import [Link];​
​ Override​
@
​public class AboutFragment extends Fragment {​ ​protected void onCreate(Bundle savedInstanceState) {​
​[Link](savedInstanceState);​
​ Override​
@ ​setContentView([Link].activity_main);​
​public View onCreateView(LayoutInflater inflater,​
​ViewGroup container,​ ​ rawerLayout = findViewById([Link]);​
d
​Bundle savedInstanceState) {​ ​navigationView = findViewById([Link]);​
​toolbar = findViewById([Link]);​
​ extView textView = new TextView(getContext());​
T
​[Link]("About Fragment");​ ​setSupportActionBar(toolbar);​
​[Link](22);​
​ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(​
​return textView;​ ​this, drawerLayout, toolbar,​
​}​ ​[Link], [Link]);​
​}​
​ [Link](toggle);​
d
​ [Link]​
M ​[Link]();​
​package [Link];​
​loadFragment(new HomeFragment());​
i​mport [Link];​
​import [Link];​ ​[Link](item -> {​
​Fragment selectedFragment = null;​

​if ([Link]() == [Link].nav_home) {​


​selectedFragment = new HomeFragment();​
​} else if ([Link]() == [Link].nav_about) {​
​selectedFragment = new AboutFragment();​
​}​

​if (selectedFragment != null) {​


​loadFragment(selectedFragment);​
​}​

​ [Link]();​
d
​return true;​
​});​
​}​

​private void loadFragment(Fragment fragment) {​


​getSupportFragmentManager()​
​.beginTransaction()​
​.replace([Link], fragment)​
​.commit();​
​}​
​}​
​ 0.​
3 i​mport [Link];​
​Activity_main.xml​ ​import [Link];​
​<?xml version="1.0" encoding="utf-8"?>​ ​import [Link];​
​<LinearLayout​
​xmlns:android="[Link] ​public class MainActivity extends AppCompatActivity {​
​android:layout_width="match_parent"​
​android:layout_height="match_parent"​ ​private static final int CAMERA_PERMISSION_CODE = 100;​
​android:orientation="vertical"​
​android:gravity="center"​ ​ ameraManager cameraManager;​
C
​android:padding="20dp">​ ​String cameraId;​
​boolean isFlashOn = false;​
​<TextView​
​android:layout_width="wrap_content"​ ​Button btnFlash;​
​android:layout_height="wrap_content"​
​android:text="Flashlight Application"​ ​ Override​
@
​android:textSize="22sp"​ ​protected void onCreate(Bundle savedInstanceState) {​
​android:textStyle="bold"​ ​[Link](savedInstanceState);​
​android:layout_marginBottom="20dp"/>​ ​setContentView([Link].activity_main);​

​<Button​ ​btnFlash = findViewById([Link]);​


​android:id="@+id/btnFlash"​
​android:layout_width="200dp"​ ​ ameraManager = (CameraManager)​
c
​android:layout_height="wrap_content"​ ​getSystemService(CAMERA_SERVICE);​
​android:text="Turn ON Flash"/>​
​try {​
​</LinearLayout>​ ​cameraId = [Link]()[0];​
​} catch (Exception e) {​
​ [Link]​
M ​[Link]();​
​package [Link];​ ​}​

i​mport [Link];​ ​[Link](v -> checkPermission());​


​import [Link];​ ​}​
​import [Link];​
​import [Link];​ ​private void checkPermission() {​
​import [Link];​
​import [Link];​ ​if ([Link](this,​
​[Link])​
​!= PackageManager.PERMISSION_GRANTED) {​ ​if (requestCode == CAMERA_PERMISSION_CODE​
​&& [Link] > 0​
​[Link](this,​ ​&& grantResults[0] ==​
​new String[]{[Link]},​ ​ ackageManager.PERMISSION_GRANTED) {​
P
​CAMERA_PERMISSION_CODE);​
​} else {​ ​toggleFlash();​
​toggleFlash();​ ​} else {​
​}​ ​[Link](this,​
​}​ ​"Camera Permission Denied",​
​Toast.LENGTH_SHORT).show();​
​private void toggleFlash() {​ ​}​
​}​
​try {​ ​}​
​if (!isFlashOn) {​
​[Link](cameraId, true);​
​[Link]("Turn OFF Flash");​
​isFlashOn = true;​
​} else {​
​[Link](cameraId, false);​
​[Link]("Turn ON Flash");​
​isFlashOn = false;​
​}​
​} catch (Exception e) {​
​[Link](this,​
​"Flash not supported",​
​Toast.LENGTH_SHORT).show();​
​}​
​}​

​ Override​
@
​public void onRequestPermissionsResult(int requestCode,​
​String[] permissions,​
​int[] grantResults) {​

​[Link](requestCode,​
​permissions, grantResults);​

You might also like