Commit a924553f authored by Chris Wren's avatar Chris Wren
Browse files

support dpads in story mode.

Bug: 8572945
Change-Id: Icabd1fc61ec7c3c5b6a2f5ef94641eb7c8deb1c3
parent 88d80f44
......@@ -100,5 +100,8 @@
<!-- Enable story mode. -->
<bool name="enable_story_mode">true</bool>
<!-- Duration ion milliseconds for the pickup animation. -->
<integer name="photo_pickup_duration">1000</integer>
</resources>
......@@ -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;
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment