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.ContentProvider;
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.DaoManager;
import com.significantfiles.mrcounter.Constants;
import com.significantfiles.mrcounter.db.Credit;
import com.significantfiles.mrcounter.db.CreditDao;
import com.significantfiles.mrcounter.db.CreditSQLiteOpenHelper;
/**
* first version of CreditContentProvider, based on DAO and Uri-Matcher.
*
* @author Andreas Siebert, significantfiles.com
*/publicclass CreditContentProvider extends ContentProvider {
publicstatic String AUTHORITY = Constants.AUTHORITY;
privatestaticfinal UriMatcher MATCHER = initUriMatcher();
/*
* Uri-Matcher-Codes :::
*/privatestaticfinalint MATCH_NEW_CREDIT = 0;
privatestaticfinalint MATCH_DEL_BY_ID = 1;
privatestaticfinalint MATCH_SELECT_BY_ID = 2;
privatestaticfinalint MATCH_SELECT_ALL = 3;
privatestatic UriMatcher initUriMatcher() {
final UriMatcher rval = new UriMatcher(UriMatcher.NO_MATCH);
rval.addURI(AUTHORITY, "credit/new", MATCH_NEW_CREDIT);
rval.addURI(AUTHORITY, "credit/del/#", MATCH_DEL_BY_ID);
rval.addURI(AUTHORITY, "credit/#", MATCH_SELECT_BY_ID);
return rval;
}
private CreditSQLiteOpenHelper database;
private DaoManager daoManager;
@Override
publicboolean onCreate() {
final Context context = getContext();
this.database = new CreditSQLiteOpenHelper(context);
this.daoManager = new DaoManager(database);
return true;
}
@Override
publicint delete(Uri uri, String arg1, String[] arg2) {
// TODO Auto-generated method stub
return 0;
}
@Override
public String getType(final Uri uri) {
switch ( MATCHER.match(uri) ) {
case MATCH_SELECT_BY_ID:
return"vnd.android.cursor.item/credit";
case MATCH_SELECT_ALL:
return"vnd.android.cursor.dir/credits";
default:
thrownew UnsupportedUri(uri);
}
}
@Override
public Uri insert(final Uri uri, ContentValues arg1) {
finalint match = MATCHER.match( uri );
final CreditDao dao = this.daoManager.build( CreditDao.class );
finallong now = System.currentTimeMillis();
dao.newCredit(1, 1.0, now);
if( match != MATCH_NEW_CREDIT )
thrownew UnsupportedUri( uri );
final String newElementQuery = "content://" + AUTHORITY + "/credit/" + now;
return Uri.parse( newElementQuery );
}
@Override
public Cursor query(Uri arg0, String[] arg1, String arg2, String[] arg3,
String arg4) {
// TODO Auto-generated method stub
return null;
}
@Override
publicint update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) {
// TODO Auto-generated method stub
return 0;
}
}