ES E 3 3 L a L b 5 Android development

Similar documents
CS 234/334 Lab 1: Android Jump Start

COMP4521 EMBEDDED SYSTEMS SOFTWARE

Lab 1: Getting Started With Android Programming

Eventually, you'll be returned to the AVD Manager. From there, you'll see your new device.

Mobile Programming Lecture 2. Layouts, Widgets, Toasts, and Event Handling

CS 370 Android Basics D R. M I C H A E L J. R E A L E F A L L

BCA 6. Question Bank

<uses-permission android:name="android.permission.internet"/>

Figure 2.10 demonstrates the creation of a new project named Chapter2 using the wizard.

Developed and taught by well-known Contact author and developer. At public for details venues or onsite at your location.

Android Workshop: Model View Controller ( MVC):

INTRODUCTION TO ANDROID

Lab 3. Accessing GSM Functions on an Android Smartphone

Android User Interface

Android Basics. - Bhaumik Shukla Android Application STEALTH FLASH

Exercise 1: First Android App

Android User Interface Android Smartphone Programming. Outline University of Freiburg

Android Development Tutorial. Yi Huang

Android Application Development

Mobile User Interfaces

Android App Development. Mr. Michaud ICE Programs Georgia Institute of Technology

CMSC 436 Lab 10. App Widgets and Supporting Different Devices

Lab 1 - Setting up the User s Profile UI

GUI Design for Android Applications

ECOM 5341 Mobile Computing(Android) Eng.Ruba A. Salamah

Android UI DateBasics

10.1 Introduction. Higher Level Processing. Word Recogniton Model. Text Output. Voice Signals. Spoken Words. Syntax, Semantics, Pragmatics

Android Beginners Workshop

LECTURE 08 UI AND EVENT HANDLING

Mobile Programming Lecture 3. Resources, Selection, Activities, Intents

When programming in groups of people, it s essential to version the code. One of the most popular versioning tools is git. Some benefits of git are:

University of Stirling Computing Science Telecommunications Systems and Services CSCU9YH: Android Practical 1 Hello World

Vienos veiklos būsena. Theory

CS 4330/5390: Mobile Application Development Exam 1

Configuring the Android Manifest File

CS378 -Mobile Computing. Anatomy of and Android App and the App Lifecycle

Building MyFirstApp Android Application Step by Step. Sang Shin Learn with Passion!

Mobile Programming Lecture 1. Getting Started

Mobila applikationer och trådlösa nät, HI1033, HT2013

Android Programming (5 Days)

Introduction To Android

Android Development Crash Course

Android Development Tools = Eclipse + ADT + SDK

Programming Concepts and Skills. Creating an Android Project

Android for Ubiquitous Computing Researchers. Andrew Rice University of Cambridge 17-Sep-2011

ListView Containers. Resources. Creating a ListView

Using Eclipse for Android Development

Mobile Application Development Android

Questions and Answers. Q.1) Which of the following is the most ^aeuroeresource hungry ^aeuroepart of dealing with activities on android?

Mobila applikationer och trådlösa nät, HI1033, HT2012

How to Set up Eclipse and Android SDK Manager Environment You need to download the following

Chapter 2 Welcome App

In this Class Mark shows you how to put applications into packages and how to run them through the command line.

CS371m - Mobile Computing. User Interface Basics

Around Android. Essential Android features illustrated by a walk through a practical example

Programming in Android. Nick Bopp

ANDROID APPS (NOW WITH JELLY BEANS!) Jordan Jozwiak November 11, 2012

CS 4518 Mobile and Ubiquitous Computing Lecture 2: Introduction to Android Programming. Emmanuel Agu

Android Programming Lecture 2 9/7/2011

COSC 3P97 Mobile Computing

Android Application Development Instructions

14.1 Overview of Android

Dependence Graph Considerering Resource for Automatic Sample Program Generation

SD Card with Eclipse/Emulator

CS 528 Mobile and Ubiquitous Computing Lecture 2a: Introduction to Android Programming. Emmanuel Agu

Understand applications and their components. activity service broadcast receiver content provider intent AndroidManifest.xml

package import import import import import import import public class extends public void super new this class extends public super public void new

Agenda. Overview of Xamarin and Xamarin.Android Xamarin.Android fundamentals Creating a detail screen

O X X X O O X O X. Tic-Tac-Toe. 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 2: The Ultimate Tic-Tac-Toe Game

CS 4518 Mobile and Ubiquitous Computing Lecture 4: WebView (Part 2) Emmanuel Agu

Mobile OS. Symbian. BlackBerry. ios. Window mobile. Android

Our First Android Application

This lecture. The BrowserIntent Example (cont d)

University of Babylon - College of IT SW Dep. - Android Assist. Lect. Wadhah R. Baiee Activities

MARS AREA SCHOOL DISTRICT Curriculum TECHNOLOGY EDUCATION

Android. Mobile operating system developed by Google A complete stack. Based on the Linux kernel Open source under the Apache 2 license

User Interface: Layout. Asst. Prof. Dr. Kanda Runapongsa Saikaew Computer Engineering Khon Kaen University

ANDROID APPS DEVELOPMENT FOR MOBILE GAME

MC Android Programming

Getting started: Installing IDE and SDK. Marco Ronchetti Università degli Studi di Trento

EMBEDDED SYSTEMS PROGRAMMING UI and Android

UI, Continued. CS 2046 Mobile Application Development Fall Jeff Davidson CS 2046

Agenda. The Android GUI Framework Introduction Anatomy A real word example Life cycle Findings

Produced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology

1. Location Services. 1.1 GPS Location. 1. Create the Android application with the following attributes. Application Name: MyLocation

Mobile App Design Project Doodle App. Description:

CS 528 Mobile and Ubiquitous Computing Lecture 3: Android UI, WebView, Android Activity Lifecycle Emmanuel Agu

COLLEGE OF ENGINEERING, NASHIK-4

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

Praktikum Entwicklung Mediensysteme. Implementing a User Interface

Security model. Marco Ronchetti Università degli Studi di Trento

LECTURE NOTES ON MOBILE APPLICATION DEVELOPMENT

Embedded Systems Programming - PA8001

Applications. Marco Ronchetti Università degli Studi di Trento

Create new Android project in Android Studio Add Button and TextView to layout Learn how to use buttons to call methods. Modify strings.

Fragments were added to the Android API in Honeycomb, API 11. The primary classes related to fragments are: android.app.fragment

Building User Interface for Android Mobile Applications II

Mul$media Support in Android

Getting Started. Dr. Miguel A. Labrador Department of Computer Science & Engineering

CS378 -Mobile Computing. Audio

Transcription:

ES3 Lab 5 Android development

This Lab Create a simple Android interface Use XML interface layouts Access the filesystem Play media files Info about Android development can be found at http://developer.android.com/index.html The JavadocSDK can be found at http://developer.android.com/reference/packages.html

Create a basic MP3 media player Assignment

Installing Eclipse and ADT Eclipse and ADT aren't installed on the lab machines Installers are provided Install Eclipse JEE x64 for OS X (eclipse-j...tar.gz) expand it to eclipse/ your home directory Install the Android SDK expand to android/ in your home directory (android-sdk...zip) Open eclipse, go to Help/Install new software... Choose Add.. and enter Androidfor the name and the adt-0.9.5.zip file for the Archive Install... Check the box by Developer Tools Click next, and use the default options (DDMS and development tools) Restart Eclipse

Create an emulator image Go to android/tools and run android In the Virtual Devices tab, click New, Call it DefaultAVD Use platform 2.1 (API level 7) Use a 1024Mb SD card Use the default (HVGA) skin Click Create AVD Start up Eclipse

Getting Started Create a new project New/Other/Android/Android Project Call it AndroidLab1 Make it targetandroid 2.1 Fill in application name: AndroidLab1 Package name: com.es3.labs.androidlab1 Make sure Create activity is ticked, and call it StartActivity

Check it works Go to Run/Run... and choose run as Android application After some time, this should appear:

The Layout Expand src and then com.es3.labs.androidlab1 Look at StartActivity.java This is where the entry point for the application will be Note that oncreate calls setcontentview on a R.layout.main You can find the definition for this layout by expanding res/layoutthen opening main.xml (choose the main.xml tab)

main.xml

Default Manifest Have a look at res/androidmanifest.xml Choose the AndroidManifest.xml tab at the bottom to actually see the XML Note the <activity> element and the <intent-filter> element within it This filter marks that the StartActivityactivity will receive the MAINaction intent and has category LAUNCHER i.e. makes it the entry point

Adding an XML layout Go to the Layout tab of main.xml and right click the TextView choose remove and remove it and the LinearLayout containing it Drag a new LinearLayoutonto the blank canvas Warning: the Eclipse UI preview is very buggy...

Adding some buttons Drag on four new Buttoninstances Go to the main.xml tab and manually edit the text attribute so they are Play/Pause, Stop, Next and Prev Change the id attribute so the buttons are @+id/playbutton etc. Click on StartActivity.java (important!) then do Run/Run...

Responding to button pushes Make StartActivity implement OnClickListener add import android.view.view.onclicklistener to the top of StartActivity.java and import android.view.* You need to implement the method onclick public void onclick(view v) { } This gets passed the view that was clicked You can get the id of a view with getid() Test each button to see if the id matches the view's id Don't do anything in the blocks yet! if(v.getid() == R.id.StopButton) { } if(v.getid() == R.id.PlayButton) { } // etc...

Adding the listeners For each button Look up the Button instance using findviewbyid() e.g. findviewbyid(r.id.playbutton) Add the listener to it using setonclicklistener Now the listener will be called when the button is pushed

Adding audio playback We need audio playback support this is in android.media.* import this Create an instance variable in StartActivity of type MediaPlayer Instantiate it in oncreate() player = new MediaPlayer(); in oncreate(), we need to load all the available MP3 files first we list all available files then we identify MP3 files we add these to a list

Listing available files Create an instance method of StartActivity called listavailablemp3s() File objects are used to access file system info (imported from java.io.file) In listavailablemp3s, create a new File object with "/media" as the path This is the Android path for media files like videos and music the listfilesmethod lists files in a directory (returns an array of File[]) note: you only want MP3 files, so you'll probably want to create FIlenameFilterclass to filter the files read (see the API docs) check each element is an actual file (not a directory) with isfile() Return the files and store them in a class instance Copy the file names into a second array (this will be shown onscreen) This is the track list for the player

Copying files onto the device Obviously the device doesn't actually have any mp3 files yet Get some (use your own or find some royalty-free music) Copy files over by going to Window/Open perspective... choose Other.../DDMS use the to phone button (tiny button at top-right, with an arrow pointing onto the phone) Copy the files to /sdcard

Media player usage Set the data source, prepare the media player, and begin playback player.setdatasource(path); player.prepare(); player.start(); Pause with player.pause() and stop with player.stop()

Pause, Stop, Previous, Next Add a boolean variable to represent the play/pause state e.g. isplaying it should initially false Make it toggle when the play/pause button is pushed If it's False, start playing (as above), make it false If it's True, then call player.pause(), make it true Similarly, if the stop button is pressed, call player.stop() Create a variable to represent the current track index For previous, decrement the track index, stop the current file, play the next file if track index<0 make track index the last file And similarly for next Test it! You should have a fully functioning (if limited) media player!

Track view Go to the main layout (res/layout/main.xml) Edit the XML directly and add a new LinearLayoutaround the whole thing You can copy and paste the existing LinearLayout, but remember to change the ID! Set the layout's orientation attribute to vertical <LinearLayout android:orientation="vertical" android:id="... After the first LinearLayout is closed add a <ListView> element set its id attribute to @+id/trackview Set the layout_height of the inner LinearLayout to "100px" instead of "fill_parent" The rough XML structure should look like this <LinearLayout vertical> <LinearLayout horizontal> <Button play> <Button stop> <Button prev> <Button next> </LinearLayout> <ListView> </LinearLayout>

Track View Each element of the ListViewmust be a View Conventionally a TextView Configure the appearance of each of the rows by creating an XML file to represent the layout of one row Go to res/layout and right-click, New.. Choose other, Android XML Set the file to track.xml Make the root element a TextView(drop down at the bottom) Click Finish Edit the generated XMLfile and change the layout_widthattribute to "fill_parent"so that the list elements extend across the whole screen

Accessing the Track View Import android.widget.* In oncreate() get hold of the ListView reference using findviewbyid on R.id.TrackView You'll need to cast the result to ListView Link the ListViewto the track array ListViews use ListAdapaters to connect data to the list We want to use an ArrayAdapter Takes as arguments a context (this), the text object to use for each row (R.layout.track), and the array to use tracklist.setadapter(new ArrayAdapter<String>(this, R.layout.track, tracks.toarray()); Add a method updatetrackviewwhich uses setselectionto match the ListView'sselection to the current track index Call it in oncreate(), and after the track index is updated when the buttons are pressed

Highlighting the current track We want to highlight the track that is currently playing Do this by setting the TextView'scolor You can get the child TextView's in the ListView by using getchildat(index) Get all TextView instances from the ListView set their colorsto gray use settextcolor() Get the current TextView instance from the ListView Set the colorof this to white

Extra functionality Make the media player automatically go to the next file when it finishes (look at the MediaPlayermethods to see how to do this) Add a shuffle mode, with a button to toggle it This means that next and the auto-advance when a track finishes should go to a random track But prevshould go to the previous track keep a list of previous tracks! Allow the user to tap on the list to select a track add a listener to the list, make it set the track index and start playing the new track