diff options
author | Daniel Sandler <dsandler@android.com> | 2014-11-24 18:54:40 -0500 |
---|---|---|
committer | Dan Sandler <dsandler@android.com> | 2014-12-03 11:53:29 +0000 |
commit | 195c438883dfcca799aa456dfe52d24c077e40da (patch) | |
tree | 8ab1f945330c729106e00a60fc5049b7b5408626 /packages/SystemUI/src/com/android/systemui/egg | |
parent | 3f6755f58722bbae532171c384a294e530864ae1 (diff) | |
download | frameworks_base-195c438883dfcca799aa456dfe52d24c077e40da.zip frameworks_base-195c438883dfcca799aa456dfe52d24c077e40da.tar.gz frameworks_base-195c438883dfcca799aa456dfe52d24c077e40da.tar.bz2 |
Fixing bugs in the LLand.
less garish hue on the bugdroid
:
+----:-----------+
| | : | Θ.......... improved pop styles
| | : @ | |
| O A |....... occasionally there was no gap to fly
| 0 O | through, creating an unintentional
| @ | | | commentary on the futility of it all
+----------------+
: :
: : animation could continue
: after activity pause, sapping
: precious cycles
:
failure is now more visceral
Bug: 17931806
Change-Id: Iea9bd88e340beb3a0ca310db071ec9f6ec719a33
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/egg')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/egg/LLand.java | 86 | ||||
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/egg/LLandActivity.java | 16 |
2 files changed, 73 insertions, 29 deletions
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.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 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 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(); } } |