Homework in preparation for this lecture
- Read HA: Chapter 4
- Type in (don't copy) all the additional code to the Soduko application
- Lay out the game board, handle input, hints, etc.
- Get it to work in the emulator, and get it to work in an Android device
- Check your code into github
- Do a screencast of you running the latest version of the app
- Include in the screencast a verbal description of the interesting/important parts as you show the code in Eclipse
- Add links to both into your Homework Log
- Learn XML. Do this basic XML Tutorial
- Create an XML document that represents a student's transcript for 4 years of college, with a good amount of detail. You will invent the tags in a way that is meaningful to you.
- Deliverable: Post the result as a blog post
- Game design from yesterday
- Yesterday we formed 4 teams and they invented a game
- Deliverable: a joint blog post describing the new game
- Learning Objectives
- understand how to create interactive 2D Graphics
- learn how to draw on a screen, using a Model/View/Controller model (see Lunar Lander)
- learn how to control the View with simple user interaction (onDraw, invalidate, e.g. FingerPaint)
- learn how to add animation effects using a handler (e.g TouchPaint)
- Walk through several examples including
- LunarLander (showing how to use a SurfaceView for Game Animations)
- APIdemo (showing a wide variety of Graphics demos including TouchPaint and FingerPaint)
- How would we implement the MazeGame as a 2D game on an Android device?
- brainstorm on the possible structures using the Sudoku example as one model
- discuss merits and drawbacks of different approaches
- Create Eclipse projects for APIdemo and LunarLander from google SDK download samples folder
- Spend 10 minutes flipping through APIdemo looking for examples that could be used in your projects
- Report back to the group and give demos ...
Fundamental Packages/Classes for 2D Graphics
This class represents the basic building block for user interface components. A View
occupies a rectangular area on the screen and is responsible for drawing and
event handling. View is the base class for widgets, which are
used to create interactive UI components (buttons, text fields, etc.). The
ViewGroup subclass is the base class for layouts, which
are invisible containers that hold other Views (or other ViewGroups) and define
their layout properties.
- Algorithm for drawing a View: http://developer.android.com/guide/topics/ui/how-android-draws.html
- Provides classes to manage a variety of visual elements that are intended for
display only, such as bitmaps and gradients. These elements are often used
by widgets as background images or simply as indicators (for example, a volume
- You can create most of these drawables using XML, as described in Drawable Resources.
- The Canvas class holds the "draw" calls. To draw something, you need
4 basic components: A Bitmap to hold the pixels, a Canvas to host
the draw calls (writing into the bitmap), a drawing primitive (e.g. Rect,
Path, text, Bitmap), and a paint (to describe the colors and styles for the
- onDraw method is called when the OS wants to refresh the screen
- android.os.Handler (used to send messages to a thread with a delay, possibly its own thread)
Kinds of 2d Graphics
- maps, charts, photos, static content (best represented as bitmaps and resources ...)
- graphs and simple static line drawings (use Canvas class and invalidate sections that need redrawing)
- use of inner class to create a custom view
- customization of Paint object and use of filters
- override onSizeChanged (can create a new canvas ...)
- override onDraw to actually draw the view using the underlying model (mixed up in this class :( )
- use of "private"
- override onTouchEvent to handle finger paint actions
- override onCreateOptions, onPrepareOptions, onOptionItemSelected to handle menus
- animation with lingering effects (use canvas with a handler to update the effects periodically)
- use of inner class to create a customized view
- use of a Bundle to store savedInstanceState
- menu handling by onCreateOptions, etc.
- use of Handler to implement an animation effect on the model ... send, catch/resend
- use of onTrackBallEvent and onTouchEvent
- use of MotionEvent history to handle several events ...
- use of Pressure sensor
- game style animation (use canvas with a simulation thread)
- Model/View/Controller approach
- LunarThread handles model runs continuously ..
- look over run method with synchronization and use of surfaceholder ...
- fancy savestate
- main view passing keypress info to thread ...