diff --git a/packages/SystemUI/res/drawable/pop_ball.xml b/packages/SystemUI/res/drawable/pop_ball.xml new file mode 100644 index 0000000000000..ee1220f42140f --- /dev/null +++ b/packages/SystemUI/res/drawable/pop_ball.xml @@ -0,0 +1,29 @@ + + + + + diff --git a/packages/SystemUI/res/drawable/pop_belt.xml b/packages/SystemUI/res/drawable/pop_belt.xml index 5c0c3d7f89f51..e0ea57527d2a5 100644 --- a/packages/SystemUI/res/drawable/pop_belt.xml +++ b/packages/SystemUI/res/drawable/pop_belt.xml @@ -20,14 +20,14 @@ Copyright (C) 2014 The Android Open Source Project android:viewportHeight="100.0"> + android:fillColor="#9C27B0"/> + android:fillColor="#BA68C8"/> + android:fillColor="#9C27B0"/> + android:fillColor="#BA68C8"/> diff --git a/packages/SystemUI/res/drawable/pop_pizza.xml b/packages/SystemUI/res/drawable/pop_pizza.xml index b6d2bb30b3d91..1806b5a17cec1 100644 --- a/packages/SystemUI/res/drawable/pop_pizza.xml +++ b/packages/SystemUI/res/drawable/pop_pizza.xml @@ -20,26 +20,26 @@ Copyright (C) 2014 The Android Open Source Project android:viewportHeight="100.0"> + android:fillColor="#2979FF"/> + android:fillColor="#FF1744"/> + android:fillColor="#0F9D58"/> + android:fillColor="#FFBC00"/> + android:fillColor="#2979FF"/> + android:fillColor="#FFBC00"/> + android:fillColor="#0F9D58"/> + android:fillColor="#FF1744"/> diff --git a/packages/SystemUI/res/drawable/pop_swirl.xml b/packages/SystemUI/res/drawable/pop_swirl.xml index acd6d3ddb5f3c..f87569b4a5f89 100644 --- a/packages/SystemUI/res/drawable/pop_swirl.xml +++ b/packages/SystemUI/res/drawable/pop_swirl.xml @@ -20,7 +20,7 @@ Copyright (C) 2014 The Android Open Source Project android:viewportHeight="100.0"> + android:fillColor="#FFFFFA"/> @@ -32,7 +32,7 @@ Copyright (C) 2014 The Android Open Source Project android:fillColor="#303F9F"/> + android:fillColor="#FFFFFA"/> @@ -44,13 +44,13 @@ Copyright (C) 2014 The Android Open Source Project android:fillColor="#303F9F"/> + android:fillColor="#FFFFFA"/> + android:fillColor="#FFFFFA"/> diff --git a/packages/SystemUI/res/drawable/pop_vortex.xml b/packages/SystemUI/res/drawable/pop_vortex.xml index faefcb1e89196..2380e68c4c16e 100644 --- a/packages/SystemUI/res/drawable/pop_vortex.xml +++ b/packages/SystemUI/res/drawable/pop_vortex.xml @@ -20,7 +20,7 @@ Copyright (C) 2014 The Android Open Source Project android:viewportHeight="100.0"> + android:fillColor="#F8F8FF"/> diff --git a/packages/SystemUI/res/values/lland_config.xml b/packages/SystemUI/res/values/lland_config.xml index 5d740824b63db..a9e732e32a05b 100644 --- a/packages/SystemUI/res/values/lland_config.xml +++ b/packages/SystemUI/res/values/lland_config.xml @@ -26,7 +26,7 @@ 90dp 12dp 170dp - 40dp + 48dp 20dp 250dp 20dp diff --git a/packages/SystemUI/src/com/android/systemui/egg/LLand.java b/packages/SystemUI/src/com/android/systemui/egg/LLand.java index cdfe6e578a9f0..5de09a3e99ccd 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.PorterDuff; 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 class LLand extends FrameLayout { 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 class LLand extends FrameLayout { 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 @@ public class LLand extends FrameLayout { 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 class LLand extends FrameLayout { 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 @@ public class LLand extends FrameLayout { 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 @@ public class LLand extends FrameLayout { 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 @@ public class LLand extends FrameLayout { } } - private void stop() { + public void stop() { if (mAnimating) { mAnim.cancel(); mAnim = null; @@ -417,8 +444,10 @@ public class LLand extends FrameLayout { if (mPlaying && mDroid.below(mHeight)) { if (DEBUG_IDDQD) { poke(); + unpoke(); } else { L("player hit the floor"); + thump(); stop(); } } @@ -429,6 +458,7 @@ public class LLand extends FrameLayout { 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 @@ public class LLand extends FrameLayout { // 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 @@ public class LLand extends FrameLayout { @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 @@ public class LLand extends FrameLayout { @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 @@ public class LLand extends FrameLayout { @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 @@ public class LLand extends FrameLayout { @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 @@ public class LLand extends FrameLayout { @Override public boolean onGenericMotionEvent (MotionEvent ev) { - if (DEBUG) L("generic: %s", ev); + L("generic: %s", ev); return false; } @@ -684,6 +715,10 @@ public class LLand extends FrameLayout { 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 @@ public class LLand extends FrameLayout { 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 @@ public class LLand extends FrameLayout { 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 @@ public class LLand extends FrameLayout { 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 88fd9521fe832..b9f8106df0ceb 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 android.widget.TextView; 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(); } }