Android Open Source - android-webview-example Credit Content Provider






From Project

Back to project page android-webview-example.

License

The source code is released under:

Apache License

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;
/*from w w  w.  jav  a 2 s .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
 */
public class CreditContentProvider extends ContentProvider {

  public static String AUTHORITY = Constants.AUTHORITY;

    private static final UriMatcher MATCHER = initUriMatcher();

    /*
     * Uri-Matcher-Codes :::
     */
  private static final int MATCH_NEW_CREDIT = 0;
  private static final int MATCH_DEL_BY_ID = 1;
  private static final int MATCH_SELECT_BY_ID = 2;
  private static final int MATCH_SELECT_ALL = 3;
  
  private static 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
  public boolean onCreate() {
    final Context context = getContext();
    this.database = new CreditSQLiteOpenHelper(context);
    this.daoManager = new DaoManager(database);
    
    return true;
  }

  @Override
  public int 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:
      throw new UnsupportedUri(uri);
    }
  }

  @Override
  public Uri insert(final Uri uri, ContentValues arg1) {
    
    final int match = MATCHER.match( uri );

    final CreditDao dao = this.daoManager.build( CreditDao.class );
    
    final long now = System.currentTimeMillis();
    dao.newCredit(1, 1.0, now);
    
    if( match != MATCH_NEW_CREDIT )
      throw new 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
  public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) {
    // TODO Auto-generated method stub
    return 0;
  }

}




Java Source Code List

com.significantfiles.android.db.CommandUriMatcherTestCase.java
com.significantfiles.android.db.CreditContentProviderTestCase.java
com.significantfiles.android.db.SQLiteCreateTableTestCase.java
com.significantfiles.android.db.SimpleProviderTestCase.java
com.significantfiles.android.db.TestCommandBasedContentProvider.java
com.significantfiles.android.provider.table.Authority.java
com.significantfiles.android.provider.table.ColumnMethodEnumeration.java
com.significantfiles.android.provider.table.OrderBy.java
com.significantfiles.android.provider.table.SQLiteField.java
com.significantfiles.android.provider.table.SQLiteTable.java
com.significantfiles.android.provider.table.SQLiteType.java
com.significantfiles.android.provider.table.UriPathExt.java
com.significantfiles.android.provider.table.constraint.IsPrimaryKey.java
com.significantfiles.android.provider.table.constraint.NotNull.java
com.significantfiles.android.provider.table.constraint.Unique.java
com.significantfiles.android.sqlite.DaoInvocationHandler.java
com.significantfiles.android.sqlite.GET.java
com.significantfiles.android.sqlite.InsertException.java
com.significantfiles.android.sqlite.UnsupportedUri.java
com.significantfiles.android.sqlite.commands.CommandBasedContentProvider.java
com.significantfiles.android.sqlite.commands.CreateTable.java
com.significantfiles.android.sqlite.commands.DaoManager.java
com.significantfiles.android.sqlite.commands.InsertCmd.java
com.significantfiles.android.sqlite.commands.InsertRow.java
com.significantfiles.android.sqlite.create.ColumnExtractor.java
com.significantfiles.android.sqlite.create.TableExtractor.java
com.significantfiles.android.sqlite.query.InsertTxChoice.java
com.significantfiles.android.sqlite.query.Insert.java
com.significantfiles.android.sqlite.query.QueryType.java
com.significantfiles.android.sqlite.query.Replace.java
com.significantfiles.android.sqlite.query.SQL.java
com.significantfiles.android.sqlite.types.BLOB.java
com.significantfiles.android.sqlite.types.ID.java
com.significantfiles.android.sqlite.types.INTEGER.java
com.significantfiles.android.sqlite.types.REAL.java
com.significantfiles.android.sqlite.types.TEXT.java
com.significantfiles.mrcounter.ActivityRequestCode.java
com.significantfiles.mrcounter.Constants.java
com.significantfiles.mrcounter.IndexActivity.java
com.significantfiles.mrcounter.StartActivity.java
com.significantfiles.mrcounter.WebChromeClient.java
com.significantfiles.mrcounter.WebViewClient.java
com.significantfiles.mrcounter.db.CommandUriMatcher.java
com.significantfiles.mrcounter.db.ContentProviderCmd.java
com.significantfiles.mrcounter.db.ContentResolverUtil.java
com.significantfiles.mrcounter.db.ContentValuesKeys.java
com.significantfiles.mrcounter.db.CreditByIdResult.java
com.significantfiles.mrcounter.db.CreditDao.java
com.significantfiles.mrcounter.db.CreditQuery.java
com.significantfiles.mrcounter.db.CreditSQLiteOpenHelper.java
com.significantfiles.mrcounter.db.Credit.java
com.significantfiles.mrcounter.db.Credits.java
com.significantfiles.mrcounter.db.DaoConfig.java
com.significantfiles.mrcounter.db.InsertCreditCmd.java
com.significantfiles.mrcounter.db.UnknownQueryTypeException.java
com.significantfiles.mrcounter.db.Uris.java
com.significantfiles.mrcounter.db.provider.CommandBasedCreditContentProvider.java
com.significantfiles.mrcounter.db.provider.CreditContentProvider.java
com.significantfiles.mrcounter.db.provider.CreditDaoBasedContentProvider.java
com.significantfiles.mrcounter.db.result.Converter.java
com.significantfiles.mrcounter.db.result.Credit.java
com.significantfiles.mrcounter.db.result.DefaultConverterStrategy.java
com.significantfiles.mrcounter.db.result.DefautInteger2IntConverter.java
com.significantfiles.mrcounter.db.result.QueryRef.java
com.significantfiles.mrcounter.js.CreateCreditControl.java
com.significantfiles.mrcounter.js.WebViewFacade.java