Developing Android Applications

Similar documents
Introduction to Android Multimedia

Android Help. Section 8. Eric Xiao

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

1. Implementation of Inheritance with objects, methods. 2. Implementing Interface in a simple java class. 3. To create java class with polymorphism

BCS3283-Mobile Application Development

Using Intents to Launch Activities

CS 193A. Multiple Activities and Intents

Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department. Mobile Computing ECOM Eng. Wafaa Audah.

Syllabus- Java + Android. Java Fundamentals

Required Core Java for Android application development

Developing Android Applications Introduction to Software Engineering Fall Updated 1st November 2015

Programming with Android: Activities and Intents. Dipartimento di Informatica Scienza e Ingegneria Università di Bologna

Mobile Development Lecture 8: Intents and Animation

CMSC436: Fall 2013 Week 3 Lab

Terms: MediaPlayer, VideoView, MediaController,

Programming with Android: Intents. Luca Bedogni. Dipartimento di Scienze dell Informazione Università di Bologna

ATC Android Application Development

Android Programming Lecture 7 9/23/2011

ORACLE UNIVERSITY AUTHORISED EDUCATION PARTNER (WDP)

Intents. 18 December 2018 Lecture Dec 2018 SE 435: Development in the Android Environment 1

Java Training Center - Android Application Development

INTRODUCTION TO ANDROID

Mobile Application Development Android

ANDROID SYLLABUS. Advanced Android

CS 528 Mobile and Ubiquitous Computing Lecture 4a: Fragments, Camera Emmanuel Agu

Android. Operating System and Architecture. Android. Screens. Main features

Developing Android Applications

1. What are the key components of Android Architecture? 2. What are the advantages of having an emulator within the Android environment?

Overview. Lecture: Implicit Calling via Share Implicit Receiving via Share Launch Telephone Launch Settings Homework

Android Application Development using Kotlin

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

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

Why using intents. Activity. Screen1 Screen 2

Workshop. 1. Create a simple Intent (Page 1 2) Launch a Camera for Photo Taking

Android Programming (5 Days)

Using Libraries, Text-to-Speech, Camera. Lecture 12

XML Tutorial. NOTE: This course is for basic concepts of XML in line with our existing Android Studio project.

07. Menu and Dialog Box. DKU-MUST Mobile ICT Education Center

Introduction to Android

Hello World. Lesson 1. Android Developer Fundamentals. Android Developer Fundamentals. Layouts, and. NonCommercial

Topics Covered in the Android Apps Development Training

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

Multiple Activities. Many apps have multiple activities

MC Android Programming

Android System Architecture. Android Application Fundamentals. Applications in Android. Apps in the Android OS. Program Model 8/31/2015

Chapter 2 Welcome App

Application Fundamentals

Android Basics. Android UI Architecture. Android UI 1

Android Application Development

Understanding Application

Midterm Examination. CSCE 4623 (Fall 2017) October 20, 2017

CS 4518 Mobile and Ubiquitous Computing Lecture 5: Rotating Device, Saving Data, Intents and Fragments Emmanuel Agu

Android Programming Lecture 8: Activities, Odds & Ends, Two New Views 9/28/2011

Software Practice 3 Today s lecture Today s Task Porting Android App. in real device

CS378 -Mobile Computing. Intents

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

Writing Efficient Drive Apps for Android. Claudio Cherubino / Alain Vongsouvanh Google Drive Developer Relations

CORE JAVA& ANDROID SYLLABUS

Android Programming - Jelly Bean

Android Apps Development

Android Application Development Course Code: AND-401 Version 7 Duration: 05 days

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

Camera and Intent. Elena Fortini

Real-Time Embedded Systems

Assistant Professor Computer Science. Introduction to Human-Computer Interaction

Android Development Crash Course

Android App Development

LECTURE 08 UI AND EVENT HANDLING

Programming Concepts and Skills. Creating an Android Project

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

Diving into Android. By Jeroen Tietema. Jeroen Tietema,

Introduction to Android

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

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

what we will cover - setting up multiple activities - intents - lab 2 What you need to know for Lab 2

Q.1 Explain the dialog and also explain the Demonstrate working dialog in android.

RUNTIME PERMISSIONS IN ANDROID 6.0 Lecture 10a

CS 528 Mobile and Ubiquitous Computing Lecture 2a: Android UI Design in XML + Examples. Emmanuel Agu

Android App Development

Android development. Outline. Android Studio. Setting up Android Studio. 1. Set up Android Studio. Tiberiu Vilcu. 2.

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

INTENTS android.content.intent

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

ANDROID DEVELOPMENT. Course Details

CS 528 Mobile and Ubiquitous Computing Lecture 3b: Android Activity Lifecycle and Intents Emmanuel Agu

ANDROID COURSE BROCHURE

Android Programming Lecture 2 9/7/2011

Mobile Computing. Introduction to Android

Mobile Programming Lecture 1. Getting Started

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

Embedded Systems Programming - PA8001

Android Exam AND-401 Android Application Development Version: 7.0 [ Total Questions: 129 ]

MARS AREA SCHOOL DISTRICT Curriculum TECHNOLOGY EDUCATION

CS 403X Mobile and Ubiquitous Computing Lecture 3: Introduction to Android Programming Emmanuel Agu

Chapter 7: Reveal! Displaying Pictures in a Gallery

Lecture 2 Android SDK

SMAATSDK. NFC MODULE ON ANDROID REQUIREMENTS AND DOCUMENTATION RELEASE v1.0

Fig. 2.2 New Android Application dialog. 2.3 Creating an App 41

Hybrid Apps Combining HTML5 + JAVASCRIPT + ANDROID

M.C.A. Semester V Subject: - Mobile Computing (650003) Week : 2

Transcription:

Developing Android Applications Introduction to Software Engineering Fall 2015 Updated 21 October 2015

Android Lab 02 Advanced Android Features 2

Class Plan UI Elements Activities Intents Data Transfer Lab App 3

Menus and Action Bar Beginning with Android 3.0 (API level 11), Android-powered devices are no longer required to provide a dedicated Menu button. Different kinds of menus Option menu and action bar (e.g. search, compose mail, settings, etc.) Context menu and contextual action mode It appears when the user performs a long-click on an element and provides actions that affect the selected content or context frame Popup menu Actions in a popup menu should not directly affect the corresponding content. Rather, the popup menu is for extended actions that relate to regions of content in your activity Menus and items are defined in an XML file 4

Menus and Action Bar (Cont.) Two ways to handle click events Implement OnClick() Define the on-click behavior for a menu item in XML (Android 3.0 and higher) Manually override the OnClick behavior in your Java Code Override onoptionitemselected() 5

Dialogs Dialogs prompt the user for decisions or additional information required by the app to continue a task. Different dialogs AlertDialog You can also add lists DatePickerDialog TimePickerDialog Custom Layout 6

Toasts Simple feedback about an operation in a small popup They automatically disappear after a timeout You can position the toast differently or even use your own layout instead of a simple text message. 7

Settings Allow users to modify app features and behaviors. For example, how often the application syncs data with the cloud. Allow to build an interface that's consistent with the user experience in other Android apps (including the system settings). 8

Activity An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map. An application usually consists of multiple activities that are loosely bound to each other, with one being the Main activity. Individual Activities perform specific tasks and are connected by Intents. Each time a new activity starts, the previous activity is stopped, but the system preserves the activity in a stack. 10

Starting a new Activity Activities are started by calling special functions: startactivity( Intent ) startactivityforresult( Intent, RequestCode ) When starting an activity, an Intent is required. An activity Intent can specify a explicit target application or a general action (like show in map ). 11

Intents Messaging Objects designed to request actions from other app components Intent use-cases To start an activity To start a service To deliver a broadcast Intent types Implicit Explicit 12

Intent (cont.) The primary information contained: Component name Action Data Category Extra Flags http://developer.android.com/guide/components/intents-filters.html 13

Lab App Team Profile Manager: Time to work! (again) 14

1. Purpose: 1. Build a profile manager for a soccer (football) team 2. Requirements: 1. Application should have multiple activities 1. Each activity should have a specific purpose 2. You should be able to set the Teams Name 3. You should be able to set the Teams Logo 1. Separate Activity 4. You should be able to set the Teams Stadium Address 1. Separate Activity 5. You should be able to open a map application in the correct address set in your application 15

Main Activity Create a New Project with an EMPTY ACTIVITY. Add a EditText field for the Team name and an accompanying TextView that reads Team name: In the TeamName EdidText field, set the hint property to: (Please enter a team name) Repeat the process for the teams Location Add a Image View to represent the team s Logo. The image will initially appear invisible. To solve this issue, set the imageview s width and height parameter to about 100dp Add a button in the bottom of the screen to open a Map 16

Changing Graphics To add an art asset (image, sound, etc) to your project, all you have to do is copy it to the drawable project folder. app >> res >> drawable. You can right-click on the drawable folder and select show in explorer to find it more easily. Switch the standard image for an empty alternative Required art assets are available at: http://www.firasoft.com.br/uot/logos.zip 17

18

Explicit Intent to External Activity Add this function to your Main Activity Java File Set the OnClick Function of your Open Map button It will open your location on Google Maps This function Explicitly requests the google maps package in the intent. public void OnOpenInGoogleMaps (View view) { } EditText teamaddres = (EditText) findviewbyid(r.id.teamaddressfield); // Create a Uri from an intent string. Use the result to create an Intent. Uri gmmintenturi = Uri.parse("http://maps.google.co.in/maps?q="+teamAddres.getText()); // Create an Intent from gmmintenturi. Set the action to ACTION_VIEW Intent mapintent = new Intent(Intent.ACTION_VIEW, gmmintenturi); // Make the Intent explicit by setting the Google Maps package mapintent.setpackage("com.google.android.apps.maps"); // Attempt to start an activity that can handle the Intent startactivity(mapintent); Warning: For this to work, you need Google APIs in your Virtual Emulator 19

Explicit Intent to Internal Activity Add the function below to your Main Activity Java File Set the OnClick Function of your ImageView It will open another activity where we will choose the new avatar for the team public void OnSetAvatarButton(View view) { Intent intent = new Intent(getApplicationContext(), ProfileActivity.class); startactivityforresult (intent,0); } //Application Context and Activity The Intent object constructor has two parameters 1. Application Context : Where the application derives from. 1. If when creating a new Activity, we set the hierarchal parent to the main activity, we pass this as the context, otherwise we need to get the application s context using the getapplicationcontext() function. 2. Intent Class: Class the intent is requesting 20

Current Status Your emulated application should look vaguely like the one to the side. Add an OnClick function to the Button in the bottom matching the function on a previous slide. This function will open our location on a map application. Add an OnClick function to the ViewImage matching a function on a previous slide. Yes, you can add OnClicks to other objects! This function will open the team logo avatar selector. 21

Creating a new Activity To create a new Activity on Android Studio, rightclick anywhere on the Android Project area and select: Select Blank Activity New >> Activity >> Blank Activity 22

Creating a new Activity Fill the information according to your needs and Finish. Creating a new Activity will generate a new.java file for the second activity and a new xml layout. If the application implements the Up button, you can set another Activity as the Hierarchical Parent. Hierarchical Parent Example Up Button 23

Second Activity Create a second activity that is hierarchically under the Main Activity (this is done in the creation box). Clear the screen and add a VerticalLayout. Add a GridLayout to the VerticalLayout and create six ImageViews inside it. Format the images as in the previous screen. Arrange the items in a 2x3 grid. Add button to the VerticalLayout bellow the GridLayout. 24

While on the Second Activity How do I get back to my main activity? Activities are Stacked when new activities are launched, so when the current activity is done it will be removed from the stack and the main activity will be called back. All your data will still be in the app, textfields will still contain the data you may have typed on them. You do not need to place Back buttons on android applications, as Android has a back button in the bottom bar. Pressing it, removes the current activity from the stack and returns to the main activity. 25

Returning to Main Activity Add the function below to your Second Activity Java File. This should be the OnClick on your Images! This code forwards the ID of the image that was pressed to the Main Activity. public void SetTeamIcon(View view) { //Creating a Return intent to pass to the Main Activity Intent returnintent = new Intent(); } //Figuring out which image was clicked ImageView selectedimage = (ImageView) view; //Adding stuff to the return intent returnintent.putextra("imageid", selectedimage.getid()); setresult(result_ok, returnintent); //Finishing Activity and return to main screen! finish(); 26

Current Status Your emulated application should look vaguely like the one to the side. Add the SetTeamIconOnClick function to each of the Images. All images can map to the same function, available in the next slide. 27

Processing the result Add the function below to your Main Activity Java File. This will process the info we provided in the Return intent. The information we passed in the return intent is interpreted and used to set the new image. If your IDs are different, update the code to reflect the changes! @Override protected void onactivityresult(int requestcode, int resultcode, Intent data) { if (resultcode == RESULT_CANCELED) return; } //Getting the Avatar Image we show to our users ImageView avatarimage = (ImageView) findviewbyid(r.id.avatarimage); //Figuring out the correct image String drawablename = "ic_logo_00"; switch (data.getintextra("imageid",r.id.teamid00)) { case R.id.teamid00: drawablename = "ic_logo_00"; break; case R.id.teamid01: drawablename = "ic_logo_01"; break; case R.id.teamid02: drawablename = "ic_logo_02"; break; case R.id.teamid03: drawablename = "ic_logo_03"; break; case R.id.teamid04: drawablename = "ic_logo_04"; break; case R.id.teamid05: drawablename = "ic_logo_05"; break; default: drawablename = "ic_logo_00"; break; } int resid = getresources().getidentifier(drawablename, "drawable", getpackagename()); avatarimage.setimageresource(resid); 28

Current Status At this point, your application should: Display and update a teams name and address Show the teams Address on Google Maps Update and Show the teams Logo from a predefined list of images. Your application currently does not: Load Images from the Device Loading Images from the Device requires your device to have images loaded to it or a camera accessible, which imposes additional constraints, therefore, the final step is optional and is presented with an educational purpose. Loading Images also requires additional Permissions, which are generally managed automatically by Gradle, but may need to be added to the manifest file. 29

Implicit Intents Implicit Intent to Camera Feature: Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Can add extra content regarding media output, save location, format, etc. onactivityresult will receive an image path and will have to decode/handle the related image file. File file = new File(Environment.getExternalStorageDirectory() + "/DCIM/", "image" + new Date().getTime() + ".png"); Uri imguri = Uri.fromFile(file); String imgpath = file.getabsolutepath(); final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putextra(mediastore.extra_output, setimageuri()); startactivityforresult(intent, CAPTURE_IMAGE); @Override protected void onactivityresult(int requestcode, int resultcode, Intent data) { if (resultcode!= Activity.RESULT_CANCELED) { if (requestcode == CAPTURE_IMAGE) { ImageView imageview = (ImageView) findviewbyid(r.id.imgview); imageview.setimagebitmap(bitmapfactory.decodefile(imgpath)); }}} 30

Implicit Intents Implicit Intent to Storage: Intent intent = new Intent(Intent.ACTION_PICK); Can add extra content regarding media type, etc. onactivityresult will receive an image path and will have to decode the related image file. Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startactivityforresult(i, RESULT_LOAD_IMAGE); @Override protected void onactivityresult(int requestcode, int resultcode, Intent data) { super.onactivityresult(requestcode, resultcode, data); if (requestcode == RESULT_LOAD_IMAGE && resultcode == RESULT_OK && null!= data) { Uri selectedimage = data.getdata(); String[] filepathcolumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getcontentresolver().query(selectedimage,filepathcolumn, null, null, null); cursor.movetofirst(); int columnindex = cursor.getcolumnindex(filepathcolumn[0]); String picturepath = cursor.getstring(columnindex); cursor.close(); ImageView imageview = (ImageView) findviewbyid(r.id.imgview); imageview.setimagebitmap(bitmapfactory.decodefile(picturepath)); }} 31

Interested in Learning more? Follow the Android Training Guide https://developer.android.com/training/index.html 32