• No results found

06 Team Project: Android Development Crash Course; Project Introduction

N/A
N/A
Protected

Academic year: 2021

Share "06 Team Project: Android Development Crash Course; Project Introduction"

Copied!
29
0
0

Loading.... (view fulltext now)

Full text

(1)

 

April 11, 2014

 

M. Kranz, P. Lindemann, A. Riener

340.301 UE “Principles of Interaction”, 2014S 06 Team Project: Android Development Crash Course; Project Introduction

 

Priv.-Doz. Dipl.-Ing. Dr. Andreas Riener Institute for Pervasive Computing Johannes Kepler University

(2)

Principles of Interaction // 2014S // Slide < 2 > M. Kranz / P. Lindemann / A. Riener

Schedule for Today

Team Project

§

Assignment 4 – Part 2 (user study execution)

§

in-class discussion

§

Android App Development

§

Crash course

§

Project Introduction and Launch

(3)

Principles of Interaction // 2014S // Slide < 3 > M. Kranz / P. Lindemann / A. Riener

Team Project >>

„Mensa Food Service“

Project phases

§

Individual assignments

§  Assignment 1: Literature review and analysis

§  Assignment 2: Ideation and brainstorming

§  Assignment 3: Development of mockups

§  Assignment 4: User study

§  Part 1: Survey/Questionnaire Design

§  Part 2: Execution

§

Team work

§  Scenario and UI design

§  Rapid prototyping (low-fidelity)

§  Implementation (Android app)

§  Evaluation with users (colleagues, classmates)

§

The project team should discuss with the instructors and receive input on each phase of the project

(4)
(5)

Android Developer System Setup

Install Android SDK

§

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

§

Contains SDK Tools and

emulator

§

In the SDK Manager, install

the proposed packages

§

To create a new emulated

device, go to

Tools > Manage AVDs

(not needed in the exercise)

(6)

Android Developer System Setup

Install Eclipse for Java Developers

§

http://www.eclipse.org/downloads/packages/eclipse-classic-42/junor

§

You can use an existing Eclipse installation, but we recommend using a

fresh build, to avoid any conflicting bundles from the start. There is no interference between multiple Eclipse installations in different folders.

§

Check if you have a Java Development Kit (JDK) installed,

Java Runtime Environment (JRE) alone is not sufficient

(7)

Android Developer System Setup

Install ADT Plugin for Eclipse

§

Select Help > Install New Software …

§

Add a new Repository with location

https://dl-ssl.google.com/android/eclipse/

§

Select Developer Tools

§

Confirm and install, restart Eclipse

§

Select Window > Preferences ;

enter install folder in SDK Location

(…/android-sdk)

M. Kranz / P. Lindemann / A. Riener Principles of Interaction // 2014S // Slide < 7 >

(8)

Android Developer System Setup

Install your phone software

§

May include required drivers or platform tools

§

e.g. for Samsung Galaxy, install Kies

§

Enable USB Debugging on your phone

(Settings > Applications > Development)

More details:

http://developer.android.com/sdk/installing/installing-adt.html

(9)

Android Developer System Setup

Test Developer System

§

Select File > New > Project …

Android Sample Project

§

Select 2.3.3 Platform

§

Create AccelerometerPlay Sample

§

Connect your phone and

deploy the sample (run as Android Application)

If you run into problems, first check the online guide at http://developer.android.com/sdk/installing.html

If it still does not work, consult our department forum at https://www.pervasive.jku.at/Forum/

(10)
(11)

Android Basics

§

Development in Java, virtual machine in Android is Dalvik

§

Class library contains most packages from Java Standard Edition (excluding some, e.g. AWT and Swing) and introduces a large set additional packages (android.*)

§

Compiled application is packaged in .apk file

§

Each application runs in its own isolated process

§

Applications are composed of one or several components: Activities,

Services, Content Providers and Broadcast receivers

§

If one component is in use, Android starts the application process and

terminates it when it is no longer required

(12)

Android Basics

(13)

Application Components

Activities (android.app.Activity)

§

implement user interface

§

each Activity subclass represents a single screen with interaction

elements, so called widgets (e.g. android.widget.Button,

android.widget.CheckBox, …)

§

Activities are independent, but can invoke each other and even activities

from other applications (e.g. to select a contact from the contact list)

§

one activity is designated as the main activity and will be shown when

the application is started

§

when another activity is started, the current activity is stopped and put

on the back stack

§

when an activity is closed, the last activity on the back stack is resumed

(14)

Application Components

Activity life cycle

§

onCreate: initialize

§

onStart: becomes visible

§

onResume: is in foreground

§

onPause: will go to background

§

onStop: is no longer visible

§

onDestroy: is being terminated

(15)

Application Components

Services (android.app.Service)

§

runs in the background and has no user interface

§

might fetch data from the network or play music …

§

a service can be can be Started, Bound or both:

§

Started: Service is started with startService(); will run until it is terminated.

§

Bound: Service is started when it is bound (when another component calls

bindService()) and is terminated as soon as the bound component

terminates (or unbinds).

(16)

Application Components

Service life cycle

§

onCreate: initialize

§

onStartCommand: is started service

§

onBind: is bound service

§

onUnbind: all bound components have unbound or have been

terminated

§

onDestroy: is being terminated

(17)

Application Components

Content providers (android.content.ContentProvider)

§

manages application data

§

data can be stored in the file system or an SQLite database

§

Android includes several Content providers, e.g. for the contact

information

Broadcast receivers (android.content.BroadcastReceiver)

§

responds to system wide announcements (e.g. screen turned off,

battery low, …)

§

intended to trigger Services or Activities

(18)
(19)

Manifest

AndroidManifest.xml

§

every application needs one

§

describes the application and all components in it

§

declares needed permissions

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

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

           package="jku.mypackage"  android:versionCode="1"  android:versionName="1.0">    

       <uses-­‐sdk  android:minSdkVersion="10"  />  

 

       <application  android:icon="@drawable/icon"  android:label="@string/app_name">                  <activity  android:name=".HelloWorldActivity"                                      android:label="@string/app_name">                          <intent-­‐filter>                                  <action  android:name="android.intent.action.MAIN"  />                                  <category  android:name="android.intent.category.LAUNCHER"  />                          </intent-­‐filter>                  </activity>          </application>     </manifest>

(20)

Resources

Put each type of resource in specific subfolders of /res:

§

e.g. Strings are defined in /res/values/strings.xml  

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

<resources>  

       <string  name="hello">Hello</string>  

       <string  name="hi">@string/hello</string>  

</resources>  

Resources can usually be used in the application by specifying the resource id:

someTextView.setText(R.string.hello);  

Read more about the specific resources and the corresponding folders at

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

(21)

GUI Editor

§

main.xml is created with

each new project

§

layouts are placed in

/res/layout/  

§

widgets can be dragged

to the layout and the most common options adjusted

§

advanced options can

be edited directly in the generated .xml

(22)

GUI Editor

To display a layout, set it as the active content view of an activity:

public  class  HelloWorldActivity  extends  Activity  {  

       /**  Called  when  the  activity  is  first  created.  */  

       @Override  

       public  void  onCreate(Bundle  savedInstanceState)  {  

               super.onCreate(savedInstanceState);  

               setContentView(R.layout.main);  

       }   }

R contains all resource IDs and is generated automatically from the resources placed in /res

(23)
(24)

SensorManager and Sensors

SensorManager (android.hardware.SensorManager)

§

The SensorManager lets you access all the different sensors

§

Retrieve the SensorManager with

(SensorManager)getSystemService(SENSOR_SERVICE);  

§

Retrieve an instance of the Sensor you need  

 

sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);    

§

Sensors: TYPE_ACCELEROMETER,  TYPE_AMBIENT_TEMPERATURE,  TYPE_GRAVITY,  

TYPE_GYROSCOPE,  TYPE_LIGHT,  TYPE_LINEAR_ACCELERATION,  TYPE_MAGNETIC_FIELD,   TYPE_PRESSURE,  TYPE_PROXIMITY,  TYPE_RELATIVE_HUMIDITY,  TYPE_ROTATION_VECTOR  

(25)

Accelerometer Sample

public  class  SensorActivity  extends  Activity  implements  SensorEventListener  {  

         private  final  SensorManager  mSensorManager;  

         private  final  Sensor  mAccelerometer;  

           protected  onCreate()  {                    super.onCreate();                    mSensorManager  =  (SensorManager)getSystemService(SENSOR_SERVICE);                    mAccelerometer  =  mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);            }    

         protected  void  onResume()  {  

                 super.onResume();  

                 mSensorManager.registerListener(this,  mAccelerometer,  SensorManager.SENSOR_DELAY_NORMAL);  

         }  

         protected  void  onPause()  {  

                 super.onPause();  

                 mSensorManager.unregisterListener(this);  

         }  

 

         public  void  onAccuracyChanged(Sensor  sensor,  int  accuracy)  {}  

         public  void  onSensorChanged(SensorEvent  event)  {  

                 Log.v("SensorActivity",  event.toString());  

         }    }  

Check the log in Eclipse (connect in DDMS view)

(26)

SensorEvent

SensorEvent (android.hardware.SensorEvent)

int    accuracy    The  accuracy  of  this  event.  

Sensor    sensor    The  sensor  that  generated  this  event.  

long    timestamp    The  time  in  nanosecond  at  which  the  event  happened   float[]    values    The  length  and  contents  of  the  values  array  

   depends  on  which  sensor  type  is  being  monitored   TYPE_ACCELEROMETER:

§

All values are in SI units (m/s2)

§

values[0]: Acceleration (including Gx) on the x-axis

§

values[1]: Acceleration (including Gy) on the y-axis

§

values[2]: Acceleration (including Gz) on the z-axis

(27)

WiFi

Android Connectivity Manager

§  Class that answers queries about the state of network connectivity. It also notifies applications when network connectivity changes. Get an instance of this class by calling Context.getSystemService(Context.CONNECTIVITY_SERVICE)!

§  The primary responsibilities of this class are to:

§  Monitor network connections (Wi-Fi, GPRS, UMTS, etc.)

§  Send broadcast intents when network connectivity changes

§  Attempt to "fail over" to another network when connectivity to a network is lost

§  Provide an API that allows applications to query the coarse-grained or fine-grained state of the available networks (à http://developer.android.com/reference/android/net/ConnectivityManager.html)

Android WiFi Manager

§  This class provides the primary API for managing all aspects of Wi-Fi connectivity. Get an instance of this class by calling

Context.getSystemService(Context.WIFI_SERVICE). It deals with:

§  The list of configured networks. The list can be viewed and updated, and attributes of individual entries can be modified.

§  The currently active Wi-Fi network, if any. Connectivity can be established or torn down, and dynamic information about the state of the network can be queried.

§  Results of access point scans, containing enough information to make decisions about what access point to connect to.

§  It defines the names of various Intent actions that are broadcast upon any sort of change in Wi-Fi state (à http://developer.android.com/reference/android/net/wifi/WifiManager.html)

(28)

Further reading

For an in-depth introduction read the developer guide at:

http://developer.android.com/guide/

M. Kranz / P. Lindemann / A. Riener Principles of Interaction // 2014S // Slide < 28 >

(29)

M. Kranz / P. Lindemann / A. Riener Principles of Interaction // 2014S // Slide < 29 >

Assignment PR Team Project >>

Implementation & Deployment

Please be aware of the due date/time!

Start first with a discussion about the research que-stion you want to address

References

Related documents

The use of galaxy clusters as probes of cosmology means minimising the systematic uncertainties and has a few key requirements (e.g. 2011): (i) the cluster masses must be

The algorithm saves the values corresponding to the arcs having a positive terminating node (this means that the value belongs to a valid tuple defined by the path). When the

Arrayed horns would have a horizontal axis at the diffraction slot, while vertical arrays would have the axis at the horn mouth.. This means that the horns can only be arrayed

For example, the ability of mentors to properly implement comfortable communication and provide adequate support in formal and/or informal mentoring activities may lead to an

The main contribution of the paper is delineated in the following part: (1) the distributed RHC scheme is developed to coordinate the impact time of the interceptor missiles, each

This entry level project management course is aimed at experienced project team members, junior project managers and project administrators who are looking to

Their baseline estimation employed the following explanatory variables: initial level of income (1989 per capita GDP), population growth (average annual growth rate), investment

Waitemata 2025 Project Team; WDHB Facilities and Development Team; Executive Leadership Team and Senior Management Team; The Institute for Innovation and Improvement; Project