=== modified file 'AndroidManifest.xml' --- AndroidManifest.xml 2011-04-17 16:40:53 +0000 +++ AndroidManifest.xml 2011-06-29 10:52:37 +0000 @@ -175,7 +175,12 @@ - + + + === added directory 'src/ru/orangesoftware/financisto/provider' === added file 'src/ru/orangesoftware/financisto/provider/FinancistoProvider.java' --- src/ru/orangesoftware/financisto/provider/FinancistoProvider.java 1970-01-01 00:00:00 +0000 +++ src/ru/orangesoftware/financisto/provider/FinancistoProvider.java 2011-06-29 10:48:39 +0000 @@ -0,0 +1,126 @@ +package ru.orangesoftware.financisto.provider; + +import java.util.HashMap; +import java.util.Map; + +import ru.orangesoftware.financisto.db.DatabaseHelper; + +import android.content.ContentProvider; +import android.content.ContentResolver; +import android.content.ContentUris; +import android.content.ContentValues; +import android.content.UriMatcher; +import android.database.Cursor; +import android.net.Uri; +import android.provider.BaseColumns; + +/** + * Android ContentProvider implementation to enable 3rd party access to + * Financisto transaction data. + * + * @author esteewhy + */ +public class FinancistoProvider extends ContentProvider { + + private final static String CONTENT_AUTHORITY = "ru.orangesoftware.financisto"; + + public static final String TRANSACTION_ITEM_TYPE = + ContentResolver.CURSOR_ITEM_BASE_TYPE + "/vnd.financisto.transaction"; + public static final String TRANSACTION_TYPE = + ContentResolver.CURSOR_DIR_BASE_TYPE + "/vnd.financisto.transactions"; + public static final String LOCATION_ITEM_TYPE = + ContentResolver.CURSOR_ITEM_BASE_TYPE + "/vnd.financisto.location"; + public static final String LOCATION_TYPE = + ContentResolver.CURSOR_DIR_BASE_TYPE + "/vnd.financisto.locations"; + + private final static int TRANSACTIONS = 100; + private final static int TRANSACTIONS_ID = 101; + private final static int LOCATIONS = 400; + private final static int LOCATIONS_ID = 401; + + private static final Map schemaLookup = new HashMap(); + private static final int LOOKUP_CONTENT_TYPE = 0; + private static final int LOOKUP_TABLE = 1; + + private static final UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); + + static { + uriMatcher.addURI(CONTENT_AUTHORITY, "transactions", TRANSACTIONS); + uriMatcher.addURI(CONTENT_AUTHORITY, "locations", LOCATIONS); + uriMatcher.addURI(CONTENT_AUTHORITY, "transactions/#", TRANSACTIONS_ID); + uriMatcher.addURI(CONTENT_AUTHORITY, "locations/#", LOCATIONS_ID); + + schemaLookup.put(TRANSACTIONS, new String[] { TRANSACTION_TYPE, "transactions" }); + schemaLookup.put(TRANSACTIONS_ID, new String[] { TRANSACTION_ITEM_TYPE, "transactions" }); + schemaLookup.put(LOCATIONS, new String[] { LOCATION_TYPE, "locations" }); + schemaLookup.put(LOCATIONS_ID, new String[] { LOCATION_ITEM_TYPE, "locations" }); + } + + @Override + public int delete(Uri arg0, String arg1, String[] arg2) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public String getType(Uri uri) { + final int uriCode = uriMatcher.match(uri); + + if(schemaLookup.containsKey(uriCode)) { + return schemaLookup.get(uriCode)[LOOKUP_CONTENT_TYPE]; + } + + throw new UnsupportedOperationException("Unknown uri: " + uri); + } + + @Override + public Uri insert(Uri uri, ContentValues values) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean onCreate() { + // TODO Auto-generated method stub + return false; + } + + @Override + public Cursor query(Uri uri, String[] projection, String selection, + String[] selectionArgs, String sortOrder) { + final int uriCode = uriMatcher.match(uri); + + if(schemaLookup.containsKey(uriCode)) { + final String table = schemaLookup.get(uriCode)[LOOKUP_TABLE]; + + switch(uriCode) { + + case TRANSACTIONS: + case LOCATIONS: + return new DatabaseHelper(getContext()) + .getReadableDatabase() + .query(table, projection, selection, selectionArgs, + null, null, sortOrder); + + case TRANSACTIONS_ID: + case LOCATIONS_ID: + final long id = ContentUris.parseId(uri); + return new DatabaseHelper(getContext()) + .getReadableDatabase() + .query(table, projection, + BaseColumns._ID + " = ?", + new String[] { Long.toString(id) }, + null, null, null, "1"); + } + } + + throw new UnsupportedOperationException("Unknown uri: " + uri); + } + + @Override + public int update(Uri uri, ContentValues values, String selection, + String[] selectionArgs) { + // TODO Auto-generated method stub + return 0; + } +} \ No newline at end of file