Initial work on new browser bar

Bug 2712871

Change-Id: Id1c76b05a5f126a4a68369a32dda8975fc1d2e6b
diff --git a/res/drawable/browserbarbutton.xml b/res/drawable/browserbarbutton.xml
new file mode 100644
index 0000000..35a6f48
--- /dev/null
+++ b/res/drawable/browserbarbutton.xml
@@ -0,0 +1,21 @@
+<?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.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:state_pressed="true"
+            android:drawable="@drawable/button_selected" />
+    <item android:state_pressed="false" android:drawable="@drawable/clear" />
+</selector>
diff --git a/res/drawable/button_selected.png b/res/drawable/button_selected.png
new file mode 100644
index 0000000..4fd1aa3
--- /dev/null
+++ b/res/drawable/button_selected.png
Binary files differ
diff --git a/res/drawable/clear.xml b/res/drawable/clear.xml
new file mode 100644
index 0000000..5973f5c
--- /dev/null
+++ b/res/drawable/clear.xml
@@ -0,0 +1,23 @@
+<?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.
+-->
+
+<!-- Used by browserbarbutton to show a clear background for the non pressed
+        state -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+    <solid android:color="#00000000"/>
+    <padding android:left="9dp" android:top="9dp"
+        android:right="9dp" android:bottom="9dp" />
+</shape>
diff --git a/res/drawable/ic_arrow_left.png b/res/drawable/ic_arrow_left.png
new file mode 100644
index 0000000..58fd2ca
--- /dev/null
+++ b/res/drawable/ic_arrow_left.png
Binary files differ
diff --git a/res/drawable/ic_arrow_right.png b/res/drawable/ic_arrow_right.png
new file mode 100644
index 0000000..aaf3fde
--- /dev/null
+++ b/res/drawable/ic_arrow_right.png
Binary files differ
diff --git a/res/drawable/ic_menu.png b/res/drawable/ic_menu.png
new file mode 100644
index 0000000..520b2c3
--- /dev/null
+++ b/res/drawable/ic_menu.png
Binary files differ
diff --git a/res/drawable/ic_pages.png b/res/drawable/ic_pages.png
new file mode 100644
index 0000000..fba4651
--- /dev/null
+++ b/res/drawable/ic_pages.png
Binary files differ
diff --git a/res/drawable/ic_reload.png b/res/drawable/ic_reload.png
new file mode 100644
index 0000000..ec0c238
--- /dev/null
+++ b/res/drawable/ic_reload.png
Binary files differ
diff --git a/res/drawable/ic_star.png b/res/drawable/ic_star.png
new file mode 100644
index 0000000..20a40de
--- /dev/null
+++ b/res/drawable/ic_star.png
Binary files differ
diff --git a/res/drawable/ic_stop.png b/res/drawable/ic_stop.png
new file mode 100644
index 0000000..7ee56e9
--- /dev/null
+++ b/res/drawable/ic_stop.png
Binary files differ
diff --git a/res/drawable/textfield_stroke.xml b/res/drawable/textfield_stroke.xml
new file mode 100644
index 0000000..4d4c74e
--- /dev/null
+++ b/res/drawable/textfield_stroke.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.
+-->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+    <solid android:color="#ffffffff"/>
+    <stroke android:width="3dp" android:color="#ff94b73f"/>
+    <padding android:left="9dp" android:top="9dp"
+        android:right="9dp" android:bottom="9dp" />
+</shape>
diff --git a/res/layout/title_bar_xlarge.xml b/res/layout/title_bar_xlarge.xml
new file mode 100644
index 0000000..c5a44f8
--- /dev/null
+++ b/res/layout/title_bar_xlarge.xml
@@ -0,0 +1,118 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+   Copyright 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:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:orientation="vertical"
+    android:paddingLeft="6dip"
+    android:paddingRight="6dip"
+    android:background="#ffdddddd" >
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal"
+        >
+        <ImageButton android:id="@+id/back"
+            android:src="@drawable/ic_arrow_left"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:layout_marginRight="6dip"
+            android:background="@drawable/browserbarbutton"
+            />
+        <ImageButton android:id="@+id/forward"
+            android:src="@drawable/ic_arrow_right"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:layout_marginRight="6dip"
+            android:background="@drawable/browserbarbutton"
+            />
+        <ImageButton android:id="@+id/star"
+            android:src="@drawable/ic_star"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:layout_marginRight="6dip"
+            android:background="@drawable/browserbarbutton"
+            />
+
+        <LinearLayout android:id="@+id/title_bg"
+            android:background="@drawable/textfield_stroke"
+            android:layout_width="0dip"
+            android:layout_weight="1.0"
+            android:layout_height="wrap_content"
+            android:layout_marginRight="6dip"
+            android:gravity="center_vertical"
+            android:orientation="horizontal"
+            >
+                <ImageView android:id="@+id/favicon"
+                    android:layout_width="20dip"
+                    android:layout_height="20dip"
+                    android:layout_marginLeft="3dip"
+                    />
+                <ImageView android:id="@+id/lock"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_marginLeft="6dip"
+                    android:visibility="gone"
+                    />
+                <TextView
+                    android:id="@+id/title"
+                    android:layout_height="wrap_content"
+                    android:layout_width="0dip"
+                    android:layout_weight="1.0"
+                    android:layout_marginLeft="3dip"
+                    android:textAppearance="?android:attr/textAppearanceMedium"
+                    android:textColor="@color/black"
+                    android:gravity="center_vertical"
+                    android:singleLine="true"
+                    android:ellipsize="end"
+                />
+        </LinearLayout>
+        <ImageButton android:id="@+id/stop"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:layout_marginRight="6dip"
+            android:src="@drawable/ic_stop"
+            android:background="@drawable/browserbarbutton"
+        />
+        <ImageButton android:id="@+id/menu"
+            android:src="@drawable/ic_menu"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:layout_marginRight="6dip"
+            android:background="@drawable/browserbarbutton"
+            />
+        <ImageButton
+            android:id="@+id/all_btn"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:scaleType="center"
+            android:background="@drawable/browserbarbutton"
+            android:src="@drawable/ic_pages"
+        />
+    </LinearLayout>
+
+    <!-- Should show translucent over the webpage -->
+    <ProgressBar android:id="@+id/progress_horizontal"
+        style="?android:attr/progressBarStyleHorizontal"
+        android:layout_width="match_parent"
+        android:layout_height="14dip"
+        android:max="100"
+        />
+
+</LinearLayout>
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java
index b2d7d82..e6982c9 100644
--- a/src/com/android/browser/BrowserActivity.java
+++ b/src/com/android/browser/BrowserActivity.java
@@ -220,17 +220,18 @@
         mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
                 .findViewById(R.id.fullscreen_custom_content);
         frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
-        mTitleBar = new TitleBar(this);
         mXLargeScreenSize = (getResources().getConfiguration().screenLayout
                 & Configuration.SCREENLAYOUT_SIZE_MASK)
                 == Configuration.SCREENLAYOUT_SIZE_XLARGE;
         if (mXLargeScreenSize) {
+            mTitleBar = new TitleBarXLarge(this);
             LinearLayout layout = (LinearLayout) mBrowserFrameLayout.
                     findViewById(R.id.vertical_layout);
             layout.addView(mTitleBar, 0, new LinearLayout.LayoutParams(
                     ViewGroup.LayoutParams.MATCH_PARENT,
                     ViewGroup.LayoutParams.WRAP_CONTENT));
         } else {
+            mTitleBar = new TitleBar(this);
             // mTitleBar will be always be shown in the fully loaded mode on
             // phone
             mTitleBar.setProgress(100);
@@ -1343,14 +1344,7 @@
                 break;
 
             case R.id.add_bookmark_menu_id:
-                Intent i = new Intent(BrowserActivity.this,
-                        AddBookmarkPage.class);
-                WebView w = getTopWindow();
-                i.putExtra("url", w.getUrl());
-                i.putExtra("title", w.getTitle());
-                i.putExtra("touch_icon_url", w.getTouchIconUrl());
-                i.putExtra("thumbnail", createScreenshot(w));
-                startActivity(i);
+                bookmarkCurrentPage();
                 break;
 
             case R.id.stop_reload_menu_id:
@@ -1490,6 +1484,17 @@
         return true;
     }
 
+    /* package */ void bookmarkCurrentPage() {
+        Intent i = new Intent(BrowserActivity.this,
+                AddBookmarkPage.class);
+        WebView w = getTopWindow();
+        i.putExtra("url", w.getUrl());
+        i.putExtra("title", w.getTitle());
+        i.putExtra("touch_icon_url", w.getTouchIconUrl());
+        i.putExtra("thumbnail", createScreenshot(w));
+        startActivity(i);
+    }
+
     /*
      * Remove the FindDialog.
      */
@@ -1588,7 +1593,7 @@
     @Override
     public void onCreateContextMenu(ContextMenu menu, View v,
             ContextMenuInfo menuInfo) {
-        if (v instanceof TitleBar) {
+        if (v instanceof TitleBarBase) {
             return;
         }
         WebView webview = (WebView) v;
@@ -4029,7 +4034,7 @@
 
     private Toast mStopToast;
 
-    private TitleBar mTitleBar;
+    private TitleBarBase mTitleBar;
 
     private LinearLayout mErrorConsoleContainer = null;
     private boolean mShouldShowErrorConsole = false;
diff --git a/src/com/android/browser/TitleBar.java b/src/com/android/browser/TitleBar.java
index dc4979b..4e76334 100644
--- a/src/com/android/browser/TitleBar.java
+++ b/src/com/android/browser/TitleBar.java
@@ -21,14 +21,8 @@
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.Color;
-import android.graphics.Rect;
 import android.graphics.drawable.Animatable;
-import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
-import android.graphics.drawable.LayerDrawable;
-import android.graphics.drawable.PaintDrawable;
 import android.os.Handler;
 import android.os.Message;
 import android.speech.RecognizerIntent;
@@ -45,7 +39,6 @@
 import android.view.View;
 import android.view.ViewConfiguration;
 import android.widget.ImageView;
-import android.widget.LinearLayout;
 import android.widget.ProgressBar;
 import android.widget.TextView;
 
@@ -55,21 +48,16 @@
  * This class represents a title bar for a particular "tab" or "window" in the
  * browser.
  */
-public class TitleBar extends LinearLayout {
+public class TitleBar extends TitleBarBase {
     private TextView        mTitle;
-    private Drawable        mCloseDrawable;
     private ImageView       mRtButton;
     private Drawable        mCircularProgress;
     private ProgressBar     mHorizontalProgress;
-    private ImageView       mFavicon;
-    private ImageView       mLockIcon;
     private ImageView       mStopButton;
     private Drawable        mBookmarkDrawable;
     private Drawable        mVoiceDrawable;
     private boolean         mInLoad;
     private BrowserActivity mBrowserActivity;
-    private Drawable        mGenericFavicon;
-    private int             mIconDimension;
     private View            mTitleBg;
     private MyHandler       mHandler;
     private Intent          mVoiceSearchIntent;
@@ -84,7 +72,7 @@
     private static int LONG_PRESS = 1;
 
     public TitleBar(BrowserActivity context) {
-        super(context, null);
+        super(context);
         mHandler = new MyHandler();
         LayoutInflater factory = LayoutInflater.from(context);
         factory.inflate(R.layout.title_bar, this);
@@ -107,13 +95,11 @@
                 TypedValue.COMPLEX_UNIT_DIP, 8f, metrics);
         mRightMargin = (int) TypedValue.applyDimension(
                 TypedValue.COMPLEX_UNIT_DIP, 6f, metrics);
-        mIconDimension = (int) TypedValue.applyDimension(
+        int iconDimension = (int) TypedValue.applyDimension(
                 TypedValue.COMPLEX_UNIT_DIP, 20f, metrics);
-        mCircularProgress.setBounds(0, 0, mIconDimension, mIconDimension);
+        mCircularProgress.setBounds(0, 0, iconDimension, iconDimension);
         mHorizontalProgress = (ProgressBar) findViewById(
                 R.id.progress_horizontal);
-        mGenericFavicon = context.getResources().getDrawable(
-                R.drawable.app_web_browser_sm);
         mVoiceSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
         mVoiceSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                 RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
@@ -248,25 +234,6 @@
     }
 
     /**
-     * Set a new Bitmap for the Favicon.
-     */
-    /* package */ void setFavicon(Bitmap icon) {
-        Drawable[] array = new Drawable[3];
-        array[0] = new PaintDrawable(Color.BLACK);
-        PaintDrawable p = new PaintDrawable(Color.WHITE);
-        array[1] = p;
-        if (icon == null) {
-            array[2] = mGenericFavicon;
-        } else {
-            array[2] = new BitmapDrawable(icon);
-        }
-        LayerDrawable d = new LayerDrawable(array);
-        d.setLayerInset(1, 1, 1, 1, 1);
-        d.setLayerInset(2, 2, 2, 2, 2);
-        mFavicon.setImageDrawable(d);
-    }
-
-    /**
      * Change the TitleBar to or from voice mode.  If there is no package to
      * handle voice search, the TitleBar cannot be set to voice mode.
      */
@@ -302,18 +269,6 @@
     }
 
     /**
-     * Set the Drawable for the lock icon, or null to hide it.
-     */
-    /* package */ void setLock(Drawable d) {
-        if (null == d) {
-            mLockIcon.setVisibility(View.GONE);
-        } else {
-            mLockIcon.setImageDrawable(d);
-            mLockIcon.setVisibility(View.VISIBLE);
-        }
-    }
-
-    /**
      * Update the progress, from 0 to 100.
      */
     /* package */ void setProgress(int newProgress) {
@@ -374,11 +329,4 @@
             }
         }
     }
-
-    /* package */ void setToTabPicker() {
-        mTitle.setText(R.string.tab_picker_title);
-        setFavicon(null);
-        setLock(null);
-        mHorizontalProgress.setVisibility(View.GONE);
-    }
 }
diff --git a/src/com/android/browser/TitleBarBase.java b/src/com/android/browser/TitleBarBase.java
new file mode 100644
index 0000000..3d234e8
--- /dev/null
+++ b/src/com/android/browser/TitleBarBase.java
@@ -0,0 +1,78 @@
+/*
+ * 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.
+ */
+
+package com.android.browser;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Color;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.LayerDrawable;
+import android.graphics.drawable.PaintDrawable;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+
+/**
+ * Base class for a title bar used by the browser.
+ */
+public class TitleBarBase extends LinearLayout {
+    // These need to be set by the subclass.
+    protected ImageView mFavicon;
+    protected ImageView mLockIcon;
+
+    private Drawable mGenericFavicon;
+
+    public TitleBarBase(Context context) {
+        super(context, null);
+        mGenericFavicon = context.getResources().getDrawable(
+                R.drawable.app_web_browser_sm);
+    }
+
+    /* package */ void setProgress(int newProgress) {}
+    /* package */ void setDisplayTitle(String title) {}
+
+    /* package */ void setLock(Drawable d) {
+        assert mLockIcon != null;
+        if (null == d) {
+            mLockIcon.setVisibility(View.GONE);
+        } else {
+            mLockIcon.setImageDrawable(d);
+            mLockIcon.setVisibility(View.VISIBLE);
+        }
+    }
+
+    /* package */ void setFavicon(Bitmap icon) {
+        assert mFavicon != null;
+        Drawable[] array = new Drawable[3];
+        array[0] = new PaintDrawable(Color.BLACK);
+        PaintDrawable p = new PaintDrawable(Color.WHITE);
+        array[1] = p;
+        if (icon == null) {
+            array[2] = mGenericFavicon;
+        } else {
+            array[2] = new BitmapDrawable(icon);
+        }
+        LayerDrawable d = new LayerDrawable(array);
+        d.setLayerInset(1, 1, 1, 1, 1);
+        d.setLayerInset(2, 2, 2, 2, 2);
+        mFavicon.setImageDrawable(d);
+    }
+
+    /* package */ void setInVoiceMode(boolean inVoiceMode) {}
+
+}
diff --git a/src/com/android/browser/TitleBarXLarge.java b/src/com/android/browser/TitleBarXLarge.java
new file mode 100644
index 0000000..5296ed1
--- /dev/null
+++ b/src/com/android/browser/TitleBarXLarge.java
@@ -0,0 +1,170 @@
+/*
+ * 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.
+ */
+
+package com.android.browser;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.drawable.Animatable;
+import android.graphics.drawable.Drawable;
+import android.util.DisplayMetrics;
+import android.util.TypedValue;
+import android.view.ContextMenu;
+import android.view.LayoutInflater;
+import android.view.MenuInflater;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.ProgressBar;
+import android.widget.TextView;
+
+import com.android.common.speech.LoggingEvents;
+
+/**
+ * This class represents a title bar for a particular "tab" or "window" in the
+ * browser.
+ */
+public class TitleBarXLarge extends TitleBarBase {
+    private Drawable        mCircularProgress;
+    private ProgressBar     mHorizontalProgress;
+    private Drawable        mStopDrawable;
+    private Drawable        mReloadDrawable;
+    private boolean         mInLoad;
+    private BrowserActivity mBrowserActivity;
+
+    private final View            mBackButton;
+    private final View            mForwardButton;
+    private final View            mStar;
+    private final View            mMenu;
+    private final ImageView       mStopButton;
+    private final TextView        mTitle;
+    private final View            mAllButton;
+
+    public TitleBarXLarge(BrowserActivity context) {
+        super(context);
+        Resources resources = context.getResources();
+        LayoutInflater factory = LayoutInflater.from(context);
+        factory.inflate(R.layout.title_bar_xlarge, this);
+        mBrowserActivity = context;
+
+        mTitle = (TextView) findViewById(R.id.title);
+        mTitle.setCompoundDrawablePadding(5);
+        mTitle.setLongClickable(true);
+
+        mLockIcon = (ImageView) findViewById(R.id.lock);
+        mFavicon = (ImageView) findViewById(R.id.favicon);
+        mStopButton = (ImageView) findViewById(R.id.stop);
+        mStopDrawable = mStopButton.getDrawable();
+        mReloadDrawable = resources.getDrawable(R.drawable.ic_reload);
+
+        mAllButton = (ImageView) findViewById(R.id.all_btn);
+        mCircularProgress = (Drawable) resources.getDrawable(
+                com.android.internal.R.drawable.search_spinner);
+        DisplayMetrics metrics = resources.getDisplayMetrics();
+        int iconDimension = (int) TypedValue.applyDimension(
+                TypedValue.COMPLEX_UNIT_DIP, 20f, metrics);
+        mCircularProgress.setBounds(0, 0, iconDimension, iconDimension);
+        mHorizontalProgress = (ProgressBar) findViewById(
+                R.id.progress_horizontal);
+
+        // FIXME: Change enabled states based on whether you can go
+        // back/forward.  Probably should be done inside onPageStarted.
+        mBackButton = findViewById(R.id.back);
+        mForwardButton = findViewById(R.id.forward);
+        mStar = findViewById(R.id.star);
+        mMenu = findViewById(R.id.menu);
+        View.OnClickListener listener = new View.OnClickListener() {
+                public void onClick(View v) {
+                    if (mBackButton == v) {
+                        mBrowserActivity.getTopWindow().goBack();
+                    } else if (mForwardButton == v) {
+                        mBrowserActivity.getTopWindow().goForward();
+                    } else if (mStar == v) {
+                        // FIXME: Show a menu with option to bookmark or
+                        // save to home page
+                        mBrowserActivity.bookmarkCurrentPage();
+                    } else if (mMenu == v) {
+                        mBrowserActivity.openOptionsMenu();
+                    } else if (mStopButton == v) {
+                        if (mInLoad) {
+                            mBrowserActivity.stopLoading();
+                        } else {
+                            mBrowserActivity.getTopWindow().reload();
+                        }
+                    } else if (mTitle == v) {
+                        mBrowserActivity.editUrl();
+                    } else if (mAllButton == v) {
+                        // FIXME: Show the new bookmarks/windows view.
+                        mBrowserActivity.bookmarksOrHistoryPicker(false);
+                    }
+                }
+        };
+        mBackButton.setOnClickListener(listener);
+        mForwardButton.setOnClickListener(listener);
+        mStar.setOnClickListener(listener);
+        mStopButton.setOnClickListener(listener);
+        mTitle.setOnClickListener(listener);
+        mAllButton.setOnClickListener(listener);
+        mMenu.setOnClickListener(listener);
+    }
+
+    @Override
+    public void createContextMenu(ContextMenu menu) {
+        MenuInflater inflater = mBrowserActivity.getMenuInflater();
+        inflater.inflate(R.menu.title_context, menu);
+        mBrowserActivity.onCreateContextMenu(menu, this, null);
+    }
+
+    /**
+     * Update the progress, from 0 to 100.
+     */
+    /* package */ void setProgress(int newProgress) {
+        if (newProgress >= mHorizontalProgress.getMax()) {
+            mTitle.setCompoundDrawables(null, null, null, null);
+            ((Animatable) mCircularProgress).stop();
+            mHorizontalProgress.setVisibility(View.GONE);
+            mInLoad = false;
+            mStopButton.setImageDrawable(mReloadDrawable);
+        } else {
+            mHorizontalProgress.setProgress(newProgress);
+            if (!mInLoad && getWindowToken() != null) {
+                // checking the window token lets us be sure that we
+                // are attached to a window before starting the animation,
+                // preventing a potential race condition
+                // (fix for bug http://b/2115736)
+                mTitle.setCompoundDrawables(null, null, mCircularProgress,
+                        null);
+                ((Animatable) mCircularProgress).start();
+                mHorizontalProgress.setVisibility(View.VISIBLE);
+                mInLoad = true;
+                mStopButton.setImageDrawable(mStopDrawable);
+            }
+        }
+    }
+
+    /**
+     * Update the text displayed in the title bar.
+     * @param title String to display.  If null, the loading string will be
+     *      shown.
+     */
+    /* package */ void setDisplayTitle(String title) {
+        if (title == null) {
+            mTitle.setText(R.string.title_bar_loading);
+        } else {
+            mTitle.setText(title);
+        }
+    }
+
+}