Android Open Source - UltraExplorer Bookmarks Provider






From Project

Back to project page UltraExplorer.

License

The source code is released under:

GNU General Public License

If you think the Android project UltraExplorer 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.mirrorlabs.filebrowser;
// w ww  . java  2s.  c  o  m
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 = "com.mirrorlabs.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.customcheckboxwidget.DontPressWithParentCheckBox.java
com.mirrorlabs.customtoast.Toaster.java
com.mirrorlabs.filebrowser.BackupManager.java
com.mirrorlabs.filebrowser.BaseActivity.java
com.mirrorlabs.filebrowser.BitmapManager.java
com.mirrorlabs.filebrowser.BookmarksProvider.java
com.mirrorlabs.filebrowser.CMDProcessor.java
com.mirrorlabs.filebrowser.CompressManager.java
com.mirrorlabs.filebrowser.DesEncrypter.java
com.mirrorlabs.filebrowser.DrawableManager.java
com.mirrorlabs.filebrowser.DrawableThreadLoader.java
com.mirrorlabs.filebrowser.DuplicatesManager.java
com.mirrorlabs.filebrowser.ExtractManager.java
com.mirrorlabs.filebrowser.FileUtils.java
com.mirrorlabs.filebrowser.FilebrowserULTRAActivity.java
com.mirrorlabs.filebrowser.ImageThreadLoader.java
com.mirrorlabs.filebrowser.LinuxShell.java
com.mirrorlabs.filebrowser.MimeTypes.java
com.mirrorlabs.filebrowser.MyApplication.java
com.mirrorlabs.filebrowser.PDFViewer.java
com.mirrorlabs.filebrowser.PreferenceActivity.java
com.mirrorlabs.filebrowser.ProcessManager.java
com.mirrorlabs.filebrowser.RootUtils.java
com.mirrorlabs.filebrowser.SearchFilesDialog.java
com.mirrorlabs.filebrowser.SearchFilesWidget.java
com.mirrorlabs.filebrowser.UltraBaseAdapter.java
com.mirrorlabs.imageviewer.EclairMotionEvent.java
com.mirrorlabs.imageviewer.ExpandImage.java
com.mirrorlabs.imageviewer.TouchImageView.java
com.mirrorlabs.imageviewer.WrapMotionEvent.java
com.mirrorlabs.menupopup.MenuItem.java
com.mirrorlabs.menupopup.PopupMenu.java
com.mirrorlabs.musicplayer.DBHelper.java
com.mirrorlabs.musicplayer.PlayerActivity.java
com.mirrorlabs.quickaction3D.ActionItem.java
com.mirrorlabs.quickaction3D.PopupWindows.java
com.mirrorlabs.quickaction3D.QuickAction.java
com.mirrorlabs.quickaction.ActionItem.java
com.mirrorlabs.quickaction.PopupWindows.java
com.mirrorlabs.quickaction.QuickAction.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
com.mirrorlabs.widgets.ExampleAppWidgetProvider1.java
com.mirrorlabs.widgets.ExampleAppWidgetProvider.java
com.mirrorlabs.widgets.UpdateWidgetService1.java
com.mirrorlabs.widgets.UpdateWidgetService.java
org.zeroxlab.widget.AnimationLayout.java
org.zeroxlab.widget.MyHorizontalScrollView.java