If you think the Android project android-webview-example listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.significantfiles.mrcounter.db.provider;
/*fromwww.java2s.com*/import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;
import com.significantfiles.android.sqlite.UnsupportedUri;
import com.significantfiles.android.sqlite.commands.CommandBasedContentProvider;
import com.significantfiles.android.sqlite.commands.DaoManager;
import com.significantfiles.mrcounter.Constants;
import com.significantfiles.mrcounter.db.CommandUriMatcher;
import com.significantfiles.mrcounter.db.CreditDao;
import com.significantfiles.mrcounter.db.CreditSQLiteOpenHelper;
publicclass CreditDaoBasedContentProvider extends CommandBasedContentProvider {
publicstatic String AUTHORITY = Constants.AUTHORITY;
privatestaticfinal UriMatcher matcher = initUriMatcher();
private CreditSQLiteOpenHelper databaseHelper;
/*
* Uri-Matcher-Codes :::
*/privatestaticfinalint MATCH_NEW_CREDIT = 0;
privatestatic UriMatcher initUriMatcher() {
final UriMatcher rval = new UriMatcher(UriMatcher.NO_MATCH);
rval.addURI(AUTHORITY, "credit/new", MATCH_NEW_CREDIT);
return rval;
}
private DaoManager daoManager;
public DaoManager getDaoManager() {
return this.daoManager;
}
public CreditSQLiteOpenHelper getDatabaseHelper() {
return databaseHelper;
}
protectedvoid onRegisterCommands(final CommandUriMatcher matcher) {
// final String path = matcher.getUriPath(InsertCreditCmd.class);
//
// final InsertCreditCmd cmd = new InsertCreditCmd();
//
// matcher.register( cmd );
}
@Override
publicboolean onCreate() {
final Context context = getContext();
this.databaseHelper = new CreditSQLiteOpenHelper(context);
this.daoManager = new DaoManager( this.databaseHelper );
return true;
}
@Override
public Cursor query(final Uri uri, final String[] projection,
final String selection, final String[] selectionArgs,
final String sortOrder) {
thrownew UnsupportedOperationException();
}
@Override
publicint delete(final Uri arg0, final String arg1, final String[] arg2) {
thrownew UnsupportedOperationException();
}
@Override
public String getType(final Uri uri) {
return"mrcounter/app";
}
@Override
public Uri insert(final Uri uri, final ContentValues values) {
finalint match = matcher.match(uri);
if( match != MATCH_NEW_CREDIT ) {
thrownew UnsupportedUri(uri);
}
final CreditDao build = this.daoManager.build(CreditDao.class);
long creditValue = 0;
// TODO: sollte die neue URI zur?ck geben?
// long creditId =
build.newCredit(creditValue, 0.0, 0);
return createNewCreditResultUri(1);
}
private Uri createNewCreditResultUri(finallong creditId) {
final String uriStr = "content://" + AUTHORITY + "/credit/" + creditId;
return Uri.parse( uriStr );
}
@Override
publicint update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
thrownew UnsupportedOperationException();
}
}