<provider
android:name=".providers.RecentSearchesContentProvider"
- android:authorities="com.cyanogenmod.explorer.providers.RecentSearchesContentProvider"
+ android:authorities="com.cyanogenmod.explorer.providers.recentsearches"
+ android:exported="false" />
+
+ <provider
+ android:name=".providers.BookmarksContentProvider"
+ android:authorities="com.cyanogenmod.explorer.providers.bookmarks"
android:exported="false" />
<activity
android:id="@+id/mnu_actions_move_selection"
android:showAsAction="always"
android:title="@string/actions_menu_move_selection"/>
+ <item
+ android:id="@+id/mnu_actions_add_to_bookmarks_current_folder"
+ android:showAsAction="always"
+ android:title="@string/actions_menu_add_to_bookmarks_current_folder"/>
</group>
<!-- FileSystemObject Actions -->
android:id="@+id/mnu_actions_open_with"
android:showAsAction="always"
android:title="@string/actions_menu_open_with"/>
+ <item
+ android:id="@+id/mnu_actions_add_to_bookmarks"
+ android:showAsAction="always"
+ android:title="@string/actions_menu_add_to_bookmarks"/>
</group>
</menu>
\ No newline at end of file
Changing to a non-privileged console.</string>
<!-- The operation to change to other kind of console failed -->
<string name="msgs_console_change_failed">Change to new type of console failed.</string>
-
<!-- The selected setting was not applied nor stored -->
<string name="msgs_settings_save_failure">The setting can\'t be stored or applied.</string>
<!-- The initial directory has an invalid directory -->
<string name="advise_insufficient_permissions">The operation requires elevated privileged.\n\n
Do you want to change to a privileged console?</string>
+ <!-- There is no registered application that can handle the mime/type -->
+ <string name="msgs_not_registered_app">There is not registered app that can handle
+ the file type selected.</string>
+
<!-- The parent directory of the current directory in navigation view -->
<string name="parent_dir">Parent Directory</string>
<string name="bookmarks_button_config_cd">Set the initial directory</string>
<!-- Bookmark name * Button * Remove bookmark content description -->
<string name="bookmarks_button_remove_bookmark_cd">Remove the bookmarks</string>
+ <!-- Bookmarks * Actions * Bookmark successfully added -->
+ <string name="bookmarks_msgs_add_success">The bookmark was added successfully.</string>
<!-- Initial directory dialog title -->
<string name="initial_directory_dialog_title">Initial directory</string>
<string name="actions_menu_copy_selection">Copy selection</string>
<!-- Actions Dialog * Menu * Move selection -->
<string name="actions_menu_move_selection">Move selection</string>
+ <!-- Actions Dialog * Menu * Add to bookmarks the current folder -->
+ <string name="actions_menu_add_to_bookmarks_current_folder">Add to bookmarks</string>
<!-- Actions Dialog * Menu * Open -->
<string name="actions_menu_open">Open</string>
<!-- Actions Dialog * Menu * Open with -->
<string name="actions_menu_rename">Rename</string>
<!-- Actions Dialog * Menu * Properties -->
<string name="actions_menu_properties">Properties</string>
+ <!-- Actions Dialog * Menu * Add to bookmarks -->
+ <string name="actions_menu_add_to_bookmarks">Add to bookmarks</string>
<!-- Actions * Ask user prior to remove files or folders -->
<string name="actions_ask_remove_folder">Are you sure you want to delete this folder
android:imeOptions="actionSearch"
android:includeInGlobalSearch="false"
android:label="@string/search"
- android:searchSuggestAuthority="com.cyanogenmod.explorer.providers.RecentSearchesContentProvider"
+ android:searchSuggestAuthority="com.cyanogenmod.explorer.providers.recentsearches"
android:searchSuggestSelection=" ?"
android:searchSuggestThreshold="3"
android:voiceMaxResults="5"
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.XmlResourceParser;
+import android.database.Cursor;
import android.os.Bundle;
import android.os.Environment;
import android.os.storage.StorageManager;
import com.cyanogenmod.explorer.adapters.BookmarksAdapter;
import com.cyanogenmod.explorer.model.Bookmark;
import com.cyanogenmod.explorer.model.Bookmark.BOOKMARK_TYPE;
-import com.cyanogenmod.explorer.preferences.BookmarksDatabase;
+import com.cyanogenmod.explorer.preferences.Bookmarks;
import com.cyanogenmod.explorer.preferences.ExplorerSettings;
import com.cyanogenmod.explorer.preferences.Preferences;
import com.cyanogenmod.explorer.ui.dialogs.InitialDirectoryDialog;
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Bookmark bookmark = ((BookmarksAdapter)parent.getAdapter()).getItem(position);
- back(false, bookmark.getDirectory());
+ back(false, bookmark.mDirectory);
}
/**
Bookmark bookmark = adapter.getItem(position);
//Configure home
- if (bookmark.getType().compareTo(BOOKMARK_TYPE.HOME) == 0) {
+ if (bookmark.mType.compareTo(BOOKMARK_TYPE.HOME) == 0) {
//Show a dialog for configure initial directory
- List<Bookmark> bookmarks = BookmarksDatabase.getInstance().getAllBookmarks();
- InitialDirectoryDialog dialog = new InitialDirectoryDialog(this, bookmarks);
+ InitialDirectoryDialog dialog = new InitialDirectoryDialog(this);
dialog.setOnValueChangedListener(new InitialDirectoryDialog.OnValueChangedListener() {
@Override
@SuppressWarnings("synthetic-access")
}
//Remove bookmark
- if (bookmark.getType().compareTo(BOOKMARK_TYPE.USER_DEFINED) == 0) {
- boolean result = BookmarksDatabase.getInstance().removeBookmark(bookmark);
+ if (bookmark.mType.compareTo(BOOKMARK_TYPE.USER_DEFINED) == 0) {
+ boolean result = Bookmarks.removeBookmark(this, bookmark);
if (!result) {
//Show warning
DialogHelper.showToast(this, R.string.msgs_operation_failure, Toast.LENGTH_SHORT);
*
* @return List<Bookmark> The bookmarks loaded
*/
- @SuppressWarnings("static-method")
private List<Bookmark> loadUserBookmarks() {
- return BookmarksDatabase.getInstance().getAllBookmarks();
+ List<Bookmark> bookmarks = new ArrayList<Bookmark>();
+ Cursor cursor = Bookmarks.getAllBookmarks(this.getContentResolver());
+ if (cursor != null && cursor.moveToFirst()) {
+ do {
+ bookmarks.add(new Bookmark(cursor));
+ } while (cursor.moveToNext());
+ cursor.close();
+ }
+ return bookmarks;
}
}
this.mData[i] = new BookmarksAdapter.DataHolder();
this.mData[i].mDwIcon =
this.mIconHolder.getDrawable(getContext(), BookmarksHelper.getIcon(bookmark));
- this.mData[i].mName = bookmark.getName();
- this.mData[i].mDirectory = bookmark.getDirectory();
+ this.mData[i].mName = bookmark.mName;
+ this.mData[i].mDirectory = bookmark.mDirectory;
this.mData[i].mDwAction = null;
this.mData[i].mActionCd = null;
- if (bookmark.getType().compareTo(BOOKMARK_TYPE.HOME) == 0) {
+ if (bookmark.mType.compareTo(BOOKMARK_TYPE.HOME) == 0) {
this.mData[i].mDwAction =
this.mIconHolder.getDrawable(getContext(), R.drawable.ic_holo_light_config);
this.mData[i].mActionCd =
getContext().getString(R.string.bookmarks_button_config_cd);
- } else if (bookmark.getType().compareTo(BOOKMARK_TYPE.USER_DEFINED) == 0) {
+ } else if (bookmark.mType.compareTo(BOOKMARK_TYPE.USER_DEFINED) == 0) {
this.mData[i].mDwAction =
this.mIconHolder.getDrawable(getContext(), R.drawable.ic_holo_light_close);
this.mData[i].mActionCd =
package com.cyanogenmod.explorer.model;
+import android.database.Cursor;
+import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
+import android.provider.BaseColumns;
+import com.cyanogenmod.explorer.providers.BookmarksContentProvider;
+
+import java.io.File;
import java.io.Serializable;
/**
- * A class that represent a folder bookmark.
+ * A class that represent a bookmark.
*/
public class Bookmark implements Serializable, Comparable<Bookmark>, Parcelable {
USER_DEFINED
}
- private static final long serialVersionUID = -2326688160035972659L;
+ private static final long serialVersionUID = -7524744999056506867L;
+
+ /**
+ * Columns of the database
+ */
+ public static class Columns implements BaseColumns {
+ /**
+ * The content:// style URL for this table
+ */
+ public static final Uri CONTENT_URI =
+ Uri.parse(
+ String.format(
+ "%s%s/%s", //$NON-NLS-1$
+ "content://", //$NON-NLS-1$
+ BookmarksContentProvider.AUTHORITY,
+ "/bookmarks") //$NON-NLS-1$
+ );
+ /**
+ * The directory of the bookmark
+ * <P>Type: TEXT</P>
+ */
+ public static final String DIRECTORY = "directory"; //$NON-NLS-1$
- private final BOOKMARK_TYPE mType;
- private final String mName;
- private final String mDirectory;
+ /**
+ * The default sort order for this table
+ */
+ public static final String DEFAULT_SORT_ORDER =
+ DIRECTORY + " ASC"; //$NON-NLS-1$
+
+ /**
+ * @hide
+ */
+ public static final String[] BOOKMARK_QUERY_COLUMNS = {_ID, DIRECTORY};
+
+ /**
+ * These save calls to cursor.getColumnIndexOrThrow()
+ * THEY MUST BE KEPT IN SYNC WITH ABOVE QUERY COLUMNS
+ */
+ /**
+ * @hide
+ */
+ public static final int BOOKMARK_ID_INDEX = 0;
+ /**
+ * @hide
+ */
+ public static final int BOOKMARK_DIRECTORY_INDEX = 1;
+ }
+ /** @hide **/
+ public int mId;
+ /** @hide **/
+ public BOOKMARK_TYPE mType;
+ /** @hide **/
+ public String mName;
+ /** @hide **/
+ public String mDirectory;
/**
* Constructor of <code>Bookmark</code>.
*
+ * @param id The id of the bookmark
* @param type The type of the bookmark
* @param name The name of the bookmark
* @param directory The directory that the bookmark points to
*/
- public Bookmark(BOOKMARK_TYPE type, String name, String directory) {
+ private Bookmark(int id, BOOKMARK_TYPE type, String name, String directory) {
super();
+ this.mId = id;
this.mType = type;
this.mName = name;
this.mDirectory = directory;
}
/**
- * Method that returns the type of the bookmark.
- *
- * @return BOOKMARK_TYPE The type of the bookmark
- */
- public BOOKMARK_TYPE getType() {
- return this.mType;
- }
-
- /**
- * Method that returns the name of the bookmark.
+ * Constructor of <code>Bookmark</code>.
*
- * @return String The name of the bookmark
+ * @param type The type of the bookmark
+ * @param name The name of the bookmark
+ * @param directory The directory that the bookmark points to
*/
- public String getName() {
- return this.mName;
+ public Bookmark(BOOKMARK_TYPE type, String name, String directory) {
+ super();
+ this.mId = -1;
+ this.mType = type;
+ this.mName = name;
+ this.mDirectory = directory;
}
/**
- * Method that returns the directory that the bookmark points to.
+ * Constructor of <code>Bookmark</code>.
*
- * @return String The directory that the bookmark points to
+ * @param c The cursor with the information of the bookmark
*/
- public String getDirectory() {
- return this.mDirectory;
+ public Bookmark(Cursor c) {
+ super();
+ this.mId = c.getInt(Columns.BOOKMARK_ID_INDEX);
+ this.mType = BOOKMARK_TYPE.USER_DEFINED;
+ this.mDirectory = c.getString(Columns.BOOKMARK_DIRECTORY_INDEX);
+ this.mName = new File(this.mDirectory).getName();
}
/**
*/
@Override
public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(this.mId);
dest.writeString(this.mType.toString());
dest.writeString(this.mName);
dest.writeString(this.mDirectory);
*/
public static final Parcelable.Creator<Bookmark> CREATOR = new Parcelable.Creator<Bookmark>() {
@Override
+ @SuppressWarnings("synthetic-access")
public Bookmark createFromParcel(Parcel in) {
+ int id = in.readInt();
BOOKMARK_TYPE type = BOOKMARK_TYPE.valueOf(in.readString());
String name = in.readString();
String directory = in.readString();
- return new Bookmark(type, name, directory);
+ return new Bookmark(id, type, name, directory);
}
@Override
*/
@Override
public String toString() {
- return "Bookmark [type=" + this.mType + ", name=" + this.mName + //$NON-NLS-1$//$NON-NLS-2$
+ return "Bookmark [id=" + this.mId + ", type=" + //$NON-NLS-1$//$NON-NLS-2$
+ this.mType + ", name=" + this.mName + //$NON-NLS-1$
", directory=" + this.mDirectory + "]"; //$NON-NLS-1$//$NON-NLS-2$
}
--- /dev/null
+/*
+ * Copyright (C) 2012 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.cyanogenmod.explorer.preferences;
+
+import android.content.ContentResolver;
+import android.content.ContentUris;
+import android.content.ContentValues;
+import android.content.Context;
+import android.database.Cursor;
+import android.net.Uri;
+
+import com.cyanogenmod.explorer.model.Bookmark;
+
+/**
+ * A class for deal with user-defined bookmarks
+ */
+public class Bookmarks {
+
+ private final static int INVALID_BOOKMARKS_ID = -1;
+
+ /**
+ * Method that add a new bookmark
+ *
+ * @param context The current context
+ * @param bookmark The bookmark to add or update
+ * @return Bookmark The bookmark added
+ */
+ public static Bookmark addBookmark(Context context, Bookmark bookmark) {
+ // Check that has a valid information
+ if (bookmark.mDirectory == null) return null;
+
+ // Retrieve the content resolver
+ ContentResolver contentResolver = context.getContentResolver();
+
+ // Check that the bookmarks not exists
+ Bookmark b = getBookmark(contentResolver, bookmark.mDirectory);
+ if (b != null) return b;
+
+ // Create the content values
+ ContentValues values = createContentValues(bookmark);
+ Uri uri = context.getContentResolver().insert(Bookmark.Columns.CONTENT_URI, values);
+ bookmark.mId = (int) ContentUris.parseId(uri);
+ if (bookmark.mId == INVALID_BOOKMARKS_ID) {
+ return null;
+ }
+ return bookmark;
+ }
+
+ /**
+ * Method that removes a bookmark
+ *
+ * @param context The current context
+ * @param bookmark The bookmark to delete
+ * @return boolean If the bookmarks was remove
+ */
+ public static boolean removeBookmark(Context context, Bookmark bookmark) {
+ // Check that has a valid information
+ if (bookmark.mId == INVALID_BOOKMARKS_ID) return false;
+
+ // Retrieve the content resolver
+ ContentResolver contentResolver = context.getContentResolver();
+ Uri uri = ContentUris.withAppendedId(Bookmark.Columns.CONTENT_URI, bookmark.mId);
+ return contentResolver.delete(uri, "", null) == 1; //$NON-NLS-1$
+ }
+
+ /**
+ * Method that return the bookmark from his identifier
+ *
+ * @param contentResolver The content resolver
+ * @param bookmarkId The bookmark identifier
+ * @return Bookmark The bookmark. null if no bookmark exists.
+ */
+ public static Bookmark getBookmark(ContentResolver contentResolver, int bookmarkId) {
+ Cursor cursor = contentResolver.query(
+ ContentUris.withAppendedId(Bookmark.Columns.CONTENT_URI, bookmarkId),
+ Bookmark.Columns.BOOKMARK_QUERY_COLUMNS,
+ null, null, null);
+ Bookmark bookmark = null;
+ if (cursor != null) {
+ if (cursor.moveToFirst()) {
+ bookmark = new Bookmark(cursor);
+ }
+ cursor.close();
+ }
+ return bookmark;
+ }
+
+ /**
+ * Method that return all the bookmarks in the database
+ *
+ * @param contentResolver The content resolver
+ * @return Bookmark The bookmark. null if no bookmark exists.
+ */
+ public static Cursor getAllBookmarks(ContentResolver contentResolver) {
+ return contentResolver.query(
+ Bookmark.Columns.CONTENT_URI,
+ Bookmark.Columns.BOOKMARK_QUERY_COLUMNS,
+ null, null, null);
+ }
+
+ /**
+ * Method that return the bookmark from his directory
+ *
+ * @param contentResolver The content resolver
+ * @param directory The bookmark identifier
+ * @return Bookmark The bookmark. null if no bookmark exists.
+ */
+ public static Bookmark getBookmark(ContentResolver contentResolver, String directory) {
+ final String where = Bookmark.Columns.DIRECTORY + " = ?"; //$NON-NLS-1$
+ Cursor cursor = contentResolver.query(
+ Bookmark.Columns.CONTENT_URI,
+ Bookmark.Columns.BOOKMARK_QUERY_COLUMNS,
+ where, new String[]{directory}, null);
+ Bookmark bookmark = null;
+ if (cursor != null) {
+ if (cursor.moveToFirst()) {
+ bookmark = new Bookmark(cursor);
+ }
+ cursor.close();
+ }
+ return bookmark;
+ }
+
+ /**
+ * Method that create the {@link ContentValues} from the bookmark
+ *
+ * @param bookmark The bookmark
+ * @return ContentValues The content
+ */
+ private static ContentValues createContentValues(Bookmark bookmark) {
+ ContentValues values = new ContentValues(1);
+ values.put(Bookmark.Columns.DIRECTORY, bookmark.mDirectory);
+ return values;
+ }
+}
+++ /dev/null
-/*
- * Copyright (C) 2012 The CyanogenMod Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.cyanogenmod.explorer.preferences;
-
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.content.SharedPreferences.Editor;
-
-import com.cyanogenmod.explorer.ExplorerApplication;
-import com.cyanogenmod.explorer.model.Bookmark;
-import com.cyanogenmod.explorer.model.Bookmark.BOOKMARK_TYPE;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-/**
- * A class that holds and manage the database of bookmarks.
- */
-public class BookmarksDatabase {
-
- private static final String BOOKMARKS_DB_FILENAME = "bookmarks.db"; //$NON-NLS-1$
-
- private static BookmarksDatabase sSingleton;
- private static final Object SYNC = new Object();
-
- /**
- * Method that returns the instance of the database of bookmarks.
- *
- * @return BookmarksDatabase The the database of bookmarks instance
- */
- public static synchronized BookmarksDatabase getInstance() {
- if (sSingleton == null) {
- sSingleton = new BookmarksDatabase();
- }
- return sSingleton;
- }
-
- /**
- * Method that returns the shared preferences where save the bookmarks.
- *
- * @return SharedPreferences The shared preferences
- */
- @SuppressWarnings("static-method")
- private SharedPreferences getSharedPreferences() {
- return ExplorerApplication.getInstance().getSharedPreferences(
- BOOKMARKS_DB_FILENAME, Context.MODE_PRIVATE);
- }
-
- /**
- * Method that adds a new bookmark to the database.
- *
- * @param bookmark The bookmark to add
- */
- public void addBookmark(Bookmark bookmark) {
- synchronized (SYNC) {
- //Get the preferences editor
- SharedPreferences sp = getSharedPreferences();
- Editor editor = sp.edit();
- editor.putString(bookmark.getName(), bookmark.getDirectory());
- //Commit settings
- editor.commit();
- }
- }
-
- /**
- * Method that removes a new bookmark to the database.
- *
- * @param bookmark The bookmark to remove
- * @return boolean If the operation completes successfully
- */
- public boolean removeBookmark(Bookmark bookmark) {
- synchronized (SYNC) {
- //Get the preferences editor
- SharedPreferences sp = getSharedPreferences();
- if (!sp.contains(bookmark.getName())) {
- return false;
- }
- Editor editor = sp.edit();
- editor.remove(bookmark.getName());
- //Commit settings
- editor.commit();
- }
- return true;
- }
-
- /**
- * Method that returns all bookmarks stored in the database.
- *
- * @return List<Bookmark> The bookmarks stored in the database
- */
- public List<Bookmark> getAllBookmarks() {
- List<Bookmark> bookmarks = new ArrayList<Bookmark>();
- synchronized (SYNC) {
- //List all the properties in the shared preferences file
- SharedPreferences sp = getSharedPreferences();
- Map<String, ?> props = sp.getAll();
- Iterator<String> it = props.keySet().iterator();
- while (it.hasNext()) {
- String name = it.next();
- String directory = (String)props.get(name);
- bookmarks.add(new Bookmark(BOOKMARK_TYPE.USER_DEFINED, name, directory));
- }
- }
- return bookmarks;
- }
-
- /**
- * Method that returns a bookmark for the name passed.
- *
- * @param name The name of the bookmark
- * @return Bookmark The bookmarks or {@link "null"} if not found
- */
- public Bookmark getBookmark(String name) {
- synchronized (SYNC) {
- //Get the property in the shared preferences file
- SharedPreferences sp = getSharedPreferences();
- String directory = sp.getString(name, null);
- if (directory != null) {
- return new Bookmark(BOOKMARK_TYPE.USER_DEFINED, name, directory);
- }
- }
- //Not found
- return null;
- }
-}
--- /dev/null
+/*
+ * Copyright (C) 2012 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.cyanogenmod.explorer.preferences;
+
+import android.content.Context;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteOpenHelper;
+import android.util.Log;
+
+/**
+ * Helper class for opening the database from multiple providers. Also provides
+ * some common functionality.
+ */
+public class BookmarksDatabaseHelper extends SQLiteOpenHelper {
+
+ private static final String TAG = "BookmarksDatabaseHelper"; //$NON-NLS-1$
+
+ private static boolean DEBUG = false;
+
+ private static final String DATABASE_NAME = "bookmarks.db"; //$NON-NLS-1$
+ private static final int DATABASE_VERSION = 1;
+
+ /**
+ * Constructor of <code>BookmarksDatabaseHelper</code>
+ *
+ * @param context The current context
+ */
+ public BookmarksDatabaseHelper(Context context) {
+ super(context, DATABASE_NAME, null, DATABASE_VERSION);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onCreate(SQLiteDatabase db) {
+ db.execSQL("CREATE TABLE bookmarks (" + //$NON-NLS-1$
+ "_id INTEGER PRIMARY KEY," + //$NON-NLS-1$
+ "directory TEXT);"); //$NON-NLS-1$
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onUpgrade(SQLiteDatabase db, int oldVersion,
+ int currentVersion) {
+ if (DEBUG) {
+ Log.v(TAG, "Upgrading bookmarks database from version " + //$NON-NLS-1$
+ oldVersion + " to " + currentVersion + //$NON-NLS-1$
+ ", which will destroy all old data"); //$NON-NLS-1$
+ }
+ db.execSQL("DROP TABLE IF EXISTS bookmarks"); //$NON-NLS-1$
+ onCreate(db);
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (C) 2012 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.cyanogenmod.explorer.providers;
+
+import android.content.ContentProvider;
+import android.content.ContentUris;
+import android.content.ContentValues;
+import android.content.UriMatcher;
+import android.database.Cursor;
+import android.database.SQLException;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteQueryBuilder;
+import android.net.Uri;
+import android.text.TextUtils;
+import android.util.Log;
+
+import com.cyanogenmod.explorer.model.Bookmark;
+import com.cyanogenmod.explorer.preferences.BookmarksDatabaseHelper;
+
+/**
+ * A content provider for manage the user-defined bookmarks
+ */
+public class BookmarksContentProvider extends ContentProvider {
+
+ private static final boolean DEBUG = false;
+
+ private static final String TAG = "BookmarksContentProvider"; //$NON-NLS-1$
+
+ private BookmarksDatabaseHelper mOpenHelper;
+
+ private static final int BOOKMARKS = 1;
+ private static final int BOOKMARKS_ID = 2;
+
+ /**
+ * The authority string name.
+ */
+ public static final String AUTHORITY =
+ "com.cyanogenmod.explorer.providers.bookmarks"; //$NON-NLS-1$
+
+ private static final UriMatcher sURLMatcher = new UriMatcher(UriMatcher.NO_MATCH);
+
+ static {
+ sURLMatcher.addURI(
+ AUTHORITY,
+ "bookmarks", BOOKMARKS); //$NON-NLS-1$
+ sURLMatcher.addURI(
+ AUTHORITY,
+ "bookmarks/#", BOOKMARKS_ID); //$NON-NLS-1$
+ }
+
+ /**
+ * Constructor of <code>BookmarksContentProvider</code>.
+ */
+ public BookmarksContentProvider() {
+ super();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean onCreate() {
+ this.mOpenHelper = new BookmarksDatabaseHelper(getContext());
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Cursor query(Uri url, String[] projectionIn, String selection,
+ String[] selectionArgs, String sort) {
+ SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
+
+ // Generate the body of the query
+ int match = sURLMatcher.match(url);
+ switch (match) {
+ case BOOKMARKS:
+ qb.setTables("bookmarks"); //$NON-NLS-1$
+ break;
+ case BOOKMARKS_ID:
+ qb.setTables("bookmarks"); //$NON-NLS-1$
+ qb.appendWhere("_id="); //$NON-NLS-1$
+ qb.appendWhere(url.getPathSegments().get(1));
+ break;
+ default:
+ throw new IllegalArgumentException("Unknown URL " + url); //$NON-NLS-1$
+ }
+
+ // Open the database
+ SQLiteDatabase db = this.mOpenHelper.getReadableDatabase();
+ Cursor cursor = qb.query(db, projectionIn, selection, selectionArgs,
+ null, null, sort);
+ if (cursor == null) {
+ if (DEBUG) {
+ Log.v(TAG, "Bookmarks.query: failed"); //$NON-NLS-1$
+ }
+ } else {
+ cursor.setNotificationUri(getContext().getContentResolver(), url);
+ }
+
+ return cursor;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getType(Uri url) {
+ int match = sURLMatcher.match(url);
+ switch (match) {
+ case BOOKMARKS:
+ return "vnd.android.cursor.dir/bookmarks"; //$NON-NLS-1$
+ case BOOKMARKS_ID:
+ return "vnd.android.cursor.item/bookmarks"; //$NON-NLS-1$
+ default:
+ throw new IllegalArgumentException("Unknown URL"); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int update(Uri url, ContentValues values, String where, String[] whereArgs) {
+ int count;
+ long rowId = 0;
+ int match = sURLMatcher.match(url);
+ SQLiteDatabase db = this.mOpenHelper.getWritableDatabase();
+ switch (match) {
+ case BOOKMARKS_ID: {
+ String segment = url.getPathSegments().get(1);
+ rowId = Long.parseLong(segment);
+ count = db.update(
+ "boolmarks", values, "_id=" + rowId, null); //$NON-NLS-1$ //$NON-NLS-2$
+ break;
+ }
+ default: {
+ throw new UnsupportedOperationException(
+ "Cannot update URL: " + url); //$NON-NLS-1$
+ }
+ }
+ if (DEBUG) {
+ Log.v(TAG,
+ "*** notifyChange() rowId: " + //$NON-NLS-1$
+ rowId + " url " + url); //$NON-NLS-1$
+ }
+ getContext().getContentResolver().notifyChange(url, null);
+ return count;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Uri insert(Uri url, ContentValues initialValues) {
+ if (sURLMatcher.match(url) != BOOKMARKS) {
+ throw new IllegalArgumentException("Cannot insert into URL: " + url); //$NON-NLS-1$
+ }
+
+ // Add the bookmark
+ SQLiteDatabase db = this.mOpenHelper.getWritableDatabase();
+ long rowId = db.insert("bookmarks", null, initialValues); //$NON-NLS-1$
+ if (rowId < 0) {
+ throw new SQLException("Failed to insert row"); //$NON-NLS-1$
+ }
+ if (DEBUG) {
+ Log.v(TAG, "Added bookmark rowId = " + rowId); //$NON-NLS-1$
+ }
+ Uri newUrl = ContentUris.withAppendedId(Bookmark.Columns.CONTENT_URI, rowId);
+
+ // Notify changes
+ getContext().getContentResolver().notifyChange(newUrl, null);
+ return newUrl;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int delete(Uri url, String where, String[] whereArgs) {
+ SQLiteDatabase db = this.mOpenHelper.getWritableDatabase();
+ int count;
+ String whereQuery = where;
+ switch (sURLMatcher.match(url)) {
+ case BOOKMARKS:
+ count = db.delete("bookmarks", whereQuery, whereArgs); //$NON-NLS-1$
+ break;
+ case BOOKMARKS_ID:
+ String segment = url.getPathSegments().get(1);
+ if (TextUtils.isEmpty(whereQuery)) {
+ whereQuery = "_id=" + segment; //$NON-NLS-1$
+ } else {
+ whereQuery = "_id=" + segment + //$NON-NLS-1$
+ " AND (" + whereQuery + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ count = db.delete("bookmarks", whereQuery, whereArgs); //$NON-NLS-1$
+ break;
+ default:
+ throw new IllegalArgumentException("Cannot delete from URL: " + url); //$NON-NLS-1$
+ }
+
+ getContext().getContentResolver().notifyChange(url, null);
+ return count;
+ }
+}
\ No newline at end of file
* The authority string name.
*/
public static final String AUTHORITY =
- "com.cyanogenmod.explorer.providers.RecentSearchesContentProvider"; //$NON-NLS-1$
+ "com.cyanogenmod.explorer.providers.recentsearches"; //$NON-NLS-1$
/**
* The provider mode.
//- Create new object
case R.id.mnu_actions_new_directory:
case R.id.mnu_actions_new_file:
+ // Dialog is dismissed inside showInputNameDialog
if (this.mOnSelectionListener != null) {
showInputNameDialog(menuItem);
+ return;
}
- return;
+ break;
//- Delete
case R.id.mnu_actions_delete:
- this.mDialog.dismiss();
ActionsPolicy.removeFileSystemObject(
this.mContext, this.mFso, this.mOnRequestRefreshListener);
- return;
+ break;
//- Delete
case R.id.mnu_actions_refresh:
- this.mDialog.dismiss();
if (this.mOnRequestRefreshListener != null) {
this.mOnRequestRefreshListener.onRequestRefresh(null); //Refresh all
}
- return;
+ break;
//- Select/Deselect
case R.id.mnu_actions_select:
}
break;
+ //- Open
+ case R.id.mnu_actions_open:
+ ActionsPolicy.openFileSystemObject(this.mContext, this.mFso, false);
+ break;
+ //- Open with
+ case R.id.mnu_actions_open_with:
+ ActionsPolicy.openFileSystemObject(this.mContext, this.mFso, true);
+ break;
+
+ //- Add to bookmarks
+ case R.id.mnu_actions_add_to_bookmarks:
+ case R.id.mnu_actions_add_to_bookmarks_current_folder:
+ ActionsPolicy.addToBookmarks(this.mContext, this.mFso);
+ break;
+
//- Properties
case R.id.mnu_actions_properties:
case R.id.mnu_actions_properties_current_folder:
menu.removeItem(R.id.mnu_actions_open_with);
}
}
+
+ //- Add to bookmarks -> Only directories
+ if (this.mFso != null && !FileHelper.isDirectory(this.mFso)) {
+ menu.removeItem(R.id.mnu_actions_add_to_bookmarks);
+ menu.removeItem(R.id.mnu_actions_add_to_bookmarks_current_folder);
+ }
}
}
//- Info
tvName.setText(this.mFso.getName());
tvParent.setText(this.mFso.getParent());
- tvType.setText(MimeTypeHelper.getDescription(this.mContext, this.mFso));
+ tvType.setText(MimeTypeHelper.getMimeTypeDescription(this.mContext, this.mFso));
if (this.mFso instanceof Symlink) {
Symlink link = (Symlink)this.mFso;
tvLink.setText(link.getLinkRef().getFullPath());
import android.widget.Toast;
import com.cyanogenmod.explorer.R;
-import com.cyanogenmod.explorer.model.Bookmark;
import com.cyanogenmod.explorer.preferences.ExplorerSettings;
import com.cyanogenmod.explorer.preferences.Preferences;
import com.cyanogenmod.explorer.ui.widgets.DirectoryInlineAutocompleteTextView;
import com.cyanogenmod.explorer.util.DialogHelper;
import java.io.File;
-import java.util.List;
/**
* A class that wraps a dialog for showing list of consoles for choosing one.
* Constructor of <code>InitialDirectoryDialog</code>.
*
* @param context The current context
- * @param bookmarks The current bookmarks
*/
- public InitialDirectoryDialog(Context context, final List<Bookmark> bookmarks) {
+ public InitialDirectoryDialog(Context context) {
super();
//Save the context
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.net.Uri;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;
import com.cyanogenmod.explorer.console.RelaunchableException;
import com.cyanogenmod.explorer.listeners.OnRequestRefreshListener;
import com.cyanogenmod.explorer.listeners.OnSelectionListener;
+import com.cyanogenmod.explorer.model.Bookmark;
+import com.cyanogenmod.explorer.model.Bookmark.BOOKMARK_TYPE;
import com.cyanogenmod.explorer.model.FileSystemObject;
+import com.cyanogenmod.explorer.preferences.Bookmarks;
import com.cyanogenmod.explorer.ui.dialogs.FsoPropertiesDialog;
import com.cyanogenmod.explorer.util.CommandHelper;
import com.cyanogenmod.explorer.util.DialogHelper;
import com.cyanogenmod.explorer.util.ExceptionUtil;
import com.cyanogenmod.explorer.util.ExceptionUtil.OnRelaunchCommandResult;
import com.cyanogenmod.explorer.util.FileHelper;
+import com.cyanogenmod.explorer.util.MimeTypeHelper;
import java.io.File;
+import java.util.List;
/**
}
/**
+ * Method that opens a {@link FileSystemObject} with the default application registered
+ * by the system.
+ *
+ * @param ctx The current context
+ * @param fso The file system object
+ * @param choose If allow the user to select the app to open with
+ */
+ public static void openFileSystemObject(
+ final Context ctx, final FileSystemObject fso, final boolean choose) {
+ try {
+ // Create the intent to
+ Intent intent = new Intent();
+ intent.setAction(android.content.Intent.ACTION_VIEW);
+
+ // Obtain the mime/type and passed it to intent
+ String mime = MimeTypeHelper.getMimeType(ctx, fso);
+ File file = new File(fso.getFullPath());
+ if (mime != null) {
+ intent.setDataAndType(Uri.fromFile(file), mime);
+ } else {
+ intent.setData(Uri.fromFile(file));
+ }
+
+ //Retrieve the activities that can handle the file
+ final PackageManager packageManager = ctx.getPackageManager();
+ if (DEBUG) {
+ intent.addFlags(Intent.FLAG_DEBUG_LOG_RESOLUTION);
+ }
+ List<ResolveInfo> info =
+ packageManager.
+ queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
+
+ // Now we have the list of activities that can handle the file. The next steps are:
+ //
+ // 1.- If choose, then show open with dialog
+ // 1.- If info size == 0. No default application, then show open with dialog
+ // 2.- If !choose, seek inside our database the default activity for the extension
+ // and open the file with this application
+ // 3.- If no default activity saved, then use system default
+
+ if (choose || info.size() == 0) {
+ // Show open with dialog
+ return;
+ }
+
+
+
+ // 2.- info size == 0
+
+
+
+// if (info.size() == 0) {
+// DialogHelper.createWarningDialog(ctx, R.string.msgs_not_registered_app);
+// }
+//
+// // Open with?
+// if (choose) {
+// String title = ctx.getString(R.string.actions_menu_open_with);
+// ((Activity)ctx).startActivity(Intent.createChooser(intent,title));
+//
+// } else {
+// ((Activity)ctx).startActivity(intent);
+// }
+
+ } catch (Exception e) {
+ ExceptionUtil.translateException(ctx, e);
+ }
+ }
+
+ /**
+ * Method that adds the {@link FileSystemObject} to the bookmarks database.
+ *
+ * @param ctx The current context
+ * @param fso The file system object
+ */
+ public static void addToBookmarks(final Context ctx, final FileSystemObject fso) {
+ try {
+ // Create the bookmark
+ Bookmark bookmark =
+ new Bookmark(BOOKMARK_TYPE.USER_DEFINED, fso.getName(), fso.getFullPath());
+ bookmark = Bookmarks.addBookmark(ctx, bookmark);
+ if (bookmark == null) {
+ // The operation fails
+ Toast.makeText(
+ ctx,
+ R.string.msgs_operation_failure,
+ Toast.LENGTH_SHORT).show();
+ } else {
+ // Success
+ Toast.makeText(
+ ctx,
+ R.string.bookmarks_msgs_add_success,
+ Toast.LENGTH_SHORT).show();
+
+ }
+
+ } catch (Exception e) {
+ ExceptionUtil.translateException(ctx, e);
+ }
+ }
+
+ /**
* Method that create the a new file system object.
*
* @param ctx The current context
* @return The associated icon
*/
public static int getIcon(Bookmark bookmark) {
- if (bookmark.getType().compareTo(Bookmark.BOOKMARK_TYPE.HOME) == 0) {
+ if (bookmark.mType.compareTo(Bookmark.BOOKMARK_TYPE.HOME) == 0) {
return R.drawable.ic_holo_light_bookmarks_home;
}
- if (bookmark.getType().compareTo(Bookmark.BOOKMARK_TYPE.FILESYSTEM) == 0) {
+ if (bookmark.mType.compareTo(Bookmark.BOOKMARK_TYPE.FILESYSTEM) == 0) {
return R.drawable.ic_holo_light_bookmarks_filesystem;
}
- if (bookmark.getType().compareTo(Bookmark.BOOKMARK_TYPE.SDCARD) == 0) {
+ if (bookmark.mType.compareTo(Bookmark.BOOKMARK_TYPE.SDCARD) == 0) {
return R.drawable.ic_holo_light_bookmarks_sdcard;
}
- if (bookmark.getType().compareTo(Bookmark.BOOKMARK_TYPE.USB) == 0) {
+ if (bookmark.mType.compareTo(Bookmark.BOOKMARK_TYPE.USB) == 0) {
return R.drawable.ic_holo_light_bookmarks_usb;
}
//Bookmark add by the user
import android.app.Activity;
import android.app.AlertDialog;
+import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.os.AsyncTask;
CommandNotFoundException.class,
OperationTimeoutException.class,
ExecutionException.class,
- ParseException.class
+ ParseException.class,
+ ActivityNotFoundException.class
};
private static final int[] KNOWN_EXCEPTIONS_IDS = {
R.string.msgs_file_not_found,
R.string.msgs_command_not_found,
R.string.msgs_operation_timeout,
R.string.msgs_operation_failure,
- R.string.msgs_operation_failure
+ R.string.msgs_operation_failure,
+ R.string.msgs_not_registered_app
};
private static final boolean[] KNOWN_EXCEPTIONS_TOAST = {
false,
false,
true,
true,
- true
+ true,
+ false
};
/**
}
/**
+ * Method that returns the mime/type of the {@link FileSystemObject}.
+ *
+ * @param context The current context
+ * @param fso The file system object
+ * @return String The mime/type
+ */
+ public static final String getMimeType(Context context, FileSystemObject fso) {
+ //Ensure that mime types are loaded
+ if (sMimeTypes == null) {
+ loadMimeTypes(context);
+ }
+
+ //Get the extension and delivery
+ String ext = FileHelper.getExtension(fso);
+ if (ext != null) {
+ //Load from the database of mime types
+ MimeTypeInfo mimeTypeInfo = sMimeTypes.get(ext);
+ if (mimeTypeInfo != null) {
+ return mimeTypeInfo.mMimeType;
+ }
+ }
+ return null;
+ }
+
+ /**
* Method that returns the mime/type description of the {@link FileSystemObject}.
*
* @param context The current context
* @param fso The file system object
* @return String The mime/type description
*/
- public static final String getDescription(Context context, FileSystemObject fso) {
+ public static final String getMimeTypeDescription(Context context, FileSystemObject fso) {
Resources res = context.getResources();
//Ensure that mime types are loaded