Slide 1 of 49© People Strategists www.peoplestrategists.com
Android Computing Platform
Slide 2 of 49© People Strategists www.peoplestrategists.com Slide 2 of 57© People Strategists www.peoplestrategists.com
Slide 3 of 49© People Strategists www.peoplestrategists.com
Android Introduction
• A Software platform and Linux Kernel based operating
system for mobile.
•Android is Open Source means it is made freely available and
may be redistributed and modified.
• Android was developed in 2003.
Slide 4 of 49© People Strategists www.peoplestrategists.com
History of Android
Slide 5 of 49© People Strategists www.peoplestrategists.com
Android Releases
Available from
November 3rd 2014
Slide 6 of 49© People Strategists www.peoplestrategists.com
Android Architecture
Slide 7 of 49© People Strategists www.peoplestrategists.com
Linux kernel
 This is the core layer of android architecture which provides services
like power management, memory management, security and binder for
process communication.
Android Architecture
Slide 8 of 49© People Strategists www.peoplestrategists.com
Native Libraries
 These libraries are written in C/C++ like web libraries to access web browser,
libraries for android video formats.
 Application framework access these libraries
Android Architecture
Slide 9 of 49© People Strategists www.peoplestrategists.com
Application Framework
The set of API's that allow developers to quickly and easily write android app and
they are written in a Java programming language.
Android Architecture
Slide 10 of 49© People Strategists www.peoplestrategists.com
Android Runtime
Takes very less time to launch an app,
More device Storage.
Note : Introduced in Kitkat version
Takes time to launch an app,
Less device storage
Note : Declared dead in Lollipop version
Slide 11 of 49© People Strategists www.peoplestrategists.com
Android Architecture
Slide 12 of 49© People Strategists www.peoplestrategists.com
Just 25$ for Registration.
https://play.google.com/apps
/publish/signup/
upload free/
paid apps.
Android App Market
Slide 13 of 49© People Strategists www.peoplestrategists.com
Android Target
Slide 14 of 49© People Strategists www.peoplestrategists.com
Setting Up your Android
Development Environment
Check System Requirements on below link:-
https://developer.android.com/sdk/index.html#Requirements
1. To develop applications for Android platform, you need
 Java SE Development Kit (JDK),
 Android SDK Integrated IDE (Android Studio)
2. Download the Android Studio
http://developer.android.com/sdk/index.html
Slide 15 of 49© People Strategists www.peoplestrategists.com
Understanding Project Structure
Slide 16 of 49© People Strategists www.peoplestrategists.com Slide 16 of 57© People Strategists www.peoplestrategists.com
Building Block,
User Interface and Controls
Slide 17 of 49© People Strategists www.peoplestrategists.com
Android Components
Activity
 Single screen in your application
Content Provider
 Can expose your data and have your applications use data from other
applications.
Slide 18 of 49© People Strategists www.peoplestrategists.com
Service
 Local services
 Remote services.
Broadcast Receiver
 Allows to register for system or application events
Android Components
Slide 19 of 49© People Strategists www.peoplestrategists.com
AndroidManifest.xml(Metadata of Android Application)
 It lists your application’s activities and services, along with the
permissions and features the application needs to run.
Syntax :
<manifest>
<Elements for Application properties should come here>
<application>
<Elements for application components should come here>
</application>
</manifest>
AndroidManifest
Slide 20 of 49© People Strategists www.peoplestrategists.com
Android Virtual Devices
 AVD allows developers to test their applications
AVD
Slide 21 of 49© People Strategists www.peoplestrategists.com
import android.app.Activity;
import android.os.Bundle;
public class HelloWorld extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
HelloWorld
Slide 22 of 49© People Strategists www.peoplestrategists.com
Android the Application Life
Cycle
Slide 23 of 49© People Strategists www.peoplestrategists.com
Android Resources
Compiled and Uncompiled Android Resources
• XML files
• Raw files
Slide 24 of 49© People Strategists www.peoplestrategists.com
String Resources
• Define strings in one or more
XML resource files.
• These XML files containing
string-resource definitions
reside in the /res/values
subdirectory.
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">hello</string>
<string name="app_name">hello
appname</string>
</resources>
Android Resources
Slide 25 of 49© People Strategists www.peoplestrategists.com
Layout Resources
• A key resource used in
Android UI programming.
public class HelloWorldActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
...
}
Android Resources
Slide 26 of 49© People Strategists www.peoplestrategists.com
Example main.xml Layout File
<?xml version="1.0" encoding="utf-
8"?>
<LinearLayout
xmlns:android="http://schemas.andr
oid.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</LinearLayout>
Android Resources
Slide 27 of 49© People Strategists www.peoplestrategists.com
Color Resources
<resources>
<color name="red">#f00</color>
<color
name="blue">#0000ff</color>
<color
name="green">#f0f0</color>
<color
name="main_back_ground_color">
#ffffff00</color>
</resources>
Android Resources
Slide 28 of 49© People Strategists www.peoplestrategists.com
Color Resources in Java code
int mainBackGroundColor =
activity.getResources.getColor(R.color.main_back_ground_color);
Using Colors in View Definitions
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/red"
android:text="Sample Text to Show Red Color"/>
Android Resources
Slide 29 of 49© People Strategists www.peoplestrategists.com
Dimension Resources
You can specify the dimensions in any of the following units:
px: Pixels
in: Inches
mm: Millimeters
pt: Points
dp: Density-independent pixels based on pixel density per inch
sp: Scale-independent pixels (dimensions that allow for user sizing;
helpful for use in fonts)
Android Resources
Slide 30 of 49© People Strategists www.peoplestrategists.com
XML Syntax for Defining Dimension
Resources
<resources>
<dimen name="mysize_in_pixels">1px</dimen>
<dimen name="mysize_in_dp">5dp</dimen>
<dimen name="medium_size">100sp</dimen>
</resources>
Using Dimension Resources in XML
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/medium_size"/>
Android Resources
Slide 31 of 49© People Strategists www.peoplestrategists.com
Image Resources
Using Image Resources in XML
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Dial"
android:background="@drawable/sample_image"
/>
Android Resources
Slide 32 of 49© People Strategists www.peoplestrategists.com
Android Resources
package com.mycompany.android.my-root-package;
public final class R {
...other entries depending on your project and application
public static final class string
{
...other entries depending on your project and application
publicstaticfinal int hello=0x7f040000;
publicstaticfinal int app_name=0x7f040001;
...other entries depending on your project and application
}
...other entries depending on your project and application
}
• R.java with unique IDs for the
two string resources specified.
R.java
Slide 33 of 49© People Strategists www.peoplestrategists.com
Resource Reference Syntax
Android resources are identified (or referenced) by their IDs in Java source code.
<TextView android:id="@+id/text">
//Success: Creates an id called "text" in the local package's R.java
In the syntax "@+id/text", the + sign has a special meaning. It tells Android that the ID
text may not already exist
Android Resources
Slide 34 of 49© People Strategists www.peoplestrategists.com
Android
View and ViewGroup
Slide 35 of 49© People Strategists www.peoplestrategists.com
Buttons
Slide 36 of 49© People Strategists www.peoplestrategists.com
Basic Button
<Button android:id="@+id/button1"
android:text="@string/basicBtnLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
……………………
ImageButton
<ImageButton android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="myClickHandler"
android:src="@drawable/icon" />
……………..
ImageButton imageButton2 =
(ImageButton)this.findViewById(R.id.imageButton2);
imageButton2.setImageResource(R.drawable.icon);
Buttons
Slide 37 of 49© People Strategists www.peoplestrategists.com
ToggleButton
<ToggleButton android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toggle Button"
android:textOn="Stop"
android:textOff="Run"/>
Button button1 = (Button)this.findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.androidbook.com"));
startActivity(intent);
}
});
Buttons
Slide 38 of 49© People Strategists www.peoplestrategists.com
CheckBox
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<CheckBox android:id="@+id/chickenCB"
android:text="Chicken" android:checked="true"
android:layout_width=“wrap_content"
android:layout_height="wrap_content" />
<CheckBox android:id="@+id/fishCB" android:text="Fish"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckBox android:id="@+id/steakCB"
android:text="Steak" android:checked="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
CheckBox
Slide 39 of 49© People Strategists www.peoplestrategists.com
RadioButton
RadioButton
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RadioGroup android:id="@+id/rBtnGrp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RadioButton android:id="@+id/chRBtn"
android:text="Chicken"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
………………………..
</RadioGroup>
</LinearLayout>
Slide 40 of 49© People Strategists www.peoplestrategists.com
RadioButton
ImageView
<ImageView android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content“
android:src="@drawable/abc"
/>
Slide 41 of 49© People Strategists www.peoplestrategists.com
DatePicker
<DatePicker android:id="@+id/datePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
………………………..
DatePicker dp = (DatePicker)this.findViewById(R.id.datePicker);
dateDefault.setText("Date defaulted to " + (dp.getMonth() + 1) + "/" +
dp.getDayOfMonth() + "/" + dp.getYear());
dp.init(2008, 11, 10, null);
TimePicker
<TimePicker android:id="@+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
………………………..
TimePicker tp = (TimePicker)this.findViewById(R.id.timePicker);
tp.setIs24HourView(true);
tp.setCurrentHour(new Integer(10));
tp.setCurrentMinute(new Integer(10));
Pickers
Slide 42 of 49© People Strategists www.peoplestrategists.com
DigitalClock
<DigitalClock
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
AnalogClock
<AnalogClock
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Pickers
Slide 43 of 49© People Strategists www.peoplestrategists.com
ListView
<ListView android:id="@+id/list"
android:layout_width=" wrap_content "
android:layout_height=" wrap_content "
android:entries=“@array/mylist” />
List
Slide 44 of 49© People Strategists www.peoplestrategists.com
Layout Manager
Layout Manager Description
LinearLayout Organizes its children either horizontally or vertically
TableLayout Organizes its children in tabular form
RelativeLayout Organizes its children relative to one another or to
the parent
FrameLayout Allows you to dynamically changethe control(s) in
the layout
Slide 45 of 49© People Strategists www.peoplestrategists.com
Layout Manager
LinearLayout
<LinearLayout
xmlns:android="http://schemas.android.com/a
pk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!—add components-->
</LinearLayout>
Slide 46 of 49© People Strategists www.peoplestrategists.com
Layout Manager
RelativeLayout
<RelativeLayout …………… >
<TextView android:id="@+id/userNameLbl"
android:text="Username: “
android:layout_alignParentTop="true" />
<EditText android:id="@+id/userNameText"
android:layout_toRightOf="@id/userNameLbl" />
<TextView android:id="@+id/pwdLbl"
android:layout_below="@id/userNameText"
android:text="Password: " />
<EditText android:id="@+id/pwdText"
android:layout_toRightOf="@id/pwdLbl"
android:layout_below="@id/userNameText" />
<TextView android:id="@+id/pwdCriteria"
android:layout_below="@id/pwdText"
android:text="Password Criteria... " />
</RelativeLayout>
Slide 47 of 49© People Strategists www.peoplestrategists.com
TableLayout
<TableLayout ……… >
<TableRow>
<TextView android:text="First Name:“
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText android:text="Edgar“
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow>
<TextView android:text="Last Name:"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText android:text="Poe"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
Layout Manager
Slide 48 of 49© People Strategists www.peoplestrategists.com
Layout Manager
FrameLayout
<FrameLayout android:id="@+id/frmLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/oneImgView"
android:src="@drawable/one"
android:scaleType="fitCenter"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<ImageView
android:id="@+id/twoImgView"
android:src="@drawable/two"
android:scaleType="fitCenter"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone" />
</FrameLayout>
Slide 49 of 49© People Strategists www.peoplestrategists.com
Styles
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name=“SpelError">
<item
name="android:layout_width">fill_parent</item>
<item
name="android:layout_height">wrap_content</item>
<item name="android:textColor">#FF0000</item>
<item
name="android:typeface">monospace</item>
</style>
</resources>
………………..
<TextView android:id="@+id/errorText"
style="@style/ SpelError"
android:text=“Styling”
/>
Styles
Slide 50 of 49© People Strategists www.peoplestrategists.com
Themes
If you have some style elements you want applied across an entire activity, or across
the whole application, you should use a theme instead. A theme is it’s exactly like a
style. To specify a theme for an activity or an application, we would add an attribute
to the <activity>or <application>tag in the AndroidManifest.xml.
<activity android:theme="@style/MyActivityTheme">
<application android:theme="@style/MyApplicationTheme">
Themes
Slide 51 of 49© People Strategists www.peoplestrategists.com Slide 51 of 57© People Strategists www.peoplestrategists.com
Slide 52 of 49© People Strategists www.peoplestrategists.com
Intent
A mechanism to communicate from one component to another.
It defines intention of an application and also used to transfer
data.
An Intent mainly can be used :-
 To start an activity or service.
 To transfer data etc.
Slide 53 of 49© People Strategists www.peoplestrategists.com
Intent
Types of Intents:-
 Implicit
Slide 54 of 49© People Strategists www.peoplestrategists.com
Intents
 Explicit
Slide 55 of 49© People Strategists www.peoplestrategists.com
Built-in Intent Actions
Intent
Slide 56 of 49© People Strategists www.peoplestrategists.com
Data Passing
An intent can include an additional attribute called extras which
can be used to pass data.
This extra information is represented by an Android class called
android.os.Bundle.
// Place a bundle in an intent
Bundle anotherBundle = new Bundle();
//populate the bundle with key/value pairs
//and then set the bundle on the Intent
intent.putExtras(anotherBundle);
//Get the Bundle from an Intent
Bundle extraBundle = intent.getExtras();
Slide 57 of 49© People Strategists www.peoplestrategists.com
Data Passing
You can use a number of methods to add fundamental types to
the bundle.
putExtra(String name, boolean value);
putExtra(String name, int value);
putExtra(String name, double value);
putExtra(String name, String value);

Android - Day 1

  • 1.
    Slide 1 of49© People Strategists www.peoplestrategists.com Android Computing Platform
  • 2.
    Slide 2 of49© People Strategists www.peoplestrategists.com Slide 2 of 57© People Strategists www.peoplestrategists.com
  • 3.
    Slide 3 of49© People Strategists www.peoplestrategists.com Android Introduction • A Software platform and Linux Kernel based operating system for mobile. •Android is Open Source means it is made freely available and may be redistributed and modified. • Android was developed in 2003.
  • 4.
    Slide 4 of49© People Strategists www.peoplestrategists.com History of Android
  • 5.
    Slide 5 of49© People Strategists www.peoplestrategists.com Android Releases Available from November 3rd 2014
  • 6.
    Slide 6 of49© People Strategists www.peoplestrategists.com Android Architecture
  • 7.
    Slide 7 of49© People Strategists www.peoplestrategists.com Linux kernel  This is the core layer of android architecture which provides services like power management, memory management, security and binder for process communication. Android Architecture
  • 8.
    Slide 8 of49© People Strategists www.peoplestrategists.com Native Libraries  These libraries are written in C/C++ like web libraries to access web browser, libraries for android video formats.  Application framework access these libraries Android Architecture
  • 9.
    Slide 9 of49© People Strategists www.peoplestrategists.com Application Framework The set of API's that allow developers to quickly and easily write android app and they are written in a Java programming language. Android Architecture
  • 10.
    Slide 10 of49© People Strategists www.peoplestrategists.com Android Runtime Takes very less time to launch an app, More device Storage. Note : Introduced in Kitkat version Takes time to launch an app, Less device storage Note : Declared dead in Lollipop version
  • 11.
    Slide 11 of49© People Strategists www.peoplestrategists.com Android Architecture
  • 12.
    Slide 12 of49© People Strategists www.peoplestrategists.com Just 25$ for Registration. https://play.google.com/apps /publish/signup/ upload free/ paid apps. Android App Market
  • 13.
    Slide 13 of49© People Strategists www.peoplestrategists.com Android Target
  • 14.
    Slide 14 of49© People Strategists www.peoplestrategists.com Setting Up your Android Development Environment Check System Requirements on below link:- https://developer.android.com/sdk/index.html#Requirements 1. To develop applications for Android platform, you need  Java SE Development Kit (JDK),  Android SDK Integrated IDE (Android Studio) 2. Download the Android Studio http://developer.android.com/sdk/index.html
  • 15.
    Slide 15 of49© People Strategists www.peoplestrategists.com Understanding Project Structure
  • 16.
    Slide 16 of49© People Strategists www.peoplestrategists.com Slide 16 of 57© People Strategists www.peoplestrategists.com Building Block, User Interface and Controls
  • 17.
    Slide 17 of49© People Strategists www.peoplestrategists.com Android Components Activity  Single screen in your application Content Provider  Can expose your data and have your applications use data from other applications.
  • 18.
    Slide 18 of49© People Strategists www.peoplestrategists.com Service  Local services  Remote services. Broadcast Receiver  Allows to register for system or application events Android Components
  • 19.
    Slide 19 of49© People Strategists www.peoplestrategists.com AndroidManifest.xml(Metadata of Android Application)  It lists your application’s activities and services, along with the permissions and features the application needs to run. Syntax : <manifest> <Elements for Application properties should come here> <application> <Elements for application components should come here> </application> </manifest> AndroidManifest
  • 20.
    Slide 20 of49© People Strategists www.peoplestrategists.com Android Virtual Devices  AVD allows developers to test their applications AVD
  • 21.
    Slide 21 of49© People Strategists www.peoplestrategists.com import android.app.Activity; import android.os.Bundle; public class HelloWorld extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } HelloWorld
  • 22.
    Slide 22 of49© People Strategists www.peoplestrategists.com Android the Application Life Cycle
  • 23.
    Slide 23 of49© People Strategists www.peoplestrategists.com Android Resources Compiled and Uncompiled Android Resources • XML files • Raw files
  • 24.
    Slide 24 of49© People Strategists www.peoplestrategists.com String Resources • Define strings in one or more XML resource files. • These XML files containing string-resource definitions reside in the /res/values subdirectory. strings.xml <?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">hello</string> <string name="app_name">hello appname</string> </resources> Android Resources
  • 25.
    Slide 25 of49© People Strategists www.peoplestrategists.com Layout Resources • A key resource used in Android UI programming. public class HelloWorldActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } ... } Android Resources
  • 26.
    Slide 26 of49© People Strategists www.peoplestrategists.com Example main.xml Layout File <?xml version="1.0" encoding="utf- 8"?> <LinearLayout xmlns:android="http://schemas.andr oid.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > </LinearLayout> Android Resources
  • 27.
    Slide 27 of49© People Strategists www.peoplestrategists.com Color Resources <resources> <color name="red">#f00</color> <color name="blue">#0000ff</color> <color name="green">#f0f0</color> <color name="main_back_ground_color"> #ffffff00</color> </resources> Android Resources
  • 28.
    Slide 28 of49© People Strategists www.peoplestrategists.com Color Resources in Java code int mainBackGroundColor = activity.getResources.getColor(R.color.main_back_ground_color); Using Colors in View Definitions <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/red" android:text="Sample Text to Show Red Color"/> Android Resources
  • 29.
    Slide 29 of49© People Strategists www.peoplestrategists.com Dimension Resources You can specify the dimensions in any of the following units: px: Pixels in: Inches mm: Millimeters pt: Points dp: Density-independent pixels based on pixel density per inch sp: Scale-independent pixels (dimensions that allow for user sizing; helpful for use in fonts) Android Resources
  • 30.
    Slide 30 of49© People Strategists www.peoplestrategists.com XML Syntax for Defining Dimension Resources <resources> <dimen name="mysize_in_pixels">1px</dimen> <dimen name="mysize_in_dp">5dp</dimen> <dimen name="medium_size">100sp</dimen> </resources> Using Dimension Resources in XML <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="@dimen/medium_size"/> Android Resources
  • 31.
    Slide 31 of49© People Strategists www.peoplestrategists.com Image Resources Using Image Resources in XML <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Dial" android:background="@drawable/sample_image" /> Android Resources
  • 32.
    Slide 32 of49© People Strategists www.peoplestrategists.com Android Resources package com.mycompany.android.my-root-package; public final class R { ...other entries depending on your project and application public static final class string { ...other entries depending on your project and application publicstaticfinal int hello=0x7f040000; publicstaticfinal int app_name=0x7f040001; ...other entries depending on your project and application } ...other entries depending on your project and application } • R.java with unique IDs for the two string resources specified. R.java
  • 33.
    Slide 33 of49© People Strategists www.peoplestrategists.com Resource Reference Syntax Android resources are identified (or referenced) by their IDs in Java source code. <TextView android:id="@+id/text"> //Success: Creates an id called "text" in the local package's R.java In the syntax "@+id/text", the + sign has a special meaning. It tells Android that the ID text may not already exist Android Resources
  • 34.
    Slide 34 of49© People Strategists www.peoplestrategists.com Android View and ViewGroup
  • 35.
    Slide 35 of49© People Strategists www.peoplestrategists.com Buttons
  • 36.
    Slide 36 of49© People Strategists www.peoplestrategists.com Basic Button <Button android:id="@+id/button1" android:text="@string/basicBtnLabel" android:layout_width="fill_parent" android:layout_height="wrap_content" /> …………………… ImageButton <ImageButton android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="myClickHandler" android:src="@drawable/icon" /> …………….. ImageButton imageButton2 = (ImageButton)this.findViewById(R.id.imageButton2); imageButton2.setImageResource(R.drawable.icon); Buttons
  • 37.
    Slide 37 of49© People Strategists www.peoplestrategists.com ToggleButton <ToggleButton android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Toggle Button" android:textOn="Stop" android:textOff="Run"/> Button button1 = (Button)this.findViewById(R.id.button1); button1.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.androidbook.com")); startActivity(intent); } }); Buttons
  • 38.
    Slide 38 of49© People Strategists www.peoplestrategists.com CheckBox <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <CheckBox android:id="@+id/chickenCB" android:text="Chicken" android:checked="true" android:layout_width=“wrap_content" android:layout_height="wrap_content" /> <CheckBox android:id="@+id/fishCB" android:text="Fish" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <CheckBox android:id="@+id/steakCB" android:text="Steak" android:checked="true" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> CheckBox
  • 39.
    Slide 39 of49© People Strategists www.peoplestrategists.com RadioButton RadioButton <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <RadioGroup android:id="@+id/rBtnGrp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <RadioButton android:id="@+id/chRBtn" android:text="Chicken" android:layout_width="wrap_content" android:layout_height="wrap_content"/> ……………………….. </RadioGroup> </LinearLayout>
  • 40.
    Slide 40 of49© People Strategists www.peoplestrategists.com RadioButton ImageView <ImageView android:id="@+id/img" android:layout_width="wrap_content" android:layout_height="wrap_content“ android:src="@drawable/abc" />
  • 41.
    Slide 41 of49© People Strategists www.peoplestrategists.com DatePicker <DatePicker android:id="@+id/datePicker" android:layout_width="wrap_content" android:layout_height="wrap_content" /> ……………………….. DatePicker dp = (DatePicker)this.findViewById(R.id.datePicker); dateDefault.setText("Date defaulted to " + (dp.getMonth() + 1) + "/" + dp.getDayOfMonth() + "/" + dp.getYear()); dp.init(2008, 11, 10, null); TimePicker <TimePicker android:id="@+id/timePicker" android:layout_width="wrap_content" android:layout_height="wrap_content" /> ……………………….. TimePicker tp = (TimePicker)this.findViewById(R.id.timePicker); tp.setIs24HourView(true); tp.setCurrentHour(new Integer(10)); tp.setCurrentMinute(new Integer(10)); Pickers
  • 42.
    Slide 42 of49© People Strategists www.peoplestrategists.com DigitalClock <DigitalClock android:layout_width="wrap_content" android:layout_height="wrap_content" /> AnalogClock <AnalogClock android:layout_width="wrap_content" android:layout_height="wrap_content" /> Pickers
  • 43.
    Slide 43 of49© People Strategists www.peoplestrategists.com ListView <ListView android:id="@+id/list" android:layout_width=" wrap_content " android:layout_height=" wrap_content " android:entries=“@array/mylist” /> List
  • 44.
    Slide 44 of49© People Strategists www.peoplestrategists.com Layout Manager Layout Manager Description LinearLayout Organizes its children either horizontally or vertically TableLayout Organizes its children in tabular form RelativeLayout Organizes its children relative to one another or to the parent FrameLayout Allows you to dynamically changethe control(s) in the layout
  • 45.
    Slide 45 of49© People Strategists www.peoplestrategists.com Layout Manager LinearLayout <LinearLayout xmlns:android="http://schemas.android.com/a pk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <!—add components--> </LinearLayout>
  • 46.
    Slide 46 of49© People Strategists www.peoplestrategists.com Layout Manager RelativeLayout <RelativeLayout …………… > <TextView android:id="@+id/userNameLbl" android:text="Username: “ android:layout_alignParentTop="true" /> <EditText android:id="@+id/userNameText" android:layout_toRightOf="@id/userNameLbl" /> <TextView android:id="@+id/pwdLbl" android:layout_below="@id/userNameText" android:text="Password: " /> <EditText android:id="@+id/pwdText" android:layout_toRightOf="@id/pwdLbl" android:layout_below="@id/userNameText" /> <TextView android:id="@+id/pwdCriteria" android:layout_below="@id/pwdText" android:text="Password Criteria... " /> </RelativeLayout>
  • 47.
    Slide 47 of49© People Strategists www.peoplestrategists.com TableLayout <TableLayout ……… > <TableRow> <TextView android:text="First Name:“ android:layout_width="wrap_content" android:layout_height="wrap_content" /> <EditText android:text="Edgar“ android:layout_width="wrap_content" android:layout_height="wrap_content" /> </TableRow> <TableRow> <TextView android:text="Last Name:" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <EditText android:text="Poe" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </TableRow> </TableLayout> Layout Manager
  • 48.
    Slide 48 of49© People Strategists www.peoplestrategists.com Layout Manager FrameLayout <FrameLayout android:id="@+id/frmLayout" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ImageView android:id="@+id/oneImgView" android:src="@drawable/one" android:scaleType="fitCenter" android:layout_width="fill_parent" android:layout_height="fill_parent"/> <ImageView android:id="@+id/twoImgView" android:src="@drawable/two" android:scaleType="fitCenter" android:layout_width="fill_parent" android:layout_height="fill_parent" android:visibility="gone" /> </FrameLayout>
  • 49.
    Slide 49 of49© People Strategists www.peoplestrategists.com Styles <?xml version="1.0" encoding="utf-8"?> <resources> <style name=“SpelError"> <item name="android:layout_width">fill_parent</item> <item name="android:layout_height">wrap_content</item> <item name="android:textColor">#FF0000</item> <item name="android:typeface">monospace</item> </style> </resources> ……………….. <TextView android:id="@+id/errorText" style="@style/ SpelError" android:text=“Styling” /> Styles
  • 50.
    Slide 50 of49© People Strategists www.peoplestrategists.com Themes If you have some style elements you want applied across an entire activity, or across the whole application, you should use a theme instead. A theme is it’s exactly like a style. To specify a theme for an activity or an application, we would add an attribute to the <activity>or <application>tag in the AndroidManifest.xml. <activity android:theme="@style/MyActivityTheme"> <application android:theme="@style/MyApplicationTheme"> Themes
  • 51.
    Slide 51 of49© People Strategists www.peoplestrategists.com Slide 51 of 57© People Strategists www.peoplestrategists.com
  • 52.
    Slide 52 of49© People Strategists www.peoplestrategists.com Intent A mechanism to communicate from one component to another. It defines intention of an application and also used to transfer data. An Intent mainly can be used :-  To start an activity or service.  To transfer data etc.
  • 53.
    Slide 53 of49© People Strategists www.peoplestrategists.com Intent Types of Intents:-  Implicit
  • 54.
    Slide 54 of49© People Strategists www.peoplestrategists.com Intents  Explicit
  • 55.
    Slide 55 of49© People Strategists www.peoplestrategists.com Built-in Intent Actions Intent
  • 56.
    Slide 56 of49© People Strategists www.peoplestrategists.com Data Passing An intent can include an additional attribute called extras which can be used to pass data. This extra information is represented by an Android class called android.os.Bundle. // Place a bundle in an intent Bundle anotherBundle = new Bundle(); //populate the bundle with key/value pairs //and then set the bundle on the Intent intent.putExtras(anotherBundle); //Get the Bundle from an Intent Bundle extraBundle = intent.getExtras();
  • 57.
    Slide 57 of49© People Strategists www.peoplestrategists.com Data Passing You can use a number of methods to add fundamental types to the bundle. putExtra(String name, boolean value); putExtra(String name, int value); putExtra(String name, double value); putExtra(String name, String value);