/** 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));
    }
  }
  @Override
  public void onDownloadCompleted(DownloadableObject downloadableObject) {
    // unsafe cast, but we have control
    SlideshowPhoto slideshowPhoto = (SlideshowPhoto) downloadableObject;
    if (queuedSlideshowPhotos == null) {
      queuedSlideshowPhotos = new ArrayList<SlideshowPhoto>(20);
    }
    queuedSlideshowPhotos.add(slideshowPhoto);

    // we want to add the slideshow photos as seldom as possible, as it creates a refresh of views
    if (gallery.getCount() <= 5 && queuedSlideshowPhotos.size() >= 5) {
      addSlideshowPhoto(queuedSlideshowPhotos);
      queuedSlideshowPhotos = null;
    } else if (gallery.getCount() - gallery.getSelectedItemPosition() <= 3
        && queuedSlideshowPhotos.size() >= 10) {
      addSlideshowPhoto(queuedSlideshowPhotos);
      queuedSlideshowPhotos = null;
    } else if (queuedSlideshowPhotos.size() >= 50) {
      addSlideshowPhoto(queuedSlideshowPhotos);
      queuedSlideshowPhotos = null;
    }
  }