Android Open Source - android-webview-example Command Based 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;
/*  www.ja  va  2 s.  co  m*/

import com.significantfiles.android.provider.table.Authority;
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.ContentProviderCmd;
import com.significantfiles.mrcounter.db.CreditQuery;
import com.significantfiles.mrcounter.db.CreditSQLiteOpenHelper;
import com.significantfiles.mrcounter.db.Credits;

import android.content.ContentProvider;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.text.TextUtils;

/**
 * http://developer.android.com/resources/samples/NotePad/src/com/example/android/notepad/NotePadProvider.html
 * http://developer.android.com/guide/topics/providers/content-providers.html
 * 
 * http://developer.android.com/guide/appendix/faq/commontasks.html
 * http://developer.android.com/guide/topics/data/data-storage.html
 * 
 * http://www.sqlite.org/lang_createtable.html
 * http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
 * http://www.casarini.org/blog/2009/android-contentprovider-on-sqlite-tables-without-the-_id-column/
 * http://android-developers.blogspot.com/2010/07/multithreading-for-performance.html
 * 
 * http://www.assembla.com/wiki/show/breakoutdocs/Assembla_REST_API
 * 
 * http://www.spiegel.de/netzwelt/games/0,1518,740309,00.html
 * 
 * @author asiebert
 *
 */
@Authority( uri=Constants.AUTHORITY )
public class CommandBasedCreditContentProvider extends CommandBasedContentProvider {

  public static Uri CONTENT_URI;
  
  private CreditSQLiteOpenHelper databaseHelper;

  private final CommandUriMatcher commandMatcher = initCommandMatcher();

  private DaoManager daoManager;
  
  public DaoManager getDaoManager() {
    return this.daoManager;
  }
  
  public CreditSQLiteOpenHelper getDatabaseHelper() {
    return databaseHelper;
  }

  private CommandUriMatcher initCommandMatcher() {
    System.out.print( "init Matcher");
    
    final Class<? extends CommandBasedCreditContentProvider> providerClass = getClass();
    final CommandUriMatcher matcher = new CommandUriMatcher( providerClass );
    
    onRegisterCommands(matcher);
    
    return matcher;
  }

  protected void onRegisterCommands(final CommandUriMatcher matcher) {
//    final String path = matcher.getUriPath(InsertCreditCmd.class);
//    
//    final InsertCreditCmd cmd = new InsertCreditCmd();
//    
//    matcher.register( cmd );
  }

  @Override
  public boolean 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) {

    final SQLiteQueryBuilder builder = CreditQuery.buildQuery(uri);

    final String orderBy = buildOrderBy(sortOrder);

        final SQLiteDatabase db = databaseHelper.getReadableDatabase();

        
        final Cursor cursor = db.rawQuery("", null);
        
//        final Cursor cursor = builder.query(db, projection, selection, selectionArgs, null, null, orderBy);

        final ContentResolver resolver = getContext().getContentResolver();
        cursor.setNotificationUri(resolver, uri);
        
        return cursor;
  }

  private String buildOrderBy(final String sortOrder) {
        if (TextUtils.isEmpty(sortOrder)) {
            return Credits.DEFAULT_SORT_ORDER;
        } else {
            return sortOrder;
        }
  }

  @Override
  public int delete(final Uri arg0, final String arg1, final String[] arg2) {
    throw new UnsupportedOperationException();
  }

  @Override
  public String getType(final Uri uri) {
//    final int match = URI_MATCHER.match(uri);

    // TODO Auto-generated method stub
    return "sqleasy/test";
  }

  @Override
  public Uri insert(final Uri uri, final ContentValues values) {
    final SQLiteDatabase db = this.databaseHelper.getWritableDatabase();    
    final ContentProviderCmd command = this.commandMatcher.match(uri);
    
    command.exec(db);
    command.notifyChanges();
    
    return  null;
  }

  @Override
  public int update(Uri uri, ContentValues values, String selection,
      String[] selectionArgs) {
    throw new UnsupportedOperationException();
  }

}




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