am 195c4388: Fixing bugs in the LLand.

* commit '195c438883dfcca799aa456dfe52d24c077e40da':
  Fixing bugs in the LLand.
diff --git a/packages/SystemUI/res/drawable/pop_ball.xml b/packages/SystemUI/res/drawable/pop_ball.xml
new file mode 100644
index 0000000..ee1220f
--- /dev/null
+++ b/packages/SystemUI/res/drawable/pop_ball.xml
@@ -0,0 +1,29 @@
+<!--
+Copyright (C) 2014 The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="100.0dp"
+        android:height="100.0dp"
+        android:viewportWidth="100.0"
+        android:viewportHeight="100.0">
+    <path
+        android:pathData="M0,50 a50,50 0 1 1 100,0
+                                a50,50 0 1 1 -100,0"
+        android:fillColor="#FFFF1744"/>
+    <path
+        android:pathData="M16,36 A24,24 0 1 1 64,36
+                          M64,36 A24,24 0 1 1 16,36"
+        android:fillColor="#20FFFFFF"/>
+</vector>
diff --git a/packages/SystemUI/res/drawable/pop_belt.xml b/packages/SystemUI/res/drawable/pop_belt.xml
index 5c0c3d7..e0ea575 100644
--- a/packages/SystemUI/res/drawable/pop_belt.xml
+++ b/packages/SystemUI/res/drawable/pop_belt.xml
@@ -20,14 +20,14 @@
         android:viewportHeight="100.0">
     <path
         android:pathData="M50.000000,50.000000m-47.599998,0.000000a47.599998,47.599998 0.000000,1.000000 1.000000,95.199997 0.000000a47.599998,47.599998 0.000000,1.000000 1.000000,-95.199997 0.000000"
-        android:fillColor="#D81B60"/>
+        android:fillColor="#9C27B0"/>
     <path
         android:pathData="M50.000000,2.429000c-26.337999,0.000000 -47.688999,21.351000 -47.688999,47.688999c0.000000,13.168000 5.337000,25.091000 13.968000,33.722000l67.444000,-67.443001C75.092003,7.766000 63.168999,2.429000 50.000000,2.429000z"
-        android:fillColor="#F06292"/>
+        android:fillColor="#BA68C8"/>
     <path
         android:pathData="M0.000000,41.573002l100.000000,0.000000l0.000000,17.090000l-100.000000,0.000000z"
-        android:fillColor="#D81B60"/>
+        android:fillColor="#9C27B0"/>
     <path
         android:pathData="M0.000000,58.662998l0.000000,-17.089996 100.000000,0.000000z"
-        android:fillColor="#F06292"/>
+        android:fillColor="#BA68C8"/>
 </vector>
diff --git a/packages/SystemUI/res/drawable/pop_pizza.xml b/packages/SystemUI/res/drawable/pop_pizza.xml
index b6d2bb3..1806b5a 100644
--- a/packages/SystemUI/res/drawable/pop_pizza.xml
+++ b/packages/SystemUI/res/drawable/pop_pizza.xml
@@ -20,26 +20,26 @@
         android:viewportHeight="100.0">
     <path
         android:pathData="M14.645000,14.645000C5.597000,23.693001 0.000000,36.193001 0.000000,50.000000l50.000000,0.000000L14.645000,14.645000z"
-        android:fillColor="#7BAAF7"/>
+        android:fillColor="#2979FF"/>
     <path
         android:pathData="M100.000000,50.000000c0.000000,-13.807000 -5.597000,-26.306999 -14.645000,-35.355000L50.000000,50.000000L100.000000,50.000000z"
-        android:fillColor="#D81B60"/>
+        android:fillColor="#FF1744"/>
     <path
         android:pathData="M85.355003,14.645000C76.306999,5.597000 63.806999,0.000000 50.000000,0.000000l0.000000,50.000000L85.355003,14.645000z"
-        android:fillColor="#F06292"/>
+        android:fillColor="#0F9D58"/>
     <path
         android:pathData="M50.000000,0.000000C36.193001,0.000000 23.693001,5.597000 14.645000,14.645000L50.000000,50.000000L50.000000,0.000000z"
-        android:fillColor="#FFF176"/>
+        android:fillColor="#FFBC00"/>
     <path
         android:pathData="M50.000000,50.000000l35.355000,35.355000C94.403000,76.307999 100.000000,63.807999 100.000000,50.000000L50.000000,50.000000z"
-        android:fillColor="#7BAAF7"/>
+        android:fillColor="#2979FF"/>
     <path
         android:pathData="M50.000000,100.000000c13.807000,0.000000 26.306999,-5.596000 35.355000,-14.645000L50.000000,50.000000L50.000000,100.000000z"
-        android:fillColor="#FFF176"/>
+        android:fillColor="#FFBC00"/>
     <path
         android:pathData="M14.645000,85.355003C23.693001,94.403999 36.193001,100.000000 50.000000,100.000000L50.000000,50.000000L14.645000,85.355003z"
-        android:fillColor="#F06292"/>
+        android:fillColor="#0F9D58"/>
     <path
         android:pathData="M0.000000,50.000000c0.000000,13.808000 5.597000,26.308001 14.645000,35.355000L50.000000,50.000000L0.000000,50.000000z"
-        android:fillColor="#D81B60"/>
+        android:fillColor="#FF1744"/>
 </vector>
diff --git a/packages/SystemUI/res/drawable/pop_swirl.xml b/packages/SystemUI/res/drawable/pop_swirl.xml
index acd6d3d..f87569b 100644
--- a/packages/SystemUI/res/drawable/pop_swirl.xml
+++ b/packages/SystemUI/res/drawable/pop_swirl.xml
@@ -20,7 +20,7 @@
         android:viewportHeight="100.0">
     <path
         android:pathData="M50.000000,50.000000C86.898003,27.834999 79.244003,11.688000 76.177002,7.399000c-7.240000,-4.459000 -15.703000,-7.112000 -24.770000,-7.363000C56.247002,2.253000 70.815002,12.456000 50.000000,50.000000z"
-        android:fillColor="#82B1FF"/>
+        android:fillColor="#FFFFFA"/>
     <path
         android:pathData="M50.000000,50.000000c20.815001,-37.543999 6.247000,-47.747002 1.407000,-49.964001C50.938000,0.022000 50.472000,0.000000 50.000000,0.000000c-8.627000,0.000000 -16.743999,2.186000 -23.827000,6.032000C31.392000,5.514000 49.251999,6.903000 50.000000,50.000000z"
         android:fillColor="#76FF03"/>
@@ -32,7 +32,7 @@
         android:fillColor="#303F9F"/>
     <path
         android:pathData="M50.000000,50.000000C27.834000,13.103000 11.687000,20.757000 7.398000,23.823999C2.940000,31.063000 0.287000,39.527000 0.035000,48.592999C2.253000,43.752998 12.456000,29.184999 50.000000,50.000000z"
-        android:fillColor="#FAFAFA"/>
+        android:fillColor="#FFFFFA"/>
     <path
         android:pathData="M50.000000,50.000000C49.251999,6.903000 31.392000,5.514000 26.173000,6.032000c-7.709000,4.187000 -14.188000,10.344000 -18.774000,17.792000C11.687000,20.757000 27.834000,13.103000 50.000000,50.000000z"
         android:fillColor="#303F9F"/>
@@ -44,13 +44,13 @@
         android:fillColor="#303F9F"/>
     <path
         android:pathData="M50.000000,50.000000c22.166000,36.897999 38.313000,29.243999 42.602001,26.177999c4.458000,-7.240000 7.111000,-15.703000 7.363000,-24.770000C97.747002,56.248001 87.543999,70.816002 50.000000,50.000000z"
-        android:fillColor="#FAFAFA"/>
+        android:fillColor="#FFFFFA"/>
     <path
         android:pathData="M50.000000,50.000000c-20.815001,37.544998 -6.247000,47.748001 -1.407000,49.965000C49.062000,99.978996 49.528000,100.000000 50.000000,100.000000c8.627000,0.000000 16.743999,-2.185000 23.827000,-6.031000C68.608002,94.486000 50.748001,93.098000 50.000000,50.000000z"
         android:fillColor="#76FF03"/>
     <path
         android:pathData="M50.000000,50.000000C13.103000,72.166000 20.757000,88.313004 23.823000,92.601997c7.240000,4.459000 15.703000,7.112000 24.770000,7.363000C43.752998,97.748001 29.184999,87.544998 50.000000,50.000000z"
-        android:fillColor="#82B1FF"/>
+        android:fillColor="#FFFFFA"/>
     <path
         android:pathData="M50.000000,50.000000C6.902000,50.749001 5.514000,68.609001 6.032000,73.828003c4.186000,7.708000 10.344000,14.188000 17.791000,18.773001C20.757000,88.313004 13.103000,72.166000 50.000000,50.000000z"
         android:fillColor="#303F9F"/>
diff --git a/packages/SystemUI/res/drawable/pop_vortex.xml b/packages/SystemUI/res/drawable/pop_vortex.xml
index faefcb1..2380e68 100644
--- a/packages/SystemUI/res/drawable/pop_vortex.xml
+++ b/packages/SystemUI/res/drawable/pop_vortex.xml
@@ -20,7 +20,7 @@
         android:viewportHeight="100.0">
     <path
         android:pathData="M50.000000,50.000000m-50.000000,0.000000a50.000000,50.000000 0.000000,1.000000 1.000000,100.000000 0.000000a50.000000,50.000000 0.000000,1.000000 1.000000,-100.000000 0.000000"
-        android:fillColor="#FFF176"/>
+        android:fillColor="#F8F8FF"/>
     <path
         android:pathData="M58.658001,89.648003c-19.330000,0.000000 -35.000000,-15.670000 -35.000000,-35.000000c0.000000,-13.531000 10.969000,-24.500000 24.500000,-24.500000c9.472000,0.000000 17.150000,7.679000 17.150000,17.150000c0.000000,6.631000 -5.375000,12.006000 -12.006000,12.006000c-3.798000,0.000000 -7.004000,-2.522000 -8.045000,-5.982000c1.021000,1.136000 2.497000,1.854000 4.145000,1.854000c2.644000,0.000000 4.853000,-1.841000 5.428000,-4.310000c0.175000,-0.558000 0.271000,-1.150000 0.271000,-1.766000c0.000000,-4.642000 -3.763000,-8.404000 -8.403000,-8.404000c-6.631000,0.000000 -12.006000,5.375000 -12.006000,12.006000c0.000000,9.472000 7.679000,17.149000 17.150000,17.149000c13.531000,0.000000 24.500000,-10.969000 24.500000,-24.500000c0.000000,-19.330000 -15.670000,-35.000000 -35.000000,-35.000000c-12.963000,0.000000 -24.773001,4.935000 -33.657001,13.025000C2.824000,31.087000 0.000000,40.212002 0.000000,50.000000c0.000000,27.615000 22.386000,50.000000 50.000000,50.000000c17.825001,0.000000 33.462002,-9.335000 42.313999,-23.375999C83.431000,84.714996 71.621002,89.648003 58.658001,89.648003z"
         android:fillColor="#7BAAF7"/>
diff --git a/packages/SystemUI/res/values/lland_config.xml b/packages/SystemUI/res/values/lland_config.xml
index 5d74082..a9e732e 100644
--- a/packages/SystemUI/res/values/lland_config.xml
+++ b/packages/SystemUI/res/values/lland_config.xml
@@ -26,7 +26,7 @@
     <dimen name="obstacle_width">90dp</dimen>
     <dimen name="obstacle_stem_width">12dp</dimen>
     <dimen name="obstacle_gap">170dp</dimen>
-    <dimen name="obstacle_height_min">40dp</dimen>
+    <dimen name="obstacle_height_min">48dp</dimen>
     <dimen name="building_width_min">20dp</dimen>
     <dimen name="building_width_max">250dp</dimen>
     <dimen name="building_height_min">20dp</dimen>
diff --git a/packages/SystemUI/src/com/android/systemui/egg/LLand.java b/packages/SystemUI/src/com/android/systemui/egg/LLand.java
index cdfe6e5..5de09a3 100644
--- a/packages/SystemUI/src/com/android/systemui/egg/LLand.java
+++ b/packages/SystemUI/src/com/android/systemui/egg/LLand.java
@@ -29,11 +29,15 @@
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.GradientDrawable;
+import android.media.AudioAttributes;
+import android.media.AudioManager;
+import android.os.Vibrator;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.view.Gravity;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
+import android.util.Slog;
 import android.view.View;
 import android.view.ViewOutlineProvider;
 import android.view.animation.DecelerateInterpolator;
@@ -51,9 +55,9 @@
     public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
     public static final boolean DEBUG_DRAW = false; // DEBUG
 
-    public static final void L(String s, Object ... objects) {
+    public static void L(String s, Object ... objects) {
         if (DEBUG) {
-            Log.d(TAG, String.format(s, objects));
+            Slog.d(TAG, objects.length == 0 ? s : String.format(s, objects));
         }
     }
 
@@ -61,17 +65,18 @@
     public static final boolean HAVE_STARS = true;
 
     public static final float DEBUG_SPEED_MULTIPLIER = 1f; // 0.1f;
-    public static final boolean DEBUG_IDDQD = false;
+    public static final boolean DEBUG_IDDQD = Log.isLoggable(TAG + ".iddqd", Log.DEBUG);
 
     final static int[] POPS = {
-            // resid                // spinny!
-            R.drawable.pop_belt,    0,
-            R.drawable.pop_droid,   0,
-            R.drawable.pop_pizza,   1,
-            R.drawable.pop_stripes, 0,
-            R.drawable.pop_swirl,   1,
-            R.drawable.pop_vortex,  1,
-            R.drawable.pop_vortex2, 1,
+            // resid                // spinny!  // alpha
+            R.drawable.pop_belt,    0,          255,
+            R.drawable.pop_droid,   0,          255,
+            R.drawable.pop_pizza,   1,          255,
+            R.drawable.pop_stripes, 0,          255,
+            R.drawable.pop_swirl,   1,          255,
+            R.drawable.pop_vortex,  1,          255,
+            R.drawable.pop_vortex2, 1,          255,
+            R.drawable.pop_ball,    0,          190,
     };
 
     private static class Params {
@@ -117,10 +122,20 @@
             PLAYER_Z = res.getDimensionPixelSize(R.dimen.player_z);
             PLAYER_Z_BOOST = res.getDimensionPixelSize(R.dimen.player_z_boost);
             HUD_Z = res.getDimensionPixelSize(R.dimen.hud_z);
+
+            // Sanity checking
+            if (OBSTACLE_MIN <= OBSTACLE_WIDTH / 2) {
+                Slog.e(TAG, "error: obstacles might be too short, adjusting");
+                OBSTACLE_MIN = OBSTACLE_WIDTH / 2 + 1;
+            }
         }
     }
 
     private TimeAnimator mAnim;
+    private Vibrator mVibrator;
+    private AudioManager mAudioManager;
+    private final AudioAttributes mAudioAttrs = new AudioAttributes.Builder()
+            .setUsage(AudioAttributes.USAGE_GAME).build();
 
     private TextView mScoreField;
     private View mSplash;
@@ -158,6 +173,8 @@
 
     public LLand(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
+        mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
+        mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
         setFocusable(true);
         PARAMS = new Params(getResources());
         mTimeOfDay = irand(0, SKIES.length);
@@ -198,7 +215,15 @@
 
     final float hsv[] = {0, 0, 0};
 
-    private void reset() {
+    private void thump() {
+        if (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
+            // No interruptions. Not even game haptics.
+            return;
+        }
+        mVibrator.vibrate(80, mAudioAttrs);
+    }
+
+    public void reset() {
         L("reset");
         final Drawable sky = new GradientDrawable(
                 GradientDrawable.Orientation.BOTTOM_TOP,
@@ -313,14 +338,16 @@
 
     private void setScore(int score) {
         mScore = score;
-        if (mScoreField != null) mScoreField.setText(String.valueOf(score));
+        if (mScoreField != null) {
+            mScoreField.setText(DEBUG_IDDQD ? "??" : String.valueOf(score));
+        }
     }
 
     private void addScore(int incr) {
         setScore(mScore + incr);
     }
 
-    private void start(boolean startPlaying) {
+    public void start(boolean startPlaying) {
         L("start(startPlaying=%s)", startPlaying?"true":"false");
         if (startPlaying) {
             mPlaying = true;
@@ -352,7 +379,7 @@
         }
     }
 
-    private void stop() {
+    public void stop() {
         if (mAnimating) {
             mAnim.cancel();
             mAnim = null;
@@ -417,8 +444,10 @@
         if (mPlaying && mDroid.below(mHeight)) {
             if (DEBUG_IDDQD) {
                 poke();
+                unpoke();
             } else {
                 L("player hit the floor");
+                thump();
                 stop();
             }
         }
@@ -429,6 +458,7 @@
             final Obstacle ob = mObstaclesInPlay.get(j);
             if (mPlaying && ob.intersects(mDroid) && !DEBUG_IDDQD) {
                 L("player hit an obstacle");
+                thump();
                 stop();
             } else if (ob.cleared(mDroid)) {
                 if (ob instanceof Stem) passedBarrier = true;
@@ -459,8 +489,9 @@
         // 3. Time for more obstacles!
         if (mPlaying && (t - mLastPipeTime) > PARAMS.OBSTACLE_PERIOD) {
             mLastPipeTime = t;
-            final int obstacley = (int) (Math.random()
-                    * (mHeight - 2*PARAMS.OBSTACLE_MIN - PARAMS.OBSTACLE_GAP)) + PARAMS.OBSTACLE_MIN;
+            final int obstacley =
+                    (int)(frand() * (mHeight - 2*PARAMS.OBSTACLE_MIN - PARAMS.OBSTACLE_GAP)) +
+                    PARAMS.OBSTACLE_MIN;
 
             final int inset = (PARAMS.OBSTACLE_WIDTH - PARAMS.OBSTACLE_STEM_WIDTH) / 2;
             final int yinset = PARAMS.OBSTACLE_WIDTH/2;
@@ -539,7 +570,7 @@
     
     @Override
     public boolean onTouchEvent(MotionEvent ev) {
-        if (DEBUG) L("touch: %s", ev);
+        L("touch: %s", ev);
         switch (ev.getAction()) {
             case MotionEvent.ACTION_DOWN:
                 poke();
@@ -553,7 +584,7 @@
 
     @Override
     public boolean onTrackballEvent(MotionEvent ev) {
-        if (DEBUG) L("trackball: %s", ev);
+        L("trackball: %s", ev);
         switch (ev.getAction()) {
             case MotionEvent.ACTION_DOWN:
                 poke();
@@ -567,7 +598,7 @@
 
     @Override
     public boolean onKeyDown(int keyCode, KeyEvent ev) {
-        if (DEBUG) L("keyDown: %d", keyCode);
+        L("keyDown: %d", keyCode);
         switch (keyCode) {
             case KeyEvent.KEYCODE_DPAD_CENTER:
             case KeyEvent.KEYCODE_DPAD_UP:
@@ -582,7 +613,7 @@
 
     @Override
     public boolean onKeyUp(int keyCode, KeyEvent ev) {
-        if (DEBUG) L("keyDown: %d", keyCode);
+        L("keyDown: %d", keyCode);
         switch (keyCode) {
             case KeyEvent.KEYCODE_DPAD_CENTER:
             case KeyEvent.KEYCODE_DPAD_UP:
@@ -597,7 +628,7 @@
 
     @Override
     public boolean onGenericMotionEvent (MotionEvent ev) {
-        if (DEBUG) L("generic: %s", ev);
+        L("generic: %s", ev);
         return false;
     }
 
@@ -684,6 +715,10 @@
 
         private boolean mBoosting;
 
+        private final int[] sColors = new int[] {
+                0xFF78C557,
+        };
+
         private final float[] sHull = new float[] {
                 0.3f,  0f,    // left antenna
                 0.7f,  0f,    // right antenna
@@ -692,7 +727,7 @@
                 0.6f,  1f,    // right foot
                 0.4f,  1f,    // left foot BLUE!
                 0.08f, 0.75f, // sinistram
-                0.08f, 0.33f,  // cold shoulder
+                0.08f, 0.33f, // cold shoulder
         };
         public final float[] corners = new float[sHull.length];
 
@@ -701,7 +736,7 @@
 
             setBackgroundResource(R.drawable.android);
             getBackground().setTintMode(PorterDuff.Mode.SRC_ATOP);
-            getBackground().setTint(0xFF00FF00);
+            getBackground().setTint(sColors[0]);
             setOutlineProvider(new ViewOutlineProvider() {
                 @Override
                 public void getOutline(View view, Outline outline) {
@@ -822,8 +857,9 @@
         int cx, cy, r;
         public Pop(Context context, float h) {
             super(context, h);
-            int idx = 2*irand(0, POPS.length/2);
+            int idx = 3*irand(0, POPS.length/3);
             setBackgroundResource(POPS[idx]);
+            setAlpha((float)(POPS[idx+2])/255);
             setScaleX(frand() < 0.5f ? -1 : 1);
             mRotate = POPS[idx+1] == 0 ? 0 : (frand() < 0.5f ? -1 : 1);
             setOutlineProvider(new ViewOutlineProvider() {
diff --git a/packages/SystemUI/src/com/android/systemui/egg/LLandActivity.java b/packages/SystemUI/src/com/android/systemui/egg/LLandActivity.java
index 88fd952..b9f8106 100644
--- a/packages/SystemUI/src/com/android/systemui/egg/LLandActivity.java
+++ b/packages/SystemUI/src/com/android/systemui/egg/LLandActivity.java
@@ -24,13 +24,21 @@
 import com.android.systemui.R;
 
 public class LLandActivity extends Activity {
+    LLand mLand;
+
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.lland);
-        LLand world = (LLand) findViewById(R.id.world);
-        world.setScoreField((TextView) findViewById(R.id.score));
-        world.setSplash(findViewById(R.id.welcome));
-        Log.v(LLand.TAG, "focus: " + world.requestFocus());
+        mLand = (LLand) findViewById(R.id.world);
+        mLand.setScoreField((TextView) findViewById(R.id.score));
+        mLand.setSplash(findViewById(R.id.welcome));
+        //Log.v(LLand.TAG, "focus: " + mLand.requestFocus());
+    }
+
+    @Override
+    public void onPause() {
+        mLand.stop();
+        super.onPause();
     }
 }