Search in sources :

Example 1 with WorkingMessage

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

the class ComposeMessageActivity method updateCounter.

private void updateCounter(CharSequence text, int start, int before, int count) {
    WorkingMessage workingMessage = mWorkingMessage;
    if (workingMessage.requiresMms()) {
        // If we're not removing text (i.e. no chance of converting back to SMS
        // because of this change) and we're in MMS mode, just bail out since we
        // then won't have to calculate the length unnecessarily.
        final boolean textRemoved = (before > count);
        if (!textRemoved) {
            showSmsOrMmsSendButton(workingMessage.requiresMms());
            return;
        }
    }
    int[] params = SmsMessage.calculateLength(text, false);
    /* SmsMessage.calculateLength returns an int[4] with:
             *   int[0] being the number of SMS's required,
             *   int[1] the number of code units used,
             *   int[2] is the number of code units remaining until the next message.
             *   int[3] is the encoding type that should be used for the message.
             */
    int msgCount = params[0];
    int remainingInCurrentMessage = params[2];
    if (!MmsConfig.getMultipartSmsEnabled()) {
        // The provider doesn't support multi-part sms's so as soon as the user types
        // an sms longer than one segment, we have to turn the message into an mms.
        mWorkingMessage.setLengthRequiresMms(msgCount > 1, true);
    } else {
        int threshold = MmsConfig.getSmsToMmsTextThreshold();
        mWorkingMessage.setLengthRequiresMms(threshold > 0 && msgCount > threshold, true);
    }
    // Show the counter only if:
    // - We are not in MMS mode
    // - We are going to send more than one message OR we are getting close
    boolean showCounter = false;
    if (!workingMessage.requiresMms() && (msgCount > 1 || remainingInCurrentMessage <= CHARS_REMAINING_BEFORE_COUNTER_SHOWN)) {
        showCounter = true;
    }
    showSmsOrMmsSendButton(workingMessage.requiresMms());
    if (showCounter) {
        // Update the remaining characters and number of messages required.
        String counterText = msgCount > 1 ? remainingInCurrentMessage + " / " + msgCount : String.valueOf(remainingInCurrentMessage);
        mTextCounter.setText(counterText);
        mTextCounter.setVisibility(View.VISIBLE);
    } else {
        mTextCounter.setVisibility(View.GONE);
    }
}
Also used : WorkingMessage(com.android.mms.data.WorkingMessage) SpannableString(android.text.SpannableString)

Example 2 with WorkingMessage

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

the class ComposeMessageActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (LogTag.VERBOSE) {
        log("onActivityResult: requestCode=" + requestCode + ", resultCode=" + resultCode + ", data=" + data);
    }
    // We're back!
    mWaitingForSubActivity = false;
    mShouldLoadDraft = false;
    if (mWorkingMessage.isFakeMmsForDraft()) {
        // We no longer have to fake the fact we're an Mms. At this point we are or we aren't,
        // based on attachments and other Mms attrs.
        mWorkingMessage.removeFakeMmsForDraft();
    }
    if (requestCode == REQUEST_CODE_PICK) {
        mWorkingMessage.asyncDeleteDraftSmsMessage(mConversation);
    }
    if (requestCode == REQUEST_CODE_ADD_CONTACT) {
        // and it will update the title bar, etc.
        if (mAddContactIntent != null) {
            String address = mAddContactIntent.getStringExtra(ContactsContract.Intents.Insert.EMAIL);
            if (address == null) {
                address = mAddContactIntent.getStringExtra(ContactsContract.Intents.Insert.PHONE);
            }
            if (address != null) {
                Contact contact = Contact.get(address, false);
                if (contact != null) {
                    contact.reload();
                }
            }
        }
    }
    if (resultCode != RESULT_OK) {
        if (LogTag.VERBOSE)
            log("bail due to resultCode=" + resultCode);
        return;
    }
    switch(requestCode) {
        case REQUEST_CODE_CREATE_SLIDESHOW:
            if (data != null) {
                WorkingMessage newMessage = WorkingMessage.load(this, data.getData());
                if (newMessage != null) {
                    mWorkingMessage = newMessage;
                    mWorkingMessage.setConversation(mConversation);
                    updateThreadIdIfRunning();
                    drawTopPanel(false);
                    updateSendButtonState();
                }
            }
            break;
        case REQUEST_CODE_TAKE_PICTURE:
            {
                // create a file based uri and pass to addImage(). We want to read the JPEG
                // data directly from file (using UriImage) instead of decoding it into a Bitmap,
                // which takes up too much memory and could easily lead to OOM.
                File file = new File(TempFileProvider.getScrapPath(this));
                Uri uri = Uri.fromFile(file);
                // Remove the old captured picture's thumbnail from the cache
                MmsApp.getApplication().getThumbnailManager().removeThumbnail(uri);
                addImageAsync(uri, false);
                break;
            }
        case REQUEST_CODE_ATTACH_IMAGE:
            {
                if (data != null) {
                    addImageAsync(data.getData(), false);
                }
                break;
            }
        case REQUEST_CODE_TAKE_VIDEO:
            Uri videoUri = TempFileProvider.renameScrapFile(".3gp", null, this);
            // Remove the old captured video's thumbnail from the cache
            MmsApp.getApplication().getThumbnailManager().removeThumbnail(videoUri);
            // can handle null videoUri
            addVideoAsync(videoUri, false);
            break;
        case REQUEST_CODE_ATTACH_VIDEO:
            if (data != null) {
                addVideoAsync(data.getData(), false);
            }
            break;
        case REQUEST_CODE_ATTACH_SOUND:
            {
                Uri uri = (Uri) data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
                if (Settings.System.DEFAULT_RINGTONE_URI.equals(uri)) {
                    break;
                }
                addAudio(uri);
                break;
            }
        case REQUEST_CODE_RECORD_SOUND:
            if (data != null) {
                addAudio(data.getData());
            }
            break;
        case REQUEST_CODE_ECM_EXIT_DIALOG:
            boolean outOfEmergencyMode = data.getBooleanExtra(EXIT_ECM_RESULT, false);
            if (outOfEmergencyMode) {
                sendMessage(false);
            }
            break;
        case REQUEST_CODE_PICK:
            if (data != null) {
                processPickResult(data);
            }
            break;
        default:
            if (LogTag.VERBOSE)
                log("bail due to unknown requestCode=" + requestCode);
            break;
    }
}
Also used : WorkingMessage(com.android.mms.data.WorkingMessage) SpannableString(android.text.SpannableString) File(java.io.File) Uri(android.net.Uri) Contact(com.android.mms.data.Contact) QuickContact(android.provider.ContactsContract.QuickContact)

Example 3 with WorkingMessage

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

the class ComposeMessageActivityTests method testCreateManyThreads.

// Here's how to execute just this one test:
// runtest -m testCreateManyThreads mms -c com.android.mms.ui.ComposeMessageActivityTests
// This test intentionally uses the UI functions to create the threads rather than adding
// the threads directly to the mms provider's threads table.
@LargeTest
public void testCreateManyThreads() {
    for (int i = 0; i < 10; i++) {
        String phoneNum = String.format("424-123-%04d", i);
        ContactList contactList = ContactList.getByNumbers(phoneNum, false, false);
        Conversation conv = Conversation.get(mActivity, contactList, false);
        WorkingMessage workingMsg = WorkingMessage.loadDraft(mActivity, conv, null);
        workingMsg.setConversation(conv);
        workingMsg.setText("This is test #" + i + " thread id: " + conv.getThreadId());
        // Log.i(TAG, "[testCreateManyThreads] workingMsg: ");
        // workingMsg.dump();
        workingMsg.saveDraft(false);
    }
}
Also used : WorkingMessage(com.android.mms.data.WorkingMessage) Conversation(com.android.mms.data.Conversation) ContactList(com.android.mms.data.ContactList) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 4 with WorkingMessage

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

the class ComposeMessageActivity method editMmsMessageItem.

private void editMmsMessageItem(MessageItem msgItem) {
    // Load the selected message in as the working message.
    WorkingMessage newWorkingMessage = WorkingMessage.load(this, msgItem.mMessageUri);
    if (newWorkingMessage == null) {
        return;
    }
    // Discard the current message in progress.
    mWorkingMessage.discard();
    mWorkingMessage = newWorkingMessage;
    mWorkingMessage.setConversation(mConversation);
    drawTopPanel(false);
    // WorkingMessage.load() above only loads the slideshow. Set the
    // subject here because we already know what it is and avoid doing
    // another DB lookup in load() just to get it.
    mWorkingMessage.setSubject(msgItem.mSubject, false);
    if (mWorkingMessage.hasSubject()) {
        showSubjectEditor(true);
    }
}
Also used : WorkingMessage(com.android.mms.data.WorkingMessage)

Aggregations

WorkingMessage (com.android.mms.data.WorkingMessage)4 SpannableString (android.text.SpannableString)2 Uri (android.net.Uri)1 QuickContact (android.provider.ContactsContract.QuickContact)1 LargeTest (android.test.suitebuilder.annotation.LargeTest)1 Contact (com.android.mms.data.Contact)1 ContactList (com.android.mms.data.ContactList)1 Conversation (com.android.mms.data.Conversation)1 File (java.io.File)1