/** Scroll to the next photo. If we reach the end, let's start over */ public void actionNextPhoto() { CustomGallery gallery = (CustomGallery) findViewById(R.id.gallery); if (gallery == null) { Log.w( LOG_PREFIX, "Gallery view is not found in actionNextPhoto! Let's make sure this doesn't crash the app"); return; } if (userCreatedTouchEvent || gallery.hasUserCreatedTouchEvent()) { Log.i( LOG_PREFIX, "User created a touch even since time task started. Will not skip to next photo yet"); return; } // Log.i(LOG_PREFIX, "Selected position is " + gallery.getSelectedItemPosition()+ " out of "+ // gallery.getCount()); // TODO: Evaluate if we should add all queued photos if we are almost at the end if (gallery.getSelectedItemPosition() + 1 == gallery.getCount()) { Log.i(LOG_PREFIX, "At the end of the slideshow. Starting on the first photo again"); Analytics.trackEvent(getApplicationContext(), "actions", "slideshow", "cycles-free"); gallery.setSelection(0); } else { // skip to next photo gallery.onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, new KeyEvent(0, 0)); } }
/* (non-Javadoc) * @see android.app.Activity#onKeyDown(int, android.view.KeyEvent) */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { Log.d(LOG_PREFIX, "Keyevent in activity" + keyCode); // Basically some key-aliases for GoogleTV buttons switch (keyCode) { // hardcoded some keyevents in order to support 2.1 // case KeyEvent.KEYCODE_MEDIA_STOP: // case KeyEvent.KEYCODE_MEDIA_PAUSE: case 86: case 127: actionPauseSlideshow(); return true; // case KeyEvent.KEYCODE_MEDIA_PLAY: case 126: actionResumeSlideshow(); return true; case KeyEvent.KEYCODE_MEDIA_NEXT: case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: userCreatedTouchEvent = true; gallery.onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, new KeyEvent(0, 0)); return true; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: case KeyEvent.KEYCODE_MEDIA_REWIND: userCreatedTouchEvent = true; gallery.onKeyDown(KeyEvent.KEYCODE_DPAD_LEFT, new KeyEvent(0, 0)); return true; default: Log.d(LOG_PREFIX, "Unhandled keyevent " + keyCode); break; } return super.onKeyDown(keyCode, event); }