checkpoint for moving UI to Holo style
  mostly final assets
  dialogs are not styled correctly

Change-Id: Ib98312ca9465ded3efc2743f9828fe9a815814cc
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java
index 7890485..e6cb473 100644
--- a/src/com/android/browser/BrowserActivity.java
+++ b/src/com/android/browser/BrowserActivity.java
@@ -23,6 +23,7 @@
 import android.app.ActionBar;
 import android.app.Activity;
 import android.app.AlertDialog;
+import android.app.Dialog;
 import android.app.ProgressDialog;
 import android.app.SearchManager;
 import android.content.ActivityNotFoundException;
@@ -105,6 +106,7 @@
 import android.widget.EditText;
 import android.widget.FrameLayout;
 import android.widget.LinearLayout;
+import android.widget.PopupMenu;
 import android.widget.TextView;
 import android.widget.Toast;
 
@@ -126,7 +128,8 @@
 import java.util.regex.Pattern;
 
 public class BrowserActivity extends Activity
-    implements View.OnCreateContextMenuListener, DownloadListener {
+    implements View.OnCreateContextMenuListener, DownloadListener,
+    PopupMenu.OnMenuItemClickListener {
 
     /* Define some aliases to make these debugging flags easier to refer to.
      * This file imports android.provider.Browser, so we can't just refer to "Browser.DEBUG".
@@ -226,6 +229,8 @@
             mTitleBar.setProgress(100);
             mFakeTitleBar = new TitleBarXLarge(this);
             ActionBar actionBar = getActionBar();
+            actionBar.setBackgroundDrawable(getResources().
+                    getDrawable(R.drawable.tabbar_bg));
             mTabBar = new TabBar(this, mTabControl, (TitleBarXLarge) mFakeTitleBar);
             actionBar.setCustomNavigationMode(mTabBar);
             // disable built in zoom controls
@@ -3869,45 +3874,70 @@
 
     }
 
-    /* package*/ void promptAddOrInstallBookmark() {
+    /* package */ void promptAddOrInstallBookmark(View anchor) {
+        PopupMenu popup = new PopupMenu(this, anchor);
+        popup.getMenuInflater().inflate(R.menu.bookmark_shortcut, popup.getMenu());
+        popup.setOnMenuItemClickListener(this);
+        popup.show();
+    }
+    
+    /**
+     * popup menu item click listener
+     * @param item
+     */
+    public boolean onMenuItemClick(MenuItem item) {
+        switch(item.getItemId()) {
+            case R.id.add_bookmark_menu_id:
+                bookmarkCurrentPage();
+                return true;
+            case R.id.shortcut_to_home_menu_id:
+                Tab current = mTabControl.getCurrentTab();
+                current.populatePickerData();
+                String touchIconUrl = mTabControl.getCurrentWebView().getTouchIconUrl();
+                if (touchIconUrl != null) {
+                    // Download the touch icon for this site then save
+                    // it to the
+                    // homescreen.
+                    Bundle b = new Bundle();
+                    b.putString("url", current.getUrl());
+                    b.putString("title", current.getTitle());
+                    b.putParcelable("favicon", current.getFavicon());
+                    Message msg = mHandler.obtainMessage(TOUCH_ICON_DOWNLOADED);
+                    msg.setData(b);
+                    new DownloadTouchIcon(BrowserActivity.this, msg,
+                            mTabControl.getCurrentWebView().getSettings().getUserAgentString())
+                            .execute(touchIconUrl);
+                } else {
+                    // add to homescreen, can do it immediately as there
+                    // is no touch
+                    // icon.
+                    showSaveToHomescreenDialog(
+                            current.getUrl(), current.getTitle(), null, current.getFavicon());
+                }
+                return true;
+            default:
+                return false;
+        }
+    }
+    
+    /* package */Dialog makeAddOrInstallDialog() {
         final Tab current = mTabControl.getCurrentTab();
         Resources resources = getResources();
-        CharSequence[] choices = {
-                resources.getString(R.string.save_to_bookmarks),
-                resources.getString(R.string.create_shortcut_bookmark)
-        };
+        CharSequence[] choices =
+                {resources.getString(R.string.save_to_bookmarks),
+                        resources.getString(R.string.create_shortcut_bookmark)};
 
         AlertDialog.Builder builder = new AlertDialog.Builder(this);
         builder.setTitle(R.string.add_new_bookmark);
         builder.setItems(choices, new DialogInterface.OnClickListener() {
-                public void onClick(DialogInterface dialog, int item) {
-                    if (item == 0) {
-                        bookmarkCurrentPage();
-                    } else if (item == 1) {
-                        current.populatePickerData();
-                        String touchIconUrl = mTabControl.getCurrentWebView().getTouchIconUrl();
-                        if (touchIconUrl != null) {
-                            // Download the touch icon for this site then save it to the
-                            // homescreen.
-                            Bundle b = new Bundle();
-                            b.putString("url", current.getUrl());
-                            b.putString("title", current.getTitle());
-                            b.putParcelable("favicon", current.getFavicon());
-                            Message msg = mHandler.obtainMessage(TOUCH_ICON_DOWNLOADED);
-                            msg.setData(b);
-                            new DownloadTouchIcon(BrowserActivity.this, msg,
-                                    mTabControl.getCurrentWebView().getSettings()
-                                    .getUserAgentString()).execute(touchIconUrl);
-                        } else {
-                            // add to homescreen, can do it immediately as there is no touch
-                            // icon.
-                            showSaveToHomescreenDialog(current.getUrl(), current.getTitle(),
-                                    null, current.getFavicon());
-                        }
-                     }
-                 }
+            public void onClick(DialogInterface dialog, int item) {
+                if (item == 0) {
+                    bookmarkCurrentPage();
+                } else if (item == 1) {
+                }
+            }
         });
-        builder.create().show();
+        return builder.create();
     }
 
     /**
diff --git a/src/com/android/browser/PageProgressView.java b/src/com/android/browser/PageProgressView.java
new file mode 100644
index 0000000..183566a
--- /dev/null
+++ b/src/com/android/browser/PageProgressView.java
@@ -0,0 +1,94 @@
+
+/*
+ * 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.Canvas;
+import android.graphics.Rect;
+import android.graphics.drawable.Drawable;
+import android.util.AttributeSet;
+import android.widget.ImageView;
+
+/**
+ *
+ */
+public class PageProgressView extends ImageView {
+
+    private int mProgress;
+    private int mMaxProgress;
+    private Rect mBounds;
+
+    /**
+     * @param context
+     * @param attrs
+     * @param defStyle
+     */
+    public PageProgressView(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+        init(context);
+    }
+
+    /**
+     * @param context
+     * @param attrs
+     */
+    public PageProgressView(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        init(context);
+    }
+
+    /**
+     * @param context
+     */
+    public PageProgressView(Context context) {
+        super(context);
+        init(context);
+    }
+
+    private void init(Context ctx) {
+        mMaxProgress = 10000;
+        mBounds = new Rect(0,0,0,0);
+        mProgress = 0;
+    }
+
+    @Override
+    public void onLayout(boolean f, int l, int t, int r, int b) {
+        mBounds.left = 0;
+        mBounds.right = (r - l) * mProgress / mMaxProgress;
+        mBounds.top = 0;
+        mBounds.bottom = b-t;
+    }
+
+    void setMaxProgress(int max) {
+        mMaxProgress = max;
+    }
+
+    void setProgress(int progress) {
+        mProgress = progress;
+        mBounds.right = getWidth()*mProgress/mMaxProgress;
+        invalidate();
+    }
+
+    @Override
+    public void onDraw(Canvas canvas) {
+//        super.onDraw(canvas);
+        Drawable d = getDrawable();
+        d.setBounds(mBounds);
+        d.draw(canvas);
+    }
+
+}
diff --git a/src/com/android/browser/TabBar.java b/src/com/android/browser/TabBar.java
index 3d8a44f..cf0f27c 100644
--- a/src/com/android/browser/TabBar.java
+++ b/src/com/android/browser/TabBar.java
@@ -55,13 +55,9 @@
     private final int mTabWidthSelected;
     private final int mTabWidthUnselected;
 
-    private final Drawable mShowUrlDrawable;
-    private final Drawable mHideUrlDrawable;
-
     private TitleBarXLarge mTitleBar;
 
     private TabScrollView mTabs;
-    private ImageButton mShowUrlButton;
     private TabControl mControl;
 
     private Map<Tab, TabViewData> mTabMap;
@@ -76,8 +72,6 @@
         Resources res = context.getResources();
         mTabWidthSelected = (int) res.getDimension(R.dimen.tab_width_selected);
         mTabWidthUnselected = (int) res.getDimension(R.dimen.tab_width_unselected);
-        mShowUrlDrawable = res.getDrawable(R.drawable.ic_menu_showurl);
-        mHideUrlDrawable = res.getDrawable(R.drawable.ic_menu_hideurl);
 
         mTitleBar = titlebar;
         mTitleBar.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
@@ -90,13 +84,10 @@
         LayoutInflater factory = LayoutInflater.from(context);
         factory.inflate(R.layout.tab_bar, this);
         mTabs = (TabScrollView) findViewById(R.id.tabs);
-        mShowUrlButton = (ImageButton) findViewById(R.id.showurl);
 
         // TODO: Change enabled states based on whether you can go
         // back/forward.  Probably should be done inside onPageStarted.
 
-        mShowUrlButton.setOnClickListener(this);
-
         // build tabs
         int tabcount = mControl.getTabCount();
         for (int i = 0; i < tabcount; i++) {
@@ -113,15 +104,7 @@
     }
 
     public void onClick(View view) {
-        if (mShowUrlButton == view) {
-            if (mShowUrlMode) {
-                showUrlBar();
-            } else if (!isLoading()) {
-                ScrollWebView swv = (ScrollWebView) mControl.getCurrentWebView();
-                swv.hideEmbeddedTitleBar();
-                mBrowserActivity.hideFakeTitleBar();
-            }
-        } else if (mTabs.getSelectedTab() == view) {
+        if (mTabs.getSelectedTab() == view) {
             if (mBrowserActivity.isFakeTitleBarShowing() && !isLoading()) {
                 mBrowserActivity.hideFakeTitleBar();
             } else {
@@ -145,8 +128,6 @@
 
     private void setShowUrlMode(boolean showUrl) {
         mShowUrlMode = showUrl;
-        Drawable newDrawable = mShowUrlMode ? mShowUrlDrawable : mHideUrlDrawable;
-        mShowUrlButton.setImageDrawable(newDrawable);
     }
 
     // callback after fake titlebar is shown
@@ -272,7 +253,10 @@
         public void setSelected(boolean selected) {
             mSelected = selected;
             mClose.setVisibility(mSelected ? View.VISIBLE : View.GONE);
-            mTitle.setTextColor(mSelected ? Color.BLACK : Color.GRAY);
+            mTitle.setTextAppearance(mBrowserActivity, mSelected ?
+                    R.style.TabTitleSelected : R.style.TabTitleUnselected);
+            setHorizontalFadingEdgeEnabled(!mSelected);
+            setFadingEdgeLength(50);
             super.setSelected(selected);
             setLayoutParams(new LayoutParams(selected ?
                     mTabWidthSelected : mTabWidthUnselected,
diff --git a/src/com/android/browser/TitleBar.java b/src/com/android/browser/TitleBar.java
index f45025d..bbb55ad 100644
--- a/src/com/android/browser/TitleBar.java
+++ b/src/com/android/browser/TitleBar.java
@@ -205,7 +205,7 @@
                     } else if (mInLoad) {
                         mBrowserActivity.stopLoading();
                     } else {
-                        mBrowserActivity.promptAddOrInstallBookmark();
+                        mBrowserActivity.promptAddOrInstallBookmark(button);
                     }
                     button.setPressed(false);
                 } else if (mTitleBg.isPressed()) {
diff --git a/src/com/android/browser/TitleBarXLarge.java b/src/com/android/browser/TitleBarXLarge.java
index a7957ab..e305c07 100644
--- a/src/com/android/browser/TitleBarXLarge.java
+++ b/src/com/android/browser/TitleBarXLarge.java
@@ -16,42 +16,51 @@
 
 package com.android.browser;
 
+import com.android.browser.UrlInputView.UrlInputListener;
+
+import android.app.AlertDialog;
 import android.app.SearchManager;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
+import android.graphics.Color;
 import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.os.Message;
 import android.view.ContextMenu;
 import android.view.LayoutInflater;
 import android.view.MenuInflater;
 import android.view.View;
 import android.view.View.OnClickListener;
+import android.view.View.OnFocusChangeListener;
 import android.widget.ImageView;
 
-import com.android.browser.UrlInputView.UrlInputListener;
-
 /**
  * tabbed title bar for xlarge screen browser
  */
 public class TitleBarXLarge extends TitleBarBase
-    implements UrlInputListener, OnClickListener {
+    implements UrlInputListener, OnClickListener, OnFocusChangeListener {
 
     private static final int PROGRESS_MAX = 100;
 
     private BrowserActivity mBrowserActivity;
     private Drawable mStopDrawable;
     private Drawable mReloadDrawable;
-    private Drawable mProgressDrawable;
+    private Drawable mFocusDrawable;
+    private Drawable mUnFocusDrawable;
+
 
     private View mContainer;
     private View mBackButton;
     private View mForwardButton;
     private View mStar;
     private View mSearchButton;
+    private View mInputContainer;
     private ImageView mStopButton;
     private View mAllButton;
-    private ImageView mProgressView;
+    private PageProgressView mProgressView;
     private UrlInputView mUrlView;
     private boolean mInLoad;
 
@@ -59,13 +68,14 @@
         super(context);
         mBrowserActivity = context;
         Resources resources = context.getResources();
-        mStopDrawable = resources.getDrawable(R.drawable.ic_stop);
-        mReloadDrawable = resources.getDrawable(R.drawable.ic_reload);
+        mStopDrawable = resources.getDrawable(R.drawable.ic_stop_normal);
+        mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_normal);
+        mFocusDrawable = resources.getDrawable(R.drawable.text_field_results);
+        mUnFocusDrawable = resources.getDrawable(R.drawable.text_field);
         rebuildLayout(context, true);
     }
 
     private void rebuildLayout(Context context, boolean rebuildData) {
-        removeAllViews();
         LayoutInflater factory = LayoutInflater.from(context);
         factory.inflate(R.layout.url_bar, this);
 
@@ -80,8 +90,8 @@
         mStopButton = (ImageView) findViewById(R.id.stop);
         mSearchButton = findViewById(R.id.search);
         mLockIcon = (ImageView) findViewById(R.id.lock);
-        mProgressView = (ImageView) findViewById(R.id.progress);
-        mProgressDrawable = mProgressView.getDrawable();
+        mProgressView = (PageProgressView) findViewById(R.id.progress);
+        mInputContainer = findViewById(R.id.urlbar);
 
         mBackButton.setOnClickListener(this);
         mForwardButton.setOnClickListener(this);
@@ -90,6 +100,15 @@
         mStopButton.setOnClickListener(this);
         mSearchButton.setOnClickListener(this);
         mUrlView.setUrlInputListener(this);
+        mUrlView.setOnFocusChangeListener(this);
+        mInputContainer.setBackgroundDrawable(mUnFocusDrawable);
+        mUrlView.setTextColor(Color.GRAY);
+
+    }
+    
+    public void onFocusChange(View v, boolean hasFocus) {
+        mInputContainer.setBackgroundDrawable(hasFocus ? mFocusDrawable : mUnFocusDrawable);
+        mUrlView.setTextColor(hasFocus ? Color.BLACK : Color.GRAY);
     }
 
     @Override
@@ -99,7 +118,7 @@
         } else if (mForwardButton == v) {
             mBrowserActivity.getTopWindow().goForward();
         } else if (mStar == v) {
-            mBrowserActivity.promptAddOrInstallBookmark();
+            mBrowserActivity.promptAddOrInstallBookmark(mStar);
         } else if (mAllButton == v) {
             mBrowserActivity.bookmarksOrHistoryPicker(false, false);
         } else if (mSearchButton == v) {
@@ -174,7 +193,7 @@
                 mInLoad = true;
                 mStopButton.setImageDrawable(mStopDrawable);
             }
-            mProgressDrawable.setLevel(newProgress*10000/PROGRESS_MAX);
+            mProgressView.setProgress(newProgress*10000/PROGRESS_MAX);
         }
     }
 
diff --git a/src/com/android/browser/UrlInputView.java b/src/com/android/browser/UrlInputView.java
index 77d7daf..9ae464b 100644
--- a/src/com/android/browser/UrlInputView.java
+++ b/src/com/android/browser/UrlInputView.java
@@ -22,8 +22,10 @@
 import android.database.Cursor;
 import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
+import android.util.Log;
 import android.view.KeyEvent;
 import android.view.LayoutInflater;
+import android.view.MotionEvent;
 import android.view.View;
 import android.view.View.OnFocusChangeListener;
 import android.view.ViewGroup;
@@ -47,7 +49,8 @@
     private UrlInputListener   mListener;
     private InputMethodManager mInputManager;
     private SuggestionsAdapter mAdapter;
-    private Drawable           mFocusDrawable;
+
+    private OnFocusChangeListener mWrappedFocusListener;
 
     public UrlInputView(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
@@ -65,16 +68,21 @@
     }
 
     private void init(Context ctx) {
-        mFocusDrawable = ctx.getResources().getDrawable(R.drawable.textfield_stroke);
         mInputManager = (InputMethodManager) ctx.getSystemService(Context.INPUT_METHOD_SERVICE);
         setOnEditorActionListener(this);
-        setOnFocusChangeListener(this);
+        super.setOnFocusChangeListener(this);
         final ContentResolver cr = mContext.getContentResolver();
         mAdapter = new SuggestionsAdapter(mContext,
                 BrowserProvider.getBookmarksSuggestions(cr, null));
         setAdapter(mAdapter);
         setOnItemClickListener(this);
-        setSelectAllOnFocus(true);
+        setSelectAllOnFocus(false);
+        
+    }
+
+    @Override
+    public void setOnFocusChangeListener(OnFocusChangeListener focusListener) {
+        mWrappedFocusListener = focusListener;
     }
 
     @Override
@@ -82,15 +90,30 @@
         finishInput(getText().toString());
         return true;
     }
-
+    
+    @Override
+    public boolean onTouchEvent(MotionEvent evt) {
+        
+        if ((evt.getAction() == MotionEvent.ACTION_DOWN) && !this.hasFocus()) {
+            Log.i("test","onTouch");
+            selectAll();
+            requestFocus();
+            return true;
+        } else {
+            return super.onTouchEvent(evt);
+        }
+    }
+    
     @Override
     public void onFocusChange(View v, boolean hasFocus) {
-        setBackgroundDrawable(hasFocus ? mFocusDrawable : null);
         if (hasFocus) {
             forceIme();
         } else {
             finishInput(null);
         }
+        if (mWrappedFocusListener != null) {
+            mWrappedFocusListener.onFocusChange(v, hasFocus);
+        }
     }
 
     @Override
@@ -110,6 +133,7 @@
 
     private void finishInput(String url) {
         this.dismissDropDown();
+        this.setSelection(0,0);
         mInputManager.hideSoftInputFromWindow(getWindowToken(), 0);
         if (url == null) {
             mListener.onDismiss();