Back to project page groceryviewer.
The source code is released under:
GNU General Public License
If you think the Android project groceryviewer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.github.knrajago.groceryviewer.providers; // w w w . j av a 2 s.c o m import com.github.knrajago.groceryviewer.localdb.GroceryListHelper; import android.content.ContentProvider; import android.content.ContentValues; import android.content.UriMatcher; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.net.Uri; import android.provider.BaseColumns; import static com.github.knrajago.groceryviewer.constants.GroceryViewerConstants.AUTHORITIES_STRING; import static com.github.knrajago.groceryviewer.constants.GroceryViewerConstants.ONE_ROW; import static com.github.knrajago.groceryviewer.constants.GroceryViewerConstants.ALL_TABLE; import static com.github.knrajago.groceryviewer.constants.GroceryViewerConstants.TABLE_NAME; import static com.github.knrajago.groceryviewer.constants.GroceryViewerConstants.ITEM_COL; public class GroceryViewerContentProvider extends ContentProvider { // Creates a UriMatcher object. private static final UriMatcher sUriMatcher; static { sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH); sUriMatcher.addURI(AUTHORITIES_STRING, "MaligaiListProvider", ALL_TABLE); sUriMatcher.addURI(AUTHORITIES_STRING, "MaligaiListProvider/#", ONE_ROW); } private GroceryListHelper mDBHelper; public GroceryViewerContentProvider() { // TODO Auto-generated constructor stub } @Override public int delete(Uri uri, String selection, String[] selectionArgs) { SQLiteDatabase db = mDBHelper.getWritableDatabase(); int deleteCount = db.delete(TABLE_NAME, selection, selectionArgs); db.close(); return deleteCount; } @Override public String getType(Uri uri) { return null; } @Override public Uri insert(Uri pUri, ContentValues pValues) { SQLiteDatabase db = mDBHelper.getWritableDatabase(); long id = db.insertOrThrow(TABLE_NAME, null, pValues); db.close(); return pUri; } @Override public boolean onCreate() { mDBHelper = new GroceryListHelper(getContext()); return true; } @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { switch(sUriMatcher.match(uri)) { case ALL_TABLE: SQLiteDatabase db = mDBHelper.getReadableDatabase(); return db.query(TABLE_NAME, new String[] {BaseColumns._ID, ITEM_COL}, null, null, null, null, null); default: } return null; } @Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { return 0; } }