Search in sources :

Example 6 with Contact

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

the class SmsReceiverService method storeMessage.

// private static int count = 0;
private Uri storeMessage(Context context, SmsMessage[] msgs, int error) {
    SmsMessage sms = msgs[0];
    // Store the message in the content provider.
    ContentValues values = extractContentValues(sms);
    values.put(Sms.ERROR_CODE, error);
    int pduCount = msgs.length;
    if (pduCount == 1) {
        // There is only one part, so grab the body directly.
        values.put(Inbox.BODY, replaceFormFeeds(sms.getDisplayMessageBody()));
    } else {
        // Build up the body from the parts.
        StringBuilder body = new StringBuilder();
        for (int i = 0; i < pduCount; i++) {
            sms = msgs[i];
            if (sms.mWrappedSmsMessage != null) {
                body.append(sms.getDisplayMessageBody());
            }
        }
        values.put(Inbox.BODY, replaceFormFeeds(body.toString()));
    }
    // Make sure we've got a thread id so after the insert we'll be able to delete
    // excess messages.
    Long threadId = values.getAsLong(Sms.THREAD_ID);
    String address = values.getAsString(Sms.ADDRESS);
    if (!TextUtils.isEmpty(address)) {
        Contact cacheContact = Contact.get(address, true);
        if (cacheContact != null) {
            address = cacheContact.getNumber();
        }
    } else {
        address = getString(R.string.unknown_sender);
        values.put(Sms.ADDRESS, address);
    }
    if (((threadId == null) || (threadId == 0)) && (address != null)) {
        threadId = Conversation.getOrCreateThreadId(context, address);
        values.put(Sms.THREAD_ID, threadId);
    }
    ContentResolver resolver = context.getContentResolver();
    Uri insertedUri = SqliteWrapper.insert(context, resolver, Inbox.CONTENT_URI, values);
    // Now make sure we're not over the limit in stored messages
    Recycler.getSmsRecycler().deleteOldMessagesByThreadId(context, threadId);
    MmsWidgetProvider.notifyDatasetChanged(context);
    return insertedUri;
}
Also used : ContentValues(android.content.ContentValues) SmsMessage(android.telephony.SmsMessage) Uri(android.net.Uri) Contact(com.android.mms.data.Contact) ContentResolver(android.content.ContentResolver)

Example 7 with Contact

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

the class RecipientsEditor method constructContactsFromInput.

public ContactList constructContactsFromInput(boolean blocking) {
    List<String> numbers = mTokenizer.getNumbers();
    ContactList list = new ContactList();
    for (String number : numbers) {
        Contact contact = Contact.get(number, blocking);
        contact.setNumber(number);
        list.add(contact);
    }
    return list;
}
Also used : SpannableString(android.text.SpannableString) ContactList(com.android.mms.data.ContactList) Contact(com.android.mms.data.Contact)

Example 8 with Contact

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

the class SearchActivity method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    String searchStringParameter = getIntent().getStringExtra(SearchManager.QUERY);
    if (searchStringParameter == null) {
        searchStringParameter = getIntent().getStringExtra("intent_extra_data_key");
    }
    final String searchString = searchStringParameter != null ? searchStringParameter.trim() : searchStringParameter;
    // If we're being launched with a source_id then just go to that particular thread.
    // Work around the fact that suggestions can only launch the search activity, not some
    // arbitrary activity (such as ComposeMessageActivity).
    final Uri u = getIntent().getData();
    if (u != null && u.getQueryParameter("source_id") != null) {
        Thread t = new Thread(new Runnable() {

            public void run() {
                try {
                    long sourceId = Long.parseLong(u.getQueryParameter("source_id"));
                    long whichTable = Long.parseLong(u.getQueryParameter("which_table"));
                    long threadId = getThreadId(sourceId, whichTable);
                    final Intent onClickIntent = new Intent(SearchActivity.this, ComposeMessageActivity.class);
                    onClickIntent.putExtra("highlight", searchString);
                    onClickIntent.putExtra("select_id", sourceId);
                    onClickIntent.putExtra("thread_id", threadId);
                    startActivity(onClickIntent);
                    finish();
                    return;
                } catch (NumberFormatException ex) {
                // ok, we do not have a thread id so continue
                }
            }
        }, "Search thread");
        t.start();
        return;
    }
    setContentView(R.layout.search_activity);
    ContentResolver cr = getContentResolver();
    searchStringParameter = searchStringParameter.trim();
    final ListView listView = getListView();
    listView.setItemsCanFocus(true);
    listView.setFocusable(true);
    listView.setClickable(true);
    // I considered something like "searching..." but typically it will
    // flash on the screen briefly which I found to be more distracting
    // than beneficial.
    // This gets updated when the query completes.
    setTitle("");
    Contact.addListener(mContactListener);
    // When the query completes cons up a new adapter and set our list adapter to that.
    mQueryHandler = new AsyncQueryHandler(cr) {

        protected void onQueryComplete(int token, Object cookie, Cursor c) {
            if (c == null) {
                setTitle(getResources().getQuantityString(R.plurals.search_results_title, 0, 0, searchString));
                return;
            }
            final int threadIdPos = c.getColumnIndex("thread_id");
            final int addressPos = c.getColumnIndex("address");
            final int bodyPos = c.getColumnIndex("body");
            final int rowidPos = c.getColumnIndex("_id");
            int cursorCount = c.getCount();
            setTitle(getResources().getQuantityString(R.plurals.search_results_title, cursorCount, cursorCount, searchString));
            // Note that we're telling the CursorAdapter not to do auto-requeries. If we
            // want to dynamically respond to changes in the search results,
            // we'll have have to add a setOnDataSetChangedListener().
            setListAdapter(new CursorAdapter(SearchActivity.this, c, false) {

                /* no auto-requery */
                @Override
                public void bindView(View view, Context context, Cursor cursor) {
                    final TextView title = (TextView) (view.findViewById(R.id.title));
                    final TextViewSnippet snippet = (TextViewSnippet) (view.findViewById(R.id.subtitle));
                    String address = cursor.getString(addressPos);
                    Contact contact = address != null ? Contact.get(address, false) : null;
                    String titleString = contact != null ? contact.getNameAndNumber() : "";
                    title.setText(titleString);
                    snippet.setText(cursor.getString(bodyPos), searchString);
                    // if the user touches the item then launch the compose message
                    // activity with some extra parameters to highlight the search
                    // results and scroll to the latest part of the conversation
                    // that has a match.
                    final long threadId = cursor.getLong(threadIdPos);
                    final long rowid = cursor.getLong(rowidPos);
                    view.setOnClickListener(new View.OnClickListener() {

                        public void onClick(View v) {
                            final Intent onClickIntent = new Intent(SearchActivity.this, ComposeMessageActivity.class);
                            onClickIntent.putExtra("thread_id", threadId);
                            onClickIntent.putExtra("highlight", searchString);
                            onClickIntent.putExtra("select_id", rowid);
                            startActivity(onClickIntent);
                        }
                    });
                }

                @Override
                public View newView(Context context, Cursor cursor, ViewGroup parent) {
                    LayoutInflater inflater = LayoutInflater.from(context);
                    View v = inflater.inflate(R.layout.search_item, parent, false);
                    return v;
                }
            });
            // ListView seems to want to reject the setFocusable until such time
            // as the list is not empty.  Set it here and request focus.  Without
            // this the arrow keys (and trackball) fail to move the selection.
            listView.setFocusable(true);
            listView.setFocusableInTouchMode(true);
            listView.requestFocus();
            // Remember the query if there are actual results
            if (cursorCount > 0) {
                SearchRecentSuggestions recent = ((MmsApp) getApplication()).getRecentSuggestions();
                if (recent != null) {
                    recent.saveRecentQuery(searchString, getString(R.string.search_history, cursorCount, searchString));
                }
            }
        }
    };
    // don't pass a projection since the search uri ignores it
    Uri uri = Telephony.MmsSms.SEARCH_URI.buildUpon().appendQueryParameter("pattern", searchString).build();
    // kick off a query for the threads which match the search string
    mQueryHandler.startQuery(0, null, uri, null, null, null, null);
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
}
Also used : SpannableString(android.text.SpannableString) Cursor(android.database.Cursor) SearchRecentSuggestions(android.provider.SearchRecentSuggestions) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) CursorAdapter(android.widget.CursorAdapter) ListView(android.widget.ListView) TextView(android.widget.TextView) ActionBar(android.app.ActionBar) Context(android.content.Context) ViewGroup(android.view.ViewGroup) Intent(android.content.Intent) AsyncQueryHandler(android.content.AsyncQueryHandler) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) TextPaint(android.text.TextPaint) Contact(com.android.mms.data.Contact) LayoutInflater(android.view.LayoutInflater)

Example 9 with Contact

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

the class RecyclerTest method storeMessage.

private Uri storeMessage(Context context, String address, String message) {
    // Store the message in the content provider.
    ContentValues values = new ContentValues();
    // values.put(Sms.ERROR_CODE, 0);
    values.put(Inbox.ADDRESS, address);
    // Use now for the timestamp to avoid confusion with clock
    // drift between the handset and the SMSC.
    values.put(Inbox.DATE, new Long(System.currentTimeMillis()));
    values.put(Inbox.PROTOCOL, 0);
    values.put(Inbox.READ, Integer.valueOf(0));
    // if (sms.getPseudoSubject().length() > 0) {
    // values.put(Inbox.SUBJECT, sms.getPseudoSubject());
    // }
    values.put(Inbox.REPLY_PATH_PRESENT, 0);
    values.put(Inbox.SERVICE_CENTER, 0);
    values.put(Inbox.BODY, message);
    // Make sure we've got a thread id so after the insert we'll be able to delete
    // excess messages.
    Long threadId = 0L;
    Contact cacheContact = Contact.get(address, true);
    if (cacheContact != null) {
        address = cacheContact.getNumber();
    }
    if (((threadId == null) || (threadId == 0)) && (address != null)) {
        values.put(Sms.THREAD_ID, Threads.getOrCreateThreadId(context, address));
    }
    ContentResolver resolver = context.getContentResolver();
    Uri insertedUri = SqliteWrapper.insert(context, resolver, Inbox.CONTENT_URI, values);
    // Now make sure we're not over the limit in stored messages
    threadId = values.getAsLong(Sms.THREAD_ID);
    Recycler.getSmsRecycler().deleteOldMessagesByThreadId(context, threadId);
    return insertedUri;
}
Also used : ContentValues(android.content.ContentValues) Uri(android.net.Uri) Contact(com.android.mms.data.Contact) ContentResolver(android.content.ContentResolver)

Example 10 with Contact

use of com.android.mms.data.Contact 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)

Aggregations

Contact (com.android.mms.data.Contact)14 SpannableString (android.text.SpannableString)7 ContentResolver (android.content.ContentResolver)6 Uri (android.net.Uri)6 Cursor (android.database.Cursor)5 Intent (android.content.Intent)4 QuickContact (android.provider.ContactsContract.QuickContact)3 ContactList (com.android.mms.data.ContactList)3 ContentValues (android.content.ContentValues)2 Drawable (android.graphics.drawable.Drawable)2 ActionBar (android.app.ActionBar)1 AsyncQueryHandler (android.content.AsyncQueryHandler)1 Context (android.content.Context)1 Bitmap (android.graphics.Bitmap)1 SearchRecentSuggestions (android.provider.SearchRecentSuggestions)1 SmsMessage (android.telephony.SmsMessage)1 Spanned (android.text.Spanned)1 TextPaint (android.text.TextPaint)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1