diff options
| author | Michael Kolb <kolby@google.com> | 2010-12-13 10:11:05 -0800 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-12-13 10:11:05 -0800 |
| commit | 479baf93afd1539e082eb99268ac96b29a60db9a (patch) | |
| tree | 8b05e66f7272aa87e95826af6ab783d35d4d002b | |
| parent | 22ce7a93d8126cdfc327ccf5badedd8eaf2ac620 (diff) | |
| parent | a0e2a75fdba703260c02838c96d9d4008e914a1d (diff) | |
| download | packages_apps_Browser-479baf93afd1539e082eb99268ac96b29a60db9a.tar.gz packages_apps_Browser-479baf93afd1539e082eb99268ac96b29a60db9a.tar.bz2 packages_apps_Browser-479baf93afd1539e082eb99268ac96b29a60db9a.zip | |
Merge "Add title bar indicator to tab"
| -rw-r--r-- | res/drawable-mdpi/ic_chevron.png | bin | 0 -> 159 bytes | |||
| -rw-r--r-- | res/layout/tab_title.xml | 18 | ||||
| -rw-r--r-- | src/com/android/browser/BaseUi.java | 6 | ||||
| -rw-r--r-- | src/com/android/browser/ScrollWebView.java | 31 | ||||
| -rw-r--r-- | src/com/android/browser/TabBar.java | 45 |
5 files changed, 55 insertions, 45 deletions
diff --git a/res/drawable-mdpi/ic_chevron.png b/res/drawable-mdpi/ic_chevron.png Binary files differnew file mode 100644 index 000000000..6804d75c1 --- /dev/null +++ b/res/drawable-mdpi/ic_chevron.png diff --git a/res/layout/tab_title.xml b/res/layout/tab_title.xml index e4a4e58fa..ce3f98765 100644 --- a/res/layout/tab_title.xml +++ b/res/layout/tab_title.xml @@ -17,10 +17,18 @@ android:gravity="center_vertical" android:orientation="horizontal"> <ImageView + android:id="@+id/chevron" + android:layout_width="16dip" + android:layout_height="16dip" + android:layout_marginRight="4dip" + android:gravity="center_vertical" + android:src="@drawable/ic_chevron" + android:visibility="gone" /> + <ImageView android:id="@+id/incognito" android:layout_width="16dip" android:layout_height="16dip" - android:layout_marginLeft="3dip" + android:layout_marginRight="16dip" android:gravity="center_vertical" android:src="@drawable/fav_incognito" android:visibility="gone" /> @@ -28,19 +36,19 @@ android:id="@+id/favicon" android:layout_width="20dip" android:layout_height="20dip" - android:layout_marginLeft="16dip" /> + android:layout_marginRight="16dip" /> <ImageView android:id="@+id/lock" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginLeft="16dip" + android:layout_marginRight="16dip" android:visibility="gone" /> <TextView android:id="@+id/title" android:layout_height="match_parent" android:layout_width="0dip" android:layout_weight="1.0" - android:layout_marginLeft="16dip" + android:layout_marginRight="16dip" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="@color/white" android:gravity="center_vertical" @@ -54,6 +62,6 @@ android:background="@drawable/browserbarbutton" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginLeft="16dip" + android:layout_marginRight="16dip" android:src="@drawable/ic_tab_close" /> </merge> diff --git a/src/com/android/browser/BaseUi.java b/src/com/android/browser/BaseUi.java index 70813e586..f220e7024 100644 --- a/src/com/android/browser/BaseUi.java +++ b/src/com/android/browser/BaseUi.java @@ -160,7 +160,7 @@ public class BaseUi implements UI, WebViewFactory { // Enable the built-in zoom w.getSettings().setBuiltInZoomControls(true); if (mXLargeScreenSize) { - w.setScrollListener(mTabBar); + w.setScrollListener(this); w.getSettings().setDisplayZoomControls(false); } @@ -848,9 +848,9 @@ public class BaseUi implements UI, WebViewFactory { } @Override - public void onScroll(boolean titleVisible) { + public void onScroll(int visibleTitleHeight) { if (mTabBar != null) { - mTabBar.onScroll(titleVisible); + mTabBar.onScroll(visibleTitleHeight); } } diff --git a/src/com/android/browser/ScrollWebView.java b/src/com/android/browser/ScrollWebView.java index 97bd2c7a1..51df9582e 100644 --- a/src/com/android/browser/ScrollWebView.java +++ b/src/com/android/browser/ScrollWebView.java @@ -26,11 +26,10 @@ import java.util.Map; /** * Manage WebView scroll events */ -public class ScrollWebView extends WebView { +public class ScrollWebView extends WebView implements Runnable { private ScrollListener mScrollListener; private boolean mIsCancelled; - private Runnable mScrollRunnable; /** * @param context @@ -68,6 +67,13 @@ public class ScrollWebView extends WebView { super(context); } + // scroll runnable implementation + public void run() { + if (!mIsCancelled && (mScrollListener != null)) { + mScrollListener.onScroll(getVisibleTitleHeight()); + } + } + void hideEmbeddedTitleBar() { scrollBy(0, getVisibleTitleHeight()); } @@ -77,13 +83,7 @@ public class ScrollWebView extends WebView { super.setEmbeddedTitleBar(title); if (title != null && mScrollListener != null) { // allow the scroll listener to initialize its state - post(new Runnable() { - @Override - public void run() { - mScrollListener.onScroll((title.getHeight() == 0 || - getVisibleTitleHeight() > 0)); - } - }); + post(this); } } @@ -97,7 +97,7 @@ public class ScrollWebView extends WebView { protected void onScrollChanged(int l, final int t, int ol, int ot) { super.onScrollChanged(l, t, ol, ot); if (!mIsCancelled) { - post(mScrollRunnable); + post(this); } else { mIsCancelled = false; } @@ -105,21 +105,12 @@ public class ScrollWebView extends WebView { void setScrollListener(ScrollListener l) { mScrollListener = l; - if (mScrollListener != null) { - mScrollRunnable = new Runnable() { - public void run() { - if (!mIsCancelled) { - mScrollListener.onScroll(getVisibleTitleHeight() > 0); - } - } - }; - } } // callback for scroll events interface ScrollListener { - public void onScroll(boolean titleVisible); + public void onScroll(int visibleTitleHeight); } } diff --git a/src/com/android/browser/TabBar.java b/src/com/android/browser/TabBar.java index 4f179b087..79699559e 100644 --- a/src/com/android/browser/TabBar.java +++ b/src/com/android/browser/TabBar.java @@ -73,8 +73,7 @@ public class TabBar extends LinearLayout private Map<Tab, TabViewData> mTabMap; private boolean mUserRequestedUrlbar; - private boolean mTitleVisible; - private boolean mShowUrlMode; + private int mVisibleTitleHeight; private boolean mHasReceivedTitle; private Drawable mGenericFavicon; @@ -121,7 +120,7 @@ public class TabBar extends LinearLayout updateTabs(mUiController.getTabs()); mUserRequestedUrlbar = false; - mTitleVisible = true; + mVisibleTitleHeight = 1; mButtonWidth = -1; // tab dimensions mTabHeight = (int) res.getDimension(R.dimen.tab_height); @@ -204,18 +203,24 @@ public class TabBar extends LinearLayout mUserRequestedUrlbar = true; } - private void setShowUrlMode(boolean showUrl) { - mShowUrlMode = showUrl; + private void showTitleBarIndicator(boolean show) { + Tab tab = mTabControl.getCurrentTab(); + if (tab != null) { + TabViewData tvd = mTabMap.get(tab); + if (tvd != null) { + tvd.mTabView.showIndicator(show); + } + } } // callback after fake titlebar is shown void onShowTitleBar() { - setShowUrlMode(false); + showTitleBarIndicator(false); } // callback after fake titlebar is hidden void onHideTitleBar() { - setShowUrlMode(!mTitleVisible); + showTitleBarIndicator(mVisibleTitleHeight == 0); Tab tab = mTabControl.getCurrentTab(); tab.getWebView().requestFocus(); mUserRequestedUrlbar = false; @@ -224,22 +229,22 @@ public class TabBar extends LinearLayout // webview scroll listener @Override - public void onScroll(boolean titleVisible) { + public void onScroll(int visibleTitleHeight) { // isLoading is using the current tab, which initially might not be set yet if (mTabControl.getCurrentTab() != null) { - mTitleVisible = titleVisible; - if (!mShowUrlMode && !mTitleVisible && !isLoading()) { + if ((mVisibleTitleHeight > 0) && (visibleTitleHeight == 0) + && !isLoading()) { if (mUserRequestedUrlbar) { mUi.hideFakeTitleBar(); } else { - setShowUrlMode(true); - } - } else if (mTitleVisible && !isLoading()) { - if (mShowUrlMode) { - setShowUrlMode(false); + showTitleBarIndicator(true); } + } else if ((mVisibleTitleHeight == 0) && (visibleTitleHeight != 0) + && !isLoading()) { + showTitleBarIndicator(false); } } + mVisibleTitleHeight = visibleTitleHeight; } @Override @@ -277,6 +282,7 @@ public class TabBar extends LinearLayout TabViewData mTabData; View mTabContent; TextView mTitle; + View mIndicator; View mIncognito; ImageView mIconView; ImageView mLock; @@ -297,7 +303,7 @@ public class TabBar extends LinearLayout mTabData = tab; setGravity(Gravity.CENTER_VERTICAL); setOrientation(LinearLayout.HORIZONTAL); - setPadding(0, 0, mTabPadding, 0); + setPadding(mTabPadding, 0, 0, 0); LayoutInflater inflater = LayoutInflater.from(getContext()); mTabContent = inflater.inflate(R.layout.tab_title, this, true); mTitle = (TextView) mTabContent.findViewById(R.id.title); @@ -306,12 +312,17 @@ public class TabBar extends LinearLayout mClose = (ImageView) mTabContent.findViewById(R.id.close); mClose.setOnClickListener(this); mIncognito = mTabContent.findViewById(R.id.incognito); + mIndicator = mTabContent.findViewById(R.id.chevron); mSelected = false; mInLoad = false; // update the status updateFromData(); } + void showIndicator(boolean show) { + mIndicator.setVisibility(show ? View.VISIBLE : View.GONE); + } + @Override public void onClick(View v) { if (v == mClose) { @@ -497,7 +508,7 @@ public class TabBar extends LinearLayout tvd.setProgress(tvd.mProgress); // update the scroll state WebView webview = tab.getWebView(); - onScroll(webview.getVisibleTitleHeight() > 0); + onScroll(webview.getVisibleTitleHeight()); } } |
