57
Slide 1 of 49 © People Strategists www.peoplestrategists.com Android Computing Platform

Android - Day 1

Embed Size (px)

Citation preview

Page 1: Android - Day 1

Slide 1 of 49© People Strategists www.peoplestrategists.com

Android Computing Platform

Page 2: Android - Day 1

Slide 2 of 49© People Strategists www.peoplestrategists.com Slide 2 of 57© People Strategists www.peoplestrategists.com

Complete, end-to-end software platform

Page 3: Android - Day 1

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.

Page 4: Android - Day 1

Slide 4 of 49© People Strategists www.peoplestrategists.com

History of Android

Page 5: Android - Day 1

Slide 5 of 49© People Strategists www.peoplestrategists.com

Android Releases

Available fromNovember 3rd 2014

Page 6: Android - Day 1

Slide 6 of 49© People Strategists www.peoplestrategists.com

Android Architecture

Page 7: Android - Day 1

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

Page 8: Android - Day 1

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

Page 9: Android - Day 1

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

Page 10: Android - Day 1

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 storageNote : Declared dead in Lollipop version

Page 11: Android - Day 1

Slide 11 of 49© People Strategists www.peoplestrategists.com

Android Architecture

Page 12: Android - Day 1

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

Page 13: Android - Day 1

Slide 13 of 49© People Strategists www.peoplestrategists.com

Android Target

Page 14: Android - Day 1

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

Page 15: Android - Day 1

Slide 15 of 49© People Strategists www.peoplestrategists.com

Understanding Project Structure

Page 16: Android - Day 1

Slide 16 of 49© People Strategists www.peoplestrategists.com Slide 16 of 57© People Strategists www.peoplestrategists.com

Building Block,User Interface and Controls

Page 17: Android - Day 1

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.

Page 18: Android - Day 1

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

Page 19: Android - Day 1

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

Page 20: Android - Day 1

Slide 20 of 49© People Strategists www.peoplestrategists.com

Android Virtual Devices

AVD allows developers to test their applications

AVD

Page 21: Android - Day 1

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

Page 22: Android - Day 1

Slide 22 of 49© People Strategists www.peoplestrategists.com

Android the Application Life Cycle

Page 23: Android - Day 1

Slide 23 of 49© People Strategists www.peoplestrategists.com

Android Resources

Compiled and Uncompiled Android Resources• XML files • Raw files

Page 24: Android - Day 1

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

Page 25: Android - Day 1

Slide 25 of 49© People Strategists www.peoplestrategists.com

Layout Resources• A key resource used in

Android UI programming.

public class HelloWorldActivity extends Activity{@Overridepublic void onCreate(Bundle savedInstanceState){

super.onCreate(savedInstanceState);setContentView(R.layout.main);

}...}

Android Resources

Page 26: Android - Day 1

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.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"></LinearLayout>

Android Resources

Page 27: Android - Day 1

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

Page 28: Android - Day 1

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

Page 29: Android - Day 1

Slide 29 of 49© People Strategists www.peoplestrategists.com

Dimension ResourcesYou can specify the dimensions in any of the following units:

px: Pixelsin: Inchesmm: Millimeterspt: Pointsdp: Density-independent pixels based on pixel density per inchsp: Scale-independent pixels (dimensions that allow for user sizing;helpful for use in fonts)

Android Resources

Page 30: Android - Day 1

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

Page 31: Android - Day 1

Slide 31 of 49© People Strategists www.peoplestrategists.com

Image Resources

Using Image Resources in XML<Buttonandroid:id="@+id/button1"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="Dial"android:background="@drawable/sample_image"/>

Android Resources

Page 32: Android - Day 1

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 applicationpublic static final class string{...other entries depending on your project and application

public static final int hello=0x7f040000;public static final 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

Page 33: Android - Day 1

Slide 33 of 49© People Strategists www.peoplestrategists.com

Resource Reference SyntaxAndroid 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

Page 34: Android - Day 1

Slide 34 of 49© People Strategists www.peoplestrategists.com

Android View and ViewGroup

Page 35: Android - Day 1

Slide 35 of 49© People Strategists www.peoplestrategists.com

Buttons

Page 36: Android - Day 1

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

Page 37: Android - Day 1

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

Page 38: Android - Day 1

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

Page 39: Android - Day 1

Slide 39 of 49© People Strategists www.peoplestrategists.com

RadioButtonRadioButton

<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>

Page 40: Android - Day 1

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" />

Page 41: Android - Day 1

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

Page 42: Android - Day 1

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

Page 43: Android - Day 1

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

Page 44: Android - Day 1

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

Page 45: Android - Day 1

Slide 45 of 49© People Strategists www.peoplestrategists.com

Layout Manager

LinearLayout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">

<!—add components-->

</LinearLayout>

Page 46: Android - Day 1

Slide 46 of 49© People Strategists www.peoplestrategists.com

Layout ManagerRelativeLayout<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>

Page 47: Android - Day 1

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

Page 48: Android - Day 1

Slide 48 of 49© People Strategists www.peoplestrategists.com

Layout ManagerFrameLayout<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>

Page 49: Android - Day 1

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

Page 50: Android - Day 1

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

Page 51: Android - Day 1

Slide 51 of 49© People Strategists www.peoplestrategists.com Slide 51 of 57© People Strategists www.peoplestrategists.com

Understanding Intents

Page 52: Android - Day 1

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.

Page 53: Android - Day 1

Slide 53 of 49© People Strategists www.peoplestrategists.com

Intent

Types of Intents:- Implicit

Page 54: Android - Day 1

Slide 54 of 49© People Strategists www.peoplestrategists.com

Intents

Explicit

Page 55: Android - Day 1

Slide 55 of 49© People Strategists www.peoplestrategists.com

Built-in Intent Actions

Intent

Page 56: Android - Day 1

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 intentBundle anotherBundle = new Bundle();

//populate the bundle with key/value pairs//and then set the bundle on the Intentintent.putExtras(anotherBundle);

//Get the Bundle from an IntentBundle extraBundle = intent.getExtras();

Page 57: Android - Day 1

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);