In Fall 2018 at
NYU
SPS,
this course is
INFO1-CE9416.
The
iOS course
has the same format.
<activity>
element in the app’s
AndroidManifest.xml
file specifies which subclass of class
Activity
will be instantiated.
onCreate
method of the activity object when the app is launched.
onCreate
is one of the methods in one of the three pairs of
Activity
lifecycle
methods.
Don’t call them directly.
For example,
call
finish
to trigger a call to
onDestroy
.
Permanent data should be saved in
onPause
,
not in
onDestroy
.
activity_main.xml
contains a
RelativeLayout
which contains a
TextView
.
The items inside a
RelativeLayout
can have
positioning attributes
such as
android:layout_below
and
android:layout_toRightOf
.
TextClock
(exercise #11).
FrameLayout
and
FrameLayout.LayoutParams
.
A FrameLayout usually holds only one child.
See exercise 12 in
LinearLayout;
exercise 1 in
GridView;
Sqlite.
if
statements,
and objects.
Input and output are performed by
dialog boxes
that pop up and are dismissed.
View.OnClickListener
in
Listener.
Toast
on the Android screen.TextView
on the Android screen.adb logcat
command on your Mac or PC.
Direct the standard output into a pipe or a file.
Activity
object.
.zip
file.
.zip
file.grep
,
awk
,
find
,
etc.)
on your Android emulator or device.
Install an
event
listener
into a
View
.
This is the most important topic of the course.
View.OnClickListener
can be installed into a
Button
or into any other type of
View
.
The
View.OnClickListener
has a method named
onClick
.
Composition vs. inheritance.View.OnKeyListener
can be installed into an
EditText
.
The
View.OnKeyListener
has a method named
onKey
.SeekBar.OnSeekBarChangeListener
can be installed into a
SeekBar
(slider).
The
SeekBar.OnSeekBarChangeListener
has a method named
onProgressChanged
.
SeekBar
.
DatePicker.OnDateChangedListener
can be installed into a
DatePicker
.
The
DatePicker.OnDateChangedListener
has a method named
onDateChanged
.
If you want the same interface each time you run the app,
create it with an
activity_main.xml
file.
If the interface might be different during each run,
create it with executable Java code containing
if
statements and other conditionals.
RelativeLayout
and
Button
as the
activity_main.xml
file of the
Click Listener
example.
Draw the graphics in a subclass of class
View
containing a constructor and an
onDraw
method.
View
,
and an object of that class.
Canvas
argument passed to
onDraw
:
drawColor
,
drawCircle
,
drawRect
,
drawPoint
,
drawLine
.Path
containing a series of points connected by straight lines:
moveTo
and
lineTo
.
Needed because
Canvas
has no methods for drawing triangles, pentagons, houses, etc.
translate
,
scale
,
rotate
,
skew
.
WebView
object.
The following pictures redraw themselves when you touch the screen.
See the
invalidate
method of class
View
.
View.OnTouchListener
and its method
onTouch
.
Uses the
Path
we saw in the triangle in
Japan.
Erases itself when the activity’s configuration
(e.g., orientation) changes;
see
Configuration
Changes.
Make the graphics move under their own power, without having to be dragged with a finger. See Animation and Graphics.
Animation
object such as
TranslateAnimation
(added in API 1)
can smoothly change the position at which a
View
is displayed,
but it has no effect on the
View
itself and its fields.
This type of animation has been superseded by
ViewPropertyAnimator,
is applicable
only to an object of class
View
and only to certain of its properties:
alpha, translate, scale, and rotate.
See
View
Animation.
ViewPropertyAnimator
(added in API 12)
is the fastest and simplest way to smoothly change a field of a
View
object.
This type of animation is applicable
only to an object of class
View
and only to certain of its properties:
alpha, translate, scale, rotate, x, y, and z.
See
Animating
with ViewPropertyAnimator.
ViewPropertyAnimator
.
ViewPropertyAnimator
.
Activity
s.
The
Activity
in this app uses two
ViewPropertyAnimator
s.
ObjectAnimator
(added in API 11)
can smoothly change any field of any object,
including objects that are not
View
s
and fields of any data type.
Unlike an
Animation
,
a
ObjectAnimator
actually changes the object’s fields,
not merely its appearance on the screen.
See
Animating
with ObjectAnimator.
ObjectAnimator
to animate the top
padding
property of a
View
.
post
to update the user interface in the main thread.
Implement an animation by having a separate
thread
call
postInvalidate
(instead of plain old
invalidate
)
over and over to trigger calls to the
the
onDraw
method of the
View
.
A
View
is touch-sensitive because we plugged a
touch
listener
into it.
The touch listener can store information about each touch into a
gesture
detector
object.
When the gesture detector feels it has received all the information
necessary to constitute a gesture,
it calls one of the methods of the
gesture
listener
plugged into the gesture detector.
See
Gestures
and
Detecting
Common Gestures.
A data item is a number, string, image, etc.
We can display one or more data items in a
View
by calling the
drawText
or
drawBitmap
methods of the
Canvas
passed to the
onDraw
method of the
View
;
see
America
for an example.
In this section,
however,
we will display each data item in its own
View
.
An
Adapter
takes a series of data items
and encases each one in a
View
.
The simplest example of an
Adapter
is an
ArrayAdapter
,
which gets its data items from a Java array.
An
Adapter
creates
View
s,
but does not actually display them on the screen.
To display the
View
s
we plug the
Adapter
into an
AdapterView
,
which is a big
View
that can display smaller
View
s
inside it.
In other words, an
AdapterView
is an example of
ViewGroup
.
In more other words,
class
AdapterView
is a subclass of class
ViewGroup
.
See
Building
Layouts with an Adapter.
AdapterView
is a
Spinner
(dropdown menu).
The
Adapter
we plug into this
Spinner
is an
ArrayAdapter
.
ListView
is another example of an
AdapterView
.
ArrayAdapter
here,
so we’ll have to
build our own implementation of interface
Adapter
.
GridView
is another type of
AdapterView
.
We’ll have to make our own implementation of the
Adapter
interface.
SimpleCursorAdapter
can write an image into an
ImageView
as easily as it can write text into a
TextView
.
sqlite3
command line shell.
ListView
and
Dialog
s.
Cursor
.
The
Cursor
comes from a
CursorLoader
running under the control of the
LoaderManager
.
Cursor
into an
Adapter
;
plug the
Adapter
into an
AdapterView
.
Our
AdapterView
is a
SimpleCursorAdapter
and our
AdapterView
is a
ListView
.
GridView
of real estate offers read from an SQLite database.
https://maps.googleapis.com/maps/api/geocode/json?address=7+East+12th+Street,+New+York,+NY+10003
GridView
.
Use an
Intent
object to launch an
Activity
belonging to another app.
See
Starting
Another Activity.
The main thread must never attempt a job that takes more than five seconds.
For longer jobs,
the main thread must create a worker thread.
But only the main thread can access the user interface.
See
Threads-threaded.
See
Offer
for threads with
Runnable
,
Thread
,
Handler
,
and
AsyncTask
.
See
MediaPlayer
for
AsyncTask
with
publishProgress
and
onPublishProgress
.
Runnable
and
Thread
.
postDelayed
Handler
.
Examples:
animation,
time picker.
AsyncTask
.
See
How to Avoid
ANRs.
Example.VideoView
object.
MediaRecorder
and save the file in the Music folder.
Activity
play music using a
MediaPlayer
.
The music starts playing from the beginning when the
Activity
is destroyed and recreated by a
change
of orientation.
MediaPlayer
,
but now run by a
Service
instead of by the
Activity.
The music reliably keeps playing even after the
Activity
is destroyed.
Service
is executed by a separate thread.
MapView
using the
Google
Maps Android API version 2.
WebView
using the
Google
Maps Android JavaScript API v3.
Marker
there with a
label
and
Infowindow
.