Update the manifest to mark the activity as the default.
This was needed during testing and threw an exception without it. Not sure how
Derek got around not having it before.
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index cee3573..b23f113 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -186,6 +186,7 @@
<activity android:name="android.webkit.PluginActivity">
<intent-filter>
<action android:name="android.intent.webkit.PLUGIN" />
+ <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
diff --git a/res/layout/custom_screen.xml b/res/layout/custom_screen.xml
index f654a84..d1f1658 100644
--- a/res/layout/custom_screen.xml
+++ b/res/layout/custom_screen.xml
@@ -24,11 +24,6 @@
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
- <com.android.browser.TitleBarSet android:id="@+id/title_bar"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:background="@drawable/tab_unselected"
- />
<LinearLayout android:id="@+id/error_console"
android:layout_width="fill_parent"
diff --git a/res/layout/title_bar.xml b/res/layout/title_bar.xml
index 3cc25ac..7245a9b 100644
--- a/res/layout/title_bar.xml
+++ b/res/layout/title_bar.xml
@@ -1,96 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2009 The Android Open Source Project
+<!--
+ Copyright 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
+ 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
+ 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.
+ 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:fitsSystemWindows="true"
- android:orientation="horizontal"
+ android:id="@+id/search_plate"
android:layout_width="fill_parent"
- android:background="@drawable/tab_selected"
- android:layout_height="45dip">
- <ImageView android:id="@+id/favicon"
- android:layout_height="20dip"
- android:layout_width="20dip"
- android:layout_marginLeft="6dip"
- android:layout_marginRight="6dip"
- android:layout_gravity="center_vertical"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:paddingLeft="12dip"
+ android:paddingRight="12dip"
+ android:paddingTop="0dip"
+ android:paddingBottom="16dip"
+ android:background="@*android:drawable/search_plate_global" >
+
+ <ProgressBar android:id="@+id/progress_horizontal"
+ style="?android:attr/progressBarStyleHorizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="5dip"
+ android:max="100"
/>
- <!-- layout which contains the title, progress bar, and url -->
+
<LinearLayout
- android:orientation="vertical"
- android:layout_width="0dip"
- android:layout_weight="1"
- android:layout_height="wrap_content">
- <!-- This part contains the favicon and the progress bar -->
- <LinearLayout
- android:orientation="vertical"
- android:layout_marginTop="0dip"
- android:layout_height="wrap_content"
- android:layout_width="fill_parent"
- >
- <!-- need to make this no wider than the horizontal progress bar -->
- <TextView android:id="@+id/title"
- android:layout_height="wrap_content"
- android:layout_width="wrap_content"
- android:layout_marginLeft="6dip"
- android:layout_marginTop="0dip"
- android:textSize="14dip"
- android:textColor="@color/white"
- android:textStyle="bold"
- android:singleLine="true"
- android:padding="0dip"
- />
- <LinearLayout
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- <TextView android:id="@+id/url"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="6dip"
- android:textSize="11dip"
- android:padding="0dip"
- android:textColor="@color/white"
- android:singleLine="true"
- />
- <ProgressBar android:id="@+id/progress_circular"
- style="?android:attr/progressBarStyleSmallTitle"
- android:layout_marginLeft="3dip"
- android:layout_gravity="center_vertical"
- android:max="100"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
- <ImageView android:id="@+id/lock_icon"
- android:layout_height="wrap_content"
- android:layout_width="wrap_content"
- android:layout_alignBottom="@id/title"
- android:layout_alignParentRight="true"
- android:visibility="gone"/>
- </LinearLayout>
- <ProgressBar android:id="@+id/progress_horizontal"
- style="?android:attr/progressBarStyleHorizontal"
- android:layout_width="fill_parent"
- android:layout_weight="1"
- android:layout_height="5dip"
- android:max="100" />
- </LinearLayout>
- </LinearLayout>
- <!-- This buttons will change look/functionality -->
- <ImageView android:id="@+id/rt_button"
- android:layout_width="52dip"
+ android:id="@+id/search_edit_frame"
+ android:layout_width="fill_parent"
android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:src="@drawable/ic_close_tab"/>
+ android:layout_marginTop="3dip"
+ android:orientation="horizontal">
+
+ <TextView
+ android:id="@+id/title"
+ android:background="@*android:drawable/textfield_search"
+ android:layout_height="40dip"
+ android:layout_width="0dip"
+ android:layout_weight="1.0"
+ android:paddingLeft="8dip"
+ android:paddingRight="6dip"
+ android:singleLine="true"
+ android:ellipsize="end"
+ />
+ <ProgressBar android:id="@+id/progress_circular"
+ style="?android:attr/progressBarStyleSmallTitle"
+ android:layout_width="40dip"
+ android:layout_height="40dip"
+ android:layout_marginLeft="3dip"
+ android:max="100"
+ />
+ <ImageView
+ android:id="@+id/rt_btn"
+ android:layout_width="40dip"
+ android:layout_height="40dip"
+ android:layout_marginLeft="8dip"
+ android:scaleType="fitXY"
+ android:background="@*android:drawable/btn_search_dialog_voice"
+ android:src="@drawable/ic_menu_bookmark"
+ />
+ </LinearLayout>
</LinearLayout>
diff --git a/res/menu/browser.xml b/res/menu/browser.xml
index c2f80d6..e7478f0 100644
--- a/res/menu/browser.xml
+++ b/res/menu/browser.xml
@@ -16,23 +16,22 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:id="@+id/MAIN_MENU">
- <item android:id="@+id/goto_menu_id"
- android:title="@string/goto_dot"
- android:alphabeticShortcut="l"
- android:icon="@android:drawable/ic_menu_search"/>
<item android:id="@+id/stop_reload_menu_id"
android:alphabeticShortcut="r" />
- <item android:id="@+id/add_bookmark_menu_id"
- android:title="@string/save_to_bookmarks"
- android:icon="@drawable/ic_menu_bookmark" />
- <item android:id="@+id/back_menu_id"
- android:title="@string/back"
- android:drawable="@*android:drawable/ic_menu_back"
- android:alphabeticShortcut="j" />
+ <item android:id="@+id/new_tab_menu_id"
+ android:title="@string/new_tab"
+ android:icon="@drawable/ic_add_tab" />
+ <item android:id="@+id/close_menu_id"
+ android:icon="@drawable/ic_btn_close_panel"
+ android:title="@string/tab_picker_remove_tab"
+ android:alphabeticShortcut="w" />
<item android:id="@+id/forward_menu_id"
android:title="@string/forward"
android:alphabeticShortcut="k"
android:icon="@*android:drawable/ic_menu_forward" />
+ <item android:id="@+id/add_bookmark_menu_id"
+ android:title="@string/save_to_bookmarks"
+ android:icon="@drawable/ic_menu_bookmark" />
<item android:id="@+id/find_menu_id"
android:title="@string/find_dot"
android:alphabeticShortcut="f" />
@@ -55,8 +54,6 @@
android:visible="false" />
</group>
<group android:id="@+id/MAIN_SHORTCUT_MENU" android:visible="false">
- <item android:id="@+id/close_menu_id"
- android:alphabeticShortcut="w" />
<item android:id="@+id/homepage_menu_id"
android:alphabeticShortcut=" " />
<item android:id="@+id/classic_history_menu_id"
@@ -81,15 +78,23 @@
android:alphabeticShortcut="7" />
<item android:id="@+id/window_eight_menu_id"
android:alphabeticShortcut="8" />
+ <item android:id="@+id/back_menu_id"
+ android:title="@string/back"
+ android:drawable="@*android:drawable/ic_menu_back"
+ android:alphabeticShortcut="j" />
+ <item android:id="@+id/goto_menu_id"
+ android:title="@string/goto_dot"
+ android:alphabeticShortcut="l"
+ android:icon="@android:drawable/ic_menu_search"/>
</group>
<!-- these items are toggled in and out of @+id/stop_reload_menu_id -->
<item android:id="@+id/stop_menu_id"
- android:title="@string/stop"
+ android:title="@string/stop"
android:icon="@*android:drawable/ic_menu_stop"
android:visible="false" />
<item android:id="@+id/reload_menu_id"
- android:title="@string/reload"
- android:icon="@*android:drawable/ic_menu_refresh"
+ android:title="@string/reload"
+ android:icon="@*android:drawable/ic_menu_refresh"
android:visible="false" />
</menu>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index c0d1429..b224517 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -18,6 +18,8 @@
<!-- The name of the application. -->
<string name="application_name">Browser</string>
+ <!-- Name of menu item of a new tab. Also used in the title bar when displaying a new tab -->
+ <string name="new_tab">New tab</string>
<!-- Name of tab containing bookmarks -->
<string name="tab_bookmarks">Bookmarks</string>
<!-- Name of tab containing the user's most visited websites, organized by number of visits -->
diff --git a/src/com/android/browser/AddBookmarkPage.java b/src/com/android/browser/AddBookmarkPage.java
index 87638d8..2575857 100644
--- a/src/com/android/browser/AddBookmarkPage.java
+++ b/src/com/android/browser/AddBookmarkPage.java
@@ -124,7 +124,7 @@
}
String url = unfilteredUrl;
if (!(url.startsWith("about:") || url.startsWith("data:") || url
- .startsWith("file:"))) {
+ .startsWith("file:") || url.startsWith("content:"))) {
WebAddress address;
try {
address = new WebAddress(unfilteredUrl);
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java
index 3f0569a..3706167 100644
--- a/src/com/android/browser/BrowserActivity.java
+++ b/src/com/android/browser/BrowserActivity.java
@@ -336,7 +336,6 @@
// holds everything else.
FrameLayout browserFrameLayout = (FrameLayout) LayoutInflater.from(this)
.inflate(R.layout.custom_screen, null);
- mTitleBar = (TitleBarSet) browserFrameLayout.findViewById(R.id.title_bar);
mContentView = (FrameLayout) browserFrameLayout.findViewById(
R.id.main_content);
mErrorConsoleContainer = (LinearLayout) browserFrameLayout.findViewById(
@@ -344,6 +343,7 @@
mCustomViewContainer = (FrameLayout) browserFrameLayout
.findViewById(R.id.fullscreen_custom_content);
frameLayout.addView(browserFrameLayout, COVER_SCREEN_PARAMS);
+ mTitleBar = new TitleBarSet(this);
} else {
mCustomViewContainer = new FrameLayout(this);
mCustomViewContainer.setBackgroundColor(Color.BLACK);
@@ -496,13 +496,13 @@
}
if (CUSTOM_BROWSER_BAR) {
+ mTitleBar.init(this);
// Create title bars for all of the tabs that have been created
for (int i = 0; i < mTabControl.getTabCount(); i ++) {
WebView view = mTabControl.getTab(i).getWebView();
mTitleBar.addTab(view, false);
}
- mTitleBar.setBrowserActivity(this);
mTitleBar.setCurrentTab(mTabControl.getCurrentIndex());
}
@@ -891,6 +891,12 @@
}
}
+ @Override
+ public boolean onMenuOpened(int featureId, Menu menu) {
+ mTitleBar.setVisibility(View.VISIBLE);
+ return true;
+ }
+
/**
* onSaveInstanceState(Bundle map)
* onSaveInstanceState is called right before onStop(). The map contains
@@ -1237,8 +1243,6 @@
attachTabToContentView(tab);
if (CUSTOM_BROWSER_BAR) {
mTitleBar.setCurrentTab(index);
- WebView view = tab.getWebView();
- view.slideIntoFocus();
}
return true;
}
@@ -1293,6 +1297,11 @@
}
switch (item.getItemId()) {
// -- Main menu
+ case R.id.new_tab_menu_id:
+ openTabAndShow(EMPTY_URL_DATA, false, null);
+ bookmarksOrHistoryPicker(false, true);
+ break;
+
case R.id.goto_menu_id:
bookmarksOrHistoryPicker(false, false);
break;
@@ -1463,6 +1472,9 @@
menu.findItem(R.id.forward_menu_id)
.setEnabled(canGoForward);
+ menu.findItem(R.id.new_tab_menu_id).setEnabled(
+ mTabControl.getTabCount() < TabControl.MAX_TABS);
+
// decide whether to show the share link option
PackageManager pm = getPackageManager();
Intent send = new Intent(Intent.ACTION_SEND);
@@ -1610,6 +1622,8 @@
ViewGroup.LayoutParams.WRAP_CONTENT));
}
+ WebView view = t.getWebView();
+ view.addTitleBar(mTitleBar);
// Attach the sub window if necessary
attachSubWindow(t);
// Request focus on the top window.
@@ -1636,6 +1650,9 @@
mErrorConsoleContainer.removeView(mTabControl.getCurrentErrorConsole(false));
}
+ WebView view = t.getWebView();
+ view.addTitleBar(null);
+
// Remove the sub window if it exists.
if (t.getSubWebView() != null) {
mContentView.removeView(t.getSubWebViewContainer());
@@ -1971,6 +1988,10 @@
closeTab(current);
} else {
if (current.closeOnExit()) {
+ // force mPageStarted to be false as we are going to either
+ // finish the activity or remove the tab. This will ensure
+ // pauseWebView() taking action.
+ mPageStarted = false;
if (mTabControl.getTabCount() == 1) {
finish();
return;
@@ -2300,9 +2321,6 @@
CookieSyncManager.getInstance().resetSync();
mInLoad = true;
- if (CUSTOM_BROWSER_BAR) {
- mTitleBar.setVisibility(View.VISIBLE);
- }
updateInLoadMenuItems();
if (!mIsNetworkUp) {
if ( mAlertDialog == null) {
@@ -2601,7 +2619,7 @@
}
}
ErrorDialog errDialog = new ErrorDialog(
- err == EventHandler.FILE_NOT_FOUND_ERROR ?
+ err == WebViewClient.ERROR_FILE_NOT_FOUND ?
R.string.browserFrameFileErrorLabel :
R.string.browserFrameNetworkErrorLabel,
desc, err);
@@ -2630,11 +2648,11 @@
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
- if (errorCode != EventHandler.ERROR_LOOKUP &&
- errorCode != EventHandler.ERROR_CONNECT &&
- errorCode != EventHandler.ERROR_BAD_URL &&
- errorCode != EventHandler.ERROR_UNSUPPORTED_SCHEME &&
- errorCode != EventHandler.FILE_ERROR) {
+ if (errorCode != WebViewClient.ERROR_HOST_LOOKUP &&
+ errorCode != WebViewClient.ERROR_CONNECT &&
+ errorCode != WebViewClient.ERROR_BAD_URL &&
+ errorCode != WebViewClient.ERROR_UNSUPPORTED_SCHEME &&
+ errorCode != WebViewClient.ERROR_FILE) {
queueError(errorCode, description);
}
Log.e(LOGTAG, "onReceivedError " + errorCode + " " + failingUrl
@@ -2859,27 +2877,6 @@
}
@Override
- public void onChangeViewingMode(WebView view, int newViewingMode) {
- if (!CUSTOM_BROWSER_BAR || view != getTopWindow()) {
- return;
- }
- switch (newViewingMode) {
- case WebView.NO_VIEWING_MODE:
- break;
- case WebView.OVERVIEW_MODE:
- case WebView.READING_MODE_WITH_TITLE_BAR:
- case WebView.TITLE_BAR_DISMISS_MODE:
- mTitleBar.setVisibility(View.VISIBLE);
- break;
- case WebView.READING_MODE:
- mTitleBar.setVisibility(View.GONE);
- break;
- default:
- break;
- }
- }
-
- @Override
public boolean onCreateWindow(WebView view, final boolean dialog,
final boolean userGesture, final Message resultMsg) {
// Short-circuit if we can't create any more tabs or sub windows.
diff --git a/src/com/android/browser/TitleBar.java b/src/com/android/browser/TitleBar.java
index 1d53e8d..f03e2da 100644
--- a/src/com/android/browser/TitleBar.java
+++ b/src/com/android/browser/TitleBar.java
@@ -34,32 +34,42 @@
*/
public class TitleBar extends LinearLayout {
private TextView mTitle;
- private TextView mUrl;
private Drawable mCloseDrawable;
private ImageView mRtButton;
private ProgressBar mCircularProgress;
private ProgressBar mHorizontalProgress;
- private ImageView mFavicon;
- private ImageView mLockIcon; // FIXME: Needs to be below the favicon
+ private Drawable mFavicon;
+ private Drawable mLockIcon;
+ private Drawable mStopDrawable;
+ private Drawable mBookmarkDrawable;
private boolean mInLoad;
- private boolean mTitleSet;
private WebView mWebView;
+ private BrowserActivity mBrowserActivity;
- public TitleBar(Context context, WebView webview) {
+ public TitleBar(Context context, WebView webview, BrowserActivity ba) {
super(context, null);
LayoutInflater factory = LayoutInflater.from(context);
factory.inflate(R.layout.title_bar, this);
+ mBrowserActivity = ba;
mTitle = (TextView) findViewById(R.id.title);
- mUrl = (TextView) findViewById(R.id.url);
+ mTitle.setCompoundDrawablePadding(5);
- mRtButton = (ImageView) findViewById(R.id.rt_button);
-
+ mRtButton = (ImageView) findViewById(R.id.rt_btn);
+ mRtButton.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ if (mInLoad) {
+ if (mWebView != null) {
+ mWebView.stopLoading();
+ }
+ } else {
+ mBrowserActivity.bookmarksOrHistoryPicker(false, false);
+ }
+ }
+ });
mCircularProgress = (ProgressBar) findViewById(R.id.progress_circular);
mHorizontalProgress = (ProgressBar) findViewById(
R.id.progress_horizontal);
- mFavicon = (ImageView) findViewById(R.id.favicon);
- mLockIcon = (ImageView) findViewById(R.id.lock_icon);
mWebView = webview;
}
@@ -71,15 +81,6 @@
}
/**
- * Determine whether a point (from a touch) hits the right button.
- */
- /* package */ boolean hitRightButton(int x, int y) {
- Rect hitRect = new Rect();
- mRtButton.getHitRect(hitRect);
- return hitRect.contains(x - getLeft(), y - getTop());
- }
-
- /**
* Return whether the associated WebView is currently loading. Needed to
* determine whether a click should stop the load or close the tab.
*/
@@ -91,19 +92,22 @@
* Set a new Drawable for the Favicon.
*/
/* package */ void setFavicon(Drawable d) {
- mFavicon.setImageDrawable(d);
+ if (d != null) {
+ d.setBounds(0, 0, 20, 20);
+ }
+ mTitle.setCompoundDrawables(d, null, mLockIcon, null);
+ mFavicon = d;
}
/**
* Set the Drawable for the lock icon, or null to hide it.
*/
/* package */ void setLock(Drawable d) {
- if (d == null) {
- mLockIcon.setVisibility(View.GONE);
- } else {
- mLockIcon.setImageDrawable(d);
- mLockIcon.setVisibility(View.VISIBLE);
+ if (d != null) {
+ d.setBounds(0, 0, 20, 20);
}
+ mTitle.setCompoundDrawables(mFavicon, null, d, null);
+ mLockIcon = d;
}
/**
@@ -113,31 +117,25 @@
if (newProgress == mCircularProgress.getMax()) {
mCircularProgress.setVisibility(View.GONE);
mHorizontalProgress.setVisibility(View.GONE);
- mRtButton.setVisibility(View.VISIBLE);
- mUrl.setVisibility(View.VISIBLE);
- if (mCloseDrawable != null) {
- mRtButton.setImageDrawable(mCloseDrawable);
+ if (mBookmarkDrawable != null) {
+ mRtButton.setImageDrawable(mBookmarkDrawable);
}
mInLoad = false;
- if (!mTitleSet) {
- mTitle.setText(mUrl.getText());
- mUrl.setText(null);
- mTitleSet = true;
- }
} else {
mCircularProgress.setProgress(newProgress);
mHorizontalProgress.setProgress(newProgress);
mCircularProgress.setVisibility(View.VISIBLE);
mHorizontalProgress.setVisibility(View.VISIBLE);
- mUrl.setVisibility(View.VISIBLE);
- if (mCloseDrawable == null) {
- // The drawable was assigned in the xml file, so it already
- // exists. Keep a pointer to it when we switch to the resource
- // so we can easily switch back.
- mCloseDrawable = mRtButton.getDrawable();
+ if (mBookmarkDrawable == null) {
+ mBookmarkDrawable = mRtButton.getDrawable();
}
- mRtButton.setImageResource(
- com.android.internal.R.drawable.ic_menu_stop);
+ if (mStopDrawable == null) {
+ mRtButton.setImageResource(
+ com.android.internal.R.drawable.ic_menu_stop);
+ mStopDrawable = mRtButton.getDrawable();
+ } else {
+ mRtButton.setImageDrawable(mStopDrawable);
+ }
mInLoad = true;
}
}
@@ -146,26 +144,11 @@
* Update the title and url.
*/
/* package */ void setTitleAndUrl(CharSequence title, CharSequence url) {
- if (url != null) {
- url = BrowserActivity.buildTitleUrl(url.toString());
- }
- if (null == title) {
- if (mInLoad) {
- mTitleSet = false;
- mTitle.setText(R.string.title_bar_loading);
- } else {
- // If the page has no title, put the url in the title space
- // and leave the url blank.
- mTitle.setText(url);
- mUrl.setText(null);
- mTitleSet = true;
- return;
- }
+ if (url == null) {
+ mTitle.setText(R.string.title_bar_loading);
} else {
- mTitle.setText(title);
- mTitleSet = true;
+ mTitle.setText(url.toString());
}
- mUrl.setText(url);
}
/* package */ void setToTabPicker() {
@@ -174,6 +157,5 @@
setLock(null);
mCircularProgress.setVisibility(View.GONE);
mHorizontalProgress.setVisibility(View.GONE);
- mUrl.setVisibility(View.INVISIBLE);
}
}
diff --git a/src/com/android/browser/TitleBarSet.java b/src/com/android/browser/TitleBarSet.java
index d26f0af..873f40b 100644
--- a/src/com/android/browser/TitleBarSet.java
+++ b/src/com/android/browser/TitleBarSet.java
@@ -39,7 +39,6 @@
implements AdapterView.OnItemSelectedListener {
private Vector<TitleBar> mTitleBars;
private BrowserActivity mBrowserActivity;
- private View mNewButton;
private int mCount;
private TitleAdapter mTitleAdapter;
private boolean mIgnoreSelectedListener;
@@ -53,9 +52,6 @@
super(context, attrs);
mTitleBars = new Vector<TitleBar>(TabControl.MAX_TABS);
mCount = 0;
- // Now create the Plus button that goes on the right.
- LayoutInflater factory = LayoutInflater.from(context);
- mNewButton = factory.inflate(R.layout.new_window_button, null);
mTitleAdapter = new TitleAdapter();
setAdapter(mTitleAdapter);
setCallbackDuringFling(false);
@@ -76,12 +72,9 @@
return;
}
int newSelection = mCount;
- TitleBar titleBar = new TitleBar(getContext(), view);
+ TitleBar titleBar = new TitleBar(getContext(), view, mBrowserActivity);
mTitleBars.add(titleBar);
mCount++;
- if (TabControl.MAX_TABS == mCount) {
- mNewButton.setEnabled(false);
- }
// Need to refresh our list
setAdapter(mTitleAdapter);
mIgnoreSelectedListener = true;
@@ -167,7 +160,6 @@
*/
public boolean performItemClick(View view, int position, long id) {
if (!(view instanceof TitleBar)) {
- // For new window button
return super.performItemClick(view, position, id);
}
// If we have no mLastTouchUp, this was not called from onSingleTapUp,
@@ -181,21 +173,7 @@
if (titleBar != getTitleBarAt(position)) {
return false;
}
- if (titleBar.hitRightButton((int) mLastTouchUp.getX() - mScrollX,
- (int) mLastTouchUp.getY() - mScrollY)) {
- if (titleBar.isInLoad()) {
- WebView webView = titleBar.getWebView();
- if (null == webView) {
- // FIXME: How did we get into this situation?
- return false;
- }
- webView.stopLoading();
- } else {
- mBrowserActivity.closeCurrentWindow();
- }
- } else {
- mBrowserActivity.bookmarksOrHistoryPicker(false, false);
- }
+ mBrowserActivity.onSearchRequested();
return true;
}
@@ -203,13 +181,12 @@
* Remove the tab at the given position.
*/
/* package */ void removeTab(int position) {
- if (TabControl.MAX_TABS == mCount) {
- mNewButton.setEnabled(true);
- }
+ int selection = getSelectedItemPosition();
mTitleBars.remove(position);
mCount--;
// Need to refresh our list
setAdapter(mTitleAdapter);
+ setCurrentTab(selection);
}
/**
@@ -221,23 +198,17 @@
/**
* Set the owning BrowserActivity. Necessary so that we can call methods
- * on it.
+ * on it. Only called once before adding any title bars.
*/
- /* package */ void setBrowserActivity(final BrowserActivity ba) {
+ /* package */ void init(final BrowserActivity ba) {
mBrowserActivity = ba;
- View.OnClickListener listener = new View.OnClickListener() {
- public void onClick(View v) {
- ba.openTabAndShow(BrowserActivity.EMPTY_URL_DATA, false, null);
- ba.bookmarksOrHistoryPicker(false, true);
- }
- };
- mNewButton.findViewById(R.id.button).setOnClickListener(listener);
}
/**
* Change to the tab at the new position.
*/
/* package */ void setCurrentTab(int position) {
+ if (position < 0 || position >= mCount) return;
mIgnoreSelectedListener = true;
setSelection(position);
mIgnoreSelectedListener = false;
@@ -319,8 +290,7 @@
public void registerDataSetObserver(DataSetObserver observer) {}
public void unregisterDataSetObserver(DataSetObserver observer) {}
public int getCount() {
- // To account for new window
- return mCount + 1;
+ return mCount;
}
public Object getItem(int position) {
return null;
@@ -332,13 +302,9 @@
return true;
}
public View getView(int position, View convertView, ViewGroup parent) {
- if (mCount == position) {
- return mNewButton;
- }
TitleBar titleBar = getTitleBarAt(position);
Gallery.LayoutParams lp;
- int desiredWidth = TitleBarSet.this.getWidth()
- - (2 * mNewButton.getWidth());
+ int desiredWidth = TitleBarSet.this.getWidth();
ViewGroup.LayoutParams old = titleBar.getLayoutParams();
if (old == null || !(old instanceof Gallery.LayoutParams)) {
lp = new Gallery.LayoutParams(desiredWidth,