Android Open Source - android-002 Place Badge Content Provider






From Project

Back to project page android-002.

License

The source code is released under:

Apache License

If you think the Android project android-002 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 course.labs.contentproviderlab.provider;
/*from   w  w w  . jav  a2 s.  c  o m*/
import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;

public class PlaceBadgeContentProvider extends ContentProvider {

  private DatabaseHelper mDbHelper;
  private static final int DATABASE_VERSION = 1;
  private static final String DATABASE_NAME = "Badges";

  private static final String CREATE_LOCATION_TABLE = " CREATE TABLE "
      + PlaceBadgesContract.BADGES_TABLE_NAME + " ("
      + PlaceBadgesContract._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
      + PlaceBadgesContract.FLAG_BITMAP_PATH + " TEXT NOT NULL, "
      + PlaceBadgesContract.COUNTRY_NAME + " TEXT NOT NULL, "
      + PlaceBadgesContract.PLACE_NAME + " TEXT NOT NULL, "
      + PlaceBadgesContract.LAT + " REAL NOT NULL, "
      + PlaceBadgesContract.LON + " REAL NOT NULL);";

  private static class DatabaseHelper extends SQLiteOpenHelper {

    public DatabaseHelper(Context context) {
      super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
      db.execSQL(CREATE_LOCATION_TABLE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      db.execSQL("DROP TABLE IF EXISTS "
          + PlaceBadgesContract.BADGES_TABLE_NAME);
      onCreate(db);
    }

  }

  @Override
  public boolean onCreate() {
    mDbHelper = new DatabaseHelper(getContext());
    return (mDbHelper != null);
  }

  @Override
  public int delete(Uri arg0, String arg1, String[] arg2) {
    int rowsDeleted = mDbHelper.getWritableDatabase().delete(
        PlaceBadgesContract.BADGES_TABLE_NAME, null, null);
    getContext().getContentResolver().notifyChange(
        PlaceBadgesContract.CONTENT_URI, null);
    return rowsDeleted;

  }

  @Override
  public Uri insert(Uri uri, ContentValues values) {
    long rowID = mDbHelper.getWritableDatabase().insert(
        PlaceBadgesContract.BADGES_TABLE_NAME, "", values);
    if (rowID > 0) {
      Uri fullUri = ContentUris.withAppendedId(
          PlaceBadgesContract.CONTENT_URI, rowID);
      getContext().getContentResolver().notifyChange(fullUri, null);
      return fullUri;
    }
    throw new SQLException("Failed to add record into" + uri);
  }

  @Override
  public Cursor query(Uri uri, String[] projection, String selection,
      String[] selectionArgs, String sortOrder) {

    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(PlaceBadgesContract.BADGES_TABLE_NAME);

    Cursor cursor = qb.query(mDbHelper.getWritableDatabase(), projection, selection,
        selectionArgs, null, null, sortOrder);

    cursor.setNotificationUri(getContext().getContentResolver(), uri);

    return cursor;

  }

  @Override
  public String getType(Uri arg0) {
    // Not Implemented
    return null;
  }

  @Override
  public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) {
    // unimplemented
    return 0;
  }

}




Java Source Code List

com.michaelfitzmaurice.android.modernart.MainActivity.java
com.michaelfitzmaurice.dailyselfie.AlarmReceiver.java
com.michaelfitzmaurice.dailyselfie.AlarmTimeInterval.java
com.michaelfitzmaurice.dailyselfie.Alarms.java
com.michaelfitzmaurice.dailyselfie.SelfieDetailActivity.java
com.michaelfitzmaurice.dailyselfie.SelfieListActivity.java
com.michaelfitzmaurice.dailyselfie.SelfieListViewAdapter.java
com.michaelfitzmaurice.dailyselfie.SelfieRecord.java
com.michaelfitzmaurice.dailyselfie.settings.ReminderIntervalDialogPreference.java
com.michaelfitzmaurice.dailyselfie.settings.SettingsActivity.java
com.michaelfitzmaurice.dailyselfie.settings.SettingsFragment.java
course.labs.contentproviderlab.MockLocationProvider.java
course.labs.contentproviderlab.PlaceDownloaderTask.java
course.labs.contentproviderlab.PlaceRecord.java
course.labs.contentproviderlab.PlaceViewActivity.java
course.labs.contentproviderlab.PlaceViewAdapter.java
course.labs.contentproviderlab.provider.PlaceBadgeContentProvider.java
course.labs.contentproviderlab.provider.PlaceBadgesContract.java
course.labs.contentproviderlab.provider.PlaceBadgesContract.java
course.labs.graphicslab.BubbleActivity.java
course.labs.locationlab.MockLocationProvider.java
course.labs.locationlab.PlaceDownloaderTask.java
course.labs.locationlab.PlaceRecord.java
course.labs.locationlab.PlaceViewActivity.java
course.labs.locationlab.PlaceViewAdapter.java
course.labs.notificationslab.DownloaderTask.java
course.labs.notificationslab.FeedFragment.java
course.labs.notificationslab.FriendsFragment.java
course.labs.notificationslab.MainActivity.java
course.labs.notificationslab.SelectionListener.java
course.labs.notificationslab.TestFrontEndActivity.java