6CS4-24 - Mad Lab Manual - 2022-23
6CS4-24 - Mad Lab Manual - 2022-23
TABLE OF CONTENT
S.No. Topic/Name of Experiment Page
Number
GENERAL DETAILS
A Zero Lecture 1
To study Android Studio and android studio installation. Create “Hello
1 World” application 10
To understand Activity, Intent, Create sample application with login 12
2 module. (Check username and password).
3 Design simple GUI application with activity and intents e.g. calculator. 20
Develop an application that makes use of RSS Feed. 24
4
Write an application that draws basic graphical primitives on the screen 33
5
Create an android app for database creation using SQLite 36
6 Database.
7 Develop a native application that uses GPS location information 45
VISION
To create knowledge based society with scientific temper, team spirit and dignity of
labor to face the global competitive challenges
MISSION
To evolve and develop skill based systems for effective delivery of knowledge so as
to equip young professionals with dedication & commitment to excellence in all
spheres of life.
VISION
Evolve as a center of excellence with wider recognition and to adapt the rapid
innovationin Computer Engineering.
MISSION
To understand Activity, Intent, Create sample application with login module. (Check
2 username and password).
3 Design simple GUI application with activity and intents e.g. calculator.
Develop an application that makes use of RSS Feed.
4
Write an application that draws basic graphical primitives on the screen
5
Create an android app for database creation using SQLite Database.
6
Develop a native application that uses GPS location information
7
EVALUATION SCHEME
I+II Mid Term Examination Attendance and performance End Term Examination
Total Marks
Experiment Viva Total Attendance Performance Total Experiment Viva Total
15 5 20 15 5 20 15 5 20 60
LAB OUTCOMES
Lab Outcomes:
Discuss the components and different Layout for mobile application
6CS4-24.1
development framework for android
6CS4-24.2 Apply essential Android Programming concepts.
Analyze various Android applications related to layouts & rich uses
6CS4-24.3
interactive interfaces.
Develop Android applications related to mobile related server-less
6CS4-24.4 database like SQLITE.
The ability to understand and apply knowledge of mathematics, system analysis &
PSO1
design, Data Modelling, Cloud Technology, and latest tools to develop computer
based solutions in the areas of system software, Multimedia, Web Applications, Big
data analytics, IOT, Business Intelligence and Networking systems
PSO2 The ability to understand the evolutionary changes in computing, apply
standards and ethical practices in project development using latest tools &
Technologies to solve societal problems and meet the challenges of the future.
PSO3 The ability to employ modern computing tools and platforms to be an entrepreneur,
lifelong learning and higher studies
DO’S
Enter the lab on time and leave at proper time.
Wait for the previous class to leave before the next class enters.
Keep the bag outside in the respective racks.
Utilize lab hours in the corresponding.
Turn off the machine before leaving the lab unless a member of lab staff has specifically
told you not to do so.
Leave the labs at least as nice as you found them.
If you notice a problem with a piece of equipment (e.g. a computer doesn't respond) or the
room in general (e.g. cooling, heating, lighting) please report it to lab staff immediately.
Do not attempt to fix the problem yourself.
DON’TS
Don't abuse the equipment.
Do not adjust the heat or air conditioners. If you feel the temperature is not properly set,
inform lab staff; we will attempt to maintain a balance that is healthy for people and
machines.
Do not attempt to reboot a computer. Report problems to lab staff.
Do not remove or modify any software or file without permission.
Do not remove printers and machines from the network without being explicitly told to do
so by lab staff.
Don't monopolize equipment. If you're going to be away from your machine for more than
10 or 15 minutes, log out before leaving. This is both for the security of your account, and
to ensure that others are able to use the lab resources while you are not.
Don’t use internet, internet chat of any kind in your regular lab schedule.
Do not download or upload of MP3, JPG or MPEG files.
No games are allowed in the lab sessions.
No hardware including USB drives can be connected or disconnected in the labs without
prior permission of the lab in-charge.
No food or drink is allowed in the lab or near any of the equipment. Aside from the fact
that it leaves a mess and attracts pests, spilling anything on a keyboard or other piece of
computer equipment could cause permanent, irreparable, and costly damage. (and in fact
has) If you need to eat or drink, take a break and do so in the canteen.
Don’t bring any external material in the lab, except your lab record, copy and books.
Don’t bring the mobile phones in the lab. If necessary then keep them in silence mode.
Please be considerate of those around you, especially in terms of noise level. While labs
are a natural place for conversations of all types, kindly keep the volume turned down.
If you are having problems or questions, please go to either the faculty, lab in-charge or the lab
supporting staff. They will help you. We need your full support and cooperation for smooth
functioning of the lab.
All the students are supposed to prepare the theory regarding the next experiment/
Program.
Students are supposed to bring their lab records as per their lab schedule.
Previous experiment/program should be written in the lab record.
If applicable trace paper/graph paper must be pasted in lab record with proper labeling.
All the students must follow the instructions, failing which he/she may not be allowed in
the lab.
Zero Lecture
Procedure
▪ One experiment with its variants will be performed by the Batch in Each Lab.
▪ Students will perform experiments in the group of four (Self Help Group) for a time slot and
so on.
▪ For first 30 Minutes program for the Experiments will be explained.
▪ Students will Develop Coding in the remaining Session and perform the experiments.
▪ In last 30 minutes viva and lab records will be evaluated.
▪ Students will be directed to write all the experiments in their Lab Records.
Getting Started
You will be delighted, to know that you can start your Android application development on
either of the following operating systems −
Overview
Android Studio is the official IDE for android application development. It works based on
IntelliJIDEA, You can download the latest version of android studio from Android
Studio 2.2 Download, If you are new to installing Android Studio on windows, you will
find a file, which is named as android-studio-bundle- 143.3101438-windows.exe. So just
download and run on windows machine according to android studio wizard guideline.
If you are installing Android Studio on Mac or Linux, You can download the latest
version from Download, or Android Studio Linux Download, check the instructions
provided along with the downloaded file for MacOS and Linux. This tutorial will consider
that you are going to setup your environment on Windows machine having Windows 8.1
operating system.
Installation
So let's launch Android Studio.exe, Make sure before launch Android Studio, Our
Machine should required installed Java JDK. To install Java JDK, take a reference of
Android environment setup
Once you launched Android Studio, its time to mention JDK7 path or later version in
android studio installer.
Need to check the components, which are required to create applications, below the image
have selected Android Studio, Android SDK, Android Virtual Machine and
performance (Intel chip).
Need to specify the location of local machine path for Android studio and Android
SDK, below the image has taken default location of windows 8.1 x64 bit architecture.
Need to specify the ram space for Android emulator by default it would take 512MB
of local machine RAM.
At final stage, it would extract SDK packages into our local machine, it would take a
while time to finish the task and would take 2626MB of Hard disk space.
After done all above steps perfectly, you must get finish button and it going to be open android
studio project with Welcome to android studio message as shown below
You can start your application development by calling start a new android studio project. In a new
installation frame should ask Application name, package information and location of the project.
After entered application name, it going to be called select the form factors your application
runs on, here need to specify Minimum SDK, in our tutorial, I have declared as API23:
Android 6.0(Marshmallow)
The next level of installation should contain selecting the activity to mobile, it specifies the
default layout for Applications
At the final stage it going to be open development tool to write the application code.
To test your Android applications, you will need a virtual Android device. So before we
start writing our code, let us create an Android virtual device. Launch Android AVD
Manager Clicking AVD_Manager icon as shown below
After Click on a virtual device icon, it going to be shown by default virtual devices which
are present on your SDK, or else need to create a virtual device by clicking Create new
If your AVD is created successfully it means your environment is ready for Android
application development. If you like, you can close this window using top-right cross
button. Better you re-start your machine and once you are done with this last step, you are
ready to proceed for your first Android example but before that we will see few more
important concepts related to Android Application Development.
Experiment–1
AIM: To study Android Studio and android studio installation. Create “Hello World”
application.
Working:- Before Writing a Hello world code, you must know about XML tags. To write hello
word code, you should redirect to App>res>layout>Activity_main.xml
To show hello word, we need to call text view with layout (about text view and layout, you must
take references at Relative Layout and Text View).
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView android:text="@string/hello_world"
android:layout_width="550dp"
android:layout_height="wrap_content" />
</RelativeLayout>
OUTPUT:
Need to run the program by clicking Run> Run App or else need to call shift+f10 key. Finally,
result should be placed at Virtual devices as shown below.
Assignment:
1. Install android studio and Create “MYINFO” application and Display your Name, City
and Collage.
Experiment–2
Object: To understand Activity, Intent, Create sample application with login module.
CONCEPT:
A login application is the screen asking your credentials to login to some particular application. You
might have seen it when logging into facebook, twitter etc. This chapter explains, how to create a
login screen and how to manage security when false attempts are made. First you have to define two
TextView asking username and password of the user. The password TextView must have inputType
set to password. Its syntax is given below −
<EditText
android:id = "@+id/editText2"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:inputType = "textPassword" />
<EditText
android:id = "@+id/editText1"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
/>
Define a button with login text and set its onClick Property. After that define the function mentioned
in the onClick property in the java file.
<Button
android:id = "@+id/button1"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:onClick = "login"
android:text ="@string/Login"
/>
In the java file, inside the method of onClick get the username and passwords text using getText()
and toString() method and match it with the text using equals()function.
EditText username = (EditText)findViewById(R.id.editText1);
EditText password = (EditText)findViewById(R.id.editText2);
//correcct password
}else{
//wrong password
The last thing you need to do is to provide a security mechanism, so that unwanted attempts should
be avoided. For this initialize a variable and on each false attempt, decrement it. And when it reaches
to 0, disable the login button.
int counter =
3; counter--;
if(counter==0){
//disble the button, close the application e.t.c
}
Example
Here is an example demonstrating a login application. It creates a basic application that gives you
only three attempts to login to an application.
To experiment with this example, you can run this on an actual device or in an emulator.
Steps Description
1 You will use Android studio to create an Android application under a package
com.example.sairamkrishna.myapplication.
5 Run the application and choose a running android device and install the application on it and
verify the results
package com.example.sairamkrishna.myapplication;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 =(Button)findViewById(R.id.button);
ed1 = (EditText)findViewById(R.id.editText); ed2 =
(EditText)findViewById(R.id.editText2);
b2 = (Button)findViewById(R.id.button2);
tx1 = (TextView)findViewById(R.id.textView3); tx1.setVisibility(View.GONE);
tx1.setVisibility(View.VISIBLE);
tx1.setBackgroundColor(Color.RED); counter--;
tx1.setText(Integer.toString(counter));
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering
if (counter== 0) {
b1.setEnabled(false);
}
}
}
});
b2.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v)
{ finish();
}
});
}
}
Following is the modified content of the xml res/layout/activity_main.xml.
\
In the following code abc indicates about logo oftutorialspoint.com
<TextView
android:layout_width = "wrap_content"
android:layout_height = "wrap_content" android:text =
"Tutorials point" android:id = "@+id/textView"
android:layout_below = "@+id/textview"
android:layout_centerHorizontal = "true" android:textColor
= "#ff7aff24" android:textSize = "35dp" />
<EditText
android:layout_width = "wrap_content"
android:layout_height = "wrap_content" android:id =
"@+id/editText" android:hint = "Enter Name"
android:focusable = "true" android:textColorHighlight =
"#ff7eff15" android:textColorHint = "#ffff25e6"
android:layout_marginTop = "46dp" android:layout_below =
"@+id/imageView" android:layout_alignParentLeft = "true"
android:layout_alignParentStart = "true"
android:layout_alignParentRight = "true"
android:layout_alignParentEnd = "true"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/abc"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword" android:ems="10"
android:id="@+id/editText2"
android:layout_below="@+id/editText"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/editText"
android:layout_alignEnd="@+id/editText"
android:textColorHint="#ffff299f" android:hint="Password"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Attempts Left:"
android:id="@+id/textView2"
android:layout_below="@+id/editText2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="25dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/textView3"
android:layout_alignTop="@+id/textView2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignBottom="@+id/textView2"
android:layout_toEndOf="@+id/textview"
android:textSize="25dp"
android:layout_toRightOf="@+id/textview" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="login"
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/textview"
android:layout_toStartOf="@+id/textview" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel" android:id="@+id/button2"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/textview"
android:layout_toEndOf="@+id/textview" />
</RelativeLayout>
Following is the content of theres/values/string.xml.
<resources>
<string name="app_name">My Application</string>
</resources>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
OUTPUT
Click Run icon from the toolbar. Android studio installs the app on your AVD and Starts it and if
everything is fine with your setup and application, it will display following Emulator window−
Type anything in the username and password field, and then press the login button. I put abc in the
username field and abc in the password field. I got failed attempt. This is shown below
Do this two more time, and you will see that you have 0 login attempts left and your login button is
disabled.
Now open the application again, and this time enter correct username as admin and password as
admin and click on login. You will be successfully login.
Experiment–3
Object: Design simple GUI application with activity and intents e.g. calculator.
PROGRAMS:
activity_main.xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.andr
oid.com/tools"android:layout_width="match_parent" android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ex_no_3.MainActivity" >
<EditText android:id="@+id/editText1"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_alignParentRight="true"
android:layout_alignParentTop="true" android:ems="10"
android:hint="Enter the first number"
tools:ignore="TextFields,HardcodedText">
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_alignParentRight="true"
android:layout_below="@+id/editText1" android:ems="10"
android:hint="Enter the second number"
tools:ignore="TextFields,HardcodedText" />
<Button
android:id="@+id/button4" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" android:layout_below="@+id/button3"
android:text="DIV" tools:ignore="HardcodedText" />
<Button
android:id="@+id/button1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" android:layout_below="@+id/editText2"
android:text="ADD" tools:ignore="HardcodedText" />
<Button
android:id="@+id/button2" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" android:layout_below="@+id/button1"
<Button
android:id="@+id/button3" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" android:layout_below="@+id/button2"
android:text="MUL" tools:ignore="HardcodedText" />
<TextView
android:id="@+id/textView1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_below="@+id/button4"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
MainActivity.java:
packagecom.example.ex_no_3;
import android.support.v7.app.ActionBarActivity;
importandroid.os.Bundle;
importandroid.view.View;
import android.view.View.OnClickListener;
import android.widget.Button; import android.widget.EditText; import
android.widget.TextView;
public class MainActivity extends ActionBarActivity {
intn1,n2; floatnum1,num2;@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditTexte1=(EditText)findViewById(R.id.editText1); final
EditTexte2=(EditText)findViewById(R.id.editText2);
Buttonb1=(Button)findViewById(R.id.button1);
Button b2=(Button)findViewById(R.id.button2); Button
b3=(Button)findViewById(R.id.button3); Buttonb4=(Button)findViewById(R.id.button4);
final TextView t=(TextView)findViewById(R.id.textView1); b1.setOnClickListener(
new OnClickListener()
{
@Override
public void onClick(View arg0){
// TODO Auto-generated method stub n1=Integer.parseInt(e1.getText().toString());
n2=Integer.parseInt(e2.getText().toString()); t.setText(e1.getText().toString()+" +
"+e2.getText().toString()+" = "+(n1+n2));
}
});
b2.setOnClickListener(
new OnClickListener()
{ @Override
{
public void onClick(View arg0)
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering
//TODOAuto-generatedmethodstub
n1=Integer.parseInt(e1.getText().toStr ing());
n2=Integer.parseInt(e2.getText().toStr ing());
t.setText(e1.getText().toString()+"* "+e2.getText().toString()+"="+(n1*n2));
});
b4.setOnClickListener(
newOnClickListener()
@Override
publicvoidonClick(Viewarg0){
//TODOAuto-generatedmethodstub
num1=Float.parseFloat(e1.getText().toS tring());
num2=Float.parseFloat(e2.getText().toS tring());
t.setText(e1.getText().toString()+"/ "+e2.getText().toString()+"="+(num1/num2));
}
});
Output:
Experiment–4
PROGRAMS:
activity_main.xml:
<?xmlversion="1.0"encoding="utf-8"?>
<FrameLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:id="@+id/fragment_container"
android:layout_height="fill_parent"/>
fragement_layout.xml:
<?xmlversion="1.0"encoding="utf-8"?>
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="vertical">
<ListView
android:id="@+id/listView" android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_centerInParent="true"/>
</RelativeLayout>
rss_item.xml:
<?xmlversion="1.0"encoding="utf-8"?>
<TextViewxmlns:android="http://schemas.android.com/apk/res/android"
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/itemTitle"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:textSize="18dp" tools:ignore="SpUsage"/>
MainActivity.java:
packagecom.example.ex_no_8; importandroid.os.Bundle;
import
android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import
android.support.v4.app.FragmentTransaction; public class MainActivity extends FragmentActivity {
@Override
addRssFragment();
privatevoidaddRssFragment(){
@Override
protectedvoid
onSaveInstanceState(Bundle outState){ super.onSaveInstanceState(outState
);
outState.putBoolean("fragment_adde d", true);
Constants.java
packagecom.example.ex_no_8; publicclassConstants{
publicstaticfinalStringTAG="RssApp";
}
PcWorldRssParser.java
packagecom.example.ex_no_8;
importjava.util.List;
importorg.xmlpull.v1.XmlPullParser;
importorg.xmlpull.v1.XmlPullParserException; importandroid.util.Xml;
publicclassPcWorldRssParser{
IOException{
try {
XmlPullParserparser=Xml.newPullParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAME
SPACES,false);parser.setInput(inputStream,null); parser.nextTag();
return readFeed(parser);
}finally{
inputStream.close();
}
privateList<RssItem>readFeed(XmlPullParserparser)throws XmlPullParserException,IOException{
parser.require(XmlPullParser.START_TAG,null,"rss"); Stringtitle=null;
Stringlink=null;
Stringname=parser.getName(); if(name.equals("title")){
title=readTitle(parser);
}elseif(name.equals("link")){
link=readLink(parser);
if(title!=null&&link!=null){
RssItemitem=newRssItem(title,link); items.add(item);
returnitems;
privateStringreadLink(XmlPullParserparser)throwsXmlPullParserException, IOException
privateStringreadTitle(XmlPullParserparser)throws XmlPullParserException,IOException{
//Forthetagstitleandlink,extracttheirtextvalues.
privateStringreadText(XmlPullParserparser)throwsIOException, XmlPullParserException
Stringresult="";
returnresult;
RssAdapter.java
packagecom.example.ex_no_8; importjava.util.List;
importandroid.widget.TextView;
publicclassRssAdapterextendsBaseAdapter{ privatefinalList<RssItem>items;
privatefinalContextcontext;
publicRssAdapter(Contextcontext, List<RssItem>items){this.items
=items;
this.context=context;
@Override
publicintgetCount(){ returnitems.size();
}
@Override
publicObjectgetItem(intposition){
returnitems.get(position);
@Override
publiclonggetItemId(intid){
return id;
@Override
publicViewgetView(intposition,ViewconvertView, ViewGroupparent){ViewHolderholder;
if(convertView==null){
holder.itemTitle=(TextView) convertView.findViewById(R.id.itemTitle);
convertView.setTag(holder);
} else {
holder=(ViewHolder)convertView.getTag();
staticclass ViewHolder{
TextViewitemTitle;
RssFragement.java
packagecom.example.ex_no_8; importjava.util.List;
importandroid.content.Intent; importandroid.net.Uri;
importandroid.os.Bundle; importandroid.os.Handler;
importandroid.os.ResultReceiver; importandroid.support.v4.app.Fragment;
importandroid.view.LayoutInflater; importandroid.view.View;
importandroid.view.ViewGroup; importandroid.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; import
android.widget.ProgressBar;
importandroid.widget.Toast;
publicclassRssFragmentextendsFragmentimplements OnItemClickListener{privateProgressBar
progressBar;
@Override
publicViewonCreateView(LayoutInflaterinflater,ViewGroup container,BundlesavedInstanceState){
if(view==null){
view=inflater.inflate(R.layout.fragment_layout, container,false);progressBar=(ProgressBar)
view.findViewById(R.id.progressBar);listView= (ListView)view.findViewById(R.id.listView);
listView.setOnItemClickListener(this); startService();
} else {
ViewGroupparent=(ViewGroup)view.getParent(); parent.removeView(view);
returnview;
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering
privatevoidstartService(){
privatefinalResultReceiverresultReceiver=new ResultReceiver(newHandler()){
@SuppressWarnings("unchecked")
@Override
protectedvoidonReceiveResult(intresultCode, BundleresultData){
progressBar.setVisibility(View.GONE);
List<RssItem>items=(List<RssItem>) resultData.getSerializable(RssService.ITEMS);
if(items!=null){
} else {
Toast.makeText(getActivity(),"Anerroroccuredwhiledownloading therssfeed.",
Toast.LENGTH_LONG).show();
};
};
@Override
publicvoidonItemClick(AdapterView<?>parent,Viewview,int
position,longid){RssAdapteradapter=(RssAdapter) parent.getAdapter();
RssItem item = (RssItem) adapter.getItem(position); Uri uri = Uri.parse(item.getLink());
RssItem.java
packagecom.example.ex_no_8;
publicclassRssItem{
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering
privatefinalStringtitle; privatefinalStringlink;
publicRssItem(Stringtitle,Stringlink){ this.title=title;
this.link=link;
RssService.java
packagecom.example.ex_no_8; importjava.io.IOException;
importorg.xmlpull.v1.XmlPullParserException;
importandroid.app.IntentService;
importandroid.content.Intent; importandroid.os.Bundle;
importandroid.os.ResultReceiver; importandroid.util.Log;
publicclassRssServiceextendsIntentService{
publicstaticfinalStringRECEIVER
="receiver";publicRssService(){ super("RssService");
}
@Override
protectedvoidonHandleIntent(Intent intent){Log.d(Constants.TAG,
"Servicestarted");List<RssItem>rssItems=null;
try {
} catch
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering
Bundlebundle=newBundle();
publicInputStream
getInputStream(Stringlink){ try {
URLurl=newURL(link);
Log.w(Constants.TAG,"Exceptionwhileretrievingthe inputstream",e);returnnull;
}
Output:
Experiment–5
Object: Write an application that draws basic graphical primitives on the screen
PROGRAM:
activity_main.xml:
<RelativeLayoutxmlns: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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ex_no_7.MainActivity">
<ImageView
android:id="@+id/imageView1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher" tools:ignore="ContentDescription"/>
</RelativeLayout>
MainActivity.java:
packagecom.example.ex_no_7;
import android.support.v7.app.ActionBarActivity;
import android.annotation.SuppressLint;
importandroid.graphics.Bitmap;
importandroid.view.View;
importandroid.view.View.OnTouchListener; importandroid.widget.ImageView;
@SuppressLint("ClickableViewAccessibility")
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering
publicclassMainActivityextendsActionBarActivityimplements OnTouchListener{ImageViewiv;
Bitmapb;
Canvas c; Paintp;
float dx=0,dy=0,ux=0,uy=0;
@SuppressWarnings("deprecation") @Override
protectedvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); iv=(ImageView)this.findViewById(R.id.imageView1);
Displayd=getWindowManager().getDefaultDisplay(); floatdw=d.getWidth();
floatdh=d.getHeight();
b=Bitmap.createBitmap((int)dw,(int) dh,Bitmap.Config.ARGB_8888);
c=newCanvas(b);p=newPaint();
p.setColor(Color.BLUE);
iv.setImageBitmap(b); iv.setOnTouchListener(this);
}
@Override
publicbooleanonTouch(Viewv,MotionEventevent){
//TODOAuto-generated methodstubintaction
=event.getAction(); switch(action)
{
caseMotionEvent.ACTION_DOWN:
caseMotionEvent.ACTION_UP:
ux=event.getX(); uy=event.getY();
c.drawLine(dx,dy,ux,uy,p); iv.invalidate();
break;
caseMotionEvent.ACTION_CANCEL:
break; default:
break;
return true;
}
}
Output:
Experiment-6
Object: Create an android app for database creation using SQLite Database
PROGRAMS:
activity_main.xml:
<RelativeLayoutxmlns: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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ex_no_4.MainActivity">
<TextView
android:id="@+id/textView1" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" android:text="Reg.No."
android:textAppearance="?android:attr/textAppearanceMedium"
tools:ignore="HardcodedText"/>
<EditText
android:id="@+id/editText1" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/textView1"
android:layout_toRightOf="@+id/textView1"
android:ems="10" android:inputType="number">
<requestFocus/>
</EditText>
<TextView
android:id="@+id/textView2" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/editText1"
android:layout_marginTop="20dp" android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:ignore="HardcodedText"/>
<TextView
android:id="@+id/textView3" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/editText2"
android:layout_marginTop="26dp" android:text="Marks"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:ignore="HardcodedText"/>
<EditText
android:id="@+id/editText3" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView3"
android:layout_alignLeft="@+id/editText2"
android:ems="10" android:inputType="number"/>
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_alignLeft="@+id/editText1"
android:ems="10" tools:ignore="TextFields"/>
<Button
android:id="@+id/button1" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView3"
android:layout_marginTop="32dp" android:text="ADD"
tools:ignore="HardcodedText"/>
<Button
android:id="@+id/button3" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button2"
android:layout_alignBottom="@+id/button2"
android:layout_alignParentRight="true" android:text="VIEWALL"
tools:ignore="HardcodedText"/>
<Button
android:id="@+id/button2" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1"
android:layout_alignLeft="@+id/editText3"
android:layout_marginLeft="24dp" android:text="VIEW"
tools:ignore="HardcodedText"/>
<Button
android:id="@+id/button4" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button1"
android:layout_marginLeft="27dp"
android:layout_marginTop="18dp" android:text="UPDATE"
tools:ignore="HardcodedText"/>
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button4"
android:layout_alignBottom="@+id/button4"
android:layout_marginLeft="20dp"
android:layout_toRightOf="@+id/button4"
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering
android:text="DELETE" tools:ignore="HardcodedText"/>
</RelativeLayout>
MainActivity.java:
packagecom.example.ex_no_4;
import android.support.v7.app.ActionBarActivity;
importandroid.app.AlertDialog.Builder;
importandroid.content.Context;
importandroid.database.Cursor;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;
importandroid.widget.EditText; publicclassMainActivityextends
ActionBarActivity{EditText
name,regno,mark;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
regno=(EditText)findViewById(R.id.editText1);
name=(EditText)findViewById(R.id.editText2);
mark=(EditText)findViewById(R.id.editText3);
btnAdd=(Button)findViewById(R.id.button1);
btnView=(Button)findViewById(R.id.button2);
btnViewAll=(Button)findViewById(R.id.button3);
btnUpdate=(Button)findViewById(R.id.button4);
btnDelete=(Button)findViewById(R.id.button5);
db=openOrCreateDatabase("Students",Context.MODE_PRIVATE,n
ull);
db.execSQL("CREATETABLEIFNOTEXISTSstudent(regnoVAR
CHAR,name VARCHR,mark
VARCHAR);");
btnAdd.setOnClickListener(newOnClickListener()
@Override
publicvoidonClick(Viewarg0){
//TODOAuto-generatedmethodstub
if(regno.getText().toString().trim().length()==0||name.getText().toSt
ring().trim().len
gth()==0||mark.getText().toString().trim().length()==0)
showMessage("Error","Please enterallvalues");return;
db.execSQL("INSERTINTOstudent
VALUES('"+regno.getText()+"','"+name.getText()+"','"+mark.getT
ext ()+"');");
showMessage("Success","Recordadded"); clearText();
}
});
btnDelete.setOnClickListener(newOnClickListener()
@Override
publicvoidonClick(Viewv){
//TODOAuto-generatedmethodstub
if(regno.getText().toString().trim().length()==0)
showMessage("Error","PleaseenterReg.No."); return; }
Cursorc=db.rawQuery("SELECT*
FROMstudentWHEREregno='"+regno.getText()+"'", null);
if(c.moveToFirst())
else
showMessage("Error","InvalidReg.No.");
clearText();
});
btnUpdate.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(Viewv){
//TODOAuto-generatedmethodstub
if(regno.getText().toString().trim().length()==0)
{
showMessage("Error","PleaseenterReg.No.");
return;
Cursorc=db.rawQuery("SELECT*FROM
studentWHEREregno='"+regno.getText()+"'",null);
if(c.moveToFirst())
db.execSQL("UPDATEstudentSET
name='"+name.getText()+"',mark='"+mark.getText()+"'WHERE
regno='"+regno.getText()+"'");
showMessage("Success","Record
Modified");
} else
{
showMessage("Error","InvalidReg. No.");
} clearText();
});
btnView.setOnClickListener(newOnClickListener()
@Override
publicvoidonClick(Viewv){
//TODOAuto-generatedmethodstub
if(regno.getText().toString().trim().length()==0)
showMessage("Error","Please enterReg.No.");return;
Cursorc=db.rawQuery("SELECT*FROM
studentWHEREregno='"+regno.getText()+"'",null);
if(c.moveToFirst())
name.setText(c.getString(1)); mark.setText(c.getString(2));
} else
{
showMessage("Error","InvalidReg.No."); clearText();
}
});
btnViewAll.setOnClickListener(newOnClickListener()
@Override
publicvoidonClick(Viewv){
//TODOAuto-generatedmethodstub
Cursorc=db.rawQuery("SELECT*FROMstudent",null);
if(c.getCount()==0)
{
showMessage("Error","Norecordsfound"); return;
}
StringBufferbuffer=newStringBuffer(); while(c.moveToNext())
buffer.append("Reg.No:"+c.getString(0)+"\n");
buffer.append("Name:"+c.getString(1)+"\n");
buffer.append("Mark:"+c.getString(2)+"\n\n");
}
showMessage("StudentDetails",buffer.toString());
});
publicvoidshowMessage(Stringtitle,Stringmessage)
Builderbuilder=newBuilder(this); builder.setCancelable(true);
builder.setTitle(title); builder.setMessage(message); builder.show();
}
publicvoidclearText()
{
regno.setText("");
name.setText("");
mark.setText(""); regno.requestFocus();
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering
Output
Thus the application that makes use of database has been developed and the output was
verified.
Experiment-7
PROGRAM:
activity_main.xml:
<RelativeLayoutxmlns: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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ex_no_5.MainActivity">
<TextView
android:id="@+id/textView1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" android:layout_alignParentTop="true"
android:layout_marginTop="114dp" android:text=""
android:textAppearance="?android:attr/textAppearanceMedium
tools:ignore="HardcodedText"/>
<TextView
android:id="@+id/textView2" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1"
android:layout_alignParentRight="true"
android:layout_below="@+id/textView1" android:layout_marginTop="51dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
tools:ignore="HardcodedText"/>
<TextView
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering
android:id="@+id/textView3" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" android:layout_marginTop="47dp"
android:text="CurrentLocation"
android:textAppearance="?android:attr/textAppearanceLarge"
tools:ignore="HardcodedText"/>
</RelativeLayout>
MainActivity.java:
packagecom.example.ex_no_5;
import android.support.v7.app.ActionBarActivity;
importandroid.content.Context;import android.location.Criteria;
importandroid.location.Location;
importandroid.location.LocationListener; importandroid.location.LocationManager;
importandroid.os.Bundle;
importandroid.widget.TextView; importandroid.widget.Toast;
publicclassMainActivityextendsActionBarActivityimplements
LocationListener{@Override
LocationManager
lm=(LocationManager)getSystemService(Context.LOCATION_SERVICE);Criteria
c=new Criteria();
Strings=lm.getBestProvider(c,false); if(s!=null&&!s.equals(""))
Locationl=lm.getLastKnownLocation(s); lm.requestLocationUpdates(s,20000,1,this);
if(l!=null)
onLocationChanged(l);
else
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering
Toast.makeText(getApplicationContext(),
"Locationcan'tberetrieved!!!",Toast.LENGTH_LONG).show();
}
else
Toast.makeText(getApplicationContext(),"Provider
notfound!!!",Toast.LENGTH_LONG).show();
@Override
publicvoid
onLocationChanged(Location arg0){//TODOAuto- generatedmethodstub
@Override
publicvoidonProviderDisabled(Stringarg0){
//TODOAuto-generatedmethodstub
@Override
publicvoidonProviderEnabled(Stringarg0){
//TODOAuto-generatedmethodstub
}
@Override
publicvoidonStatusChanged(Stringarg0,intarg1, Bundlearg2){//TODOAuto-
generatedmethod stub
}
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering
Output:
Experiment-8
PROGRAM:
activity_main.xml:
<RelativeLayoutxmlns: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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ex_no_6.MainActivity">
<EditText
android:id="@+id/editText1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" android:ems="10"
android:hint="Path" tools:ignore="TextFields,HardcodedText">
<requestFocus/>
</EditText>
<Button
android:id="@+id/button1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignTop="@+id/editText1"
android:layout_toRightOf="@+id/editText1" android:text="READ"
tools:ignore="HardcodedText"/>
<EditText
android:id="@+id/editText2" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignLeft="@+id/editText1"
android:layout_centerVertical="true" android:ems="10"
android:hint="ContentsofFile"
android:inputType="textMultiLine" tools:ignore="HardcodedText"/>
<Button
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering
android:id="@+id/button2" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentRight="true"
android:layout_centerVertical="true" android:text="SAVE" tools:ignore="HardcodedText"/>
</RelativeLayout>
MainActivity.java:
packagecom.example.ex_no_6;
importjava.io.BufferedReader; importjava.io.File;
importjava.io.FileNotFoundException; importjava.io.FileReader;
importjava.io.FileWriter; importjava.io.IOException;
import android.support.v7.app.ActionBarActivity; import android.annotation.SuppressLint;
importandroid.content.SharedPreferences;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.view.View.OnClickListener; importandroid.widget.Button;
importandroid.widget.EditText;
importandroid.widget.Toast; publicclassMainActivityextends
ActionBarActivity{ @SuppressLint("SdCardPath")
@Override
Buttonb1=(Button)findViewById(R.id.button1);
Buttonb2=(Button)findViewById(R.id.button2);
Stringpath=getPreferences(MODE_PRIVATE).getString("fpath", "/sdcard/file1");e1.setText(path);
b1.setOnClickListener(
newOnClickListener()
@Override
publicvoidonClick(Viewarg0){
//TODOAuto-generatedmethodstub
Strings="";
StringBuildersb=newStringBuilder(); FileReaderfr=null;
try {
fr=newFileReader(f);
}catch(FileNotFoundExceptione){
//TODOAuto-generatedcatch block
e.printStackTrace();
BufferedReaderbr=new BufferedReader(fr);
try {
while((s=br.readLine())!=null)
sb.append(s+"\n");
}catch(IOExceptione){
e.printStackTrace();
Toast.makeText(getApplicationContext(
),"FileReadSuccessfully!!!",Toast.LENGTH_LONG).show();
e2.setText(sb);
});
b2.setOnClickListener(
newOnClickListener()
@Override
publicvoidonClick(Viewarg0){
//TODOAuto-generatedmethodstub
}catch(IOExceptione3){
//TODOAuto-generatedcatch block
e3.printStackTrace();
try {
fw.write(e2.getText().toString()
);
}catch(IOExceptione2){
e2.printStackTrace();
try {
fw.close();
}catch(IOExceptione2){
//TODOAuto-generatedcatch block
e2.printStackTrace();
SharedPreferences.Editor
e=getPreferences(MODE_PRIVATE).edit();
e.putString("fpath",f.getPath());
e.commit(); Toast.makeText(getApplicationContext()
, "Saved Successfully!!!",Toast.LENGTH_LONG).show();
}});
}}
Output:
Experiment-9
PROGRAM:
activity_main.xml:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"
android:layout_height="match_parent" tools:context=".MainActivity">
<TextView android:id="@+id/textView"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="23dp" android:text="@string/heading" android:textSize="36sp"
android:textStyle="bold" app:fontFamily="cursive" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" app:srcCompat="@drawable/grid" />
<LinearLayout
android:layout_width="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:orientation="horizontal">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_weight="1"
android:orientation="horizontal">
android:layout_height="match_parent" android:layout_weight="1"
android:onClick="playerTap" android:padding="20sp" android:tag="6" />
android:padding="20sp" android:tag="7"/>
</LinearLayout>
<TextView android:id="@+id/status"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="15sp" android:text="@string/status"
android:textSize="18sp" android:textStyle="italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayout"/>
</androidx.constraintlayout.widget.ConstraintLayout>
File:- MainActivity.java
package com.poornima.tictactoe;
// Player representation
// 0 -X
// 1 -O
int activePlayer = 0;
// Statemeanings:
// 0 -X
// 1 -O
// 2 -Null
{0,4,8}, {2,4,6}};
img.setImageResource(R.drawable.o); activePlayer = 0;
TextView status = findViewById(R.id.status); status.setText("X's Turn - Tap to play");
}
img.animate().translationYBy(1000f).setDuration(300);
else{
((ImageView)findViewById(R.id.imageView0)).setImageResource(0);
((ImageView)findViewById(R.id.imageView1)).setImageResource(0);
((ImageView)findViewById(R.id.imageView2)).setImageResource(0);
((ImageView)findViewById(R.id.imageView3)).setImageResource(0);
((ImageView)findViewById(R.id.imageView4)).setImageResource(0);
((ImageView)findViewById(R.id.imageView5)).setImageResource(0);
((ImageView)findViewById(R.id.imageView6)).setImageResource(0);
((ImageView)findViewById(R.id.imageView7)).setImageResource(0);
((ImageView)findViewById(R.id.imageView8)).setImageResource(0);
Output:
Experiment-10
activity_main.xml
Drag the VideoView from the pallete, now the activity_main.xml file will like this:
File: activity_main.xml
tools:context=".MainActivity" >
<VideoView
android:id="@+id/videoView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
Activity class
Let's write the code of to play the video file. Here, we are going to play 1.mp4 file located inside
the sdcard/media directory.
File: MainActivity.java
package com.example.video1;
importandroid.net.Uri;
importandroid.os.Bundle;
importandroid.app.Activity;
importandroid.view.Menu;
importandroid.widget.MediaController;
import android.widget.VideoView; 9.
public class MainActivity extends Activity {
@Override
//CreatingMediaController
MediaController mediaController= newMediaController(this);
mediaController.setAnchorView(videoView); 22.
//specify the location of mediafile
Uri uri=Uri.parse(Environment.getExternalStorageDirectory().getPath()+"/m
edia/1.mp4");
RESULT:
Thus the application that uses GUI Components, Fonts, handle images and videos
and Colors has been developed and the output was verified.
Program:
package example.abhiandroid.galleryexample;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
public class CustomGalleryAdapter extends BaseAdapter {
private Context context;
private int[] images;
param
return imageView;
}
}
Code for main:
package example.abhiandroid.galleryexample;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Gallery;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
Gallery simpleGallery;
CustomGalleryAdapter customGalleryAdapter;
ImageView selectedImageView;
// array of images
int[] images = {R.drawable.image1, R.drawable.image2, R.drawable.image3,
R.drawable.image4, R.drawable.image5,
R.drawable.image6, R.drawable.image7, R.drawable.image8, R.drawable.image9,
R.drawable.image10, R.drawable.image11,
R.drawable.image12, R.drawable.image13};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
simpleGallery = (Gallery) findViewById(R.id.simpleGallery); // get the reference of
Gallery
selectedImageView = (ImageView) findViewById(R.id.selectedImageView); // get the
reference of ImageView
customGalleryAdapter = new CustomGalleryAdapter(getApplicationContext(), images); //
initialize the adapter
simpleGallery.setAdapter(customGalleryAdapter); // set the adapter
// perform setOnItemClickListener event on the Gallery
simpleGallery.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// set the selected image in the ImageView
selectedImageView.setImageResource(images[position]);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Output:
<Spinner
android:id="@+id/spinner"
android:layout_width="149dp"
android:layout_height="40dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.498" />
</android.support.constraint.ConstraintLayout>
package example.javatpoint.com.spinner;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Getting the instance of Spinner and applying OnItemSelectedListener on it
Spinner spin = (Spinner) findViewById(R.id.spinner);
spin.setOnItemSelectedListener(this);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//Setting the ArrayAdapter data on the Spinner
spin.setAdapter(aa);
Toast.makeText(getApplicationContext(),country[position] ,
Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
Output: