Android Open Source - TheCompressYourFiles Bookmarks Provider






From Project

Back to project page TheCompressYourFiles.

License

The source code is released under:

Apache License

If you think the Android project TheCompressYourFiles 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 th.watsize.filebrowser;
//from   w w  w.j a  va 2 s.  com
import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
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;
import android.provider.BaseColumns;
import android.text.TextUtils;

public class BookmarksProvider extends ContentProvider implements BaseColumns{
    public static final String TB_NAME = "bookmarks";
    public static final String NAME = "name";
    public static final String PATH = "path";
    public static final String CHECKED = "checked"; //Only because of multiple choice delete dialog
    public static final String PROVIDER_NAME = "th.watsize.filebrowser.bookmarks";
    public static final Uri CONTENT_URI = 
            Uri.parse("content://"+PROVIDER_NAME);
    public static final String BOOKMARK_MIMETYPE =
        "vnd.android.cursor.item/vnd.mirrorlabs.bookmark";
    public static final String BOOKMARKS_MIMETYPE =
        "vnd.android.cursor.dir/vnd.mirrorlabs.bookmark";
    

    private static final int BOOKMARKS = 1;
    private static final int BOOKMARK_ID = 2;
    private static final UriMatcher uriMatcher;
    static{
       uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
       uriMatcher.addURI(PROVIDER_NAME, null, BOOKMARKS);   
       uriMatcher.addURI(PROVIDER_NAME, "#", BOOKMARK_ID);  
    }

    private DatabaseHelper dbHelper;
    private SQLiteDatabase db;


    private static final String DATABASE_CREATE =
        String.format("CREATE TABLE %s (%s integer primary key autoincrement, "
            + "%s text not null, %s text not null, %s integer default 0);",
            TB_NAME, _ID, NAME, PATH, CHECKED);

    private static final String DATABASE_NAME = "com.mirrorlabs.filebrowser";
    private static final int DATABASE_VERSION = 2;

    private static class DatabaseHelper extends SQLiteOpenHelper {

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

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

        /*
         * !!!
         * When changing database version, you MUST change this method.
         * Currently, it would delete all users' bookmarks
         */
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            db.execSQL("DROP TABLE IF EXISTS "+TB_NAME);
            onCreate(db);
        }
    }
    

  @Override
  public int delete(Uri arg0, String arg1, String[] arg2) {
    int count = 0;
    switch (uriMatcher.match(arg0)) {
    case BOOKMARKS:
      count = db.delete(TB_NAME, arg1, arg2);
      break;
    case BOOKMARK_ID:
      String id = arg0.getPathSegments().get(0);
      count = db.delete(TB_NAME, _ID + " = " + id
          + (!TextUtils.isEmpty(arg1) ? " AND (" + arg1 + ')' : ""),
          arg2);
      break;
    default:
      throw new IllegalArgumentException("Unknown URI " + arg0);
    }
    getContext().getContentResolver().notifyChange(arg0, null);
    return count;
  }

  @Override
  public String getType(Uri uri) {
    switch (uriMatcher.match(uri)){
    case BOOKMARKS:
      return BOOKMARKS_MIMETYPE;
    case BOOKMARK_ID:                
      return BOOKMARK_MIMETYPE;
    default:
      throw new IllegalArgumentException("Unsupported URI: " + uri);        
    }   
  }

  @Override
  public Uri insert(Uri uri, ContentValues values){
    long rowID = db.insert(TB_NAME, "", values);
    if (rowID > 0){
      Uri _uri = ContentUris.withAppendedId(CONTENT_URI, rowID);
      getContext().getContentResolver().notifyChange(_uri, null);    
      return _uri;                
    }
    throw new SQLException("Failed to insert row into " + uri);
  }

  @Override
  public boolean onCreate() {
    dbHelper = new DatabaseHelper(getContext());
        db = dbHelper.getWritableDatabase();
        return (db == null)? false:true;
  }

  @Override
  public Cursor query(Uri uri, String[] projection, String selection,
      String[] selectionArgs, String sortOrder) {
    SQLiteQueryBuilder sqlBuilder = new SQLiteQueryBuilder();
    sqlBuilder.setTables(TB_NAME);
    if (uriMatcher.match(uri) == BOOKMARK_ID){
      sqlBuilder.appendWhere(_ID + " = " + uri.getPathSegments().get(0));  
    }
    
    if (sortOrder==null || sortOrder=="")
      sortOrder = _ID;
    
    Cursor c = sqlBuilder.query(db, 
                  projection, 
                  selection, 
                  selectionArgs, 
                  null, 
                  null, 
                  sortOrder);
    c.setNotificationUri(getContext().getContentResolver(), uri);
    return c;
  }

  @Override
  public int update(Uri uri, ContentValues values, String selection,
      String[] selectionArgs) {
    int count = 0;
    switch (uriMatcher.match(uri)){
    case BOOKMARKS:
      count = db.update(
            TB_NAME, 
            values,
            selection, 
            selectionArgs);
      break;
    case BOOKMARK_ID:   
      count = db.update(
          TB_NAME, 
          values,
          _ID + " = " + uri.getPathSegments().get(0)
            + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""),
          selectionArgs);
      break;
    default: throw new IllegalArgumentException("Unknown URI " + uri);    
    }
    getContext().getContentResolver().notifyChange(uri, null);
    return count;
  }

}




Java Source Code List

com.android.gestures.CreateGestureActivity.java
com.android.gestures.GestureBuilderActivity.java
com.android.gestures.GestureMonitorActivity.java
com.markupartist.android.widget.ActionBar.java
com.markupartist.android.widget.ScrollingTextView.java
com.mirrorlabs.ui.widgets.ClickableSlidingDrawer.java
com.mirrorlabs.ui.widgets.DropDownMenu.java
com.mirrorlabs.ui.widgets.IcsListPopupWindow.java
com.mirrorlabs.ui.widgets.JavaYoutubeDownloader.java
com.mirrorlabs.ui.widgets.Panel.java
com.mirrorlabs.ui.widgets.ScrollPager.java
com.mirrorlabs.ui.widgets.SlidingFrameLayout.java
org.zeroxlab.widget.AnimationLayout.java
org.zeroxlab.widget.MyHorizontalScrollView.java
th.watsize.customcheckboxwidget.DontPressWithParentCheckBox.java
th.watsize.customtoast.Toaster.java
th.watsize.filebrowser.BackupManager.java
th.watsize.filebrowser.BaseActivity.java
th.watsize.filebrowser.BitmapManager.java
th.watsize.filebrowser.BookmarksProvider.java
th.watsize.filebrowser.CMDProcessor.java
th.watsize.filebrowser.CompressManager.java
th.watsize.filebrowser.DesEncrypter.java
th.watsize.filebrowser.DrawableManager.java
th.watsize.filebrowser.DrawableThreadLoader.java
th.watsize.filebrowser.DuplicatesManager.java
th.watsize.filebrowser.ExtractManager.java
th.watsize.filebrowser.FileUtils.java
th.watsize.filebrowser.FilebrowserULTRAActivity.java
th.watsize.filebrowser.ImageThreadLoader.java
th.watsize.filebrowser.LinuxShell.java
th.watsize.filebrowser.MimeTypes.java
th.watsize.filebrowser.MyApplication.java
th.watsize.filebrowser.PDFViewer.java
th.watsize.filebrowser.PreferenceActivity.java
th.watsize.filebrowser.ProcessManager.java
th.watsize.filebrowser.RootUtils.java
th.watsize.filebrowser.SearchFilesDialog.java
th.watsize.filebrowser.SearchFilesWidget.java
th.watsize.filebrowser.UltraBaseAdapter.java
th.watsize.imageviewer.EclairMotionEvent.java
th.watsize.imageviewer.ExpandImage.java
th.watsize.imageviewer.TouchImageView.java
th.watsize.imageviewer.WrapMotionEvent.java
th.watsize.menupopup.MenuItem.java
th.watsize.menupopup.PopupMenu.java
th.watsize.musicplayer.DBHelper.java
th.watsize.musicplayer.PlayerActivity.java
th.watsize.quickaction3D.ActionItem.java
th.watsize.quickaction3D.PopupWindows.java
th.watsize.quickaction3D.QuickAction.java
th.watsize.quickaction.ActionItem.java
th.watsize.quickaction.PopupWindows.java
th.watsize.quickaction.QuickAction.java
th.watsize.widgets.ExampleAppWidgetProvider1.java
th.watsize.widgets.ExampleAppWidgetProvider.java
th.watsize.widgets.UpdateWidgetService1.java
th.watsize.widgets.UpdateWidgetService.java