Flag Quiz App - KSU Web Home

Download Report

Transcript Flag Quiz App - KSU Web Home

Flag Quiz App
1
CS7030: Mobile App Development
assets Folder

drawable folder

Image contents at the root level
assets folder
–
–
–

AssetManager open an InputStream to read image file name; next
create a Drawable object from the stream; finally display the object
on an ImageView using setImageDrawable method
–
2
Images can be organized in subfolders
Accessed via AssetManager
InputStream stream = assets.open(region + "/“ +
nextImageName +".png");
Drawable flag =
Drawable.createFromStream(stream,nextImageName);
flagImageView.setImageDrawable(flag);
CS7030: Mobile App Development
String Resource


3
strings.xml
–
Create string array
–
<string-array name="regionsList">
<item>Africa</item>
<item>Asia</item>
<item>Europe</item>
<item>North_America</item>
<item>Oceania</item>
<item>South_America</item>
</string-array>
getResources().getStringArray(R.array.
regionsList);
CS7030: Mobile App Development
Animation Category
Tweened Animations
1.
–
–
–
–
2.

4
Scale animations (resize)
Rotate animations
Alpha animations (transparency)
Translate animations (move)
Frame-by-Frame Animations
An animation set may contain any
combination of tweened animations
CS7030: Mobile App Development
Animation xml file
<set
mlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator">
<translate
android:fromXDelta="0" android:toXDelta="-5%p"
android:duration="100"/>
<translate
android:fromXDelta="-5%p" android:toXDelta="5%p"
android:duration="100" android:startOffset="100"/>
<translate
android:fromXDelta="5%p" android:toXDelta="-5%p"
android:duration="100" android:startOffset="200"/>
</set>
5
CS7030: Mobile App Development
Attributes of Animations

fromXDelta: the view’s offset when the animation starts
toXDelta: the view’s offset when the animation ends

These attributes can have

–
–
–
–
–


6
Absolute values (in pixels)
A percentage of the animated View’s size
A percentage of the animated View’s parent’s size
-5%p indicates the View move to the left by 5% of the parent’s width
5% indicates the View move to the right by 5% of the View’s width
duration: how long the animation lasts in milliseconds
startOffset: the number of milliseconds into the future at
which an animation should begin
CS7030: Mobile App Development
Load Tweened Animations


Create a folder called anim under res folder
Create new xml files in the anim folder. Add a set tag in the xml files:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator">
</set>

Add rotate, alpha, scale, or translate tag in the set tag.

Use AnimationUtils.loadAnimation to load the xml file, and
then create an object of Animation
–

startAnimation
–
7
shakeAnimation = AnimationUtils.loadAnimation(this,
R.anim.incorrect_shake);
flagImageView.startAnimation(shakeAnimation);
CS7030: Mobile App Development
Handler

postDelayed receives Runnable as arguments to
execute and a delay in milliseconds

Each Handler instance is associated with a single
thread and that thread's message queue.
There are two main uses for a Handler:

–
–
8
to schedule messages and runnables to be
executed as some point in the future
to enqueue an action to be performed on a different
thread than your own.
CS7030: Mobile App Development