In the
onDraw
method of
AmericaView,
the
Path
draws the star even though the
Path
crosses itself.
radius
is a
float
because the argument of
scale
is
float.
x
and
y
are
floats
because the arguments of
moveTo
and
lineTo
are
floats.
MainActivity.javaAmericaView.javaR.java
activity_main.xml:
unused and ignored.
AndroidManifest.xmlbuild.gradle
(Module: app)
patton.png
(104 × 205 pixels)
In the Android Studio
project
view,
select the folder
app/java/edu.nyu.scps.america.
It already holds the file
MainActivity.java.
File →
New →
UI Component →
Custom View
View Class: AmericaView
Finish
Put the file
patton.png
on your Desktop.
Control-click on it and select Copy “patton.png”.
Control-click on the
app/res/drawable
folder in the
res
folder in the Android Studio
project
view
and select Paste.
Copy
Copy file /Users/myname/Desktop/patton.png
New name: patton.png
To directory: /Users/myname/AndroidStudioProjects/America/app/src/main/res/drawable
OK
You should now see
patton.png
in the Android Studio
project
view.
See
Bitmap
under
Drawable
Resources.
translate?
canvas.save(); for (int i = 0; i < 7; ++i) { //left, top, right, bottom canvas.drawRect(0, 0, stripeWidth, height, paint); canvas.translate(2 * stripeWidth, 0); } canvas.restore();
patton.png
is 104 × 205 pixels.
Use a piece of
Toast
to verify that the
BitMap
object is 312 × 615 pixels
(thrice the original),
at least on Genymotion simulating the Samsung Galaxy S5.
Call
getContext
to get the first argument for
makeToast.
Recall that
Text
showed there were three pixels per
dp.
See
Puzzle
to get the dimensions of the originl image file.