Example usage for android.content ContentUris withAppendedId

List of usage examples for android.content ContentUris withAppendedId

Introduction

In this page you can find the example usage for android.content ContentUris withAppendedId.

Prototype

public static Uri withAppendedId(Uri contentUri, long id) 

Source Link

Document

Appends the given ID to the end of the path.

Usage

From source file:com.android.mms.ui.MessageUtils.java

/** M: Move this functiom from compose activity to this class.*/
public static boolean isRestrictedType(Context context, long msgId) {
    PduBody body = PduBodyCache.getPduBody(context, ContentUris.withAppendedId(Mms.CONTENT_URI, msgId));
    if (body == null) {
        return false;
    }/*w ww  .ja  v  a2 s  .  c  o m*/

    int partNum = body.getPartsNum();
    for (int i = 0; i < partNum; i++) {
        PduPart part = body.getPart(i);
        int width = 0;
        int height = 0;
        String type = new String(part.getContentType());

        int mediaTypeStringId;
        if (MmsContentType.isVideoType(type)) {
            mediaTypeStringId = R.string.type_video;
        } else if (MmsContentType.isAudioType(type) || "application/ogg".equalsIgnoreCase(type)) {
            mediaTypeStringId = R.string.type_audio;
        } else if (MmsContentType.isImageType(type)) {
            mediaTypeStringId = R.string.type_picture;
            InputStream input = null;
            try {
                input = context.getContentResolver().openInputStream(part.getDataUri());
                BitmapFactory.Options opt = new BitmapFactory.Options();
                opt.inJustDecodeBounds = true;
                BitmapFactory.decodeStream(input, null, opt);
                width = opt.outWidth;
                height = opt.outHeight;
            } catch (FileNotFoundException e) {
                // Ignore
                MmsLog.e(TAG, "FileNotFoundException caught while opening stream", e);
            } finally {
                if (null != input) {
                    try {
                        input.close();
                    } catch (IOException e) {
                        // Ignore
                        MmsLog.e(TAG, "IOException caught while closing stream", e);
                    }
                }
            }
        } else {
            continue;
        }
        if (!MmsContentType.isUnrestrictedType(type) || width > MmsConfig.getMaxRestrictedImageWidth()
                || height > MmsConfig.getMaxRestrictedImageHeight()) {
            if (WorkingMessage.sCreationMode == WorkingMessage.RESTRICTED_TYPE) {
                Resources res = context.getResources();
                MessageUtils.showErrorDialog((Activity) context, R.string.unsupported_media_format,
                        R.string.select_different_media, mediaTypeStringId, mediaTypeStringId);
            }
            return true;
        }
    }
    return false;
}

From source file:com.android.contacts.quickcontact.QuickContactActivity.java

private static void populateGPlusOrHangoutsDataItemModel(GPlusOrHangoutsDataItemModel dataModel) {
    final Intent secondIntent = new Intent(Intent.ACTION_VIEW);
    secondIntent.setDataAndType(ContentUris.withAppendedId(Data.CONTENT_URI, dataModel.secondDataItem.getId()),
            dataModel.secondDataItem.getMimeType());
    // There is no guarantee the order the data items come in. Second
    // data item does not necessarily mean it's the alternate.
    // Hangouts video and Add to circles should be alternate. Swap if needed
    if (HANGOUTS_DATA_5_VIDEO.equals(dataModel.dataItem.getContentValues().getAsString(Data.DATA5))
            || GPLUS_PROFILE_DATA_5_ADD_TO_CIRCLE
                    .equals(dataModel.dataItem.getContentValues().getAsString(Data.DATA5))) {
        dataModel.alternateIntent = dataModel.intent;
        dataModel.alternateContentDescription = new StringBuilder(dataModel.header);

        dataModel.intent = secondIntent;
        dataModel.header = dataModel.secondDataItem.buildDataStringForDisplay(dataModel.context,
                dataModel.secondDataItem.getDataKind());
        dataModel.text = dataModel.secondDataItem.getDataKind().typeColumn;
    } else if (HANGOUTS_DATA_5_MESSAGE.equals(dataModel.dataItem.getContentValues().getAsString(Data.DATA5))
            || GPLUS_PROFILE_DATA_5_VIEW_PROFILE
                    .equals(dataModel.dataItem.getContentValues().getAsString(Data.DATA5))) {
        dataModel.alternateIntent = secondIntent;
        dataModel.alternateContentDescription = new StringBuilder(dataModel.secondDataItem
                .buildDataStringForDisplay(dataModel.context, dataModel.secondDataItem.getDataKind()));
    }/* ww  w  . j  a va2 s  . c o m*/
}

From source file:com.android.mms.ui.MessageUtils.java

public static boolean checkNeedNotify(Context context, long threadId, Cursor cursor) {
    if (threadId < 0) {
        MmsLog.w(TAG, "illegal threadId:" + threadId);
        return false;
    }//  w w  w  . j a va  2s . c om
    boolean appNotificationEnabled = true;
    long appMute = 0;
    long appMuteStart = 0;
    boolean threadNotificationEnabled = true;
    long threadMute = 0;
    long threadMuteStart = 0;
    if (!checkAppSettingsNeedNotify(context)) {
        return false;
    }
    if (threadId == 0) {
        return true;
    }
    /// M: check thread settings
    Uri threadSettingsUri = ContentUris.withAppendedId(THREAD_SETTINGS_URI, (int) threadId);
    if (cursor != null) {
        threadNotificationEnabled = cursor.getInt(Conversation.NOTIFICATION_ENABLE) == 0 ? false : true;
        threadMute = cursor.getLong(Conversation.MUTE);
        threadMuteStart = cursor.getLong(Conversation.MUTE_START);
        MmsLog.d(TAG, "before check: threadNotificationEnabled = " + threadNotificationEnabled
                + ", \tthreadMute = " + threadMute + ", \tthreadMuteStart = " + threadMuteStart);
    } else {
        /// M: fix bug ALPS00415754, add some useful log
        MmsLog.d(TAG, "before query threadSettingsUri in checkNeedNotify()");
        Cursor c = context.getContentResolver().query(threadSettingsUri,
                new String[] { Telephony.ThreadSettings.NOTIFICATION_ENABLE, Telephony.ThreadSettings.MUTE,
                        Telephony.ThreadSettings.MUTE_START, Telephony.ThreadSettings.RINGTONE,
                        Telephony.ThreadSettings.VIBRATE },
                null, null, null);
        MmsLog.d(TAG, "after query threadSettingsUri in checkNeedNotify()");

        if (c == null) {
            MmsLog.d(TAG, "cursor is null.");
            return true;
        }
        try {
            if (c.getCount() == 0) {
                MmsLog.d(TAG, "cursor count is 0");
            } else {
                c.moveToFirst();
                threadNotificationEnabled = c.getInt(0) == 0 ? false : true;
                threadMute = c.getLong(1);
                threadMuteStart = c.getLong(2);

                MmsLog.d(TAG, "before check: threadNotificationEnabled = " + threadNotificationEnabled
                        + ", \tthreadMute = " + threadMute + ", \tthreadMuteStart = " + threadMuteStart);
            }
        } finally {
            if (c != null) {
                c.close();
            }
        }
    }

    if (!threadNotificationEnabled) {
        MmsLog.d(TAG, "thread notification is disabled!");
        return false;
    }

    MmsLog.d(TAG, "\t threadMute:" + threadMute + ", threadMute*3600=" + threadMute * 3600
            + "\t threadMuteStart" + threadMuteStart / 1000);

    threadMute = checkThreadMuteTimeout(threadMuteStart, threadMute, threadSettingsUri, context);

    if (threadMute > 0) {
        MmsLog.d(TAG, "thread mute is set!");
        return false;
    }

    return true;
}

From source file:com.android.calendar.EventInfoFragment.java

private boolean saveReminders() {
    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(3);

    // Read reminders from UI
    mReminders = EventViewUtils.reminderItemsToReminders(mReminderViews, mReminderMinuteValues,
            mReminderMethodValues);//from   www.j a v a  2  s .co m
    mOriginalReminders.addAll(mUnsupportedReminders);
    Collections.sort(mOriginalReminders);
    mReminders.addAll(mUnsupportedReminders);
    Collections.sort(mReminders);

    // Check if there are any changes in the reminder
    boolean changed = EditEventHelper.saveReminders(ops, mEventId, mReminders, mOriginalReminders,
            false /* no force save */);

    if (!changed) {
        return false;
    }

    // save new reminders
    AsyncQueryService service = new AsyncQueryService(getActivity());
    service.startBatch(0, null, Calendars.CONTENT_URI.getAuthority(), ops, 0);
    mOriginalReminders = mReminders;
    // Update the "hasAlarm" field for the event
    Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, mEventId);
    int len = mReminders.size();
    boolean hasAlarm = len > 0;
    if (hasAlarm != mHasAlarm) {
        ContentValues values = new ContentValues();
        values.put(Events.HAS_ALARM, hasAlarm ? 1 : 0);
        service.startUpdate(0, null, uri, values, null, null, 0);
    }
    return true;
}

From source file:com.android.exchange.EasSyncService.java

public void run() {
    if (!setupService())
        return;/*from w  w  w . j a v a 2  s  .c  o m*/

    try {
        SyncManager.callback().syncMailboxStatus(mMailboxId, EmailServiceStatus.IN_PROGRESS, 0);
    } catch (RemoteException e1) {
        // Don't care if this fails
    }

    // Whether or not we're the account mailbox
    try {
        mDeviceId = SyncManager.getDeviceId();
        if ((mMailbox == null) || (mAccount == null)) {
            return;
        } else if (mMailbox.mType == Mailbox.TYPE_EAS_ACCOUNT_MAILBOX) {
            runAccountMailbox();
        } else {
            AbstractSyncAdapter target;
            if (mMailbox.mType == Mailbox.TYPE_CONTACTS) {
                target = new ContactsSyncAdapter(mMailbox, this);
            } else if (mMailbox.mType == Mailbox.TYPE_CALENDAR) {
                target = new CalendarSyncAdapter(mMailbox, this);
            } else {
                target = new EmailSyncAdapter(mMailbox, this);
            }
            // We loop here because someone might have put a request in while we were syncing
            // and we've missed that opportunity...
            do {
                if (mRequestTime != 0) {
                    userLog("Looping for user request...");
                    mRequestTime = 0;
                }
                sync(target);
            } while (mRequestTime != 0);
        }
    } catch (EasAuthenticationException e) {
        userLog("Caught authentication error");
        mExitStatus = EXIT_LOGIN_FAILURE;
    } catch (IOException e) {
        String message = e.getMessage();
        userLog("Caught IOException: ", (message == null) ? "No message" : message);
        mExitStatus = EXIT_IO_ERROR;
    } catch (Exception e) {
        userLog("Uncaught exception in EasSyncService", e);
    } finally {
        int status;

        if (!mStop) {
            userLog("Sync finished");
            SyncManager.done(this);
            switch (mExitStatus) {
            case EXIT_IO_ERROR:
                status = EmailServiceStatus.CONNECTION_ERROR;
                break;
            case EXIT_DONE:
                status = EmailServiceStatus.SUCCESS;
                ContentValues cv = new ContentValues();
                cv.put(Mailbox.SYNC_TIME, System.currentTimeMillis());
                String s = "S" + mSyncReason + ':' + status + ':' + mChangeCount;
                cv.put(Mailbox.SYNC_STATUS, s);
                mContentResolver.update(ContentUris.withAppendedId(Mailbox.CONTENT_URI, mMailboxId), cv, null,
                        null);
                break;
            case EXIT_LOGIN_FAILURE:
                status = EmailServiceStatus.LOGIN_FAILED;
                break;
            case EXIT_SECURITY_FAILURE:
                status = EmailServiceStatus.SECURITY_FAILURE;
                // Ask for a new folder list.  This should wake up the account mailbox; a
                // security error in account mailbox should start the provisioning process
                SyncManager.reloadFolderList(mContext, mAccount.mId, true);
                break;
            default:
                status = EmailServiceStatus.REMOTE_EXCEPTION;
                errorLog("Sync ended due to an exception.");
                break;
            }
        } else {
            userLog("Stopped sync finished.");
            status = EmailServiceStatus.SUCCESS;
        }

        try {
            SyncManager.callback().syncMailboxStatus(mMailboxId, status, 0);
        } catch (RemoteException e1) {
            // Don't care if this fails
        }

        // Make sure SyncManager knows about this
        SyncManager.kick("sync finished");
    }
}

From source file:com.android.mms.ui.MessageUtils.java

public static boolean checkNeedNotifyForFolderMode(Context context, long threadId, long threadMute,
        long threadMuteStart, boolean threadNotificationEnabled) {
    if (threadId < 0) {
        MmsLog.w(TAG, "illegal threadId:" + threadId);
        return false;
    }// w  w w .  j  av a 2s. co m
    if (!checkAppSettingsNeedNotify(context)) {
        return false;
    }

    if (threadId == 0) {
        return true;
    }
    /// M: check thread settings
    if (!threadNotificationEnabled) {
        MmsLog.d(TAG, "thread notification is disabled!");
        return false;
    }

    MmsLog.d(TAG, "\t threadMute:" + threadMute + ", threadMute*3600=" + threadMute * 3600
            + "\t threadMuteStart" + threadMuteStart / 1000);

    Uri threadSettingsUri = ContentUris.withAppendedId(THREAD_SETTINGS_URI, (int) threadId);
    threadMute = checkThreadMuteTimeout(threadMuteStart, threadMute, threadSettingsUri, context);
    if (threadMute > 0) {
        MmsLog.d(TAG, "thread mute is set!");
        return false;
    }

    return true;
}

From source file:com.amaze.carbonfilemanager.activities.MainActivity.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {

    Uri uri = Uri.withAppendedPath(Uri.parse("content://" + CloudContract.PROVIDER_AUTHORITY),
            "/keys.db/secret_keys/");

    String[] projection = new String[] { CloudContract.COLUMN_ID, CloudContract.COLUMN_CLIENT_ID,
            CloudContract.COLUMN_CLIENT_SECRET_KEY };

    switch (id) {
    case REQUEST_CODE_CLOUD_LIST_KEY:
        Uri uriAppendedPath = uri;/*from www.  ja  v a 2  s  .  c  om*/
        switch (OpenMode.getOpenMode(args.getInt(ARGS_KEY_LOADER, 6))) {
        case GDRIVE:
            uriAppendedPath = ContentUris.withAppendedId(uri, 1);
            break;
        case DROPBOX:
            uriAppendedPath = ContentUris.withAppendedId(uri, 2);
            break;
        case BOX:
            uriAppendedPath = ContentUris.withAppendedId(uri, 3);
            break;
        case ONEDRIVE:
            uriAppendedPath = ContentUris.withAppendedId(uri, 4);
            break;
        }
        return new CursorLoader(this, uriAppendedPath, projection, null, null, null);
    case REQUEST_CODE_CLOUD_LIST_KEYS:
        // we need a list of all secret keys
        Uri uriAll = Uri.withAppendedPath(Uri.parse("content://" + CloudContract.PROVIDER_AUTHORITY),
                "/keys.db/secret_keys");
        CloudHandler cloudHandler = new CloudHandler(getApplicationContext());
        try {
            List<CloudEntry> cloudEntries = cloudHandler.getAllEntries();

            String ids[] = new String[cloudEntries.size()];

            for (int i = 0; i < cloudEntries.size(); i++) {

                // we need to get only those cloud details which user wants
                switch (cloudEntries.get(i).getServiceType()) {
                case GDRIVE:
                    ids[i] = 1 + "";
                    break;
                case DROPBOX:
                    ids[i] = 2 + "";
                    break;
                case BOX:
                    ids[i] = 3 + "";
                    break;
                case ONEDRIVE:
                    ids[i] = 4 + "";
                    break;
                }
            }
            return new CursorLoader(this, uriAll, projection, CloudContract.COLUMN_ID, ids, null);
        } catch (CloudPluginException e) {
            e.printStackTrace();

            Toast.makeText(this, getResources().getString(R.string.cloud_error_plugin), Toast.LENGTH_LONG)
                    .show();
        }
    case REQUEST_CODE_CLOUD_LIST_KEY_CLOUD:
        Uri uriAppendedPathCloud = ContentUris.withAppendedId(uri, 5);
        return new CursorLoader(this, uriAppendedPathCloud, projection, null, null, null);
    default:
        return null;
    }
}

From source file:com.android.mms.ui.ComposeMessageActivity.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    if (id == LOAD_TEMPLATE_BY_ID) {
        long rowID = args.getLong("id");
        Uri uri = ContentUris.withAppendedId(Template.CONTENT_URI, rowID);
        return new CursorLoader(this, uri, null, null, null, null);
    } else {/*from  w ww . ja  v a 2  s  .  com*/
        return new CursorLoader(this, Template.CONTENT_URI, null, null, null, null);
    }
}

From source file:me.ububble.speakall.fragment.ConversationChatFragment.java

private Bitmap getPhoto(Uri uri) {
    Bitmap photo = null;/*from  ww w.ja  va 2s  . co m*/
    String id = null;
    Cursor contactCursor = activity.getContentResolver().query(uri,
            new String[] { ContactsContract.Contacts._ID }, null, null, null);

    if (contactCursor.moveToFirst()) {
        id = contactCursor.getString(0);
    }
    contactCursor.close();
    try {
        InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(activity.getContentResolver(),
                ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(id)));
        if (input != null) {
            photo = BitmapFactory.decodeStream(input);
            input.close();
        }

    } catch (IOException iox) {
        Log.e("Error: ", iox.toString());
    }
    return photo;
}