blob: 30180aa189c1bb96f9bd797fb692af9e422d1d5c [file] [log] [blame]
Michael Kolb66706532010-12-12 19:50:22 -08001/*
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
17package com.android.browser;
18
19import com.android.browser.ScrollWebView.ScrollListener;
20
21import android.app.ActionBar;
22import android.app.Activity;
23import android.graphics.Bitmap;
24import android.view.ActionMode;
25import android.webkit.WebView;
26
27import java.util.List;
28
29/**
30 * Ui for xlarge screen sizes
31 */
32public 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);
49 mFakeTitleBar = new TitleBarXLarge(mActivity, mUiController, this);
50 ActionBar actionBar = mActivity.getActionBar();
51 mTabBar = new TabBar(mActivity, mUiController, this);
52 actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
53 actionBar.setCustomView(mTabBar);
54 }
55
56 @Override
57 public void onDestroy() {
58 hideFakeTitleBar();
59 }
60
61 // webview factory
62
63 @Override
64 public WebView createWebView(boolean privateBrowsing) {
65 // Create a new WebView
66 ScrollWebView w = new ScrollWebView(mActivity, null,
67 android.R.attr.webViewStyle, privateBrowsing);
68 initWebViewSettings(w);
69 w.setScrollListener(this);
70 w.getSettings().setDisplayZoomControls(false);
71 return w;
72 }
73
74 @Override
75 public WebView createSubWebView(boolean privateBrowsing) {
76 ScrollWebView web = (ScrollWebView) createWebView(privateBrowsing);
77 // no scroll listener for subview
78 web.setScrollListener(null);
79 return web;
80 }
81
82 @Override
83 public void onScroll(int visibleTitleHeight) {
84 mTabBar.onScroll(visibleTitleHeight);
85 }
86
87 void stopWebViewScrolling() {
88 ScrollWebView web = (ScrollWebView) mUiController.getCurrentWebView();
89 if (web != null) {
90 web.stopScroll();
91 }
92 }
93
94 // WebView callbacks
95
96 @Override
97 public void onPageStarted(Tab tab, String url, Bitmap favicon) {
98 super.onPageStarted(tab, url, favicon);
99 mTabBar.onPageStarted(tab, url, favicon);
100 }
101
102 @Override
103 public void bookmarkedStatusHasChanged(Tab tab) {
104 if (tab.inForeground()) {
105 boolean isBookmark = tab.isBookmarkedSite();
106 mTitleBar.setCurrentUrlIsBookmark(isBookmark);
107 mFakeTitleBar.setCurrentUrlIsBookmark(isBookmark);
108 }
109 }
110
111 @Override
112 public void onPageFinished(Tab tab, String url) {
113 mTabBar.onPageFinished(tab);
114 super.onPageFinished(tab, url);
115 }
116
117 @Override
118 public void onProgressChanged(Tab tab, int progress) {
119 mTabBar.onProgress(tab, progress);
120 if (tab.inForeground()) {
121 mFakeTitleBar.setProgress(progress);
122 if (progress == 100) {
123 hideFakeTitleBar();
124 } else {
125 showFakeTitleBar();
126 }
127 }
128 }
129
130 @Override
131 public boolean needsRestoreAllTabs() {
132 return true;
133 }
134
135 @Override
136 public void addTab(Tab tab) {
137 mTabBar.onNewTab(tab);
138 }
139
140 @Override
141 public void setActiveTab(Tab tab) {
142 super.setActiveTab(tab);
143 mTabBar.onSetActiveTab(tab);
144 }
145
146 @Override
147 public void updateTabs(List<Tab> tabs) {
148 mTabBar.updateTabs(tabs);
149 }
150
151 @Override
152 public void removeTab(Tab tab) {
153 super.removeTab(tab);
154 mTabBar.onRemoveTab(tab);
155 }
156
157 int getTitleBarWidth() {
158 if (mTitleBar != null) {
159 return mTitleBar.getWidth();
160 }
161 return 0;
162 }
163
164 void editUrl(boolean clearInput) {
165 showFakeTitleBar();
166 mFakeTitleBar.onEditUrl(clearInput);
167 }
168
169 @Override
170 protected void attachFakeTitleBar(WebView mainView) {
171 mContentView.addView(mFakeTitleBar);
172 mTabBar.onShowTitleBar();
173 }
174
175 @Override
176 protected void hideFakeTitleBar() {
177 if (isFakeTitleBarShowing()) {
178 mContentView.removeView(mFakeTitleBar);
179 mTabBar.onHideTitleBar();
180 }
181 }
182
183 @Override
184 protected boolean isFakeTitleBarShowing() {
185 return (mFakeTitleBar.getParent() != null);
186 }
187
188 @Override
189 protected TitleBarBase getFakeTitleBar() {
190 return mFakeTitleBar;
191 }
192
193 @Override
194 protected TitleBarBase getEmbeddedTitleBar() {
195 return mTitleBar;
196 }
197
198 // action mode callbacks
199
200 @Override
201 public void onActionModeStarted(ActionMode mode) {
202 if (mFakeTitleBar.isEditingUrl()) {
203 // hide the fake title bar when CAB is shown
204 hideFakeTitleBar();
205 }
206 }
207
208 @Override
209 public void setUrlTitle(Tab tab, String url, String title) {
210 super.setUrlTitle(tab, url, title);
211 mTabBar.onUrlAndTitle(tab, url, title);
212 }
213
214 // Set the favicon in the title bar.
215 @Override
216 public void setFavicon(Tab tab, Bitmap icon) {
217 super.setFavicon(tab, icon);
218 mTabBar.onFavicon(tab, icon);
219 }
220
221}