Example usage for android.content ContentUris parseId

List of usage examples for android.content ContentUris parseId

Introduction

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

Prototype

public static long parseId(Uri contentUri) 

Source Link

Document

Converts the last path segment to a long.

Usage

From source file:org.dmfs.webcal.fragments.CalendarItemFragment.java

@Override
public void onStart() {
    super.onStart();
    mId = ContentUris.parseId(mContentUri);

    Analytics.screen(mTitle + "/calendar_preview", null, String.valueOf(ContentItem.getApiId(mId)));
}

From source file:com.silentcircle.contacts.list.ScContactBrowseListFragment.java

private void parseSelectedContactUri() {
    if (mSelectedContactUri != null) {
        String directoryParam = mSelectedContactUri.getQueryParameter(ScContactsContract.DIRECTORY_PARAM_KEY);
        mSelectedContactDirectoryId = TextUtils.isEmpty(directoryParam) ? Directory.DEFAULT
                : Long.parseLong(directoryParam);
        if (mSelectedContactUri.toString().startsWith(RawContacts.CONTENT_URI.toString())
                && mSelectedContactUri.getPathSegments().size() >= 2) {
            mSelectedContactLookupKey = null;
            mSelectedContactId = ContentUris.parseId(mSelectedContactUri);
        } else {/*from   w w  w .j  av a 2s.  c  om*/
            Log.e(TAG, "Unsupported contact URI: " + mSelectedContactUri);
            mSelectedContactLookupKey = null;
            mSelectedContactId = 0;
        }

    } else {
        mSelectedContactDirectoryId = Directory.DEFAULT;
        mSelectedContactLookupKey = null;
        mSelectedContactId = 0;
    }
}

From source file:com.example.joel.sunshine.FetchWeatherTask.java

private long addLocation(String locationSetting, String cityName, double lat, double lon) {
    Log.v(LOG_TAG, "inserting " + cityName + ", with coord: " + lat + ", " + lon);

    // First, check if the location with this city name exists in the db
    Cursor cursor = mContext.getContentResolver().query(LocationEntry.CONTENT_URI,
            new String[] { LocationEntry._ID }, LocationEntry.COLUMN_LOC_SETTING + " = ?",
            new String[] { locationSetting }, null);

    if (cursor.moveToFirst()) {
        Log.v(LOG_TAG, "Found it in the database!");
        int locationIdIndex = cursor.getColumnIndex(LocationEntry._ID);
        return cursor.getLong(locationIdIndex);
    } else {/* w w w  . jav a 2s.co  m*/
        Log.v(LOG_TAG, "Didn't find it in the database, inserting now!");
        ContentValues locationValues = new ContentValues();
        locationValues.put(LocationEntry.COLUMN_LOC_SETTING, locationSetting);
        locationValues.put(LocationEntry.COLUMN_CITY_NAME, cityName);
        locationValues.put(LocationEntry.COLUMN_LAT, lat);
        locationValues.put(LocationEntry.COLUMN_LONG, lon);

        Uri locationInsertUri = mContext.getContentResolver().insert(LocationEntry.CONTENT_URI, locationValues);

        return ContentUris.parseId(locationInsertUri);
    }
}

From source file:com.sonetel.db.DBProvider.java

@Override
public Uri insert(Uri uri, ContentValues initialValues) {
    int matched = URI_MATCHER.match(uri);
    String matchedTable = null;/*w ww.  j  a v  a2 s .com*/
    Uri baseInsertedUri = null;
    switch (matched) {
    case ACCOUNTS:
    case ACCOUNTS_ID:
        matchedTable = SipProfile.ACCOUNTS_TABLE_NAME;
        baseInsertedUri = SipProfile.ACCOUNT_ID_URI_BASE;
        break;
    case CALLLOGS:
    case CALLLOGS_ID:
        matchedTable = SipManager.CALLLOGS_TABLE_NAME;
        baseInsertedUri = SipManager.CALLLOG_ID_URI_BASE;
        break;
    case FILTERS:
    case FILTERS_ID:
        matchedTable = SipManager.FILTERS_TABLE_NAME;
        baseInsertedUri = SipManager.FILTER_ID_URI_BASE;
        break;
    case MESSAGES:
    case MESSAGES_ID:
        matchedTable = SipMessage.MESSAGES_TABLE_NAME;
        baseInsertedUri = SipMessage.MESSAGE_ID_URI_BASE;
        break;
    case ACCESSNO:
        matchedTable = SipProfile.ACCESS_NUMS_TABLE_NAME;
        baseInsertedUri = SipProfile.ACCESS_URI_BASE;
        break;
    case ACCOUNTS_STATUS_ID:
        long id = ContentUris.parseId(uri);
        synchronized (profilesStatus) {
            SipProfileState ps = new SipProfileState();
            if (profilesStatus.containsKey(id)) {
                ContentValues currentValues = profilesStatus.get(id);
                ps.createFromContentValue(currentValues);
            }
            ps.createFromContentValue(initialValues);
            ContentValues cv = ps.getAsContentValue();
            cv.put(SipProfileState.ACCOUNT_ID, id);
            profilesStatus.put(id, cv);
            Log.d(THIS_FILE, "Added " + cv);
        }
        getContext().getContentResolver().notifyChange(uri, null);
        return uri;
    default:
        break;
    }

    if (matchedTable == null) {
        throw new IllegalArgumentException(UNKNOWN_URI_LOG + uri);
    }

    ContentValues values;

    if (initialValues != null) {
        values = new ContentValues(initialValues);
    } else {
        values = new ContentValues();
    }

    SQLiteDatabase db = mOpenHelper.getWritableDatabase();

    long rowId = db.insert(matchedTable, null, values);

    // If the insert succeeded, the row ID exists.
    if (rowId >= 0) {
        // TODO : for inserted account register it here

        Uri retUri = ContentUris.withAppendedId(baseInsertedUri, rowId);
        getContext().getContentResolver().notifyChange(retUri, null);

        if (matched == ACCOUNTS || matched == ACCOUNTS_ID) {
            broadcastAccountChange(rowId);
        }
        if (matched == CALLLOGS || matched == CALLLOGS_ID) {
            db.delete(SipManager.CALLLOGS_TABLE_NAME,
                    CallLog.Calls._ID + " IN " + "(SELECT " + CallLog.Calls._ID + " FROM "
                            + SipManager.CALLLOGS_TABLE_NAME + " ORDER BY " + CallLog.Calls.DEFAULT_SORT_ORDER
                            + " LIMIT -1 OFFSET 500)",
                    null);
        }
        if (matched == ACCOUNTS_STATUS || matched == ACCOUNTS_STATUS_ID) {
            broadcastRegistrationChange(rowId);
        }
        if (matched == FILTERS || matched == FILTERS_ID) {
            Filter.resetCache();
        }

        return retUri;
    }

    throw new SQLException("Failed to insert row into " + uri);
}

From source file:com.abcvoipsip.ui.calllog.CallLogDetailsFragment.java

public void onMenuRemoveFromCallLog(MenuItem menuItem) {
    final StringBuilder callIds = new StringBuilder();
    for (Uri callUri : getCallLogEntryUris()) {
        if (callIds.length() != 0) {
            callIds.append(",");
        }// w ww.j  av a  2s. co  m
        callIds.append(ContentUris.parseId(callUri));
    }

    getActivity().getContentResolver().delete(SipManager.CALLLOG_URI, Calls._ID + " IN (" + callIds + ")",
            null);
    if (quitListener != null) {
        quitListener.onQuit();
    }
}

From source file:org.jraf.android.bikey.app.ride.detail.RideDetailActivity.java

private void delete() {
    final long[] ids = { ContentUris.parseId(mRideUri) };
    new TaskFragment(new Task<RideDetailActivity>() {
        @Override//w  ww  . j  av  a  2  s  . com
        protected void doInBackground() throws Throwable {
            RideManager.get().delete(ids);
        }

        @Override
        protected void onPostExecuteOk() {
            finish();
        }
    }).execute(getSupportFragmentManager());
}

From source file:com.appsimobile.appsii.module.home.provider.HomeContentProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

    selection = fixWhereProjection(uri, selection);
    SqlArguments args = new SqlArguments(uri, selection, selectionArgs);

    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

    String tables = createTablesFromTableQuery(args.table);

    qb.setTables(tables);//from  w w  w .j  a  v  a 2s . c  om

    Map<String, String> projectionMap = getProjectionMapForTable(args.table);

    if (projectionMap != null) {
        qb.setProjectionMap(projectionMap);
        qb.setStrict(true);
    }

    SQLiteDatabase db = mOpenHelper.getWritableDatabase();

    if (HomeContract.CELLS_TABLE_NAME.equals(args.table)) {
        sortOrder = fixSortOrder(sortOrder);
    }
    String where = args.where;
    if (HomeContract.HOTSPOT_PAGES_DETAILS_TABLE_NAME.equals(args.table)) {
        where = "_ht." + BaseColumns._ID + "=" + ContentUris.parseId(uri);
    }

    Cursor result = qb.query(db, projection, where, args.args, null, null, sortOrder);

    result.setNotificationUri(getContext().getContentResolver(), uri);

    return result;
}

From source file:com.csipsimple.db.DBProvider.java

@Override
public Uri insert(Uri uri, ContentValues initialValues) {
    int matched = URI_MATCHER.match(uri);
    String matchedTable = null;/*from w w w  .  java2s  . c  o  m*/
    Uri baseInsertedUri = null;

    switch (matched) {
    case ACCOUNTS:
    case ACCOUNTS_ID:
        matchedTable = SipProfile.ACCOUNTS_TABLE_NAME;
        baseInsertedUri = SipProfile.ACCOUNT_ID_URI_BASE;
        break;
    case CALLLOGS:
    case CALLLOGS_ID:
        matchedTable = SipManager.CALLLOGS_TABLE_NAME;
        baseInsertedUri = SipManager.CALLLOG_ID_URI_BASE;
        break;
    case FILTERS:
    case FILTERS_ID:
        matchedTable = SipManager.FILTERS_TABLE_NAME;
        baseInsertedUri = SipManager.FILTER_ID_URI_BASE;
        break;
    case MESSAGES:
    case MESSAGES_ID:
        matchedTable = SipMessage.MESSAGES_TABLE_NAME;
        baseInsertedUri = SipMessage.MESSAGE_ID_URI_BASE;
        break;
    case ACCOUNTS_STATUS_ID:
        long id = ContentUris.parseId(uri);
        synchronized (profilesStatus) {
            SipProfileState ps = new SipProfileState();
            if (profilesStatus.containsKey(id)) {
                ContentValues currentValues = profilesStatus.get(id);
                ps.createFromContentValue(currentValues);
            }
            ps.createFromContentValue(initialValues);
            ContentValues cv = ps.getAsContentValue();
            cv.put(SipProfileState.ACCOUNT_ID, id);
            profilesStatus.put(id, cv);
            Log.d(THIS_FILE, "Added " + cv);
        }
        getContext().getContentResolver().notifyChange(uri, null);
        return uri;
    default:
        break;
    }

    if (matchedTable == null) {
        throw new IllegalArgumentException(UNKNOWN_URI_LOG + uri);
    }

    ContentValues values;

    if (initialValues != null) {
        values = new ContentValues(initialValues);
    } else {
        values = new ContentValues();
    }

    SQLiteDatabase db = mOpenHelper.getWritableDatabase();

    long rowId = db.insert(matchedTable, null, values);

    // If the insert succeeded, the row ID exists.
    if (rowId >= 0) {
        // TODO : for inserted account register it here

        Uri retUri = ContentUris.withAppendedId(baseInsertedUri, rowId);
        getContext().getContentResolver().notifyChange(retUri, null);

        if (matched == ACCOUNTS || matched == ACCOUNTS_ID) {
            broadcastAccountChange(rowId);
        }
        if (matched == CALLLOGS || matched == CALLLOGS_ID) {
            db.delete(SipManager.CALLLOGS_TABLE_NAME,
                    CallLog.Calls._ID + " IN " + "(SELECT " + CallLog.Calls._ID + " FROM "
                            + SipManager.CALLLOGS_TABLE_NAME + " ORDER BY " + CallLog.Calls.DEFAULT_SORT_ORDER
                            + " LIMIT -1 OFFSET 500)",
                    null);
        }
        if (matched == ACCOUNTS_STATUS || matched == ACCOUNTS_STATUS_ID) {
            broadcastRegistrationChange(rowId);
        }
        if (matched == FILTERS || matched == FILTERS_ID) {
            Filter.resetCache();
        }

        return retUri;
    }

    throw new SQLException("Failed to insert row into " + uri);
}

From source file:me.albinmathew.celluloid.ui.fragments.MovieDetailFragment.java

private void setFavourites() {
    if (isFavourite) {
        showUnFavourites();/*w ww  .  j  av  a  2 s.  co  m*/
        int rowDeleted = getContext().getContentResolver().delete(MovieContract.Movie.CONTENT_URI,
                MovieContract.Movie.COLUMN_MOVIE_ID + "= ?",
                new String[] { String.valueOf(moviesResponseBean.getId()) });
        if (rowDeleted > 0) {
            showSnackBar("Removed " + moviesResponseBean.getTitle() + " from favourites");
        }
    } else {
        showFavourites();
        Uri rowUri = getContext().getContentResolver().insert(MovieContract.Movie.CONTENT_URI, values);
        long rowId = ContentUris.parseId(rowUri);
        if (rowId > 0) {
            showSnackBar("Added " + moviesResponseBean.getTitle() + " to favourites");
        }
    }
}

From source file:com.silentcircle.contacts.detail.ContactLoaderFragment.java

private void setShareIntent() {
    if (mShareActionProvider != null) {
        long rawContactId = ContentUris.parseId(mLookupUri);
        Uri shareUri = ContentUris.withAppendedId(RawContacts.CONTENT_VCARD_URI, rawContactId); // (RawContacts.CONTENT_VCARD_URI, lookupKey);
        final Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/x-vcard");
        // RawContacts.CONTENT_VCARD_TYPE is not supported by standard Bluetooth sender app
        // intent.setType(RawContacts.CONTENT_VCARD_TYPE);
        intent.putExtra(Intent.EXTRA_STREAM, shareUri);
        mShareActionProvider.setShareIntent(intent);
    }//  ww  w. jav a 2 s.c  om
}