コード例 #1
0
  public static int getAttachmentType(SlideshowModel model) {
    if (model == null) {
      return WorkingMessage.TEXT;
    }

    int numberOfSlides = model.size();
    if (numberOfSlides > 1) {
      return WorkingMessage.SLIDESHOW;
    } else if (numberOfSlides == 1) {
      // Only one slide in the slide-show.
      SlideModel slide = model.get(0);
      if (slide.hasVideo()) {
        return WorkingMessage.VIDEO;
      }

      if (slide.hasAudio() && slide.hasImage()) {
        return WorkingMessage.SLIDESHOW;
      }

      if (slide.hasAudio()) {
        return WorkingMessage.AUDIO;
      }

      if (slide.hasImage()) {
        return WorkingMessage.IMAGE;
      }

      if (slide.hasText()) {
        return WorkingMessage.TEXT;
      }
    }

    return WorkingMessage.TEXT;
  }
コード例 #2
0
  public static void viewSimpleSlideshow(Context context, SlideshowModel slideshow) {
    if (!slideshow.isSimple()) {
      throw new IllegalArgumentException("viewSimpleSlideshow() called on a non-simple slideshow");
    }
    SlideModel slide = slideshow.get(0);
    MediaModel mm = null;
    if (slide.hasImage()) {
      mm = slide.getImage();
    } else if (slide.hasVideo()) {
      mm = slide.getVideo();
    }

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    intent.putExtra("SingleItemOnly", true); // So we don't see "surrounding" images in Gallery

    String contentType;
    if (mm.isDrmProtected()) {
      contentType = mm.getDrmObject().getContentType();
    } else {
      contentType = mm.getContentType();
    }
    intent.setDataAndType(mm.getUri(), contentType);
    context.startActivity(intent);
  }
  /**
   * Determines whether this is a "simple" slideshow. Criteria: - Exactly one slide - Exactly one
   * multimedia attachment, but no audio - It can optionally have a caption
   */
  public boolean isSimple() {
    // There must be one (and only one) slide.
    if (size() != 1) return false;

    SlideModel slide = get(0);
    // The slide must have either an image or video, but not both.
    if (!(slide.hasImage() ^ slide.hasVideo())) return false;

    // No audio allowed.
    if (slide.hasAudio()) return false;

    return true;
  }
コード例 #4
0
 public void onClick(View v) {
   SlideModel slide = mSlideshowModel.get(mPosition);
   if (slide != null && slide.hasVideo()) {
     Toast.makeText(
             SlideEditorActivity.this,
             R.string.cannot_add_picture_and_video,
             Toast.LENGTH_SHORT)
         .show();
     return;
   }
   Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
   intent.setType(ContentType.IMAGE_UNSPECIFIED);
   startActivityForResult(intent, REQUEST_CODE_CHANGE_PICTURE);
 }
コード例 #5
0
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    if (isFinishing()) {
      return false;
    }
    menu.clear();

    SlideModel slide = mSlideshowModel.get(mPosition);

    if (slide == null) {
      return false;
    }

    // Preview slideshow.
    menu.add(0, MENU_PREVIEW_SLIDESHOW, 0, R.string.preview_slideshow)
        .setIcon(com.android.internal.R.drawable.ic_menu_play_clip);

    // Text
    if (slide.hasText() && !TextUtils.isEmpty(slide.getText().getText())) {
      // "Change text" if text is set.
      menu.add(0, MENU_REMOVE_TEXT, 0, R.string.remove_text)
          .setIcon(R.drawable.ic_menu_remove_text);
    }

    // Picture
    if (slide.hasImage()) {
      menu.add(0, MENU_DEL_PICTURE, 0, R.string.remove_picture)
          .setIcon(R.drawable.ic_menu_remove_picture);
    } else if (!slide.hasVideo()) {
      menu.add(0, MENU_ADD_PICTURE, 0, R.string.add_picture).setIcon(R.drawable.ic_menu_picture);
      menu.add(0, MENU_TAKE_PICTURE, 0, R.string.attach_take_photo)
          .setIcon(R.drawable.ic_menu_picture);
    }

    // Music
    if (slide.hasAudio()) {
      menu.add(0, MENU_DEL_AUDIO, 0, R.string.remove_music)
          .setIcon(R.drawable.ic_menu_remove_sound);
    } else if (!slide.hasVideo()) {
      if (MmsConfig.getAllowAttachAudio()) {
        SubMenu subMenu =
            menu.addSubMenu(0, MENU_SUB_AUDIO, 0, R.string.add_music)
                .setIcon(R.drawable.ic_menu_add_sound);
        subMenu.add(0, MENU_ADD_AUDIO, 0, R.string.attach_sound);
        subMenu.add(0, MENU_RECORD_SOUND, 0, R.string.attach_record_sound);
      } else {
        menu.add(0, MENU_RECORD_SOUND, 0, R.string.attach_record_sound)
            .setIcon(R.drawable.ic_menu_add_sound);
      }
    }

    // Video
    if (slide.hasVideo()) {
      menu.add(0, MENU_DEL_VIDEO, 0, R.string.remove_video)
          .setIcon(R.drawable.ic_menu_remove_video);
    } else if (!slide.hasAudio() && !slide.hasImage()) {
      menu.add(0, MENU_ADD_VIDEO, 0, R.string.add_video).setIcon(R.drawable.ic_menu_movie);
      menu.add(0, MENU_TAKE_VIDEO, 0, R.string.attach_record_video)
          .setIcon(R.drawable.ic_menu_movie);
    }

    // Add slide
    menu.add(0, MENU_ADD_SLIDE, 0, R.string.add_slide).setIcon(R.drawable.ic_menu_add_slide);

    // Slide duration
    String duration = getResources().getString(R.string.duration_sec);
    menu.add(
            0, MENU_DURATION, 0, duration.replace("%s", String.valueOf(slide.getDuration() / 1000)))
        .setIcon(R.drawable.ic_menu_duration);

    // Slide layout
    int resId;
    if (mSlideshowModel.getLayout().getLayoutType() == LayoutModel.LAYOUT_TOP_TEXT) {
      resId = R.string.layout_top;
    } else {
      resId = R.string.layout_bottom;
    }
    // FIXME: set correct icon when layout icon is available.
    menu.add(0, MENU_LAYOUT, 0, resId).setIcon(R.drawable.ic_menu_picture);
    return true;
  }