Android Bootcamp. Elaborado (com adaptações) a partir dos tutoriais:



Similar documents
Android Introduction. Hello Mihail L. Sichitiu 1

Getting Started With Android

MMI 2: Mobile Human- Computer Interaction Android

Chapter 2 Getting Started

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

Mobile Application Development

Tutorial #1. Android Application Development Advanced Hello World App

Android App Development. Rameel Sethi

Android Development. Marc Mc Loughlin

Android Persistency: Files

Developing an Android App. CSC207 Fall 2014

Android Programming Basics

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

Android Application Development. Yevheniy Dzezhyts

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

Android For Java Developers. Marko Gargenta Marakana

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

Saindo da zona de conforto resolvi aprender Android! by Daniel Baccin

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

Building Your First App

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

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

Developing Android Applications: Case Study of Course Design

Android Concepts and Programming TUTORIAL 1

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

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

ECWM511 MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction to Android

How to Create an Android Application using Eclipse on Windows 7

Developing Android Apps: Part 1

Getting Started: Creating a Simple App

TUTORIAL. BUILDING A SIMPLE MAPPING APPLICATION

App Development for Android. Prabhaker Matet

Android Java Live and In Action

Android Services. Services

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

How to develop your own app

4. The Android System

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

Android Environment SDK

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

Basics. Bruce Crawford Global Solutions Manager

Location-Based Services Design and Implementation Using Android Platforms

Presenting Android Development in the CS Curriculum

By sending messages into a queue, we can time these messages to exit the cue and call specific functions.

Mocean Android SDK Developer Guide

Introduction to Android SDK Jordi Linares

Getting started with Android and App Engine

Android Development Tutorial

Android Basics. Xin Yang

How to build your first Android Application in Windows

Backend as a Service

Les fragments. Programmation Mobile Android Master CCI. Une application avec deux fragments. Premier layout : le formulaire

Creating a List UI with Android. Michele Schimd

Tutorial for developing the Snake Game in Android: What is Android?

Hello World. by Elliot Khazon

Android Apps Development Boot Camp. Ming Chow Lecturer, Tufts University DAC 2011 Monday, June 6, 2011

Android Programming. An Introduction. The Android Community and David Read. For the CDJDN April 21, 2011

Android Application Development

PROJECT REPORT. Android Application

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

ADITION Android Ad SDK Integration Guide for App Developers

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

Android Environment SDK

Localization and Resources

Android-Entwicklung. Michael secure Stapelberg

Woubshet Behutiye ANDROID ECG APPLICATION DEVELOPMENT

Exemplo 12 usa fragmentos de acordo com a orientação da tela (landscape ou portrait)

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

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

Android Programming Tutorials. by Mark L. Murphy

ANDROID AS A PLATFORM FOR DATABASE APPLICATION DEVELOPMENT

BEGIN ANDROID JOURNEY IN HOURS

andbook! Android Programming written by Nicolas Gramlich release with Tutorials from the anddev.org-community.

Create Your Own Android App Tools Using ArcGIS Runtime SDK for Android

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

AdFalcon Android SDK Developer's Guide. AdFalcon Mobile Ad Network Product of Noqoush Mobile Media Group

A software stack for mobile devices:

Advertiser Campaign SDK Your How-to Guide

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

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

Android Application Development - Exam Sample

Getting Started with Android Programming (5 days) with Android 4.3 Jelly Bean

ANDROID APP DEVELOPMENT: AN INTRODUCTION CSCI /19/14 HANNAH MILLER

Transcription:

Android Bootcamp Elaborado (com adaptações) a partir dos tutoriais: http://developer.android.com/resources/tutorials/hello-world.html http://developer.android.com/resources/tutorials/views/index.html

Bootcamp Pen Drive Por favor, copie a partir do pen drive a pasta BOOTCAMP para o seu notebook.

Instalação do Plugin ADT No Eclipse: Help -> Install New Software... -> Add Name: Android Plugin Archive: ADT-10.0.0.zip (no diretório BOOTCAMP) [x] Developer Tools [ ] DESMARQUE "Check all update sites..." Next, next, next..., restart.

Configurar Localização do SDK No Eclipse: Preferences -> Android SDK Location: BOOTCAMP/android-sdk.../ Clicar "Apply" Clicar "OK"

Criar um Virtual Device Window -> AVD Manager -> Virtual Devices->New Name: MyAVD Target: Android 2.1 Resolution/Built-In: HVGA Create AVD Close

Projeto Hello World File -> New -> Android Project Project Name: Hello World Build Target: Android 2.1 Properties: Application Name: Hello World Package Name: com.example.helloworld Create Activity: HelloActivity

src/com/example/helloactivity.java - oncreate() - Bundle savedinstancestate - setcontentview(r.layout.main);

Android Application Lifecycle

res/layout/main.xml Define o layout da Activity

LinearLayout res/layout/main.xml

res/layout/main.xml android:orientation="vertical" android:layout_width / android:layout_height "fill_parent" "wrap_content" "@string/hello"

res/values/strings.xml Cadeias de caracteres da aplicação

Teste Project -> Run (Ctrl + Shift + F11)

Isto é uma atividade

Hello World é legal... mas é chato.

Upgrade: Uma lista

Crear res/layout/list_item.xml [1] <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp" android:textsize="16sp" > </TextView> Define o layout de cada item da lista

Modificar res/layout/main.xml [2] <?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" > <ListView android:id="@+id/mylistview" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout>

HelloActivity.java [3] public class HelloActivity extends Activity implements OnItemClickListener { static final String[] COUNTRIES = { "Brazil", "Argentina","Mexico" }; @Override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); ListView lv = (ListView) findviewbyid(r.id.mylistview); lv.setadapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES)); lv.setonitemclicklistener(this); } public void onitemclick(adapterview<?> parent, View view, int pos, long id) { Toast.makeText(getApplicationContext(), ((TextView) view).gettext(), Toast.LENGTH_SHORT).show(); }

Teste Project -> Run (Ctrl + Shift + F11)

EditText e Botão para Adicionar

Modificar main.xml [4] <?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:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/mytextview" android:layout_width="200sp" android:layout_height="wrap_content" android:text=""/> <Button android:id="@+id/mybutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="adicionar"/> </LinearLayout> <ListView android:id="@+id/mylistview" android:layout_width="fill_parent" android:layout_height="fill_parent"/> </LinearLayout>

Teste Project -> Run (Ctrl + Shift + F11)

Agora vamos implementar...

package com.example.helloworld; import... HelloActivity.java [5] public class HelloActivity extends Activity implements OnItemClickListener, OnClickListener { private List<String> countries = new ArrayList<String>(); private ArrayAdapter<String> adapter; @Override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); countries.add("mexico"); ListView lv = (ListView) findviewbyid(r.id.mylistview); adapter = new ArrayAdapter<String>( this, R.layout.list_item, countries); lv.setadapter(adapter); lv.setonitemclicklistener(this); Button btn = (Button) findviewbyid(r.id.mybutton); btn.setonclicklistener(this); }...

... HelloActivity.java [5] public void onitemclick(adapterview<?> parent, View view, int pos, long id) { Toast.makeText(getApplicationContext(), ((TextView)view).getText(), Toast.LENGTH_SHORT).show(); } public void onclick(view view) { EditText et = (EditText) findviewbyid(r.id.mytextview); countries.add(et.gettext().tostring()); adapter.notifydatasetchanged(); }

Teste Project -> Run (Ctrl + Shift + F11)

Experimento Fechar a aplicação (apertando "Home") Iniciar novamente a partir do menu de aplicações. Qual é o resultado?

Resultado O conteúdo continua na lista. Por que isso acontece?

Experimento Porque o Android faz "Activity Lifecycle Management"...e pode manter ativas ou fechar Activities conforme a necessidade

Experimento 2 Fechar a aplicação (apertando "Home") Fazer Force Close através do menu Menu -> Manage Apps -> Hello World -> Force Close Iniciar novamente a partir do menu de aplicações. Qual é o resultado?

Resultado O conteúdo sumiu.

Persistência Fácil -> SharedPreferences Completo -> SQLite

Fácil -> SharedPreferences Completo -> Base de datos SQLite

SharedPreferences SharedPreferences sp = getpreferences(mode_private); Ler: String x = sp.getstring("key", "defaultvalue"); Gravar: SharedPreferences.Editor spe = sp.edit(); spe.putstring("key", "value"); spe.commit();

HelloActivity.java [6] void savedata() { SharedPreferences.Editor spe = getpreferences(mode_private).edit(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < countries.size(); i++) sb.append( ((i == 0)? "" : ";") + countries.get(i)); spe.putstring("countries", sb.tostring()); spe.commit(); } void loaddata() { SharedPreferences sp = getpreferences(mode_private); String countrylist = sp.getstring("countries", "Argentina;Brazil;Chile;Mexico"); for (String country : countrylist.split(";")) countries.add(country); }

HelloActivity.java [6] public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); loaddata(); ListView lv = (ListView) findviewbyid(r.id.mylistview); adapter = new ArrayAdapter<String>(this, R.layout.list_item, countries); lv.setadapter(adapter); lv.setonitemclicklistener(this); Button btn = (Button) findviewbyid(r.id.mybutton); btn.setonclicklistener(this); }

HelloActivity.java [6] public void onclick(view view) { EditText et = (EditText) findviewbyid(r.id.mytextview); countries.add(et.gettext().tostring()); adapter.notifydatasetchanged(); } savedata();

Teste Project -> Run (Ctrl + Shift + F11)

O "Toast" que aparece quando clicamos na lista também está sem graça... Como se pode implementar uma busca na web no lugar do Toast?

... HelloActivity.java [7] public void onitemclick(adapterview<?> parent, View view, int pos, long id) { Uri uri = Uri.parse("http://en.wikipedia.org/" + "wiki/" + Uri.encode(countries.get(pos), null)); Intent intent = new Intent( Intent.ACTION_VIEW, uri); startactivity(intent); }

Obrigado!