Search in sources :

Example 1 with SlideshowModel

use of com.moez.QKSMS.model.SlideshowModel in project qksms by moezbhatti.

the class NotificationManager method buildSingleMessageNotification.

/**
 * Builds the actual notification for the single message. This code can be called at different points in execution
 * depending on whether or not the MMS data has been downloaded
 */
private static void buildSingleMessageNotification(final Context context, ArrayList<MessageItem> messages, long threadId, final NotificationCompat.Builder builder, ConversationPrefsHelper conversationPrefs, final Integer privateNotifications) {
    MessageItem message = messages.get(0);
    Intent threadIntent = new Intent(context, MainActivity.class);
    threadIntent.putExtra(MessageListActivity.ARG_THREAD_ID, threadId);
    final PendingIntent threadPI = PendingIntent.getActivity(context, buildRequestCode(threadId, 1), threadIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    Intent readIntent = new Intent(ACTION_MARK_READ);
    readIntent.putExtra("thread_id", threadId);
    final PendingIntent readPI = PendingIntent.getBroadcast(context, buildRequestCode(threadId, 2), readIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    Intent seenIntent = new Intent(ACTION_MARK_SEEN);
    final PendingIntent seenPI = PendingIntent.getBroadcast(context, buildRequestCode(threadId, 4), seenIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    int unreadMessageCount = SmsHelper.getUnreadMessageCount(context);
    String body;
    String title;
    NotificationCompat.Style nstyle = null;
    switch(privateNotifications) {
        case // Hide nothing
        0:
            body = message.mBody;
            title = message.mContact;
            nstyle = new NotificationCompat.BigTextStyle().bigText(message.mBody);
            break;
        case // Hide message
        1:
            body = sRes.getString(R.string.new_message);
            title = message.mContact;
            break;
        case // Hide sender & message
        2:
            body = sRes.getString(R.string.new_message);
            title = "QKSMS";
            break;
        default:
            body = message.mBody;
            title = message.mContact;
            nstyle = null;
    }
    builder.setContentTitle(title).setContentText(body).setLargeIcon(getLargeIcon(context, Contact.get(message.mAddress, false), privateNotifications)).setContentIntent(threadPI).setNumber(unreadMessageCount).setStyle(nstyle).setColor(ThemeManager.getColor()).addAction(R.drawable.ic_accept, sRes.getString(R.string.read), readPI).extend(RemoteMessagingReceiver.getConversationExtender(context, message.mContact, message.mAddress, threadId)).setDeleteIntent(seenPI);
    if (Build.VERSION.SDK_INT < 24) {
        Intent replyIntent = new Intent(context, QKReplyActivity.class);
        replyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        replyIntent.putExtra(QKReplyActivity.EXTRA_THREAD_ID, threadId);
        replyIntent.putExtra(QKReplyActivity.EXTRA_SHOW_KEYBOARD, true);
        PendingIntent replyPI = PendingIntent.getActivity(context, buildRequestCode(threadId, 0), replyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(R.drawable.ic_reply, sRes.getString(R.string.reply), replyPI);
    } else {
        builder.addAction(RemoteMessagingReceiver.getReplyAction(context, message.mAddress, threadId));
    }
    if (conversationPrefs.getDimissedReadEnabled()) {
        builder.setDeleteIntent(readPI);
    }
    if (conversationPrefs.getCallButtonEnabled()) {
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:" + message.mAddress));
        PendingIntent callPI = PendingIntent.getActivity(context, buildRequestCode(threadId, 3), callIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(R.drawable.ic_call, sRes.getString(R.string.call), callPI);
    }
    if (message.isMms()) {
        Log.d(TAG, "Message is MMS");
        SlideshowModel model = message.mSlideshow;
        if (model != null && model.isSimple() && model.get(0).getImage() != null) {
            Log.d(TAG, "MMS type: image");
            ImageModel imageModel = model.get(0).getImage();
            Bitmap image = imageModel.getBitmap(imageModel.getWidth(), imageModel.getHeight());
            NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle().setBigContentTitle(message.mContact).setSummaryText(message.mBody).bigLargeIcon(getLargeIcon(context, Contact.get(message.mAddress, false), privateNotifications)).bigPicture(image);
            if (privateNotifications == 0)
                builder.setStyle(style);
            else
                builder.setStyle(null);
        } else {
            Log.d(TAG, "MMS Type: not an image lol");
            if (privateNotifications == 0)
                builder.setStyle(new NotificationCompat.BigTextStyle().bigText(message.mBody));
            else
                builder.setStyle(null);
        }
    }
    NotificationManager.notify(context, (int) threadId, builder.build());
}
Also used : MessageItem(com.moez.QKSMS.ui.messagelist.MessageItem) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Bitmap(android.graphics.Bitmap) SlideshowModel(com.moez.QKSMS.model.SlideshowModel) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) ImageModel(com.moez.QKSMS.model.ImageModel)

Example 2 with SlideshowModel

use of com.moez.QKSMS.model.SlideshowModel in project qksms by moezbhatti.

the class PduLoaderManager method getPdu.

public ItemLoadedFuture getPdu(Uri uri, boolean requestSlideshow, final ItemLoadedCallback<PduLoaded> callback) {
    if (uri == null) {
        throw new NullPointerException();
    }
    PduCacheEntry cacheEntry = null;
    synchronized (mPduCache) {
        if (!mPduCache.isUpdating(uri)) {
            cacheEntry = mPduCache.get(uri);
        }
    }
    final SlideshowModel slideshow = (requestSlideshow && !DEBUG_DISABLE_CACHE) ? mSlideshowCache.get(uri) : null;
    final boolean slideshowExists = !requestSlideshow || slideshow != null;
    final boolean pduExists = cacheEntry != null && cacheEntry.getPdu() != null;
    final boolean taskExists = mPendingTaskUris.contains(uri);
    final boolean newTaskRequired = (!pduExists || !slideshowExists) && !taskExists;
    final boolean callbackRequired = callback != null;
    if (pduExists && slideshowExists) {
        if (callbackRequired) {
            PduLoaded pduLoaded = new PduLoaded(cacheEntry.getPdu(), slideshow);
            callback.onItemLoaded(pduLoaded, null);
        }
        return new NullItemLoadedFuture();
    }
    if (callbackRequired) {
        addCallback(uri, callback);
    }
    if (newTaskRequired) {
        mPendingTaskUris.add(uri);
        Runnable task = new PduTask(uri, requestSlideshow);
        mExecutor.execute(task);
    }
    return new ItemLoadedFuture() {

        private boolean mIsDone;

        public void cancel(Uri uri) {
            cancelCallback(callback);
            // the pdu and/or slideshow might be half loaded. Make sure
            removePdu(uri);
        // we load fresh the next time this uri is requested.
        }

        public void setIsDone(boolean done) {
            mIsDone = done;
        }

        public boolean isDone() {
            return mIsDone;
        }
    };
}
Also used : SlideshowModel(com.moez.QKSMS.model.SlideshowModel) PduCacheEntry(com.google.android.mms.util_alt.PduCacheEntry) Uri(android.net.Uri)

Example 3 with SlideshowModel

use of com.moez.QKSMS.model.SlideshowModel in project qksms by moezbhatti.

the class SlideshowActivity method onCreate.

@Override
public void onCreate(Bundle icicle) {
    // Play slide-show in full-screen mode.
    supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(icicle);
    mHandler = new Handler();
    getWindow().setFormat(PixelFormat.TRANSLUCENT);
    setContentView(R.layout.view_slideshow);
    Intent intent = getIntent();
    Uri msg = intent.getData();
    final SlideshowModel model;
    try {
        model = SlideshowModel.createFromMessageUri(this, msg);
        mSlideCount = model.size();
    } catch (MmsException e) {
        Log.e(TAG, "Cannot present the slide show.", e);
        finish();
        return;
    }
    mSlideView = (SlideView) findViewById(R.id.slide_view);
    new SlideshowPresenter(this, mSlideView, model);
    mHandler.post(new Runnable() {

        private boolean isRotating() {
            return mSmilPlayer.isPausedState() || mSmilPlayer.isPlayingState() || mSmilPlayer.isPlayedState();
        }

        public void run() {
            mSmilPlayer = SmilPlayer.getPlayer();
            if (mSlideCount > 1) {
                // Only show the slideshow controller if we have more than a single slide.
                // Otherwise, when we play a sound on a single slide, it appears like
                // the slide controller should control the sound (seeking, ff'ing, etc).
                initMediaController();
                mSlideView.setMediaController(mMediaController);
            }
            // Use SmilHelper.getDocument() to ensure rebuilding the
            // entire SMIL document.
            mSmilDoc = SmilHelper.getDocument(model);
            if (isMMSConformance(mSmilDoc)) {
                int imageLeft = 0;
                int imageTop = 0;
                int textLeft = 0;
                int textTop = 0;
                LayoutModel layout = model.getLayout();
                if (layout != null) {
                    RegionModel imageRegion = layout.getImageRegion();
                    if (imageRegion != null) {
                        imageLeft = imageRegion.getLeft();
                        imageTop = imageRegion.getTop();
                    }
                    RegionModel textRegion = layout.getTextRegion();
                    if (textRegion != null) {
                        textLeft = textRegion.getLeft();
                        textTop = textRegion.getTop();
                    }
                }
                mSlideView.enableMMSConformanceMode(textLeft, textTop, imageLeft, imageTop);
            }
            if (DEBUG) {
                ByteArrayOutputStream ostream = new ByteArrayOutputStream();
                SmilXmlSerializer.serialize(mSmilDoc, ostream);
                if (LOCAL_LOGV) {
                    Log.v(TAG, ostream.toString());
                }
            }
            // Add event listener.
            ((EventTarget) mSmilDoc).addEventListener(SmilDocumentImpl.SMIL_DOCUMENT_END_EVENT, SlideshowActivity.this, false);
            mSmilPlayer.init(mSmilDoc);
            if (isRotating()) {
                mSmilPlayer.reload();
            } else {
                mSmilPlayer.play();
            }
        }
    });
}
Also used : MmsException(com.google.android.mms.MmsException) SlideshowModel(com.moez.QKSMS.model.SlideshowModel) Handler(android.os.Handler) Intent(android.content.Intent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Uri(android.net.Uri) RegionModel(com.moez.QKSMS.model.RegionModel) LayoutModel(com.moez.QKSMS.model.LayoutModel)

Example 4 with SlideshowModel

use of com.moez.QKSMS.model.SlideshowModel in project qksms by moezbhatti.

the class MmsThumbnailPresenter method present.

@Override
public void present(ItemLoadedCallback callback) {
    mOnLoadedCallback = callback;
    SlideModel slide = ((SlideshowModel) mModel).get(0);
    if (slide != null) {
        presentFirstSlide((SlideViewInterface) mView, slide);
    }
}
Also used : SlideshowModel(com.moez.QKSMS.model.SlideshowModel) SlideModel(com.moez.QKSMS.model.SlideModel)

Aggregations

SlideshowModel (com.moez.QKSMS.model.SlideshowModel)4 Intent (android.content.Intent)2 Uri (android.net.Uri)2 PendingIntent (android.app.PendingIntent)1 Bitmap (android.graphics.Bitmap)1 Handler (android.os.Handler)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 MmsException (com.google.android.mms.MmsException)1 PduCacheEntry (com.google.android.mms.util_alt.PduCacheEntry)1 ImageModel (com.moez.QKSMS.model.ImageModel)1 LayoutModel (com.moez.QKSMS.model.LayoutModel)1 RegionModel (com.moez.QKSMS.model.RegionModel)1 SlideModel (com.moez.QKSMS.model.SlideModel)1 MessageItem (com.moez.QKSMS.ui.messagelist.MessageItem)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1