Android Java Live and In Action



Similar documents
Tutorial #1. Android Application Development Advanced Hello World App

Getting Started: Creating a Simple App

Android Basics. Xin Yang

INTRODUCTION TO ANDROID CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 11 02/15/2011

Admin. Mobile Software Development Framework: Android Activity, View/ViewGroup, External Resources. Recap: TinyOS. Recap: J2ME Framework

Building Your First App

Now that we have the Android SDK, Eclipse and Phones all ready to go we can jump into actual Android development.

Introduction to Android SDK Jordi Linares

Android Programming Basics

Chapter 2 Getting Started

MMI 2: Mobile Human- Computer Interaction Android

directory to "d:\myproject\android". Hereafter, I shall denote the android installed directory as

@ME (About) Marcelo Cyreno. Skype: marcelocyreno Linkedin: marcelocyreno Mail:

Android Application Development

06 Team Project: Android Development Crash Course; Project Introduction

Android For Java Developers. Marko Gargenta Marakana

Presenting Android Development in the CS Curriculum

Jordan Jozwiak November 13, 2011

How to develop your own app

Android Development. Marc Mc Loughlin

Android Security Lab WS 2014/15 Lab 1: Android Application Programming

Q1. What method you should override to use Android menu system?

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

An Introduction to Android Application Development. Serdar Akın, Haluk Tüfekçi

Arduino & Android. A How to on interfacing these two devices. Bryant Tram

Basics of Android Development 1

23442 ECE Introduction to Android Mobile Programming ECE Special Topics: Android Mobile Programming

Android Development Tutorial

Android Programming. Høgskolen i Telemark Telemark University College. Cuong Nguyen,

Developing NFC Applications on the Android Platform. The Definitive Resource

Lab 1 (Reading Sensors & The Android API) Week 3

Android Development. 吳 俊 興 國 立 高 雄 大 學 資 訊 工 程 學 系

Introduction to Android Programming (CS5248 Fall 2015)

2. Click the download button for your operating system (Windows, Mac, or Linux).

Android Environment SDK

Android Application Development: Hands- On. Dr. Jogesh K. Muppala

Mocean Android SDK Developer Guide

Mobile Application Development

App Development for Smart Devices. Lec #4: Services and Broadcast Receivers Try It Out

Introduction to NaviGenie SDK Client API for Android

Introduction to Android. CSG250 Wireless Networks Fall, 2008

Programming with Android: System Architecture. Dipartimento di Scienze dell Informazione Università di Bologna

Getting started with Android and App Engine

Android 多 核 心 嵌 入 式 多 媒 體 系 統 設 計 與 實 作

Android Environment SDK

ELET4133: Embedded Systems. Topic 15 Sensors

4. The Android System

App Development for Smart Devices. Lec #2: Android Tools, Building Applications, and Activities

How To Develop Android On Your Computer Or Tablet Or Phone

Getting Started With Android

OpenCV on Android Platforms

Developing apps for Android OS: Develop an app for interfacing Arduino with Android OS for home automation

ECWM511 MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction to Android

Mobile Application Development 2014

Mobile Application Development Android

Android Application Development. Daniel Switkin Senior Software Engineer, Google Inc.

Frameworks & Android. Programmeertechnieken, Tim Cocx

Università Degli Studi di Parma. Distributed Systems Group. Android Development. Lecture 2 Android Platform. Marco Picone

Advantages. manage port forwarding, set breakpoints, and view thread and process information directly

CSE476 Mobile Application Development. Yard. Doç. Dr. Tacha Serif Department of Computer Engineering Yeditepe University

BEGIN ANDROID JOURNEY IN HOURS

Login with Amazon Getting Started Guide for Android. Version 2.0

How to Create an Android Application using Eclipse on Windows 7

Android Concepts and Programming TUTORIAL 1

Developing an Android App. CSC207 Fall 2014

Android Introduction. Hello Mihail L. Sichitiu 1

Developing Android Applications Introduction to Software Engineering Fall Updated 7 October 2015

PubMatic Android SDK. Developer Guide. For Android SDK Version 4.3.5

Introduction to Android Development. Jeff Avery CS349, Mar 2013

IOIO for Android Beginners Guide Introduction

Getting Started with Android

ECWM511 MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction to Android

Android App Development. Rameel Sethi

Developing Android Apps: Part 1

With a single download, the ADT Bundle includes everything you need to begin developing apps:

Backend as a Service

Specialized Android APP Development Program with Java (SAADPJ) Duration 2 months

Android App Development Lloyd Hasson 2015 CONTENTS. Web-Based Method: Codenvy. Sponsored by. Android App. Development

Android Services. Services

Generate Android App

AndroLIFT: A Tool for Android Application Life Cycles

Getting Started with Android Development

Introduction to Android: Hello, Android! 26 Mar 2010 CMPT166 Dr. Sean Ho Trinity Western University

Based on Android 4.0. by Lars Vogel. Version 9.8. Copyright 2009, 2010, 2011, 2012 Lars Vogel Home Tutorials Trainings Books Social

Android Application Development - Exam Sample

Homeschool Programming, Inc.

MAP524/DPS924 MOBILE APP DEVELOPMENT (ANDROID) MIDTERM TEST OCTOBER 2013 STUDENT NAME STUDENT NUMBER

Android Development Tutorial. Human-Computer Interaction II (COMP 4020) Winter 2013

Location-Based Services Design and Implementation Using Android Platforms

Transcription:

Android Java Live and In Action Norman McEntire Founder, Servin Corp UCSD Extension Instructor norman.mcentire@servin.com Copyright (c) 2013 Servin Corp 1

Opening Remarks Welcome! Thank you! My promise to you is this: Show you Android Java skills faster than any method on planet earth Great INTRO if you are new to Android Java Great REVIEW if you already know Android Java Copyright (c) 2013 Servin Corp 2

Agenda Part 1-7:15pm - 7:50pm 100% Android Java Source Code (No XML) Architecture, Tools, Activities, Intents Part 2 8pm - 8:45pm XML + Android Java Source Code XML, Activities, Broadcast Receivers, Services, and Content Providers Part 3 8:45pm - 9pm Questions/Answers Copyright (c) 2013 Servin Corp 3

Summer 2013 UCSD Extension Android I Programming Course This presentation is a SAMPLE of the Android I Programming Course I give at UCSD Extension Summer 2013 Starts June 29! 100% On-Line! REPEAT: 100% ON-LINE! Register Today! http://extension.ucsd.edu Android I always fills up! Register Today! Copyright (c) 2013 Servin Corp 4

UCSD Extension Android I Programming - Course Schedule Total of Nine Lessons One Lesson Per Week Format of Each Lesson Slides for Concepts Coding Demos Quiz Programming Assignment Copyright (c) 2013 Servin Corp 5

Course Lessons Lesson 1. Introduction Lesson 2. Widgets Lesson 3. Activities and Intents Lesson 4. Storage Lesson 5. Internet Lesson 6. Multimedia Lesson 7. Broadcast Receivers Lesson 8. Services Lesson 9. Content Providers Copyright (c) 2013 Servin Corp 6

About MySelf Norman McEntire norman.mcentire@servin.com B.S/M.S. Computer Engineering University of South Carolina 30+ Years Computer Engineering Experience Hardware and Software (Android, ios, Linux) UCSD Extension Instructor Android I, Intro to Objective-C, ios I, ios II Founder/Owner of Servin Corp Since 1995, Software Technology Training for Software Technology Professionals(tm) Copyright (c) 2013 Servin Corp 7

Question: Why Cover Android Java at SDJUG? Copyright (c) 2013 Servin Corp 8

Why Cover Android Java at SDJUG? Answer #1: Android Java is ONE OF the most widely used versions of Java used by Java Software Developers Answer #2: Android Java is THE most widely run JVM: 1+ Million More PER DAY! Copyright (c) 2013 Servin Corp 9

So for the members of SDJUG, knowing Android Java is a valuable addition to your Java Skills Set Copyright (c) 2013 Servin Corp 10

Part 1 100% Android Java Source Code (No XML) Architecture, Tools, and Activities Copyright (c) 2013 Servin Corp 11

Key Android Skill Android Architecture Copyright (c) 2013 Servin Corp 12

Android Architecture Android Java Apps Android Java Virtual Machine C-Language Libraries Linux OS Hardware Copyright (c) 2013 Servin Corp 13

Key Android Skill: Android Development Tools Copyright (c) 2013 Servin Corp 14

ADT = Android Developer Tools You can download ADT Bundle from here: http://developer.android.com Copyright (c) 2013 Servin Corp 15

Step 1. Startup ADT (Eclipse) Click on Green icon on Desktop Quick Tour of Eclipse Workspace Perspective Views Java Perspective DDMS Perspective Debug Perspective Copyright (c) 2013 Servin Corp 16

Step 2. Create New Android Application Project File > New > Android Application Project Application Name: SDJUG Project Name: SDJUG Package Name: org.sdjug.android.hello Minimum Required SDK: API 8 DEMO: An aside on Android Versioning Target SDK: 17 Next > Next > Next > Finish Copyright (c) 2013 Servin Corp 17

Key Android Skill android.app.activity Copyright (c) 2013 Servin Corp 18

MainActivity.java package org.sdjug.android.hello; Package name will also be your process name! import android.os.bundle import android.app.activity public class MainActivity extends Activity protected void oncreate(bundle savedinstance) super.oncreate(savedinstance) //Not yet! setcontentview(r.layout.activity_main) Copyright (c) 2013 Servin Corp 19

Key Android Skill android.widget.toast Copyright (c) 2013 Servin Corp 20

android.widget.toast Displays a floating view over the application Never receives focus Disappears after a brief moment Example oncreate() Toast.makeText(this, oncreate, Toast.LENGTH_LONG).show(); Copyright (c) 2013 Servin Corp 21

Key Android Skill Activity Lifecycle Copyright (c) 2013 Servin Corp 22

Activity Lifecycle Demo 1 oncreate(), onrestart(), ondestroy() Demo 2 onstart(), onstop() - view/hide onresume(), onpause() - interact/no-interact What to test for each demo 1. Pressing HOME key 2. Pressing BACK key 3. Rotating Device Copyright (c) 2013 Servin Corp 23

Key Android Skill Touch Handling Copyright (c) 2013 Servin Corp 24

ontouchevent() public boolean ontouchevent(motionevent event) switch (event.getaction()) case MotionEvent.ACTION_DOWN: // Handle Motion Down return true case MotionEvent.ACTION_UP: // Handle Motion Up return true return super.ontouchevent(event) Copyright (c) 2013 Servin Corp 25

Key Android Skill android.view.view Copyright (c) 2013 Servin Corp 26

android.view.view All user interface elements in Android Java are built using View and ViewGroup objects A View draws something on the screen Demo View view oncreate() view = new View(this) view.setbackgroundcolor(color.red) setcontentview(view) Copyright (c) 2013 Servin Corp 27

android.graphics.color Android color is a 32-bit value Alpha, Red, Green, Blue Demo 1 int color = Color.YELLOW view.setbackgroundcolor(color) Demo 2 int color = Color.argb(255,0,255,0); //Green view.setbackgroundcolor(color) Copyright (c) 2013 Servin Corp 28

android.widget.linearlayout A ViewGroup is an object that holds other View and ViewGroup Objects Demo LinearLayout linearlayout linearlayout = new LinearLayout(this) linearlayout.setorientation(linearlayout.vertica L) linearlayout.setbackgroundcolor(color.green) setcontentview(linearlayout) Copyright (c) 2013 Servin Corp 29

android.widget.textview Use a TextView widget to display text on the screen Demo TextView textview int width = LinearLayout.LayoutParams.MATCH_PARENT int height = LinearLayout.LayoutParams.WRAP_CONTENT textview = new TextView(this) textview.setbackgroundcolor(color.yellow) linearlayout.addview(textview,width,height) Copyright (c) 2013 Servin Corp 30

android.widget.button - 1 Use a Button to allow user to send event to app Demo Button button int width = LinearLayout.LayoutParams.MATCH_PARENT int height = LinearLayout.LayoutParams.WRAP_CONTENT button = new Button(this) button.setbackgroundcolor(color.cyan) button.settext( Touch Me! ) linearlayout.addview(button,width,height) Copyright (c) 2013 Servin Corp 31

android.widget.button - 2 Using Anonymous Inner class to respond to button touch Demo button.setonclicklistener(new View.OnClickListener() public void onclick(view view) Toast.makeText(MainActivity.this, Touched The Button!, Toast.LENGTH_LONG).show() Copyright (c) 2013 Servin Corp 32

android.content.intent An intent provides a facility for performing late runtime binding The code can be in different applications The most significant use of an Intent is launching activities Demo Intent intent = new Intent() intent.setaction(intent.action_dial) startactivity(intent) Copyright (c) 2013 Servin Corp 33

Part 1 Summary 100% Android Java Source Code Architecture Android Developer Tools Activity (including Activity Lifecycle) Toast ontouchevent(motionevent event) View TextView Button Intent Copyright (c) 2013 Servin Corp 34

Android Java Live and In Action Part 2 XML + Android Java Norman McEntire Founder, Servin Corp UCSD Extension Instructor norman.mcentire@servin.com Copyright (c) 2013 Servin Corp 35

Key Android Skill AndroidManifest.xml Copyright (c) 2013 Servin Corp 36

AndroidManifest.xml The AndroidManifest.xml file defines all of your applications components <?xml version= 1.0 encoding= utf-8?> <manifest <uses-sdk <application <activity... <receiver <service <provider... Copyright (c) 2013 Servin Corp 37

To Create New Activity <activity /> The Activity is the foundation of the user interface 1. Select AndroidManifest.xml 2. Select Application Tab 3. Scroll to bottom 4. Application Nodes Add Activity Click on Name Hyperlink Name: AboutActivity Superclass: android.app.activity Copyright (c) 2013 Servin Corp 38

AboutActivity.java oncreate() settitle( About This App ) Button button = new Button(this) button.settext( Touch Button\nTo End Activity ) button.setonclicklistener(new View.OnClickListener() public void onclick(view view) finish(); setcontentview(button); Copyright (c) 2013 Servin Corp 39

MainActivity.java ondoaboutactivity() Intent intent = new Intent(this, AboutActivity.class) startactivity(intent) Copyright (c) 2013 Servin Corp 40

To Create New Broadcast Receiver <receiver /> A Broadcast Receiver receives broadcasts 1. Select AndroidManifest.xml 2. Select Application Tab 3. Scroll to bottom 4. Application Nodes Add Receiver Click on Name Hyperlink Name: MyReceiver Superclass: android.content.broadcastreceiver Copyright (c) 2013 Servin Corp 41

To Create New Service <service /> A Service runs in the background without a user interface 1. Select AndroidManifest.xml 2. Select Application Tab 3. Scroll to bottom 4. Application Nodes Add Service Click on Name Hyperlink Name: MyService Superclass: android.app.service Copyright (c) 2013 Servin Corp 42

To Create New Provider <provider /> A Content Provider provides content to other applications 1. Select AndroidManifest.xml 2. Select Application Tab 3. Scroll to bottom 4. Application Nodes Add Provider Click on Name Hyperlink Name: MyProvider Superclass: android.content.contentprovider Authorities: org.sdjug.android.demo Copyright (c) 2013 Servin Corp 43

Key Android Skill XML Layout Copyright (c) 2013 Servin Corp 44

res/layout res/layout/main.xml Use this as the default layout res/layout-port/main.xml Use this as the layout for portrait mode res/layout-land/main.xml Use this as the layout for landscape mode Copyright (c) 2013 Servin Corp 45

res/layout/main.xml <?xml version= 1.0 encoding= utf-8?> <LinearLayout android:layout_width= match_parent android:layout_height= match_parent android:orientation= vertical > <View android:id= @+id/view1 android:layout_width= wrap_content android:layout_height= wrap_content Copyright (c) 2013 Servin Corp 46

Key Android Skill Mapping XML ids To Java Objects Copyright (c) 2013 Servin Corp 47

findviewbyid() Use findviewbyid() to map from XML layout to Android Java class View view view = findviewbyid(r.id.view1)... Copyright (c) 2013 Servin Corp 48

Key Android Skill XML Values Copyright (c) 2013 Servin Corp 49

res/values/strings.xml <?xml version= 1.0 encoding= utf-8?> <resources> <string name= app_name >SDJUG</string> <string name= hello_world >Hello World!</string> </resources> Copyright (c) 2013 Servin Corp 50

res/values/colors.xml <?xml version= 1.0 encoding= utf-8?> <resources> <color name= green >#ff00ff00</color> </resources> Copyright (c) 2013 Servin Corp 51

getresources().getcolor() Use getresources().getcolor() to map from XML value to integer color View view view = findviewbyid(r.id.view1) int color = getresources().getcolor(r.color.green) view.setbackgroundcolor(color) Copyright (c) 2013 Servin Corp 52

Part 2 Summary XML + Android Java Source Code AndroidManifest.xml res/layout res/layout-port/main.xml res/layout-land/main.xml findviewbyid() res/values res/values/strings.xml res/values/colors.xml Copyright (c) 2013 Servin Corp 53

Summary This was a sample of the topics covered in the UCSD Extension Course titled Android I Programming Starts June 29! 100% ON-LINE! Register Today! In Part 1, we did an app with 100% Android Java Source Code In Part 2, we did an app with XML + Android Java Source Code Copyright (c) 2013 Servin Corp 54

Part 3 Questions / Answers Copyright (c) 2013 Servin Corp 55