mark.meretzky@nyu.edu
)
the differences between the PC and Mac installations.
Create a free
GitHub account
and email me its name.
Look
here
to see your classmates’ GitHub accounts.
Study
XML.
Run
Hello
and do the exercises, but don’t hand them in.
Look at the flowchart diagram of the Activity lifecycle
in the documentation for class
Activity
.
To try out the
Java examples,
create the
Hello
project.
It already has a
TextView
in its
activity_main.xml
file:
<TextView android:text="@string/hello_world" android:layout_width="wrap_content" android:layout_height="wrap_content" />Give the
TextView
an
id
number, as in exercise 9 of
Hello.
<TextView android:id="@+id/textView" android:text="@string/hello_world" android:layout_width="wrap_content" android:layout_height="wrap_content" />The Hello project also has a method named
onCreate
in its
MainActivity.java
file:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); }Let’s say we wanted to see the output of the Java example
For2.java
on the screen of the Android emulator.
Give
onCreate
the following extra statements immediately after the
setContentView
statement.
The expression originally written in the parentheses after
System.out.println
in
For2.java
should be written in the parentheses after
String.valueOf
.
The
+ "\n"
moves us down to the start of the next line;
you can omit it if you don’t want to move down.
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Get our hands on the TextView in the activity_main.xml file. TextView textView = (TextView)findViewById(R.id.textView); //Erase the existing text in the TextView, if any. textView.setText(""); for (int i = 1; i <= 10; i = i + 1) { textView.append(String.valueOf(i) + "\n"); } }
TextView
object in an Andoid app;
see the above homework for February 7.
We saw Java code that got integer input from an
EditText
object in an Android app;
see
Bed.
We got up to
ReturnValue.java
in
these Java examples.
Write an Android app that does input and output,
but don’t hand it in.
Run it on an
Android device
as well as on the Genymotion emulator.
Button
,
and a
key listener
plugged into an
EditText
.
Here is the
Date.java
file we created in class on February 21.
res/menu/menu_main.xml
file of the project and the
onCreateOptionsMenu
and
onOptionsItemSelected
methods of class
Activity
.
For example,
here is the
res/menu/menu_main.xml
file containing one
<item>
element
from
Hello;
see
Menu
Resource.
In Touch, the code to create the circle in the center of the big white view is now in exercise #2.
I updated and debugged Manhattan. It was the same bug that prevented Japan’s drop shadow from working: we have to turn off hardware acceleration in the newer versions of Android.
On February 28th I asked you to write an app and upload it to your GitHub account. On March 14th, we’ll look at these apps in class. Take a peek at them now.
WebView
object to draw text and graphics that can be displayed on Android and
Apple iOS,
and to download files from the Web.
Graphics examples:
Etch,
etc.
The three animation examples have been debugged:
Animation,
ObjectAnimator,
and
ViewPropertyAnimator.
We did gesture recognition:
Tap,
Fling,
Pinch.
We uploaded two student apps,
CornerDot
(with two
Spinner
s)
and
Touch
(with multiple copies of Patton)
to GitHub.
Play with
ApiDemos
on your simulator,
and try to install it on your Android device.
Read the source code of ApiDemos on GitHub.
For example, the demonstration
App → Activity → HelloWorld
is in the files
HelloWorld.java
,
hello_world.xml
,
and
strings.xml
.
Note that the string resource named
hello_world
at line 36 of
strings.xml
.
contains the HTML tags
<b>
(bold)
and
<i>
(italic).
Is there anything I need to add to the installation instructions for Microsoft Windows 7 or 8 and/or HAXM? Thanks.
Write another Android app (or work on the one you already have)
and upload it to your GitHub account by 9:00 am on March 28th.
Look at
the other
students’ apps.
Please email me
(mark.meretzky@nyu.edu
)
your name and the name of your GitHub account
if I don’t already have it.
No class March 21 (Spring Break).
Write and upload to your GitHub account an interesting app that we can look
at in-class on April 4th.
For example, an app that displays
“face up”
or
“face down”
to tell you if the Android device is lying face up or face down.
(The app will detect g-forces along the Z axis.
You will use the third value in the
A HREF =
"http://developer.android.com/reference/android/hardware/SensorEvent.html#values">values
array.
See the comment in the third box in exercise 4c in
Pearl.)
Or an app that displays a motion picture made of frames as in
Phase.
How about the 45 frames of the first motion picture,
Fred
Ott’s Sneeze?
Or the Zapruder film, for you assasination buffs?
Or an app that’s a two-player game
(exercise 6 of
Pong)?
Or a one-person game?
Or something with a
Spinner
or a
ListView?
PLay with
each other’s apps.
Read some of the ApiDemos demonstrations: the notorious list of 500 cheeses in ListView (easy reading), and the bouncing balls that squash against the floor in ObjectAnimator (hard reading).
On March 28, we looked at a
project
that displayed a menu whose items contained icons for the sun and moon.
In the current version of Android,
a menu item icon is displayed
only when the menu item is displayed in the form of an icon in the action bar.
To see both icons in the action bar,
change the project’s
menu_main.xml
file to the following.
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity" > <item android:id="@+id/action_settings" android:title="@string/action_settings" android:icon="@drawable/sunny" app:showAsAction="always" /> <item android:id="@+id/exit_the_app" android:title="@string/options_exit_text" android:icon="@drawable/night" app:showAsAction="always" /> </menu>
adb shell
command we saw in
Cursor
to run
sqlite3
on your emulator or device.
Use
adb pull
to copy a
.db
file from your emulator or device to the Desktop of your Mac or PC,
and then use
sqlite3
to examine that file.
Review our three examples of dialog boxes:
EditText
in the
dialog.xml
file and the
getDouble
method in the
MainActivity.java
file of
Testbed.
The
EditText
has a listener that listens for the
ENTER
key.
The dialog does not have an OK button.
displayString
method in the
MainActivity.java
file of
Testbed.
The OK button does have a listener.
Add a few contacts to your emulator or device if you have not already done so. Then write and upload an app that adds two features to the Sqlite app.
EditText
asking for the name in the new row.
EditText
will have a listener that
listens for the
ENTER
key and appends the new row.
The dialog will not have an OK button.
menu_main.xml
for
“Append a new row”
and
“Delete all rows”.
Add a menu entry for “Update a row”.
It will pop up a dialog that asks for the id number of a row and the new name
that will go in that row,
overwriting the old name.
I would be delighted if you added even more features, or wrote an additional app involving accelerometers, animation, the beeping sound in the Pong exercise, etc.
On April 11th, we’ll have brief in-class oral reports on exercises 4 and 5 of Cursor. How can we list the browser bookmarks and browsing history separately? How can we get a list of all the databases created by Android, either in the documentation or via executable code? My thanks to the volunteers.
I understand that what you want me to create from scratch for you in class
on April 11th is an app with a
GridView
displaying two columns in portrait orientation,
three columns in landscape orientation.
Each item in the
GridView
should be a
LinearLayout
whose
orientation
is vertical in portrait,
horizontal in landscape.
Each
LinearLayout
represents an “offer”
and will contain two
TextView
s
named
title
and
description
.
The text in the
TextView
should come from a table in an SQLite database file.
The database file could be stored inside the app as we did in
Cursor.
But I understand that you would be delighted if the file was downloaded
by the app from a server, such as the Solaris Unix server
i5.nyu.edu
where this course is hosted.
offers.db
file in the project’s assets folder,
and (in exercise #7)
it even reads correctly from an SQLite
offers.db
that the app downloads from a server while the app is running.
For an outline of what went wrong,
see the paragraph I added on April 15th to my
Stack
Overflow post.
As usual, you should play with and read about the stuff we did in class.
In
Offer,
we saw pairs of
.xml
resource files for
-port
and
-land
,
so you should read Android’s documentation about
Providing
Alternative Resources.
And in
Cursor
and
Sqlite,
we used the
adb
shell
command to examine the directories and files inside the Android emulator
or device, and to run
sqlite3
inside the emulator or device.
Again, as usual, you should write a simple but interesting app
and upload it to your GitHub account.
i5.nyu.edu
).
The server consisted of
sqlite3
and a little “glue” program written in the language Perl.
Do exercise #2 of MediaPlayer. You’ll be appalled that the visble behavior (or at least the audible behavior) of the app depends on the vagaries of the Java garbage collector! As usual, write and upload a simple but interesting app. A Scratch demo is coming!
ActionBarActivity
has been deprecated.
Your class
ActivityMain
should now extend
AppCompatActivity
instead of
ActionBarActivity
.
I’m tempted to say that
Oceania
is now at war with
Eurasia,
not
Eastasia.
In Android Studio,
Tools → Android → SDK Manager
and download all the new stuff it recommends.
When you create a new project,
the
ActionBarActivity
in
ActivityMain
should now be striken through because it is deprecated.
Replace it with
AppCompatActivity
.
As usual, write an app (maybe with a
Service
playing background music this week?)
and upload it to GitHub.
Thanks.
I was impressed by the succes of our group effort on May 9th,
so I’m going to propose another one for May 16th.
I acquired a Samsung Galaxy SII phone
(model number SPH-D710,
Android version 4.0.4,
hardware version D710.10,
baseband version S:D710.10 S.FL24),
with Google Play services so we could run the
MapView
in
MapView.
I see the Play Store icon that looks like a briefcase.
But when I connect the phone with a USB cable
to my OS X Yosemite 10.10.3 Macintosh,
the Mac doesn’t notice the phone.
For example,
adb devices
does not list the phone.
Neither does the Mac application “System Information”
in the Utilities subfolder of the Applications folder.
(I selected Hardware → USB
and pulled down File → Refresh Information.)
What do I have to do to make the Samsung show up in
adb devices
?