summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2011-03-21 11:46:09 -0700
committerJohn Reck <jreck@google.com>2011-03-21 14:58:39 -0700
commit18e93f72fdfdd57ecaebe80ecccc9fecfbb16c8f (patch)
tree11cd560b335f4842bfde8619b7b948acf5cb6191
parentbd9eaf60f38ce56f7aa25ba59bc60a6051eb37ce (diff)
downloadpackages_apps_Browser-18e93f72fdfdd57ecaebe80ecccc9fecfbb16c8f.zip
packages_apps_Browser-18e93f72fdfdd57ecaebe80ecccc9fecfbb16c8f.tar.gz
packages_apps_Browser-18e93f72fdfdd57ecaebe80ecccc9fecfbb16c8f.tar.bz2
Tab switcher cleanup
Make it holo and clean up the code Change-Id: I6462cb72f104a2c076fd2ce2da876c74de8e783a
-rw-r--r--res/layout/active_tabs.xml64
-rw-r--r--res/layout/tab_view.xml27
-rw-r--r--res/layout/tab_view_add_incognito_tab.xml39
-rw-r--r--res/layout/tab_view_add_tab.xml39
-rw-r--r--src/com/android/browser/ActiveTabsPage.java264
-rw-r--r--src/com/android/browser/BrowserBookmarksAdapter.java8
6 files changed, 172 insertions, 269 deletions
diff --git a/res/layout/active_tabs.xml b/res/layout/active_tabs.xml
index 8b5fe9e..f9bd6b0 100644
--- a/res/layout/active_tabs.xml
+++ b/res/layout/active_tabs.xml
@@ -14,31 +14,41 @@
limitations under the License.
-->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_height="match_parent"
- android:layout_width="match_parent"
- android:orientation="vertical"
- android:background="@color/black"
- >
- <RelativeLayout
- style="?android:attr/windowTitleBackgroundStyle"
- android:layout_width="match_parent"
- android:layout_height="?android:attr/windowTitleSize"
- >
- <TextView android:id="@android:id/title"
- style="?android:attr/windowTitleStyle"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="@null"
- android:fadingEdge="horizontal"
- android:gravity="center_vertical"
- android:text="@string/active_tabs"
- />
- </RelativeLayout>
- <ListView android:id="@+id/list"
+<merge xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+
+ <Button
+ android:id="@+id/new_tab"
+ android:text="@string/new_tab"
+ android:layout_width="0dip"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceSmall" />
+
+ <Button
+ android:id="@+id/new_incognito_tab"
+ android:text="@string/new_incognito_tab"
+ android:layout_width="0dip"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:paddingLeft="0dip"
+ android:paddingRight="0dip" />
+
+ </LinearLayout>
+
+ <ListView
+ android:id="@android:id/list"
android:layout_width="match_parent"
- android:layout_height="0dip"
- android:layout_weight="1"
- android:cacheColorHint="@color/black"
- />
-</LinearLayout>
+ android:layout_height="match_parent"
+ android:listSelector="@drawable/bookmark_thumb_selector"
+ android:drawSelectorOnTop="true"
+ android:focusable="true"
+ android:focusableInTouchMode="true" />
+
+</merge>
diff --git a/res/layout/tab_view.xml b/res/layout/tab_view.xml
index 885f4cf..5426f61 100644
--- a/res/layout/tab_view.xml
+++ b/res/layout/tab_view.xml
@@ -20,21 +20,20 @@
android:layout_width="match_parent"
android:orientation="horizontal"
android:gravity="center_vertical"
+ android:paddingLeft="8dip"
>
- <!-- This ImageView has the same width as the ImageView in
- tab_view_add_tab.xml. -->
<ImageView android:id="@+id/favicon"
- android:layout_width="20dip"
- android:layout_height="20dip"
- android:layout_marginLeft="18dip"
- android:layout_marginRight="18dip"
- android:background="@drawable/fav_icn_background"
- android:padding="2dip"/>
+ android:layout_height="32dip"
+ android:layout_width="32dip"
+ android:layout_gravity="center_vertical"
+ android:background="@drawable/bookmark_list_favicon_bg"
+ android:scaleType="fitXY" />
<LinearLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
+ android:paddingLeft="8dip"
>
<TextView android:id="@+id/title"
android:layout_width="match_parent"
@@ -54,8 +53,8 @@
/>
</LinearLayout>
<View android:id="@+id/divider"
- android:background="#ff313431"
- android:layout_width="1dip"
+ android:background="?android:attr/dividerVertical"
+ android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginLeft="8dip"
android:layout_marginTop="5dip"
@@ -64,10 +63,10 @@
<view class="com.android.browser.ActiveTabsPage$CloseHolder" android:id="@+id/close"
android:layout_width="wrap_content"
android:layout_height="match_parent"
- android:paddingLeft="18dip"
- android:paddingRight="18dip"
- android:background="@drawable/close_background"
- android:src="@drawable/btn_close_window"
+ android:paddingLeft="12dip"
+ android:paddingRight="12dip"
+ android:background="@drawable/bookmark_thumb_selector"
+ android:src="@drawable/ic_close_window_holo_dark"
android:scaleType="center"
/>
</LinearLayout>
diff --git a/res/layout/tab_view_add_incognito_tab.xml b/res/layout/tab_view_add_incognito_tab.xml
deleted file mode 100644
index 43fcb43..0000000
--- a/res/layout/tab_view_add_incognito_tab.xml
+++ /dev/null
@@ -1,39 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- 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.
--->
-
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_height="wrap_content"
- android:minHeight="?android:attr/listPreferredItemHeight"
- android:layout_width="match_parent"
- android:orientation="horizontal"
- android:gravity="center_vertical"
- >
- <ImageView
- android:layout_width="40dip"
- android:layout_height="40dip"
- android:layout_marginLeft="8dip"
- android:layout_marginRight="8dip"
- android:src="@drawable/ic_new_window_holo_dark"/>
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:maxLines="1"
- android:singleLine="true"
- android:ellipsize="end"
- android:text="@string/new_incognito_tab"
- />
-</LinearLayout>
diff --git a/res/layout/tab_view_add_tab.xml b/res/layout/tab_view_add_tab.xml
deleted file mode 100644
index f4e0f02..0000000
--- a/res/layout/tab_view_add_tab.xml
+++ /dev/null
@@ -1,39 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- 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.
--->
-
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_height="wrap_content"
- android:minHeight="?android:attr/listPreferredItemHeight"
- android:layout_width="match_parent"
- android:orientation="horizontal"
- android:gravity="center_vertical"
- >
- <ImageView
- android:layout_width="40dip"
- android:layout_height="40dip"
- android:layout_marginLeft="8dip"
- android:layout_marginRight="8dip"
- android:src="@drawable/ic_new_window_holo_dark"/>
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:maxLines="1"
- android:singleLine="true"
- android:ellipsize="end"
- android:text="@string/new_tab"
- />
-</LinearLayout>
diff --git a/src/com/android/browser/ActiveTabsPage.java b/src/com/android/browser/ActiveTabsPage.java
index 664fd68..5e27eab 100644
--- a/src/com/android/browser/ActiveTabsPage.java
+++ b/src/com/android/browser/ActiveTabsPage.java
@@ -18,62 +18,86 @@ package com.android.browser;
import android.content.Context;
import android.graphics.Bitmap;
-import android.os.Handler;
import android.util.AttributeSet;
-import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
+import android.view.View.OnClickListener;
import android.view.ViewGroup;
+import android.widget.AbsListView;
import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
+import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
-import android.widget.ListView;
import android.widget.TextView;
-public class ActiveTabsPage extends LinearLayout {
+interface OnCloseTab {
+ void onCloseTab(int position);
+}
- private static final String LOGTAG = "TabPicker";
+public class ActiveTabsPage extends LinearLayout implements OnClickListener,
+ OnItemClickListener, OnCloseTab {
- private final LayoutInflater mFactory;
- private final UiController mUiController;
- private final TabControl mControl;
- private final TabsListAdapter mAdapter;
- private final ListView mListView;
+ private Context mContext;
+ private UiController mController;
+ private TabControl mTabControl;
+ private View mNewTab, mNewIncognitoTab;
+ private TabAdapter mAdapter;
+ private AbsListView mTabsList;
- public ActiveTabsPage(Context context, UiController control) {
+ public ActiveTabsPage(Context context, UiController controller) {
super(context);
- mUiController = control;
- mControl = control.getTabControl();
- mFactory = LayoutInflater.from(context);
- mFactory.inflate(R.layout.active_tabs, this);
- mListView = (ListView) findViewById(R.id.list);
- mAdapter = new TabsListAdapter();
- mListView.setAdapter(mAdapter);
- mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- public void onItemClick(AdapterView<?> parent, View view,
- int position, long id) {
- if (mControl.canCreateNewTab()) {
- position -= 2;
- }
- boolean needToAttach = false;
- if (position == -2) {
- // Create a new tab
- mUiController.openTabToHomePage();
- } else if (position == -1) {
- // Create a new incognito tab
- mUiController.openIncognitoTab();
- } else {
- // Open the corresponding tab
- // If the tab is the current one, switchToTab will
- // do nothing and return, so we need to make sure
- // it gets attached back to its mContentView in
- // removeActiveTabPage
- needToAttach = !mUiController.switchToTab(position);
- }
- mUiController.removeActiveTabsPage(needToAttach);
- }
- });
+ mContext = context;
+ mController = controller;
+ mTabControl = mController.getTabControl();
+ setOrientation(VERTICAL);
+ setBackgroundResource(R.drawable.bg_browser);
+ LayoutInflater inflate = LayoutInflater.from(mContext);
+ inflate.inflate(R.layout.active_tabs, this, true);
+ mNewTab = findViewById(R.id.new_tab);
+ mNewIncognitoTab = findViewById(R.id.new_incognito_tab);
+ mNewTab.setOnClickListener(this);
+ mNewIncognitoTab.setOnClickListener(this);
+ int visibility = mTabControl.canCreateNewTab() ? View.VISIBLE : View.GONE;
+ mNewTab.setVisibility(visibility);
+ mNewIncognitoTab.setVisibility(visibility);
+ mTabsList = (AbsListView) findViewById(android.R.id.list);
+ mAdapter = new TabAdapter(mContext, mTabControl);
+ mAdapter.setOnCloseListener(this);
+ mTabsList.setAdapter(mAdapter);
+ mTabsList.setOnItemClickListener(this);
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v == mNewTab) {
+ mController.openTabToHomePage();
+ } else if (v == mNewIncognitoTab) {
+ mController.openIncognitoTab();
+ }
+ mController.removeActiveTabsPage(false);
+ }
+
+ @Override
+ public void onItemClick(
+ AdapterView<?> parent, View view, int position, long id) {
+ boolean needToAttach = !mController.switchToTab(position);
+ mController.removeActiveTabsPage(needToAttach);
+ }
+
+ @Override
+ public void onCloseTab(int position) {
+ Tab tab = mTabControl.getTab(position);
+ if (tab != null) {
+ mController.closeTab(tab);
+ if (mTabControl.getTabCount() == 0) {
+ mController.openTabToHomePage();
+ mController.removeActiveTabsPage(false);
+ } else {
+ mAdapter.notifyDataSetChanged();
+ }
+ }
}
/**
@@ -81,7 +105,7 @@ public class ActiveTabsPage extends LinearLayout {
* the parent to be pressed without being pressed itself. This way the line
* of a tab can be pressed, but the close button itself is not.
*/
- private static class CloseHolder extends ImageView {
+ public static class CloseHolder extends ImageView {
public CloseHolder(Context context, AttributeSet attrs) {
super(context, attrs);
}
@@ -96,118 +120,72 @@ public class ActiveTabsPage extends LinearLayout {
}
}
- private class TabsListAdapter extends BaseAdapter {
- private boolean mNotified = true;
- private int mReturnedCount;
- private Handler mHandler = new Handler();
+ static class TabAdapter extends BaseAdapter implements OnClickListener {
- public int getCount() {
- int count = mControl.getTabCount();
- if (mControl.canCreateNewTab()) {
- count += 2;
- }
- // XXX: This is a workaround to be more like a real adapter. Most
- // adapters call notifyDataSetChanged() whenever the internal data
- // has changed. Since TabControl is our internal data, we don't
- // know when that changes.
- //
- // Keep track of the last count we returned and whether we called
- // notifyDataSetChanged(). If we did not initiate a data set
- // change, and the count is different, send the notify and return
- // the old count.
- if (!mNotified && count != mReturnedCount) {
- notifyChange();
- return mReturnedCount;
- }
- mReturnedCount = count;
- mNotified = false;
- return count;
- }
- public Object getItem(int position) {
- return null;
- }
- public long getItemId(int position) {
- return position;
- }
- public int getViewTypeCount() {
- return 2;
+ LayoutInflater mInflater;
+ OnCloseTab mCloseListener;
+ TabControl mTabControl;
+
+ TabAdapter(Context context, TabControl tabs) {
+ mInflater = LayoutInflater.from(context);
+ mTabControl = tabs;
}
- public int getItemViewType(int position) {
- if (mControl.canCreateNewTab()) {
- position -= 2;
- }
- // Do not recycle the "add new tab" item.
- return position < 0 ? IGNORE_ITEM_VIEW_TYPE : 1;
+
+ void setOnCloseListener(OnCloseTab listener) {
+ mCloseListener = listener;
}
- public View getView(int position, View convertView, ViewGroup parent) {
- final int tabCount = mControl.getTabCount();
- if (mControl.canCreateNewTab()) {
- position -= 2;
+
+ @Override
+ public View getView(int position, View view, ViewGroup parent) {
+ if (view == null) {
+ view = mInflater.inflate(R.layout.tab_view, parent, false);
}
+ ImageView favicon = (ImageView) view.findViewById(R.id.favicon);
+ TextView title = (TextView) view.findViewById(R.id.title);
+ TextView url = (TextView) view.findViewById(R.id.url);
+ Tab tab = getItem(position);
- if (convertView == null) {
- if (position == -2) {
- convertView = mFactory.inflate(R.layout.tab_view_add_tab, null);
- } else if (position == -1) {
- convertView = mFactory.inflate(R.layout.tab_view_add_incognito_tab, null);
+ title.setText(tab.getTitle());
+ url.setText(tab.getUrl());
+ Bitmap faviconBitmap = tab.getFavicon();
+ if (tab.isPrivateBrowsingEnabled()) {
+ favicon.setImageResource(R.drawable.ic_incognito_holo_dark);
+ favicon.setBackgroundDrawable(null);
+ } else {
+ if (faviconBitmap == null) {
+ favicon.setImageResource(R.drawable.app_web_browser_sm);
} else {
- convertView = mFactory.inflate(R.layout.tab_view, null);
+ favicon.setImageBitmap(faviconBitmap);
}
+ favicon.setBackgroundResource(R.drawable.bookmark_list_favicon_bg);
}
+ View close = view.findViewById(R.id.close);
+ close.setTag(position);
+ close.setOnClickListener(this);
+ return view;
+ }
- if (position >= 0) {
- 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);
- Tab tab = mControl.getTab(position);
- if (tab.getWebView() == null) {
- // This means that populatePickerData will have to use the
- // saved state.
- Log.w(LOGTAG, "Tab " + position + " has a null WebView and "
- + (tab.getSavedState() == null ? "null" : "non-null")
- + " saved state ");
- }
- if (tab.getTitle() == null || tab.getTitle().length() == 0) {
- Log.w(LOGTAG, "Tab " + position + " has no title. "
- + "Check above in the Logs to see whether it has a "
- + "null WebView or null WebHistoryItem");
- }
- title.setText(tab.getTitle());
- url.setText(tab.getUrl());
- 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) {
- mUiController.closeTab(
- mControl.getTab(closePosition));
- if (tabCount == 1) {
- mUiController.openTabToHomePage();
- mUiController.removeActiveTabsPage(false);
- } else {
- mNotified = true;
- notifyDataSetChanged();
- }
- }
- });
+ @Override
+ public void onClick(View v) {
+ int position = (Integer) v.getTag();
+ if (mCloseListener != null) {
+ mCloseListener.onCloseTab(position);
}
- return convertView;
}
- void notifyChange() {
- mHandler.post(new Runnable() {
- public void run() {
- mNotified = true;
- notifyDataSetChanged();
- }
- });
+ @Override
+ public int getCount() {
+ return mTabControl.getTabCount();
+ }
+
+ @Override
+ public Tab getItem(int position) {
+ return mTabControl.getTab(position);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position;
}
}
}
diff --git a/src/com/android/browser/BrowserBookmarksAdapter.java b/src/com/android/browser/BrowserBookmarksAdapter.java
index 9e71077..201079c 100644
--- a/src/com/android/browser/BrowserBookmarksAdapter.java
+++ b/src/com/android/browser/BrowserBookmarksAdapter.java
@@ -20,7 +20,6 @@ import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
-import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -31,7 +30,6 @@ import android.widget.TextView;
class BrowserBookmarksAdapter extends CursorAdapter {
LayoutInflater mInflater;
int mCurrentView;
- Drawable mFaviconBackground;
/**
* Create a new BrowserBookmarksAdapter.
@@ -42,8 +40,6 @@ class BrowserBookmarksAdapter extends CursorAdapter {
super(context, null, 0);
mInflater = LayoutInflater.from(context);
selectView(defaultView);
- float density = context.getResources().getDisplayMetrics().density;
- mFaviconBackground = BookmarkUtils.createListFaviconBackground(context);
}
@Override
@@ -101,9 +97,7 @@ class BrowserBookmarksAdapter extends CursorAdapter {
} else {
favicon.setImageBitmap(faviconBitmap);
}
- //favicon.setBackgroundResource(R.drawable.bookmark_list_favicon_bg);
- // TODO: Switch to above instead of below once b/3353813 is fixed
- favicon.setBackgroundDrawable(mFaviconBackground);
+ favicon.setBackgroundResource(R.drawable.bookmark_list_favicon_bg);
}
}