List of usage examples for android.net Uri getPathSegments
public abstract List<String> getPathSegments();
From source file:mobisocial.musubi.objects.WebAppObj.java
String getAppName(Obj obj) { Uri appUri = Uri.parse(obj.getJson().optString(OBJ_URL)); String given = appUri.getQueryParameter("n"); if (given == null) { given = appUri.getLastPathSegment(); if (given == null || given.length() <= 1 || given.startsWith("index")) { List<String> segs = appUri.getPathSegments(); if (segs.size() > 1) { given = segs.get(segs.size() - 2); } else { given = appUri.getAuthority(); }/* w w w . j ava2s . com*/ } } return given; }
From source file:org.mozilla.labs.Soup.provider.AppsProvider.java
@Override public int delete(Uri uri, String where, String[] whereArgs) { SQLiteDatabase db = mOpenHelper.getWritableDatabase(); int count;//ww w . j av a 2 s . co m switch (sUriMatcher.match(uri)) { case APPS: count = db.delete(APPS_TABLE_NAME, where, whereArgs); break; case APP_ID: String appId = uri.getPathSegments().get(1); count = db.delete(APPS_TABLE_NAME, Apps._ID + "=" + appId + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""), whereArgs); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } getContext().getContentResolver().notifyChange(uri, null); return count; }
From source file:org.coocood.vcontentprovider.VContentProvider.java
private void notifyChange(Uri uri, int count) { if (!batchingUris.contains(uri) && count != 0) { getContext().getContentResolver().notifyChange(uri, null); // Notify not only the table Uri, but also the view Uris which // contain the table. String table = uri.getPathSegments().get(0); for (String view : viewTablesMap.keySet()) { if (viewTablesMap.get(view).contains(table)) { Uri viewUri = new Uri.Builder().scheme(uri.getScheme()).authority(uri.getAuthority()) .appendPath(view).build(); getContext().getContentResolver().notifyChange(viewUri, null); }/*from www.ja v a2 s . co m*/ } } }
From source file:cn.code.notes.gtask.data.SqlNote.java
public void commit(boolean validateVersion) { if (mIsCreate) { if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) { mDiffNoteValues.remove(NoteColumns.ID); }/*from w ww.j a v a 2 s. c o m*/ Uri uri = mContentResolver.insert(Notes.CONTENT_NOTE_URI, mDiffNoteValues); try { mId = Long.valueOf(uri.getPathSegments().get(1)); } catch (NumberFormatException e) { Log.e(TAG, "Get note id error :" + e.toString()); throw new ActionFailureException("create note failed"); } if (mId == 0) { throw new IllegalStateException("Create thread id failed"); } if (mType == Notes.TYPE_NOTE) { for (SqlData sqlData : mDataList) { sqlData.commit(mId, false, -1); } } } else { if (mId <= 0 && mId != Notes.ID_ROOT_FOLDER && mId != Notes.ID_CALL_RECORD_FOLDER) { Log.e(TAG, "No such note"); throw new IllegalStateException("Try to update note with invalid id"); } if (mDiffNoteValues.size() > 0) { mVersion++; int result = 0; if (!validateVersion) { result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "(" + NoteColumns.ID + "=?)", new String[] { String.valueOf(mId) }); } else { result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "(" + NoteColumns.ID + "=?) AND (" + NoteColumns.VERSION + "<=?)", new String[] { String.valueOf(mId), String.valueOf(mVersion) }); } if (result == 0) { Log.w(TAG, "there is no update. maybe user updates note when syncing"); } } if (mType == Notes.TYPE_NOTE) { for (SqlData sqlData : mDataList) { sqlData.commit(mId, validateVersion, mVersion); } } } // refresh local info loadFromCursor(mId); if (mType == Notes.TYPE_NOTE) loadDataContent(); mDiffNoteValues.clear(); mIsCreate = false; }
From source file:com.manning.androidhacks.hack043.provider.MySQLContentProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); switch (sUriMatcher.match(uri)) { case ITEM://from www .j a va2 s. c o m qb.setTables(TABLE_NAME); qb.setProjectionMap(projectionMap); break; case ITEM_ID: qb.setTables(TABLE_NAME); qb.setProjectionMap(projectionMap); qb.appendWhere(COLUMN_ID + "=" + uri.getPathSegments().get(1)); break; default: throw new RuntimeException("Unknown URI"); } SQLiteDatabase db = getDatabaseHelper().getReadableDatabase(); Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder); c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
From source file:com.manning.androidhacks.hack043.provider.BatchNumbersContentProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); switch (sUriMatcher.match(uri)) { case ITEM://from w w w. j ava 2 s . co m qb.setTables(TABLE_NAME); qb.setProjectionMap(projectionMap); break; case ITEM_ID: qb.setTables(TABLE_NAME); qb.setProjectionMap(projectionMap); qb.appendWhere(COLUMN_ID + "=" + uri.getPathSegments().get(1)); break; default: throw new RuntimeException("Unknown URI"); } SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder); c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
From source file:com.coinomi.wallet.ExchangeRatesProvider.java
@Override public Cursor query(final Uri uri, final String[] projection, final String selection, final String[] selectionArgs, final String sortOrder) { final long now = System.currentTimeMillis(); final List<String> pathSegments = uri.getPathSegments(); if (pathSegments.size() != 2) { throw new IllegalArgumentException("Unrecognized URI: " + uri); }/*w ww . jav a 2 s . com*/ final boolean offline = uri.getQueryParameter(QUERY_PARAM_OFFLINE) != null; long lastUpdated; final String symbol; final boolean isLocalToCrypto; if (pathSegments.get(0).equals("to-crypto")) { isLocalToCrypto = true; symbol = pathSegments.get(1); lastUpdated = symbol.equals(lastLocalCurrency) ? localToCryptoLastUpdated : 0; } else if (pathSegments.get(0).equals("to-local")) { isLocalToCrypto = false; symbol = pathSegments.get(1); lastUpdated = symbol.equals(lastCryptoCurrency) ? cryptoToLocalLastUpdated : 0; } else { throw new IllegalArgumentException("Unrecognized URI path: " + uri); } if (!offline && (lastUpdated == 0 || now - lastUpdated > Constants.RATE_UPDATE_FREQ_MS)) { URL url; try { if (isLocalToCrypto) { url = new URL(String.format(TO_CRYPTO_URL, symbol)); } else { url = new URL(String.format(TO_LOCAL_URL, symbol)); } } catch (final MalformedURLException x) { throw new RuntimeException(x); // Should not happen } JSONObject newExchangeRatesJson = requestExchangeRatesJson(url); Map<String, ExchangeRate> newExchangeRates = parseExchangeRates(newExchangeRatesJson, symbol, isLocalToCrypto); if (newExchangeRates != null) { if (isLocalToCrypto) { localToCryptoRates = newExchangeRates; localToCryptoLastUpdated = now; lastLocalCurrency = symbol; config.setCachedExchangeRates(lastLocalCurrency, newExchangeRatesJson); } else { cryptoToLocalRates = newExchangeRates; cryptoToLocalLastUpdated = now; lastCryptoCurrency = symbol; } } } Map<String, ExchangeRate> exchangeRates = isLocalToCrypto ? localToCryptoRates : cryptoToLocalRates; if (exchangeRates == null) return null; final MatrixCursor cursor = new MatrixCursor(new String[] { BaseColumns._ID, KEY_CURRENCY_ID, KEY_RATE_COIN, KEY_RATE_COIN_CODE, KEY_RATE_FIAT, KEY_RATE_FIAT_CODE, KEY_SOURCE }); if (selection == null) { for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) { final ExchangeRate exchangeRate = entry.getValue(); addRow(cursor, exchangeRate); } } else if (selection.equals(KEY_CURRENCY_ID)) { final ExchangeRate exchangeRate = exchangeRates.get(selectionArgs[0]); if (exchangeRate != null) { addRow(cursor, exchangeRate); } } return cursor; }
From source file:com.mygeopay.wallet.ExchangeRatesProvider.java
@Override public Cursor query(final Uri uri, final String[] projection, final String selection, final String[] selectionArgs, final String sortOrder) { final long now = System.currentTimeMillis(); final List<String> pathSegments = uri.getPathSegments(); if (pathSegments.size() != 2) { throw new IllegalArgumentException("Unrecognized URI: " + uri); }/*from w w w . j a v a 2s . c o m*/ final boolean offline = uri.getQueryParameter(QUERY_PARAM_OFFLINE) != null; long lastUpdated; // TODO Add rate values for other Altcoins final String symbol; final boolean isLocalToCrypto; if (pathSegments.get(0).equals("to-crypto")) { isLocalToCrypto = true; symbol = pathSegments.get(1); lastUpdated = symbol.equals(lastLocalCurrency) ? localToCryptoLastUpdated : 0; } else if (pathSegments.get(0).equals("to-local")) { isLocalToCrypto = false; symbol = pathSegments.get(1); lastUpdated = symbol.equals(lastCryptoCurrency) ? cryptoToLocalLastUpdated : 0; } else { throw new IllegalArgumentException("Unrecognized URI path: " + uri); } // TODO Add rate values for other Altcoins if (!offline && (lastUpdated == 0 || now - lastUpdated > Constants.RATE_UPDATE_FREQ_MS)) { URL url; try { if (isLocalToCrypto) { url = new URL(String.format(TO_CRYPTO_URL, symbol)); } else { url = new URL(String.format(TO_LOCAL_URL, symbol)); } } catch (final MalformedURLException x) { throw new RuntimeException(x); // Should not happen } JSONObject newExchangeRatesJson = requestExchangeRatesJson(url); Map<String, ExchangeRate> newExchangeRates = parseExchangeRates(newExchangeRatesJson, symbol, isLocalToCrypto); if (newExchangeRates != null) { if (isLocalToCrypto) { localToCryptoRates = newExchangeRates; localToCryptoLastUpdated = now; lastLocalCurrency = symbol; config.setCachedExchangeRates(lastLocalCurrency, newExchangeRatesJson); } else { cryptoToLocalRates = newExchangeRates; cryptoToLocalLastUpdated = now; lastCryptoCurrency = symbol; } } } Map<String, ExchangeRate> exchangeRates = isLocalToCrypto ? localToCryptoRates : cryptoToLocalRates; if (exchangeRates == null) return null; final MatrixCursor cursor = new MatrixCursor(new String[] { BaseColumns._ID, KEY_CURRENCY_ID, KEY_RATE_COIN, KEY_RATE_COIN_CODE, KEY_RATE_FIAT, KEY_RATE_FIAT_CODE, KEY_SOURCE }); if (selection == null) { for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) { final ExchangeRate exchangeRate = entry.getValue(); addRow(cursor, exchangeRate); } } else if (selection.equals(KEY_CURRENCY_ID)) { final ExchangeRate exchangeRate = exchangeRates.get(selectionArgs[0]); if (exchangeRate != null) { addRow(cursor, exchangeRate); } } return cursor; }
From source file:com.manning.androidhacks.hack023.provider.TodoContentProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); switch (sUriMatcher.match(uri)) { case TODO:/*from ww w . j ava2 s . com*/ qb.setTables(TODO_TABLE_NAME); qb.setProjectionMap(projectionMap); break; case TODO_ID: qb.setTables(TODO_TABLE_NAME); qb.setProjectionMap(projectionMap); qb.appendWhere(COLUMN_ID + "=" + uri.getPathSegments().get(1)); break; default: throw new RuntimeException("Unknown URI"); } SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder); c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
From source file:com.example.android.notepad.CMNotesProvider.java
@Override public int delete(Uri uri, String where, String[] whereArgs) { // SQLiteDatabase db = mOpenHelper.getWritableDatabase(); int count;//from w w w . jav a2 s .c o m CMAdapter cmAdapter = new CMAdapter(); switch (sUriMatcher.match(uri)) { case NOTES: //count = db.delete(NOTES_TABLE_NAME, where, whereArgs); count = 0; break; case NOTE_ID: String noteId = uri.getPathSegments().get(1); //count = db.delete(NOTES_TABLE_NAME, Notes._ID + "=" + noteId // + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""), whereArgs); cmAdapter.deleteKeys(new String[] { noteId }); count = 1; break; default: throw new IllegalArgumentException("Unknown URI " + uri); } getContext().getContentResolver().notifyChange(uri, null); return count; }