Android Open Source - EBrowser Weave Content Provider






From Project

Back to project page EBrowser.

License

The source code is released under:

GNU General Public License

If you think the Android project EBrowser 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

/*
 * Zirco Browser for Android/*from   www.  jav  a  2  s.  c om*/
 * 
 * Copyright (C) 2010 - 2011 J. Devauchelle and contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 3 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

package org.zirco.providers;

import org.zirco.providers.WeaveColumns;

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;

public class WeaveContentProvider extends ContentProvider {
  
  public static final String AUTHORITY = "org.zirco.providers.weavecontentprovider";
  
  private static final int DATABASE_VERSION = 1;
  private static final String DATABASE_NAME = "weave.db";
  
  public static final String WEAVE_BOOKMARKS_TABLE = "WEAVE_BOOKMARKS";
  
  private static final String WEAVE_BOOKMARKS_TABLE_CREATE = "CREATE TABLE " + WEAVE_BOOKMARKS_TABLE + " (" + 
    WeaveColumns.WEAVE_BOOKMARKS_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
    WeaveColumns.WEAVE_BOOKMARKS_WEAVE_ID + " TEXT, " +
    WeaveColumns.WEAVE_BOOKMARKS_WEAVE_PARENT_ID + " TEXT, " +
    WeaveColumns.WEAVE_BOOKMARKS_TITLE + " TEXT, " +
    WeaveColumns.WEAVE_BOOKMARKS_URL + " TEXT, " +
    WeaveColumns.WEAVE_BOOKMARKS_FOLDER + " BOOLEAN);";
  
  private static final int WEAVE_BOOKMARKS = 1;
  private static final int WEAVE_BOOKMARKS_BY_ID = 2;
  
  private static final UriMatcher sUriMatcher;
  
  private SQLiteDatabase mDb;
  private DatabaseHelper mDbHelper;
  
  private Context mContext;
  
  static {
    sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    sUriMatcher.addURI(AUTHORITY, WEAVE_BOOKMARKS_TABLE, WEAVE_BOOKMARKS);
    sUriMatcher.addURI(AUTHORITY, WEAVE_BOOKMARKS_TABLE + "/#", WEAVE_BOOKMARKS_BY_ID);
  }
  
  @Override
  public boolean onCreate() {
    mContext = getContext();
    mDbHelper = new DatabaseHelper(mContext);
    mDb = mDbHelper.getWritableDatabase();
    return true;
  }

  @Override
  public int delete(Uri uri, String whereClause, String[] whereArgs) {
    int count = 0;
    
    switch (sUriMatcher.match(uri)) {
    case WEAVE_BOOKMARKS:
      count = mDb.delete(WEAVE_BOOKMARKS_TABLE, whereClause, whereArgs);
      break;
      
    default: throw new IllegalArgumentException("Unknown URI " + uri);
    }    
    
    if (count > 0) {
      mContext.getContentResolver().notifyChange(uri, null);
    }
    
    return count;
  }

  @Override
  public String getType(Uri uri) {
    switch (sUriMatcher.match(uri)) {
    case WEAVE_BOOKMARKS:
      return WeaveColumns.CONTENT_TYPE;
    case WEAVE_BOOKMARKS_BY_ID:
      return WeaveColumns.CONTENT_ITEM_TYPE;

    default: throw new IllegalArgumentException("Unknown URI " + uri);
    }
  }

  @Override
  public Uri insert(Uri uri, ContentValues values) {
    switch (sUriMatcher.match(uri)) {
    case WEAVE_BOOKMARKS:
      long rowId = mDb.insert(WEAVE_BOOKMARKS_TABLE, null, values);
      if (rowId > 0) {
        Uri rowUri = ContentUris.withAppendedId(WeaveColumns.CONTENT_URI, rowId);
        mContext.getContentResolver().notifyChange(rowUri, null);
        return rowUri;
      }
      
      throw new SQLException("Failed to insert row into " + uri);
      
    default: throw new IllegalArgumentException("Unknown URI " + uri);
    }                    
  }  

  @Override
  public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    
    switch (sUriMatcher.match(uri)) {
    case WEAVE_BOOKMARKS:
      qb.setTables(WEAVE_BOOKMARKS_TABLE);      
      break;
    case WEAVE_BOOKMARKS_BY_ID:
      qb.setTables(WEAVE_BOOKMARKS_TABLE);
      qb.appendWhere(WeaveColumns.WEAVE_BOOKMARKS_ID + " = " + uri.getPathSegments().get(1));
      break;    
    default: throw new IllegalArgumentException("Unknown URI " + uri);
    }
    
    Cursor c = qb.query(mDb, 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 (sUriMatcher.match(uri)) {
    case WEAVE_BOOKMARKS:
      count = mDb.update(WEAVE_BOOKMARKS_TABLE, values, selection, selectionArgs);
      break;
      
    default: throw new IllegalArgumentException("Unknown URI " + uri);
    }
            
    if (count > 0) {
      mContext.getContentResolver().notifyChange(uri, null);
    }
    
    return count;
  }
  
  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(WEAVE_BOOKMARKS_TABLE_CREATE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { }    
  }

}




Java Source Code List

org.emergent.android.weave.client.Base32.java
org.emergent.android.weave.client.Base64Encoder.java
org.emergent.android.weave.client.Base64.java
org.emergent.android.weave.client.BulkKeyCouplet.java
org.emergent.android.weave.client.Dbg.java
org.emergent.android.weave.client.HexEncoder.java
org.emergent.android.weave.client.Hex.java
org.emergent.android.weave.client.QueryParams.java
org.emergent.android.weave.client.QueryResult.java
org.emergent.android.weave.client.UserWeave.java
org.emergent.android.weave.client.WeaveAccountInfo.java
org.emergent.android.weave.client.WeaveBasicObject.java
org.emergent.android.weave.client.WeaveConstants.java
org.emergent.android.weave.client.WeaveCryptoUtil.java
org.emergent.android.weave.client.WeaveException.java
org.emergent.android.weave.client.WeaveFactory.java
org.emergent.android.weave.client.WeaveHeader.java
org.emergent.android.weave.client.WeaveResponse.java
org.emergent.android.weave.client.WeaveSSLSocketFactory.java
org.emergent.android.weave.client.WeaveTransport.java
org.emergent.android.weave.client.WeaveUtil.java
org.greendroid.QuickActionGrid.java
org.greendroid.QuickActionWidget.java
org.greendroid.QuickAction.java
org.zirco.controllers.Controller.java
org.zirco.events.EventConstants.java
org.zirco.events.EventController.java
org.zirco.events.IDownloadEventsListener.java
org.zirco.model.DbAdapter.java
org.zirco.model.UrlSuggestionItemComparator.java
org.zirco.model.adapters.BookmarksCursorAdapter.java
org.zirco.model.adapters.DownloadListAdapter.java
org.zirco.model.adapters.HistoryExpandableListAdapter.java
org.zirco.model.adapters.UrlSuggestionCursorAdapter.java
org.zirco.model.adapters.WeaveBookmarksCursorAdapter.java
org.zirco.model.items.BookmarkItem.java
org.zirco.model.items.DownloadItem.java
org.zirco.model.items.HistoryItem.java
org.zirco.model.items.UrlSuggestionItem.java
org.zirco.model.items.WeaveBookmarkItem.java
org.zirco.providers.BookmarksProviderWrapper.java
org.zirco.providers.WeaveColumns.java
org.zirco.providers.WeaveContentProvider.java
org.zirco.providers.ZircoBookmarksContentProvider.java
org.zirco.sync.ISyncListener.java
org.zirco.sync.WeaveSyncTask.java
org.zirco.ui.activities.AboutActivity.java
org.zirco.ui.activities.AdBlockerWhiteListActivity.java
org.zirco.ui.activities.BookmarksHistoryActivity.java
org.zirco.ui.activities.BookmarksListActivity.java
org.zirco.ui.activities.ChangelogActivity.java
org.zirco.ui.activities.DownloadsListActivity.java
org.zirco.ui.activities.EditBookmarkActivity.java
org.zirco.ui.activities.HistoryListActivity.java
org.zirco.ui.activities.IToolbarsContainer.java
org.zirco.ui.activities.MainActivity.java
org.zirco.ui.activities.MobileViewListActivity.java
org.zirco.ui.activities.WeaveBookmarksListActivity.java
org.zirco.ui.activities.preferences.BaseSpinnerCustomPreferenceActivity.java
org.zirco.ui.activities.preferences.HomepagePreferenceActivity.java
org.zirco.ui.activities.preferences.PreferencesActivity.java
org.zirco.ui.activities.preferences.SearchUrlPreferenceActivity.java
org.zirco.ui.activities.preferences.UserAgentPreferenceActivity.java
org.zirco.ui.activities.preferences.WeavePreferencesActivity.java
org.zirco.ui.activities.preferences.WeaveServerPreferenceActivity.java
org.zirco.ui.components.CustomWebViewClient.java
org.zirco.ui.components.CustomWebView.java
org.zirco.ui.runnables.DownloadRunnable.java
org.zirco.ui.runnables.FaviconUpdaterRunnable.java
org.zirco.ui.runnables.HideToolbarsRunnable.java
org.zirco.ui.runnables.HistoryUpdater.java
org.zirco.ui.runnables.XmlHistoryBookmarksExporter.java
org.zirco.ui.runnables.XmlHistoryBookmarksImporter.java
org.zirco.utils.AnimationManager.java
org.zirco.utils.ApplicationUtils.java
org.zirco.utils.Constants.java
org.zirco.utils.DateUtils.java
org.zirco.utils.IOUtils.java
org.zirco.utils.ProxyChangeReceiver.java
org.zirco.utils.ProxySettings.java
org.zirco.utils.UrlUtils.java