List of usage examples for android.content ContentUris parseId
public static long parseId(Uri contentUri)
From source file:info.guardianproject.otr.app.im.app.NewChatActivity.java
private void doResolveIntent(Intent intent) { if (requireOpenDashboardOnStart(intent)) { long providerId = intent.getLongExtra(ImServiceConstants.EXTRA_INTENT_PROVIDER_ID, -1L); mLastAccountId = intent.getLongExtra(ImServiceConstants.EXTRA_INTENT_ACCOUNT_ID, -1L); if (providerId == -1L || mLastAccountId == -1L) { finish();/* ww w. ja va 2s. c om*/ } else { // mChatSwitcher.open(); } return; } if (ImServiceConstants.ACTION_MANAGE_SUBSCRIPTION.equals(intent.getAction())) { long providerId = intent.getLongExtra(ImServiceConstants.EXTRA_INTENT_PROVIDER_ID, -1); mLastAccountId = intent.getLongExtra(ImServiceConstants.EXTRA_INTENT_ACCOUNT_ID, -1L); String from = intent.getStringExtra(ImServiceConstants.EXTRA_INTENT_FROM_ADDRESS); if ((providerId == -1) || (from == null)) { finish(); } else { showSubscriptionDialog(providerId, from); } } else if (intent != null) { Uri data = intent.getData(); if (intent.getBooleanExtra("showaccounts", false)) mDrawer.openDrawer(GravityCompat.START); if (data != null) { if (data.getScheme() != null && data.getScheme().equals("immu")) { String user = data.getUserInfo(); String host = data.getHost(); String path = null; if (data.getPathSegments().size() > 0) path = data.getPathSegments().get(0); if (host != null && path != null) { IImConnection connMUC = findConnectionForGroupChat(user, host); if (connMUC != null) { startGroupChat(path, host, user, connMUC); setResult(RESULT_OK); } else { mHandler.showAlert("Connection Error", "Unable to find a connection to join a group chat from. Please sign in and try again."); setResult(Activity.RESULT_CANCELED); finish(); } } } else { String type = getContentResolver().getType(data); if (Imps.Chats.CONTENT_ITEM_TYPE.equals(type)) { long requestedContactId = ContentUris.parseId(data); Cursor cursorChats = mChatPagerAdapter.getCursor(); if (cursorChats != null) { cursorChats.moveToPosition(-1); int posIdx = 1; boolean foundChatView = false; while (cursorChats.moveToNext()) { long chatId = cursorChats.getLong(ChatView.CONTACT_ID_COLUMN); if (chatId == requestedContactId) { mChatPager.setCurrentItem(posIdx); foundChatView = true; break; } posIdx++; } if (!foundChatView) { Uri.Builder builder = Imps.Contacts.CONTENT_URI.buildUpon(); ContentUris.appendId(builder, requestedContactId); Cursor cursor = getContentResolver().query(builder.build(), ChatView.CHAT_PROJECTION, null, null, null); try { if (cursor.getCount() > 0) { cursor.moveToFirst(); openExistingChat(cursor); } } finally { cursor.close(); } } } } else if (Imps.Invitation.CONTENT_ITEM_TYPE.equals(type)) { //chatView.bindInvitation(ContentUris.parseId(data)); } } } else if (intent.hasExtra(ImServiceConstants.EXTRA_INTENT_ACCOUNT_ID)) { //set the current account id mLastAccountId = intent.getLongExtra(ImServiceConstants.EXTRA_INTENT_ACCOUNT_ID, -1L); //move the pager back to the first page if (mChatPager != null) mChatPager.setCurrentItem(0); } else { // refreshConnections(); } } }
From source file:com.sonetel.db.DBProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { // Constructs a new query builder and sets its table name SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); String finalSortOrder = sortOrder; String[] finalSelectionArgs = selectionArgs; String finalGrouping = null;/*from ww w. jav a 2 s .com*/ String finalHaving = null; int type = URI_MATCHER.match(uri); Uri regUri = uri; int remoteUid = Binder.getCallingUid(); int selfUid = android.os.Process.myUid(); if (remoteUid != selfUid) { if (type == ACCOUNTS || type == ACCOUNTS_ID) { for (String proj : projection) { if (proj.toLowerCase().contains(SipProfile.FIELD_DATA) || proj.toLowerCase().contains("*")) { throw new SecurityException("Password not readable from external apps"); } } } } Cursor c; long id; switch (type) { case ACCOUNTS: qb.setTables(SipProfile.ACCOUNTS_TABLE_NAME); if (sortOrder == null) { finalSortOrder = SipProfile.FIELD_PRIORITY + " ASC"; } break; case ACCOUNTS_ID: qb.setTables(SipProfile.ACCOUNTS_TABLE_NAME); qb.appendWhere(SipProfile.FIELD_ID + "=?"); finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[] { uri.getLastPathSegment() }); break; case CALLLOGS: qb.setTables(SipManager.CALLLOGS_TABLE_NAME); if (sortOrder == null) { finalSortOrder = CallLog.Calls.DATE + " DESC"; } break; case CALLLOGS_ID: qb.setTables(SipManager.CALLLOGS_TABLE_NAME); qb.appendWhere(CallLog.Calls._ID + "=?"); finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[] { uri.getLastPathSegment() }); break; case FILTERS: qb.setTables(SipManager.FILTERS_TABLE_NAME); if (sortOrder == null) { finalSortOrder = Filter.DEFAULT_ORDER; } break; case FILTERS_ID: qb.setTables(SipManager.FILTERS_TABLE_NAME); qb.appendWhere(Filter._ID + "=?"); finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[] { uri.getLastPathSegment() }); break; case MESSAGES: qb.setTables(SipMessage.MESSAGES_TABLE_NAME); if (sortOrder == null) { finalSortOrder = SipMessage.FIELD_DATE + " DESC"; } break; case MESSAGES_ID: qb.setTables(SipMessage.MESSAGES_TABLE_NAME); qb.appendWhere(SipMessage.FIELD_ID + "=?"); finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[] { uri.getLastPathSegment() }); break; case THREADS: qb.setTables(SipMessage.MESSAGES_TABLE_NAME); if (sortOrder == null) { finalSortOrder = SipMessage.FIELD_DATE + " DESC"; } projection = new String[] { "ROWID AS _id", SipMessage.FIELD_FROM, SipMessage.FIELD_FROM_FULL, SipMessage.FIELD_TO, "CASE " + "WHEN " + SipMessage.FIELD_FROM + "='SELF' THEN " + SipMessage.FIELD_TO + " WHEN " + SipMessage.FIELD_FROM + "!='SELF' THEN " + SipMessage.FIELD_FROM + " END AS message_ordering", SipMessage.FIELD_BODY, "MAX(" + SipMessage.FIELD_DATE + ") AS " + SipMessage.FIELD_DATE, "MIN(" + SipMessage.FIELD_READ + ") AS " + SipMessage.FIELD_READ, //SipMessage.FIELD_READ, "COUNT(" + SipMessage.FIELD_DATE + ") AS counter" }; //qb.appendWhere(SipMessage.FIELD_TYPE + " in (" + SipMessage.MESSAGE_TYPE_INBOX // + "," + SipMessage.MESSAGE_TYPE_SENT + ")"); finalGrouping = "message_ordering"; regUri = SipMessage.MESSAGE_URI; break; case THREADS_ID: qb.setTables(SipMessage.MESSAGES_TABLE_NAME); if (sortOrder == null) { finalSortOrder = SipMessage.FIELD_DATE + " DESC"; } projection = new String[] { "ROWID AS _id", SipMessage.FIELD_FROM, SipMessage.FIELD_TO, SipMessage.FIELD_BODY, SipMessage.FIELD_DATE, SipMessage.FIELD_MIME_TYPE, SipMessage.FIELD_TYPE, SipMessage.FIELD_STATUS, SipMessage.FIELD_FROM_FULL }; qb.appendWhere(MESSAGES_THREAD_SELECTION); String from = uri.getLastPathSegment(); finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[] { from, from }); regUri = SipMessage.MESSAGE_URI; break; case ACCOUNTS_STATUS: synchronized (profilesStatus) { ContentValues[] cvs = new ContentValues[profilesStatus.size()]; int i = 0; for (ContentValues ps : profilesStatus.values()) { cvs[i] = ps; i++; } c = getCursor(cvs); } if (c != null) { c.setNotificationUri(getContext().getContentResolver(), uri); } return c; case ACCOUNTS_STATUS_ID: id = ContentUris.parseId(uri); synchronized (profilesStatus) { ContentValues cv = profilesStatus.get(id); if (cv == null) { return null; } c = getCursor(new ContentValues[] { cv }); } c.setNotificationUri(getContext().getContentResolver(), uri); return c; case ACCESSNO: qb.setTables(SipProfile.ACCESS_NUMS_TABLE_NAME); break; default: throw new IllegalArgumentException(UNKNOWN_URI_LOG + uri); } SQLiteDatabase db = mOpenHelper.getReadableDatabase(); c = qb.query(db, projection, selection, finalSelectionArgs, finalGrouping, finalHaving, finalSortOrder); c.setNotificationUri(getContext().getContentResolver(), regUri); return c; }
From source file:org.totschnig.myexpenses.model.Account.java
/** * Saves the account, creating it new if necessary * * @return the id of the account. Upon creation it is returned from the database *//* ww w . j a va 2s. c o m*/ public Uri save() { Uri uri; ContentValues initialValues = new ContentValues(); initialValues.put(KEY_LABEL, label); initialValues.put(KEY_OPENING_BALANCE, openingBalance.getAmountMinor()); initialValues.put(KEY_DESCRIPTION, description); initialValues.put(KEY_CURRENCY, currency.getCurrencyCode()); initialValues.put(KEY_TYPE, type.name()); initialValues.put(KEY_GROUPING, grouping.name()); initialValues.put(KEY_COLOR, color); if (getId() == 0) { uri = cr().insert(CONTENT_URI, initialValues); if (uri == null) { return null; } setId(ContentUris.parseId(uri)); } else { uri = CONTENT_URI.buildUpon().appendPath(String.valueOf(getId())).build(); cr().update(uri, initialValues, null, null); } if (!accounts.containsKey(getId())) { accounts.put(getId(), this); } Money.ensureFractionDigitsAreCached(currency); return uri; }
From source file:com.fututel.db.DBProvider.java
@Override public int update(Uri uri, ContentValues values, String where, String[] whereArgs) { SQLiteDatabase db = mOpenHelper.getWritableDatabase(); int count;/*from w ww . ja v a 2 s . c o m*/ String finalWhere; int matched = URI_MATCHER.match(uri); switch (matched) { case ACCOUNTS: count = db.update(SipProfile.ACCOUNTS_TABLE_NAME, values, where, whereArgs); break; case ACCOUNTS_ID: finalWhere = DatabaseUtilsCompat .concatenateWhere(SipProfile.FIELD_ID + " = " + ContentUris.parseId(uri), where); count = db.update(SipProfile.ACCOUNTS_TABLE_NAME, values, finalWhere, whereArgs); break; case CALLLOGS: count = db.update(SipManager.CALLLOGS_TABLE_NAME, values, where, whereArgs); break; case CALLLOGS_ID: finalWhere = DatabaseUtilsCompat.concatenateWhere(CallLog.Calls._ID + " = " + ContentUris.parseId(uri), where); count = db.update(SipManager.CALLLOGS_TABLE_NAME, values, finalWhere, whereArgs); break; case FILTERS: count = db.update(SipManager.FILTERS_TABLE_NAME, values, where, whereArgs); break; case FILTERS_ID: finalWhere = DatabaseUtilsCompat.concatenateWhere(Filter._ID + " = " + ContentUris.parseId(uri), where); count = db.update(SipManager.FILTERS_TABLE_NAME, values, finalWhere, whereArgs); break; case MESSAGES: count = db.update(SipMessage.MESSAGES_TABLE_NAME, values, where, whereArgs); break; case MESSAGES_ID: finalWhere = DatabaseUtilsCompat .concatenateWhere(SipMessage.FIELD_ID + " = " + ContentUris.parseId(uri), where); count = db.update(SipMessage.MESSAGES_TABLE_NAME, values, where, whereArgs); 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(values); ContentValues cv = ps.getAsContentValue(); cv.put(SipProfileState.ACCOUNT_ID, id); profilesStatus.put(id, cv); Log.d(THIS_FILE, "Updated " + cv); } count = 1; break; default: throw new IllegalArgumentException(UNKNOWN_URI_LOG + uri); } getContext().getContentResolver().notifyChange(uri, null); long rowId = -1; if (matched == ACCOUNTS_ID || matched == ACCOUNTS_STATUS_ID) { rowId = ContentUris.parseId(uri); } if (rowId >= 0) { if (matched == ACCOUNTS_ID) { // Don't broadcast if we only changed wizard or only changed priority boolean doBroadcast = true; if (values.size() == 1) { if (values.containsKey(SipProfile.FIELD_WIZARD)) { doBroadcast = false; } else if (values.containsKey(SipProfile.FIELD_PRIORITY)) { doBroadcast = false; } } if (doBroadcast) { broadcastAccountChange(rowId); } } else if (matched == ACCOUNTS_STATUS_ID) { broadcastRegistrationChange(rowId); } } if (matched == FILTERS || matched == FILTERS_ID) { Filter.resetCache(); } return count; }
From source file:at.bitfire.vcard4android.AndroidContact.java
public Uri add() throws ContactsStorageException { BatchOperation batch = new BatchOperation(addressBook.provider); ContentProviderOperation.Builder builder = ContentProviderOperation .newInsert(addressBook.syncAdapterURI(RawContacts.CONTENT_URI)); buildContact(builder, false);//from w w w .j a v a2s . c o m batch.enqueue(builder.build()); insertDataRows(batch); batch.commit(); Uri uri = batch.getResult(0).uri; id = ContentUris.parseId(uri); // we need a raw contact ID to insert the photo insertPhoto(contact.photo); return uri; }
From source file:net.sf.diningout.content.SyncAdapter.java
/** * Sync remote changes to a restaurant./*from w ww. j a v a 2 s.c om*/ */ private void syncRestaurant(ContentProviderClient cp, Sync<Restaurant> sync) throws RemoteException { Restaurant restaurant = sync.object; switch (sync.action) { case INSERT: ContentValues vals = Restaurants.values(restaurant); vals.put(Restaurants.COLOR, Restaurants.defaultColor()); restaurant.localId = ContentUris.parseId(cp.insert(RESTAURANTS_URI, vals)); if (restaurant.localId > 0 && restaurant.status == ACTIVE) { RestaurantService.download(restaurant.localId); try { RestaurantService.photo(restaurant.localId, vals); } catch (IOException e) { Log.e(TAG, "downloading Street View image", e); exception(e); } } break; case UPDATE: restaurant.localId = Restaurants.idForGlobalId(restaurant.globalId); if (restaurant.localId > 0) { vals = Restaurants.values(restaurant); try { // while place_id has UNIQUE constraint cp.update(ContentUris.withAppendedId(RESTAURANTS_URI, restaurant.localId), vals, null, null); } catch (SQLiteConstraintException e) { Log.e(TAG, "updating restaurant from sync", e); exception(e); } try { RestaurantService.photo(restaurant.localId, vals); } catch (IOException e) { Log.e(TAG, "downloading Street View image", e); exception(e); } } else { // re-added on other device sync.action = INSERT; syncRestaurant(cp, sync); } break; } }
From source file:com.csipsimple.db.DBProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { // Constructs a new query builder and sets its table name SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); String finalSortOrder = sortOrder; String[] finalSelectionArgs = selectionArgs; String finalGrouping = null;//w ww .j a v a 2 s .c o m String finalHaving = null; int type = URI_MATCHER.match(uri); Uri regUri = uri; // Security check to avoid data retrieval from outside int remoteUid = Binder.getCallingUid(); int selfUid = android.os.Process.myUid(); if (remoteUid != selfUid) { if (type == ACCOUNTS || type == ACCOUNTS_ID) { for (String proj : projection) { if (proj.toLowerCase().contains(SipProfile.FIELD_DATA) || proj.toLowerCase().contains("*")) { throw new SecurityException("Password not readable from external apps"); } } } } // Security check to avoid project of invalid fields or lazy projection List<String> possibles = getPossibleFieldsForType(type); if (possibles == null) { throw new SecurityException("You are asking wrong values " + type); } checkProjection(possibles, projection); checkSelection(possibles, selection); Cursor c; long id; switch (type) { case ACCOUNTS: qb.setTables(SipProfile.ACCOUNTS_TABLE_NAME); if (sortOrder == null) { finalSortOrder = SipProfile.FIELD_PRIORITY + " ASC"; } break; case ACCOUNTS_ID: qb.setTables(SipProfile.ACCOUNTS_TABLE_NAME); qb.appendWhere(SipProfile.FIELD_ID + "=?"); finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[] { uri.getLastPathSegment() }); break; case CALLLOGS: qb.setTables(SipManager.CALLLOGS_TABLE_NAME); if (sortOrder == null) { finalSortOrder = CallLog.Calls.DATE + " DESC"; } break; case CALLLOGS_ID: qb.setTables(SipManager.CALLLOGS_TABLE_NAME); qb.appendWhere(CallLog.Calls._ID + "=?"); finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[] { uri.getLastPathSegment() }); break; case FILTERS: qb.setTables(SipManager.FILTERS_TABLE_NAME); if (sortOrder == null) { finalSortOrder = Filter.DEFAULT_ORDER; } break; case FILTERS_ID: qb.setTables(SipManager.FILTERS_TABLE_NAME); qb.appendWhere(Filter._ID + "=?"); finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[] { uri.getLastPathSegment() }); break; case MESSAGES: qb.setTables(SipMessage.MESSAGES_TABLE_NAME); if (sortOrder == null) { finalSortOrder = SipMessage.FIELD_DATE + " DESC"; } break; case MESSAGES_ID: qb.setTables(SipMessage.MESSAGES_TABLE_NAME); qb.appendWhere(SipMessage.FIELD_ID + "=?"); finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[] { uri.getLastPathSegment() }); break; case THREADS: qb.setTables(SipMessage.MESSAGES_TABLE_NAME); if (sortOrder == null) { finalSortOrder = SipMessage.FIELD_DATE + " DESC"; } projection = new String[] { "ROWID AS _id", SipMessage.FIELD_FROM, SipMessage.FIELD_FROM_FULL, SipMessage.FIELD_TO, "CASE " + "WHEN " + SipMessage.FIELD_FROM + "='SELF' THEN " + SipMessage.FIELD_TO + " WHEN " + SipMessage.FIELD_FROM + "!='SELF' THEN " + SipMessage.FIELD_FROM + " END AS message_ordering", SipMessage.FIELD_BODY, "MAX(" + SipMessage.FIELD_DATE + ") AS " + SipMessage.FIELD_DATE, "MIN(" + SipMessage.FIELD_READ + ") AS " + SipMessage.FIELD_READ, //SipMessage.FIELD_READ, "COUNT(" + SipMessage.FIELD_DATE + ") AS counter" }; //qb.appendWhere(SipMessage.FIELD_TYPE + " in (" + SipMessage.MESSAGE_TYPE_INBOX // + "," + SipMessage.MESSAGE_TYPE_SENT + ")"); finalGrouping = "message_ordering"; regUri = SipMessage.MESSAGE_URI; break; case THREADS_ID: qb.setTables(SipMessage.MESSAGES_TABLE_NAME); if (sortOrder == null) { finalSortOrder = SipMessage.FIELD_DATE + " DESC"; } projection = new String[] { "ROWID AS _id", SipMessage.FIELD_FROM, SipMessage.FIELD_TO, SipMessage.FIELD_BODY, SipMessage.FIELD_DATE, SipMessage.FIELD_MIME_TYPE, SipMessage.FIELD_TYPE, SipMessage.FIELD_STATUS, SipMessage.FIELD_FROM_FULL }; qb.appendWhere(MESSAGES_THREAD_SELECTION); String from = uri.getLastPathSegment(); finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[] { from, from }); regUri = SipMessage.MESSAGE_URI; break; case ACCOUNTS_STATUS: synchronized (profilesStatus) { ContentValues[] cvs = new ContentValues[profilesStatus.size()]; int i = 0; for (ContentValues ps : profilesStatus.values()) { cvs[i] = ps; i++; } c = getCursor(cvs); } if (c != null) { c.setNotificationUri(getContext().getContentResolver(), uri); } return c; case ACCOUNTS_STATUS_ID: id = ContentUris.parseId(uri); synchronized (profilesStatus) { ContentValues cv = profilesStatus.get(id); if (cv == null) { return null; } c = getCursor(new ContentValues[] { cv }); } c.setNotificationUri(getContext().getContentResolver(), uri); return c; default: throw new IllegalArgumentException(UNKNOWN_URI_LOG + uri); } SQLiteDatabase db = mOpenHelper.getReadableDatabase(); c = qb.query(db, projection, selection, finalSelectionArgs, finalGrouping, finalHaving, finalSortOrder); c.setNotificationUri(getContext().getContentResolver(), regUri); return c; }
From source file:com.android.messaging.mmslib.pdu.PduPersister.java
/** * Load a PDU from storage by given Uri. * * @param uri The Uri of the PDU to be loaded. * @return A generic PDU object, it may be cast to dedicated PDU. * @throws MmsException Failed to load some fields of a PDU. */// w w w . j ava 2 s .c o m public GenericPdu load(final Uri uri) throws MmsException { GenericPdu pdu = null; PduCacheEntry cacheEntry = null; int msgBox = 0; final long threadId = -1; try { synchronized (PDU_CACHE_INSTANCE) { if (PDU_CACHE_INSTANCE.isUpdating(uri)) { if (LOCAL_LOGV) { LogUtil.v(TAG, "load: " + uri + " blocked by isUpdating()"); } try { PDU_CACHE_INSTANCE.wait(); } catch (final InterruptedException e) { Log.e(TAG, "load: ", e); } } // Check if the pdu is already loaded cacheEntry = PDU_CACHE_INSTANCE.get(uri); if (cacheEntry != null) { return cacheEntry.getPdu(); } // Tell the cache to indicate to other callers that this item // is currently being updated. PDU_CACHE_INSTANCE.setUpdating(uri, true); } final Cursor c = SqliteWrapper.query(mContext, mContentResolver, uri, PDU_PROJECTION, null, null, null); final PduHeaders headers = new PduHeaders(); final long msgId = ContentUris.parseId(uri); try { if ((c == null) || (c.getCount() != 1) || !c.moveToFirst()) { return null; // MMS not found } msgBox = c.getInt(PDU_COLUMN_MESSAGE_BOX); //threadId = c.getLong(PDU_COLUMN_THREAD_ID); loadHeadersFromCursor(c, headers); } finally { if (c != null) { c.close(); } } // Check whether 'msgId' has been assigned a valid value. if (msgId == -1L) { throw new MmsException("Error! ID of the message: -1."); } // Load address information of the MM. loadAddress(msgId, headers); final int msgType = headers.getOctet(PduHeaders.MESSAGE_TYPE); final PduBody body = loadBody(msgId, msgType); pdu = createPdu(msgType, headers, body); } finally { synchronized (PDU_CACHE_INSTANCE) { if (pdu != null) { Assert.isNull(PDU_CACHE_INSTANCE.get(uri), "Pdu exists for " + uri); // Update the cache entry with the real info cacheEntry = new PduCacheEntry(pdu, msgBox, threadId); PDU_CACHE_INSTANCE.put(uri, cacheEntry); } PDU_CACHE_INSTANCE.setUpdating(uri, false); PDU_CACHE_INSTANCE.notifyAll(); // tell anybody waiting on this entry to go ahead } } return pdu; }
From source file:com.example.mydemos.view.RingtonePickerActivity.java
@Override public View createTabContent(String tag) { Log.i("lys", "createTabContent tag == " + tag); if (tag.equals("tab_system")) { tabName = SYSTEM_TONE;/*from www . j a va2 s . co m*/ if (toneType == ALARM_TYPE) { where = MediaStore.Audio.Media.IS_ALARM; } else if (toneType == RINGTONE_TYPE) { where = MediaStore.Audio.Media.IS_RINGTONE; } else if (toneType == NOTIFICATION_TYPE) { where = MediaStore.Audio.Media.IS_NOTIFICATION; } } else if (tag.equals("tab_music")) { tabName = MUSIC_TONE; } else { tabName = RECORD_TONE; } Log.e("lys", "tabContent where == " + where); //String project[] = {" DISTINCT title ","_id","_data",MediaStore.Audio.Media.ALBUM,"track","year","is_music","is_ringtone","is_alarm","is_notification"}; switch (tabName) { case SYSTEM_TONE: toneCur = getCursor(tabName, where); //toneCur = getContentResolver().query( // MediaStore.Audio.Media.INTERNAL_CONTENT_URI,null,where, // null, MediaStore.Audio.Media.TITLE+" COLLATE LOCALIZED ASC"); //BaseUri = MediaStore.Audio.Media.INTERNAL_CONTENT_URI; break; case MUSIC_TONE: { where = "mime_type != 'audio/amr'" + " AND " + MediaStore.Audio.Media.TITLE + " != 'hangout_ringtone' AND " + MediaStore.Audio.Media.TITLE + " != 'Join Hangout' AND " + MediaStore.Audio.Media.TITLE + " != 'hangout_dingtone' "; toneCur = getCursor(tabName, where); //final String status = Environment.getExternalStorageState(); //if (status.equals(Environment.MEDIA_MOUNTED) || // status.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) //{ // toneCur = getContentResolver() // .query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,null, // where, null, // MediaStore.Audio.Media.TITLE+" COLLATE LOCALIZED ASC"); //} //else //{ // toneCur = null; //} //BaseUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; break; } case RECORD_TONE: { //new String[] { "recordings" } //where = MediaStore.Audio.Media.ALBUM + " = 'Records' "; where = "mime_type = 'audio/amr'"; toneCur = getCursor(tabName, where); //final String status = Environment.getExternalStorageState(); //if (status.equals(Environment.MEDIA_MOUNTED) || // status.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) //{ // toneCur = getContentResolver().query( // MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,null, where, // null, // MediaStore.Audio.Media.DATE_ADDED+" COLLATE LOCALIZED ASC"); //} //else //{ // toneCur = null; //} //BaseUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; break; } default: return null; } Log.i("lys", "toneCur == " + toneCur); if (toneCur == null) { Log.e("lys", "createTabContent toneCur== null"); //listView.setEmptyView(findViewById(android.R.id.empty)); listView.setAdapter(null); listView.invalidate(); return listView; } if (mHasDefaultItem) { if (RingtoneManager.isDefault(mExistingUri)) { defaultItemChecked = true; silentItemChecked = false; mSelectedId = DEFAULT_ID; //mSelectedUri = mUriForDefaultItem; } } if (mHasSilentItem) { if (mExistingUri == null) { silentItemChecked = true; defaultItemChecked = false; mSelectedId = SILENT_ID; //mSelectedUri = null; } } if ((mSelectedId != DEFAULT_ID) && (mSelectedId != SILENT_ID)) { silentItemChecked = false; defaultItemChecked = false; if (mExistingUri != null) { Log.e("mExistingUri===", mExistingUri.toString()); mSelectedId = ContentUris.parseId(mExistingUri); } //mSelectedUri = mExistingUri; } adapter = new TabListAdapter(this, R.layout.tab_picker_item, toneCur, new String[] {}, new int[] {}); listView.setAdapter(adapter); listView.invalidate(); int index = getRingtonePosition(mExistingUri, tabName, where); if (mHasSilentItem) { index += 1; } if (mHasDefaultItem) { index += 1; } listView.setSelection(index); return listView; }
From source file:com.katamaditya.apps.weather4u.weathersync.Weather4USyncAdapter.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city * @param lon the longitude of the city * @return the row ID of the added location. *//* w ww . j av a2 s . com*/ long addLocation(String locationSetting, String cityName, double lat, double lon) { long locationId; // First, check if the location with this city name exists in the db Cursor locationCursor = getContext().getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, new String[] { WeatherContract.LocationEntry._ID }, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (locationCursor.moveToFirst()) { int locationIdIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID); locationId = locationCursor.getLong(locationIdIndex); } else { // Now that the content provider is set up, inserting rows of data is pretty simple. // First create a ContentValues object to hold the data you want to insert. ContentValues locationValues = new ContentValues(); // Then add the data, along with the corresponding name of the data type, // so the content provider knows what kind of value is being inserted. locationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); // Finally, insert location data into the database. Uri insertedUri = getContext().getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, locationValues); // The resulting URI contains the ID for the row. Extract the locationId from the Uri. locationId = ContentUris.parseId(insertedUri); } locationCursor.close(); // Wait, that worked? Yes! return locationId; }