atps - programação em dispositivos móveis [unidade 2]

39
ANHANGUERA EDUCACIONAL UNIAN UNIVERSIDADE ANHANGUERA PAULISTA SISTEMAS DE INFORMAÇÃO BRUNO PEREIRA RA 6814001065 DANIEL MASTRODOMENICO RA 6814015174 EDUARDO XAVIER RA 6856494918 FRANCISCO HUGORA 6444296266 HELBER SCHIMITH RA 6268235461 ATIVIDADES PRÁTICAS SUPERVISIONADAS Programação em Dispositivos Móveis SANTO ANDRÉ 2015

Upload: eric-graves-camollez

Post on 14-Dec-2015

15 views

Category:

Documents


0 download

DESCRIPTION

ATPS - Programação Em Dispositivos Móveis [Unidade 2]

TRANSCRIPT

Page 1: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

ANHANGUERA EDUCACIONAL

UNIAN – UNIVERSIDADE ANHANGUERA PAULISTA

SISTEMAS DE INFORMAÇÃO

BRUNO PEREIRA – RA 6814001065

DANIEL MASTRODOMENICO – RA 6814015174

EDUARDO XAVIER – RA 6856494918

FRANCISCO HUGO– RA 6444296266

HELBER SCHIMITH – RA 6268235461

ATIVIDADES PRÁTICAS SUPERVISIONADAS

Programação em Dispositivos Móveis

SANTO ANDRÉ

2015

Page 2: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

2

BRUNO NEVES – RA 6814001065

DANIEL MASTRODOMENICO – RA 6814015174

EDUARDO XAVIER – RA 6856494918

FRANCISCO HUGO– RA 6444296266

HELBER SCHIMITH – RA 6268235461

ATIVIDADES PRÁTICAS SUPERVISIONADAS

Programação em Dispositivos Móveis

ATIVIDADE PRÁTICA SUPERVISIONADA DA

MATÉRIA PROGRAMAÇÃO EM DISPOSITIVOS

MÓVEIS DESTINADA À UNIAN – UNIVERSIDADE

ANHANGUERA PAULISTA - ANHANGUERA

EDUCACIONAL SOB A ORIENTAÇÃO DO

PROFESSOR CLAUDIO BURANELLO.

SANTO ANDRÉ

2015

Page 3: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

3

RESUMO

Será apresentado a seguir como desafio da Atividade Prática Supervisionada – ATPS,

uma série de exemplos teóricos e práticos sobre a programação em dispositivos mobile com

sistema operacional android. O conteúdo aqui descrito representa as etapas um e dois da atps

“Programação em Dispositivos Móveis”, feita por Tiago Teixeira Medeiros da Faculdade de

Negócios e Tecnologia.

Muito comum em nosso dia a dia, os dispositivos moveis simplesmente tornaram-se

elementos indispensáveis em muitas situações rotineiras como na comunicação, auxilio em

tarefas, lembretes, informação, divulgação, interatividade, entre muitos ouros aspectos.

Estas duas etapas da atps que estão presentes neste trabalho são importantes para que

conheçamos características e recursos do desenvolvimento para o android e adquir assim, o

conhecimento de criação de interfaces gráficas, manipulação de elementos e navegação nas

Activitys.

Page 4: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

4

SUMÁRIO

Resumo.................................................................................................................................... 03

ETAPA 1..................................................................................................................................05

Passo 3 - Relatório 1.3 .............................................................................................05

ETAPA 2 .................................................................................................................................16

Passo 3 - Relatório 2.3 .............................................................................................16

ETAPA 3 .................................................................................................................................22

Passo 3 - Relatório 3.3 .............................................................................................22

ETAPA 4 .................................................................................................................................38

Passo 3 - Relatório 4.3 .............................................................................................38

Conclusão.................................................................................................................................39

Bibliografia..............................................................................................................................39

Page 5: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

5

ETAPA 1______________________________________________

Passo 3 - Relatório 1.3 – Entregar um relatório contendo todo código fonte gerado no Passo 2.

Implementar a classe Desejo conforme diagrama abaixo:

public class Desejo {

private int _id;

private String poduto;

private String categoria;

private String lojas;

private double precoMinimo;

private double precoMaximo;

public int getId() {

return _id;

}

public void setId(int _id) {

this._id = _id;

}

public String getPoduto() {

return poduto;

}

public void setPoduto(String

poduto){

this.poduto = poduto;

}

public String getCategoria() {

return categoria;

}

public void setCategoria(String

categoria) {

this.categoria = categoria;

}

public String getLojas() {

return lojas;

}

public void setLojas(String lojas) {

this.lojas = lojas;

}

public double getPrecoMinimo() {

return precoMinimo;

}

public void setPrecoMinimo(double

precoMinimo) {

this.precoMinimo =

precoMinimo;

}

public double getPrecoMaximo() {

return precoMaximo;

}

public void setPrecoMaximo(double

precoMaximo) {

this.precoMaximo =

precoMaximo;

}

}

Page 6: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

6

Criar as Activities (apenas a Interface Gráfica) abaixo:

Listar Desejos (Activity Principal)

Inserir Desejo

Detalhes do Desejo

Alterar Desejo

Uma activity é o componente responsável por mostrar uma tela ao usuário.

Activity Listar Desejos (Activity Principal):

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingLeft="16dp"

android:paddingRight="16dp"

android:orientation="vertical" >

<Button

android:id= " @ + id / button_criarP "

android:layout_width= " match_parent "

android:layout_height= " wrap_content "

android:text= " @string / criar_p " />

<TextView

android:layout_width= " match_parent "

android:layout_height= " wrap_content "

android:text= "@string/nome_produto" />

<TextView

android:layout_width= " match_parent "

android:layout_height= " wrap_content "

android:text= "@string/categoria" />

Page 7: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

7

<Button

android:id= " @ + id / button_detalharP "

android:layout_width= " match_parent "

android:layout_height= " wrap_content "

android:text= " @string / detalhar_p " />

</LinearLayout>

Page 8: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

8

Activity Inserir Desejo:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingLeft="16dp"

android:paddingRight="16dp"

android:orientation="vertical" >

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="@string/nome_produto" />

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="@string/categoria" />

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="@string/preco_minimo" />

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="@string/preco_maximo" />

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="@string/lojas" />

Page 9: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

9

<Button

android:layout_width="100dp"

android:layout_height="wrap_content"

android:layout_gravity="right"

android:text="@string/salvar" />

</LinearLayout>

Page 10: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

10

Activity Detalhar Desejo:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingLeft="16dp"

android:paddingRight="16dp"

android:orientation="vertical" >

<Button

android:id= " @ + id / button_alterarP "

android:layout_width= " match_parent "

android:layout_height= " wrap_content "

android:text= " @string / alterar_p " />

<TextView

android:layout_width= " match_parent "

android:layout_height= " wrap_content "

android:text= "@string/nome_produto" />

<TextView

android:id= " @ + id / show_nome "

android:layout_width= " match_parent "

android:layout_height= " wrap_content "

android:text= " @string / show_nome "

android:visibility= " invisible " />

<TextView

android:layout_width= " match_parent "

android:layout_height= " wrap_content "

android:text= "@string/categoria" />

<TextView

Page 11: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

11

android:id= " @ + id / show_categoria "

android:layout_width= " match_parent "

android:layout_height= " wrap_content "

android:text= " @string / show_categoria "

android:visibility= " invisible " />

<TextView

android:layout_width= " match_parent "

android:layout_height= " wrap_content "

android:text= "@string/preco_minimo" />

<TextView

android:id= " @ + id / show_preco_minimo "

android:layout_width= " match_parent "

android:layout_height= " wrap_content "

android:text= " @string / show_preco_minimo "

android:visibility= " invisible " />

<TextView

android:layout_width= " match_parent "

android:layout_height= " wrap_content "

android:text= "@string/preco_maximo" />

<TextView

android:id= " @ + id / show_preco_maximo "

android:layout_width= " match_parent "

android:layout_height= " wrap_content "

android:text= " @string / show_preco_maximo "

android:visibility= " invisible " />

<TextView

android:layout_width= " match_parent "

android:layout_height= " wrap_content "

android:text= "@string/lojas" />

Page 12: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

12

<TextView

android:id= " @ + id / show_lojas "

android:layout_width= " match_parent "

android:layout_height= " wrap_content "

android:text= " @string / show_lojas "

android:visibility= " invisible " />

</LinearLayout>

Page 13: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

13

Activity Alterar Desejo:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingLeft="16dp"

android:paddingRight="16dp"

android:orientation="vertical" >

<TextView

android:layout_width= " match_parent "

android:layout_height= " wrap_content "

android:text= "@string/nome_produto" />

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"/>

<TextView

android:layout_width= " match_parent "

android:layout_height= " wrap_content "

android:text= "@string/categoria" />

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"/>

<TextView

android:layout_width= " match_parent "

android:layout_height= " wrap_content "

android:text= "@string/preco_minimo" />

<EditText

android:layout_width="match_parent"

Page 14: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

14

android:layout_height="wrap_content"/>

<TextView

android:layout_width= " match_parent "

android:layout_height= " wrap_content "

android:text= "@string/preco_maximo" />

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"/>

<TextView

android:layout_width= " match_parent "

android:layout_height= " wrap_content "

android:text= "@string/lojas" />

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"/>

<Button

android:layout_width="100dp"

android:layout_height="wrap_content"

android:layout_gravity="right"

android:text="@string/salvar" />

</LinearLayout>

Page 15: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

15

Resources

<? xml version = " 1.0 " encoding= " utf -8 " ?>

<resources>

<string name= " app_name " >Lista de Desejos</string>

<string name= " name_produto " > Nome do Produto </string>

<string name= " categoria " > Categoria </string>

<string name= " preco_minimo " > Preço Mínimo </string>

<string name= " preco_maximo " > Preço Máximo </string>

<string name= " lojas " > Lojas </string>

<string name= " salvar " >Salvar</string>

<string name= " criar_p " > Ciar Desejo </string>

<string name= " alterar_p " > Alterar Desejo </string>

<string name= " detalhar_p " > Detalhar Desejo </string>

</resources>

Page 16: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

16

ETAPA 2______________________________________________

Passo 3 – Relatório 2.3– Conteúdo do código fonte gerado no Passo 2.

Usar Intents para programar a navegação entre as Activities criadas na etapa anterior:

Listar Desejos (Activity Principal)

Inserir Desejo

Detalhes do Desejo

Alterar Desejo

Intents Listar Desejos (Activity Principal)

package br.com.Lista.de.Desejos;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

public class ListarDesejoMainActivity1 extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Button button = (Button) findViewById(R.id.button_criarP);

button.setOnClickListener( new OnClickListener() {

Page 17: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

17

public void onClick(View v) {

Intent intent = new Intent(ListarDesejoMainActivity1.this ,

InseriDesejoActivity2.class);

startActivity(intent);

}

Button button = (Button) findViewById(R.id.button_detalharP);

button.setOnClickListener( new OnClickListener() {

public void onClick(View v) {

Intent intent = new Intent(ListarDesejoMainActivity1.this ,

DetalharDesejoActivity2.class);

startActivity(intent);

}

});

}

}

Page 18: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

18

Intents Inserir Desejos

package br.com.Lista.de.Desejos;

import android.app.Activity;

import android.os.Bundle;

import android.widget.EditText;

public class InseriDesejoActivity2 extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super .onCreate(savedInstanceState);

setContentView(R.layout.second);

}

}

Page 19: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

19

Intents Detalhar Desejos

package br.com.Lista.de.Desejos;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

public class DetalharDesejoActivity1 extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Button button = (Button) findViewById(R.id.button_alterarP);

button.setOnClickListener( new OnClickListener() {

public void onClick(View v) {

Intent intent = new Intent(DetalharDesejoActivity1.this ,

AlterarDesejoActivity2.class);

startActivity(intent);

}

});

}

}

Page 20: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

20

package br.com.Lista.de.Desejos;

import android.app.Activity;

import android.os.Bundle;

import android.widget.EditText;

public class DetalharDesejoActivity2 extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super .onCreate(savedInstanceState);

setContentView(R.layout.second);

}

}

Page 21: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

21

Intents Alterar Desejos

package br.com.Lista.de.Desejos;

import android.app.Activity;

import android.os.Bundle;

import android.widget.EditText;

public class AlterarDesejoActivity2 extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super .onCreate(savedInstanceState);

setContentView(R.layout.second);

}

}

Page 22: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

22

ETAPA 3______________________________________________

Passo 3 – Relatório 3.3– Conteúdo do código fonte gerado no Passo 2.

ListarDesejos – Deve ser capaz de consultar todos os desejos cadastrados no banco

de dados e exibir na Activity através de um ListView (ou similar).

AdicionarDesejo – Deve ser capaz de incluir um desejo no banco de dados.

DetalharDesejo – Deve ser capaz de exibir os detalhes do Desejo. A partir dessa

Activity, deve ser possível ir para a Activity Alterar Desejo e acionar a funcionalidade

Excluir Desejo.

AlterarDesejo – Deve ser capaz de alterar os dados de um Desejo previamente

cadastrado no banco de dados.

Programar a funcionalidade Excluir Desejo – Deve ser capaz de excluir um desejo

previamente cadastrado no banco de dados.

ListarDesejo.java

package br.com.Lista.de.Desejos;

import android.content.Context;

import android.content.Intent;

import android.os.Bundle;

import android.view.KeyEvent;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.widget.AdapterView;

import android.widget.ArrayAdapter;

import android.widget.AdapterView.OnItemClickListener;

import android.widget.ListView;

import java.util.ArrayList;

import java.util.List;

Page 23: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

23

public class ListarDesejo extends {

private ListView obj;

OperadorBancoDados mydb;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.LinearLayout.ListarDesejo);

mydb = new OperadorBancoDados(this);

ArrayList array_list = mydb.getAllCotacts();

ArrayAdapter arrayAdapter=new

ArrayAdapter(this,android.R.layout.simple_list_item_1, array_list);

obj = (ListView)findViewById(R.id.listView1);

obj.setAdapter(arrayAdapter);

obj.setOnItemClickListener(new OnItemClickListener(){

@Override

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {

int id_To_Search = arg2 + 1;

Bundle dataBundle = new Bundle();

dataBundle.putInt("id", id_To_Search);

Intent intent = new

Intent(getApplicationContext(),br.com.Lista.de.Desejos.class);

Page 24: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

24

intent.putExtras(dataBundle);

startActivity(intent);

}

});

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

getMenuInflater().inflate(R.menu.menu_main, menu);

return true;

}

@Override

public boolean onOptionsItemSelected(MenuItem item){

super.onOptionsItemSelected(item);

switch(item.getItemId())

{

case R.id.item1:Bundle dataBundle = new Bundle();

dataBundle.putInt("id", 0);

Intent intent = new

Intent(getApplicationContext(),br.com.Lista.de.Desejos.class);

intent.putExtras(dataBundle);

startActivity(intent);

Page 25: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

25

return true;

default:

return super.onOptionsItemSelected(item);

}

}

public boolean onKeyDown(int keycode, KeyEvent event) {

if (keycode == KeyEvent.KEYCODE_BACK) {

moveTaskToBack(true);

}

return super.onKeyDown(keycode, event);

}

}

Page 26: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

26

DetalharDesejo.java

package br.com.Lista.de.Desejos;

import android.os.Bundle;

import android.app.Activity;

import android.app.AlertDialog;

import android.content.DialogInterface;

import android.content.Intent;

import android.database.Cursor;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.widget.Button;

import android.widget.TextView;

import android.widget.Toast;

public class DetalharDesejo extends Activity {

int from_Where_I_Am_Coming = 0;

private OperadorBancoDados mydb ;

TextView show_nome ;

TextView show_categoria;

TextView show_preco_minimo;

TextView show_preco_maximo;

TextView show_lojas;

int id_To_Update = 0;

Page 27: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

27

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.LinearLayout.ListarDesejo);

show_nome = (TextView) findViewById(R.id.editTextshow_nome);

show_categoria = (TextView) findViewById(R.id.editTextshow_categoria);

show_preco_minimo = (TextView)

findViewById(R.id.editTextshow_preco_maximo);

show_preco_maximo = (TextView)

findViewById(R.id.editTextshow_preco_minimo);

show_lojas = (TextView) findViewById(R.id.editTextshow_lojas);

mydb = new OperadorBancoDados(this);

Bundle extras = getIntent().getExtras();

if(extras !=null)

{

int Value = extras.getInt("id");

if(Value>0){

Cursor rs = mydb.getData(Value);

id_To_Update = Value;

rs.moveToFirst();

String show_nom =

rs.getString(rs.getColumnIndex(OperadorBancoDados.DESEJOS_COLUMN_show_nome));

Page 28: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

28

String show_categori =

rs.getString(rs.getColumnIndex(OperadorBancoDados.DESEJOS_COLUMN_show_categori

a));

String show_preco_minim =

rs.getString(rs.getColumnIndex(OperadorBancoDados.DESEJOS_COLUMN_show_preco_m

inimo));

String show_preco_maxim =

rs.getString(rs.getColumnIndex(OperadorBancoDados.DESEJOS_COLUMN_show_preco_m

aximo));

String show_loja =

rs.getString(rs.getColumnIndex(OperadorBancoDados.DESEJOSS_COLUMN_show_lojas));

if (!rs.isClosed())

{

rs.close();

}

Button b = (Button)findViewById(R.id.button1);

b.setVisibility(View.INVISIBLE);

show_nome.setText((CharSequence)show_nom);

show_nome.setFocusable(false);

show_nome.setClickable(false);

show_categoria.setText((CharSequence)show_categori);

show_categoria.setFocusable(false);

show_categoria.setClickable(false);

show_preco_minimo.setText((CharSequence)show_preco_minim);

show_preco_minimo.setFocusable(false);

show_preco_minimo.setClickable(false);

Page 29: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

29

show_preco_maximo.setText((CharSequence)show_preco_maxim);

show_preco_maximo.setFocusable(false);

show_preco_maximo.setClickable(false);

show_lojas.setText((CharSequence)show_loja);

show_lojas.setFocusable(false);

show_lojas.setClickable(false);

}

}

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

Bundle extras = getIntent().getExtras();

if(extras !=null)

{

int Value = extras.getInt("id");

if(Value>0){

getMenuInflater().inflate(R.menu.DetalharDesejo, menu);

}

else{

getMenuInflater().inflate(R.menu.ListarDesejo, menu);

}

Page 30: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

30

}

return true;

}

public boolean onOptionsItemSelected(MenuItem item)

{

super.onOptionsItemSelected(item);

switch(item.getItemId())

{

case R.id.AlterarDesejo:

Button b = (Button)findViewById(R.id.button1);

b.setVisibility(View.VISIBLE);

show_nome.setEnabled(true);

show_nome.setFocusableInTouchMode(true);

show_nome.setClickable(true);

show_categoria.setEnabled(true);

show_categoria.setFocusableInTouchMode(true);

show_categoria.setClickable(true);

show_preco_minimo.setEnabled(true);

show_preco_minimo.setFocusableInTouchMode(true);

show_preco_minimo.setClickable(true);

show_preco_maximo.setEnabled(true);

show_preco_maximo.setFocusableInTouchMode(true);

show_preco_maximo.setClickable(true);

Page 31: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

31

show_lojas.setEnabled(true);

show_lojas.setFocusableInTouchMode(true);

show_lojas.setClickable(true);

return true;

case R.id.Delete_Desejo:

AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setMessage(R.string.deleteDesejo)

.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int id) {

mydb.deleteDesejo(id_To_Update);

Toast.makeText(getApplicationContext(), "Deletado com Sucesso! ",

Toast.LENGTH_SHORT).show();

Intent intent = new

Intent(getApplicationContext(),com.example.addressbook.MainActivity.class);

startActivity(intent);

}

})

.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int id) {

}

});

AlertDialog d = builder.create();

d.setTitle("Are you sure");

d.show();

Page 32: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

32

return true;

default:

return super.onOptionsItemSelected(item);

}

}

public void run(View view)

{

Bundle extras = getIntent().getExtras();

if(extras !=null)

{

int Value = extras.getInt("id");

if(Value>0){

if(mydb.updateDesejo(id_To_Update,show_nome.getText().toString(),

show_categoria.getText().toString(), show_preco_minimo.getText().toString(),

show_preco_maximo.getText().toString(), show_lojas.getText().toString())){

Toast.makeText(getApplicationContext(), "Updated",

Toast.LENGTH_SHORT).show();

Intent intent = new

Intent(getApplicationContext(),com.example.addressbook.MainActivity.class);

startActivity(intent);

}

else{

Toast.makeText(getApplicationContext(), "not Updated",

Toast.LENGTH_SHORT).show();

}

}

Page 33: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

33

else{

if(mydb.insertDesejo(show_nome.getText().toString(),

show_categoria.getText().toString(), show_preco_minimo.getText().toString(),

show_preco_maximo.getText().toString(), show_lojas.getText().toString())){

Toast.makeText(getApplicationContext(), "done",

Toast.LENGTH_SHORT).show();

}

else{

Toast.makeText(getApplicationContext(), "not done",

Toast.LENGTH_SHORT).show();

}

Intent intent = new

Intent(getApplicationContext(),com.example.addressbook.MainActivity.class);

startActivity(intent);

}

}

}

}

Page 34: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

34

OperadorBancoDados.java

package com.example.addressbook;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.Hashtable;

import android.content.ContentValues;

import android.content.Context;

import android.database.Cursor;

import android.database.DatabaseUtils;

import android.database.sqlite.SQLiteOperadorBancoDados;

import android.database.sqlite.SQLiteDatabase;

public class OperadorBancoDados extends SQLiteOpenHelper {

public static final String DATABASE_NAME = "MyDBDesejos.db";

public static final String DESEJOS_TABLE_DESEJOS = "desejos";

public static final String DESEJOS_COLUMN_ID = "id";

public static final String DESEJOS_COLUMN_SHOW_NAME = "show_nome";

public static final String DESEJOS_COLUMN_SHOW_CATEGORIA =

"show_categoria";

public static final String DESEJOS_COLUMN_SHOW_PRECO_MINIMO =

"show_preco_minimo";

public static final String DESEJOS_COLUMN_SHOW_PRECO_MAXIMO =

"show_preco_maximo";

public static final String DESEJOS_COLUMN_SHOW_LOJAS = "show_lojas";

private HashMap hp;

Page 35: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

35

public OperadorBancoDados(Context context){

super(context, DATABASE_NAME , null, 1);

}

@Override

public void onCreate(SQLiteDatabase db) {

db.execSQL(

"create table desejos " +

"(id integer primary key, show_nome text,show_categoria

text,show_preco_minimo text, show_preco_maximo text,show_lojas text)"

);

}

@Override

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

db.execSQL("DROP TABLE IF EXISTS desejos");

onCreate(db);

}

public boolean insertDesejos (String show_nome, String show_categoria, String

show_preco_minimo, String show_preco_maximo,String show_lojas)

{ SQLiteDatabase db = this.getWritableDatabase();

ContentValues contentValues = new ContentValues();

contentValues.put("show_nome", show_nome);

contentValues.put("show_categoria", show_categoria);

contentValues.put("show_preco_minimo", show_preco_minimo);

contentValues.put("show_preco_maximo", show_preco_maximo);

contentValues.put("show_lojas", show_lojas);

db.insert("desejos", null, contentValues);

return true;

}

Page 36: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

36

public Cursor getData(int id){

SQLiteDatabase db = this.getReadableDatabase();

Cursor res = db.rawQuery( "select * from desejos where id="+id+"", null );

return res;

}

public int numberOfRows(){

SQLiteDatabase db = this.getReadableDatabase();

int numRows = (int) DatabaseUtils.queryNumEntries(db,

DESEJOS_TABLE_NAME);

return numRows;

}

public boolean updatedesejo (Integer id, String show_nome, String show_categoria,

String show_preco_minimo, String show_preco_maximo,String show_lojas)

{

SQLiteDatabase db = this.getWritableDatabase();

ContentValues contentValues = new ContentValues();

contentValues.put("show_nome", show_nome);

contentValues.put("show_categoria", show_categoria);

contentValues.put("show_preco_minimo", show_preco_minimo);

contentValues.put("show_preco_maximo", show_preco_maximo);

contentValues.put("show_lojas", show_lojas);

db.update("desejos", contentValues, "id = ? ", new String[] { Integer.toString(id) }

);

return true;

}

Page 37: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

37

public Integer deletedesejo (Integer id)

{

SQLiteDatabase db = this.getWritableDatabase();

return db.delete("desejos",

"id = ? ",

new String[] { Integer.toString(id) });

}

public ArrayList<String> getAllCotacts()

{

ArrayList<String> array_list = new ArrayList<String>();

//hp = new HashMap();

SQLiteDatabase db = this.getReadableDatabase();

Cursor res = db.rawQuery( "select * from desejos", null );

res.moveToFirst();

while(res.isAfterLast() == false){

array_list.add(res.getString(res.getColumnIndex(DESEJOS_COLUMN_NAME)));

res.moveToNext();

}

return array_list;

}

}

Page 38: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

38

ETAPA 4______________________________________________

Passo 3 – Relatório 4.3– Conteúdo do código fonte gerado no Passo 2.

<item

android:id="@+id/menu_item_share"

android:showAsAction="ifRoom"

android:title="Share"

android:actionProviderClass="android.widget.ShareActionProvider"

/>

------------------------------------------------------------------------

private ShareActionProvider mShareActionProvider;

@Override

public boolean onCreateOptionsMenu(Menu menu) {

getMenuInflater().inflate(R.menu.share_menu, menu);

MenuItem item = menu.findItem(R.id.menu_item_share);

mShareActionProvider = (ShareActionProvider) item.getActionProvider();

return true;

}

private void setShareIntent(Intent shareIntent) {

if (mShareActionProvider != null) {

mShareActionProvider.setShareIntent(shareIntent);

}

}

Page 39: ATPS - Programação Em Dispositivos Móveis [Unidade 2]

39

CONCLUSÃO

O conteúdo exposto é o resultado do desenvolvimento proposto na ATPS. Os

exemplos implementados foram feitos com a ajuda do conteúdo proposto pela atps e também

sites na internet. Conteúdo este, que foi fundamental para o desenvolvimento dos exemplos.

BIBLIOGRAFIA

Livro k19 k41. Desenvolvimento mobile com android.

LEE, Wei Meng. Introdução ao Desenvolvimento de Aplicativos para o Android. 1ª

ed. São Paulo: Ciência Moderna, 2011.

SANTOS, Rafael. Introdução à Programação Orientada a Objeto Utilizando Java. 1ª

ed. Rio de Janeiro: Campus - Elsevier, 2003, v.1.

DEITEL, P. J.; DEITEL, Harvery M.. C: Como Programar. 6ª ed. São Paulo: Pearson,

2011.

CADENHEAD, Rogers. Aprenda em 21 dias Java 2. 4ª ed. Rio de Janeiro: Elsevier,

2005.

RESENDE, Antônio Maria Pereira. Programação Orientada a Aspectos em Java:

Desenvolvimento de Software Orientado a Aspectos. 1ª ed. Rio de Janeiro: Brasport, 2005.

NIEMEYER, Patrick. Aprendendo Java 2 SDK: versão 1.3. 1ª ed. Rio de Janeiro:

Campus, 2000.

TUTORIAL – Android – Parte 3 – Construção de Telas por Renan Drabach

< http://www.mobiltec.com.br/blog/index.php/tutorial-android-parte-3-construcao-de-telas/ >

Acesso em: 04 Abril. 2015

Android Developers Training por Google

< http://developer.android.com/training/index.html >

Acesso em: 04 Abril. 2015

Android - SQLite Database Tutorial

< http://www.tutorialspoint.com/android/android_sqlite_database.htm >