summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2010-11-23 13:09:17 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-11-23 13:09:17 -0800
commit72519f5a4c4e64ccbaf274f0965f31a899f4186a (patch)
tree90fedadc9df5fcda2109ec819133412b9af9831c
parent62bea339876f7d1608550f1d0c967e489d778d0c (diff)
parent8af906474c84854598da1886edacfd5f10cae70f (diff)
downloadpackages_apps_Browser-72519f5a4c4e64ccbaf274f0965f31a899f4186a.zip
packages_apps_Browser-72519f5a4c4e64ccbaf274f0965f31a899f4186a.tar.gz
packages_apps_Browser-72519f5a4c4e64ccbaf274f0965f31a899f4186a.tar.bz2
Merge "Adds a list view option for viewing bookmarks"
-rw-r--r--res/layout/bookmark_list.xml41
-rw-r--r--res/layout/bookmarks.xml7
-rw-r--r--res/layout/bookmarks_history.xml17
-rw-r--r--res/menu/bookmark_view.xml22
-rw-r--r--res/values/strings.xml8
-rw-r--r--src/com/android/browser/BrowserBookmarksAdapter.java75
-rw-r--r--src/com/android/browser/BrowserBookmarksPage.java54
-rw-r--r--src/com/android/browser/CombinedBookmarkHistoryView.java45
8 files changed, 250 insertions, 19 deletions
diff --git a/res/layout/bookmark_list.xml b/res/layout/bookmark_list.xml
new file mode 100644
index 0000000..720685b
--- /dev/null
+++ b/res/layout/bookmark_list.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source 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.
+-->
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/list_item"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:minHeight="@dimen/widgetItemMinHeight"
+ android:orientation="horizontal"
+ android:padding="8dip">
+ <ImageView
+ android:id="@+id/favicon"
+ android:layout_height="24dp"
+ android:layout_width="24dp"
+ android:layout_gravity="center_vertical"
+ android:scaleType="fitXY"/>
+ <TextView
+ android:id="@+id/label"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:padding="8dip"
+ android:maxLines="1"
+ android:scrollHorizontally="true"
+ android:ellipsize="marquee"/>
+</LinearLayout>
diff --git a/res/layout/bookmarks.xml b/res/layout/bookmarks.xml
index fa08353..66a78e8 100644
--- a/res/layout/bookmarks.xml
+++ b/res/layout/bookmarks.xml
@@ -31,6 +31,13 @@
android:focusable="true"
android:focusableInTouchMode="true"
android:numColumns="auto_fit" />
+ <ListView
+ android:id="@+id/list"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:focusable="true"
+ android:focusableInTouchMode="true"
+ android:visibility="gone"/>
<TextView
android:id="@android:id/empty"
android:layout_width="wrap_content"
diff --git a/res/layout/bookmarks_history.xml b/res/layout/bookmarks_history.xml
index a89a2b9..b8ccfe7 100644
--- a/res/layout/bookmarks_history.xml
+++ b/res/layout/bookmarks_history.xml
@@ -76,6 +76,23 @@
android:background="@null"
android:drawableLeft="@drawable/ic_favorite_off_normal"
android:drawablePadding="16dip" />
+ <ImageView
+ android:id="@+id/seperate_select_add"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:layout_toLeftOf="@id/addbm"
+ android:paddingRight="16dip"
+ android:src="@drawable/divider_vert" />
+ <TextView
+ android:id="@+id/select_bookmark_view"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:text="@string/switch_to_thumbnails"
+ android:layout_toLeftOf="@id/seperate_select_add"
+ android:paddingRight="16dip"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:gravity="center_vertical"
+ android:background="@null" />
</RelativeLayout>
<FrameLayout
android:id="@+id/fragment"
diff --git a/res/menu/bookmark_view.xml b/res/menu/bookmark_view.xml
new file mode 100644
index 0000000..fdfd672
--- /dev/null
+++ b/res/menu/bookmark_view.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source 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.
+-->
+
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:id="@+id/thumbnail_view"
+ android:title="@string/bookmark_thumbnail_view"/>
+ <item android:id="@+id/list_view"
+ android:title="@string/bookmark_list_view"/>
+</menu>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 4f63d3f..7d27dec 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -184,11 +184,11 @@
showing. -->
<string name="bookmark_page">Bookmark last-viewed page</string>
<!-- Menu item in the page that displays all bookmarks. Switches to
- a grid view which shows thumbnails -->
- <string name="switch_to_thumbnails">Thumbnail view</string>
+ a grid view which shows thumbnails [CHAR LIMIT=50] -->
+ <string name="bookmark_thumbnail_view">Thumbnail view</string>
<!-- Menu item in the page that displays all bookmarks. Switches to a
- list view which shows titles -->
- <string name="switch_to_list">List view</string>
+ list view which shows titles [CHAR LIMIT=50] -->
+ <string name="bookmark_list_view">List view</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/BrowserBookmarksAdapter.java b/src/com/android/browser/BrowserBookmarksAdapter.java
index a5d51dd..6478b10 100644
--- a/src/com/android/browser/BrowserBookmarksAdapter.java
+++ b/src/com/android/browser/BrowserBookmarksAdapter.java
@@ -20,42 +20,97 @@ import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
+import android.view.LayoutInflater;
import android.view.View;
+import android.view.ViewGroup;
+import android.widget.CursorAdapter;
import android.widget.ImageView;
-import android.widget.ResourceCursorAdapter;
import android.widget.TextView;
-class BrowserBookmarksAdapter extends ResourceCursorAdapter {
+class BrowserBookmarksAdapter extends CursorAdapter {
+ LayoutInflater mInflater;
+ int mCurrentView;
+
/**
* Create a new BrowserBookmarksAdapter.
*/
- public BrowserBookmarksAdapter(Context context) {
+ public BrowserBookmarksAdapter(Context context, int defaultView) {
// Make sure to tell the CursorAdapter to avoid the observer and auto-requery
// since the Loader will do that for us.
- super(context, R.layout.bookmark_thumbnail, null);
+ super(context, null);
+ mInflater = LayoutInflater.from(context);
+ selectView(defaultView);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
+ if (mCurrentView == BrowserBookmarksPage.VIEW_LIST) {
+ bindListView(view, context, cursor);
+ } else {
+ bindGridView(view, context, cursor);
+ }
+ }
+
+ void bindGridView(View view, Context context, Cursor cursor) {
ImageView thumb = (ImageView) view.findViewById(R.id.thumb);
TextView tv = (TextView) view.findViewById(R.id.label);
tv.setText(cursor.getString(BookmarksLoader.COLUMN_INDEX_TITLE));
- Bitmap thumbnail = null;
if (cursor.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) != 0) {
// folder
thumb.setImageResource(R.drawable.ic_folder);
} else {
- byte[] data = cursor.getBlob(BookmarksLoader.COLUMN_INDEX_THUMBNAIL);
- if (data != null) {
- thumbnail = BitmapFactory.decodeByteArray(data, 0, data.length);
+ byte[] thumbData = cursor.getBlob(BookmarksLoader.COLUMN_INDEX_THUMBNAIL);
+ Bitmap thumbBitmap = null;
+ if (thumbData != null) {
+ thumbBitmap = BitmapFactory.decodeByteArray(thumbData, 0, thumbData.length);
}
- if (thumbnail == null) {
+ if (thumbBitmap == null) {
thumb.setImageResource(R.drawable.browser_thumbnail);
} else {
- thumb.setImageBitmap(thumbnail);
+ thumb.setImageBitmap(thumbBitmap);
+ }
+ }
+ }
+
+ void bindListView(View view, Context context, Cursor cursor) {
+ ImageView favicon = (ImageView) view.findViewById(R.id.favicon);
+ TextView tv = (TextView) view.findViewById(R.id.label);
+
+ tv.setText(cursor.getString(BookmarksLoader.COLUMN_INDEX_TITLE));
+ if (cursor.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) != 0) {
+ // folder
+ favicon.setImageResource(R.drawable.ic_folder);
+ } else {
+ byte[] faviconData = cursor.getBlob(BookmarksLoader.COLUMN_INDEX_FAVICON);
+ Bitmap faviconBitmap = null;
+ if (faviconData != null) {
+ faviconBitmap = BitmapFactory.decodeByteArray(faviconData, 0, faviconData.length);
+ }
+
+ if (faviconBitmap == null) {
+ favicon.setImageResource(R.drawable.app_web_browser_sm);
+ } else {
+ favicon.setImageBitmap(faviconBitmap);
}
}
}
+
+ @Override
+ public View newView(Context context, Cursor cursor, ViewGroup parent) {
+ if (mCurrentView == BrowserBookmarksPage.VIEW_LIST) {
+ return mInflater.inflate(R.layout.bookmark_list, parent, false);
+ } else {
+ return mInflater.inflate(R.layout.bookmark_thumbnail, parent, false);
+ }
+ }
+
+ public void selectView(int view) {
+ if (view != BrowserBookmarksPage.VIEW_LIST
+ && view != BrowserBookmarksPage.VIEW_THUMBNAILS) {
+ throw new IllegalArgumentException("Unknown view specified: " + view);
+ }
+ mCurrentView = view;
+ }
}
diff --git a/src/com/android/browser/BrowserBookmarksPage.java b/src/com/android/browser/BrowserBookmarksPage.java
index c7392cc..2b8c535 100644
--- a/src/com/android/browser/BrowserBookmarksPage.java
+++ b/src/com/android/browser/BrowserBookmarksPage.java
@@ -31,6 +31,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.Loader;
import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -53,6 +54,7 @@ import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.GridView;
+import android.widget.ListView;
import android.widget.Toast;
/**
@@ -77,15 +79,20 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte
public static final String PREF_ACCOUNT_NAME = "acct_name";
static final String DEFAULT_ACCOUNT = "local";
+ static final int VIEW_THUMBNAILS = 1;
+ static final int VIEW_LIST = 2;
+ static final String PREF_SELECTED_VIEW = "bookmarks_view";
BookmarksHistoryCallbacks mCallbacks;
GridView mGrid;
+ ListView mList;
BrowserBookmarksAdapter mAdapter;
boolean mDisableNewWindow;
BookmarkItem mContextHeader;
boolean mCanceled = false;
boolean mCreateShortcut;
View mEmptyView;
+ int mCurrentView;
BreadCrumbView mCrumbs;
@@ -134,9 +141,10 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte
if (cursor == null || cursor.getCount() == 0) {
mEmptyView.setVisibility(View.VISIBLE);
mGrid.setVisibility(View.GONE);
+ mList.setVisibility(View.GONE);
} else {
mEmptyView.setVisibility(View.GONE);
- mGrid.setVisibility(View.VISIBLE);
+ setupBookmarkView();
}
// Give the new data to the adapter
@@ -372,13 +380,19 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte
if (!mCreateShortcut) {
mGrid.setOnCreateContextMenuListener(this);
}
-
- mAdapter = new BrowserBookmarksAdapter(getActivity());
- mGrid.setAdapter(mAdapter);
+ mList = (ListView) root.findViewById(R.id.list);
+ mList.setOnItemClickListener(this);
+ if (!mCreateShortcut) {
+ mList.setOnCreateContextMenuListener(this);
+ registerForContextMenu(mList);
+ }
// Start the loaders
LoaderManager lm = getLoaderManager();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ mCurrentView =
+ prefs.getInt(PREF_SELECTED_VIEW, BrowserBookmarksPage.VIEW_THUMBNAILS);
+ mAdapter = new BrowserBookmarksAdapter(getActivity(), mCurrentView);
String accountType = prefs.getString(PREF_ACCOUNT_TYPE, DEFAULT_ACCOUNT);
String accountName = prefs.getString(PREF_ACCOUNT_NAME, DEFAULT_ACCOUNT);
if (!TextUtils.isEmpty(accountType) && !TextUtils.isEmpty(accountName)) {
@@ -609,4 +623,36 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte
cm.setPrimaryClip(ClipData.newRawUri(null, null, Uri.parse(text.toString())));
}
+ void selectView(int view) {
+ if (view == mCurrentView) {
+ return;
+ }
+ mCurrentView = view;
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
+ Editor edit = prefs.edit();
+ edit.putInt(PREF_SELECTED_VIEW, mCurrentView);
+ edit.apply();
+ if (mEmptyView.getVisibility() == View.VISIBLE) {
+ return;
+ }
+ setupBookmarkView();
+ }
+
+ private void setupBookmarkView() {
+ mAdapter.selectView(mCurrentView);
+ switch (mCurrentView) {
+ case VIEW_THUMBNAILS:
+ mList.setAdapter(null);
+ mGrid.setAdapter(mAdapter);
+ mGrid.setVisibility(View.VISIBLE);
+ mList.setVisibility(View.GONE);
+ break;
+ case VIEW_LIST:
+ mGrid.setAdapter(null);
+ mList.setAdapter(mAdapter);
+ mGrid.setVisibility(View.GONE);
+ mList.setVisibility(View.VISIBLE);
+ break;
+ }
+ }
}
diff --git a/src/com/android/browser/CombinedBookmarkHistoryView.java b/src/com/android/browser/CombinedBookmarkHistoryView.java
index c078b51..4f6f10c 100644
--- a/src/com/android/browser/CombinedBookmarkHistoryView.java
+++ b/src/com/android/browser/CombinedBookmarkHistoryView.java
@@ -21,17 +21,22 @@ import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
+import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.provider.Browser;
import android.view.LayoutInflater;
+import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebIconDatabase;
import android.webkit.WebIconDatabase.IconListener;
import android.widget.LinearLayout;
+import android.widget.PopupMenu;
+import android.widget.PopupMenu.OnMenuItemClickListener;
import android.widget.TextView;
import java.util.HashMap;
@@ -44,7 +49,7 @@ interface BookmarksHistoryCallbacks {
}
public class CombinedBookmarkHistoryView extends LinearLayout
- implements OnClickListener, BreadCrumbView.Controller {
+ implements OnClickListener, BreadCrumbView.Controller, OnMenuItemClickListener {
final static String STARTING_FRAGMENT = "fragment";
@@ -63,6 +68,8 @@ public class CombinedBookmarkHistoryView extends LinearLayout
TextView mTabBookmarks;
TextView mTabHistory;
TextView mAddBookmark;
+ TextView mSelectBookmarkView;
+ View mSeperateSelectAdd;
BrowserBookmarksPage mBookmarks;
BrowserHistoryPage mHistory;
@@ -122,9 +129,20 @@ public class CombinedBookmarkHistoryView extends LinearLayout
mTabBookmarks = (TextView) findViewById(R.id.bmtab);
mTabHistory = (TextView) findViewById(R.id.historytab);
mAddBookmark = (TextView) findViewById(R.id.addbm);
+ mSeperateSelectAdd = findViewById(R.id.seperate_select_add);
+ mSelectBookmarkView = (TextView) findViewById(R.id.select_bookmark_view);
mAddBookmark.setOnClickListener(this);
mTabHistory.setOnClickListener(this);
mTabBookmarks.setOnClickListener(this);
+ mSelectBookmarkView.setOnClickListener(this);
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
+ int bookmarksView =
+ prefs.getInt(BrowserBookmarksPage.PREF_SELECTED_VIEW, BrowserBookmarksPage.VIEW_THUMBNAILS);
+ if (bookmarksView == BrowserBookmarksPage.VIEW_THUMBNAILS) {
+ mSelectBookmarkView.setText(R.string.bookmark_thumbnail_view);
+ } else {
+ mSelectBookmarkView.setText(R.string.bookmark_list_view);
+ }
// Start up the default fragment
initFragments(mExtras);
loadFragment(startingFragment, mExtras, false);
@@ -157,6 +175,8 @@ public class CombinedBookmarkHistoryView extends LinearLayout
switch (id) {
case FRAGMENT_ID_BOOKMARKS:
fragment = mBookmarks;
+ mSeperateSelectAdd.setVisibility(View.VISIBLE);
+ mSelectBookmarkView.setVisibility(View.VISIBLE);
mCrumbs.setVisibility(View.VISIBLE);
if (notify) {
mCrumbs.notifyController();
@@ -165,6 +185,8 @@ public class CombinedBookmarkHistoryView extends LinearLayout
case FRAGMENT_ID_HISTORY:
fragment = mHistory;
mCrumbs.setVisibility(View.GONE);
+ mSeperateSelectAdd.setVisibility(View.GONE);
+ mSelectBookmarkView.setVisibility(View.GONE);
break;
default:
throw new IllegalArgumentException();
@@ -189,6 +211,12 @@ public class CombinedBookmarkHistoryView extends LinearLayout
}
} else if (mAddBookmark == view) {
mUiController.bookmarkCurrentPage(mBookmarks.getFolderId());
+ } else if (mSelectBookmarkView == view) {
+ PopupMenu popup = new PopupMenu(mContext, mSelectBookmarkView);
+ popup.getMenuInflater().inflate(R.menu.bookmark_view,
+ popup.getMenu());
+ popup.setOnMenuItemClickListener(this);
+ popup.show();
}
}
@@ -212,4 +240,19 @@ public class CombinedBookmarkHistoryView extends LinearLayout
return false;
}
+ @Override
+ public boolean onMenuItemClick(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.list_view:
+ mSelectBookmarkView.setText(R.string.bookmark_list_view);
+ mBookmarks.selectView(BrowserBookmarksPage.VIEW_LIST);
+ return true;
+ case R.id.thumbnail_view:
+ mSelectBookmarkView.setText(R.string.bookmark_thumbnail_view);
+ mBookmarks.selectView(BrowserBookmarksPage.VIEW_THUMBNAILS);
+ return true;
+ }
+ return false;
+ }
+
}