android ppt
DESCRIPTION
Brief Introduction to android...TRANSCRIPT
-
Introduction to Android Technology
Er. Girish Kumar ShakyaAndroid Developer
-
AgendaWhat is an Android ?
History of Android
System Architecture
The Open Handset Alliance (OHA)
Anatomy of an Android application
Android Activity Life Cycle
Er. Girish Kumar ShakyaAndroid Developer
-
Android is an open software platform for Mobile Development.
What is an Android?
Operating Systems
Middleware
Applications
www.android.com
developer.android.com
Er. Girish Kumar ShakyaAndroid Developer
-
History of Android ?
Android 1.5 (Cupcake)
support for soft (onscreen) keyboards
video recording
application widgets
more than 1,000 changes to API
Er. Girish Kumar ShakyaAndroid Developer
-
History of Android ?(cont..)
Android 1.6 (Donut)
High and Low Density Display
a Number of minor changes
Er. Girish Kumar ShakyaAndroid Developer
-
History of Android ?(cont..)
Android 2.0 (Eclair)
multi-touch
Virtual keys
centralized account management
synchronization APIs
Docking
HTML5 and more
Er. Girish Kumar ShakyaAndroid Developer
-
History of Android ?(cont..)
Android 2.1 (Eclair Maintenance Release 1)
more HTML5 support
other minor improvement
Home screen enhancements
live wallpaper and widgets
Er. Girish Kumar ShakyaAndroid Developer
-
History of Android ?(cont..)
Next Generation (FroYo)
Then - Gengerberd
Er. Girish Kumar ShakyaAndroid Developer
-
System Architecture
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
Hardware Abstraction Layer
Security
Memory Management
Process Management
Network Stack
Driver Model
Er. Girish Kumar ShakyaAndroid Developer
-
C or C++
Compiled for particular architecture
Surface Manager
No screen buffer off screen bitmaps (combined with other bitmaps)
2D and 3D graphics
Media Codecs
AAC, AVC, H.263, MP3, MPEG4
SQL Database (Firefox/iPhone)
Browser Engine (Crome, Safari, iPhone, Nokia S60)Er. Girish Kumar Shakya
Android Developer
-
- Dalvik Virtual Machine
Googles implementation of Java
Optimized for Mobile devices
Runs .dex files
More compact and efficient than .class files
Memory and power concerns
Core Java libraries are different from JavaSE and
JavaMEEr. Girish Kumar Shakya
Android Developer
-
Building block for creating ApplicationsPre Installed in AndroidActivityManager- Control Activity Life CycleContentProvider Encapsulates any data to share between applications (contacts)ResourceManager- Parts of program that are not code (sound bites, video, images)LocationManager- Android always know where it is........NotificationManager- Events, messages, appointments, any alerts.........
Er. Girish Kumar ShakyaAndroid Developer
-
Apps
- Programs which take over the entire screen
Widgets (Gadgets)
Operate in a small rectangle of Home screen
Er. Girish Kumar ShakyaAndroid Developer
-
The Open Handset Alliance (OHA) is a collection of more than 30 technology companies including hardware manufacturers, mobile carriers, and software developers. Of particular note are the prominent mobile technology companies Motorola, HTC, T-Mobile, and Qualcomm. In their own words, the OHA represents:
A commitment to openness, a shared vision for the future, and concrete plans to make the vision a reality. To accelerate innovation in mobile and offer consumers a richer, less expensive, and better mobile experience.
Open Handset Alliance
Er. Girish Kumar ShakyaAndroid Developer
-
Open Handset Alliance (cont..)
Some of the alliances prominent members are as follow:
Sprint Nextel
T-Mobile
Motorola
Samsung
Sony Ericsson
Toshiba
Vodafone * Google * Intel * Texas Instruments
Er. Girish Kumar ShakyaAndroid Developer
-
Anatomy of an Android application
Lets create a simple Android TutorialBasic Application.
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
How to make an Android Application ?
Er. Girish Kumar ShakyaAndroid Developer
-
SCREEN
Er. Girish Kumar ShakyaAndroid Developer
-
Intent
Er. Girish Kumar ShakyaAndroid Developer
-
Model
View
i.e.
Model 1+ View 1= Activity 1
Er. Girish Kumar ShakyaAndroid Developer
-
Model
Java (Logic)
Er. Girish Kumar ShakyaAndroid Developer
-
View
XML (Layout)
Er. Girish Kumar ShakyaAndroid Developer
-
Controller
AndroidManifest.xml
Er. Girish Kumar ShakyaAndroid Developer
-
Model
Java (Logic)
Er. Girish Kumar ShakyaAndroid Developer
-
View
XML (Layout)
Er. Girish Kumar ShakyaAndroid Developer
-
Controller
AndroidManifest.xml
Er. Girish Kumar ShakyaAndroid Developer
-
CONTROLLER(AndroidManifest.
xml)
ACTIVITY 1
ACTIVITY 2
Intent
Er. Girish Kumar ShakyaAndroid Developer
-
CONTROLLER(AndroidManif
est.xml)
ACTIVITY 1
ACTIVITY 2
Intent 2
ACTIVITY 3
Intent 3
Er. Girish Kumar ShakyaAndroid Developer
-
ACTIVITY (n)
(1)Controller(AndroidManifest.xml)
1 Model + 1 View = 1 Activity
Er. Girish Kumar ShakyaAndroid Developer
-
Open Eclipse IDE
Close the Welcome Window if Open
Go to File -> New -> Other -> Android -> Android Project.
Give Project Name : TutorialBasic
Select Target Name as : Android2.2
Click Next
Give Package Name: my.hello.world
Then click Finish.
TutorialBasic Application
Er. Girish Kumar ShakyaAndroid Developer
-
Application Name (Project Node)
Source Folder. Here we put allJava Code
Java Code also Known as Model or Activity Source Code in Java Format
Auto Generated Code by Eclipse
Target SDK or Platform here Android2.2
APK or also known as single Out putFile
Resource Folder.. Collections of all Your resources.
Layout Folder Your VIEWs in XMLFormat
Controller Er. Girish Kumar ShakyaAndroid Developer
-
Res Folder
Resources: Text , pictures, sound etc. Everything is broken out of the code into a resource, which is reference in a class
called R.Er. Girish Kumar ShakyaAndroid Developer
-
Src Folder
Collection of your packages, Activity Class, Common Java Classes
Er. Girish Kumar ShakyaAndroid Developer
-
Displays a user interface component and responds to system/user initiated.
When an application has a user interface, it contains one or more Activities One activity is then considered as the main entry point by the system
An existing Activity can be replaced with a new one that fulfill the same contract
Each Activity can be invoked from others applications
What is really an Activity?
Er. Girish Kumar ShakyaAndroid Developer
-
Adding a new Activity in an Android project
The new Java class must extend the framework Activity class
Created Activity must be defined into the applications Manifest
What is really an Activity?
Er. Girish Kumar ShakyaAndroid Developer
-
Running in the multitasking environment
Users switch apps,calls come in,system run low on memory
System invoke callbacks in your application
The System will kill your application
Be sure to save state
Anatomy of App (Activity lifecycle)
Er. Girish Kumar ShakyaAndroid Developer
-
Anatomy of App (Activity lifecycle)
Activity Created
onCreate()
onResume()
Activity Running Er. Girish Kumar Shakya
Android Developer
-
Anatomy of App (Activity lifecycle)
onResume()
Activity Running
Call Comes in
onPause()Er. Girish Kumar Shakya
Android Developer
-
Anatomy of App (Activity lifecycle)
onResume()
Activity Running
Call Comes in
onPause()Low
Memory
Activity Destroy
Return to App
Er. Girish Kumar ShakyaAndroid Developer
-
Intents / Intent Filters
Simple message objects that represent:
An intention to do something
A declaration of capacity and interest in ofering assistance to those in need
Er. Girish Kumar ShakyaAndroid Developer
-
Intents / Intent Filters (cont)
An intent is made up a number off pieces off information describing the action or the service:
action attribute is typically a verb (VIEW, EDIT, DIAL,)
The data to operate on is expressed in the form off an Universal Resource Identifier (URI)
category attribute gives additional information about the action to executeEr. Girish Kumar Shakya
Android Developer
-
Receivers
When an application desires to receive and respond to a global event..
In order to be triggered when an event occurs,, application does not have to be running
By default,, Android includes some built-in Intents Receiver
Er. Girish Kumar ShakyaAndroid Developer
-
Receivers
How to receive these specific Intents?
The user class must extend the framework IntentReceiver class
To process incoming Intents,, onReceiveIntent() method is implemented
receiver element must be described into the application's Manifest
Er. Girish Kumar ShakyaAndroid Developer
-
Service(A long running background task)
Defining and invoking a Service
Adding a Service with Android is quite similar tthan for an Activity..
Framework Service class must be extended
The new Service must be defined into the application's Manifest
Er. Girish Kumar ShakyaAndroid Developer
-
Service(cont..)(A long running background task)
When a Service is using IPC, an AIDL description of its features is also needed..
Android Interface Definition Language (AIDL) is used to generated code to allow communication between two processes through IIPC
This mechanism is interface-based,, similar to Cobra (Unix) or COM (windows) but lighter weight
With this specific mode, the Service is started through the binder and not with startService()
Er. Girish Kumar ShakyaAndroid Developer
-
ContentProvider(Handle data and expose them to
other applications)
The only way to share data between Android applications..
It implements a standard set of methods to allow access to a data store
Any form off data storage can be used like SQLite database,, files,, or memory hash map
Er. Girish Kumar ShakyaAndroid Developer
-
ContentProvider(cont..)(Handle data and expose them to
other applications)
A Content Providers exposes a unique URI used to query,add,update and delete data::
A standard prefix (content:://)
The authority part (fully-qualified to ensure uniqueness)
The path to determine what kind off data is being requested
A specific record being requested,, if any
Er. Girish Kumar ShakyaAndroid Developer
-
Processes and Task (A Task between Kernel and
Android)Processes
A low-level kernel process in which an application's code is running..
By default,, Android binds the content off an APK to a Linux process
Process tag can be used to tune this relation with a lower granularity (activity, service,)
Tasks
A notion that users know on other platform as application..
A collection of related Activities
Capable of spanning multiple processes
Interaction with Activities can be controlled through Activity's launchMode attribute
Er. Girish Kumar ShakyaAndroid Developer
-
Processes and Task(cont.)(A Task between Kernel and
Android)
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
Using XML based layouts Using Basic Widgets Working with Containers Using Selection Widgets Using Fancy Widgets and Containers Applying Menus Embedding the WebKit browser Showing Pop-up Messages Dealing with Threads Handling Activity Lifecycle events
Er. Girish Kumar ShakyaAndroid Developer
-
Text Controlso TextViewo EditText (EditText control is subclass of TextView)o AutoCompleteTextViewo MultiAutoCompleteTextView
Button Controlso Buttono ImageButtono ToggleButton
CheckBox RadioButton Spinner ProgressBar RatingBar SeekBar
Er. Girish Kumar ShakyaAndroid Developer
-
Text Controls
Er. Girish Kumar ShakyaAndroid Developer
-
Text Controls
Er. Girish Kumar ShakyaAndroid Developer
-
Text Controls
Declare TextView
TextView tv;
Er. Girish Kumar ShakyaAndroid Developer
-
Text Controls
Initialize or Bind it in your Activity TextView
tv=(TextView)findViewById(R.id.textView1);
Er. Girish Kumar ShakyaAndroid Developer
-
Text Controls
Initialize or Bind it in your Activity TextView
tv=(TextView)findViewById(R.id.textView1);tv.setText(I Love my India);
Er. Girish Kumar ShakyaAndroid Developer
-
Text Controls
Initialize or Bind it in your Activity TextView
tv=(TextView)findViewById(R.id.textView1);tv.setText(I Love my India);
Er. Girish Kumar ShakyaAndroid Developer
-
Text Controls
Er. Girish Kumar ShakyaAndroid Developer
-
Text Controls
Er. Girish Kumar ShakyaAndroid Developer
-
Text Controls
Er. Girish Kumar ShakyaAndroid Developer
-
Text Controls
EditText simpleEdit;AutoCompleteTextView autoEdit;MultiAutoCompleteTextView multiEdit;Button mybtn;
Declare your Views:
Er. Girish Kumar ShakyaAndroid Developer
-
Text Controls
simpleEdit=(EditText)findViewById(R.id.editText1);autoEdit=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);multiEdit=(MultiAutoCompleteTextView)findViewById(R.id.multiAutoCompleteTextView1);mybtn=(Button)findViewById(R.id.button1);
Initialize your view
Er. Girish Kumar ShakyaAndroid Developer
-
Text Controls
mybtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {// TODO Auto-generated method stub/// Put some code here}});
Add listener and perform some Event say OnClickListener() and OnClick()
Er. Girish Kumar ShakyaAndroid Developer
-
Text Controls
mybtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {// TODO Auto-generated method stub
simpleEdit.setText("Hello");autoEdit.setText("Hi");multiEdit.setText("Bye");}
});
Add listener and perform some Event say OnClickListener() and OnClick()
Er. Girish Kumar ShakyaAndroid Developer
-
Text Controls
Er. Girish Kumar ShakyaAndroid Developer
-
Button Controls
Er. Girish Kumar ShakyaAndroid Developer
-
Button Controls
Er. Girish Kumar ShakyaAndroid Developer
-
Button Controls
Declare your Views
Button simpleBtn;ImageButton imgBtn;ToggleButton toggleBtn;
Er. Girish Kumar ShakyaAndroid Developer
-
Button Controls
Initialize or Bind your Views
simpleBtn=(Button)findViewById(R.id.button1);imgBtn=(ImageButton)findViewById(R.id.imageButton1);toggleBtn=(ToggleButton)findViewById(R.id.toggleButton1);
Er. Girish Kumar ShakyaAndroid Developer
-
Button Controls
Perform Listener and Event
simpleBtn=(Button)findViewById(R.id.button1);imgBtn=(ImageButton)findViewById(R.id.imageButton1);toggleBtn=(ToggleButton)findViewById(R.id.toggleButton1);
Er. Girish Kumar ShakyaAndroid Developer
-
Button Controls
Listener and Event simpleBtn
simpleBtn.setOnClickListener(new OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stub//do something useful}});
Er. Girish Kumar ShakyaAndroid Developer
-
Button Controls
Listener and Event simpleBtn
simpleBtn.setOnClickListener(new OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubToast.makeText(MainActivity.this, "I Clicked On Button",
Toast.LENGTH_SHORT).show();}});
Er. Girish Kumar ShakyaAndroid Developer
-
Button Controls
Listener and Event imageBtn
imgBtn.setOnClickListener(new OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stub//put some code here}});
Er. Girish Kumar ShakyaAndroid Developer
-
Button Controls
Listener and Event imageBtn
imgBtn.setOnClickListener(new OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubToast.makeText(MainActivity.this, "I Clicked On Image Button", Toast.LENGTH_SHORT).show();}});
Er. Girish Kumar ShakyaAndroid Developer
-
Button Controls Listener and Event toggleBtn
toggleBtn.setOnCheckedChangeListener(new OnCheckedChangeListener() {public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {// TODO Auto-generated method stub
//put some code here}});
Er. Girish Kumar ShakyaAndroid Developer
-
Button Controls Listener and Event toggleBtn
toggleBtn.setOnCheckedChangeListener(new OnCheckedChangeListener() {public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {// TODO Auto-generated method stub
//put some code here}});
Er. Girish Kumar ShakyaAndroid Developer
-
Button Controls Listener and Event toggleBtn
toggleBtn.setOnCheckedChangeListener(new OnCheckedChangeListener() {public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {// TODO Auto-generated method stubif(isChecked){Toast.makeText(MainActivity.this, "Run Charlie Run !!",
Toast.LENGTH_SHORT).show();}else{Toast.makeText(MainActivity.this, "Stop Charlie !!",
Toast.LENGTH_SHORT).show();}
}});
Er. Girish Kumar ShakyaAndroid Developer
-
Button Controls
Er. Girish Kumar ShakyaAndroid Developer
-
Button Controls
Er. Girish Kumar ShakyaAndroid Developer
-
Button Controls
Er. Girish Kumar ShakyaAndroid Developer
-
CheckBox
Er. Girish Kumar ShakyaAndroid Developer
-
CheckBox
Er. Girish Kumar ShakyaAndroid Developer
-
CheckBoxDeclare your checkboxes
CheckBox chk1;CheckBox chk2;CheckBox chk3;
Er. Girish Kumar ShakyaAndroid Developer
-
CheckBoxInitialize your checkboxes
chk1=(CheckBox)findViewById(R.id.checkBox1);
chk2=(CheckBox)findViewById(R.id.checkBox2);
chk3=(CheckBox)findViewById(R.id.checkBox3);
Er. Girish Kumar ShakyaAndroid Developer
-
CheckBoxSet your listener (OnCheckedListener)
chk1.setOnCheckedChangeListener(this);chk2.setOnCheckedChangeListener(this);chk3.setOnCheckedChangeListener(this);
Er. Girish Kumar ShakyaAndroid Developer
-
CheckBoxSet your listener (OnCheckedListener)
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {// TODO Auto-generated method stubint id=buttonView.getId();switch(id){case R.id.checkBox1:if(isChecked)Toast.makeText(this, "Fish", Toast.LENGTH_SHORT).show();break;case R.id.checkBox2:if(isChecked)Toast.makeText(this, "Chicken", Toast.LENGTH_SHORT).show();break;case R.id.checkBox3:if(isChecked)Toast.makeText(this, "Dosa", Toast.LENGTH_SHORT).show();break;}}
Er. Girish Kumar ShakyaAndroid Developer
-
CheckBox
Er. Girish Kumar ShakyaAndroid Developer
-
RadioButton
Er. Girish Kumar ShakyaAndroid Developer
-
RadioButton
Er. Girish Kumar ShakyaAndroid Developer
-
RadioButton
Declare RadioGroup
RadioGroup rg;
Er. Girish Kumar ShakyaAndroid Developer
-
RadioButton
Initialize RadioGroup
rg=(RadioGroup)findViewById(R.id.radioGroup1);
Er. Girish Kumar ShakyaAndroid Developer
-
RadioButton
Perform Listener and event
rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {// TODO Auto-generated method stub//put some code here}});
Er. Girish Kumar ShakyaAndroid Developer
-
RadioButtonPerform Listener and event
rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {public void onCheckedChanged(RadioGroup group, int checkedId) {// TODO Auto-generated method stubswitch(checkedId){case R.id.radio0:Toast.makeText(MainActivity.this, "Fish", Toast.LENGTH_SHORT).show();break;case R.id.radio1:Toast.makeText(MainActivity.this, "Chicken", Toast.LENGTH_SHORT).show();break;case R.id.radio2:Toast.makeText(MainActivity.this, "Dosa", Toast.LENGTH_SHORT).show();break;}}});
Er. Girish Kumar ShakyaAndroid Developer
-
RadioButton
Er. Girish Kumar ShakyaAndroid Developer
-
Spinner , AutoCompleteTextView, MultiAutoCompleteTextView
Er. Girish Kumar ShakyaAndroid Developer
-
Spinner , AutoCompleteTextView, MultiAutoCompleteTextView
Er. Girish Kumar Shakya
Android Developer
-
Spinner , AutoCompleteTextView, MultiAutoCompleteTextView
Declare your View
Spinner spinner;AutoCompleteTextView autoEdit;MultiAutoCompleteTextView multiEdit;
Er. Girish Kumar ShakyaAndroid Developer
-
Spinner , AutoCompleteTextView, MultiAutoCompleteTextView
Declare your View
Spinner spinner;AutoCompleteTextView autoEdit;MultiAutoCompleteTextView multiEdit;String[] list={"Sunday","Monday","Tuesday","Wednesday","Thrusday","Friday","Saturday"};
Er. Girish Kumar ShakyaAndroid Developer
-
Spinner , AutoCompleteTextView, MultiAutoCompleteTextView
Initialize your View
spinner=(Spinner)findViewById(R.id.spinner1);
autoEdit=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
multiEdit=(MultiAutoCompleteTextView)findViewById(R.id.multiAutoCompleteTextView1);
Er. Girish Kumar ShakyaAndroid Developer
-
Spinner , AutoCompleteTextView, MultiAutoCompleteTextView
Create an Object of ArrayAdapter
ArrayAdapter adapter=new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, list);
Er. Girish Kumar ShakyaAndroid Developer
-
Spinner , AutoCompleteTextView, MultiAutoCompleteTextView
Set Adapter to Spinner
ArrayAdapter adapter=new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, list);
spinner.setAdapter(adapter);
Er. Girish Kumar ShakyaAndroid Developer
-
Spinner , AutoCompleteTextView, MultiAutoCompleteTextView
Set Adapter to AutoCompleteTextView
ArrayAdapter adapter=new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, list);
spinner.setAdapter(adapter);autoEdit.setAdapter(adapter);
Er. Girish Kumar ShakyaAndroid Developer
-
Spinner , AutoCompleteTextView, MultiAutoCompleteTextView
Set Adapter to AutoCompleteTextView
ArrayAdapter adapter=new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, list);
spinner.setAdapter(adapter);autoEdit.setAdapter(adapter);
multiEdit.setAdapter(adapter);multiEdit.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
Er. Girish Kumar ShakyaAndroid Developer
-
Spinner , AutoCompleteTextView, MultiAutoCompleteTextView
Er. Girish Kumar ShakyaAndroid Developer
-
ProgressBar
Er. Girish Kumar ShakyaAndroid Developer
-
RatingBar
Er. Girish Kumar ShakyaAndroid Developer
-
RatingBar
Er. Girish Kumar ShakyaAndroid Developer
-
RatingBar
Er. Girish Kumar ShakyaAndroid Developer
-
RatingBar
TextView rateText;RatingBar rateBar;
Declare your View
Er. Girish Kumar ShakyaAndroid Developer
-
RatingBar
rateText=(TextView)findViewById(R.id.textViewRateValue);rateBar=(RatingBar)findViewById(R.id.ratingBar1);
Initialize or Bind your View
Er. Girish Kumar ShakyaAndroid Developer
-
RatingBar
rateBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {public void onRatingChanged(RatingBar ratingBar, float rating,boolean fromUser) {// TODO Auto-generated method stub
rateText.setText("rating is:"+rating);}});
Perform Listener
setOnRatingBarChangeListener()
Er. Girish Kumar ShakyaAndroid Developer
-
RatingBar
Er. Girish Kumar ShakyaAndroid Developer
-
SeekBar
Er. Girish Kumar ShakyaAndroid Developer
-
SeekBar
Er. Girish Kumar ShakyaAndroid Developer
-
SeekBar
Declare your views
TextView pertxt;SeekBar seek;
Er. Girish Kumar ShakyaAndroid Developer
-
SeekBar
Initialize or bind your views
pertxt=(TextView)findViewById(R.id.textView1); seek=(SeekBar)findViewById(R.id.seekBar1);
Er. Girish Kumar ShakyaAndroid Developer
-
SeekBarPerform Listener on SeekBar(setOnSeekBarChangeListener)
seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub
}
public void onStartTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub
}
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {// TODO Auto-generated method stub//put some here}});
Er. Girish Kumar ShakyaAndroid Developer
-
SeekBarPerform Listener on SeekBar(setOnSeekBarChangeListener)
seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub
}
public void onStartTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub
}
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {// TODO Auto-generated method stubpertxt.setText("your percentage is: "+progress);}});
Er. Girish Kumar ShakyaAndroid Developer
-
SeekBar
Er. Girish Kumar ShakyaAndroid Developer
-
Organizes its children either horizontally or vertically LinearLayout
TableLayout
RelativeLayout
FrameLayout
Organizes its children in tabular form
Organizes its children relative to one another or to the parent
Allows you to dynamically change the control(s) in the layout
Er. Girish Kumar ShakyaAndroid Developer
-
LinearLayout
Er. Girish Kumar ShakyaAndroid Developer
-
TableLayout
Er. Girish Kumar ShakyaAndroid Developer
-
Relative Layout
Er. Girish Kumar ShakyaAndroid Developer
-
FrameLayout
Er. Girish Kumar ShakyaAndroid Developer
-
Pick and Choose
o DatePicker
o TimePicker
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
TextView tv;DatePicker dp;TimePicker tp;Button clickDp;Button clickTp;
Declare your views
Er. Girish Kumar ShakyaAndroid Developer
-
tv=(TextView)findViewById(R.id.textViewDateandTime);dp=(DatePicker)findViewById(R.id.datePicker1);tp=(TimePicker)findViewById(R.id.timePicker1);clickDp=(Button)findViewById(R.id.buttondate);clickTp=(Button)findViewById(R.id.buttontime);
Initialize or bind your views
Er. Girish Kumar ShakyaAndroid Developer
-
clickDp.setOnClickListener(this);clickTp.setOnClickListener(this);
Perform Listeners and Events
Er. Girish Kumar ShakyaAndroid Developer
-
public void onClick(View v) {// TODO Auto-generated method stub
switch(v.getId()){case R.id.buttondate:String []month={"Jan","Feb","March","April","May","June","July","Aug","Sep","Oct","Nov","Dec"};String
strdate=dp.getDayOfMonth()+"/"+month[dp.getMonth()]+"/"+dp.getYear();
tv.setText(strdate);break;case R.id.buttontime:String
timestr=""+tp.getCurrentHour()+":"+tp.getCurrentMinute();tv.setText(timestr);
break;}
}
Perform Listeners and Events
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
AnalogClock
DigitalClock
Er. Girish Kumar ShakyaAndroid Developer
-
Creating a simple Menu
Er. Girish Kumar ShakyaAndroid Developer
-
Creating a simple Menu@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
super.onCreateOptionsMenu(menu);
MenuInflater menuInflator=getMenuInflater();
menuInflator.inflate(R.menu.mymenu, menu);return true;}
@Overridepublic boolean onOptionsItemSelected(MenuItem item) {// TODO Auto-generated method stubsuper.onOptionsItemSelected(item);//add some codereturn true;}
Er. Girish Kumar ShakyaAndroid Developer
-
Creating a simple Menu
@Overridepublic boolean onOptionsItemSelected(MenuItem item) {// TODO Auto-generated method stubsuper.onOptionsItemSelected(item);switch(item.getItemId()){
case R.id.mp:Toast.makeText(MainActivity.this, "Madhya Pradesh",
Toast.LENGTH_SHORT).show();break;case R.id.andhra:Toast.makeText(MainActivity.this, "Andhra Pradesh",
Toast.LENGTH_SHORT).show();break;return true;
}
Er. Girish Kumar ShakyaAndroid Developer
-
Creating a simple Menu
Er. Girish Kumar ShakyaAndroid Developer
-
WebView
Er. Girish Kumar ShakyaAndroid Developer
-
Toast Alert
ToastA Toast is a transient message, meaning that it displays and disappears onits own without user interaction.
Alert A subclass of Dialog that can display one, two or three buttons.
Er. Girish Kumar ShakyaAndroid Developer
-
Toast
Toast.makeText(this, "", Toast.LENGTH_SHORT).show();
Er. Girish Kumar ShakyaAndroid Developer
-
AlertDialog
AlertDialog.Builder alert=new AlertDialog.Builder(this);alert.setTitle(MessageDemo);alert.setMessage(Hello Friends);alert.show();
Er. Girish Kumar ShakyaAndroid Developer
-
Example:
toastbtn.setOnClickListener(new OnClickListener() {
@Overridepublic void onClick(View v) {// TODO Auto-generated method stubToast.makeText(PopUpDemo.this, "Hello from toast", Toast.LENGTH_SHORT).show();}});
alertbtn.setOnClickListener(new OnClickListener() {
@Overridepublic void onClick(View v) {// TODO Auto-generated method
stubAlertDialog.Builder alert=new
AlertDialog.Builder(PopUpDemo.this);alert.setTitle("MessageDemo");alert.setMessage("welcome to
India");alert.show();}});
Er. Girish Kumar ShakyaAndroid Developer
-
Example:
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
....
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
Intents are used as a message-passing mechanism
Explicitly (by specifying the class to load)
Implicitly (by specifying inside AndroidManifest.xml)
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
Declare your View
EditText edit;Button btnClk;
Er. Girish Kumar ShakyaAndroid Developer
-
Initialize your View
edit=(EditText)findViewById(R.id.editText1);btnClk=(Button)findViewById(R.id.button1);
Er. Girish Kumar ShakyaAndroid Developer
-
Prepare Listener and Event
btnClk.setOnClickListener(new OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubIntent intent=new Intent();intent.setClass(FirstActivity.this,
SecondActivity.class);startActivity(intent);
}});
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.second);}
Er. Girish Kumar ShakyaAndroid Developer
-
AndroidManifest.xml
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
putExtra(String name, boolean value);
putExtra(String name, int value);
putExtra(String name, double value);
putExtra(String name, String value);
Passing Message between Activity
Intent intent = new Intent();Intent.setClass(FirstActivity.this, SecondActivity.class);
intent.putExtra(key,value);
startActivity(intent);
Er. Girish Kumar ShakyaAndroid Developer
-
Bundle bundle=getIntent().getExtras();
String str=bundle.getString(Key);
boolean b=bundle.getBoolean(Key);
int b=bundle.getInt(Key);
float b=bundle.getFloat(Key);
double b=bundle.getDouble(Key);
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.google.com"));
startActivity(intent);
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);intent.setData(Uri.parse("http://www.google.com"));startActivity(intent);
Intent intent = new Intent(Intent.ACTION_CALL);intent.setData(Uri.parse("tel:555-555-5555"));startActivity(intent);
Intent intent = new Intent(Intent.ACTION_DIAL);startActivity(intent);
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
Declare Views
EditText edittextBrowser;Button btngo;Button btnsearch;Button btncall;Button btncallme;
Er. Girish Kumar ShakyaAndroid Developer
-
Initialized or Bind Views
edittextBrowser=(EditText)findViewById(R.id.editTextbrowser);btngo=(Button)findViewById(R.id.buttonGo);btnsearch=(Button)findViewById(R.id.buttonSearch);btncall=(Button)findViewById(R.id.buttoncall);btncallme=(Button)findViewById(R.id.buttoncallme);
Er. Girish Kumar ShakyaAndroid Developer
-
Perform Listener and Event
btngo.setOnClickListener(this);btnsearch.setOnClickListener(this);btncall.setOnClickListener(this);btncallme.setOnClickListener(this);
Er. Girish Kumar ShakyaAndroid Developer
-
switch(v.getId()){case R.id.buttonGo:intent = new Intent(Intent.ACTION_VIEW);intent.setData(Uri.parse("http://"+edittextBrowser.getText().toString()));startActivity(intent);break;case R.id.buttonSearch:intent = new Intent(Intent.ACTION_WEB_SEARCH);intent.setData(Uri.parse("http://www.google.com"));startActivity(intent);break;case R.id.buttoncall:intent = new Intent(Intent.ACTION_DIAL);startActivity(intent);break;case R.id.buttoncallme:intent = new Intent(Intent.ACTION_CALL);intent.setData(Uri.parse("tel:9584458363"));startActivity(intent);break;}
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
ListView is used to display a scrollable list of items.
ListView gets the data to display via an adapter.
Er. Girish Kumar ShakyaAndroid Developer
-
ListView
ListActivity
setListAdapter(ArrayAdapter);
setOnItemselectedListener();
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
public class ListSampleDemoActivity extends ListActivity {
ArrayList days;
}
Er. Girish Kumar ShakyaAndroid Developer
-
@Overridepublic void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
days=new ArrayList( );
days.add("Sunday"); days.add("Monday"); days.add("Tuesday");
days.add("Wednesday"); days.add("Thursday"); days.add("Friday");
days.add("Saturday");
setListAdapter(new ArrayAdapter(this, R.layout.main,days));
}
Er. Girish Kumar ShakyaAndroid Developer
-
@Overridepublic void onCreate(Bundle savedInstanceState)
{super.onCreate(savedInstanceState);
..setListAdapter(new ArrayAdapter(this, R.layout.main,days));ListView listview=getListView();}
Er. Girish Kumar ShakyaAndroid Developer
-
@Overridepublic void onCreate(Bundle savedInstanceState) {
..ListView listview=getListView();listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView adapter, View view, intposition,long arg3) {// TODO Auto-generated method stubString itemname=adapter.getItemAtPosition(position).toString();Toast.makeText(ListSampleDemoActivity.this, itemname, Toast.LENGTH_SHORT).show();}});} Er. Girish Kumar Shakya
Android Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
You can also define your own layout for the rows and assign this layout to your row adapter. We will add a graphic to each list entry.
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
public class ListViewWithGraphicsActivity extends Activity {/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);setContentView(R.layout.main);
}}
Er. Girish Kumar ShakyaAndroid Developer
-
public class ListViewWithGraphicsActivity extends ListActivity {/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);setContentView(R.layout.main);
}}
Er. Girish Kumar ShakyaAndroid Developer
-
@Overridepublic void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create an array of Strings, that will be put to our ListActivityString[] names = new String[] { "Linux", "Windows7", "Eclipse", "Suse",
"Ubuntu", "Solaris", "Android", "iPhone" };
// Use your own layout and point the adapter to the UI elements which// contains the label
this.setListAdapter(new ArrayAdapter(this, R.layout.main,R.id.label, names));
}
Er. Girish Kumar ShakyaAndroid Developer
-
@Overridepublic void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create an array of Strings, that will be put to our ListActivityString[] names = new String[] { "Linux", "Windows7", "Eclipse", "Suse",
"Ubuntu", "Solaris", "Android", "iPhone" };
// Use your own layout and point the adapter to the UI elements which// contains the label
this.setListAdapter(new ArrayAdapter(this, R.layout.main,R.id.label, names));
}
Er. Girish Kumar ShakyaAndroid Developer
-
@Overridepublic void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create an array of Strings, that will be put to our ListActivityString[] names = new String[] { "Linux", "Windows7", "Eclipse", "Suse",
"Ubuntu", "Solaris", "Android", "iPhone" };
// Use your own layout and point the adapter to the UI elements which// contains the label
this.setListAdapter(new ArrayAdapter(this, R.layout.main,R.id.label, names));
}Er. Girish Kumar Shakya
Android Developer
-
@Overridepublic void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create an array of Strings, that will be put to our ListActivityString[] names = new String[] { "Linux", "Windows7", "Eclipse", "Suse",
"Ubuntu", "Solaris", "Android", "iPhone" };
// Use your own layout and point the adapter to the UI elements which// contains the label
this.setListAdapter(new ArrayAdapter(this,
R.layout.main,R.id.label, names));
}Er. Girish Kumar Shakya
Android Developer
-
@Overridepublic void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create an array of Strings, that will be put to our ListActivityString[] names = new String[] { "Linux", "Windows7", "Eclipse", "Suse",
"Ubuntu", "Solaris", "Android", "iPhone" };
// Use your own layout and point the adapter to the UI elements which// contains the label
this.setListAdapter(new ArrayAdapter(this,
R.layout.main,R.id.label, names));}
Er. Girish Kumar ShakyaAndroid Developer
-
@Overridepublic void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create an array of Strings, that will be put to our ListActivityString[] names = new String[] { "Linux", "Windows7", "Eclipse", "Suse",
"Ubuntu", "Solaris", "Android", "iPhone" };
// Use your own layout and point the adapter to the UI elements which// contains the label
this.setListAdapter(new ArrayAdapter(this,
R.layout.main,R.id.label, names));}
Er. Girish Kumar ShakyaAndroid Developer
-
@Overridepublic void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);..this.setListAdapter(new ArrayAdapter(this,
R.layout.main,R.id.label, names));listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView adapter, View view, intposition,long arg3) {// TODO Auto-generated method stubString item=adapter.getItemAtPosition(position).toString();Toast.makeText(ListViewWithGraphicsActivity.this, item, Toast.LENGTH_SHORT).show();}});}
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
o A Browser
o Loading It Up
o Navigation
Er. Girish Kumar ShakyaAndroid Developer
-
WebView is not significantly different than any other widget in Android pop it into a layout, tell it what URL to navigate to via Java code, and you're done.
loadUrl();
loadData();
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
public class WebBrowserDemoActivity extends Activity {WebView browser;
/** Called when the activity is first created. */@Override
public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);
browser=(WebView)findViewById(R.id.webkit);browser.loadUrl("http://www.google.com");
}}
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
browser.loadData(Hello, world! ,"text/html", "UTF-8
);
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
reload()
goBack()
goForward()
canGoForward()
goBackOrForward()
canGoBackOrForward()
goBackOrForward()
clearCache()
clearHistory()
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar Shakya(DAC,CDAC,Pune(Mh.)
Er. Girish Kumar ShakyaAndroid Developer
-
Particularly used to store your data.
That can be Shareable within your all activities in an application.
Or might be Shareable across application.
Data sharing done by using key/values pairs(akin to Map).
Er. Girish Kumar ShakyaAndroid Developer
-
To get access to the preferences, you have two APIs to choose from:
1. getPreferences() from within your Activity,
to access activity specific preferences
2. getSharedPreferences() from within your
Activity (or other application Context), to
access application-level preferences
Er. Girish Kumar ShakyaAndroid Developer
-
Get the preference by using:
SharedPreferences settings=getPreferences(0);
Create an editor to edit your Preferences
SharedPreferences.Editor editor=settings.edit();
Set your preference by using put Methods e.g. editor.putBoolean(key,false);
Commit it using editor.commit();
Er. Girish Kumar ShakyaAndroid Developer
-
Use additional method if necessary:
remove() to get rid of a single named preference
clear() to get rid of all preferences
commit() to persist your changes made via the editor
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
Create a Project Named PreferenceDemo
Name the main Activity PreferenceDemoActivity
Edit the main.xml file:
Er. Girish Kumar Shakya
Android Developer
-
Open PreferenceDemoActivity
Edit it:
public class PreferenceDemoActivity extends Activity {CheckBox chb;}
//Inside onCreate() write some code to close the //application when Button close is clicked//set onclicklistener to close the applicationButton close=(Button)findViewById(R.id.close);
close.setOnClickListener(new OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubfinish();}});
//inside onCreate() write some to code to perform checked change when
//user clicked on checkedButtonchb=(CheckBox)findViewById(R.id.check);chb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {// TODO Auto-generated method stub
if(chb.isChecked()){chb.setText("This checkbox is: checked");}else{
chb.setText("This checkbox is: unchecked");}
}});
@Overrideprotected void onPause() {// TODO Auto-generated method stubsuper.onPause();SharedPreferences settings=getPreferences(0);SharedPreferences.Editor editor=settings.edit();
editor.putBoolean("chb_checked", chb.isChecked());editor.commit();}
@Overrideprotected void onResume() {// TODO Auto-generated method stubsuper.onResume();
SharedPreferences settings=getPreferences(0);chb.setChecked(settings.getBoolean("chb_checked", false));}
Er. Girish Kumar ShakyaAndroid Developer
-
Finally run your program.
And see the difference
Er. Girish Kumar ShakyaAndroid Developer
-
Xml folder
PreferenceActivity
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar Shakya
Android Developer
-
public class TablePreference extends PreferenceActivityimplements OnPreferenceChangeListener {@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);addPreferencesFromResource(R.xml.mytable);}
Er. Girish Kumar ShakyaAndroid Developer
-
ListPreference listpreference=(ListPreference)findPreference("tableno");CheckBoxPreferencechkpreference=(CheckBoxPreference)findPreference("chekboxsum");EditTextPreference editpreference=(EditTextPreference)findPreference("editTextPref");RingtonePreferenceringtpreference=(RingtonePreference)findPreference("ringtonePref");
listpreference.setOnPreferenceChangeListener(this);chkpreference.setOnPreferenceChangeListener(this);editpreference.setOnPreferenceChangeListener(this);ringpreference.setOnPreferenceChangeListener(this);}
public boolean onPreferenceChange(Preference preference, Object newValue) {// TODO Auto-generated method stubToast.makeText(this, newValue.toString(), Toast.LENGTH_SHORT).show();return true;}}
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
Introducing SQLite
DDL Statements
Modification Statements
Query Statements
Using SQLite in Android.
Er. Girish Kumar ShakyaAndroid Developer
-
SQLite is a powerful Relational Database engine created by Dr. Richard Hipp in 2000.
SQLite can be found in the Apple iPhone, Symbian phones, Mozilla Firefox, Skype, PHP, Adobe AIR, Mac OS X, Solaris, and many other places.
Er. Girish Kumar ShakyaAndroid Developer
-
It is well Regarded, being:
Open Source
Standard-Complaint
Lightweight
Single-tier
Er. Girish Kumar ShakyaAndroid Developer
-
Three reason for its popularity:
It's free
It's small
It require no setup or Administration
Er. Girish Kumar ShakyaAndroid Developer
-
Data Definition Language(DDL) Statement is used to define tables and columns names....
create table contactlist (_id integer primary key autoincrement,nametext,mob text not null,emailtext,address text);
Er. Girish Kumar ShakyaAndroid Developer
-
create table contactlist (_id integer primary key autoincrement,name text,mob text not null,email text,address text);
_id name mob email address
Primary Key
Er. Girish Kumar ShakyaAndroid Developer
-
SQL provides number of statement that let you perform CRUD operation . like create,retrive, update and delete of operation in the database....
For example:update contactlist set name=ashish where id=1;
Er. Girish Kumar ShakyaAndroid Developer
-
update contactlist set name=ashish where id=1;
_id name mob email address
1 ashish 9039176xxx
n
228/B trade center indore
Auto Generated value....
Er. Girish Kumar ShakyaAndroid Developer
-
SQL provides number of statement that let you perform CRUD operation . like create,retrive, update and delete of operation in the database....
For example:select * from table where _id=1;
Er. Girish Kumar ShakyaAndroid Developer
-
select * from table where _id=1;
_id name mob email address
1 girish 9039176xxx [email protected]
228/B trade center indore
1;girish;9039176xxx;[email protected];228/B trade center indore
Er. Girish Kumar ShakyaAndroid Developer
-
Content Values
Using the SQLiteOpenHelper
ContactClass
Inserting Row in contactlist table
Retrieving from contactlist table
Updating contactlist table
Deleting from contactlist table
Er. Girish Kumar ShakyaAndroid Developer
-
This class is used to store values.
Each Content Values object represents a single row, as a map of column names to values.
Queries in Android are returned as Cursor objects.
Er. Girish Kumar ShakyaAndroid Developer
-
The Cursor class includes several functions to navigate query results including, but not limited to, the following:
moveToFirst
moveToNext
moveToPrevious
getCount
getColumnIndexOrThrow
getColumnName
getColumnNames
moveToPosition
getPosition
Er. Girish Kumar ShakyaAndroid Developer
-
SQLiteOpenHelper is an abstract class that help us to perform CRUD operation for database.
Er. Girish Kumar ShakyaAndroid Developer
-
SQLiteOpenHelper
SQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version);
SQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version, DatabaseErrorHandler errorHandler)
onCreate(SQLiteDatabase db)
onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
getReadableDatabase()
getWritableDatabase()
onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion)
onOpen(SQLiteDatabase db)
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
public static final String DB_NAME="contact.db";
public static final int DB_VERSION=1;
public static final String DB_TABLE="contactlist";
////creating column
public static final String NAME="name";
public static final String PHONE_NO="mob";
public static final String EMAIL="email";
public static final String ADDRESS="address";
Er. Girish Kumar ShakyaAndroid Developer
-
"create table " +
"" +DB_TABLE+" (_id integer primary key autoincrement," +
""+NAME+" text," + ""+PHONE_NO+" text not null," +
""+EMAIL+" text,"+ADDRESS+" text);";
Er. Girish Kumar ShakyaAndroid Developer
-
public ContactClass(Context context) {
super(context, DB_NAME, null, DB_VERSION);
// TODO Auto-generated constructor stub
}
Er. Girish Kumar ShakyaAndroid Developer
-
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int arg1, intarg2) {
// TODO Auto-generated method stub
db.execSQL("drop table if exists "+DB_TABLE);
}
Er. Girish Kumar ShakyaAndroid Developer
-
ContactClass ccdatabase=new ContactClass(this);
SQLiteDatabasesd=ccdatabase.getWritableDatabase();
ContentValues cv=new ContentValues();
cv.put(key, value);
sd.insert(table, colname, contentvalues);
sd.close();
Er. Girish Kumar ShakyaAndroid Developer
-
ContactClass ccdatabase=new ContactClass(this);
SQLiteDatabasesd=ccdatabase.getWritableDatabase();
ContentValues cv=new ContentValues();
cv.put(ccdatabase.NAME, name.getText().toString());
cv.put(ccdatabase.PHONE_NO, mobileno.getText().toString());
cv.put(ccdatabase.EMAIL, email.getText().toString());
cv.put(ccdatabase.ADDRESS, address.getText().toString());
//
sd.insert(ccdatabase.DB_TABLE, ccdatabase.NAME, cv);
sd.close();
Er. Girish Kumar ShakyaAndroid Developer
-
Cursor c=sd.query
(table,
Columns,
where,
selectionArgs,
groupBy,
having,
OrderBy);
Er. Girish Kumar ShakyaAndroid Developer
-
Table :- eg: ccdatabase.DB_TABLE
Columns :- null for all or _id,name for specific
Where :- String where = _id + = + requiredValue;
whereArgs :- String whereArgs[]={_id=1,name='girish'};
GroupBy :-use here group by statement of sql
Having :- put here having query
OrderBy :-String orderBy = name;
Er. Girish Kumar ShakyaAndroid Developer
-
Cursor c=sd.query(ccdatabase.DB_TABLE, null, null, null, null, null, null);
while(c.moveToNext()){
mylist.add(c.getString(0)+";"+c.getString(1)+";"+c.getString(2)+";"+c.getString(3)+";"+c.getString(4));
}
c.close();
Er. Girish Kumar ShakyaAndroid Developer
-
ContentValues cv=new ContentValues();
if(!(editname.getText().toString().equals("")))
cv.put(ccdatabase.NAME, editname.getText().toString());
if((editmobile.getText().toString().equals("")))
Toast.makeText(this, "mobile no cannot updated", Toast.LENGTH_SHORT).show();
else
cv.put(ccdatabase.PHONE_NO, editmobile.getText().toString());
if(!(editemail.getText().toString().equals("")))
cv.put(ccdatabase.EMAIL, editemail.getText().toString());
if(!(editaddress.getText().toString().equals("")))
cv.put(ccdatabase.ADDRESS, editaddress.getText().toString());
String where="_id="+editid.getText().toString();
sd.update(ccdatabase.DB_TABLE, cv, where, null);
sd.close();
Er. Girish Kumar ShakyaAndroid Developer
-
SQLiteDatabasesd=ccdatabase.getWritableDatabase();
String where="_id="+_id;
sd.delete(ccdatabase.DB_TABLE, where, null);
sd.close();
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar Shakya
Android Developer & Trainer
Er. Girish Kumar ShakyaAndroid Developer
-
Introduction
Playing Audio Content
Playing Video Content
Audio Recording
Image Capture
Er. Girish Kumar ShakyaAndroid Developer
-
android.media
Web
asset
Secure Digital Card (SD) Card
Codex: 3GPP
MP3
MIDI
PCM/WAVE
MPEG-4
http://developer.android.com/guide/appendix/media-formats.html
Er. Girish Kumar ShakyaAndroid Developer
-
android.media.MediaPlayer
playAudio()
KillMedia()
Er. Girish Kumar ShakyaAndroid Developer
-
android.media.MediaPlayer : MediaPlayerclass can be used to control playback of audio/video files and streams.
Some Important methods :
reset(), setDataSource(), prepare(), start(), seekTo(), pause(), getCurrentPosition(), isLooping(), isPlaying(), release(), seekTo()
Er. Girish Kumar ShakyaAndroid Developer
-
MediaPlayer (constructing)
MediaPlayer mediaPlayer=MediaPlayer.create(context, resid);
e.g.MediaPlayer mediaPlayer=
MediaPlayer.create(this, R.raw.song1);
MediaPlayer mediaPlayer=new MediaPlayer();
e.g.MediaPlayer mediaPlayer=
new MediaPlayer();
Er. Girish Kumar ShakyaAndroid Developer
-
MediaPlayer (setting Data source)
String path=/sdcard/mysong.mp3;mediaPlayer.setDataSource(path);
MediaPlayer (prepare for media)
mediaPlayer.prepare();
MediaPlayer (start media)
mediaPlayer.start();
Er. Girish Kumar ShakyaAndroid Developer
-
MediaPlayer (Seek to Position)
mediaPlayer.seekTo(0); // supply int value
MediaPlayer (Pause media)
mediaPlayer.pause();
MediaPlayer (find current Position)
int currentposition=mediaPlayer.getCurrentPosition();
Er. Girish Kumar ShakyaAndroid Developer
-
MediaPlayer (find media is playing or not)
mediaPlayer.isPlaying(); // supply int value
MediaPlayer (if everything done release media)
mediaPlayer.release();
Er. Girish Kumar ShakyaAndroid Developer
-
public void playAudio() throws Exception{KillMediaPlayer();
mediaPlayer=new MediaPlayer();mediaPlayer.setDataSource(AUDIO_PATH);mediaPlayer.prepare();mediaPlayer.start();
}
Er. Girish Kumar ShakyaAndroid Developer
-
public void killMediaPlayer(){try{if(mediaPlayer!=null){
mediaPlayer.release();}}catch(Exception e){
}}
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
final String AUDIO_PATH="/sdcard/Cuppycake_Song_.mp3";
MediaPlayer mediaPlayer;int loopback=0;
@Overridepublic void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);setContentView(R.layout.main);//retrive all button from xmlButton playbtn=(Button)findViewById(R.id.buttonstart);Button restartbtn=(Button)findViewById(R.id.buttonrestart);Button pausebtn=(Button)findViewById(R.id.buttonpause);
...........................................
}
Er. Girish Kumar ShakyaAndroid Developer
-
playbtn.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {// TODO Auto-generated method stubtry {
playAudio();} catch (Exception e) {
// TODO Auto-generated catch blocke.printStackTrace();
}}
});
Er. Girish Kumar ShakyaAndroid Developer
-
pausebtn.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {// TODO Auto-generated method stub
loopback=mediaPlayer.getCurrentPosition();mediaPlayer.pause();
}});
Er. Girish Kumar ShakyaAndroid Developer
-
restartbtn.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {// TODO Auto-generated method stub
mediaPlayer.seekTo(loopback);mediaPlayer.start();
}});
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
android.widget.VideoView
android.widget.MediaController
Er. Girish Kumar ShakyaAndroid Developer
-
android.widget.VideoView
Displays a video file. The VideoView class can loadimages from various sources (such as resources or contentproviders), takes care of computing its measurement fromthe video so that it can be used in any layout manager, andprovides various display options such as scaling and tinting.
Important methods:setMediaController(MediaController);setVideoPath(VIDEO_PATH);requestFocus();start();
Er. Girish Kumar ShakyaAndroid Developer
-
A view containing controls for aMediaPlayer.Contains buttons like Play/Pause Rewind Fast Forward Progress slider
android.widget.MediaController
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
VideoView videoView=(VideoView)findViewById(R.id.videoView1);MediaController mc=new MediaController(this);mc.setBackgroundDrawable(getWallpaper());videoView.setMediaController(mc);videoView.setVideoPath("/sdcard/320474911302296_31015.mp4");videoView.requestFocus();videoView.start();
Er. Girish Kumar ShakyaAndroid Developer
-
android.provider.MediaStore.RECORD_SOUND
startRecording();
onActivityResult();
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
android.provider.MediaStore.RECORD_SOUNDpublic void startRecording(){
Intent intent=new Intent("android.provider.MediaStore.RECORD_SOUND");startActivityForResult(intent, 0);
}
Er. Girish Kumar ShakyaAndroid Developer
-
android.provider.MediaStore.RECORD_SOUND
@Overrideprotected void onActivityResult(int requestCode,
int resultCode, Intent data) {// TODO Auto-generated method stubsuper.onActivityResult(requestCode, resultCode, data);switch(requestCode){case 0:
if(resultCode== RESULT_OK){Uri recordedAudioPath=data.getData();
}}}
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer
-
public void captureImage(View view){ContentValues values=new ContentValues();values.put(Media.TITLE, "My demo Image");values.put(Media.DESCRIPTION,
"Image capture by Camera via an Intent");
myPicture=getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
Intent intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, myPicture);startActivityForResult(intent, 0);
}
Er. Girish Kumar ShakyaAndroid Developer
-
@Override
protected void onActivityResult(int
requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode,
resultCode, data);
if(requestCode==0 && resultCode==
Activity.RESULT_OK){
}
} Er. Girish Kumar ShakyaAndroid Developer
-
Er. Girish Kumar ShakyaAndroid Developer