private void addNewSlide() { if (mSlideshowEditor.addNewSlide()) { // add successfully mSlideListAdapter.notifyDataSetChanged(); // Select the new slide. mList.requestFocus(); mList.setSelection(mSlideshowModel.size() - 1); } else { Toast.makeText(this, R.string.cannot_add_slide_anymore, Toast.LENGTH_SHORT).show(); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { int position = mList.getSelectedItemPosition(); switch (item.getItemId()) { case MENU_MOVE_UP: if ((position > 0) && (position < mSlideshowModel.size())) { mSlideshowEditor.moveSlideUp(position); mSlideListAdapter.notifyDataSetChanged(); mList.setSelection(position - 1); } break; case MENU_MOVE_DOWN: if ((position >= 0) && (position < mSlideshowModel.size() - 1)) { mSlideshowEditor.moveSlideDown(position); mSlideListAdapter.notifyDataSetChanged(); mList.setSelection(position + 1); } break; case MENU_REMOVE_SLIDE: if ((position >= 0) && (position < mSlideshowModel.size())) { mSlideshowEditor.removeSlide(position); mSlideListAdapter.notifyDataSetChanged(); } break; case MENU_ADD_SLIDE: addNewSlide(); break; case MENU_DISCARD_SLIDESHOW: // delete all slides from slideshow. mSlideshowEditor.removeAllSlides(); mSlideListAdapter.notifyDataSetChanged(); finish(); break; } return true; }
public void onClick(View v) { // Validate mPosition if (mPosition >= 0 && mPosition < mSlideshowModel.size()) { mSlideshowEditor.removeSlide(mPosition); int size = mSlideshowModel.size(); if (size > 0) { if (mPosition >= size) { mPosition--; } showCurrentSlide(); } else { finish(); return; } } }
private void initSlideList() throws MmsException { cleanupSlideshowModel(); mSlideshowModel = SlideshowModel.createFromMessageUri(this, mUri); mSlideshowModel.registerModelChangedObserver(mModelChangedObserver); mSlideshowEditor = new SlideshowEditor(this, mSlideshowModel); if ((mSlideshowModel.size() == 0)) { boolean b = getSharedPreferences("SetDefaultLayout", 0).getBoolean("SetDefaultLayout", true); if (b) { mSlideshowEditor.changeLayout(LayoutModel.LAYOUT_BOTTOM_TEXT); } else { getSharedPreferences("SetDefaultLayout", 0) .edit() .putBoolean("SetDefaultLayout", true) .commit(); } } mSlideListAdapter = new SlideListAdapter(this, R.layout.slideshow_edit_item, mSlideshowModel); mList.setAdapter(mSlideListAdapter); }
public void onResizeResult(PduPart part, boolean append) { Context context = SlideEditorActivity.this; if (part == null) { Toast.makeText( SlideEditorActivity.this, getResourcesString(R.string.failed_to_add_media, getPictureString()), Toast.LENGTH_SHORT) .show(); return; } try { long messageId = ContentUris.parseId(mUri); PduPersister persister = PduPersister.getPduPersister(context); Uri newUri = persister.persistPart(part, messageId); mSlideshowEditor.changeImage(mPosition, newUri); setReplaceButtonText(R.string.replace_image); } catch (MmsException e) { notifyUser("add picture failed"); Toast.makeText( SlideEditorActivity.this, getResourcesString(R.string.failed_to_add_media, getPictureString()), Toast.LENGTH_SHORT) .show(); } catch (UnsupportContentTypeException e) { MessageUtils.showErrorDialog( SlideEditorActivity.this, getResourcesString(R.string.unsupported_media_format, getPictureString()), getResourcesString(R.string.select_different_media, getPictureString())); } catch (ResolutionException e) { MessageUtils.showErrorDialog( SlideEditorActivity.this, getResourcesString(R.string.failed_to_resize_image), getResourcesString(R.string.resize_image_error_information)); } catch (ExceedMessageSizeException e) { MessageUtils.showErrorDialog( SlideEditorActivity.this, getResourcesString(R.string.exceed_message_size_limitation), getResourcesString(R.string.failed_to_add_media, getPictureString())); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode != RESULT_OK) { return; } switch (requestCode) { case REQUEST_CODE_EDIT_TEXT: // XXX where does this come from? Action is probably not the // right place to have the text... mSlideshowEditor.changeText(mPosition, data.getAction()); break; case REQUEST_CODE_TAKE_PICTURE: Uri pictureUri = null; boolean showError = false; try { pictureUri = TempFileProvider.renameScrapFile(".jpg", Integer.toString(mPosition), this); if (pictureUri == null) { showError = true; } else { mSlideshowEditor.changeImage(mPosition, pictureUri); setReplaceButtonText(R.string.replace_image); } } catch (MmsException e) { Log.e(TAG, "add image failed", e); showError = true; } catch (UnsupportContentTypeException e) { MessageUtils.showErrorDialog( SlideEditorActivity.this, getResourcesString(R.string.unsupported_media_format, getPictureString()), getResourcesString(R.string.select_different_media, getPictureString())); } catch (ResolutionException e) { MessageUtils.resizeImageAsync( this, pictureUri, new Handler(), mResizeImageCallback, false); } catch (ExceedMessageSizeException e) { MessageUtils.resizeImageAsync( this, pictureUri, new Handler(), mResizeImageCallback, false); } if (showError) { notifyUser("add picture failed"); Toast.makeText( SlideEditorActivity.this, getResourcesString(R.string.failed_to_add_media, getPictureString()), Toast.LENGTH_SHORT) .show(); } break; case REQUEST_CODE_CHANGE_PICTURE: try { mSlideshowEditor.changeImage(mPosition, data.getData()); setReplaceButtonText(R.string.replace_image); } catch (MmsException e) { Log.e(TAG, "add image failed", e); notifyUser("add picture failed"); Toast.makeText( SlideEditorActivity.this, getResourcesString(R.string.failed_to_add_media, getPictureString()), Toast.LENGTH_SHORT) .show(); } catch (UnsupportContentTypeException e) { MessageUtils.showErrorDialog( SlideEditorActivity.this, getResourcesString(R.string.unsupported_media_format, getPictureString()), getResourcesString(R.string.select_different_media, getPictureString())); } catch (ResolutionException e) { MessageUtils.resizeImageAsync( this, data.getData(), new Handler(), mResizeImageCallback, false); } catch (ExceedMessageSizeException e) { MessageUtils.resizeImageAsync( this, data.getData(), new Handler(), mResizeImageCallback, false); } break; case REQUEST_CODE_CHANGE_MUSIC: case REQUEST_CODE_RECORD_SOUND: Uri uri; if (requestCode == REQUEST_CODE_CHANGE_MUSIC) { uri = (Uri) data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); if (Settings.System.DEFAULT_RINGTONE_URI.equals(uri)) { return; } } else { uri = data.getData(); } try { mSlideshowEditor.changeAudio(mPosition, uri); } catch (MmsException e) { Log.e(TAG, "add audio failed", e); notifyUser("add music failed"); Toast.makeText( SlideEditorActivity.this, getResourcesString(R.string.failed_to_add_media, getAudioString()), Toast.LENGTH_SHORT) .show(); } catch (UnsupportContentTypeException e) { MessageUtils.showErrorDialog( SlideEditorActivity.this, getResourcesString(R.string.unsupported_media_format, getAudioString()), getResourcesString(R.string.select_different_media, getAudioString())); } catch (ExceedMessageSizeException e) { MessageUtils.showErrorDialog( SlideEditorActivity.this, getResourcesString(R.string.exceed_message_size_limitation), getResourcesString(R.string.failed_to_add_media, getAudioString())); } break; case REQUEST_CODE_TAKE_VIDEO: try { Uri videoUri = TempFileProvider.renameScrapFile(".3gp", Integer.toString(mPosition), this); mSlideshowEditor.changeVideo(mPosition, videoUri); } catch (MmsException e) { notifyUser("add video failed"); Toast.makeText( SlideEditorActivity.this, getResourcesString(R.string.failed_to_add_media, getVideoString()), Toast.LENGTH_SHORT) .show(); } catch (UnsupportContentTypeException e) { MessageUtils.showErrorDialog( SlideEditorActivity.this, getResourcesString(R.string.unsupported_media_format, getVideoString()), getResourcesString(R.string.select_different_media, getVideoString())); } catch (ExceedMessageSizeException e) { MessageUtils.showErrorDialog( SlideEditorActivity.this, getResourcesString(R.string.exceed_message_size_limitation), getResourcesString(R.string.failed_to_add_media, getVideoString())); } break; case REQUEST_CODE_CHANGE_VIDEO: try { mSlideshowEditor.changeVideo(mPosition, data.getData()); } catch (MmsException e) { Log.e(TAG, "add video failed", e); notifyUser("add video failed"); Toast.makeText( SlideEditorActivity.this, getResourcesString(R.string.failed_to_add_media, getVideoString()), Toast.LENGTH_SHORT) .show(); } catch (UnsupportContentTypeException e) { MessageUtils.showErrorDialog( SlideEditorActivity.this, getResourcesString(R.string.unsupported_media_format, getVideoString()), getResourcesString(R.string.select_different_media, getVideoString())); } catch (ExceedMessageSizeException e) { MessageUtils.showErrorDialog( SlideEditorActivity.this, getResourcesString(R.string.exceed_message_size_limitation), getResourcesString(R.string.failed_to_add_media, getVideoString())); } break; case REQUEST_CODE_CHANGE_DURATION: mSlideshowEditor.changeDuration(mPosition, Integer.valueOf(data.getAction()) * 1000); break; } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case MENU_PREVIEW_SLIDESHOW: previewSlideshow(); break; case MENU_REMOVE_TEXT: SlideModel slide = mSlideshowModel.get(mPosition); if (slide != null) { slide.removeText(); } break; case MENU_ADD_PICTURE: Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null); intent.setType(ContentType.IMAGE_UNSPECIFIED); startActivityForResult(intent, REQUEST_CODE_CHANGE_PICTURE); break; case MENU_TAKE_PICTURE: intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // We have to pass a uri to store the picture data, otherwise the camera will return // a very small image bitmap. intent.putExtra(MediaStore.EXTRA_OUTPUT, TempFileProvider.SCRAP_CONTENT_URI); startActivityForResult(intent, REQUEST_CODE_TAKE_PICTURE); break; case MENU_DEL_PICTURE: mSlideshowEditor.removeImage(mPosition); setReplaceButtonText(R.string.add_picture); break; case MENU_ADD_AUDIO: MessageUtils.selectAudio(this, REQUEST_CODE_CHANGE_MUSIC); break; case MENU_RECORD_SOUND: slide = mSlideshowModel.get(mPosition); int currentSlideSize = slide.getSlideSize(); long sizeLimit = ComposeMessageActivity.computeAttachmentSizeLimit(mSlideshowModel, currentSlideSize); MessageUtils.recordSound(this, REQUEST_CODE_RECORD_SOUND, sizeLimit); break; case MENU_DEL_AUDIO: mSlideshowEditor.removeAudio(mPosition); break; case MENU_ADD_VIDEO: intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType(ContentType.VIDEO_UNSPECIFIED); intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true); startActivityForResult(intent, REQUEST_CODE_CHANGE_VIDEO); break; case MENU_TAKE_VIDEO: slide = mSlideshowModel.get(mPosition); currentSlideSize = slide.getSlideSize(); sizeLimit = ComposeMessageActivity.computeAttachmentSizeLimit(mSlideshowModel, currentSlideSize); if (sizeLimit > 0) { MessageUtils.recordVideo(this, REQUEST_CODE_TAKE_VIDEO, sizeLimit); } else { Toast.makeText(this, getString(R.string.message_too_big_for_video), Toast.LENGTH_SHORT) .show(); } break; case MENU_DEL_VIDEO: mSlideshowEditor.removeVideo(mPosition); break; case MENU_ADD_SLIDE: mPosition++; if (mSlideshowEditor.addNewSlide(mPosition)) { // add successfully showCurrentSlide(); } else { // move position back mPosition--; Toast.makeText(this, R.string.cannot_add_slide_anymore, Toast.LENGTH_SHORT).show(); } break; case MENU_LAYOUT: showLayoutSelectorDialog(); break; case MENU_DURATION: showDurationDialog(); break; } return true; }
public void onTextChanged(String s) { if (!isFinishing()) { mSlideshowEditor.changeText(mPosition, s); } }