Вы находитесь на странице: 1из 173

Desenvolvimento Android

Pontap inicial...

Toshi Kurauchi

andrew.kurauchi@gmail.com

@toshikurauchi

Por que desenvolver para Android?

Por que desenvolver para Android?

Por que desenvolver para Android?

Por que desenvolver para Android?

Por que desenvolver para Android?

Por que desenvolver para Android?

Por que desenvolver para Android?

Tudo o que voc precisa saber:

Tudo o que voc precisa saber:

http://developer.android.com/index.html

Dvidas?

Obrigado!

Quero desenvolver para Android!!!

Quero desenvolver para Android!!!


1. Baixar o SDK

Quero desenvolver para Android!!!


1. Baixar o SDK 2. Instalar o Eclipse

Quero desenvolver para Android!!!


1. Baixar o SDK 2. Instalar o Eclipse 3. Instalar o plugin do ADT para o Eclipse

E mais um pouco de download...


Window -> Android SDK Manager

E mais um pouco de download...


Window -> Android SDK Manager

E mais um pouco de download...


Window -> Android SDK Manager

E mais um pouco de download...


Window -> Android SDK Manager

E mais um pouco de download...


Window -> Android SDK Manager
API Levels?

E mais um pouco de download...


Window -> Android SDK Manager
API Levels? 1 = Android 1.0 2 = Android 1.1 3 = Android 1.5 4 = Android 1.6 5 = Android 2.0 6 = Android 2.0.1 7 = Android 2.1.x 8 = Android 2.2.x ...

Criando o emulador...
- Window '-- AVD Manager '-- New...

Criando o emulador...
- Window '-- AVD Manager '-- New...

Criando o emulador...
- Window '-- AVD Manager '-- New...

Criando o emulador...
- Window '-- AVD Manager '-- New...

Criando o emulador...
- Window '-- AVD Manager '-- New...

Criando o emulador...
- Window '-- AVD Manager '-- New...

Criando o emulador...
- Window '-- AVD Manager '-- New...

Criando o emulador...
- Window '-- AVD Manager Dica: '-- New...

Nunca feche o emulador

Criando o emulador...
- Window '-- AVD Manager Dica: '-- New...

NUNCA Nunca feche o emulador

Vai desenvolver uma app?

Vai desenvolver uma app?

JAVA

Vai desenvolver uma app?

<XML>
JAVA

Criando nosso projeto...

Criando nosso projeto...

Criando nosso projeto...

Criando nosso projeto...

Criando nosso projeto...

Criando nosso projeto...

Criando nosso projeto...

Entendendo o que foi gerado

Entendendo o que foi gerado

Entendendo o que foi gerado

Entendendo o que foi gerado

Entendendo o que foi gerado

Entendendo o que foi gerado

Entendendo o que foi gerado

Entendendo o que foi gerado

Entendendo o que foi gerado

Densidades de tela

Aprox. 1mm Fonte: http://ignorethecode.net/blog/2012/03/16/ipad_screen_microscope/

Entendendo o que foi gerado

Resource qualifiers

Entendendo o que foi gerado

Entendendo o que foi gerado

Strings, dimenses, cores, valores numricos, ...

Entendendo o que foi gerado


Internacionalizao: values-en-rUS values-pt-rBR

Strings, dimenses, cores, valores numricos, ...

strings.xml

Entendendo o que foi gerado

AndroidManifest.xml

AndroidManifest.xml

AndroidManifest.xml

AndroidManifest.xml

AndroidManifest.xml

AndroidManifest.xml

AndroidManifest.xml

Tela

=
Tela

=
Tela

Activity (Java)

=
Tela

Activity (Java)

=
Tela

Activity (Java)

+ layout (xml)

Layout XML

Layout XML
LinearLayout (vertical)

Layout XML
LinearLayout (vertical)

Layout XML
LinearLayout (vertical)

Layout XML
LinearLayout (vertical)

Layout XML
LinearLayout (vertical)

Layout XML
LinearLayout (horizontal)

Layout XML
LinearLayout (horizontal)

Layout XML
LinearLayout (horizontal)

Layout XML
LinearLayout (horizontal)

Layout XML
LinearLayout (horizontal)

Layout XML
RelativeLayout

Layout XML
RelativeLayout

Layout XML
RelativeLayout

Layout XML
RelativeLayout

Views

Views

<RadioButton>

Views

<RadioButton>

<DatePicker>

Views

<RadioButton>

<RatingBar>

<DatePicker>

Views
<TextView> Texto <RadioButton> <RatingBar>

<DatePicker>

Views
<TextView> Texto <RadioButton> <RatingBar>

<Button>

<DatePicker>

Views
<TextView> Texto <RadioButton> <RatingBar>

<EditText> <Button> <DatePicker>

Views
<TextView> Texto <RadioButton> <CheckBox>

<RatingBar>

<EditText> <Button> <DatePicker>

Views
<TextView> Texto <RadioButton> <CheckBox>

<RatingBar>

Etc...
<EditText> <Button> <DatePicker>

Activity

Activity

Activity

Activity

onCreate() onStart() onResume()

Rodando...
onPause() onStop() onDestroy()

Activity

Activity

Activity
Activity

onCreate() onStart() onResume()

XML

Referncia para uma View Activity

Layout XML
<Button android:layout_width="..." android:layout_height="..." android:layout_id="@+id/botao" />

Referncia para uma View Activity

Layout XML
<Button android:layout_width="..." android:layout_height="..." android:layout_id="@+id/botao" />

findViewById(?)

Diretrio res

Diretrio res

Referncia para uma View Activity Layout XML

Button

findViewById(R.id.botao)

<Button ... />

Clicando no boto

Abrindo outra tela...

Abrindo outra tela...


Tela => Activity

Abrindo outra tela...


Tela => Activity Activity a = new MinhaActivity(); a.onCreate(null);

Abrindo outra tela...


Tela => Activity Activity a = new MinhaActivity(); a.onCreate(null);

Abrindo outra tela...


Tela => Activity Activity a = new MinhaActivity(); a.onCreate(null);

Abrindo outra tela...


Tela => Activity Activity a = new MinhaActivity(); a.onCreate(null);

Intent i = new Intent(context, OutraTela.class);

Abrindo outra tela...


Tela => Activity Activity a = new MinhaActivity(); a.onCreate(null);

Intent i = new Intent(context, OutraTela.class); startActivity(i);

Abrindo outra tela...

Abrindo outra tela...

Abrindo outra tela...

Chamando outras apps


Ligao, SMS, sites...

Chamando outras apps


Ligao, SMS, sites...

Chamando outras apps


O que eu quero fazer?

Chamando outras apps


O que eu quero fazer? Ligar!

Chamando outras apps


O que eu quero fazer? Ligar! Intent i = new Intent(Intent.ACTION_CALL);

Chamando outras apps


O que eu quero fazer? Ligar! Intent i = new Intent(Intent.ACTION_CALL); Para quem?

Chamando outras apps


O que eu quero fazer? Ligar! Intent i = new Intent(Intent.ACTION_CALL); Para quem? i.setData(Uri.parse("tel:12345678"));

Chamando outras apps


O que eu quero fazer? Ligar! Intent i = new Intent(Intent.ACTION_CALL); Para quem? i.setData(Uri.parse("tel:12345678")); Chamar a Activity:

Chamando outras apps


O que eu quero fazer? Ligar! Intent i = new Intent(Intent.ACTION_CALL); Para quem? i.setData(Uri.parse("tel:12345678")); Chamar a Activity: startActivity(i);

Chamando outras apps


O que eu quero fazer?

Chamando outras apps


O que eu quero fazer? Site!

Chamando outras apps


O que eu quero fazer? Site! Intent i = new Intent(Intent.ACTION_VIEW);

Chamando outras apps


O que eu quero fazer? Site! Intent i = new Intent(Intent.ACTION_VIEW); Qual?

Chamando outras apps


O que eu quero fazer? Site! Intent i = new Intent(Intent.ACTION_VIEW); Qual? i.setData(Uri.parse("http://www.ime.usp.br"));

Chamando outras apps


O que eu quero fazer? Site! Intent i = new Intent(Intent.ACTION_VIEW); Qual? i.setData(Uri.parse("http://www.ime.usp.br")); Chamar a Activity:

Chamando outras apps


O que eu quero fazer? Site! Intent i = new Intent(Intent.ACTION_VIEW); Qual? i.setData(Uri.parse("http://www.ime.usp.br")); Chamar a Activity: startActivity(i);

Chamando outras apps


O que eu quero fazer?

Chamando outras apps


O que eu quero fazer? SMS!

Chamando outras apps


O que eu quero fazer? SMS! Intent i = new Intent(Intent.ACTION_VIEW);

Chamando outras apps


O que eu quero fazer? SMS! Intent i = new Intent(Intent.ACTION_VIEW); Para quem?

Chamando outras apps


O que eu quero fazer? SMS! Intent i = new Intent(Intent.ACTION_VIEW); Para quem? i.setData(Uri.parse("sms:12345678"));

Chamando outras apps


O que eu quero fazer? SMS! Intent i = new Intent(Intent.ACTION_VIEW); Para quem? i.setData(Uri.parse("sms:12345678")); O que?

Chamando outras apps


O que eu quero fazer? SMS! Intent i = new Intent(Intent.ACTION_VIEW); Para quem? i.setData(Uri.parse("sms:12345678")); O que? i.putExtra("sms_body", "Mensagem do SMS")

Chamando outras apps


O que eu quero fazer? SMS! Intent i = new Intent(Intent.ACTION_VIEW); Para quem? i.setData(Uri.parse("sms:12345678")); O que? i.putExtra("sms_body", "Mensagem do SMS") Chamar a Activity:

Chamando outras apps


O que eu quero fazer? SMS! Intent i = new Intent(Intent.ACTION_VIEW); Para quem? i.setData(Uri.parse("sms:12345678")); O que? i.putExtra("sms_body", "Mensagem do SMS") Chamar a Activity: startActivity(i);

Permisses...

Permisses...

Acessando a internet...

Acessando a internet...

Acessando a internet...

Acessando a internet...
HttpClient c = new DefaultHttpClient();

Acessando a internet...
HttpClient c = new DefaultHttpClient(); HttpGet get = new HttpGet("http://www.ime.usp.br");

Acessando a internet...
HttpClient c = new DefaultHttpClient(); HttpGet get = new HttpGet("http://www.ime.usp.br"); HttpResponse response = c.execute(get);

Acessando a internet...
HttpClient c = new DefaultHttpClient(); HttpGet get = new HttpGet("http://www.ime.usp.br"); HttpResponse response = c.execute(get); String conteudo = EntityUtils.toString(response.getEntity());

Acessando a internet...
HttpClient c = new DefaultHttpClient(); HttpGet get = new HttpGet("http://www.ime.usp.br"); HttpResponse response = c.execute(get); t String conteudo = e n r e t EntityUtils.toString(response.getEntity()); In

m r e

s is

e d o

Fragments

Fragments

Fragments

Fragments

Fragments

Colocando Fragments na tela...


Layout XML

Colocando Fragments na tela...


Layout XML

Activity

Colocando Fragments na tela...


Layout XML

Activity

p a

o d r i art

n o H ( 0 3.

m o eyC

! ! ! ) b

Colocando Fragments na tela...


Layout XML

Activity

n o H ( Compatibility 0 . Library 3 o d r i t r a p a

m o eyC

! ! ! ) b

ActionBar

ActionBar

ActionBar

ActionBar

ActionBar

ActionBar
res/menu/main_menu.xml

ActionBar

ActionBar

ActionBar

d r i t r pa

0 . 3 o

Links teis
http://developer.android.com/index.html http://developer.android.com/design/index.html http://actionbarsherlock.com/ http://pivotal.github.com/robolectric/ http://blog.stylingandroid.com/ http://code.google.com/p/google-gson/

Вам также может понравиться