You are on page 1of 50

Mobile Application Development (3170726)

A Laboratory Manual for

Mobile Application Development


(3170726)

B.E. Semester 7
(Computer Engineering)

Directorate of Technical Education, Gandhinagar,


Gujarat

Government Engineering College, Modasa


Mobile Application Development (3170726)

CERTIFICATE

This is to certify that Mr. Vaishnav Vishal Dipakbhai Enrollment No.


200160107129 of B.E. Semester 7 Computer Engineering Department of this
Institute (GTU Code: 016) has satisfactorily completed the Practical / Tutorial work
for the subject Mobile Application Development (3170726) for the academic year
2023-24.

Date: __________

Sign of Faculty Coordinator Head of Department


Mobile Application Development (3170726)

Preface

Main motto of any laboratory/practical/field work is for enhancing required skills as well as
creating ability amongst students to solve real time problem by developing relevant competencies
in psychomotor domain. By keeping in view, GTU has designed competency focused outcome-
based curriculum for engineering degree programs where sufficient weightage is given to
practical work. It shows importance of enhancement of skills amongst the students and it pays
attention to utilize every second of time allotted for practical amongst students, instructors and
faculty members to achieve relevant outcomes by performing the experiments rather than having
merely study type experiments. It is must for effective implementation of competency focused
outcome-based curriculum that every practical is keenly designed to serve as a tool to develop
and enhance relevant competency required by the various industry among every student. These
psychomotor skills are very difficult to develop through traditional chalk and board content
delivery method in the classroom. Accordingly, this lab manual is designed to focus on the
industry defined relevant outcomes, rather than old practice of conducting practical to prove
concept and theory.

By using this lab manual students can go through the relevant theory and procedure in advance
before the actual performance which creates an interest and students can have basic idea prior to
performance. This in turn enhances pre-determined outcomes amongst students. Each experiment
in this manual begins with competency, industry relevant skills, course outcomes as well as
practical outcomes (objectives). The students will also achieve safety and necessary precautions
to be taken while performing practical.

This manual also provides guidelines to faculty members to facilitate student centric lab activities
through each experiment by arranging and managing necessary resources in order that the
students follow the procedures with required safety and necessary precautions to achieve the
outcomes. It also gives an idea that how students will be assessed by providing rubrics.

Mobile application development involves creating software applications that are specifically
designed to run on mobile devices, such as smartphones and tablets. These applications can serve
a wide range of purposes, from entertainment and communication to productivity and business
tools. It is a dynamic field at the crossroads of technology, design, and user experience. It requires
a holistic approach that integrates technical proficiency, creative design thinking, and a
commitment to delivering valuable and engaging solutions that cater to the needs of today's
mobile-oriented world. The key technical aspects of mobile application development are UI
design, Back-end development, Programming language, Development tools, Testing and Iteration
Deployment and Maintenance.
Utmost care has been taken while preparing this lab manual however always there is chances of
improvement. Therefore, we welcome constructive suggestions for improvement and removal of
errors if any.
Mobile Application Development (3170726)

Course Outcomes (COs):


1. Understand Android architecture, activities and their life cycle.
2. Apply the knowledge to design user interface using Android UI and Component.
3. Manage system database, remote database operations using web services and Firebase.
4. Apply knowledge of map, location services, Graphics, android system and background services.
5. Publish and distribute Android Application.

Sr. C C C C
C
No Objective(s) of Experiment O1
O O O O
2 3 4 5
.
Design Login activity and implement control events: Use
EditText, Checkbox and Buttons. And implement above
events using following layouts:
1. 1. Linear Layout √
2. Relative Layout
3. Table Layout

Create Activities & implement following


1. Implicit intent
2. 2. Explicit Intent √ √
3. Start Activity for Result

Practical: Use an Options Menu


3. √
Create a Recycler View and list the details of student using
following fields:
1. Name
4. 2. Address √ √
3. Photo (Image)
4. Delete (Button Operation)

Practical: Theme, Custom Styles, Drawable


5. √
Practical: Save user data in a database
6. √
Practical: Get and Save User Preferences √ √
7.
Practical: make a use of android system
8. √
√ √
Using location service get the current location and display
9. in Text View

Practical: Display the use of animations √


10.
Mobile Application Development (3170726)

Industry Relevant Skills

The following industry relevant competencies are expected to be developed in the student by
undertaking the practical work of this laboratory.

1. Investigation and analysis skills: Develop the ability to investigate and analyze various
digital devices and systems, including computers, mobile devices, and networks. Learn
how to extract and analyze data from these devices and systems to identify evidence
of cybercrime.
2. Evidence handling and preservation skills: How to handle and preserve digital
evidence in a way that is admissible in court. This includes learning about chain of
custody, evidence storage, and documentation.
3. Technical skills: Technical skills related to computer and network security, including
knowledge of operating systems, file systems, and network protocols. Students may
also learn about encryption, steganography, and other techniques used to hide
information.
4. Legal and regulatory knowledge: Relevant laws and regulations related to cybercrime,
such as the IT Act 2000. Students will learn about legal procedures, courtroom
procedures, and other aspects of the legal system.
5. Communication and reporting skills: Students will learn how to communicate complex
technical information to non-technical stakeholders, such as lawyers, judges, and
juries. They will also learn how to write clear and concise reports that summarize their
findings and conclusions.
6. Critical thinking and problem-solving skills: Complex problem-solving scenarios that
require students to think critically and apply their knowledge and skills to real-world
situations.

Guidelines for Faculty members


1. Teacher should provide the guideline with demonstration of practical to the students
with all features.
2. Teacher shall explain basic concepts/theory related to the experiment to the students before
starting of each practical
3. Involve all the students in performance of each experiment.
4. Teacher is expected to share the skills and competencies to be developed in the
students and ensure that the respective skills and competencies are developed in the
students after the completion of the experimentation.
5. Teachers should give opportunity to students for hands-on experience after the
demonstration.
6. Teacher may provide additional knowledge and skills to the students even though not
covered in the manual but are expected from the students by concerned industry.
7. Give practical assignment and assess the performance of students based on task
assigned to check whether it is as per the instructions or not.
8. Teacher is expected to refer complete curriculum of the course and follow the
Mobile Application Development (3170726)

guidelines for implementation.

Instructions for Students


1. Students are expected to carefully listen to all the theory classes delivered by the faculty
members and understand the COs, content of the course, teaching and examination scheme,
skill set to be developed etc.
2. Students shall organize the work in the group and make record of all observations.
3. Students shall develop maintenance skill as expected by industries.
4. Student shall attempt to develop related hand-on skills and build confidence.
5. Student shall develop the habits of evolving more ideas, innovations, skills etc. apart from
those included in scope of manual.
6. Student shall refer technical magazines and data books, follow real cyber forensic cases.
7. Student should develop a habit of submitting the experimentation work as per the schedule
and s/he should be well prepared for the same.

Common Safety Instructions

Students are expected to carefully perform each experiment without damaging the lab computer
systems. All the experiments are for learning purpose only and never perform anywhere else without
proper authorization.
Mobile Application Development (3170726)

Index
(Progressive Assessment Sheet)

Sr. Objective(s) of Experiment Pa Dat Date Asse Sign. Re


No. ge e of of ssme of mar
No. perf sub nt Teach ks
orm miss Mar er
anc ion ks with
e date
Design Login activity and implement control
events: Use EditText, Checkbox and
Buttons. And implement above events using
following layouts:
1. 1. Linear Layout
2. Relative Layout
3. Table Layout

Create Activities & implement following


1. Implicit intent
2. 2. Explicit Intent
3. Start Activity for Result

Practical: Use an Options Menu


3.
Create a Recycler View and list the details of
student using following fields:
1. Name
4. 2. Address
3. Photo (Image)
4. Delete (Button Operation)

Practical: Theme, Custom Styles,


5.
Drawable
Practical: Save user data in a database
6.
Practical: Get and Save User Preferences
7.
Practical: make a use of android system
8.

Using location service get the current


9. location and display in Text View

Practical: Display the use of animations


10.
Total
Practical-1
AIM: Design Login activity and implement control events: Use EditText, Checkbox and
Buttons. And implement above events using following layouts:
1. Linear Layout 2. Relative Layout 3. Table Layout
Date:

Relevant CO: CO2

Theory :

➢ LinearLayout:
• Orientation: LinearLayout is a simple and straightforward layout that arranges its child views
either horizontally or vertically, depending on the specified orientation (horizontal or vertical).
• Child View Alignment: Child views are positioned in a linear manner one after the other, and you can
control their alignment within the layout, such as left, center, right (for horizontal orientation) or top,
center, bottom (for vertical orientation).
• Weighted Distribution: You can assign weights to child views, which allows you to control how much
space each view occupies relative to others. This is useful for creating flexible layouts where views
can expand or shrink based on screen size or content.

• Nested Layouts: LinearLayout can be nested within other layouts, such as inside a ScrollView or as a
child of other ViewGroup layouts, to create complex UI designs.

➢ RelativeLayout:
• Positioning Based on Relationships: RelativeLayout allows you to position child views relative to
each other or relative to the parent layout. You define the position of a view in relation to another
view using attributes like android:layout_above, android:layout_below, android:layout_toLeftOf,
android:layout_toRightOf, etc.

• Dynamic Layouts: RelativeLayout is great for creating dynamic and responsive layouts that adapt to
different screen sizes and orientations. It's particularly useful when you don't know the exact size or
position of views in advance.
• Complex Hierarchies: You can create complex view hierarchies with RelativeLayout by specifying
rules for each view, allowing for intricate and customized UI designs.

➢ TableLayout:

• Grid-Based Layout: TableLayout is used to create a grid-like layout where child views are organized
in rows and columns. It's especially useful when you need to display data or elements in a tabular
format.
• Rows and Columns: You define the structure of the table by adding TableRow elements as child views
of TableLayout. Each TableRow represents a row in the table, and you can add child views to these
TableRow elements, which act as cells within the table.
• Uniform Sizing: TableLayout distributes space evenly among columns and rows, ensuring that cells
have uniform sizes. You can customize the width of columns or the height of rows if needed.
• Data Display: TableLayout is commonly used for displaying data sets or grids of content, such as
contact lists, calendars, or data input forms.

Code: XML FILE, JAVA FILE

Activity_Practical1.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
Vishal Vaishnav 200160107129

android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".prac1.MainActivity"
android:orientation="vertical"
android:layout_marginHorizontal="10dp"
android:gravity="center_vertical"
>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login Page"
android:layout_gravity="center"
android:textColor="@color/black"
android:textStyle="bold"
android:textSize="20dp"
/>

<EditText
android:id="@+id/userNameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter User Name"
android:layout_marginTop="10dp"
/>

<EditText
android:id="@+id/userPasswordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Your Password"
android:layout_marginTop="10dp"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Which fast food do you like?"
android:textStyle="bold"
android:layout_marginTop="10dp"
/>

<CheckBox android:id="@+id/checkbox_burger"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Burger" />

<CheckBox android:id="@+id/checkbox_pizza"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pizza"/>

<Button
android:id="@+id/loginBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
Vishal Vaishnav 200160107129

android:text="LOGIN"
/>

<CheckBox android:id="@+id/checkbox_pizza"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pizza"
android:layout_toEndOf="@id/checkbox_burger"
android:layout_below="@id/checkboxQuestion"
/>

<Button
android:id="@+id/loginBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="LOGIN"
android:layout_below="@id/checkbox_pizza"
android:layout_centerHorizontal="true"
/>

</RelativeLayout>
<?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=".prac1.TableLayoutActivity"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="20dp"
android:stretchColumns="1"
>

<TableRow>

<TextView
android:layout_span="2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login Page"
android:textColor="@color/black"
android:textStyle="bold"
android:layout_gravity="center"
android:textSize="20dp"
/>
</TableRow>

<TableRow>
<EditText
android:id="@+id/userNameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter User Name"
android:layout_marginTop="10dp"
android:layout_span="2"
Vishal Vaishnav 200160107129

/>
🡪Practical_1.java
package com.vgec.collegeproject.prac1;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

import com.vgec.collegeproject.R;

public class MainActivity extends AppCompatActivity {

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

EditText userName,userPassword;
CheckBox burger,pizza;
Button loginBtn;

userName = findViewById(R.id.userNameEditText);
userPassword = findViewById(R.id.userPasswordEditText);
burger = findViewById(R.id.checkbox_burger);
pizza = findViewById(R.id.checkbox_pizza);
loginBtn = findViewById(R.id.loginBtn);

loginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(userName.getText().toString().equals("User")){
if(userPassword.getText().toString().equals("12345")){
Toast.makeText(MainActivity.this, "Login Successful", Toast.LENGTH_SHORT).show();
String checkedValues = "";
if(burger.isChecked()){
checkedValues += "burger ";
}
if(pizza.isChecked()){
checkedValues += "pizza";
}
if(checkedValues.equals("")){
Toast.makeText(MainActivity.this, "No checked values.",
Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(MainActivity.this, "Checked Values : " + checkedValues,
Toast.LENGTH_SHORT).show();
}
return;
}
}
Vishal Vaishnav 200160107129

Toast.makeText(MainActivity.this, "Incorrect username or password",


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

}
}

Output:

References used by the students:


• https://developer.android.com/codelabs/build-your-first-android-app#0
• https://developer.android.com/develop/ui/views/layout/declaring-layout
• https://developer.android.com/guide/topics/media/exoplayer/ui-components
• https://www.tutorialspoint.com/android/android_table_layout.htm
• https://data-flair.training/blogs/android-radiobutton/

Rubric wise marks obtained:

Ethical and
Practical Problem Task Documentation
Professional
Understanding Solving Execution and Reporting
Rubrics Conduct Total
Good Avg. Good Avg. Good Avg. Good Avg. Good Avg.
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)

Marks
Vishal Vaishnav 200160107129

Practical-2
AIM: Create Activities & implement following
1. Implicit intent 2. Explicit Intent 3. Start Activity for Result

Date:

Relevant CO: CO1, CO2

Theory :

➢ Explicit Intent:

• Target Component Specified: An explicit intent is used when you know exactly which component
(usually an activity) you want to start. You provide the fully qualified class name of the target
component.

• Specific Component: You explicitly define the component to be launched within your app, making it
suitable for navigating within your own app's various screens or functionalities.

• Common Use Cases: Explicit intents are commonly used for navigating within an app, launching
specific activities, and passing data between them.
• Strongly Typed: Explicit intents are strongly typed, meaning you have compile-time checks, and
Android Studio can validate whether the target component exists and whether the data types match.

➢ Implicit Intent:
• Target Component Not Specified: An implicit intent is used when you want to perform an action, but
you do not specify the exact component to handle it. Instead, you define the action, data, and type,
and Android system resolves the appropriate component.

• Dynamic Component Resolution: Implicit intents are suitable for scenarios where multiple
components within the device or other installed apps can respond to the specified action and data type.

• Common Use Cases: Implicit intents are used for actions that can be performed by various apps or
components, such as opening a web link, sharing content, or sending an email.

• Runtime Resolution: Android's system resolves which component should handle the implicit intent at
runtime, based on the action, data, and type specified. This allows for greater flexibility.
• Fallback Mechanism: If no suitable component is found to handle the implicit intent, your app won't
crash; it can gracefully handle the absence of a capable component.

Code:

Activity_implicit_intent.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".prac2.ImplicitIntentActivity"
android:orientation="vertical"
android:gravity="center"
android:layout_marginHorizontal="20dp"
Vishal Vaishnav 200160107129

>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Implicit Activity"
android:layout_marginVertical="10dp"
android:textSize="20dp"
/>

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Paste any link here"
android:textColor="@color/black"
/>

<Button
android:id="@+id/btn"
android:text="Search"
android:onClick="search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
Activity_explicit_intent.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".prac2.ExplicitIntentActivity1"
android:orientation="vertical"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is explicit activity 1"
android:textSize="20dp"
/>

<Button
android:id="@+id/explicitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go to Activity 2"
android:layout_marginTop="10dp"
/>

</LinearLayout>
Vishal Vaishnav 200160107129

Activity_start_act_for_result1.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".prac2.ActivityForResult"
android:orientation="vertical"
android:gravity="center">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Activity For Result Example"
android:textSize="20dp"
android:textStyle="bold"
/>

<Button
android:id="@+id/pickContactBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click here to pick contact"
/>

<TextView
android:id="@+id/contactDetailsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
/>
</LinearLayout>

ExplicitIntentActivity.java
package com.vgec.collegeproject.prac2;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.vgec.collegeproject.R;

public class ExplicitIntentActivity1 extends AppCompatActivity {

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

Button button = findViewById(R.id.explicitButton);


button.setOnClickListener(new View.OnClickListener() {
Vishal Vaishnav 200160107129

@Override
public void onClick(View view) {
Intent intent= new Intent(ExplicitIntentActivity1.this, ExplicitIntentActivity2.class);
startActivity(intent);
}
});
}
}
ImplicitIntentActivity.java
package com.vgec.collegeproject.prac2;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.vgec.collegeproject.R;

public class ImplicitIntentActivity extends AppCompatActivity {

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

EditText editText;
Button button;
button = findViewById(R.id.btn);
editText = (EditText) findViewById(R.id.editText);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String url=editText.getText().toString();
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
});
}
}
StartActForResult_1Activity.java
package com.vgec.collegeproject.prac2;

import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
Vishal Vaishnav 200160107129

import android.provider.ContactsContract;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.vgec.collegeproject.R;

public class ActivityForResult extends AppCompatActivity {

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

Button pickContact;
TextView contactDetails;

pickContact = findViewById(R.id.pickContactBtn);
contactDetails = findViewById(R.id.contactDetailsText);

ActivityResultLauncher<Intent> contactActivityResultLauncher = registerForActivityResult(


new ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
if (result.getResultCode() == Activity.RESULT_OK) {
// There are no request codes
Intent data = result.getData();
assert data != null;
Uri contactData = data.getData();
Cursor c = getContentResolver().query(contactData, null, null, null, null);
if (c.moveToFirst()) {
int phoneIndex =
c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
int nameIndex =
c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
String num = c.getString(phoneIndex);
String name = c.getString(nameIndex);

String details = "Picked Contact: \nName: " + name + "\nNumber: " + num;

contactDetails.setText(details);
}
}
else{
Toast.makeText(ActivityForResult.this, "An error occurred fetching contact details.",
Toast.LENGTH_SHORT).show();
}
}
});

pickContact.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent pickContact=newIntent(Intent.ACTION_PICK,
ContactsContract.Contacts.CONTENT_URI);
pickContact.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
Vishal Vaishnav 200160107129

contactActivityResultLauncher.launch(pickContact);
}
});

}
}

ThirdPractical.java
package com.vgec.collegeproject.prac2;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.vgec.collegeproject.R;

public class ExplicitIntentActivity2 extends AppCompatActivity {

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

References used by the students:


https://www.geeksforgeeks.org/android-tutorial/
https://www.javatpoint.com/android-tutorial

Rubric wise marks obtained:

Ethical and
Practical Problem Task Documentation
Professional
Understanding Solving Execution and Reporting
Rubrics Conduct Total
Good Avg. Good Avg. Good Avg. Good Avg. Good Avg.
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)

Marks
Vishal Vaishnav 200160107129

Practical-3
AIM: Use an Options Menu.

Date:

Relevant CO: CO2

Theory :

The Option Menu in Android Studio, also known as the "Overflow Menu" or "Action Bar Menu," is a common user
interface element used to provide access to various actions, settings, and additional functionality within an Android app.
Here's an explanation of the Option Menu, point by point:

➢ Purpose:

• The Option Menu provides a way to access app-specific actions and settings, typically displayed as a
three-dot icon (⋮) in the top-right corner of the app's action bar (also known as the app bar or toolbar).

• Access: Users can access the Option Menu by tapping the three-dot icon or by pressing the device's
menu button (if available) when it's supported. In modern Android app design, the menu button on
devices has largely been replaced by on-screen navigation.

• Items: The Option Menu consists of a list of items, each representing a specific action, command, or
setting. These items can be text-based or include icons.

• Grouping: Menu items are typically organized into groups for better categorization and to make it
easier for users to find the desired action. Common groups include "Settings," "Share," "Help," and
"About."

• Inflating the Menu: To create and define the Option Menu, you override the onCreateOptionsMenu
method in your activity or fragment. You inflate a menu XML resource that defines the menu items
and their properties.

• Handling Selection: You can specify callback methods to handle user selection of menu items. The
onOptionsItemSelected method is used to define what should happen when a menu item is selected.

• Icons and Icons with Text: Menu items can include icons to provide visual cues for the actions.
Android allows you to use both icons alone or icons accompanied by text labels.

• Dynamic Changes: You can dynamically change the contents of the Option Menu based on the app's
state. This is useful for enabling or disabling specific actions or updating menu item labels.

• Overflow Menu: When the action bar lacks space to display all menu items, some items may be moved
to the Overflow Menu, which is accessible by tapping the three-dot icon. This allows for a cleaner
and more accessible user interface.

• Compatibility: The Option Menu is designed to be compatible with various Android versions. It adapts
its appearance and behavior depending on the version of Android the app is running on.

• Customization: You can customize the appearance of the Option Menu, including changing the
background color, text color, and more to match your app's design and branding.

• Best Practices: When implementing the Option Menu, consider the Android design guidelines to
ensure a consistent and user-friendly experience. Keep the menu items concise, use appropriate icons,
and organize actions logically.
Vishal Vaishnav 200160107129

• Alternative Menu Types: In addition to the Option Menu, Android supports other menu types like the
Popup Menu and the Bottom App Bar for different UI designs and use cases.

Code:
Activity_fifth_practical.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:title="Options Menu"
app:titleTextColor="#ffffff"
>
</androidx.appcompat.widget.Toolbar>
FifthPractical.java
package com.vgec.collegeproject.prac3;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.vgec.collegeproject.R;

public class OptionsMenuActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_options_menu);
Toolbar toolbar = findViewById(R.id.options_menu_tb);
setSupportActionBar(toolbar);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.options_menu, menu);
return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {

if (item.getItemId() == R.id.item1) {
Toast.makeText(this, "Item 1 Selected", Toast.LENGTH_SHORT).show();
return true;
Vishal Vaishnav 200160107129

}
else if(item.getItemId() == R.id.item2){
Toast.makeText(this, "Item 2 Selected", Toast.LENGTH_SHORT).show();
return true;
}
else if(item.getItemId() == R.id.item3){
Toast.makeText(this, "Item 3 Selected", Toast.LENGTH_SHORT).show();
return true;
}

return super.onOptionsItemSelected(item);
}
}
Output:

References used by the students:


https://www.geeksforgeeks.org/android-tutorial/
https://www.javatpoint.com/android-tutorial

Rubric wise marks obtained:

Ethical and
Practical Problem Task Documentation
Professional
Understanding Solving Execution and Reporting
Rubrics Conduct Total
Good Avg. Good Avg. Good Avg. Good Avg. Good Avg.
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)

Marks
Vishal Vaishnav 200160107129

Practical-4
AIM: Create a Recycler View and list the details of student using following fields:
1. Name 2. Address 3. Photo (Image) 4. Delete (Button Operation)

Date:

Relevant CO: CO1, CO2

Theory :
RecyclerView is a ViewGroup added to the android studio as a successor of the GridView and
ListView. It is an improvement on both and can be found in the latest v-7 support packages. It
has been created to make possible construction of any lists with XML layouts as an item which
can be customized vastly while improving on the efficiency of ListViews and GridViews. This
improvement is achieved by recycling the views which are out of the visibility of the user. For
example, if a user scrolled down to a position where items 4 and 5 are visible; items 1, 2, and
3 would be cleared from the memory to reduce memory consumption.

To implement a basic RecyclerView three sub-parts are needed to be constructed which offer
the users the degree of control they require in making varying designs of their choice.

The Card Layout: The card layout is an XML layout which will be treated as an item for the
list created by the RecyclerView.

The ViewHolder: The ViewHolder is a java class that stores the reference to the card layout
views that must be dynamically modified during the execution of the program by a list of data
obtained either by online databases or added in some other way.

The Data Class: The Data class is a custom java class that acts as a structure for holding the
information for every item of the RecyclerView.

Steps for implementing your RecyclerView


If you are going to use RecyclerView, there are a few things you need to do. They are explained
in detail in the following sections.
1. Decide how the list or grid looks. Ordinarily, you can use one of the RecyclerView library's standard
layout managers.
2. Design how each element in the list looks and behaves. Based on this design, extend the ViewHolder
class. Your version of ViewHolder provides all the functionality for your list items. Your view holder
is a wrapper around a View, and that view is managed by RecyclerView.
3. Define the Adapter that associates your data with the ViewHolder views.

There are also advanced customization options that let you tailor your RecyclerView to your exact needs.

Plan your layout


The items in your RecyclerView are arranged by a LayoutManager class. The RecyclerView
library provides three layout managers, which handle the most common layout situations:

• LinearLayoutManager arranges the items in a one-dimensional list.


• GridLayoutManager arranges the items in a two-dimensional grid:
o If the grid is arranged vertically, GridLayoutManager tries to make all the elements in each
row have the same width and height, but different rows can have different heights.
o If the grid is arranged horizontally, GridLayoutManager tries to make all the elements in each
column have the same width and height, but different columns can have different widths.
• StaggeredGridLayoutManager is similar to GridLayoutManager, but it does not require that items in a
row have the same height (for vertical grids) or items in the same column have the same width (for
horizontal grids). The result is that the items in a row or column can end up offset from each other.
Vishal Vaishnav 200160107129

You also need to design the layout of the individual items. You need this layout when you
design the view holder, as described in the next section.

Implement your adapter and view holder


Once you determine your layout, you need to implement your Adapter and ViewHolder. These
two classes work together to define how your data is displayed. The ViewHolder is a wrapper
around a View that contains the layout for an individual item in the list. The Adapter creates
ViewHolder objects as needed and also sets the data for those views. The process of associating
views to their data is called binding.

When you define your adapter, you override three key methods:
• onCreateViewHolder(): RecyclerView calls this method whenever it needs to create a new ViewHolder.
The method creates and initializes the ViewHolder and its associated View, but does not fill in the view's
contents—the ViewHolder has not yet been bound to specific data.
• onBindViewHolder(): RecyclerView calls this method to associate a ViewHolder with data. The method
fetches the appropriate data and uses the data to fill in the view holder's layout. For example, if the
RecyclerView displays a list of names, the method might find the appropriate name in the list and fill in
the view holder's TextView widget.
• getItemCount(): RecyclerView calls this method to get the size of the dataset. For example, in an address
book app, this might be the total number of addresses. RecyclerView uses this to determine when there
are no more items that can be displayed.

Code:
Student_list_rec_view_model.xml
<?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="wrap_content"
android:orientation="horizontal"
android:paddingHorizontal="10dp"
android:paddingVertical="10dp"
>
<ImageView
android:id="@+id/studentImageView"
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@drawable/s1"
android:background="@color/black"
/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:paddingHorizontal="5dp"
>
<TextView
Vishal Vaishnav 200160107129

android:id="@+id/studentNameText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cleo"
android:textSize="16sp"
/>
<TextView
android:id="@+id/studentAddressText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Park Avenue Street"
android:textSize="16sp"
/>
</LinearLayout>
<Button
android:id="@+id/studentRemoveBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Remove"
android:layout_gravity="center_vertical"
/>
</LinearLayout>
Activity_student_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".prac4.StudentListActivity"
android:layout_marginHorizontal="10dp"
android:layout_marginVertical="10dp"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="Student List :"
android:textStyle="bold"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/studentListRecView"
Vishal Vaishnav 200160107129

android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:visibility="visible"
/>
</LinearLayout>

StudentListActivity.java
package com.vgec.collegeproject.prac4;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import com.vgec.collegeproject.R;
import java.util.ArrayList;
import java.util.List;
public class StudentListActivity extends AppCompatActivity {
public static List<Student> studentList = new ArrayList<>();
RecyclerView recyclerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_student_list);
studentList.add(new Student("Prit","BH-1, Vishwakarma government engineering college.",
R.drawable.s1));
studentList.add(new Student("Dharmik","BH-2, Vishwakarma government engineering college.",
R.drawable.s2));
studentList.add(new Student("Rutik","BH-1, Vishwakarma government engineering college.",
R.drawable.s3));
studentList.add(new Student("Sahil","BH-1, Vishwakarma government engineering college.",
R.drawable.s1));
studentList.add(new Student("Prakash","BH-2, Vishwakarma government engineering college.",
R.drawable.s2));
studentList.add(new Student("Sanket","BH-1, Vishwakarma government engineering college.",
R.drawable.s3));
recyclerView = findViewById(R.id.studentListRecView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
StudentListRecViewAdapter studentListRecViewAdapter = new
StudentListRecViewAdapter(StudentListActivity.this,studentList);
recyclerView.setAdapter(studentListRecViewAdapter);
}
}
Vishal Vaishnav 200160107129

StudentListRecViewAdapter.java
package com.vgec.collegeproject.prac4;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
public class StudentListRecViewAdapter extends
RecyclerView.Adapter<StudentListRecViewAdapter.StudentListRecViewHolder>{
Context mContext;
List<Student> studentList;
public StudentListRecViewAdapter(Context mContext, List<Student> studentList) {
this.mContext = mContext;
this.studentList = studentList;
}
@NonNull
@Override
public StudentListRecViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v= LayoutInflater.from(mContext).inflate(R.layout.student_list_rec_view_model,parent,false);
return new StudentListRecViewAdapter.StudentListRecViewHolder(v);
}
@Override
public void onBindViewHolder(@NonNull StudentListRecViewHolder holder, int position) {
Student student = studentList.get(position);
holder.name.setText(student.getName());
holder.address.setText(student.getAddress());
holder.photo.setImageResource(student.getImageUri());
holder.remove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
studentList.remove(holder.getAdapterPosition());
notifyItemRemoved(holder.getAdapterPosition());
notifyItemRangeChanged(holder.getAdapterPosition(), studentList.size());
}
});
}
@Override
public int getItemCount() {
return studentList.size();
}
class StudentListRecViewHolder extends RecyclerView.ViewHolder {
Vishal Vaishnav 200160107129

TextView name, address;


ImageView photo;
Button remove;
public StudentListRecViewHolder(@NonNull @NotNull View itemView) {
super(itemView);
name = itemView.findViewById(R.id.studentNameText);
address = itemView.findViewById(R.id.studentAddressText);
photo = itemView.findViewById(R.id.studentImageView);
remove = itemView.findViewById(R.id.studentRemoveBtn);
}
}
}

Output:

References used by the students:


https://www.geeksforgeeks.org/android-tutorial/
https://www.javatpoint.com/android-tutorial

Rubric wise marks obtained:

Ethical and
Practical Problem Task Documentation
Professional
Understanding Solving Execution and Reporting
Rubrics Conduct Total
Good Avg. Good Avg. Good Avg. Good Avg. Good Avg.
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)

Marks
Vishal Vaishnav 200160107129

Practical-5

AIM: Theme, Custom Styles, Drawables

Date:

Relevant CO: CO3

Theory :
The Android platform provides a large collection of styles and themes that you can use in your applications.
You can find a reference of all available styles in the R.style class. To use the styles listed here, replace all
underscores in the style name with a period. For example, you can apply the Theme_NoTitleBar theme with
"@android:style/Theme.NoTitleBar".

Material Theming Properties


The Main 3 properties to achieve functional material theme in Android application are:

1. Color
2. Typography
3. Shape
4. Material Design Components

Primary Color Variants:

Attribute Description Default


Value

This color primary color of the application. This color is the


colorPrimary most used color in the Application. This can also be called a #FF6200EE
branding color

This is the variant of the colorPrimary. This may be a lighter or


colorPrimaryVariant #FF3700B3
darker variant of the primary color.

The name itself indicates the color should be assigned to those


colorOnPrimary #FFFFFFFF
elements which are above the colorPrimary.

Applying Colors to Theme Attributes

Your color resource can then be applied to some theme attributes, such as the window background and the
primary text color, by adding <item> elements to your custom theme. These attributes are defined in your
styles.xml file. For example, to apply the custom color to the window background, add the following two
<item> elements to your custom theme, defined in MyAndroidApp/res/values/styles.xml file :

<resources>
...
<style name="MyCustomTheme" ...>
<item name="android:windowBackground">@color/my_custom_color</item>
<item name="android:colorBackgroundCacheHint">@color/my_custom_color</item>
</style>
...
</resources>
Vishal Vaishnav 200160107129

Drawable:

When you need to display static images in your app, you can use the Drawable class and its subclasses to
draw shapes and images. A Drawable is a general abstraction for something that can be drawn. The various
subclasses help with specific image scenarios, and you can extend them to define your own drawable objects
that behave in unique ways.

There are two ways to define and instantiate a Drawable besides using the class constructors:

• Inflate an image resource (a bitmap file) saved in your project.


• Inflate an XML resource that defines the drawable properties.

Create drawables from resource images

You can add graphics to your app by referencing an image file from your project resources. Supported file
types are PNG (preferred), JPG (acceptable), and GIF (discouraged). App icons, logos, and other graphics,
such as those used in games, are well suited for this technique.

To use an image resource, add your file to the res/drawable/ directory of your project. Once in your project,
you can reference the image resource from your code or your XML layout. Either way, it's referred to using
a resource ID, which is the file name without the file type extension. For example, refer to my_image.png as
my_image.

Code:

Activity_Seventh_practical.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".prac5.tcd"
android:orientation="vertical"
android:gravity="center_horizontal">
<Button
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="normal button"
/>
<Button
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="custom button"
android:background="@drawable/custom_btn"
/>
</LinearLayout>
Vishal Vaishnav 200160107129

SeventhPractical.java
package com.vgec.collegeproject.prac5;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.vgec.collegeproject.R;

public class tcd extends AppCompatActivity {


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

References used by the students:


https://www.geeksforgeeks.org/android-tutorial/
https://www.javatpoint.com/android-tutorial

Rubric wise marks obtained:

Ethical and
Practical Problem Task Documentation
Professional
Understanding Solving Execution and Reporting
Rubrics Conduct Total
Good Avg. Good Avg. Good Avg. Good Avg. Good Avg.
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)

Marks
Vishal Vaishnav 200160107129

Practical-6
AIM: Practical: Save user data in a database

Date:

Relevant CO: CO3

Theory:
SQLite is another data storage available in Android where we can store data in the user’s device and can use
it any time when required. In this article, we will take a look at creating an SQLite database in the Android
app and adding data to that database in the Android app.

Important Methods in SQLite Database


Below are the several important methods that we will be using in this SQLite database integration in
Android.

Method Description

This method is used to get the Array of column names of our


getColumnNames()
SQLite table.

getCount() This method will return the number of rows in the cursor.

This method returns a Boolean value when our cursor is


isClosed()
closed.

This method returns the total number of columns present in our


getColumnCount()
table.

getColumnName(int This method will return the name of the column when we
columnIndex) passed the index of our column in it.

getColumnIndex(String This method will return the index of our column from the name
columnName) of the column.

This method will return the current position of our cursor in our
getPosition()
table.

Database - Creation
In order to create a database you just need to call this method openOrCreateDatabase with your database
name and mode as a parameter. It returns an instance of SQLite database which you have to receive in your
own object.Its syntax is given below

SQLiteDatabase mydatabase =
openOrCreateDatabase("your database name",MODE_PRIVATE,null);

Database - Helper class


For managing all the operations related to the database , an helper class has been given and is called
SQLiteOpenHelper. It automatically manages the creation and update of the database. Its syntax is given
Vishal Vaishnav 200160107129

below

public class DBHelper extends SQLiteOpenHelper {


public DBHelper(){
super(context,DATABASE_NAME,null,1);
}
public void onCreate(SQLiteDatabase db) {}
public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {}
}

Database - Insertion
we can create table or insert data into table using execSQL method defined in SQLiteDatabase class. Its
syntax is given below
mydatabase.execSQL(
"CREATE TABLE IF NOT EXISTS
database(Username VARCHAR,Password VARCHAR);");
mydatabase.execSQL(
"INSERT INTO TutorialsPoint VALUES('admin','admin');");

Database - Fetching
We can retrieve anything from database using an object of the Cursor class. We will call a method of this
class called rawQuery and it will return a resultset with the cursor pointing to the table. We can move the
cursor forward and retrieve the data.

Cursor resultSet = mydatbase.rawQuery("Select * from TutorialsPoint",null);


resultSet.moveToFirst();
String username = resultSet.getString(0);
String password = resultSet.getString(1);

Code:

Activity_student_data.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".prac6.studentData">
<EditText
android:id="@+id/studentName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Enter student Name" />
<EditText
android:id="@+id/studentEnroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Vishal Vaishnav 200160107129

android:layout_margin="10dp"
android:hint="Enter Enrollment No" />
<!--edit text to display course tracks-->
<EditText
android:id="@+id/studentSem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Enter Student Semester" />
<Button
android:id="@+id/addStudent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Add Student"
android:textAllCaps="false" />
</LinearLayout>

StudentData.java
package com.vgec.collegeproject.prac6;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.vgec.collegeproject.R;

public class studentData extends AppCompatActivity {


private EditText studentName, enroll, sem;
private Button addStudentBtn;
private DBHandler dbHandler;

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

studentName = findViewById(R.id.studentName);
enroll = findViewById(R.id.studentEnroll);
sem = findViewById(R.id.studentSem);
addStudentBtn = findViewById(R.id.addStudent);
dbHandler = new DBHandler(this);
Vishal Vaishnav 200160107129

addStudentBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String name = studentName.getText().toString();
String enrol = enroll.getText().toString();
String semtext = sem.getText().toString();
dbHandler.addNewStudent(name, enrol, semtext);
Toast.makeText(studentData.this, "Student has been added", Toast.LENGTH_SHORT).show();
studentName.setText("");
enroll.setText("");
sem.setText("");
}
});
}
}

DBHandler.java
package com.vgec.collegeproject.prac6;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHandler extends SQLiteOpenHelper {


private static final String DB_NAME = "collegeDB";
private static final int DB_VERSION = 1;
private static final String TABLE_NAME = "student";
private static final String ID_COL = "id";
private static final String NAME_COL = "name";
private static final String ENROLL_COL = "enrollNo";
private static final String SEMESTER_COL = "sem";
public DBHandler(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String query = "CREATE TABLE " + TABLE_NAME + " ("
+ ID_COL + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ NAME_COL + " TEXT,"
+ ENROLL_COL + " TEXT,"
+ SEMESTER_COL + " TEXT)";
db.execSQL(query);
}

public void addNewStudent(String studentName, String enrolNo, String semester) {


SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(NAME_COL, studentName);
values.put(ENROLL_COL, enrolNo);
values.put(SEMESTER_COL, semester);
db.insert(TABLE_NAME, null, values);
Vishal Vaishnav 200160107129

db.close();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
}
Output:

References used by the students:


https://www.geeksforgeeks.org/android-tutorial/
https://www.javatpoint.com/android-tutorial

Rubric wise marks obtained:

Ethical and
Practical Problem Task Documentation
Professional
Understanding Solving Execution and Reporting
Rubrics Conduct Total
Good Avg. Good Avg. Good Avg. Good Avg. Good Avg.
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)

Marks
Vishal Vaishnav 200160107129

Practical-7

AIM: Get and Save User Preferences

Date:

Relevant CO: CO3, CO4

Theory :
One of the most Interesting Data Storage options Android provides its users is Shared Preferences. Shared
Preferences is the way in which one can store and retrieve small amounts of primitive data as key/value pairs
to a file on the device storage such as String, int, float, Boolean that make up your preferences in an XML file
inside the app on the device storage. Shared Preferences can be thought of as a dictionary or a key/value pair.
For example, you might have a key being “username” and for the value, you might store the user’s username.
And then you could retrieve that by its key (here username). You can have a simple shared preference API
that you can use to store preferences and pull them back as and when needed. The shared Preferences class
provides APIs for reading, writing, and managing this data.

Shared Preferences are suitable for different situations. For example, when the user’s settings need to be saved
or to store data that can be used in different activities within the app. As you know, onPause() will always be
called before your activity is placed in the background or destroyed, So for the data to be saved persistently,
it’s preferred to save it in onPause(), which could be restored in onCreate() of the activity. The data stored
using shared preferences are kept private within the scope of the application. However, shared preferences are
different from that activity’s instance state.

When you want to get the values, call the getSharedPreferences() method. Shared Preferences provide modes
of storing the data (private mode and public mode). It is for backward compatibility- use only
MODE_PRIVATE to be secure.

public abstract SharedPreferences getSharedPreferences (String name, int mode)

This method takes two arguments, the first being the name of the SharedPreference(SP) file and the other is
the context mode that we want to store our file in.

MODE_PUBLIC will make the file public which could be accessible by other applications on the device

MODE_PRIVATE keeps the files private and secures the user’s data.

MODE_APPEND is used while reading the data from the SP file.

Following are the methods of Shared Preferences :

• contains(String key): This method is used to check whether the preferences contain a preference.

• edit(): This method is used to create a new Editor for these preferences, through which you can make
modifications to the data in the preferences and atomically commit those changes back to the
SharedPreferences object.

• getAll(): This method is used to retrieve all values from the preferences.

• getBoolean(String key, boolean defValue): This method is used to retrieve a boolean value from the
preferences.

• getFloat(String key, float defValue): This method is used to retrieve a float value from the preferences.

• getInt(String key, int defValue): This method is used to retrieve an int value from the preferences.

• getLong(String key, long defValue): This method is used to retrieve a long value from the preferences.
Vishal Vaishnav 200160107129

• getString(String key, String defValue): This method is used to retrieve a String value from the
preferences.

• getStringSet(String key, Set defValues): This method is used to retrieve a set of String values from the
preferences.

• registerOnSharedPreferencechangeListener(SharedPreferences.OnSharedPreferencechangeListener
listener): This method is used to register a callback to be invoked when a change happens to a
preference.

• unregisterOnSharedPreferencechangeListener(SharedPreferences.OnSharedPreferencechangeListene
r listener): This method is used to unregister a previous callback.

Code:
activity_register.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".prac7.registerActivity"
android:orientation="vertical"
android:gravity="center_horizontal"
>

<TextView
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="REGISTER"
/>
<EditText
android:id="@+id/registerusername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter Username"
/>
<EditText
android:id="@+id/registerpassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter Password"
/>
<Button
android:id="@+id/registerSubmitBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="submit"
/>
</LinearLayout>

Activity_login.xml
Vishal Vaishnav 200160107129

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


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".prac7.LoginActivity"
android:orientation="vertical"
android:gravity="center_horizontal"
>
<TextView
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LOGIN"
/>
<Button
android:id="@+id/loginSubmitBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="login"
/>
</LinearLayout>

LoginActivity.java
package com.vgec.collegeproject.prac7;
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;
import android.widget.Toast;
import com.vgec.collegeproject.R;

public class LoginActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
EditText name,pass;
name = findViewById(R.id.loginusername);
pass = findViewById(R.id.loginpassword);
Vishal Vaishnav 200160107129

Button submit = findViewById(R.id.loginSubmitBtn);


submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
UserPreferences userPreferences = new UserPreferences(LoginActivity.this);
userPreferences.verifyUser(name.getText().toString(),pass.getText().toString());
}
});
}
}

RegisterActivity.java
package com.vgec.collegeproject.prac7;
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;
import android.widget.Toast;
import com.vgec.collegeproject.R;

public class registerActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
EditText name,pass;
name = findViewById(R.id.registerusername);
pass = findViewById(R.id.registerpassword);
Button submit = findViewById(R.id.registerSubmitBtn);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
UserPreferences userPreferences = new UserPreferences(registerActivity.this);
userPreferences.registerUser(name.getText().toString(),pass.getText().toString());
Toast.makeText(registerActivity.this, "Login using credentials",
public void verifyUser(String name,String pass) {
String usName = userSession.getString(KEY_NAME, null);
String usPass = userSession.getString(KEY_PASS, null);
if(name.equals(usName)){
if(pass.equals(usPass)){
Toast.makeText(context, "Login Sucessfull", Toast.LENGTH_SHORT).show();
Vishal Vaishnav 200160107129

}
else{
Toast.makeText(context, "Invalid user or password", Toast.LENGTH_SHORT).show();
}
}
else{
Toast.makeText(context, "Invalid user or password", Toast.LENGTH_SHORT).show();
}
}
}
Output:

References used by the students:


https://www.geeksforgeeks.org/android-tutorial/
https://www.javatpoint.com/android-tutorial

Rubric wise marks obtained:

Ethical and
Practical Problem Task Documentation
Professional
Understanding Solving Execution and Reporting
Rubrics Conduct Total
Good Avg. Good Avg. Good Avg. Good Avg. Good Avg.
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)

Marks
Vishal Vaishnav 200160107129

Practical – 8

Aim: make a use of android system


Date:

Relevant CO: CO5

Theory :
You will use MediaStore.ACTION_IMAGE_CAPTURE to launch an existing camera application installed
on your phone. Its syntax is given below

Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

Apart from the above, there are other available Intents provided by MediaStore. They are listed as follows

Sr.No Intent type and description


1. ACTION_IMAGE_CAPTURE_SECURE
It returns the image captured from the camera , when the device is secured

2.ACTION_VIDEO_CAPTURE
It calls the existing video application in android to capture video

3.EXTRA_SCREEN_ORIENTATION
It is used to set the orientation of the screen to vertical or landscape

4.EXTRA_FULL_SCREEN
It is used to control the user interface of the ViewImage

5.INTENT_ACTION_VIDEO_CAMERA
This intent is used to launch the camera in the video mode

6.EXTRA_SIZE_LIMIT
It is used to specify the size limit of video or image capture size

Code:
Activity_camera.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".prac8.CameraActivity"
android:orientation="vertical"
android:gravity="center_horizontal"
>
<Button
android:id="@+id/camera_button"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_marginTop="20dp"
android:text="Camera" />
<ImageView
Vishal Vaishnav 200160107129

android:id="@+id/click_image"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="20dp"
/>
</LinearLayout>

CameraActivity.java
package com.example.mad_practicals.Practical15;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

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

import com.example.mad_practicals.R;

public class FifteenPractical extends AppCompatActivity {

Button btnCapture;
ImageView imgCapture;
int CAM_CODE=100;

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

btnCapture=findViewById(R.id.btnCapture);
imgCapture=findViewById(R.id.imgCapture);

btnCapture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!checkcamPermission()){
askPermission();
}else {
captureImage();
}
}
});

}
Vishal Vaishnav 200160107129

Output:

References used by the students:


https://www.geeksforgeeks.org/android-tutorial/
https://www.javatpoint.com/android-tutorial

Rubric wise marks obtained:

Ethical and
Practical Problem Task Documentation
Professional
Understanding Solving Execution and Reporting
Rubrics Conduct Total
Good Avg. Good Avg. Good Avg. Good Avg. Good Avg.
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)

Marks
Vishal Vaishnav 200160107129

Practical – 9
AIM: Using location service get the current location and display in TextView.

Date:

Relevant CO: CO3, CO4

Theory :
A data class representing a geographic location. A location consists of a latitude, longitude, timestamp,
accuracy, and other information such as bearing, altitude and velocity.

All locations generated through LocationManager are guaranteed to have a valid latitude, longitude, timestamp
(both Unix epoch time and elapsed realtime since boot), and accuracy. All other parameters are optional.

Since using the user’s permission is a matter concerned with high privacy, first acquire the user’s permission
to use their location by requesting them for it. From Android 6.0(Marshmallow), the concept of run-time
permissions was rolled in and so the same will be used for getting permission. Any of the following
permissions can be used for this:

ACCESS_COARSE_LOCATION: It provides location accuracy within a city block.


<uses-permission android:name=”android.permission.ACCESS_COARSE_LOCATION”/>

• In order to get the last location of the user, make use of the Java public class
FusedLocationProviderClient. It is actually a location service that combines GPS location and network
location to achieve a balance between battery consumption and accuracy. GPS location is used to
provide accuracy and network location is used to get location when the user is indoors.
• In conjunction with FusedLocationProviderClient, LocationRequest public class is used to get the last
known location. On this LocationRequest object, set a variety of methods such as set the priority of
how accurate the location to be or in how many intervals, request of the location is to be made.
• If very high accuracy is required, use PRIORITY_HIGH_ACCURACY as an argument to the
setPriority(int) method. For a city level accuracy(low accuracy), use PRIORITY_LOW_POWER.
• Once the LocationRequest object is ready, set it on the FusedLocationProviderClient object to get the
final location.

Code:
Activity_location.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".prac9.LocationActivity"
android:orientation="vertical"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-black"
android:text="Latitude:" />
<TextView
android:id="@+id/latTextView"
android:layout_width="wrap_content"
Vishal Vaishnav 200160107129

android:layout_height="wrap_content"
android:text="Latitude will be here! "
android:textColor="#f5f5f5" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-black"
android:text="Longitude:" />
<TextView
android:id="@+id/lonTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Longitude will be here! "
android:textColor="#f5f5f5" />
</LinearLayout>

LocationActivity.java
package com.vgec.collegeproject.prac9;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Looper;
import android.provider.Settings;
import android.widget.TextView;

public class LocationActivity extends AppCompatActivity {


FusedLocationProviderClient mFusedLocationClient;
TextView latitudeTextView, longitTextView;
int PERMISSION_ID = 44;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_location);
latitudeTextView = findViewById(R.id.latTextView);
longitTextView = findViewById(R.id.lonTextView);
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
getLastLocation();
}
@SuppressLint("MissingPermission")
private void getLastLocation() {
if (checkPermissions()) {
if (isLocationEnabled()) {
mFusedLocationClient.getLastLocation().addOnCompleteListener(new
OnCompleteListener<Location>() {
@Override
public void onComplete(@NonNull Task<Location> task) {
Location location = task.getResult();
if (location == null) {
Vishal Vaishnav 200160107129

requestNewLocationData();
} else {
latitudeTextView.setText(location.getLatitude() + "");
longitTextView.setText(location.getLongitude() + "");
}
}
});
} else {
Toast.makeText(this, "Please turn on" + " your location...", Toast.LENGTH_LONG).show();
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
} else {
requestPermissions();
}
}
@SuppressLint("MissingPermission")
private void requestNewLocationData() {
LocationRequest mLocationRequest = new LocationRequest();
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setInterval(5);
mLocationRequest.setFastestInterval(0);
mLocationRequest.setNumUpdates(1);
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback,
Looper.myLooper());
}
private LocationCallback mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
Location mLastLocation = locationResult.getLastLocation();
latitudeTextView.setText("Latitude: " + mLastLocation.getLatitude() + "");
longitTextView.setText("Longitude: " + mLastLocation.getLongitude() + "");
}
};
private boolean checkPermissions() {
return ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) ==
PackageManager.PERMISSION_GRANTED;
}
private void requestPermissions() {
ActivityCompat.requestPermissions(this, new String[]{
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSION_ID);
}
private boolean isLocationEnabled() {
LocationManager locationManager = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) ||
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
}
@Override
public void
onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[]
grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
Vishal Vaishnav 200160107129

if (requestCode == PERMISSION_ID) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
getLastLocation();
}
}
}
@Override
public void onResume() {
super.onResume();
if (checkPermissions()) {
getLastLocation();
}
}
}

Output:

References used by the students:


https://www.geeksforgeeks.org/android-tutorial/
https://www.javatpoint.com/android-tutorial

Rubric wise marks obtained:

Ethical and
Practical Problem Task Documentation
Professional
Understanding Solving Execution and Reporting
Rubrics Conduct Total
Good Avg. Good Avg. Good Avg. Good Avg. Good Avg.
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)

Marks
Vishal Vaishnav 200160107129

Practical - 10
Aim: Display the use of animations.

Date:

Relevant CO: CO4

Theory :
Animation is the process of adding a motion effect to any view, image, or text. With the help of an animation,
you can add motion or can change the shape of a specific view. Animation in Android is generally used to
give your UI a rich look and feel. The animations are basically of three types as follows:

1. Property Animation
2. View Animation
3. Drawable Animation

1. Property Animation
Property Animation is one of the robust frameworks which allows animating almost everything. This is one
of the powerful and flexible animations which was introduced in Android 3.0. Property animation can be used
to add any animation in the CheckBox, RadioButtons, and widgets other than any view.
2. View Animation
View Animation can be used to add animation to a specific view to perform tweened animation on views.
Tweened animation calculates animation information such as size, rotation, start point, and endpoint. These
animations are slower and less flexible. An example of View animation can be used if we want to expand a
specific layout in that place we can use View Animation. The example of View Animation can be seen in
Expandable RecyclerView.
3. Drawable Animation
Drawable Animation is used if you want to animate one image over another. The simple way to understand is
to animate drawable is to load the series of drawable one after another to create an animation. A simple
example of drawable animation can be seen in many apps Splash screen on apps logo animation.

Important Methods Of Animation:

Methods Description

startAnimation() This method will start the animation.

clearAnimation() This method will clear the animation running on a specific view.

Code:
Activity_animation.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".prac10.AnimationActivity"
android:orientation="vertical"
android:gravity="center_horizontal">
<ImageView
android:id="@+id/imageview"
Vishal Vaishnav 200160107129

android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="20dp"
android:contentDescription="@string/app_name"
android:src="@drawable/ic_launcher_background"
/>
<Button
android:id="@+id/animatedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Animate"
android:layout_marginTop="20dp"
/>
</LinearLayout>

AnimationActivity.java
package com.vgec.collegeproject.prac10;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import com.vgec.collegeproject.R;

public class AnimationActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_animation);
Button blinkBTN = findViewById(R.id.animatedButton);
ImageView imageView = findViewById(R.id.imageview);
blinkBTN.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blink);
imageView.startAnimation(animation);
}
});
}
}
Output:
Vishal Vaishnav 200160107129

References used by the students:


https://www.geeksforgeeks.org/android-tutorial/
https://www.javatpoint.com/android-tutorial

Rubric wise marks obtained:

Ethical and
Practical Problem Task Documentation
Professional
Understanding Solving Execution and Reporting
Rubrics Conduct Total
Good Avg. Good Avg. Good Avg. Good Avg. Good Avg.
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)

Marks

You might also like