Search in sources :

Example 1 with UnsupportContentTypeException

use of com.android.mms.UnsupportContentTypeException in project android-aosp-mms by slvn.

the class SlideEditorActivity method onActivityResult.

@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 {
                    // Remove the old captured picture's thumbnail from the cache
                    MmsApp.getApplication().getThumbnailManager().removeThumbnail(pictureUri);
                    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;
    }
}
Also used : ResolutionException(com.android.mms.ResolutionException) MmsException(com.google.android.mms.MmsException) Handler(android.os.Handler) ExceedMessageSizeException(com.android.mms.ExceedMessageSizeException) UnsupportContentTypeException(com.android.mms.UnsupportContentTypeException) Uri(android.net.Uri)

Example 2 with UnsupportContentTypeException

use of com.android.mms.UnsupportContentTypeException in project android-aosp-mms by slvn.

the class SlideshowModel method createFromPduBody.

public static SlideshowModel createFromPduBody(Context context, PduBody pb) throws MmsException {
    SMILDocument document = SmilHelper.getDocument(pb);
    // Create root-layout model.
    SMILLayoutElement sle = document.getLayout();
    SMILRootLayoutElement srle = sle.getRootLayout();
    int w = srle.getWidth();
    int h = srle.getHeight();
    if ((w == 0) || (h == 0)) {
        w = LayoutManager.getInstance().getLayoutParameters().getWidth();
        h = LayoutManager.getInstance().getLayoutParameters().getHeight();
        srle.setWidth(w);
        srle.setHeight(h);
    }
    RegionModel rootLayout = new RegionModel(null, 0, 0, w, h);
    // Create region models.
    ArrayList<RegionModel> regions = new ArrayList<RegionModel>();
    NodeList nlRegions = sle.getRegions();
    int regionsNum = nlRegions.getLength();
    for (int i = 0; i < regionsNum; i++) {
        SMILRegionElement sre = (SMILRegionElement) nlRegions.item(i);
        RegionModel r = new RegionModel(sre.getId(), sre.getFit(), sre.getLeft(), sre.getTop(), sre.getWidth(), sre.getHeight(), sre.getBackgroundColor());
        regions.add(r);
    }
    LayoutModel layouts = new LayoutModel(rootLayout, regions);
    // Create slide models.
    SMILElement docBody = document.getBody();
    NodeList slideNodes = docBody.getChildNodes();
    int slidesNum = slideNodes.getLength();
    ArrayList<SlideModel> slides = new ArrayList<SlideModel>(slidesNum);
    int totalMessageSize = 0;
    for (int i = 0; i < slidesNum; i++) {
        // FIXME: This is NOT compatible with the SMILDocument which is
        // generated by some other mobile phones.
        SMILParElement par = (SMILParElement) slideNodes.item(i);
        // Create media models for each slide.
        NodeList mediaNodes = par.getChildNodes();
        int mediaNum = mediaNodes.getLength();
        ArrayList<MediaModel> mediaSet = new ArrayList<MediaModel>(mediaNum);
        for (int j = 0; j < mediaNum; j++) {
            SMILMediaElement sme = (SMILMediaElement) mediaNodes.item(j);
            try {
                MediaModel media = MediaModelFactory.getMediaModel(context, sme, layouts, pb);
                /*
                    * This is for slide duration value set.
                    * If mms server does not support slide duration.
                    */
                if (!MmsConfig.getSlideDurationEnabled()) {
                    int mediadur = media.getDuration();
                    float dur = par.getDur();
                    if (dur == 0) {
                        mediadur = MmsConfig.getMinimumSlideElementDuration() * 1000;
                        media.setDuration(mediadur);
                    }
                    if ((int) mediadur / 1000 != dur) {
                        String tag = sme.getTagName();
                        if (ContentType.isVideoType(media.mContentType) || tag.equals(SmilHelper.ELEMENT_TAG_VIDEO) || ContentType.isAudioType(media.mContentType) || tag.equals(SmilHelper.ELEMENT_TAG_AUDIO)) {
                            /*
                                * add 1 sec to release and close audio/video
                                * for guaranteeing the audio/video playing.
                                * because the mmsc does not support the slide duration.
                                */
                            par.setDur((float) mediadur / 1000 + 1);
                        } else {
                            /*
                                * If a slide has an image and an audio/video element
                                * and the audio/video element has longer duration than the image,
                                * The Image disappear before the slide play done. so have to match
                                * an image duration to the slide duration.
                                */
                            if ((int) mediadur / 1000 < dur) {
                                media.setDuration((int) dur * 1000);
                            } else {
                                if ((int) dur != 0) {
                                    media.setDuration((int) dur * 1000);
                                } else {
                                    par.setDur((float) mediadur / 1000);
                                }
                            }
                        }
                    }
                }
                SmilHelper.addMediaElementEventListeners((EventTarget) sme, media);
                mediaSet.add(media);
                totalMessageSize += media.getMediaSize();
            } catch (IOException e) {
                Log.e(TAG, e.getMessage(), e);
            } catch (IllegalArgumentException e) {
                Log.e(TAG, e.getMessage(), e);
            } catch (UnsupportContentTypeException e) {
                Log.e(TAG, e.getMessage(), e);
            }
        }
        SlideModel slide = new SlideModel((int) (par.getDur() * 1000), mediaSet);
        slide.setFill(par.getFill());
        SmilHelper.addParElementEventListeners((EventTarget) par, slide);
        slides.add(slide);
    }
    SlideshowModel slideshow = new SlideshowModel(layouts, slides, document, pb, context);
    slideshow.mTotalMessageSize = totalMessageSize;
    slideshow.registerModelChangedObserver(slideshow);
    return slideshow;
}
Also used : SMILDocument(org.w3c.dom.smil.SMILDocument) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) SMILElement(org.w3c.dom.smil.SMILElement) IOException(java.io.IOException) UnsupportContentTypeException(com.android.mms.UnsupportContentTypeException) SMILMediaElement(org.w3c.dom.smil.SMILMediaElement) SMILRootLayoutElement(org.w3c.dom.smil.SMILRootLayoutElement) SMILLayoutElement(org.w3c.dom.smil.SMILLayoutElement) SMILParElement(org.w3c.dom.smil.SMILParElement) SMILRegionElement(org.w3c.dom.smil.SMILRegionElement)

Aggregations

UnsupportContentTypeException (com.android.mms.UnsupportContentTypeException)2 Uri (android.net.Uri)1 Handler (android.os.Handler)1 ExceedMessageSizeException (com.android.mms.ExceedMessageSizeException)1 ResolutionException (com.android.mms.ResolutionException)1 MmsException (com.google.android.mms.MmsException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 NodeList (org.w3c.dom.NodeList)1 SMILDocument (org.w3c.dom.smil.SMILDocument)1 SMILElement (org.w3c.dom.smil.SMILElement)1 SMILLayoutElement (org.w3c.dom.smil.SMILLayoutElement)1 SMILMediaElement (org.w3c.dom.smil.SMILMediaElement)1 SMILParElement (org.w3c.dom.smil.SMILParElement)1 SMILRegionElement (org.w3c.dom.smil.SMILRegionElement)1 SMILRootLayoutElement (org.w3c.dom.smil.SMILRootLayoutElement)1