Search in sources :

Example 36 with ContentValues

use of android.content.ContentValues in project qksms by moezbhatti.

the class Conversation method blockingMarkAllMmsMessagesAsSeen.

private static void blockingMarkAllMmsMessagesAsSeen(final Context context) {
    ContentResolver resolver = context.getContentResolver();
    Cursor cursor = resolver.query(Mms.Inbox.CONTENT_URI, SEEN_PROJECTION, "seen=0", null, null);
    int count = 0;
    if (cursor != null) {
        try {
            count = cursor.getCount();
        } finally {
            cursor.close();
        }
    }
    if (count == 0) {
        return;
    }
    if (DELETEDEBUG || Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
        Log.d(TAG, "mark " + count + " MMS msgs as seen");
    }
    ContentValues values = new ContentValues(1);
    values.put("seen", 1);
    resolver.update(Mms.Inbox.CONTENT_URI, values, "seen=0", null);
}
Also used : ContentValues(android.content.ContentValues) Cursor(android.database.Cursor) ContentResolver(android.content.ContentResolver)

Example 37 with ContentValues

use of android.content.ContentValues in project qksms by moezbhatti.

the class RecipientIdCache method updateCanonicalAddressInDb.

private void updateCanonicalAddressInDb(long id, String number) {
    if (LogTag.VERBOSE || Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
        Log.d(TAG, "[RecipientIdCache] updateCanonicalAddressInDb: id=" + id + ", number=" + number);
    }
    final ContentValues values = new ContentValues();
    values.put(Telephony.CanonicalAddressesColumns.ADDRESS, number);
    final StringBuilder buf = new StringBuilder(Telephony.CanonicalAddressesColumns._ID);
    buf.append('=').append(id);
    final Uri uri = ContentUris.withAppendedId(sSingleCanonicalAddressUri, id);
    final ContentResolver cr = mContext.getContentResolver();
    // We're running on the UI thread so just fire & forget, hope for the best.
    // (We were ignoring the return value anyway...)
    new Thread("updateCanonicalAddressInDb") {

        public void run() {
            cr.update(uri, values, buf.toString(), null);
        }
    }.start();
}
Also used : ContentValues(android.content.ContentValues) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Example 38 with ContentValues

use of android.content.ContentValues in project qksms by moezbhatti.

the class Conversation method blockingMarkAllSmsMessagesAsSeen.

private static void blockingMarkAllSmsMessagesAsSeen(final Context context) {
    ContentResolver resolver = context.getContentResolver();
    Cursor cursor = resolver.query(Sms.Inbox.CONTENT_URI, SEEN_PROJECTION, "seen=0", null, null);
    int count = 0;
    if (cursor != null) {
        try {
            count = cursor.getCount();
        } finally {
            cursor.close();
        }
    }
    if (count == 0) {
        return;
    }
    if (DELETEDEBUG || Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
        Log.d(TAG, "mark " + count + " SMS msgs as seen");
    }
    ContentValues values = new ContentValues(1);
    values.put("seen", 1);
    resolver.update(Sms.Inbox.CONTENT_URI, values, "seen=0", null);
}
Also used : ContentValues(android.content.ContentValues) Cursor(android.database.Cursor) ContentResolver(android.content.ContentResolver)

Example 39 with ContentValues

use of android.content.ContentValues in project qksms by moezbhatti.

the class ConversationLegacy method saveDraft.

public void saveDraft(final String draft) {
    clearDrafts();
    if (draft.length() > 0) {
        try {
            DraftCache.getInstance().setSavingDraft(true);
            DraftCache.getInstance().setDraftState(threadId, true);
            ConversationLegacy.this.draft = draft;
            ContentResolver contentResolver = context.getContentResolver();
            ContentValues cv = new ContentValues();
            cv.put("address", getAddress());
            cv.put("body", draft);
            contentResolver.insert(SmsHelper.DRAFTS_CONTENT_PROVIDER, cv);
        } finally {
            DraftCache.getInstance().setSavingDraft(false);
        }
    } else {
        ConversationLegacy.this.draft = null;
    }
    Toast.makeText(context, R.string.toast_draft, Toast.LENGTH_SHORT).show();
}
Also used : ContentValues(android.content.ContentValues) ContentResolver(android.content.ContentResolver)

Example 40 with ContentValues

use of android.content.ContentValues in project qksms by moezbhatti.

the class ConversationLegacy method markUnread.

public void markUnread() {
    new DefaultSmsHelper(context, R.string.not_default_mark_unread).showIfNotDefault(null);
    try {
        cursor = context.getContentResolver().query(getUri(), MessageColumns.PROJECTION, null, null, SmsHelper.sortDateDesc);
        cursor.moveToFirst();
        MessageColumns.ColumnsMap columnsMap = new MessageColumns.ColumnsMap(cursor);
        MessageItem message = new MessageItem(context, cursor.getString(columnsMap.mColumnMsgType), cursor, columnsMap, null, true);
        if (message.isMe()) {
            while (cursor.moveToNext()) {
                MessageItem message2 = new MessageItem(context, cursor.getString(columnsMap.mColumnMsgType), cursor, columnsMap, null, true);
                if (!message2.isMe()) {
                    message = message2;
                    break;
                }
            }
        }
        ContentValues cv = new ContentValues();
        cv.put("read", false);
        cv.put("seen", false);
        context.getContentResolver().update(message.mMessageUri, cv, null, null);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    NotificationManager.create(context);
}
Also used : MessageItem(com.moez.QKSMS.ui.messagelist.MessageItem) ContentValues(android.content.ContentValues) DefaultSmsHelper(com.moez.QKSMS.ui.dialog.DefaultSmsHelper) MessageColumns(com.moez.QKSMS.ui.messagelist.MessageColumns)

Aggregations

ContentValues (android.content.ContentValues)4022 Cursor (android.database.Cursor)721 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)638 Uri (android.net.Uri)619 Test (org.junit.Test)374 SQLException (android.database.SQLException)231 ContentResolver (android.content.ContentResolver)212 ArrayList (java.util.ArrayList)192 Intent (android.content.Intent)163 File (java.io.File)156 IOException (java.io.IOException)131 RemoteException (android.os.RemoteException)96 CursorAssert.assertThatCursor (org.hisp.dhis.android.core.data.database.CursorAssert.assertThatCursor)91 NonNull (android.support.annotation.NonNull)74 Date (java.util.Date)73 MediumTest (android.test.suitebuilder.annotation.MediumTest)63 HashMap (java.util.HashMap)62 JSONException (org.json.JSONException)60 SQLiteConstraintException (android.database.sqlite.SQLiteConstraintException)55 SQLiteException (android.database.sqlite.SQLiteException)53