summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--AndroidManifest.xml3
-rw-r--r--res/menu/bookmarks.xml2
-rw-r--r--res/values/strings.xml3
-rw-r--r--src/com/android/browser/AddNewBookmark.java12
-rw-r--r--src/com/android/browser/BookmarkGridPage.java272
-rw-r--r--src/com/android/browser/BrowserBookmarksAdapter.java190
-rw-r--r--src/com/android/browser/BrowserBookmarksPage.java97
-rw-r--r--src/com/android/browser/CombinedBookmarkHistoryActivity.java2
8 files changed, 188 insertions, 393 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 2c237de..cdac176 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -124,9 +124,6 @@
<activity android:name="BrowserBookmarksPage" android:label="@string/bookmarks"
android:launchMode="singleTop" android:configChanges="orientation|keyboardHidden">
</activity>
- <activity android:name="BookmarkGridPage" android:label="@string/bookmarks"
- android:launchMode="singleTop" android:configChanges="orientation|keyboardHidden"/>
-
<activity android:name="MostVisitedActivity" android:label=""
android:launchMode="singleTop" android:configChanges="orientation|keyboardHidden"/>
diff --git a/res/menu/bookmarks.xml b/res/menu/bookmarks.xml
index 50dcfa9..8a6e32e 100644
--- a/res/menu/bookmarks.xml
+++ b/res/menu/bookmarks.xml
@@ -18,4 +18,6 @@
<item android:id="@+id/new_context_menu_id"
android:icon="@android:drawable/ic_menu_add"
android:title="@string/bookmark_page" />
+ <item android:id="@+id/switch_mode_menu_id"
+ android:title="@string/switch_mode"/>
</menu>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 6ad436e..5f158a2 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -167,6 +167,9 @@
currently on, but is not visible because the bookmarks page is
showing. -->
<string name="bookmark_page">Bookmark last-viewed page</string>
+ <!-- Menu item in the page that displays all bookmarks. Switches between
+ a vertical list view and a grid view which shows thumbnails -->
+ <string name="switch_mode">Switch viewing mode</string>
<!-- Summary text under the New Bookmark item on the Bookmarks screen.
Tells the user that if they select this item, it will bring up a
dialog to bookmark the page that the browser is currently viewing,
diff --git a/src/com/android/browser/AddNewBookmark.java b/src/com/android/browser/AddNewBookmark.java
index a75d002..5308f6b 100644
--- a/src/com/android/browser/AddNewBookmark.java
+++ b/src/com/android/browser/AddNewBookmark.java
@@ -47,17 +47,7 @@ class AddNewBookmark extends LinearLayout {
mUrlText = (TextView) findViewById(R.id.url);
mImageView = (ImageView) findViewById(R.id.favicon);
}
-
- /**
- * Copy this BookmarkItem to item.
- * @param item BookmarkItem to receive the info from this BookmarkItem.
- */
- /* package */ void copyTo(AddNewBookmark item) {
- item.mTextView.setText(mTextView.getText());
- item.mUrlText.setText(mUrlText.getText());
- item.mImageView.setImageDrawable(mImageView.getDrawable());
- }
-
+
/**
* Set the new url for the bookmark item.
* @param url The new url for the bookmark item.
diff --git a/src/com/android/browser/BookmarkGridPage.java b/src/com/android/browser/BookmarkGridPage.java
index 2e05183..5517d9c 100644
--- a/src/com/android/browser/BookmarkGridPage.java
+++ b/src/com/android/browser/BookmarkGridPage.java
@@ -16,266 +16,32 @@
package com.android.browser;
-import android.app.Activity;
import android.content.Context;
-import android.content.Intent;
-import android.database.Cursor;
-import android.database.ContentObserver;
-import android.database.DataSetObserver;
-import android.graphics.BitmapFactory;
-import android.os.Bundle;
-import android.os.Handler;
-import android.provider.Browser;
-import android.provider.Browser.BookmarkColumns;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.AdapterView;
import android.widget.GridView;
-import android.widget.ImageView;
-import android.widget.ListAdapter;
-import android.widget.TextView;
import java.util.ArrayList;
-public class BookmarkGridPage extends Activity {
- private final static int SPACING = 10;
- private static final int BOOKMARKS_SAVE = 1;
- private BookmarkGrid mGridView;
- private BookmarkGridAdapter mAdapter;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- mGridView = new BookmarkGrid(this);
- mGridView.setNumColumns(3);
- mAdapter = new BookmarkGridAdapter(this);
- mGridView.setAdapter(mAdapter);
- mGridView.setFocusable(true);
- mGridView.setFocusableInTouchMode(true);
- mGridView.setSelector(android.R.drawable.gallery_thumb);
- mGridView.setVerticalSpacing(SPACING);
- mGridView.setHorizontalSpacing(SPACING);
- setContentView(mGridView);
- mGridView.requestFocus();
+public class BookmarkGridPage extends GridView {
+ private final static int SPACING = 10;
+ private BrowserBookmarksAdapter mAdapter;
+
+ public BookmarkGridPage(Context context, BrowserBookmarksAdapter adapter) {
+ super(context);
+ setNumColumns(3);
+ mAdapter = adapter;
+ setAdapter(mAdapter);
+ setFocusable(true);
+ setFocusableInTouchMode(true);
+ setSelector(android.R.drawable.gallery_thumb);
+ setVerticalSpacing(SPACING);
+ setHorizontalSpacing(SPACING);
}
@Override
- protected void onActivityResult(int requestCode, int resultCode,
- Intent data) {
- switch(requestCode) {
- case BOOKMARKS_SAVE:
- if (resultCode == RESULT_OK) {
- mAdapter.refreshData();
- }
- break;
- default:
- break;
- }
- }
-
- private class BookmarkGrid extends GridView {
- public BookmarkGrid(Context context) {
- super(context);
- }
- @Override
- protected void onSizeChanged(int w, int h, int oldw, int oldh) {
- int thumbHeight = (h - 2 * (SPACING + getListPaddingTop()
- + getListPaddingBottom())) / 3;
- mAdapter.heightChanged(thumbHeight);
- super.onSizeChanged(w, h, oldw, oldh);
- }
- }
-
- private class BookmarkGridAdapter implements ListAdapter {
- private ArrayList<DataSetObserver> mDataObservers;
- private Context mContext; // Context to use to inflate views
- private Cursor mCursor;
- private int mThumbHeight;
-
- public BookmarkGridAdapter(Context context) {
- mContext = context;
- mDataObservers = new ArrayList<DataSetObserver>();
- String whereClause = Browser.BookmarkColumns.BOOKMARK + " != 0";
- String orderBy = Browser.BookmarkColumns.VISITS + " DESC";
- mCursor = managedQuery(Browser.BOOKMARKS_URI,
- Browser.HISTORY_PROJECTION, whereClause, null, orderBy);
- mCursor.registerContentObserver(new ChangeObserver());
- mGridView.setOnItemClickListener(
- new AdapterView.OnItemClickListener() {
- public void onItemClick(AdapterView parent, View v,
- int position, long id) {
- if (0 == position) {
- // Launch the add bookmark activity
- Intent i = new Intent(BookmarkGridPage.this,
- AddBookmarkPage.class);
- i.putExtras(getIntent());
- startActivityForResult(i, BOOKMARKS_SAVE);
- return;
- }
- position--;
- mCursor.moveToPosition(position);
- String url = mCursor.getString(
- Browser.HISTORY_PROJECTION_URL_INDEX);
- Intent intent = (new Intent()).setAction(url);
- getParent().setResult(RESULT_OK, intent);
- finish();
- }});
- }
-
- void heightChanged(int newHeight) {
- mThumbHeight = newHeight;
- }
-
- private class ChangeObserver extends ContentObserver {
- public ChangeObserver() {
- super(new Handler());
- }
-
- @Override
- public boolean deliverSelfNotifications() {
- return true;
- }
-
- @Override
- public void onChange(boolean selfChange) {
- BookmarkGridAdapter.this.refreshData();
- }
- }
-
- void refreshData() {
- mCursor.requery();
- for (DataSetObserver o : mDataObservers) {
- o.onChanged();
- }
- }
-
- /* (non-Javadoc)
- * @see android.widget.ListAdapter#areAllItemsSelectable()
- */
- public boolean areAllItemsEnabled() {
- return true;
- }
-
- /* (non-Javadoc)
- * @see android.widget.ListAdapter#isSelectable(int)
- */
- public boolean isEnabled(int position) {
- if (position >= 0 && position < mCursor.getCount()) {
- return true;
- }
- return false;
- }
-
- /* (non-Javadoc)
- * @see android.widget.Adapter#getCount()
- */
- public int getCount() {
- return mCursor.getCount();
- }
-
- /* (non-Javadoc)
- * @see android.widget.Adapter#getItem(int)
- */
- public Object getItem(int position) {
- return null;
- }
-
- /* (non-Javadoc)
- * @see android.widget.Adapter#getItemId(int)
- */
- public long getItemId(int position) {
- return position;
- }
-
- /* (non-Javadoc)
- * @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
- */
- public View getView(int position, View convertView, ViewGroup parent) {
- View v = null;
- if (convertView != null) {
- v = convertView;
- } else {
- LayoutInflater factory = LayoutInflater.from(mContext);
- v = factory.inflate(R.layout.bookmark_thumbnail, null);
- }
- ImageView thumb = (ImageView) v.findViewById(R.id.thumb);
- // Favicon disabled for now.
- //ImageView fav = (ImageView) v.findViewById(R.id.fav);
- TextView tv = (TextView) v.findViewById(R.id.label);
-
- ViewGroup.LayoutParams lp = thumb.getLayoutParams();
- if (lp.height != mThumbHeight) {
- lp.height = mThumbHeight;
- thumb.requestLayout();
- }
-
- if (0 == position) {
- // This is to create a bookmark for the current page.
- tv.setText(R.string.add_new_bookmark);
- thumb.setImageResource(
- R.drawable.ic_tab_browser_bookmark_selected);
- return v;
- }
- position--;
- mCursor.moveToPosition(position);
- tv.setText(mCursor.getString(
- Browser.HISTORY_PROJECTION_TITLE_INDEX));
- byte[] data = mCursor.getBlob(
- Browser.HISTORY_PROJECTION_THUMBNAIL_INDEX);
- if (data == null) {
- // Backup is to just show white
- thumb.setImageResource(R.drawable.blank);
- } else {
- thumb.setImageBitmap(
- BitmapFactory.decodeByteArray(data, 0, data.length));
- }
-/*
- // Now show the favicon
- data = mCursor.getBlob(Browser.HISTORY_PROJECTION_FAVICON_INDEX);
- if (data == null) {
- fav.setVisibility(View.GONE);
- } else {
- fav.setVisibility(View.VISIBLE);
- fav.setImageBitmap(
- BitmapFactory.decodeByteArray(data, 0, data.length));
- }
-*/
- return v;
- }
-
- /* (non-Javadoc)
- * @see android.widget.Adapter#registerDataSetObserver(android.database.DataSetObserver)
- */
- public void registerDataSetObserver(DataSetObserver observer) {
- mDataObservers.add(observer);
- }
-
- /* (non-Javadoc)
- * @see android.widget.Adapter#hasStableIds()
- */
- public boolean hasStableIds() {
- return true;
- }
-
- /* (non-Javadoc)
- * @see android.widget.Adapter#unregisterDataSetObserver(android.database.DataSetObserver)
- */
- public void unregisterDataSetObserver(DataSetObserver observer) {
- mDataObservers.remove(observer);
- }
-
- public int getItemViewType(int position) {
- return 0;
- }
-
- public int getViewTypeCount() {
- return 1;
- }
-
- public boolean isEmpty() {
- return getCount() == 0;
- }
+ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+ int thumbHeight = (h - 2 * (SPACING + getListPaddingTop()
+ + getListPaddingBottom())) / 3;
+ mAdapter.heightChanged(thumbHeight);
+ super.onSizeChanged(w, h, oldw, oldh);
}
}
diff --git a/src/com/android/browser/BrowserBookmarksAdapter.java b/src/com/android/browser/BrowserBookmarksAdapter.java
index c403b44..c7210af 100644
--- a/src/com/android/browser/BrowserBookmarksAdapter.java
+++ b/src/com/android/browser/BrowserBookmarksAdapter.java
@@ -30,11 +30,14 @@ import android.os.Handler;
import android.provider.Browser;
import android.provider.Browser.BookmarkColumns;
import android.view.KeyEvent;
+import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebIconDatabase;
import android.webkit.WebIconDatabase.IconListener;
import android.widget.BaseAdapter;
+import android.widget.ImageView;
+import android.widget.TextView;
import java.io.ByteArrayOutputStream;
@@ -43,15 +46,14 @@ class BrowserBookmarksAdapter extends BaseAdapter {
private String mCurrentPage;
private Cursor mCursor;
private int mCount;
- private String mLastWhereClause;
- private String[] mLastSelectionArgs;
- private String mLastOrderBy;
private BrowserBookmarksPage mBookmarksPage;
private ContentResolver mContentResolver;
- private ChangeObserver mChangeObserver;
- private DataSetObserver mDataSetObserver;
private boolean mDataValid;
+ // The following variables are used for the grid mode
+ private boolean mGridMode;
+ private int mThumbHeight;
+
// When true, this adapter is used to pick a bookmark to create a shortcut
private boolean mCreateShortcut;
private int mExtraOffset;
@@ -91,11 +93,21 @@ class BrowserBookmarksAdapter extends BaseAdapter {
mCurrentPage = b.getResources().getString(R.string.current_page) +
curPage;
mContentResolver = b.getContentResolver();
- mLastOrderBy = Browser.BookmarkColumns.CREATED + " DESC";
- mChangeObserver = new ChangeObserver();
- mDataSetObserver = new MyDataSetObserver();
+ mGridMode = false;
+
// FIXME: Should have a default sort order that the user selects.
- search(null);
+ String whereClause = Browser.BookmarkColumns.BOOKMARK + " != 0";
+ String orderBy = Browser.BookmarkColumns.VISITS + " DESC";
+ mCursor = b.managedQuery(Browser.BOOKMARKS_URI,
+ Browser.HISTORY_PROJECTION, whereClause, null, orderBy);
+ mCursor.registerContentObserver(new ChangeObserver());
+ mCursor.registerDataSetObserver(new MyDataSetObserver());
+
+ mDataValid = true;
+ notifyDataSetChanged();
+
+ mCount = mCursor.getCount() + mExtraOffset;
+
// FIXME: This requires another query of the database after the
// initial search(null). Can we optimize this?
Browser.requestAllIcons(mContentResolver,
@@ -240,52 +252,9 @@ class BrowserBookmarksAdapter extends BaseAdapter {
* Refresh list to recognize a change in the database.
*/
public void refreshList() {
- // FIXME: consider using requery().
- // Need to do more work to get it to function though.
- searchInternal(mLastWhereClause, mLastSelectionArgs, mLastOrderBy);
- }
-
- /**
- * Search the database for bookmarks that match the input string.
- * @param like String to use to search the database. Strings with spaces
- * are treated as having multiple search terms using the
- * OR operator. Search both the title and url.
- */
- public void search(String like) {
- String whereClause = Browser.BookmarkColumns.BOOKMARK + " == 1";
- String[] selectionArgs = null;
- if (like != null) {
- String[] likes = like.split(" ");
- int count = 0;
- boolean firstTerm = true;
- StringBuilder andClause = new StringBuilder(256);
- for (int j = 0; j < likes.length; j++) {
- if (likes[j].length() > 0) {
- if (firstTerm) {
- firstTerm = false;
- } else {
- andClause.append(" OR ");
- }
- andClause.append(Browser.BookmarkColumns.TITLE
- + " LIKE ? OR " + Browser.BookmarkColumns.URL
- + " LIKE ? ");
- count += 2;
- }
- }
- if (count > 0) {
- selectionArgs = new String[count];
- count = 0;
- for (int j = 0; j < likes.length; j++) {
- if (likes[j].length() > 0) {
- like = "%" + likes[j] + "%";
- selectionArgs[count++] = like;
- selectionArgs[count++] = like;
- }
- }
- whereClause += " AND (" + andClause + ")";
- }
- }
- searchInternal(whereClause, selectionArgs, mLastOrderBy);
+ mCursor.requery();
+ mCount = mCursor.getCount() + mExtraOffset;
+ notifyDataSetChanged();
}
/**
@@ -335,46 +304,6 @@ class BrowserBookmarksAdapter extends BaseAdapter {
}
/**
- * This sorts alphabetically, with non-capitalized titles before
- * capitalized.
- */
- public void sortAlphabetical() {
- searchInternal(mLastWhereClause, mLastSelectionArgs,
- Browser.BookmarkColumns.TITLE + " COLLATE UNICODE ASC");
- }
-
- /**
- * Internal function used in search, sort, and refreshList.
- */
- private void searchInternal(String whereClause, String[] selectionArgs,
- String orderBy) {
- if (mCursor != null) {
- mCursor.unregisterContentObserver(mChangeObserver);
- mCursor.unregisterDataSetObserver(mDataSetObserver);
- mBookmarksPage.stopManagingCursor(mCursor);
- mCursor.deactivate();
- }
-
- mLastWhereClause = whereClause;
- mLastSelectionArgs = selectionArgs;
- mLastOrderBy = orderBy;
- mCursor = mContentResolver.query(
- Browser.BOOKMARKS_URI,
- Browser.HISTORY_PROJECTION,
- whereClause,
- selectionArgs,
- orderBy);
- mCursor.registerContentObserver(mChangeObserver);
- mCursor.registerDataSetObserver(mDataSetObserver);
- mBookmarksPage.startManagingCursor(mCursor);
-
- mDataValid = true;
- notifyDataSetChanged();
-
- mCount = mCursor.getCount() + mExtraOffset;
- }
-
- /**
* How many items should be displayed in the list.
* @return Count of items.
*/
@@ -412,6 +341,24 @@ class BrowserBookmarksAdapter extends BaseAdapter {
return position;
}
+ /* package */ void heightChanged(int newHeight) {
+ mThumbHeight = newHeight;
+ }
+
+ /* package */ void switchViewMode(boolean toGrid) {
+ mGridMode = toGrid;
+ }
+
+ /* package */ void populateBookmarkItem(BookmarkItem b, int position) {
+ mCursor.moveToPosition(position - mExtraOffset);
+ b.setUrl(mCursor.getString(Browser.HISTORY_PROJECTION_URL_INDEX));
+ b.setName(mCursor.getString(Browser.HISTORY_PROJECTION_TITLE_INDEX));
+ byte[] data = mCursor.getBlob(Browser.HISTORY_PROJECTION_FAVICON_INDEX);
+ Bitmap bitmap = (null == data) ? null :
+ BitmapFactory.decodeByteArray(data, 0, data.length);
+ b.setFavicon(bitmap);
+ }
+
/**
* Get a View that displays the data at the specified position
* in the list.
@@ -427,6 +374,57 @@ class BrowserBookmarksAdapter extends BaseAdapter {
throw new AssertionError(
"BrowserBookmarksAdapter tried to get a view out of range");
}
+ if (mGridMode) {
+ if (convertView == null || convertView instanceof AddNewBookmark
+ || convertView instanceof BookmarkItem) {
+ LayoutInflater factory = LayoutInflater.from(mBookmarksPage);
+ convertView
+ = factory.inflate(R.layout.bookmark_thumbnail, null);
+ }
+ ImageView thumb = (ImageView) convertView.findViewById(R.id.thumb);
+ // Favicon disabled for now.
+ //ImageView fav = (ImageView) convertView.findViewById(R.id.fav);
+ TextView tv = (TextView) convertView.findViewById(R.id.label);
+
+ ViewGroup.LayoutParams lp = thumb.getLayoutParams();
+ if (lp.height != mThumbHeight) {
+ lp.height = mThumbHeight;
+ thumb.requestLayout();
+ }
+
+ if (0 == position && !mCreateShortcut) {
+ // This is to create a bookmark for the current page.
+ tv.setText(R.string.add_new_bookmark);
+ thumb.setImageResource(
+ R.drawable.ic_tab_browser_bookmark_selected);
+ return convertView;
+ }
+ mCursor.moveToPosition(position - mExtraOffset);
+ tv.setText(mCursor.getString(
+ Browser.HISTORY_PROJECTION_TITLE_INDEX));
+ byte[] data = mCursor.getBlob(
+ Browser.HISTORY_PROJECTION_THUMBNAIL_INDEX);
+ if (data == null) {
+ // Backup is to just show white
+ thumb.setImageResource(R.drawable.blank);
+ } else {
+ thumb.setImageBitmap(
+ BitmapFactory.decodeByteArray(data, 0, data.length));
+ }
+/*
+ // Now show the favicon
+ data = mCursor.getBlob(Browser.HISTORY_PROJECTION_FAVICON_INDEX);
+ if (data == null) {
+ fav.setVisibility(View.GONE);
+ } else {
+ fav.setVisibility(View.VISIBLE);
+ fav.setImageBitmap(
+ BitmapFactory.decodeByteArray(data, 0, data.length));
+ }
+*/
+ return convertView;
+
+ }
if (position == 0 && !mCreateShortcut) {
AddNewBookmark b;
if (convertView instanceof AddNewBookmark) {
@@ -437,7 +435,7 @@ class BrowserBookmarksAdapter extends BaseAdapter {
b.setUrl(mCurrentPage);
return b;
}
- if (convertView == null || convertView instanceof AddNewBookmark) {
+ if (convertView == null || !(convertView instanceof BookmarkItem)) {
convertView = new BookmarkItem(mBookmarksPage);
}
bind((BookmarkItem)convertView, position);
diff --git a/src/com/android/browser/BrowserBookmarksPage.java b/src/com/android/browser/BrowserBookmarksPage.java
index 45fca87..513ce3e 100644
--- a/src/com/android/browser/BrowserBookmarksPage.java
+++ b/src/com/android/browser/BrowserBookmarksPage.java
@@ -36,6 +36,7 @@ import android.text.IClipboard;
import android.util.Log;
import android.view.ContextMenu;
import android.view.KeyEvent;
+import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -52,6 +53,9 @@ import android.widget.Toast;
public class BrowserBookmarksPage extends Activity implements
View.OnCreateContextMenuListener {
+ private boolean mGridMode;
+ private BookmarkGridPage mGridPage;
+ private View mVerticalList;
private BrowserBookmarksAdapter mBookmarksAdapter;
private static final int BOOKMARKS_SAVE = 1;
private boolean mMaxTabsOpen;
@@ -138,25 +142,29 @@ public class BrowserBookmarksPage extends Activity implements
((ViewGroup) mAddHeader.getParent()).
removeView(mAddHeader);
}
- ((AddNewBookmark) i.targetView).copyTo(mAddHeader);
+ mAddHeader.setUrl(getIntent().getStringExtra("url"));
menu.setHeaderView(mAddHeader);
return;
}
menu.setGroupVisible(R.id.ADD_MENU, false);
- BookmarkItem b = (BookmarkItem) i.targetView;
+ if (mMaxTabsOpen) {
+ menu.findItem(R.id.new_window_context_menu_id).setVisible(
+ false);
+ }
if (mContextHeader == null) {
mContextHeader = new BookmarkItem(BrowserBookmarksPage.this);
} else if (mContextHeader.getParent() != null) {
((ViewGroup) mContextHeader.getParent()).
removeView(mContextHeader);
}
- b.copyTo(mContextHeader);
- menu.setHeaderView(mContextHeader);
-
- if (mMaxTabsOpen) {
- menu.findItem(R.id.new_window_context_menu_id).setVisible(
- false);
+ if (mGridMode) {
+ mBookmarksAdapter.populateBookmarkItem(mContextHeader,
+ i.position);
+ } else {
+ BookmarkItem b = (BookmarkItem) i.targetView;
+ b.copyTo(mContextHeader);
}
+ menu.setHeaderView(mContextHeader);
}
/**
@@ -166,25 +174,52 @@ public class BrowserBookmarksPage extends Activity implements
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
- setContentView(R.layout.browser_bookmarks_page);
- setTitle(R.string.browser_bookmarks_page_bookmarks_text);
-
if (Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())) {
mCreateShortcut = true;
}
-
- mBookmarksAdapter = new BrowserBookmarksAdapter(this,
- getIntent().getStringExtra("url"), mCreateShortcut);
mMaxTabsOpen = getIntent().getBooleanExtra("maxTabsOpen", false);
- ListView listView = (ListView) findViewById(R.id.list);
- listView.setAdapter(mBookmarksAdapter);
- listView.setDrawSelectorOnTop(false);
- listView.setVerticalScrollBarEnabled(true);
- listView.setOnItemClickListener(mListener);
+ setTitle(R.string.browser_bookmarks_page_bookmarks_text);
+ mBookmarksAdapter = new BrowserBookmarksAdapter(this,
+ getIntent().getStringExtra("url"), mCreateShortcut);
+ mGridMode = true;
+ switchViewMode(mGridMode);
+ }
- if (!mCreateShortcut) {
- listView.setOnCreateContextMenuListener(this);
+ /**
+ * Set the ContentView to be either the grid of thumbnails or the vertical
+ * list. Pass true to set it to the grid.
+ */
+ private void switchViewMode(boolean gridMode) {
+ mGridMode = gridMode;
+ mBookmarksAdapter.switchViewMode(gridMode);
+ if (mGridMode) {
+ if (mGridPage == null) {
+ mGridPage = new BookmarkGridPage(this, mBookmarksAdapter);
+ mGridPage.setOnItemClickListener(mListener);
+ if (!mCreateShortcut) {
+ mGridPage.setOnCreateContextMenuListener(this);
+ }
+ }
+ setContentView(mGridPage);
+ } else {
+ if (null == mVerticalList) {
+ LayoutInflater factory = LayoutInflater.from(this);
+ mVerticalList = factory.inflate(R.layout.browser_bookmarks_page,
+ null);
+
+ ListView listView
+ = (ListView) mVerticalList.findViewById(R.id.list);
+ listView.setAdapter(mBookmarksAdapter);
+ listView.setDrawSelectorOnTop(false);
+ listView.setVerticalScrollBarEnabled(true);
+ listView.setOnItemClickListener(mListener);
+
+ if (!mCreateShortcut) {
+ listView.setOnCreateContextMenuListener(this);
+ }
+ }
+ setContentView(mVerticalList);
}
}
@@ -203,7 +238,7 @@ public class BrowserBookmarksPage extends Activity implements
// It is possible that the view has been canceled when we get to
// this point as back has a higher priority
if (mCanceled) {
- android.util.Log.e("browser", "item clicked when dismising");
+ android.util.Log.e(LOGTAG, "item clicked when dismissing");
return;
}
if (!mCreateShortcut) {
@@ -301,12 +336,16 @@ public class BrowserBookmarksPage extends Activity implements
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
- case R.id.new_context_menu_id:
- saveCurrentPage();
- break;
-
- default:
- return super.onOptionsItemSelected(item);
+ case R.id.new_context_menu_id:
+ saveCurrentPage();
+ break;
+
+ case R.id.switch_mode_menu_id:
+ switchViewMode(!mGridMode);
+ break;
+
+ default:
+ return super.onOptionsItemSelected(item);
}
return true;
}
@@ -377,7 +416,7 @@ public class BrowserBookmarksPage extends Activity implements
/**
* Refresh the shown list after the database has changed.
*/
- public void refreshList() {
+ private void refreshList() {
mBookmarksAdapter.refreshList();
}
diff --git a/src/com/android/browser/CombinedBookmarkHistoryActivity.java b/src/com/android/browser/CombinedBookmarkHistoryActivity.java
index 6926c8f..963f179 100644
--- a/src/com/android/browser/CombinedBookmarkHistoryActivity.java
+++ b/src/com/android/browser/CombinedBookmarkHistoryActivity.java
@@ -84,7 +84,7 @@ public class CombinedBookmarkHistoryActivity extends TabActivity
Resources resources = getResources();
getIconListenerSet(getContentResolver());
- Intent bookmarksIntent = new Intent(this, BookmarkGridPage.class);
+ Intent bookmarksIntent = new Intent(this, BrowserBookmarksPage.class);
bookmarksIntent.putExtras(extras);
tabHost.addTab(tabHost.newTabSpec(BOOKMARKS_TAB)
.setIndicator(resources.getString(R.string.tab_bookmarks),