© copyright ntt data italia – all rights reserved the information contained in this document is...

12
© Copyright NTT DATA Italia – All Rights Reserved The information contained in this document is the property of NTT DATA Italia S.p.A. and the addressee of the document. The information is closely linked to the oral comments accompanying the same, and may be used only by those attending the presentation. Copying, publishing or divulging the material contained in this document is forbidden and may be illegal. ITIS A. Monaco Cosenza, 25 Marzo 2014 Struttura di un progetto ed elementi principali di una App

Upload: orlanda-nardi

Post on 02-May-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: © Copyright NTT DATA Italia – All Rights Reserved The information contained in this document is the property of NTT DATA Italia S.p.A. and the addressee

© Copyright NTT DATA Italia – All Rights Reserved

The information contained in this document is the property of NTT DATA Italia S.p.A. and the addressee of the document. The information is closely linked to the oral comments accompanying the same, and may be used only by those attending the presentation. Copying, publishing or divulging the material contained in this document is forbidden and may be illegal.

ITIS A. Monaco

Cosenza, 25 Marzo 2014

Struttura di un progetto ed elementi principali di una App

Page 2: © Copyright NTT DATA Italia – All Rights Reserved The information contained in this document is the property of NTT DATA Italia S.p.A. and the addressee

© Copyright NTT DATA Italia – All Rights Reserved 2

M052 - 04

► Cartelle

► Gestione delle risorse

► Manifest dell’applicazione

► Elementi principali

Sommario

Page 3: © Copyright NTT DATA Italia – All Rights Reserved The information contained in this document is the property of NTT DATA Italia S.p.A. and the addressee

© Copyright NTT DATA Italia – All Rights Reserved 3

M052 - 04

Primo mesePrimo mese

Cartelle di un progetto Android

/src: sorgenti Java

/bin: compilati (.apk, ecc…)

/libs: librerie esterne

/res: risorse managed (processati)

/gen: sorgenti generati (R.java)

/assets: risorse unmanaged (nel .apk)

/AndroidManifest.xml: metadati

.properties, .cfg, .xml: altri files

http://developer.android.com/tools/projects/index.html#ApplicationProjects

Page 4: © Copyright NTT DATA Italia – All Rights Reserved The information contained in this document is the property of NTT DATA Italia S.p.A. and the addressee

© Copyright NTT DATA Italia – All Rights Reserved 4

M052 - 04

Primo mesePrimo mese Secondo meseSecondo mese …………………………

Gestione delle risorse: struttura a cartelle

E’ buona prassi mantenere le risorse usate da una applicazione (immagini, stringhe, ecc) slegate dal codice:

•Supportare diverse lingue•Supportare diversi screen size dei dispositivi.

Per questi scopi, in Android si organizzano le risorse all’interno della cartella res/, usando varie sotto cartelle per raggruppare le risorse per tipo e configurazione.

http://developer.android.com/guide/topics/resources/overview.html

Page 5: © Copyright NTT DATA Italia – All Rights Reserved The information contained in this document is the property of NTT DATA Italia S.p.A. and the addressee

© Copyright NTT DATA Italia – All Rights Reserved 5

M052 - 04

Primo mesePrimo mese Secondo meseSecondo mese …………………………

Gestione delle risorse: accesso

In fase di compilazione, l’Android Asset Packaging Tool (AAPT), genera la classe R.java.

•R.java contiene un’identificativo (ID) per ogni risorsa nella cartella res/. •Per ogni tipo di risorsa, viene creata una sottoclasse di R.•Per ogni risorsa di un dato tipo, viene creato un valore static integer

Questo intero è il resource ID che useremo nel codice per utilizzare la relativa risorsa.

Esempi:

•R.drawable.mia_icona•R.string.testo_benvenuto

http://developer.android.com/guide/topics/resources/accessing-resources.html

Page 6: © Copyright NTT DATA Italia – All Rights Reserved The information contained in this document is the property of NTT DATA Italia S.p.A. and the addressee

© Copyright NTT DATA Italia – All Rights Reserved 6

M052 - 04

Primo mesePrimo mese Secondo meseSecondo mese …………………………

Manifest dell’applicazione

File AndroidManifest.xml nella root.Presenta al sistema Android le informazioni essenziali riguardanti l’app, informazioni che il sistema deve avere prima di poter eseguire qualsiasi parte di codice.

Descrive:•l’applicazione, •il nome del package, •il namespace, •i permessi richiesti dall’app.

Dichiara che livello di API è richiesto.

Include la specifica di ogni componente: Activity, Service, Receiver, etc.

http://developer.android.com/guide/topics/manifest/manifest-intro.html

Page 7: © Copyright NTT DATA Italia – All Rights Reserved The information contained in this document is the property of NTT DATA Italia S.p.A. and the addressee

© Copyright NTT DATA Italia – All Rights Reserved 7

M052 - 04

Primo mesePrimo mese Secondo meseSecondo mese …………………………

Elementi principali di una App

Android fornisce quattro mattoni di base:

•Activity

•Service

•Broadcast Receiver

•Content Provider

Un’applicazione Android è costituita da uno o più di questi elementi. Molto frequentemente, contiene almeno un’attività.

Page 8: © Copyright NTT DATA Italia – All Rights Reserved The information contained in this document is the property of NTT DATA Italia S.p.A. and the addressee

© Copyright NTT DATA Italia – All Rights Reserved 8

M052 - 04

Primo mesePrimo mese Secondo meseSecondo mese …………………………

Elementi principali di una App: Activity

Le attività sono quei blocchi di un’applicazione che interagiscono con l’utente utilizzando lo schermo ed i dispositivi di input messi a disposizione dallo smartphone.

Comunemente fanno uso di componenti UI già pronti, come quelli presenti nel pacchettoandroid.widget, ma questa non è necessariamente la regola.

Le attività sono probabilmente il modello più diffuso in Android, e si realizzano estendendo la classe base android.app.Activity

Page 9: © Copyright NTT DATA Italia – All Rights Reserved The information contained in this document is the property of NTT DATA Italia S.p.A. and the addressee

© Copyright NTT DATA Italia – All Rights Reserved 9

M052 - 04

Primo mesePrimo mese Secondo meseSecondo mese …………………………

Elementi principali di una App: Service

Un servizio gira in sottofondo e non interagisce direttamente con l’utente.

Ad esempio può riprodurre un brano MP3, mentre l’utente utilizza delle attività per fare altro.

Un servizio si realizza estendendo la classe android.app.Service

Page 10: © Copyright NTT DATA Italia – All Rights Reserved The information contained in this document is the property of NTT DATA Italia S.p.A. and the addressee

© Copyright NTT DATA Italia – All Rights Reserved 10

M052 - 04

Primo mesePrimo mese Secondo meseSecondo mese …………………………

Elementi principali di una App: Broadcast Receiver

Un Broadcast Receiver è un sistema per la comunicazione tra applicazioni.

Viene utilizzato quando si intende intercettare un particolare evento, attraverso tutto il sistema.

Ad esempio lo si può utilizzare se si desidera compiere un’azione quando si scatta una foto o quando parte la segnalazione di batteria scarica.

La classe da estendere è android.content.BroadcastReceiver

Page 11: © Copyright NTT DATA Italia – All Rights Reserved The information contained in this document is the property of NTT DATA Italia S.p.A. and the addressee

© Copyright NTT DATA Italia – All Rights Reserved 11

M052 - 04

Primo mesePrimo mese Secondo meseSecondo mese …………………………

Elementi principali di una App: Content Provider

I Content Provider sono utilizzati per esporre dati ed informazioni.

Costituiscono un canale di comunicazione tra le differenti applicazioni installate nel sistema.

Si può creare un Content Provider estendendo la classe astratta android.content.ContentProvider

Android ne mette a disposizione molti già pronti:

•Lista dei contatti•Lista delle immagini sul dispositivo•Dati che risiedono in un DB SQLite•Dati che risiedono su un web service

Page 12: © Copyright NTT DATA Italia – All Rights Reserved The information contained in this document is the property of NTT DATA Italia S.p.A. and the addressee

12© Copyright NTT DATA Italia – All Rights Reserved

M052 - 04

[email protected]