summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorPatrick Scott <phanna@android.com>2009-09-23 08:08:17 -0400
committerPatrick Scott <phanna@android.com>2009-09-23 14:48:32 -0400
commit555c5808b3beb8d535480bbed6b7b4d17e21aa98 (patch)
tree8c9a205e43365db00f8455e2db7c3d535fbd2270 /src/com
parent5e335a381a0cd66e94117b202c1f34f5cb29c9b8 (diff)
downloadpackages_apps_Browser-555c5808b3beb8d535480bbed6b7b4d17e21aa98.zip
packages_apps_Browser-555c5808b3beb8d535480bbed6b7b4d17e21aa98.tar.gz
packages_apps_Browser-555c5808b3beb8d535480bbed6b7b4d17e21aa98.tar.bz2
Use favicons in the tab page instead of a snapshot.
Remove the FakeWebView and all the picture stuff from the picker data. Use the favicon in a layout similar to history and bookmarks. Add tab_view_add_tab.xml to have a simpler layout for the "new tab" item in the list.
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/browser/ActiveTabsPage.java51
-rw-r--r--src/com/android/browser/FakeWebView.java106
-rw-r--r--src/com/android/browser/TabControl.java68
3 files changed, 39 insertions, 186 deletions
diff --git a/src/com/android/browser/ActiveTabsPage.java b/src/com/android/browser/ActiveTabsPage.java
index e589d42..90c417a 100644
--- a/src/com/android/browser/ActiveTabsPage.java
+++ b/src/com/android/browser/ActiveTabsPage.java
@@ -17,6 +17,7 @@
package com.android.browser;
import android.content.Context;
+import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@@ -102,36 +103,44 @@ public class ActiveTabsPage extends LinearLayout {
public long getItemId(int position) {
return position;
}
- public View getView(int position, View convertView, ViewGroup parent) {
- if (convertView == null) {
- convertView = mFactory.inflate(R.layout.tab_view, null);
+ public int getViewTypeCount() {
+ return 2;
+ }
+ public int getItemViewType(int position) {
+ if (mControl.getTabCount() < TabControl.MAX_TABS) {
+ position--;
}
- TextView title = (TextView) convertView.findViewById(R.id.title);
- TextView url = (TextView) convertView.findViewById(R.id.url);
- FakeWebView webView
- = (FakeWebView) convertView.findViewById(R.id.screen_shot);
- View close = convertView.findViewById(R.id.close);
- View divider = convertView.findViewById(R.id.divider);
-
+ // Do not recycle the "add new tab" item.
+ return position == -1 ? IGNORE_ITEM_VIEW_TYPE : 1;
+ }
+ public View getView(int position, View convertView, ViewGroup parent) {
final int tabCount = mControl.getTabCount();
if (tabCount < TabControl.MAX_TABS) {
position--;
}
- if (position == -1) {
- title.setText(R.string.new_tab);
- url.setVisibility(View.GONE);
- webView.setImageResource(R.drawable.ic_add_tab);
- close.setVisibility(View.GONE);
- divider.setVisibility(View.GONE);
- } else {
+
+ if (convertView == null) {
+ convertView = mFactory.inflate(position == -1 ?
+ R.layout.tab_view_add_tab : R.layout.tab_view, null);
+ }
+
+ if (position != -1) {
+ TextView title =
+ (TextView) convertView.findViewById(R.id.title);
+ TextView url = (TextView) convertView.findViewById(R.id.url);
+ ImageView favicon =
+ (ImageView) convertView.findViewById(R.id.favicon);
+ View close = convertView.findViewById(R.id.close);
TabControl.Tab tab = mControl.getTab(position);
mControl.populatePickerData(tab);
title.setText(tab.getTitle());
url.setText(tab.getUrl());
- url.setVisibility(View.VISIBLE);
- webView.setTab(tab);
- divider.setVisibility(View.VISIBLE);
- close.setVisibility(View.VISIBLE);
+ Bitmap icon = tab.getFavicon();
+ if (icon != null) {
+ favicon.setImageBitmap(icon);
+ } else {
+ favicon.setImageResource(R.drawable.app_web_browser_sm);
+ }
final int closePosition = position;
close.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
diff --git a/src/com/android/browser/FakeWebView.java b/src/com/android/browser/FakeWebView.java
deleted file mode 100644
index da5ef5f..0000000
--- a/src/com/android/browser/FakeWebView.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (C) 2008 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.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Picture;
-import android.util.AttributeSet;
-import android.view.View;
-import android.webkit.WebView;
-import android.widget.ImageView;
-
-import android.util.Log;
-
-/**
- * This class is used by ImageAdapter to draw a representation of each tab. It
- * overrides ImageView so it can be used for the new tab image as well.
- */
-public class FakeWebView extends ImageView {
- private TabControl.PickerData mPickerData;
- private boolean mUsesResource;
-
- public FakeWebView(Context context) {
- this(context, null);
- }
-
- public FakeWebView(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public FakeWebView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- }
-
- @Override
- protected void onDraw(Canvas canvas) {
- if (mUsesResource) {
- super.onDraw(canvas);
- } else {
- // Always draw white behind the picture just in case the picture
- // draws nothing.
- // FIXME: We used to draw white only when the WebView was null but
- // sometimes the picture was empty. So now we always draw white. It
- // would be nice to know if the picture is empty so we can avoid
- // drawing white.
- canvas.drawColor(Color.WHITE);
- if (mPickerData != null) {
- final Picture p = mPickerData.mPicture;
- if (p != null) {
- canvas.save();
- float scale = getWidth() * mPickerData.mScale
- / mPickerData.mWidth;
- // Check for NaN and infinity.
- if (Float.isNaN(scale) || Float.isInfinite(scale)) {
- scale = 1.0f;
- }
- canvas.scale(scale, scale);
- canvas.translate(-mPickerData.mScrollX,
- -mPickerData.mScrollY);
- canvas.drawPicture(p);
- canvas.restore();
- }
- }
- }
- }
-
- @Override
- public void setImageResource(int resId) {
- mUsesResource = true;
- mPickerData = null;
- super.setImageResource(resId);
- }
-
- /**
- * Set a WebView for this FakeWebView to represent.
- * @param t The tab whose picture and other data will be used in onDraw.
- */
- public void setTab(TabControl.Tab t) {
- mUsesResource = false;
- if (mPickerData != null) {
- // Clear the old tab's view first
- mPickerData.mFakeWebView = null;
- }
- mPickerData = null;
- if (t != null && t.getPickerData() != null) {
- mPickerData = t.getPickerData();
- mPickerData.mFakeWebView = this;
- }
- }
-}
diff --git a/src/com/android/browser/TabControl.java b/src/com/android/browser/TabControl.java
index 6e4bae2..3de60a3 100644
--- a/src/com/android/browser/TabControl.java
+++ b/src/com/android/browser/TabControl.java
@@ -17,6 +17,7 @@
package com.android.browser;
import android.content.Context;
+import android.graphics.Bitmap;
import android.graphics.Picture;
import android.net.http.SslError;
import android.os.Bundle;
@@ -159,20 +160,16 @@ class TabControl {
public static class PickerData {
String mUrl;
String mTitle;
+ Bitmap mFavicon;
float mScale;
int mScrollX;
int mScrollY;
- int mWidth;
- Picture mPicture;
- // This can be null. When a new picture comes in, this view should be
- // invalidated to show the new picture.
- FakeWebView mFakeWebView;
}
/**
* Private class for maintaining Tabs with a main WebView and a subwindow.
*/
- public class Tab implements WebView.PictureListener {
+ public class Tab {
// The Geolocation permissions prompt
private GeolocationPermissionsPrompt mGeolocationPermissionsPrompt;
private View mContainer;
@@ -372,11 +369,11 @@ class TabControl {
return null;
}
- /**
- * Returns the picker data.
- */
- public PickerData getPickerData() {
- return mPickerData;
+ public Bitmap getFavicon() {
+ if (mPickerData != null) {
+ return mPickerData.mFavicon;
+ }
+ return null;
}
private void setParentTab(Tab parent) {
@@ -439,18 +436,6 @@ class TabControl {
return mCloseOnExit;
}
- public void onNewPicture(WebView view, Picture p) {
- if (mPickerData == null) {
- return;
- }
-
- mPickerData.mPicture = p;
- // Tell the FakeWebView to redraw.
- if (mPickerData.mFakeWebView != null) {
- mPickerData.mFakeWebView.invalidate();
- }
- }
-
void setLockIconType(int type) {
mSavedLockIconType = type;
}
@@ -730,7 +715,6 @@ class TabControl {
private static final String CURRTAB = "currentTab";
private static final String CURRURL = "currentUrl";
private static final String CURRTITLE = "currentTitle";
- private static final String CURRWIDTH = "currentWidth";
private static final String CURRPICTURE = "currentPicture";
private static final String CLOSEONEXIT = "closeonexit";
private static final String PARENTTAB = "parentTab";
@@ -1194,15 +1178,6 @@ class TabControl {
final WebHistoryItem item =
list != null ? list.getCurrentItem() : null;
populatePickerData(t, item);
-
- // This method is only called during the tab picker creation. At this
- // point we need to listen for new pictures since the WebView is still
- // active.
- final WebView w = t.getTopWindow();
- w.setPictureListener(t);
- // Capture the picture here instead of populatePickerData since it can
- // be called when saving the state of a tab.
- t.mPickerData.mPicture = w.capturePicture();
}
// Create the PickerData and populate it using the saved state of the tab.
@@ -1215,25 +1190,12 @@ class TabControl {
final Bundle state = t.mSavedState;
data.mUrl = state.getString(CURRURL);
data.mTitle = state.getString(CURRTITLE);
- data.mWidth = state.getInt(CURRWIDTH, 0);
// XXX: These keys are from WebView.savePicture so if they change, this
// will break.
data.mScale = state.getFloat("scale", 1.0f);
data.mScrollX = state.getInt("scrollX", 0);
data.mScrollY = state.getInt("scrollY", 0);
- if (state.containsKey(CURRPICTURE)) {
- final File f = new File(t.mSavedState.getString(CURRPICTURE));
- try {
- final FileInputStream in = new FileInputStream(f);
- data.mPicture = Picture.createFromStream(in);
- in.close();
- } catch (Exception ex) {
- // Ignore any problems with inflating the picture. We just
- // won't draw anything.
- }
- }
-
// Set the tab's picker data.
t.mPickerData = data;
}
@@ -1245,6 +1207,7 @@ class TabControl {
if (item != null) {
data.mUrl = item.getUrl();
data.mTitle = item.getTitle();
+ data.mFavicon = item.getFavicon();
if (data.mTitle == null) {
data.mTitle = data.mUrl;
}
@@ -1252,15 +1215,10 @@ class TabControl {
// We want to display the top window in the tab picker but use the url
// and title of the main window.
final WebView w = t.getTopWindow();
- data.mWidth = w.getWidth();
data.mScale = w.getScale();
data.mScrollX = w.getScrollX();
data.mScrollY = w.getScrollY();
- // Remember the old picture if possible.
- if (t.mPickerData != null) {
- data.mPicture = t.mPickerData.mPicture;
- }
t.mPickerData = data;
}
@@ -1274,13 +1232,6 @@ class TabControl {
if (t != null && t.mSavedState == null) {
t.mPickerData = null;
}
- if (t.mMainView != null) {
- // Clear the picture listeners.
- t.mMainView.setPictureListener(null);
- if (t.mSubView != null) {
- t.mSubView.setPictureListener(null);
- }
- }
}
}
@@ -1319,7 +1270,6 @@ class TabControl {
if (data.mTitle != null) {
b.putString(CURRTITLE, data.mTitle);
}
- b.putInt(CURRWIDTH, data.mWidth);
b.putBoolean(CLOSEONEXIT, t.mCloseOnExit);
if (t.mAppId != null) {
b.putString(APPID, t.mAppId);