Phone UI title bar work

 Updated progress bar to holo and below URL bar
 Removed spinner
 Swapped stop/bookmark with new assets
 Wired up bookmark listener to change star state

Change-Id: Ie91ae446cc1c429ce4a1662cc337202aaf7877c3
diff --git a/res/layout/title_bar.xml b/res/layout/title_bar.xml
index f6d519f..99ac04d 100644
--- a/res/layout/title_bar.xml
+++ b/res/layout/title_bar.xml
@@ -18,25 +18,17 @@
 <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="8dip"
-    android:paddingRight="12dip"
-    android:paddingTop="2dip"
-    android:paddingBottom="1dip"
-    android:background="@drawable/bg_urlbar" >
-
-    <ProgressBar android:id="@+id/progress_horizontal"
-        style="?android:attr/progressBarStyleHorizontal"
-        android:layout_width="match_parent"
-        android:layout_height="5dip"
-        android:layout_marginLeft="1dip"
-        android:max="100"
-        />
+    android:orientation="vertical" >
 
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
+        android:background="@drawable/bg_urlbar"
+        android:paddingLeft="4dip"
+        android:paddingRight="4dip"
+        android:paddingTop="2dip"
+        android:paddingBottom="1dip"
         >
 
         <LinearLayout android:id="@+id/title_bg"
@@ -51,12 +43,11 @@
                 <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:layout_marginLeft="3dip"
                     android:visibility="gone"
                     />
                 <com.android.browser.UrlInputView
@@ -81,24 +72,27 @@
         </LinearLayout>
         <ImageButton
             android:id="@+id/stop"
-            android:background="@drawable/stop_background"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
-            android:layout_marginBottom="4dip"
-            android:src="@drawable/ic_btn_stop_v2"
+            style="@style/HoloButton"
+            android:src="@drawable/ic_stop_holo_dark"
             android:visibility="gone"
         />
         <ImageButton
             android:id="@+id/bookmark"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
-            android:layout_marginLeft="-2dip"
-            android:layout_marginTop="-6.5dip"
-            android:layout_marginBottom="-2dip"
-            android:layout_marginRight="-5dip"
-            android:scaleType="center"
-            android:background="@drawable/btn_bookmark"
-            android:src="@drawable/ic_bookmark_on_holo_dark"
+            style="@style/HoloButton"
+            android:src="@drawable/btn_imageview_star"
         />
     </LinearLayout>
+
+    <com.android.browser.PageProgressView
+        android:id="@+id/progress_horizontal"
+        android:layout_width="match_parent"
+        android:layout_height="22dip"
+        android:background="@null"
+        android:src="@drawable/progress"
+        android:layout_marginTop="-11dip"
+        android:visibility="gone" />
 </LinearLayout>
diff --git a/res/layout/url_bar.xml b/res/layout/url_bar.xml
index 2998677..4d8efdd 100644
--- a/res/layout/url_bar.xml
+++ b/res/layout/url_bar.xml
@@ -12,7 +12,6 @@
     -->
 <LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/content"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:orientation="vertical">
diff --git a/src/com/android/browser/BaseUi.java b/src/com/android/browser/BaseUi.java
index 9bce3cd..6e8f603 100644
--- a/src/com/android/browser/BaseUi.java
+++ b/src/com/android/browser/BaseUi.java
@@ -193,7 +193,10 @@
 
     @Override
     public void bookmarkedStatusHasChanged(Tab tab) {
-        // no op in base case
+        if (tab.inForeground()) {
+            boolean isBookmark = tab.isBookmarkedSite();
+            getTitleBar().setCurrentUrlIsBookmark(isBookmark);
+        }
     }
 
     @Override
diff --git a/src/com/android/browser/TitleBar.java b/src/com/android/browser/TitleBar.java
index 56db187..686416c 100644
--- a/src/com/android/browser/TitleBar.java
+++ b/src/com/android/browser/TitleBar.java
@@ -21,15 +21,12 @@
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 import android.content.res.Resources;
-import android.graphics.drawable.Animatable;
 import android.graphics.drawable.Drawable;
 import android.speech.RecognizerIntent;
 import android.text.SpannableString;
 import android.text.Spanned;
 import android.text.TextUtils;
 import android.text.style.ImageSpan;
-import android.util.DisplayMetrics;
-import android.util.TypedValue;
 import android.view.ContextMenu;
 import android.view.LayoutInflater;
 import android.view.MenuInflater;
@@ -38,7 +35,6 @@
 import android.view.View.OnFocusChangeListener;
 import android.widget.ImageButton;
 import android.widget.ImageView;
-import android.widget.ProgressBar;
 
 /**
  * This class represents a title bar for a particular "tab" or "window" in the
@@ -49,19 +45,13 @@
 
     private Activity mActivity;
     private ImageButton mBookmarkButton;
-    private Drawable mCircularProgress;
-    private ProgressBar mHorizontalProgress;
+    private PageProgressView mHorizontalProgress;
     private ImageButton mStopButton;
     private Drawable mBookmarkDrawable;
     private Drawable mVoiceDrawable;
     private boolean mInLoad;
-    private View mTitleBg;
     private Intent mVoiceSearchIntent;
-    private Drawable mVoiceModeBackground;
-    private Drawable mNormalBackground;
     private ImageSpan mArcsSpan;
-    private int mLeftMargin;
-    private int mRightMargin;
 
     public TitleBar(Activity activity, UiController controller, PhoneUi ui) {
         super(activity, controller, ui);
@@ -77,7 +67,6 @@
         mUrlInput.setUrlInputListener(this);
         mUrlInput.setOnFocusChangeListener(this);
 
-        mTitleBg = findViewById(R.id.title_bg);
         mLockIcon = (ImageView) findViewById(R.id.lock);
         mFavicon = (ImageView) findViewById(R.id.favicon);
         mStopButton = (ImageButton) findViewById(R.id.stop);
@@ -85,18 +74,7 @@
         mStopButton.setOnClickListener(this);
         mBookmarkButton.setOnClickListener(this);
 
-        Resources resources = activity.getResources();
-        mCircularProgress = resources.getDrawable(
-                com.android.internal.R.drawable.search_spinner);
-        DisplayMetrics metrics = resources.getDisplayMetrics();
-        mLeftMargin = (int) TypedValue.applyDimension(
-                TypedValue.COMPLEX_UNIT_DIP, 8f, metrics);
-        mRightMargin = (int) TypedValue.applyDimension(
-                TypedValue.COMPLEX_UNIT_DIP, 6f, metrics);
-        int iconDimension = (int) TypedValue.applyDimension(
-                TypedValue.COMPLEX_UNIT_DIP, 20f, metrics);
-        mCircularProgress.setBounds(0, 0, iconDimension, iconDimension);
-        mHorizontalProgress = (ProgressBar) findViewById(
+        mHorizontalProgress = (PageProgressView) findViewById(
                 R.id.progress_horizontal);
         mVoiceSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
         mVoiceSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
@@ -110,6 +88,7 @@
         PackageManager pm = activity.getPackageManager();
         ResolveInfo ri = pm.resolveActivity(mVoiceSearchIntent,
                 PackageManager.MATCH_DEFAULT_ONLY);
+        Resources resources = getResources();
         if (ri == null) {
             mVoiceSearchIntent = null;
         } else {
@@ -117,9 +96,6 @@
                     android.R.drawable.ic_btn_speak_now);
         }
         mBookmarkDrawable = mBookmarkButton.getDrawable();
-        mVoiceModeBackground = resources.getDrawable(
-                R.drawable.title_voice);
-        mNormalBackground = mTitleBg.getBackground();
         mArcsSpan = new ImageSpan(activity, R.drawable.arcs,
                 ImageSpan.ALIGN_BASELINE);
     }
@@ -142,13 +118,9 @@
         Drawable titleDrawable;
         if (mInVoiceMode) {
             mBookmarkButton.setImageDrawable(mVoiceDrawable);
-            titleDrawable = mVoiceModeBackground;
             mUrlInput.setEllipsize(null);
             mBookmarkButton.setVisibility(View.VISIBLE);
             mStopButton.setVisibility(View.GONE);
-            mTitleBg.setBackgroundDrawable(titleDrawable);
-            mTitleBg.setPadding(mLeftMargin, mTitleBg.getPaddingTop(),
-                    mRightMargin, mTitleBg.getPaddingBottom());
         } else {
             if (mInLoad) {
                 mBookmarkButton.setVisibility(View.GONE);
@@ -159,7 +131,6 @@
                 mBookmarkButton.setImageDrawable(mBookmarkDrawable);
             }
             mUrlInput.setEllipsize(TextUtils.TruncateAt.END);
-            mTitleBg.setPadding(mLeftMargin, 0, mRightMargin, 0);
         }
         mUrlInput.setSingleLine(!mInVoiceMode);
     }
@@ -169,31 +140,20 @@
      */
     @Override
     void setProgress(int newProgress) {
-        if (newProgress >= mHorizontalProgress.getMax()) {
-            mUrlInput.setCompoundDrawables(null, null, null, null);
-            ((Animatable) mCircularProgress).stop();
-            mHorizontalProgress.setVisibility(View.INVISIBLE);
+        if (newProgress >= PROGRESS_MAX) {
+            mHorizontalProgress.setVisibility(View.GONE);
             if (!mInVoiceMode) {
                 mBookmarkButton.setImageDrawable(mBookmarkDrawable);
                 mBookmarkButton.setVisibility(View.VISIBLE);
                 mStopButton.setVisibility(View.GONE);
-                mTitleBg.setBackgroundDrawable(mNormalBackground);
-                mTitleBg.setPadding(mLeftMargin, 0, mRightMargin, 0);
             }
             mInLoad = false;
         } 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)
-                mUrlInput.setCompoundDrawables(null, null, mCircularProgress,
-                        null);
-                ((Animatable) mCircularProgress).start();
+            mHorizontalProgress.setProgress(newProgress * PageProgressView.MAX_PROGRESS
+                    / PROGRESS_MAX);
+            if (!mInLoad) {
                 mHorizontalProgress.setVisibility(View.VISIBLE);
                 if (!mInVoiceMode) {
-                    mTitleBg.setPadding(mLeftMargin, 0, mRightMargin, 0);
                     mBookmarkButton.setVisibility(View.GONE);
                     mStopButton.setVisibility(View.VISIBLE);
                 }
@@ -243,4 +203,9 @@
                     true);
         }
     }
+
+    @Override
+    public void setCurrentUrlIsBookmark(boolean isBookmark) {
+        mBookmarkButton.setActivated(isBookmark);
+    }
 }
diff --git a/src/com/android/browser/TitleBarBase.java b/src/com/android/browser/TitleBarBase.java
index f62e0e4..2b64aa3 100644
--- a/src/com/android/browser/TitleBarBase.java
+++ b/src/com/android/browser/TitleBarBase.java
@@ -39,6 +39,9 @@
  * Base class for a title bar used by the browser.
  */
 public class TitleBarBase extends LinearLayout implements UrlInputListener {
+
+    protected static final int PROGRESS_MAX = 100;
+
     // These need to be set by the subclass.
     protected ImageView mFavicon;
     protected ImageView mLockIcon;
@@ -168,4 +171,7 @@
         }
     }
 
+    public void setCurrentUrlIsBookmark(boolean isBookmark) {
+    }
+
 }
diff --git a/src/com/android/browser/TitleBarXLarge.java b/src/com/android/browser/TitleBarXLarge.java
index 3931526..c732da8 100644
--- a/src/com/android/browser/TitleBarXLarge.java
+++ b/src/com/android/browser/TitleBarXLarge.java
@@ -48,8 +48,6 @@
         implements OnClickListener, OnFocusChangeListener,
     TextWatcher {
 
-    private static final int PROGRESS_MAX = 100;
-
     private XLargeUi mUi;
 
     private Drawable mStopDrawable;
@@ -210,6 +208,7 @@
         mUrlInput.clearNeedsUpdate();
     }
 
+    @Override
     public void setCurrentUrlIsBookmark(boolean isBookmark) {
         mStar.setActivated(isBookmark);
     }
diff --git a/src/com/android/browser/XLargeUi.java b/src/com/android/browser/XLargeUi.java
index f361e57..90e3683 100644
--- a/src/com/android/browser/XLargeUi.java
+++ b/src/com/android/browser/XLargeUi.java
@@ -161,14 +161,6 @@
     // WebView callbacks
 
     @Override
-    public void bookmarkedStatusHasChanged(Tab tab) {
-        if (tab.inForeground()) {
-            boolean isBookmark = tab.isBookmarkedSite();
-            mTitleBar.setCurrentUrlIsBookmark(isBookmark);
-        }
-    }
-
-    @Override
     public void onProgressChanged(Tab tab) {
         int progress = tab.getLoadProgress();
         mTabBar.onProgress(tab, progress);