blob: b7b3ed956d48714d61dbfa5cf35caccf82ac4b2a [file] [log] [blame]
Leon Scroggins571b3762010-05-26 10:25:01 -04001/*
John Reck0f602f32011-07-07 15:38:43 -07002 * Copyright (C) 2011 The Android Open Source Project
Leon Scroggins571b3762010-05-26 10:25:01 -04003 *
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 */
Leon Scroggins571b3762010-05-26 10:25:01 -040016package com.android.browser;
17
18import android.content.Context;
19import android.content.res.Resources;
Leon Scroggins571b3762010-05-26 10:25:01 -040020import android.graphics.drawable.Drawable;
Michael Kolb1ce78132010-09-23 15:50:53 -070021import android.text.TextUtils;
John Reck0f602f32011-07-07 15:38:43 -070022import android.util.AttributeSet;
Leon Scroggins571b3762010-05-26 10:25:01 -040023import android.view.View;
Michael Kolbb6bc32c2010-12-10 11:51:54 -080024import android.webkit.WebView;
Michael Kolb5a72f182011-01-13 20:35:06 -080025import android.widget.ImageButton;
Leon Scroggins571b3762010-05-26 10:25:01 -040026import android.widget.ImageView;
Leon Scroggins571b3762010-05-26 10:25:01 -040027
Michael Kolbcfa3af52010-12-14 10:36:11 -080028import java.util.List;
29
John Reck0f602f32011-07-07 15:38:43 -070030public class NavigationBarTablet extends NavigationBarBase {
Michael Kolb8233fac2010-10-26 16:08:53 -070031
Michael Kolba2b2ba82010-08-04 17:54:03 -070032 private Drawable mStopDrawable;
33 private Drawable mReloadDrawable;
Michael Kolbc7485ae2010-09-03 10:10:58 -070034
Michael Kolb11d19782011-03-20 10:17:40 -070035 private View mUrlContainer;
Michael Kolb5a72f182011-01-13 20:35:06 -080036 private ImageButton mBackButton;
37 private ImageButton mForwardButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080038 private ImageView mStar;
Michael Kolbe3524d82011-03-02 14:53:15 -080039 private ImageView mUrlIcon;
40 private ImageView mSearchButton;
Michael Kolb513286f2010-09-09 12:55:12 -070041 private View mGoButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070042 private ImageView mStopButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070043 private View mAllButton;
Michael Kolbb7b115e2010-09-25 16:59:37 -070044 private View mClearButton;
Michael Kolbe3524d82011-03-02 14:53:15 -080045 private ImageView mVoiceSearch;
Michael Kolbcfa3af52010-12-14 10:36:11 -080046 private Drawable mFocusDrawable;
47 private Drawable mUnfocusDrawable;
Michael Kolb81b6f832010-12-12 12:44:27 -080048
John Reck0f602f32011-07-07 15:38:43 -070049 public NavigationBarTablet(Context context) {
50 super(context);
51 init(context);
52 }
53
54 public NavigationBarTablet(Context context, AttributeSet attrs) {
55 super(context, attrs);
56 init(context);
57 }
58
59 public NavigationBarTablet(Context context, AttributeSet attrs, int defStyle) {
60 super(context, attrs, defStyle);
61 init(context);
62 }
63
64 private void init(Context context) {
65 Resources resources = context.getResources();
Michael Kolb5a72f182011-01-13 20:35:06 -080066 mStopDrawable = resources.getDrawable(R.drawable.ic_stop_holo_dark);
67 mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_holo_dark);
Michael Kolbcfa3af52010-12-14 10:36:11 -080068 mFocusDrawable = resources.getDrawable(
69 R.drawable.textfield_active_holo_dark);
70 mUnfocusDrawable = resources.getDrawable(
71 R.drawable.textfield_default_holo_dark);
Michael Kolbfe251992010-07-08 15:41:55 -070072 }
Leon Scroggins571b3762010-05-26 10:25:01 -040073
Michael Kolb7cdc4902011-02-03 17:54:40 -080074 @Override
John Reck0f602f32011-07-07 15:38:43 -070075 protected void onFinishInflate() {
76 super.onFinishInflate();
Michael Kolbfe251992010-07-08 15:41:55 -070077 mAllButton = findViewById(R.id.all_btn);
78 // TODO: Change enabled states based on whether you can go
Leon Scroggins571b3762010-05-26 10:25:01 -040079 // back/forward. Probably should be done inside onPageStarted.
Michael Kolb5a72f182011-01-13 20:35:06 -080080 mBackButton = (ImageButton) findViewById(R.id.back);
81 mForwardButton = (ImageButton) findViewById(R.id.forward);
Michael Kolbe3524d82011-03-02 14:53:15 -080082 mUrlIcon = (ImageView) findViewById(R.id.url_icon);
Michael Kolb31d469b2010-12-09 20:49:54 -080083 mStar = (ImageView) findViewById(R.id.star);
Michael Kolba2b2ba82010-08-04 17:54:03 -070084 mStopButton = (ImageView) findViewById(R.id.stop);
Michael Kolbe3524d82011-03-02 14:53:15 -080085 mSearchButton = (ImageView) findViewById(R.id.search);
Michael Kolb513286f2010-09-09 12:55:12 -070086 mGoButton = findViewById(R.id.go);
Michael Kolbb7b115e2010-09-25 16:59:37 -070087 mClearButton = findViewById(R.id.clear);
Michael Kolbe3524d82011-03-02 14:53:15 -080088 mVoiceSearch = (ImageView) findViewById(R.id.voicesearch);
Michael Kolb31d469b2010-12-09 20:49:54 -080089 mUrlContainer = findViewById(R.id.urlbar_focused);
Michael Kolba2b2ba82010-08-04 17:54:03 -070090 mBackButton.setOnClickListener(this);
91 mForwardButton.setOnClickListener(this);
92 mStar.setOnClickListener(this);
93 mAllButton.setOnClickListener(this);
94 mStopButton.setOnClickListener(this);
95 mSearchButton.setOnClickListener(this);
Michael Kolb513286f2010-09-09 12:55:12 -070096 mGoButton.setOnClickListener(this);
Michael Kolbb7b115e2010-09-25 16:59:37 -070097 mClearButton.setOnClickListener(this);
Michael Kolbcfa3af52010-12-14 10:36:11 -080098 mVoiceSearch.setOnClickListener(this);
John Reck46500332011-06-07 14:36:10 -070099 setUaSwitcher(mUrlIcon);
Michael Kolb31d469b2010-12-09 20:49:54 -0800100 mUrlInput.setContainer(mUrlContainer);
John Reck0f602f32011-07-07 15:38:43 -0700101 }
102
103 @Override
104 public void setTitleBar(TitleBar titleBar) {
105 super.setTitleBar(titleBar);
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800106 setFocusState(false);
Michael Kolb31d469b2010-12-09 20:49:54 -0800107 }
108
Michael Kolb5a72f182011-01-13 20:35:06 -0800109 void updateNavigationState(Tab tab) {
110 WebView web = tab.getWebView();
111 if (web != null) {
112 mBackButton.setImageResource(web.canGoBack()
113 ? R.drawable.ic_back_holo_dark
114 : R.drawable.ic_back_disabled_holo_dark);
115 mForwardButton.setImageResource(web.canGoForward()
116 ? R.drawable.ic_forward_holo_dark
117 : R.drawable.ic_forward_disabled_holo_dark);
118 }
John Reckb8b2af82011-05-20 15:58:33 -0700119 updateUrlIcon();
Michael Kolb5a72f182011-01-13 20:35:06 -0800120 }
121
Michael Kolb31d469b2010-12-09 20:49:54 -0800122 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500123 public void setCurrentUrlIsBookmark(boolean isBookmark) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800124 mStar.setActivated(isBookmark);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500125 }
126
Michael Kolba2b2ba82010-08-04 17:54:03 -0700127 @Override
128 public void onClick(View v) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800129 if (mBackButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700130 mUiController.getCurrentTopWebView().goBack();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700131 } else if (mForwardButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700132 mUiController.getCurrentTopWebView().goForward();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700133 } else if (mStar == v) {
John Reck3ffc5ca2011-06-10 15:56:06 -0700134 mUiController.bookmarkCurrentPage(true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700135 } else if (mAllButton == v) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700136 mUiController.bookmarksOrHistoryPicker(false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700137 } else if (mSearchButton == v) {
John Reck0f602f32011-07-07 15:38:43 -0700138 mBaseUi.editUrl(true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700139 } else if (mStopButton == v) {
140 stopOrRefresh();
Michael Kolb513286f2010-09-09 12:55:12 -0700141 } else if (mGoButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800142 if (!TextUtils.isEmpty(mUrlInput.getText())) {
143 onAction(mUrlInput.getText().toString(), null,
Michael Kolb257cc2c2010-12-09 09:45:52 -0800144 UrlInputView.TYPED);
Michael Kolb1ce78132010-09-23 15:50:53 -0700145 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700146 } else if (mClearButton == v) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800147 clearOrClose();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800148 } else if (mVoiceSearch == v) {
149 mUiController.startVoiceSearch();
Michael Kolb11d19782011-03-20 10:17:40 -0700150 } else {
151 super.onClick(v);
Michael Kolbfe251992010-07-08 15:41:55 -0700152 }
153 }
154
Michael Kolb31d469b2010-12-09 20:49:54 -0800155 private void clearOrClose() {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000156 if (TextUtils.isEmpty(mUrlInput.getUserText())) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800157 // close
Michael Kolb7cdc4902011-02-03 17:54:40 -0800158 mUrlInput.clearFocus();
Michael Kolb31d469b2010-12-09 20:49:54 -0800159 } else {
160 // clear
161 mUrlInput.setText("");
162 }
163 }
164
John Reckb8b2af82011-05-20 15:58:33 -0700165 void updateUrlIcon() {
John Reck46500332011-06-07 14:36:10 -0700166 mUrlIcon.setImageResource(mInVoiceMode ?
167 R.drawable.ic_search_holo_dark
168 : R.drawable.ic_web_holo_dark);
John Reckb8b2af82011-05-20 15:58:33 -0700169 }
170
Michael Kolb11d19782011-03-20 10:17:40 -0700171 @Override
172 protected void setFocusState(boolean focus) {
173 super.setFocusState(focus);
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800174 if (focus) {
Michael Kolbb7b115e2010-09-25 16:59:37 -0700175 mSearchButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800176 mStar.setVisibility(View.GONE);
177 mClearButton.setVisibility(View.VISIBLE);
Michael Kolbe3524d82011-03-02 14:53:15 -0800178 mUrlIcon.setImageResource(R.drawable.ic_search_holo_dark);
Michael Kolb60a68f52011-02-24 11:02:52 -0800179 updateSearchMode(false);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700180 } else {
Michael Kolbb7b115e2010-09-25 16:59:37 -0700181 mGoButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800182 mVoiceSearch.setVisibility(View.GONE);
183 mStar.setVisibility(View.VISIBLE);
184 mClearButton.setVisibility(View.GONE);
John Reck0f602f32011-07-07 15:38:43 -0700185 if (mTitleBar.useQuickControls()) {
Michael Kolb376b5412010-12-15 11:52:57 -0800186 mSearchButton.setVisibility(View.GONE);
187 } else {
188 mSearchButton.setVisibility(View.VISIBLE);
189 }
John Reckb8b2af82011-05-20 15:58:33 -0700190 updateUrlIcon();
Michael Kolbb7b115e2010-09-25 16:59:37 -0700191 }
John Reck7e5b8b52011-06-22 13:46:25 -0700192 mUrlContainer.setBackgroundDrawable(focus
193 ? mFocusDrawable : mUnfocusDrawable);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700194 }
195
Michael Kolba2b2ba82010-08-04 17:54:03 -0700196 private void stopOrRefresh() {
John Reck0f602f32011-07-07 15:38:43 -0700197 if (mTitleBar.isInLoad()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700198 mUiController.stopLoading();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700199 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -0700200 mUiController.getCurrentTopWebView().reload();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700201 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400202 }
203
Michael Kolbfe251992010-07-08 15:41:55 -0700204 @Override
John Reck0f602f32011-07-07 15:38:43 -0700205 public void onProgressStarted() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700206 mStopButton.setImageDrawable(mStopDrawable);
207 }
208
209 @Override
John Reck0f602f32011-07-07 15:38:43 -0700210 public void onProgressStopped() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700211 mStopButton.setImageDrawable(mReloadDrawable);
Michael Kolbfe251992010-07-08 15:41:55 -0700212 }
213
Michael Kolb11d19782011-03-20 10:17:40 -0700214 protected void updateSearchMode(boolean userEdited) {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000215 setSearchMode(!userEdited || TextUtils.isEmpty(mUrlInput.getUserText()));
Michael Kolb31d469b2010-12-09 20:49:54 -0800216 }
217
Michael Kolb11d19782011-03-20 10:17:40 -0700218 @Override
219 protected void setSearchMode(boolean voiceSearchEnabled) {
Michael Kolb793e05e2011-01-11 15:17:31 -0800220 boolean showvoicebutton = voiceSearchEnabled &&
Michael Kolb736990c2011-03-20 10:01:20 -0700221 mUiController.supportsVoiceSearch();
Michael Kolb793e05e2011-01-11 15:17:31 -0800222 mVoiceSearch.setVisibility(showvoicebutton ? View.VISIBLE :
Michael Kolb31d469b2010-12-09 20:49:54 -0800223 View.GONE);
224 mGoButton.setVisibility(voiceSearchEnabled ? View.GONE :
225 View.VISIBLE);
226 }
227
Michael Kolbfe251992010-07-08 15:41:55 -0700228 @Override
Michael Kolbcfa3af52010-12-14 10:36:11 -0800229 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
Michael Kolb11d19782011-03-20 10:17:40 -0700230 super.setInVoiceMode(voicemode, voiceResults);
Michael Kolb3aaef252011-03-09 18:13:56 -0800231 if (voicemode) {
232 mUrlIcon.setImageDrawable(mSearchButton.getDrawable());
233 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800234 }
235
Leon Scroggins571b3762010-05-26 10:25:01 -0400236}