/**
   * Share the provided photo through other android apps
   *
   * <p>Will share the image as a image/jpg content type and include title and description as extra
   *
   * @param slideshowPhoto
   */
  public void actionSharePhoto(SlideshowPhoto slideshowPhoto) {
    Log.i(LOG_PREFIX, "Attempting to share photo " + slideshowPhoto);
    // TODO: Refactor this code.. rather ugly due to some GoogleTV related hacks

    if (slideshowPhoto != null) {
      Intent shareIntent = new Intent();
      shareIntent.setAction(Intent.ACTION_SEND);
      // we assume the type is image/jpg
      shareIntent.setType("image/jpg");

      String sharedText =
          slideshowPhoto.getTitle()
              + ": "
              + slideshowPhoto.getDescription()
              + "\n\n"
              + getResources().getString(R.string.share_footer);

      // if we have a cached file, add the stream and the sharedText
      // if not, add the url and the sharedText
      if (slideshowPhoto.isCacheExisting(rootFileDirectory)) {
        String path =
            "file://" + rootFileDirectory.getAbsolutePath() + "/" + slideshowPhoto.getFileName();
        Log.i(LOG_PREFIX, "Attempting to pass stream url " + path);
        shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
        shareIntent.putExtra(Intent.EXTRA_TEXT, sharedText);
      } else {
        shareIntent.putExtra(
            Intent.EXTRA_TEXT, slideshowPhoto.getLargePhoto() + "\n\n" + sharedText);
      }

      shareIntent.putExtra(Intent.EXTRA_SUBJECT, slideshowPhoto.getTitle());

      // Start the actual sharing activity
      try {
        List<ResolveInfo> relevantActivities =
            getPackageManager().queryIntentActivities(shareIntent, 0);
        if (AndroidUtils.isGoogleTV(getApplicationContext())
            || relevantActivities == null
            || relevantActivities.size() == 0) {
          Log.i(
              LOG_PREFIX,
              "No activity found that can handle image/jpg. Performing simple text share");
          Intent backupShareIntent = new Intent();
          backupShareIntent.setAction(Intent.ACTION_SEND);
          backupShareIntent.setType("text/plain");
          String backupSharedText = slideshowPhoto.getLargePhoto() + "\n\n" + sharedText;
          backupShareIntent.putExtra(Intent.EXTRA_TEXT, backupSharedText);
          startActivity(backupShareIntent);
        } else {
          startActivity(shareIntent);
        }

      } catch (ActivityNotFoundException e) {
        notifyUser("Unable to share current photo");
      }

    } else {
      notifyUser("Unable to share current photo");
    }
  }
  /**
   * Set a photo as the wallpaper (or possibly other apps receiving the intent)
   *
   * @param slideshowPhoto
   */
  public void actionSetAsWallpaper(SlideshowPhoto slideshowPhoto) {
    Uri uri = null;

    // If it is a drawable resource, handle it different
    if (slideshowPhoto instanceof SlideshowPhotoDrawable) {
      Log.i(LOG_PREFIX, "Set as... for one of the first three photos");
      // write the file to a cache dir
      SlideshowPhotoDrawable slideshowPhotoDrawable = (SlideshowPhotoDrawable) slideshowPhoto;
      // didn't work, as crop gets no access to folder
      // File cacheDir = getCacheDir();

      File cacheDir = new File(rootFileDirectory, "temp");
      cacheDir.mkdir();

      int drawableId = slideshowPhotoDrawable.getDrawableId();
      InputStream inputStream = getResources().openRawResource(drawableId);

      File cachedPhoto = FileUtils.writeToFile(cacheDir, "" + drawableId + ".jpg", inputStream);

      if (cachedPhoto == null) {
        notifyUser(getString(R.string.msg_wallpaper_failed_drawable));
        return;
      }

      uri = Uri.fromFile(cachedPhoto);
    } else {
      File filePhoto = new File(rootFileDirectory, slideshowPhoto.getFileName());
      uri = Uri.fromFile(filePhoto);
    }

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_ATTACH_DATA);
    String mimeType = "image/jpg";

    intent.setDataAndType(uri, mimeType);
    intent.putExtra("mimeType", mimeType);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    Log.i(LOG_PREFIX, "Attempting to set photo as wallpaper uri:" + uri);
    if (AndroidUtils.isGoogleTV(getApplicationContext())) {
      notifyUser(getString(R.string.msg_wallpaper_googletv));
    }

    startActivity(Intent.createChooser(intent, "Set Photo As"));
  }