com.google.android.mms.pdu_alt.PduPart

Here are the examples of the java api class com.google.android.mms.pdu_alt.PduPart taken from open source projects.

1. UriImage#getResizedImageAsPart()

Project: qksms
File: UriImage.java
/**
     * Get a version of this image resized to fit the given dimension and byte-size limits. Note
     * that the content type of the resulting PduPart may not be the same as the content type of
     * this UriImage; always call @link PduPart#getContentType() to get the new content type.
     *
     * @param widthLimit The width limit, in pixels
     * @param heightLimit The height limit, in pixels
     * @param byteLimit The binary size limit, in bytes
     * @return A new PduPart containing the resized image data
     */
public PduPart getResizedImageAsPart(int widthLimit, int heightLimit, int byteLimit) {
    PduPart part = new PduPart();
    byte[] data = getResizedImageData(mWidth, mHeight, widthLimit, heightLimit, byteLimit, mUri, mContext);
    if (data == null) {
        if (LOCAL_LOGV) {
            Log.v(TAG, "Resize image failed.");
        }
        return null;
    }
    part.setData(data);
    // getResizedImageData ALWAYS compresses to JPEG, regardless of the original content type
    part.setContentType(ContentType.IMAGE_JPEG.getBytes());
    return part;
}

2. SmilHelper#getDocument()

Project: qksms
File: SmilHelper.java
public static SMILDocument getDocument(PduBody pb) {
    // Find SMIL part in the message.
    PduPart smilPart = findSmilPart(pb);
    SMILDocument document = null;
    // Try to load SMIL document from existing part.
    if (smilPart != null) {
        document = getSmilDocument(smilPart);
    }
    if (document == null) {
        // Create a new SMIL document.
        document = createSmilDocument(pb);
    }
    return document;
}

3. MediaModelFactory#getMediaModel()

Project: qksms
File: MediaModelFactory.java
/**
     * Returns the media model for the given SMILMediaElement in the PduBody.
     *
     * @param context Context
     * @param sme     The SMILMediaElement to find
     * @param srcs    String array of sources
     * @param layouts LayoutModel
     * @param pb      PduBuddy
     * @return MediaModel
     * @throws IOException
     * @throws IllegalArgumentException
     * @throws MmsException
     */
public static MediaModel getMediaModel(Context context, SMILMediaElement sme, ArrayList<String> srcs, LayoutModel layouts, PduBody pb) throws IOException, IllegalArgumentException, MmsException {
    String tag = sme.getTagName();
    String src = sme.getSrc();
    PduPart part = findPart(context, pb, src, srcs);
    if (sme instanceof SMILRegionMediaElement) {
        return getRegionMediaModel(context, tag, src, (SMILRegionMediaElement) sme, layouts, part);
    } else {
        return getGenericMediaModel(context, tag, src, sme, part, null);
    }
}

4. SlideshowModel#makePduBody()

Project: qksms
File: SlideshowModel.java
private PduBody makePduBody(SMILDocument document) {
    PduBody pb = new PduBody();
    boolean hasForwardLock = false;
    for (SlideModel slide : mSlides) {
        for (MediaModel media : slide) {
            PduPart part = new PduPart();
            if (media.isText()) {
                TextModel text = (TextModel) media;
                // Don't create empty text part.
                if (TextUtils.isEmpty(text.getText())) {
                    continue;
                }
                // Set Charset if it's a text media.
                part.setCharset(text.getCharset());
            }
            // Set Content-Type.
            part.setContentType(media.getContentType().getBytes());
            String src = media.getSrc();
            String location;
            boolean startWithContentId = src.startsWith("cid:");
            if (startWithContentId) {
                location = src.substring("cid:".length());
            } else {
                location = src;
            }
            // Set Content-Location.
            part.setContentLocation(location.getBytes());
            // Set Content-Id.
            if (startWithContentId) {
                //Keep the original Content-Id.
                part.setContentId(location.getBytes());
            } else {
                int index = location.lastIndexOf(".");
                String contentId = (index == -1) ? location : location.substring(0, index);
                part.setContentId(contentId.getBytes());
            }
            if (media.isText()) {
                part.setData(((TextModel) media).getText().getBytes());
            } else if (media.isImage() || media.isVideo() || media.isAudio()) {
                part.setDataUri(media.getUri());
            } else {
                Log.w(TAG, "Unsupport media: " + media);
            }
            pb.addPart(part);
        }
    }
    // Create and insert SMIL part(as the first part) into the PduBody.
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    SmilXmlSerializer.serialize(document, out);
    PduPart smilPart = new PduPart();
    smilPart.setContentId("smil".getBytes());
    smilPart.setContentLocation("smil.xml".getBytes());
    smilPart.setContentType(ContentType.APP_SMIL.getBytes());
    smilPart.setData(out.toByteArray());
    pb.addPart(0, smilPart);
    return pb;
}

5. Transaction#getBytes()

Project: qksms
File: Transaction.java
public static MessageInfo getBytes(Context context, boolean saveMessage, String[] recipients, MMSPart[] parts, String subject) throws MmsException {
    final SendReq sendRequest = new SendReq();
    // create send request addresses
    for (int i = 0; i < recipients.length; i++) {
        final EncodedStringValue[] phoneNumbers = EncodedStringValue.extract(recipients[i]);
        if (phoneNumbers != null && phoneNumbers.length > 0) {
            sendRequest.addTo(phoneNumbers[0]);
        }
    }
    if (subject != null) {
        sendRequest.setSubject(new EncodedStringValue(subject));
    }
    sendRequest.setDate(Calendar.getInstance().getTimeInMillis() / 1000L);
    try {
        sendRequest.setFrom(new EncodedStringValue(Utils.getMyPhoneNumber(context)));
    } catch (Exception e) {
    }
    final PduBody pduBody = new PduBody();
    // assign parts to the pdu body which contains sending data
    if (parts != null) {
        for (int i = 0; i < parts.length; i++) {
            MMSPart part = parts[i];
            if (part != null) {
                try {
                    PduPart partPdu = new PduPart();
                    partPdu.setName(part.Name.getBytes());
                    partPdu.setContentType(part.MimeType.getBytes());
                    if (part.MimeType.startsWith("text")) {
                        partPdu.setCharset(CharacterSets.UTF_8);
                    }
                    partPdu.setData(part.Data);
                    pduBody.addPart(partPdu);
                } catch (Exception e) {
                }
            }
        }
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    SmilXmlSerializer.serialize(SmilHelper.createSmilDocument(pduBody), out);
    PduPart smilPart = new PduPart();
    smilPart.setContentId("smil".getBytes());
    smilPart.setContentLocation("smil.xml".getBytes());
    smilPart.setContentType(ContentType.APP_SMIL.getBytes());
    smilPart.setData(out.toByteArray());
    pduBody.addPart(0, smilPart);
    sendRequest.setBody(pduBody);
    // create byte array which will actually be sent
    final PduComposer composer = new PduComposer(context, sendRequest);
    final byte[] bytesToSend;
    try {
        bytesToSend = composer.make();
    } catch (OutOfMemoryError e) {
        throw new MmsException("Out of memory!");
    }
    MessageInfo info = new MessageInfo();
    info.bytes = bytesToSend;
    if (saveMessage) {
        try {
            PduPersister persister = PduPersister.getPduPersister(context);
            info.location = persister.persist(sendRequest, Uri.parse("content://mms/outbox"), true, settings.getGroup(), null);
        } catch (Exception e) {
            if (LOCAL_LOGV)
                Log.v(TAG, "error saving mms message");
            Log.e(TAG, "exception thrown", e);
            insert(context, recipients, parts, subject);
        }
    }
    try {
        Cursor query = context.getContentResolver().query(info.location, new String[] { "thread_id" }, null, null, null);
        if (query != null && query.moveToFirst()) {
            info.token = query.getLong(query.getColumnIndex("thread_id"));
        } else {
            // just default sending token for what I had before
            info.token = 4444L;
        }
    } catch (Exception e) {
        Log.e(TAG, "exception thrown", e);
        info.token = 4444L;
    }
    return info;
}

6. ImageModel#resizeMedia()

Project: qksms
File: ImageModel.java
@Override
protected void resizeMedia(int byteLimit, long messageId) throws MmsException {
    UriImage image = new UriImage(mContext, getUri());
    int widthLimit = MmsConfig.getMaxImageWidth();
    int heightLimit = MmsConfig.getMaxImageHeight();
    int size = getMediaSize();
    // possible.
    if (image.getHeight() > image.getWidth()) {
        int temp = widthLimit;
        widthLimit = heightLimit;
        heightLimit = temp;
    }
    if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
        Log.v(TAG, "resizeMedia size: " + size + " image.getWidth(): " + image.getWidth() + " widthLimit: " + widthLimit + " image.getHeight(): " + image.getHeight() + " heightLimit: " + heightLimit + " image.getContentType(): " + image.getContentType());
    }
    // set the size.
    if (size != 0 && size <= byteLimit && image.getWidth() <= widthLimit && image.getHeight() <= heightLimit && SUPPORTED_MMS_IMAGE_CONTENT_TYPES.contains(image.getContentType())) {
        if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
            Log.v(TAG, "resizeMedia - already sized");
        }
        return;
    }
    PduPart part = image.getResizedImageAsPart(widthLimit, heightLimit, byteLimit);
    if (part == null) {
        throw new ExceedMessageSizeException("Not enough memory to turn image into part: " + getUri());
    }
    // Update the content type because it may have changed due to resizing/recompressing
    mContentType = new String(part.getContentType());
    String src = getSrc();
    byte[] srcBytes = src.getBytes();
    part.setContentLocation(srcBytes);
    int period = src.lastIndexOf(".");
    byte[] contentId = period != -1 ? src.substring(0, period).getBytes() : srcBytes;
    part.setContentId(contentId);
    PduPersister persister = PduPersister.getPduPersister(mContext);
    this.mSize = part.getData().length;
    if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
        Log.v(TAG, "resizeMedia mSize: " + mSize);
    }
    Uri newUri = persister.persistPart(part, messageId, null);
    setUri(newUri);
}