@Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { SQLiteDatabase db = helper.getWritableDatabase(); int count = 0; switch (uriMatcher.match(uri)) { case MEDIAS: count = db.update(MediaSchema.TABLE_NAME, values, selection, selectionArgs); break; case MEDIA_ID: count = db.update( // MediaSchema.TABLE_NAME, // values, // MediaSchema._ID + " = " + uri.getPathSegments().get(1) + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), // selectionArgs // ); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } getContext().getContentResolver().notifyChange(uri, null); return count; }
@Override public int update(Uri uri, ContentValues values, String where, String[] whereArgs) { int count = 0; SQLiteDatabase db = openHelper.getWritableDatabase(); int match = uriMatcher.match(uri); switch (match) { case CHATS: count = db.update(TABLE_CHAT, values, where, whereArgs); break; case MESSAGES: count = db.update(TABLE_MESSAGE, values, where, whereArgs); break; case CHAT_ID: count = db.update( TABLE_CHAT, values, ChatData.KEY_ID + "=" + Integer.parseInt(uri.getPathSegments().get(1)), null); break; case MESSAGE_ID: count = db.update( TABLE_MESSAGE, values, MessageData.KEY_ID + "=" + Integer.parseInt(uri.getPathSegments().get(1)), null); break; default: throw new UnsupportedOperationException("Cannot update URI " + uri); } getContext().getContentResolver().notifyChange(uri, null); return count; }
public Uri insert(Uri paramUri, ContentValues paramContentValues) { SQLiteDatabase localSQLiteDatabase = mOpenHelper.getWritableDatabase(); int i = paramUri.getPathSegments().size(); if (i < 1) { throw new IllegalArgumentException("Unknown Uri"); } long l2 = -1L; String str = (String) paramUri.getPathSegments().get(0); Object localObject = null; paramUri = (Uri) localObject; long l1 = l2; if (str.equals("suggestions")) { paramUri = (Uri) localObject; l1 = l2; if (i == 1) { l2 = localSQLiteDatabase.insert("suggestions", "query", paramContentValues); paramUri = (Uri) localObject; l1 = l2; if (l2 > 0L) { paramUri = Uri.withAppendedPath(mSuggestionsUri, String.valueOf(l2)); l1 = l2; } } } if (l1 < 0L) { throw new IllegalArgumentException("Unknown Uri"); } getContext().getContentResolver().notifyChange(paramUri, null); return paramUri; }
public static boolean matchesContentUri(Uri uri, Uri baseContentUri) { if (uri == null) { return false; } // Check that scheme and authority are the same. if (!uri.getScheme().equals(baseContentUri.getScheme()) || !uri.getAuthority().equals(baseContentUri.getAuthority())) { return false; } // Checks that all the base path components are in the URI. List<String> uriPathSegments = uri.getPathSegments(); List<String> basePathSegments = baseContentUri.getPathSegments(); if (basePathSegments.size() > uriPathSegments.size()) { return false; } for (int i = 0; i < basePathSegments.size(); i++) { if (!uriPathSegments.get(i).equals(basePathSegments.get(i))) { return false; } } return true; }
static BitmapHunter forRequest( Context context, Picasso picasso, Dispatcher dispatcher, Cache cache, Stats stats, Action action, Downloader downloader) { if (action.getData().resourceId != 0) { return new ResourceBitmapHunter(context, picasso, dispatcher, cache, stats, action); } Uri uri = action.getData().uri; String scheme = uri.getScheme(); if (SCHEME_CONTENT.equals(scheme)) { if (Contacts.CONTENT_URI.getHost().equals(uri.getHost()) // && !uri.getPathSegments().contains(Contacts.Photo.CONTENT_DIRECTORY)) { return new ContactsPhotoBitmapHunter(context, picasso, dispatcher, cache, stats, action); } else { return new ContentProviderBitmapHunter(context, picasso, dispatcher, cache, stats, action); } } else if (SCHEME_FILE.equals(scheme)) { if (!uri.getPathSegments().isEmpty() && ANDROID_ASSET.equals(uri.getPathSegments().get(0))) { return new AssetBitmapHunter(context, picasso, dispatcher, cache, stats, action); } return new FileBitmapHunter(context, picasso, dispatcher, cache, stats, action); } else if (SCHEME_ANDROID_RESOURCE.equals(scheme)) { return new ResourceBitmapHunter(context, picasso, dispatcher, cache, stats, action); } else { return new NetworkBitmapHunter(picasso, dispatcher, cache, stats, action, downloader); } }
@Override public int update(Uri uri, ContentValues values, String where, String[] whereArgs) { SQLiteDatabase db = mOpenHelper.getWritableDatabase(); int count; String finalWhere; switch (sUriMatcher.match(uri)) { case NOTES: count = db.update(NotePad.Notes.TABLE_NAME, values, where, whereArgs); break; case NOTE_ID: String noteId = uri.getPathSegments().get(NotePad.Notes.NOTE_ID_PATH_POSITION); finalWhere = NotePad.Notes._ID + " = " + uri.getPathSegments().get(NotePad.Notes.NOTE_ID_PATH_POSITION); if (where != null) { finalWhere = finalWhere + " AND " + where; } count = db.update(NotePad.Notes.TABLE_NAME, values, finalWhere, whereArgs); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } getContext().getContentResolver().notifyChange(uri, null); return count; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor cursor = null; switch (uriMatcher.match(uri)) { case BOOK_DIR: cursor = db.query("Book", projection, selection, selectionArgs, null, null, sortOrder); break; case BOOK_ITEM: String bookId = uri.getPathSegments().get(1); cursor = db.query("Book", projection, "id = ?", new String[] {bookId}, null, null, sortOrder); break; case CATEGORY_DIR: cursor = db.query("Category", projection, selection, selectionArgs, null, null, sortOrder); break; case CATEGORY_ITEM: String categoryId = uri.getPathSegments().get(1); cursor = db.query( "Category", projection, "id = ?", new String[] {categoryId}, null, null, sortOrder); break; default: break; } return cursor; }
@Override public Cursor query( Uri uri, String[] projections, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder sqlBuilder = new SQLiteQueryBuilder(); switch (uriMatcher.match(uri)) { case FINDS_BY_PROJECT: sqlBuilder.setTables(PositDbHelper.FINDS_TABLE); sqlBuilder.appendWhere( PositDbHelper.FINDS_PROJECT_ID + " = " + uri.getPathSegments().get(1)); break; case FIND_ID: sqlBuilder.setTables(PositDbHelper.FINDS_TABLE); sqlBuilder.appendWhere(PositDbHelper.FINDS_ID + " = " + uri.getPathSegments().get(1)); break; case PHOTO_FINDID: sqlBuilder.setTables(PositDbHelper.PHOTOS_TABLE); sqlBuilder.appendWhere(PositDbHelper.FINDS_ID + " = " + uri.getPathSegments().get(1)); break; case PHOTOS_BY_PROJECT: sqlBuilder.setTables(PositDbHelper.PHOTOS_TABLE); sqlBuilder.appendWhere( PositDbHelper.FINDS_PROJECT_ID + " = " + uri.getPathSegments().get(1)); break; } Cursor c = sqlBuilder.query(db, projections, selection, selectionArgs, null, null, sortOrder); c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
public static String[] getLocationAndTimeFromUri(Uri uri) { String[] locationWithTime = new String[] { uri.getPathSegments().get(1), uri.getPathSegments().get(2), uri.getPathSegments().get(3) }; return locationWithTime; }
SqlArguments(Uri url) { if (url.getPathSegments().size() == 1) { table = url.getPathSegments().get(0); where = null; args = null; } else { throw new IllegalArgumentException("Invalid URI: " + url); } }
protected void initView() { mHandler = new Handler(this); mDialog = new LoadingDialog(this); mFragmentManager = getSupportFragmentManager(); getSupportActionBar().setTitle(R.string.main_name); DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); // 获取屏幕信息 indicatorWidth = dm.widthPixels / 4; // 指示器宽度为屏幕宽度的4/1 mMainShow = (LinearLayout) findViewById(R.id.main_show); mMainConversationLiner = (RelativeLayout) findViewById(R.id.main_conversation_liner); mMainGroupLiner = (RelativeLayout) findViewById(R.id.main_group_liner); mMainChatroomLiner = (RelativeLayout) findViewById(R.id.main_chatroom_liner); mMainCustomerLiner = (RelativeLayout) findViewById(R.id.main_customer_liner); mMainConversationTv = (TextView) findViewById(R.id.main_conversation_tv); mMainGroupTv = (TextView) findViewById(R.id.main_group_tv); mMainChatroomTv = (TextView) findViewById(R.id.main_chatroom_tv); mMainCustomerTv = (TextView) findViewById(R.id.main_customer_tv); mViewPager = (ViewPager) findViewById(R.id.main_viewpager); mMainSelectImg = (ImageView) findViewById(R.id.main_switch_img); mUnreadNumView = (TextView) findViewById(R.id.de_num); mCustomerNoRead = (TextView) findViewById(R.id.customer_noread); ViewGroup.LayoutParams cursor_Params = mMainSelectImg.getLayoutParams(); cursor_Params.width = indicatorWidth; // 初始化滑动下标的宽 mMainSelectImg.setLayoutParams(cursor_Params); // 获取布局填充器 mInflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE); if (getIntent() != null) { if (getIntent().hasExtra("PUSH_TOKEN") && getIntent().hasExtra("PUSH_INTENT")) { Uri uri = getIntent().getParcelableExtra("PUSH_INTENT"); String token = getIntent().getStringExtra("PUSH_TOKEN").toString(); String pathSegments; String conversationType = null; String targetId = null; if (uri.getPathSegments().get(0).equals("conversation")) { pathSegments = uri.getPathSegments().get(0); conversationType = Conversation.ConversationType.valueOf( uri.getLastPathSegment().toUpperCase(Locale.getDefault())) .toString(); targetId = uri.getQueryParameter("targetId").toString(); } else { pathSegments = uri.getLastPathSegment(); } reconnect(token, pathSegments, conversationType, targetId); if (DemoContext.getInstance() != null) { mGetMyGroupsRequest = DemoContext.getInstance().getDemoApi().getMyGroups(MainActivity.this); } } } }
private QuerySelection querySingle(Uri uri) { final String selection = " vercode = ? and id = ? "; final String[] args = { // First (0th) path segment is the word "apk", // and we are not interested in it. uri.getPathSegments().get(1), uri.getPathSegments().get(2), }; return new QuerySelection(selection, args); }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { final SQLiteDatabase db = new TravelDbHelper(getContext()).getReadableDatabase(); Cursor ret; switch (matcher.match(uri)) { case JOURNAL: ret = db.query( JournalEntry.TABLE_NAME, projection, selection, selectionArgs, null, null, sortOrder); break; case ENTRY: ret = db.query( EntryEntry.TABLE_NAME, projection, selection, selectionArgs, null, null, sortOrder); break; case ENTRY_BY_JOURNAL: if (selection == (null) || selection.equals("")) selection = "1"; Cursor cursor = db.query( JournalEntry.TABLE_NAME, new String[] {JournalEntry.COLUMN_ID}, JournalEntry.COLUMN_NAME + " = ?", new String[] {uri.getPathSegments().get(1)}, null, null, null); if (cursor.moveToFirst()) { long journalID = cursor.getLong(0); ret = db.query( EntryEntry.TABLE_NAME, projection, selection + " AND " + EntryEntry.COLUMN_JOURNAL_ID + " = " + journalID, selectionArgs, null, null, sortOrder); } else throw new UnsupportedOperationException( "There is no journal with the name: " + uri.getPathSegments().get(1)); cursor.close(); break; default: throw new UnsupportedOperationException("Unknown URI detected: " + uri); } ret.setNotificationUri(getContext().getContentResolver(), uri); return ret; }
@Override public int delete(Uri uri, String selection, String[] selectionArgs) { final SQLiteDatabase db = new TravelDbHelper(getContext()).getWritableDatabase(); int rows = 0; if (selection == null) selection = "1"; switch (matcher.match(uri)) { case JOURNAL: rows = db.delete(JournalEntry.TABLE_NAME, selection, selectionArgs); Log.w( "TravelLogger", "Journal deleted without using TravelContentProvider.SafeDelete()! Possible journal entries left undeleted!"); break; case ENTRY: rows = db.delete( EntryEntry.TABLE_NAME, selection + " AND " + EntryEntry.COLUMN_JOURNAL_ID + " = " + uri.getPathSegments().get(1), selectionArgs); break; case ENTRY_BY_JOURNAL: Cursor cursor = db.query( JournalEntry.TABLE_NAME, new String[] {JournalEntry.COLUMN_ID}, JournalEntry.COLUMN_NAME + " = ?", new String[] {uri.getPathSegments().get(1)}, null, null, null); if (cursor.moveToFirst()) { long journalID = cursor.getLong(0); rows = db.delete( EntryEntry.TABLE_NAME, selection + " AND " + EntryEntry.COLUMN_JOURNAL_ID + " = " + journalID, selectionArgs); } else throw new UnsupportedOperationException( "No journal with name: " + uri.getPathSegments().get(1)); break; default: throw new UnsupportedOperationException("Unknown Uri detected: " + uri); } if (rows > 0) { getContext().getContentResolver().notifyChange(uri, null); } return rows; }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if ((requestCode == PHOTO_PICKED || requestCode == CROP_DONE) && (resultCode == RESULT_OK) && (data != null)) { Log.d(LOG_TAG, "what is data=" + data); Bundle extrbudle = data.getExtras(); Bitmap bitmap = (Bitmap) extrbudle.get("data"); if (bitmap == null) { Uri uri = Uri.parse(data.getAction()); if (uri != null) { String[] cols = new String[] { MediaStore.Images.Media.DATA, }; String who = uri.getPathSegments().get(uri.getPathSegments().size() - 1); String[] whereclause = new String[] {who}; Cursor mCursor = getContentResolver() .query(uri, cols, android.provider.BaseColumns._ID + " = ?", whereclause, null); if (mCursor != null) { mCursor.moveToFirst(); String filePath = mCursor.getString(0); try { Log.d(LOG_TAG, "save path=" + filePath); File tempFile = new File(filePath); InputStream s = new FileInputStream(filePath); bitmap = BitmapFactory.decodeStream(s); } catch (Exception ne) { Log.d(LOG_TAG, "no such file=" + ne.getMessage()); } } } } if (bitmap == null) { Log.e(LOG_TAG, "Failed to set wallpaper. Couldn't get bitmap for path " + mTempFilePath); finish(); } else { Log.v(LOG_TAG, "bitmap size is " + bitmap.getWidth() + " / " + bitmap.getHeight()); mHandler.sendEmptyMessage(SHOW_PROGRESS); new SetWallpaperThread(bitmap, mHandler, this, null).start(); } mDoLaunch = false; } else { Log.d(LOG_TAG, "no data"); setResult(RESULT_CANCELED); finish(); } }
public int delete(Uri paramUri, String paramString, String[] paramArrayOfString) { SQLiteDatabase localSQLiteDatabase = mOpenHelper.getWritableDatabase(); if (paramUri.getPathSegments().size() != 1) { throw new IllegalArgumentException("Unknown Uri"); } if (((String) paramUri.getPathSegments().get(0)).equals("suggestions")) { int i = localSQLiteDatabase.delete("suggestions", paramString, paramArrayOfString); getContext().getContentResolver().notifyChange(paramUri, null); return i; } throw new IllegalArgumentException("Unknown Uri"); }
@Override public int update(Uri uri, ContentValues values, String where, String[] whereArgs) { SQLiteDatabase db; String noteId; int count; switch (sUriMatcher.match(uri)) { case KNOU_NOTICES: db = mOpenHelper.getWritableDatabase(); count = db.update(KNOU_NOTICE.TABLE_NAME, values, where, whereArgs); break; case KNOU_NOTICE_ID: noteId = uri.getPathSegments().get(1); db = mOpenHelper.getWritableDatabase(); count = db.update( KNOU_NOTICE.TABLE_NAME, values, KNOU_NOTICE._ID + "=" + noteId + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""), whereArgs); break; case KNOU_NOTICE_FILES: db = mOpenHelper.getWritableDatabase(); count = db.update(KNOU_NOTICE_FILE.TABLE_NAME, values, where, whereArgs); break; case KNOU_NOTICE_FILE_ID: noteId = uri.getPathSegments().get(1); db = mOpenHelper.getWritableDatabase(); count = db.update( KNOU_NOTICE_FILE.TABLE_NAME, values, KNOU_NOTICE_FILE._ID + "=" + noteId + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""), whereArgs); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } getContext().getContentResolver().notifyChange(uri, null); return count; }
@Override public Cursor query( Uri url, String[] projectionIn, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qBuilder = new SQLiteQueryBuilder(); int match = URI_MATCHER.match(url); String groupBy = null; switch (match) { case GROUPS: qBuilder.setTables(TABLE_ROSTER + " " + QUERY_ALIAS); groupBy = RosterConstants.GROUP; break; case GROUP_MEMBERS: qBuilder.setTables(TABLE_ROSTER + " " + QUERY_ALIAS); qBuilder.appendWhere(RosterConstants.GROUP + "="); qBuilder.appendWhere(url.getPathSegments().get(1)); break; case CONTACTS: qBuilder.setTables(TABLE_ROSTER + " " + QUERY_ALIAS); break; case CONTACT_ID: qBuilder.setTables(TABLE_ROSTER + " " + QUERY_ALIAS); qBuilder.appendWhere("_id="); qBuilder.appendWhere(url.getPathSegments().get(1)); break; default: throw new IllegalArgumentException("Unknown URL " + url); } String orderBy; if (TextUtils.isEmpty(sortOrder) && match == CONTACTS) { orderBy = RosterConstants.DEFAULT_SORT_ORDER; // 默认按在线状态排序 } else { orderBy = sortOrder; } SQLiteDatabase db = mOpenHelper.getReadableDatabase(); Cursor ret = qBuilder.query(db, projectionIn, selection, selectionArgs, groupBy, null, orderBy); if (ret == null) { infoLog("RosterProvider.query: failed"); } else { ret.setNotificationUri(getContext().getContentResolver(), url); } return ret; }
@Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { final SQLiteDatabase db = new TravelDbHelper(getContext()).getWritableDatabase(); int rows = 0; if (selection == (null) || selection.equals("")) { selection = "1"; } switch (matcher.match(uri)) { case JOURNAL: rows = db.update(JournalEntry.TABLE_NAME, values, selection, selectionArgs); break; case ENTRY: values.put("journal_id", Integer.parseInt(uri.getPathSegments().get(1))); rows = db.update(EntryEntry.TABLE_NAME, values, selection, selectionArgs); break; case ENTRY_BY_JOURNAL: Cursor c = db.query( JournalEntry.TABLE_NAME, new String[] {JournalEntry.COLUMN_ID}, JournalEntry.COLUMN_NAME + " = ?", new String[] {uri.getPathSegments().get(1)}, null, null, null); if (!c.moveToFirst()) { throw new UnsupportedOperationException( "There is no journal with the following name: " + uri.getPathSegments().get(1)); } long dbIndex = c.getLong(0); rows = db.update( EntryEntry.TABLE_NAME, values, selection + " AND " + EntryEntry.COLUMN_JOURNAL_ID + " = " + dbIndex, selectionArgs); c.close(); break; default: throw new UnsupportedOperationException("Unknown Uri detected: " + uri); } if (rows > 0) { getContext().getContentResolver().notifyChange(uri, null); } return rows; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qdb = new SQLiteQueryBuilder(); // qdb.setTables(TABLE_NAMEIP); Log.v("CP", "QUERY"); switch (uriMatcher.match(uri)) { // Selecting rows case ALL_ROWS_IP: Log.v("CP", "all_rows"); qdb.setTables(TABLE_NAMEIP); qdb.setProjectionMap(hash_values); // Sorting by id if (sortOrder == null || sortOrder.equals("")) sortOrder = _ID; break; case SINGLE_ROW_IP: Log.v("CP", "single_rows"); qdb.setTables(TABLE_NAMEIP); qdb.appendWhere(_ID + "=" + uri.getPathSegments().get(1)); // Sorting by id if (sortOrder == null || sortOrder.equals("")) sortOrder = _ID; break; case ALL_ROWS_DATA: Log.v("CP", "all_rows"); qdb.setTables(TABLE_NAMEDATA); qdb.setProjectionMap(hash_values); // Sorting by id if (sortOrder == null || sortOrder.equals("")) sortOrder = _ID2; break; case SINGLE_ROW_DATA: Log.v("CP", "single_rows"); qdb.setTables(TABLE_NAMEDATA); qdb.appendWhere(_ID2 + "=" + uri.getPathSegments().get(1)); // Sorting by id if (sortOrder == null || sortOrder.equals("")) sortOrder = _ID2; break; default: throw new IllegalArgumentException("Unknown URI: " + uri); } // Starting query Cursor c = qdb.query(db, projection, selection, selectionArgs, null, null, sortOrder); c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
SqlArguments(Uri url, String where, String[] args) { if (url.getPathSegments().size() == 1) { this.table = url.getPathSegments().get(0); this.where = where; this.args = args; } else if (url.getPathSegments().size() != 2) { throw new IllegalArgumentException("Invalid URI: " + url); } else if (!TextUtils.isEmpty(where)) { throw new UnsupportedOperationException("WHERE clause not supported: " + url); } else { this.table = url.getPathSegments().get(0); this.where = "_id=" + ContentUris.parseId(url); this.args = null; } }
public String getType(Uri paramUri) { if (mUriMatcher.match(paramUri) == 1) { return "vnd.android.cursor.dir/vnd.android.search.suggest"; } int i = paramUri.getPathSegments().size(); if ((i >= 1) && (((String) paramUri.getPathSegments().get(0)).equals("suggestions"))) { if (i == 1) { return "vnd.android.cursor.dir/suggestion"; } if (i == 2) { return "vnd.android.cursor.item/suggestion"; } } throw new IllegalArgumentException("Unknown Uri"); }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { String orderBy = null; SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); switch (sUriMatcher.match(uri)) { case INCOMING_EVENT_COLLECTION_URI_INDICATOR: qb.setTables(EventTableMetaData.TABLE_NAME); qb.setProjectionMap(sEventProjectionMap); break; case INCOMING_EVENT_SINGLE_URI_INDICATOR: qb.setTables(EventTableMetaData.TABLE_NAME); qb.setProjectionMap(sEventProjectionMap); qb.appendWhere(EventTableMetaData.ITEM_ID + "=" + uri.getPathSegments().get(1)); break; case INCOMING_PROFILE_SINGLE_URI_INDICATOR: qb.setTables(ProfileTableMetaData.TABLE_NAME); qb.setProjectionMap(sProfileProjectionMap); qb.appendWhere(ProfileTableMetaData._ID + "=" + uri.getPathSegments().get(1)); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } // set order by switch (sUriMatcher.match(uri)) { case INCOMING_EVENT_COLLECTION_URI_INDICATOR: case INCOMING_EVENT_SINGLE_URI_INDICATOR: if (TextUtils.isEmpty(sortOrder)) { orderBy = EventTableMetaData.DEFAULT_SORT_ORDER; } else { orderBy = sortOrder; } break; case INCOMING_PROFILE_SINGLE_URI_INDICATOR: if (TextUtils.isEmpty(sortOrder)) { orderBy = ProfileTableMetaData.DEFAULT_SORT_ORDER; } else { orderBy = sortOrder; } break; default: throw new IllegalArgumentException("Unknown URI " + uri); } SQLiteDatabase db = mOpenHelper.getReadableDatabase(); Cursor cursor = qb.query(db, projection, selection, selectionArgs, null, null, orderBy); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { // TODO Auto-generated method stub // check uri // first 通过SQLiteQueryBuilder,设置数据库查询的信息.Uri有两种情况,一种是collect, // 一种已经指定某个item,两者需要区别对待,item将获取_ID,并在where中增加一个匹配条件. SQLiteQueryBuilder dbQuery = new SQLiteQueryBuilder(); final int match = sUriMatch.match(uri); switch (match) { case HISTORY_COLLECTION_URI_INDICATOR: dbQuery.setTables(ChatHistoryTable.TABLE_NAME); dbQuery.setProjectionMap(sHistoryProjectionMap); break; case HISTORY_ITEM_URI_INDICATION: dbQuery.setTables(ChatHistoryTable.TABLE_NAME); dbQuery.setProjectionMap(sHistoryProjectionMap); dbQuery.appendWhere(ChatHistoryTable._ID + "=" + uri.getPathSegments().get(1)); break; default: throw new IllegalArgumentException("Unknow uri=" + uri); } // second v 对排序进行缺省设置 // String order = TextUtils.isEmpty(sortOrder) ? HistoryTable.DEFAULE_SORT_ORDER : sortOrder; SQLiteDatabase db = mOpenHelper.getReadableDatabase(); // third start query final Cursor c = dbQuery.query(db, projection, selection, selectionArgs, null, null, sortOrder); // fourth 向系统注册通知:观察所要查询的数据,即Uri对应的数据是否发生变化 // 开发者通过provider接口获取数据,可通过通知获知数据已经发生变更 if (c != null) { c.setNotificationUri(mContentResolver, ChatHistoryTable.CONTENT_URI); } return c; }
@Override public int delete(Uri uri, String where, String[] whereArgs) { SQLiteDatabase db = mOpenHelper.getWritableDatabase(); int count; switch (sUriMatcher.match(uri)) { case RECIPES: count = db.delete(RECIPES_TABLE_NAME, where, whereArgs); break; case RECIPE_ID: String recipeId = uri.getPathSegments().get(1); count = db.delete( RECIPES_TABLE_NAME, Recipes._ID + "=" + recipeId + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""), whereArgs); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } getContext().getContentResolver().notifyChange(uri, null); return count; }
@Override public int delete(Uri url, String where, String[] whereArgs) { SQLiteDatabase db = mOpenHelper.getWritableDatabase(); int count; switch (URI_MATCHER.match(url)) { case CONTACTS: count = db.delete(TABLE_ROSTER, where, whereArgs); break; case CONTACT_ID: String segment = url.getPathSegments().get(1); if (TextUtils.isEmpty(where)) { where = "_id=" + segment; } else { where = "_id=" + segment + " AND (" + where + ")"; } count = db.delete(TABLE_ROSTER, where, whereArgs); break; default: throw new IllegalArgumentException("Cannot delete from URL: " + url); } getContext().getContentResolver().notifyChange(GROUPS_URI, null); notifyChange(); return count; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { Log.e("appstorequery", "uri is " + uri.toString()); Log.e("appstorequery", "seletcion is " + selection); Log.e("appstorequery", "selectionArgs is " + selectionArgs[0]); Log.e("appstorequery", "selectionArgs is " + selectionArgs[1]); selection = "url=? AND service_name=?"; selectionArgs = new String[] {"http://www.baidu.com/1", "service1"}; switch (uriMatcher.match(uri)) { case ITEMS: // Log.d("appstorequery", "uri is ITEMS "); return database.query( TABLE_URL_PERMISSIONS, projection, selection, selectionArgs, null, null, sortOrder); case ITEM: // Log.d("appstorequery", "uri is ITEM "); return database.query( TABLE_URL_PERMISSIONS, projection, _ID + "=" + uri.getPathSegments().get(1), selectionArgs, null, null, null); default: throw new IllegalArgumentException("unknown uri: " + uri); } }
public PublicURLProcessor(Uri uri) { mUri = uri; mHost = mUri.getHost(); if (!Util.isEmpty(mHost)) { mHost = mHost.toLowerCase(); } mPathSegments = mUri.getPathSegments(); mRefmarker = mUri.getQueryParameter("ref"); mAssociateTag = mUri.getQueryParameter("tag"); mLocaleName = getLocaleNameFromUri(uri); mParams = new HashMap(); String s; boolean flag; if (android.os.Build.VERSION.SDK_INT >= 11) { flag = true; } else { flag = false; } if (flag) { uri = mUri.getQueryParameterNames(); } else { uri = parseQueryParameterNames(mUri); } for (uri = uri.iterator(); uri.hasNext(); mParams.put(s, mUri.getQueryParameter(s))) { s = (String)uri.next(); } }
/** * Returns the mime type for a given attachment. There are three possible results: - If thumbnail * Uri, always returns "image/png" (even if there's no attachment) - If the attachment does not * exist, returns null - Returns the mime type of the attachment */ @Override public String getType(Uri uri) { List<String> segments = uri.getPathSegments(); String accountId = segments.get(0); String id = segments.get(1); String format = segments.get(2); if (FORMAT_THUMBNAIL.equals(format)) { return "image/png"; } else { uri = ContentUris.withAppendedId(Attachment.CONTENT_URI, Long.parseLong(id)); Cursor c = getContext().getContentResolver().query(uri, MIME_TYPE_PROJECTION, null, null, null); try { if (c.moveToFirst()) { String mimeType = c.getString(MIME_TYPE_COLUMN_MIME_TYPE); String fileName = c.getString(MIME_TYPE_COLUMN_FILENAME); mimeType = inferMimeType(fileName, mimeType); return mimeType; } } finally { c.close(); } return null; } }
public Cursor a( Uri uri, String as[], String s, String as1[], String s1, SQLiteQueryBuilder sqlitequerybuilder, SQLiteDatabase sqlitedatabase) { sqlitequerybuilder.setProjectionMap(a()); sqlitequerybuilder.setTables("attach"); if (a) { sqlitequerybuilder.appendWhere( (new StringBuilder()) .append("_id=") .append((String) uri.getPathSegments().get(1)) .toString()); } String s2; if (TextUtils.isEmpty(s1)) { s2 = "url DESC"; } else { s2 = s1; } return sqlitequerybuilder.query(sqlitedatabase, as, s, as1, null, null, s2); }