Android Open Source - coursera-android-001 Place Badge Content Provider






From Project

Back to project page coursera-android-001.

License

The source code is released under:

MIT License

If you think the Android project coursera-android-001 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;
// www.j  a  va2 s  .co 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 SQLiteDatabase database;
  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 int delete(Uri arg0, String arg1, String[] arg2) {
    int rowsDeleted = database.delete(PlaceBadgesContract.BADGES_TABLE_NAME, null, null);
    getContext().getContentResolver().notifyChange(PlaceBadgesContract.CONTENT_URI, null);
    return rowsDeleted;

  }

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

  @Override
  public Uri insert(Uri uri, ContentValues values) {
    long rowID = database.insert(PlaceBadgesContract.BADGES_TABLE_NAME, "", values);

    if (rowID > 0) {
      Uri _uri = ContentUris.withAppendedId(
          PlaceBadgesContract.CONTENT_URI, rowID);
      getContext().getContentResolver().notifyChange(_uri, null);
      return _uri;
    }
    throw new SQLException("Failed to add record into" + uri);
  }

  @Override
  public boolean onCreate() {
    DatabaseHelper dbHelper = new DatabaseHelper(getContext());
    database = dbHelper.getWritableDatabase();
    return (database != null);
  }

  @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 c = qb.query(database, null, null, null, null, null, null);

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

    return c;
  
  }

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

}




Java Source Code List

course.labs.GraphicsLab.BubbleActivity.java
course.labs.activitylab.ActivityOne.java
course.labs.activitylab.ActivityTwo.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.dangerousapp.DangerousActivity.java
course.labs.fragmentslab.FeedFragmentData.java
course.labs.fragmentslab.FeedFragment.java
course.labs.fragmentslab.FriendsFragment.java
course.labs.fragmentslab.MainActivity.java
course.labs.intentslab.ActivityLoaderActivity.java
course.labs.intentslab.ExplicitlyLoadedActivity.java
course.labs.intentslab.mybrowser.MyBrowserActivity.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
course.labs.permissionslab.ActivityLoaderActivity.java
course.labs.permissionslab.BookmarksActivity.java
course.labs.permissionslab.GoToDangerousActivity.java
course.labs.todomanager.AddToDoActivity.java
course.labs.todomanager.ToDoItem.java
course.labs.todomanager.ToDoListAdapter.java
course.labs.todomanager.ToDoManagerActivity.java