From a924553fc2a5bf5ab88ac031adf154480b970bd9 Mon Sep 17 00:00:00 2001 From: Chris Wren Date: Tue, 9 Apr 2013 15:26:22 -0400 Subject: support dpads in story mode. Bug: 8572945 Change-Id: Icabd1fc61ec7c3c5b6a2f5ef94641eb7c8deb1c3 --- res/values/config.xml | 3 +++ .../dreams/phototable/KeyboardInterpreter.java | 23 ++++++++++++++++++++-- src/com/android/dreams/phototable/PhotoTable.java | 15 ++++---------- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/res/values/config.xml b/res/values/config.xml index e20ac68..c8d419c 100644 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -100,5 +100,8 @@ true + + 1000 + diff --git a/src/com/android/dreams/phototable/KeyboardInterpreter.java b/src/com/android/dreams/phototable/KeyboardInterpreter.java index aa316cb..0b0d6bb 100644 --- a/src/com/android/dreams/phototable/KeyboardInterpreter.java +++ b/src/com/android/dreams/phototable/KeyboardInterpreter.java @@ -27,15 +27,17 @@ public class KeyboardInterpreter { private static final boolean DEBUG = false; private final PhotoTable mTable; + private final long mBounce; + private long mLastDeckNavigation; public KeyboardInterpreter(PhotoTable table) { + mBounce = 2000; // TODO: remove this once latencies in lower layers are removed. mTable = table; } - public boolean onKeyDown(int keyCode, KeyEvent event) { final View focus = mTable.getFocus(); boolean consumed = true; - + Log.d(TAG, "down: " + keyCode); if (mTable.hasSelection()) { switch (keyCode) { case KeyEvent.KEYCODE_ENTER: @@ -44,6 +46,23 @@ public class KeyboardInterpreter { mTable.setFocus(mTable.getSelection()); mTable.clearSelection(); break; + + case KeyEvent.KEYCODE_DPAD_RIGHT: + case KeyEvent.KEYCODE_L: + if ((System.currentTimeMillis() - mLastDeckNavigation) > mBounce) { + mLastDeckNavigation = System.currentTimeMillis(); + mTable.selectPrevious(); + } + break; + + case KeyEvent.KEYCODE_DPAD_LEFT: + case KeyEvent.KEYCODE_H: + if ((System.currentTimeMillis() - mLastDeckNavigation) > mBounce) { + mLastDeckNavigation = System.currentTimeMillis(); + mTable.selectNext(); + } + break; + default: if (DEBUG) Log.d(TAG, "dropped unexpected: " + keyCode); consumed = false; diff --git a/src/com/android/dreams/phototable/PhotoTable.java b/src/com/android/dreams/phototable/PhotoTable.java index 7d2f6b6..ddf071f 100644 --- a/src/com/android/dreams/phototable/PhotoTable.java +++ b/src/com/android/dreams/phototable/PhotoTable.java @@ -94,6 +94,7 @@ public class PhotoTable extends FrameLayout { private final EdgeSwipeDetector mEdgeSwipeDetector; private final KeyboardInterpreter mKeyboardInterpreter; private final boolean mStoryModeEnabled; + private final long mPickUpDuration; private DreamService mDream; private PhotoLaunchTask mPhotoLaunchTask; private LoadNaturalSiblingTask mLoadOnDeckTasks[]; @@ -120,6 +121,7 @@ public class PhotoTable extends FrameLayout { mTableRatio = mResources.getInteger(R.integer.table_ratio) / 1000000f; mImageRotationLimit = (float) mResources.getInteger(R.integer.max_image_rotation); mThrowSpeed = mResources.getDimension(R.dimen.image_throw_speed); + mPickUpDuration = mResources.getInteger(R.integer.photo_pickup_duration); mThrowRotation = (float) mResources.getInteger(R.integer.image_throw_rotatioan); mTableCapacity = mResources.getInteger(R.integer.table_capacity); mRedealCount = mResources.getInteger(R.integer.redeal_count); @@ -604,11 +606,6 @@ public class PhotoTable extends FrameLayout { float x = (getWidth() - photoWidth) / 2f; float y = (getHeight() - photoHeight) / 2f; - View selected = getSelection(); - float selectedWidth = selected.getWidth(); - float selectedHeight = selected.getHeight(); - float selectedScale = Math.min(getHeight() / photoHeight, getWidth() / photoWidth); - float offset = (((float) mWidth + scale * (photoWidth - 2f * mInset)) / 2f); x += (slot == NEXT? 1f : -1f) * offset; @@ -619,7 +616,7 @@ public class PhotoTable extends FrameLayout { .scaleY(scale) .x(x) .y(y) - .setDuration(1000) + .setDuration(mPickUpDuration) .setInterpolator(new DecelerateInterpolator(2f)); } } @@ -784,10 +781,6 @@ public class PhotoTable extends FrameLayout { float dx = x - x0; float dy = y - y0; - float dist = (float) (Math.sqrt(dx * dx + dy * dy)); - int duration = (int) (1000f * dist / 600f); - duration = Math.max(duration, 500); - photo.setRotation(wrapAngle(photo.getRotation())); log("animate it"); @@ -799,7 +792,7 @@ public class PhotoTable extends FrameLayout { .scaleY(scale) .x(x) .y(y) - .setDuration(duration) + .setDuration(mPickUpDuration) .setInterpolator(new DecelerateInterpolator(2f)) .withEndAction(new Runnable() { @Override -- cgit v1.2.3