8 Ball with a ViewPropertyAnimator

Ask the 8 Ball a question and tap the screen. Then do it again.

The action bar of the MarkActivity has a left arrow leading to the MainActivity because we said that the MainActivity was the hierarchical parent of the MarkActivity when we created the MarkActivity. See Navigation with Back and Up and Navigating Up with the App Icon.

Source code in Jul11.zip

  1. MainActivity.java. The ListView has an AdapterView.OnItemClickListener.
  2. activity_main.xml
  3. MarkActivity.java. The dark blue RelativeLayout has a View.OnTouchListener which feeds a GestureDetector that detects a single tap.
  4. activity_mark.xml
  5. strings.xml contains a string array resource used by the ListView’s ArrayAdapter<CharSequence>. I changed the app_name to Jul11 Mark.
  6. AndroidManifest.xml contains an <activity> element for each Activity class.
  7. build.gradle (Module: app)

Create the project

Follow the instructions in Collective for creating the second activity.

Things to try

  1. Replace the Java array of Strings in MarkActivity with the following string array resource in strings.xml.
        <string-array name="answers_array">
            <item>It is certain.</item>
            <item>It is decidedly so.</item>
            <item>Without a doubt.</item>
            <item>Yes, definitely.</item>
            <item>You may rely on it.</item>
            <item>As I see it, yes.</item>
            <item>Most likely.</item>
            <item>Outlook good.</item>
            <item>Yes.</item>
            <item>Signs point to yes.</item>
            <item>Reply hazy. Try again.</item>
            <item>Ask again later.</item>
            <item>Better not tell you now.</item>
            <item>Cannot predict now.</item>
            <item>Concentrate and ask again.</item>
            <item>Don\u2019t count on it.</item> <!-- Unicode apostrophe -->
            <item>My reply is no.</item>
            <item>My sources say no.</item>
            <item>Outlook not so good.</item>
            <item>Very doubtful.</item>
        </string-array>
    
    Change the answers field of class MarkActivity to the following.
        private static String[] answers;
    
    Initialize answers in the onCreate method of class MarkActivity after the setContentView.
            Resources resources = getResources();
            answers = resources.getStringArray(R.array.answers_array);
    

  2. A regular icosahedron is a polyhedron whose 20 sides are equilateral triangles. In the 8 Ball, the 20 answers were printed on the 20 faces of a regular icosahedron. An answer would float to the surface in the middle of an equilateral triangle, rotated at an unpredictable angle. Can you program this?