Search in sources :

Example 6 with SlideModel

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

the class MessagingNotification method addMmsNotificationInfos.

private static final void addMmsNotificationInfos(Context context, Set<Long> threads, SortedSet<NotificationInfo> notificationSet) {
    ContentResolver resolver = context.getContentResolver();
    // This query looks like this when logged:
    // I/Database(  147): elapsedTime4Sql|/data/data/com.android.providers.telephony/databases/
    // mmssms.db|0.362 ms|SELECT thread_id, date, _id, sub, sub_cs FROM pdu WHERE ((msg_box=1
    // AND seen=0 AND (m_type=130 OR m_type=132))) ORDER BY date desc
    Cursor cursor = SqliteWrapper.query(context, resolver, Mms.CONTENT_URI, MMS_STATUS_PROJECTION, NEW_INCOMING_MM_CONSTRAINT, null, Mms.DATE + " desc");
    if (cursor == null) {
        return;
    }
    try {
        while (cursor.moveToNext()) {
            long msgId = cursor.getLong(COLUMN_MMS_ID);
            Uri msgUri = Mms.CONTENT_URI.buildUpon().appendPath(Long.toString(msgId)).build();
            String address = AddressUtils.getFrom(context, msgUri);
            Contact contact = Contact.get(address, false);
            if (contact.getSendToVoicemail()) {
                // don't notify, skip this one
                continue;
            }
            String subject = getMmsSubject(cursor.getString(COLUMN_SUBJECT), cursor.getInt(COLUMN_SUBJECT_CS));
            subject = MessageUtils.cleanseMmsSubject(context, subject);
            long threadId = cursor.getLong(COLUMN_THREAD_ID);
            long timeMillis = cursor.getLong(COLUMN_DATE) * 1000;
            if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
                Log.d(TAG, "addMmsNotificationInfos: count=" + cursor.getCount() + ", addr = " + address + ", thread_id=" + threadId);
            }
            // Extract the message and/or an attached picture from the first slide
            Bitmap attachedPicture = null;
            String messageBody = null;
            int attachmentType = WorkingMessage.TEXT;
            try {
                GenericPdu pdu = sPduPersister.load(msgUri);
                if (pdu != null && pdu instanceof MultimediaMessagePdu) {
                    SlideshowModel slideshow = SlideshowModel.createFromPduBody(context, ((MultimediaMessagePdu) pdu).getBody());
                    attachmentType = getAttachmentType(slideshow);
                    SlideModel firstSlide = slideshow.get(0);
                    if (firstSlide != null) {
                        if (firstSlide.hasImage()) {
                            int maxDim = dp2Pixels(MAX_BITMAP_DIMEN_DP);
                            attachedPicture = firstSlide.getImage().getBitmap(maxDim, maxDim);
                        }
                        if (firstSlide.hasText()) {
                            messageBody = firstSlide.getText().getText();
                        }
                    }
                }
            } catch (final MmsException e) {
                Log.e(TAG, "MmsException loading uri: " + msgUri, e);
                // skip this bad boy -- don't generate an empty notification
                continue;
            }
            NotificationInfo info = getNewMessageNotificationInfo(context, false, /* isSms */
            address, messageBody, subject, threadId, timeMillis, attachedPicture, contact, attachmentType);
            notificationSet.add(info);
            threads.add(threadId);
        }
    } finally {
        cursor.close();
    }
}
Also used : MultimediaMessagePdu(com.google.android.mms.pdu.MultimediaMessagePdu) SpannableString(android.text.SpannableString) Cursor(android.database.Cursor) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) Contact(com.android.mms.data.Contact) Bitmap(android.graphics.Bitmap) MmsException(com.google.android.mms.MmsException) SlideshowModel(com.android.mms.model.SlideshowModel) GenericPdu(com.google.android.mms.pdu.GenericPdu) SlideModel(com.android.mms.model.SlideModel)

Example 7 with SlideModel

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

the class WorkingMessage method ensureSlideshow.

/**
 * Makes sure mSlideshow is set up.
 */
private void ensureSlideshow() {
    if (mSlideshow != null) {
        return;
    }
    SlideshowModel slideshow = SlideshowModel.createNew(mActivity);
    SlideModel slide = new SlideModel(slideshow);
    slideshow.add(slide);
    mSlideshow = slideshow;
}
Also used : SlideshowModel(com.android.mms.model.SlideshowModel) SlideModel(com.android.mms.model.SlideModel)

Example 8 with SlideModel

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

the class WorkingMessage method removeThumbnailsFromCache.

public static void removeThumbnailsFromCache(SlideshowModel slideshow) {
    if (slideshow != null) {
        ThumbnailManager thumbnailManager = MmsApp.getApplication().getThumbnailManager();
        boolean removedSomething = false;
        Iterator<SlideModel> iterator = slideshow.iterator();
        while (iterator.hasNext()) {
            SlideModel slideModel = iterator.next();
            if (slideModel.hasImage()) {
                thumbnailManager.removeThumbnail(slideModel.getImage().getUri());
                removedSomething = true;
            } else if (slideModel.hasVideo()) {
                thumbnailManager.removeThumbnail(slideModel.getVideo().getUri());
                removedSomething = true;
            }
        }
        if (removedSomething) {
            // HACK: the keys to the thumbnail cache are the part uris, such as mms/part/3
            // Because the part table doesn't have auto-increment ids, the part ids are reused
            // when a message or thread is deleted. For now, we're clearing the whole thumbnail
            // cache so we don't retrieve stale images when part ids are reused. This will be
            // fixed in the next release in the mms provider.
            MmsApp.getApplication().getThumbnailManager().clearBackingStore();
        }
    }
}
Also used : ThumbnailManager(com.android.mms.util.ThumbnailManager) SlideModel(com.android.mms.model.SlideModel)

Example 9 with SlideModel

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

the class WorkingMessage method changeMedia.

/**
 * Change the message's attachment to the data in the specified Uri.
 * Used only for single-slide ("attachment mode") messages. If the attachment fails to
 * attach, restore the slide to its original state.
 */
private int changeMedia(int type, Uri uri, SlideshowEditor slideShowEditor) {
    SlideModel originalSlide = mSlideshow.get(0);
    if (originalSlide != null) {
        // remove the original slide
        slideShowEditor.removeSlide(0);
    }
    slideShowEditor.addNewSlide(0);
    // get the new empty slide
    SlideModel slide = mSlideshow.get(0);
    int result = OK;
    if (slide == null) {
        Log.w(LogTag.TAG, "[WorkingMessage] changeMedia: no slides!");
        return result;
    }
    // Clear the attachment type since we removed all the attachments. If this isn't cleared
    // and the slide.add fails (for instance, a selected video could be too big), we'll be
    // left in a state where we think we have an attachment, but it's been removed from the
    // slide.
    mAttachmentType = TEXT;
    // If we're changing to text, just bail out.
    if (type == TEXT) {
        return result;
    }
    result = internalChangeMedia(type, uri, 0, slideShowEditor);
    if (result != OK) {
        // remove the failed slide
        slideShowEditor.removeSlide(0);
        if (originalSlide != null) {
            // restore the original slide.
            slideShowEditor.addSlide(0, originalSlide);
        }
    }
    return result;
}
Also used : SlideModel(com.android.mms.model.SlideModel)

Example 10 with SlideModel

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

the class WorkingMessage method syncTextToSlideshow.

/**
 * Moves the message text into the slideshow.  Should be called any time
 * the message is about to be sent or written to disk.
 */
private void syncTextToSlideshow() {
    if (mSlideshow == null || mSlideshow.size() != 1)
        return;
    SlideModel slide = mSlideshow.get(0);
    TextModel text;
    if (!slide.hasText()) {
        // Add a TextModel to slide 0 if one doesn't already exist
        text = new TextModel(mActivity, ContentType.TEXT_PLAIN, "text_0.txt", mSlideshow.getLayout().getTextRegion());
        slide.add(text);
    } else {
        // Otherwise just reuse the existing one.
        text = slide.getText();
    }
    text.setText(mText);
}
Also used : TextModel(com.android.mms.model.TextModel) SlideModel(com.android.mms.model.SlideModel)

Aggregations

SlideModel (com.android.mms.model.SlideModel)17 SlideshowModel (com.android.mms.model.SlideshowModel)4 TextModel (com.android.mms.model.TextModel)3 Intent (android.content.Intent)2 ContentResolver (android.content.ContentResolver)1 Cursor (android.database.Cursor)1 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 SpannableString (android.text.SpannableString)1 SubMenu (android.view.SubMenu)1 Contact (com.android.mms.data.Contact)1 AudioModel (com.android.mms.model.AudioModel)1 MediaModel (com.android.mms.model.MediaModel)1 VideoModel (com.android.mms.model.VideoModel)1 ThumbnailManager (com.android.mms.util.ThumbnailManager)1 MmsException (com.google.android.mms.MmsException)1 GenericPdu (com.google.android.mms.pdu.GenericPdu)1 MultimediaMessagePdu (com.google.android.mms.pdu.MultimediaMessagePdu)1