M. Kranz, P. Lindemann, A. Riener 340.301 UE Principles of Interaction, 2014S 06 Team Project: Android Development Crash Course; Project Introduction April 11, 2014 Priv.-Doz. Dipl.-Ing. Dr. Andreas Riener Institute for Pervasive Computing Johannes Kepler University riener@pervasive.jku.at
Schedule for Today Team Project Assignment 4 Part 2 (user study execution) in-class discussion Android App Development Crash course Project Introduction and Launch Discussion: how, who, what, when? Principles of Interaction // 2014S // Slide < 2 >
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 Team work Part 1: Survey/Questionnaire Design Part 2: Execution 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 Some of the phases might be done through in-class HCI practice activities Principles of Interaction // 2014S // Slide < 3 >
Android Software Development Introduction
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) Principles of Interaction // 2014S // Slide < 5 >
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 Principles of Interaction // 2014S // Slide < 6 >
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) Principles of Interaction // 2014S // Slide < 7 >
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 Principles of Interaction // 2014S // Slide < 8 >
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/ Principles of Interaction // 2014S // Slide < 9 >
Android Application Development
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 Principles of Interaction // 2014S // Slide < 11 >
Android Basics Principles of Interaction // 2014S // Slide < 12 >
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 Principles of Interaction // 2014S // Slide < 13 >
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 Principles of Interaction // 2014S // Slide < 14 >
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). Principles of Interaction // 2014S // Slide < 15 >
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 Principles of Interaction // 2014S // Slide < 16 >
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 Principles of Interaction // 2014S // Slide < 17 >
Resources and GUI Editor
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> Principles of Interaction // 2014S // Slide < 19 >
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 Principles of Interaction // 2014S // Slide < 20 >
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 Principles of Interaction // 2014S // Slide < 21 >
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 Principles of Interaction // 2014S // Slide < 22 >
Sensors and acquiring sensor data
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 Principles of Interaction // 2014S // Slide < 24 >
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()); } } Principles of Interaction // 2014S // Slide < 25 > Check the log in Eclipse (connect in DDMS view)
SensorEvent SensorEvent (android.hardware.sensorevent) int accuracy The accuracy of this event. Sensor sensor The sensor that generated this event. long float[] values timestamp The time in nanosecond at which the event happened 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/s 2 ) 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 Principles of Interaction // 2014S // Slide < 26 >
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) Principles of Interaction // 2014S // Slide < 27 >
Further reading For an in-depth introduction read the developer guide at: http://developer.android.com/guide/ Principles of Interaction // 2014S // Slide < 28 >
Assignment PR Team Project >> Implementation & Deployment Please be aware of the due date/time! Start first with a discussion about the research question you want to address Principles of Interaction // 2014S // Slide < 29 >