summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--res/layout/bookmark_thumbnail.xml42
-rw-r--r--res/values/strings.xml3
-rw-r--r--src/com/android/browser/BookmarkGridPage.java47
-rw-r--r--src/com/android/browser/BrowserActivity.java95
-rw-r--r--src/com/android/browser/BrowserBookmarksAdapter.java49
-rw-r--r--src/com/android/browser/BrowserBookmarksPage.java20
6 files changed, 120 insertions, 136 deletions
diff --git a/res/layout/bookmark_thumbnail.xml b/res/layout/bookmark_thumbnail.xml
index 5e7a27b..2f8a09d 100644
--- a/res/layout/bookmark_thumbnail.xml
+++ b/res/layout/bookmark_thumbnail.xml
@@ -14,7 +14,7 @@
limitations under the License.
-->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:padding="4dip"
@@ -23,21 +23,47 @@
<ImageView android:id="@+id/thumb"
android:src="@drawable/blank"
android:scaleType="center"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
+ android:layout_width="100dip"
+ android:layout_height="80dip"
/>
-<!--
<ImageView android:id="@+id/fav"
android:scaleType="center"
android:layout_width="20dip"
android:layout_height="20dip"
+ android:layout_alignBottom="@+id/thumb"
+ android:background="@color/white"
/>
--->
-
- <TextView android:id="@+id/label"
+ <LinearLayout android:id="@+id/holder"
+ android:layout_height="wrap_content"
android:layout_width="fill_parent"
+ android:orientation="horizontal"
+ android:background="#cc000000"
+ android:gravity="center"
+ android:layout_alignBottom="@+id/thumb"
+ >
+ <ImageView
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:layout_marginTop="3dip"
+ android:layout_marginBottom="3dip"
+ android:src="@drawable/ic_tab_browser_bookmark_selected"
+ />
+ <TextView
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textStyle="bold"
+ android:textColor="@color/white"
+ android:text="@string/add_bookmark_short"
+ />
+ </LinearLayout>
+ <!-- Keep the width in sync with BrowserBookmarksPage and
+ BrowserActivity.updateScreenshot -->
+ <TextView android:id="@+id/label"
+ android:layout_width="100dip"
android:layout_height="wrap_content"
+ android:layout_below="@+id/thumb"
android:layout_gravity="bottom"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold"
@@ -50,4 +76,4 @@
android:scrollHorizontally="true"
android:ellipsize="marquee"
/>
-</LinearLayout>
+</RelativeLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5f158a2..b8fa9cf 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -495,6 +495,9 @@
<string name="empty_history">Browser history is empty.</string>
<!-- Displayed at the top of the bookmarks page. When clicked, it bookmarks the page the browser is currently showing -->
<string name="add_new_bookmark">Add bookmark\u2026</string>
+ <!-- Verb placed in front of a screenshot of a web page that, when clicked,
+ will add that page to bookmarks -->
+ <string name="add_bookmark_short">Add</string>
<!-- Add bookmark dialog sets its title to this if we have no database.
This is an error case -->
<string name="no_database">No database!</string>
diff --git a/src/com/android/browser/BookmarkGridPage.java b/src/com/android/browser/BookmarkGridPage.java
deleted file mode 100644
index 5517d9c..0000000
--- a/src/com/android/browser/BookmarkGridPage.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2009 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.
- */
-
-package com.android.browser;
-
-import android.content.Context;
-import android.widget.GridView;
-
-import java.util.ArrayList;
-
-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 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/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java
index 43f1acd..585b8ff 100644
--- a/src/com/android/browser/BrowserActivity.java
+++ b/src/com/android/browser/BrowserActivity.java
@@ -2878,6 +2878,58 @@ public class BrowserActivity extends Activity
}
};
+ private void updateScreenshot(WebView view) {
+ // If this is a bookmarked site, add a screenshot to the database.
+ // FIXME: When should we update? Every time?
+ // FIXME: Would like to make sure there is actually something to
+ // draw, but the API for that (WebViewCore.pictureReady()) is not
+ // currently accessible here.
+ String original = view.getOriginalUrl();
+ if (original != null) {
+ // copied from BrowserBookmarksAdapter
+ int query = original.indexOf('?');
+ String noQuery = original;
+ if (query != -1) {
+ noQuery = original.substring(0, query);
+ }
+ String URL = noQuery + '?';
+ String[] selArgs = new String[] { noQuery, URL };
+ final String where
+ = "(url == ? OR url GLOB ? || '*') AND bookmark == 1";
+ final String[] projection
+ = new String[] { Browser.BookmarkColumns._ID };
+ ContentResolver cr = getContentResolver();
+ final Cursor c = cr.query(Browser.BOOKMARKS_URI, projection,
+ where, selArgs, null);
+ boolean succeed = c.moveToFirst();
+ ContentValues values = null;
+ while (succeed) {
+ if (values == null) {
+ final ByteArrayOutputStream os
+ = new ByteArrayOutputStream();
+ Picture thumbnail = view.capturePicture();
+ // Keep width and height in sync with BrowserBookmarksPage
+ // and bookmark_thumb
+ Bitmap bm = Bitmap.createBitmap(100, 80,
+ Bitmap.Config.ARGB_4444);
+ Canvas canvas = new Canvas(bm);
+ // May need to tweak these values to determine what is the
+ // best scale factor
+ canvas.scale(.5f, .5f);
+ thumbnail.draw(canvas);
+ bm.compress(Bitmap.CompressFormat.PNG, 100, os);
+ values = new ContentValues();
+ values.put(Browser.BookmarkColumns.THUMBNAIL,
+ os.toByteArray());
+ }
+ cr.update(ContentUris.withAppendedId(Browser.BOOKMARKS_URI,
+ c.getInt(0)), values, null, null);
+ succeed = c.moveToNext();
+ }
+ c.close();
+ }
+ }
+
// -------------------------------------------------------------------------
// WebViewClient implementation.
//-------------------------------------------------------------------------
@@ -2989,48 +3041,7 @@ public class BrowserActivity extends Activity
// Update the lock icon image only once we are done loading
updateLockIconImage(mLockIconType);
-
- // If this is a bookmarked site, add a screenshot to the database.
- // FIXME: When should we update? Every time?
- String original = view.getOriginalUrl();
- if (original != null) {
- // copied from BrowserBookmarksAdapter
- int query = original.indexOf('?');
- String noQuery = original;
- if (query != -1) {
- noQuery = original.substring(0, query);
- }
- String URL = noQuery + '?';
- String[] selArgs = new String[] { noQuery, URL };
- final String where = "(url == ? OR url GLOB ? || '*') AND bookmark == 1";
- final String[] projection = new String[] { Browser.BookmarkColumns._ID };
- ContentResolver cr = getContentResolver();
- final Cursor c = cr.query(Browser.BOOKMARKS_URI, projection, where, selArgs, null);
- boolean succeed = c.moveToFirst();
- ContentValues values = null;
- while (succeed) {
- if (values == null) {
- final ByteArrayOutputStream os = new ByteArrayOutputStream();
- Picture thumbnail = view.capturePicture();
- // Height was arbitrarily chosen
- Bitmap bm = Bitmap.createBitmap(100, 100,
- Bitmap.Config.ARGB_4444);
- Canvas canvas = new Canvas(bm);
- // Scale chosen to be about one third, since we want
- // roughly three rows/columns for bookmark page
- canvas.scale(.3f, .3f);
- thumbnail.draw(canvas);
- bm.compress(Bitmap.CompressFormat.PNG, 100, os);
- values = new ContentValues();
- values.put(Browser.BookmarkColumns.THUMBNAIL,
- os.toByteArray());
- }
- cr.update(ContentUris.withAppendedId(Browser.BOOKMARKS_URI,
- c.getInt(0)), values, null, null);
- succeed = c.moveToNext();
- }
- c.close();
- }
+ updateScreenshot(view);
// Performance probe
if (false) {
diff --git a/src/com/android/browser/BrowserBookmarksAdapter.java b/src/com/android/browser/BrowserBookmarksAdapter.java
index c7210af..75be45b 100644
--- a/src/com/android/browser/BrowserBookmarksAdapter.java
+++ b/src/com/android/browser/BrowserBookmarksAdapter.java
@@ -44,15 +44,13 @@ import java.io.ByteArrayOutputStream;
class BrowserBookmarksAdapter extends BaseAdapter {
private String mCurrentPage;
+ private String mCurrentTitle;
private Cursor mCursor;
private int mCount;
private BrowserBookmarksPage mBookmarksPage;
private ContentResolver mContentResolver;
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;
@@ -70,28 +68,19 @@ class BrowserBookmarksAdapter extends BaseAdapter {
/**
* Create a new BrowserBookmarksAdapter.
- * @param b BrowserBookmarksPage that instantiated this.
- * Necessary so it will adjust its focus
- * appropriately after a search.
- */
- public BrowserBookmarksAdapter(BrowserBookmarksPage b, String curPage) {
- this(b, curPage, false);
- }
-
- /**
- * Create a new BrowserBookmarksAdapter.
* @param b BrowserBookmarksPage that instantiated this.
* Necessary so it will adjust its focus
* appropriately after a search.
*/
public BrowserBookmarksAdapter(BrowserBookmarksPage b, String curPage,
- boolean createShortcut) {
+ String curTitle, boolean createShortcut) {
mDataValid = false;
mCreateShortcut = createShortcut;
mExtraOffset = createShortcut ? 0 : 1;
mBookmarksPage = b;
- mCurrentPage = b.getResources().getString(R.string.current_page) +
- curPage;
+ mCurrentPage = b.getResources().getString(R.string.current_page)
+ + curPage;
+ mCurrentTitle = curTitle;
mContentResolver = b.getContentResolver();
mGridMode = false;
@@ -109,7 +98,7 @@ class BrowserBookmarksAdapter extends BaseAdapter {
mCount = mCursor.getCount() + mExtraOffset;
// FIXME: This requires another query of the database after the
- // initial search(null). Can we optimize this?
+ // managedQuery. Can we optimize this?
Browser.requestAllIcons(mContentResolver,
Browser.BookmarkColumns.FAVICON + " is NULL AND " +
Browser.BookmarkColumns.BOOKMARK + " == 1", mIconReceiver);
@@ -341,10 +330,6 @@ class BrowserBookmarksAdapter extends BaseAdapter {
return position;
}
- /* package */ void heightChanged(int newHeight) {
- mThumbHeight = newHeight;
- }
-
/* package */ void switchViewMode(boolean toGrid) {
mGridMode = toGrid;
}
@@ -381,24 +366,21 @@ class BrowserBookmarksAdapter extends BaseAdapter {
convertView
= factory.inflate(R.layout.bookmark_thumbnail, null);
}
+ View holder = convertView.findViewById(R.id.holder);
ImageView thumb = (ImageView) convertView.findViewById(R.id.thumb);
- // Favicon disabled for now.
- //ImageView fav = (ImageView) convertView.findViewById(R.id.fav);
+ 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);
+ holder.setVisibility(View.VISIBLE);
+ fav.setVisibility(View.GONE);
+ tv.setText(mCurrentTitle);
+ // FIXME: Want to show the screenshot of the current page
+ thumb.setImageResource(R.drawable.blank);
return convertView;
}
+ holder.setVisibility(View.GONE);
mCursor.moveToPosition(position - mExtraOffset);
tv.setText(mCursor.getString(
Browser.HISTORY_PROJECTION_TITLE_INDEX));
@@ -411,7 +393,6 @@ class BrowserBookmarksAdapter extends BaseAdapter {
thumb.setImageBitmap(
BitmapFactory.decodeByteArray(data, 0, data.length));
}
-/*
// Now show the favicon
data = mCursor.getBlob(Browser.HISTORY_PROJECTION_FAVICON_INDEX);
if (data == null) {
@@ -421,7 +402,7 @@ class BrowserBookmarksAdapter extends BaseAdapter {
fav.setImageBitmap(
BitmapFactory.decodeByteArray(data, 0, data.length));
}
-*/
+
return convertView;
}
diff --git a/src/com/android/browser/BrowserBookmarksPage.java b/src/com/android/browser/BrowserBookmarksPage.java
index 513ce3e..428aa92 100644
--- a/src/com/android/browser/BrowserBookmarksPage.java
+++ b/src/com/android/browser/BrowserBookmarksPage.java
@@ -44,6 +44,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AdapterView;
+import android.widget.GridView;
import android.widget.ListView;
import android.widget.Toast;
@@ -54,7 +55,7 @@ public class BrowserBookmarksPage extends Activity implements
View.OnCreateContextMenuListener {
private boolean mGridMode;
- private BookmarkGridPage mGridPage;
+ private GridView mGridPage;
private View mVerticalList;
private BrowserBookmarksAdapter mBookmarksAdapter;
private static final int BOOKMARKS_SAVE = 1;
@@ -181,9 +182,9 @@ public class BrowserBookmarksPage extends Activity implements
setTitle(R.string.browser_bookmarks_page_bookmarks_text);
mBookmarksAdapter = new BrowserBookmarksAdapter(this,
- getIntent().getStringExtra("url"), mCreateShortcut);
- mGridMode = true;
- switchViewMode(mGridMode);
+ getIntent().getStringExtra("url"),
+ getIntent().getStringExtra("title"), mCreateShortcut);
+ switchViewMode(true);
}
/**
@@ -195,8 +196,17 @@ public class BrowserBookmarksPage extends Activity implements
mBookmarksAdapter.switchViewMode(gridMode);
if (mGridMode) {
if (mGridPage == null) {
- mGridPage = new BookmarkGridPage(this, mBookmarksAdapter);
+ mGridPage = new GridView(this);
+ mGridPage.setAdapter(mBookmarksAdapter);
mGridPage.setOnItemClickListener(mListener);
+ mGridPage.setNumColumns(GridView.AUTO_FIT);
+ // Keep this in sync with bookmark_thumb and
+ // BrowserActivity.updateScreenshot
+ mGridPage.setColumnWidth(100);
+ mGridPage.setFocusable(true);
+ mGridPage.setFocusableInTouchMode(true);
+ mGridPage.setSelector(android.R.drawable.gallery_thumb);
+ mGridPage.setVerticalSpacing(10);
if (!mCreateShortcut) {
mGridPage.setOnCreateContextMenuListener(this);
}