Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.browser; |
| 18 | |
| 19 | import com.android.browser.ScrollWebView.ScrollListener; |
| 20 | |
| 21 | import android.app.ActionBar; |
| 22 | import android.app.Activity; |
| 23 | import android.graphics.Bitmap; |
| 24 | import android.view.ActionMode; |
| 25 | import android.webkit.WebView; |
| 26 | |
| 27 | import java.util.List; |
| 28 | |
| 29 | /** |
| 30 | * Ui for xlarge screen sizes |
| 31 | */ |
| 32 | public class XLargeUi extends BaseUi implements ScrollListener { |
| 33 | |
| 34 | private static final String LOGTAG = "XLargeUi"; |
| 35 | |
| 36 | private TabBar mTabBar; |
| 37 | |
| 38 | private TitleBarXLarge mTitleBar; |
| 39 | private TitleBarXLarge mFakeTitleBar; |
| 40 | |
| 41 | /** |
| 42 | * @param browser |
| 43 | * @param controller |
| 44 | */ |
| 45 | public XLargeUi(Activity browser, UiController controller) { |
| 46 | super(browser, controller); |
| 47 | mTitleBar = new TitleBarXLarge(mActivity, mUiController, this); |
| 48 | mTitleBar.setProgress(100); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame^] | 49 | mTitleBar.setEditable(false); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 50 | mFakeTitleBar = new TitleBarXLarge(mActivity, mUiController, this); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame^] | 51 | mFakeTitleBar.setEditable(true); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 52 | ActionBar actionBar = mActivity.getActionBar(); |
| 53 | mTabBar = new TabBar(mActivity, mUiController, this); |
| 54 | actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); |
| 55 | actionBar.setCustomView(mTabBar); |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public void onDestroy() { |
| 60 | hideFakeTitleBar(); |
| 61 | } |
| 62 | |
| 63 | // webview factory |
| 64 | |
| 65 | @Override |
| 66 | public WebView createWebView(boolean privateBrowsing) { |
| 67 | // Create a new WebView |
| 68 | ScrollWebView w = new ScrollWebView(mActivity, null, |
| 69 | android.R.attr.webViewStyle, privateBrowsing); |
| 70 | initWebViewSettings(w); |
| 71 | w.setScrollListener(this); |
| 72 | w.getSettings().setDisplayZoomControls(false); |
| 73 | return w; |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public WebView createSubWebView(boolean privateBrowsing) { |
| 78 | ScrollWebView web = (ScrollWebView) createWebView(privateBrowsing); |
| 79 | // no scroll listener for subview |
| 80 | web.setScrollListener(null); |
| 81 | return web; |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public void onScroll(int visibleTitleHeight) { |
| 86 | mTabBar.onScroll(visibleTitleHeight); |
| 87 | } |
| 88 | |
| 89 | void stopWebViewScrolling() { |
| 90 | ScrollWebView web = (ScrollWebView) mUiController.getCurrentWebView(); |
| 91 | if (web != null) { |
| 92 | web.stopScroll(); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | // WebView callbacks |
| 97 | |
| 98 | @Override |
| 99 | public void onPageStarted(Tab tab, String url, Bitmap favicon) { |
| 100 | super.onPageStarted(tab, url, favicon); |
| 101 | mTabBar.onPageStarted(tab, url, favicon); |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public void bookmarkedStatusHasChanged(Tab tab) { |
| 106 | if (tab.inForeground()) { |
| 107 | boolean isBookmark = tab.isBookmarkedSite(); |
| 108 | mTitleBar.setCurrentUrlIsBookmark(isBookmark); |
| 109 | mFakeTitleBar.setCurrentUrlIsBookmark(isBookmark); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public void onPageFinished(Tab tab, String url) { |
| 115 | mTabBar.onPageFinished(tab); |
| 116 | super.onPageFinished(tab, url); |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public void onProgressChanged(Tab tab, int progress) { |
| 121 | mTabBar.onProgress(tab, progress); |
| 122 | if (tab.inForeground()) { |
| 123 | mFakeTitleBar.setProgress(progress); |
| 124 | if (progress == 100) { |
| 125 | hideFakeTitleBar(); |
| 126 | } else { |
| 127 | showFakeTitleBar(); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | @Override |
| 133 | public boolean needsRestoreAllTabs() { |
| 134 | return true; |
| 135 | } |
| 136 | |
| 137 | @Override |
| 138 | public void addTab(Tab tab) { |
| 139 | mTabBar.onNewTab(tab); |
| 140 | } |
| 141 | |
| 142 | @Override |
| 143 | public void setActiveTab(Tab tab) { |
| 144 | super.setActiveTab(tab); |
| 145 | mTabBar.onSetActiveTab(tab); |
| 146 | } |
| 147 | |
| 148 | @Override |
| 149 | public void updateTabs(List<Tab> tabs) { |
| 150 | mTabBar.updateTabs(tabs); |
| 151 | } |
| 152 | |
| 153 | @Override |
| 154 | public void removeTab(Tab tab) { |
| 155 | super.removeTab(tab); |
| 156 | mTabBar.onRemoveTab(tab); |
| 157 | } |
| 158 | |
| 159 | int getTitleBarWidth() { |
| 160 | if (mTitleBar != null) { |
| 161 | return mTitleBar.getWidth(); |
| 162 | } |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | void editUrl(boolean clearInput) { |
| 167 | showFakeTitleBar(); |
| 168 | mFakeTitleBar.onEditUrl(clearInput); |
| 169 | } |
| 170 | |
| 171 | @Override |
| 172 | protected void attachFakeTitleBar(WebView mainView) { |
| 173 | mContentView.addView(mFakeTitleBar); |
| 174 | mTabBar.onShowTitleBar(); |
| 175 | } |
| 176 | |
| 177 | @Override |
| 178 | protected void hideFakeTitleBar() { |
| 179 | if (isFakeTitleBarShowing()) { |
| 180 | mContentView.removeView(mFakeTitleBar); |
| 181 | mTabBar.onHideTitleBar(); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | @Override |
| 186 | protected boolean isFakeTitleBarShowing() { |
| 187 | return (mFakeTitleBar.getParent() != null); |
| 188 | } |
| 189 | |
| 190 | @Override |
| 191 | protected TitleBarBase getFakeTitleBar() { |
| 192 | return mFakeTitleBar; |
| 193 | } |
| 194 | |
| 195 | @Override |
| 196 | protected TitleBarBase getEmbeddedTitleBar() { |
| 197 | return mTitleBar; |
| 198 | } |
| 199 | |
| 200 | // action mode callbacks |
| 201 | |
| 202 | @Override |
| 203 | public void onActionModeStarted(ActionMode mode) { |
| 204 | if (mFakeTitleBar.isEditingUrl()) { |
| 205 | // hide the fake title bar when CAB is shown |
| 206 | hideFakeTitleBar(); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | @Override |
| 211 | public void setUrlTitle(Tab tab, String url, String title) { |
| 212 | super.setUrlTitle(tab, url, title); |
| 213 | mTabBar.onUrlAndTitle(tab, url, title); |
| 214 | } |
| 215 | |
| 216 | // Set the favicon in the title bar. |
| 217 | @Override |
| 218 | public void setFavicon(Tab tab, Bitmap icon) { |
| 219 | super.setFavicon(tab, icon); |
| 220 | mTabBar.onFavicon(tab, icon); |
| 221 | } |
| 222 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame^] | 223 | @Override |
| 224 | public void showVoiceTitleBar(String title) { |
| 225 | List<String> vsresults = null; |
| 226 | if (getActiveTab() != null) { |
| 227 | vsresults = getActiveTab().getVoiceSearchResults(); |
| 228 | } |
| 229 | mTitleBar.setInVoiceMode(true, null); |
| 230 | mTitleBar.setDisplayTitle(title); |
| 231 | mFakeTitleBar.setInVoiceMode(true, vsresults); |
| 232 | mFakeTitleBar.setDisplayTitle(title); |
| 233 | } |
| 234 | |
| 235 | @Override |
| 236 | public void revertVoiceTitleBar(Tab tab) { |
| 237 | mTitleBar.setInVoiceMode(false, null); |
| 238 | String url = tab.getCurrentUrl(); |
| 239 | mTitleBar.setDisplayTitle(url); |
| 240 | mFakeTitleBar.setInVoiceMode(false, null); |
| 241 | mFakeTitleBar.setDisplayTitle(url); |
| 242 | } |
| 243 | |
| 244 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 245 | } |