SpotOn Game App Android How to Program ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

Slides:



Advertisements
Similar presentations
Chapter 6: Jam! Implementing Audio in Android Apps.
Advertisements

Unlocking Android Chapter 4.  Understanding activities and views  Exploring the Activity lifecycle  Working with resources  Defining the AndroidManifest.xml.
Android 02: Activities David Meredith
All About Android Introduction to Android 1. Creating a New App “These aren’t the droids we’re looking for.” Obi-wan Kenobi 1. Bring up Eclipse. 2. Click.
The Android Activity Lifecycle. Slide 2 Introduction Working with the Android logging system Rotation and multiple layouts Understanding the Android activity.
Filip Debelić What is it? Android is a mobile operating system (OS) based on the Linux kernel and currently developed by Google Android,
Android Fragments.
More on User Interface Android Applications. Layouts Linear Layout Relative Layout Table Layout Grid View Tab Layout List View.
By: Jeremy Smith.  Introduction  Droid Draw  Add XML file  Layouts  LinearLayout  RelativeLayout  Objects  Notifications  Toast  Status Bar.
Basic Animation. Animation 4 options – Animated.gif – Frame by Frame animation – Tweened animation This is our focus – OpenGL ES Graphics API for more.
CS378 - Mobile Computing Anatomy of an Android App and the App Lifecycle.
Android: versions Note that: Honeycomb (Android v3.0) A tablet-only release Jelly Bean (Android v4.1) Released on July 09, 2012.
 Understanding an activity  Starting an activity  Passing information between activities  Understanding intents  Understanding the activity lifecycle.
ANDROID UI – FRAGMENTS. Fragment  An activity is a container for views  When you have a larger screen device than a phone –like a tablet it can look.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Concurrency in Android with.
Chapter 10: Move! Creating Animation
Favorite Twitter® Searches App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Chapter 2: Simplify! The Android User Interface
Tip Calculator App Building an Android App with Java © by Pearson Education, Inc. All Rights Reserved.
Doodlz App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
DUE Hello World on the Android Platform.
Activities and Intents. Activities Activity is a window that contains the user interface of your application,typically an application has one or more.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Using Android XML Resources.
Chapter 2 The Android User Interface. Objectives  In this chapter, you learn to:  Develop a user interface using the TextView, ImageView, and Button.
INTRODUCTION TO ANDROID. Slide 2 Application Components An Android application is made of up one or more of the following components Activities We will.
Programming Mobile Applications with Android September, Albacete, Spain Jesus Martínez-Gómez.
Android Boot Camp for Developers Using Java, 3E
Android – Fragments L. Grewe.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 2: Simplify! The Android User Interface.
Field Trip #32 Digital Alarm Clock By Keith Lynn.
Noname. Conceptual Parts States of Activities Active Pause Stop Inactive.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.
Chapter 14 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
HW#9 Clues CSCI 571 Fall, HW#9 Prototype
MOBILE COMPUTING D10K-7D02 MC05: Android UI Design Dr. Setiawan Hadi, M.Sc.CS. Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
User Interface Layout Interaction. EventsEvent Handlers/Listeners Interacting with a user.
Flag Quiz Game App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 10: Move! Creating Animation 1 Android.
Class on Fragments & threads. Fragments fragment is a modular section of an activity, which has its own lifecycle, receives its own input events, and.
CHAPTER 4 Fragments ActionBar Menus. Explore how to build applications that use an ActionBar and Fragments Understand the Fragment lifecycle Learn to.
ANDROID LAYOUTS AND WIDGETS. Slide 2 Introduction Parts of the Android screen Sizing widgets and fonts Layouts and their characteristics Buttons, checkboxes.
Android Fragments. Slide 2 Lecture Overview Getting resources and configuration information Conceptualizing the Back Stack Introduction to fragments.
The Flag Quiz app tests your ability to correctly identify 10 flags from various countries and territories.
Dive Into® Visual Basic 2010 Express
Chapter 2: Simplify! The Android User Interface
Open Handset Alliance.
Activity and Fragment.
Android Boot Camp for Developers Using Java, 3E
Activities, Fragments, and Events
Fragment ?.
Mobile Application Development BSCS-7 Lecture # 6
Activities and Intents
Android Activities An application can have one or more activities, where Each activity Represents a screen that an app present to its user Extends the.
Android Mobile Application Development
Android Widget Tutorial
Creation of an Android App By Keith Lynn
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
The Android Activity Lifecycle
ANDROID UI – FRAGMENTS UNIT II.
Chapter 3: Coding the GUI Programmatically, Layout Managers
Adding Functionality to the App Tip Calculator App Activity and the Activity Lifecycle onCreate is called by the system when an Activity.
Cannon Game App Android How to Program
Android Topics Android Activity Lifecycle and Experiment Toast
Programming Mobile Applications with Android
Android Development Tools
Activities, Fragments, and Intents
Presentation transcript:

SpotOn Game App Android How to Program © by Pearson Education, Inc. All Rights Reserved.

Android 3.x ▫First app to use features of Android 3.0+ ▫Using it to animate properties ▫Actually this is an Android 3.1 app AVDs for Android 3.0+ apps are extremely slow ▫Run on an Android device, if possible © by Pearson Education, Inc. All Rights Reserved.

Test driving the app © by Pearson Education, Inc. All Rights Reserved.

Technologies Overview Prior to Android 3.0 animation done three ways: ▫Tweened View animations to change View’s appearance, such as where it is displayed, rotation, size the way we did in FlagQuizGame ▫Frame View animations for sequence of images ▫Create animations the way we did it with CannonGame Problem: if you animate a button, can only initiate Button’s click event where the Button was originally © by Pearson Education, Inc. All Rights Reserved.

Technologies Overview Property Animators ▫Used to move and scale ImageViews dynamically ▫Can animate ANY property of ANY object ▫Not limited to Views ▫Can interact with a Button after it has moved Property Animators animate values over time Specify ▫Target object ▫Property to animate ▫Duration of animation ▫Values to animate between for each property ▫How to change the values over time (interpolator) © by Pearson Education, Inc. All Rights Reserved.

Technologies Overview Two property animation classes: Value Animator and Object Animator ValueAnimator ▫Calculates property values over time ▫Must specify AnimatorUpdateListener ▫Programmatically modigy target object’s property values ▫Useful if target object does not have standard set methods for changing property values © by Pearson Education, Inc. All Rights Reserved.

Technologies Overview Two property animation classes ObjectAnimator ▫Subclass of ValueAnimator ▫Uses target object’s set methods to modify object’s animated properties as their values change over time © by Pearson Education, Inc. All Rights Reserved.

New Utility class Added by Android 3.1 ViewPropertyAnimator ▫Simplifies property animation for Views ▫Allows multiple properties to be animated in parallel ▫Now each View contains an animate method  Returns a ViewPropertyAnimator on which you can chain method calls to configure the animation  When last method call on chain finishes, the animation starts  Used to animate spots in this game © by Pearson Education, Inc. All Rights Reserved.

Technologies Overview Two ways to listening for Animation Lifecycle Events Implement interface AnimatorListener ▫Defines methods called when animation starts, ends, repeats or is cancelled Extend class AnimatorListenerAdapter ▫If you do not need all four methods ▫Override only the listener method(s) you need © by Pearson Education, Inc. All Rights Reserved.

Technologies Overview Touch Handling ▫Introduced in CannonGame – overrode Activity method onTouchEvent ▫Two types of touches in the SpotOn game  Touching a spot  Touching elsewhere on the screen Register onClickListeners for each spot (i.e. ImageView) to process touching a spot Use onTouchEvent to process all other screen touches © by Pearson Education, Inc. All Rights Reserved.

Building the App’s GUI Set attributes in string.xml (not shown and not discussed) Set attributes in AndroidManifest.xml file App’s main.xml layout file contains two layouts ▫RelativeLayout  Positions the app’s TextViews for displaying  High score, level and current score ▫LinearLayout (nested inside RelativeLayout)  Display’s lives remaining The layouts and GUI components in this app have all been seen before …and two other XML files © by Pearson Education, Inc. All Rights Reserved.

This ImageView will be inflated and configured dynamically for each new spot in the game.

© by Pearson Education, Inc. All Rights Reserved. This ImageView will be inflated and configured dynamically each time a new life is added to the Screen during the game.

Building the App Consists of two classes ▫SpotOn – app’s main Activity ▫SpotOnView – subclass of View, it defines the game logic and spot animations © by Pearson Education, Inc. All Rights Reserved.

Construct the SpotOnView Requires 3 arguments: Context in which GUI component is displayed (this Activity) A SharedPreference object The RelativeLayout (so SpotOnView can interact with other GUI components in the layout) layout); Ch5 showed how to read from a SharedPreferences file, here we use default one associated with this Activity

© by Pearson Education, Inc. All Rights Reserved. Add the SpotOnView to the RelativeLayout at position 0 – that is, behind all the other elements in the layout Call the SpotOnView’s pause And resume methods

OnPause and OnResume onPause releases SoundPool resources and cancels running animations. When an Activity begins executing, ▫The method OnCreate is executed, followed by OnStart, then onResume onResume is also called when an Activity in the background returns to the foreground In this app’s Activity, SpotOnView’s resume method obtains (or re-obtains) SoundPool resources and starts (or restarts) the game This app does not save the game’s state when the app is not on the screen. © by Pearson Education, Inc. All Rights Reserved.

SpotOnView Subclass of View © by Pearson Education, Inc. All Rights Reserved. OnCreateOnResume OnPause +SpotOnView constructor +pause +resume +cancelAnimations +initializeSoundEffects +resetGame +displayScores +addSpotRunnable +addNewSpot +touchedSpot +missedSpot onTouchEvent +displayScores onClickListener

© by Pearson Education, Inc. All Rights Reserved. For collection of spots and animators

© by Pearson Education, Inc. All Rights Reserved.

Call to this from OnCreate view = new SpotOnView (this, getPreferences(Context.MODE_PRIVATE), layout);

© by Pearson Education, Inc. All Rights Reserved.

For each loops Do not want animations to continue executing when app not on screen

© by Pearson Education, Inc. All Rights Reserved. If dialogDisplayed is true, it is because the end-of-game dialog is still displayed on the screen and user can click the Reset Game button to start over; otherwise, it will call resetGame.

© by Pearson Education, Inc. All Rights Reserved. Inflate the life.xml file

© by Pearson Education, Inc. All Rights Reserved. Schedule game’s first few spots

© by Pearson Education, Inc. All Rights Reserved. Uses CannonGame’s same technique to prepare game’s sound effects

© by Pearson Education, Inc. All Rights Reserved.

resetGame’s spotHandler’s postDelayed method receives the addSpotRunnable as an argument. This Runnable’s run method simply calls addNewSpot.

© by Pearson Education, Inc. All Rights Reserved. Called -Several times near the beginning of game to display initial spots -Whenever the user touches a spot -When a spot’s animation ends without the spot being touched Set spot’s values

© by Pearson Education, Inc. All Rights Reserved. Each new added spot has a listener

© by Pearson Education, Inc. All Rights Reserved. Chained methods Only override two of the four AnimatorListener’s methods

© by Pearson Education, Inc. All Rights Reserved.

Wrap-up Be able to describe three animation mechanisms Know what was added in Android 3.0 and 3.1 that was used in the SpotOn game Know what 4 methods are available in AnimatorListenerAdapter Know how to chain methods to configure an animation Know how to cancel animations Know the methods of the ConcurrentLinkedQueue class and what it is used for © by Pearson Education, Inc. All Rights Reserved.