Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [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 | |
Michael Kolb | 3aaef25 | 2011-03-09 18:13:56 -0800 | [diff] [blame] | 19 | import com.android.browser.autocomplete.SuggestedTextController.TextChangeWatcher; |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 20 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 21 | import android.app.Activity; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.content.res.Resources; |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 24 | import android.graphics.Bitmap; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 25 | import android.graphics.drawable.Drawable; |
Michael Kolb | 1ce7813 | 2010-09-23 15:50:53 -0700 | [diff] [blame] | 26 | import android.text.TextUtils; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 27 | import android.view.View; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 28 | import android.view.View.OnClickListener; |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 29 | import android.view.View.OnFocusChangeListener; |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 30 | import android.view.ViewGroup; |
Michael Kolb | b6bc32c | 2010-12-10 11:51:54 -0800 | [diff] [blame] | 31 | import android.webkit.WebView; |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 32 | import android.widget.AbsoluteLayout; |
| 33 | import android.widget.FrameLayout; |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 34 | import android.widget.ImageButton; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 35 | import android.widget.ImageView; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 36 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 37 | import java.util.List; |
| 38 | |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 39 | /** |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 40 | * tabbed title bar for xlarge screen browser |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 41 | */ |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 42 | public class TitleBarXLarge extends TitleBarBase |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 43 | implements OnClickListener, OnFocusChangeListener, TextChangeWatcher, |
| 44 | DeviceAccountLogin.AutoLoginCallback { |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 45 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 46 | private XLargeUi mUi; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 47 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 48 | private Drawable mStopDrawable; |
| 49 | private Drawable mReloadDrawable; |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 50 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame^] | 51 | private View mUrlContainer; |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 52 | private ImageButton mBackButton; |
| 53 | private ImageButton mForwardButton; |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 54 | private ImageView mStar; |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 55 | private ImageView mUrlIcon; |
| 56 | private ImageView mSearchButton; |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame^] | 57 | private View mContainer; |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 58 | private View mGoButton; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 59 | private ImageView mStopButton; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 60 | private View mAllButton; |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 61 | private View mClearButton; |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 62 | private ImageView mVoiceSearch; |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 63 | private PageProgressView mProgressView; |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 64 | private Drawable mFocusDrawable; |
| 65 | private Drawable mUnfocusDrawable; |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 66 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 67 | private boolean mInLoad; |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 68 | private boolean mUseQuickControls; |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 69 | |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 70 | public TitleBarXLarge(Activity activity, UiController controller, |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 71 | XLargeUi ui) { |
John Reck | 9202673 | 2011-02-15 10:12:30 -0800 | [diff] [blame] | 72 | super(activity, controller, ui); |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 73 | mUi = ui; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 74 | Resources resources = activity.getResources(); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 75 | mStopDrawable = resources.getDrawable(R.drawable.ic_stop_holo_dark); |
| 76 | mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_holo_dark); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 77 | mFocusDrawable = resources.getDrawable( |
| 78 | R.drawable.textfield_active_holo_dark); |
| 79 | mUnfocusDrawable = resources.getDrawable( |
| 80 | R.drawable.textfield_default_holo_dark); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 81 | mInVoiceMode = false; |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame^] | 82 | initLayout(activity, R.layout.url_bar); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 83 | } |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 84 | |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 85 | @Override |
| 86 | void setTitleGravity(int gravity) { |
| 87 | if (mUseQuickControls) { |
| 88 | FrameLayout.LayoutParams lp = |
| 89 | (FrameLayout.LayoutParams) getLayoutParams(); |
| 90 | lp.gravity = gravity; |
| 91 | setLayoutParams(lp); |
| 92 | } else { |
| 93 | super.setTitleGravity(gravity); |
| 94 | } |
| 95 | } |
| 96 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame^] | 97 | @Override |
| 98 | protected void initLayout(Context context, int layoutId) { |
| 99 | super.initLayout(context, layoutId); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 100 | |
Michael Kolb | 3f65c38 | 2010-08-20 15:31:16 -0700 | [diff] [blame] | 101 | mContainer = findViewById(R.id.taburlbar); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 102 | mAllButton = findViewById(R.id.all_btn); |
| 103 | // TODO: Change enabled states based on whether you can go |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 104 | // back/forward. Probably should be done inside onPageStarted. |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 105 | mBackButton = (ImageButton) findViewById(R.id.back); |
| 106 | mForwardButton = (ImageButton) findViewById(R.id.forward); |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 107 | mUrlIcon = (ImageView) findViewById(R.id.url_icon); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 108 | mStar = (ImageView) findViewById(R.id.star); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 109 | mStopButton = (ImageView) findViewById(R.id.stop); |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 110 | mSearchButton = (ImageView) findViewById(R.id.search); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 111 | mLockIcon = (ImageView) findViewById(R.id.lock); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 112 | mGoButton = findViewById(R.id.go); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 113 | mClearButton = findViewById(R.id.clear); |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 114 | mVoiceSearch = (ImageView) findViewById(R.id.voicesearch); |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 115 | mProgressView = (PageProgressView) findViewById(R.id.progress); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 116 | mUrlContainer = findViewById(R.id.urlbar_focused); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 117 | mBackButton.setOnClickListener(this); |
| 118 | mForwardButton.setOnClickListener(this); |
| 119 | mStar.setOnClickListener(this); |
| 120 | mAllButton.setOnClickListener(this); |
| 121 | mStopButton.setOnClickListener(this); |
| 122 | mSearchButton.setOnClickListener(this); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 123 | mGoButton.setOnClickListener(this); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 124 | mClearButton.setOnClickListener(this); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 125 | mVoiceSearch.setOnClickListener(this); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 126 | mUrlInput.setContainer(mUrlContainer); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 127 | setFocusState(false); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 128 | } |
| 129 | |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 130 | void updateNavigationState(Tab tab) { |
| 131 | WebView web = tab.getWebView(); |
| 132 | if (web != null) { |
| 133 | mBackButton.setImageResource(web.canGoBack() |
| 134 | ? R.drawable.ic_back_holo_dark |
| 135 | : R.drawable.ic_back_disabled_holo_dark); |
| 136 | mForwardButton.setImageResource(web.canGoForward() |
| 137 | ? R.drawable.ic_forward_holo_dark |
| 138 | : R.drawable.ic_forward_disabled_holo_dark); |
| 139 | } |
| 140 | } |
| 141 | |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 142 | private ViewGroup.LayoutParams makeLayoutParams() { |
| 143 | if (mUseQuickControls) { |
| 144 | return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, |
| 145 | LayoutParams.WRAP_CONTENT); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 146 | } else { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 147 | return new AbsoluteLayout.LayoutParams( |
| 148 | LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, |
| 149 | 0, 0); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | |
Michael Kolb | 29ccf8a | 2011-02-23 16:13:24 -0800 | [diff] [blame] | 153 | @Override |
| 154 | public int getEmbeddedHeight() { |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 155 | int height = mContainer.getHeight(); |
| 156 | if (mAutoLogin.getVisibility() == View.VISIBLE) { |
| 157 | height += mAutoLogin.getHeight(); |
| 158 | } |
| 159 | return height; |
Michael Kolb | 29ccf8a | 2011-02-23 16:13:24 -0800 | [diff] [blame] | 160 | } |
| 161 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 162 | void setUseQuickControls(boolean useQuickControls) { |
| 163 | mUseQuickControls = useQuickControls; |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 164 | setLayoutParams(makeLayoutParams()); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | void setShowProgressOnly(boolean progress) { |
Michael Kolb | 8a4c382 | 2011-03-15 14:52:05 -0700 | [diff] [blame] | 168 | if (progress && !inAutoLogin()) { |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 169 | mContainer.setVisibility(View.GONE); |
| 170 | } else { |
| 171 | mContainer.setVisibility(View.VISIBLE); |
| 172 | } |
| 173 | } |
| 174 | |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 175 | @Override |
| 176 | public void onFocusChange(View view, boolean hasFocus) { |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 177 | // if losing focus and not in touch mode, leave as is |
| 178 | if (hasFocus || view.isInTouchMode() || mUrlInput.needsUpdate()) { |
| 179 | setFocusState(hasFocus); |
| 180 | mUrlContainer.setBackgroundDrawable(hasFocus |
| 181 | ? mFocusDrawable : mUnfocusDrawable); |
| 182 | } |
| 183 | if (hasFocus) { |
| 184 | mUrlInput.forceIme(); |
| 185 | if (mInVoiceMode) { |
| 186 | mUrlInput.forceFilter(); |
| 187 | } |
| 188 | } else if (!mUrlInput.needsUpdate()) { |
| 189 | mUrlInput.dismissDropDown(); |
| 190 | mUrlInput.hideIME(); |
Michael Kolb | 2a56eca | 2011-02-25 09:45:06 -0800 | [diff] [blame] | 191 | if (mUseQuickControls) { |
| 192 | mUi.hideTitleBar(); |
| 193 | } |
Narayan Kamath | c93a2a9 | 2011-03-15 11:33:52 +0000 | [diff] [blame] | 194 | |
| 195 | if (mUrlInput.getText().length() == 0) { |
| 196 | Tab currentTab = mUiController.getTabControl().getCurrentTab(); |
| 197 | if (currentTab != null) { |
| 198 | mUrlInput.setText(currentTab.getUrl(), false); |
| 199 | } |
| 200 | } |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 201 | } |
| 202 | mUrlInput.clearNeedsUpdate(); |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 203 | } |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 204 | |
John Reck | 94b7e04 | 2011-02-15 15:02:33 -0800 | [diff] [blame] | 205 | @Override |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 206 | public void setCurrentUrlIsBookmark(boolean isBookmark) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 207 | mStar.setActivated(isBookmark); |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 208 | } |
| 209 | |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 210 | /** |
| 211 | * called from the Ui when the user wants to edit |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 212 | * @param clearInput clear the input field |
| 213 | */ |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 214 | void startEditingUrl(boolean clearInput) { |
Michael Kolb | bd018d4 | 2010-12-15 15:43:39 -0800 | [diff] [blame] | 215 | // editing takes preference of progress |
| 216 | mContainer.setVisibility(View.VISIBLE); |
| 217 | if (mUseQuickControls) { |
| 218 | mProgressView.setVisibility(View.GONE); |
| 219 | } |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 220 | if (!mUrlInput.hasFocus()) { |
| 221 | mUrlInput.requestFocus(); |
| 222 | } |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 223 | if (clearInput) { |
| 224 | mUrlInput.setText(""); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 225 | } else if (mInVoiceMode) { |
| 226 | mUrlInput.showDropDown(); |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame^] | 230 | @Override |
| 231 | protected void showAutoLogin(boolean animate) { |
| 232 | if (mUseQuickControls) { |
| 233 | mUi.showTitleBar(); |
| 234 | } |
| 235 | super.showAutoLogin(animate); |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 236 | } |
| 237 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame^] | 238 | @Override |
| 239 | protected void hideAutoLogin(boolean animate) { |
| 240 | mAutoLoginHandler = null; |
| 241 | if (mUseQuickControls) { |
| 242 | mUi.hideTitleBar(); |
| 243 | mAutoLogin.setVisibility(View.GONE); |
| 244 | mUi.refreshWebView(); |
| 245 | } else { |
| 246 | super.hideAutoLogin(animate); |
| 247 | } |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 248 | } |
| 249 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 250 | @Override |
| 251 | public void onClick(View v) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 252 | if (mBackButton == v) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 253 | mUiController.getCurrentTopWebView().goBack(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 254 | } else if (mForwardButton == v) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 255 | mUiController.getCurrentTopWebView().goForward(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 256 | } else if (mStar == v) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 257 | mUiController.bookmarkCurrentPage( |
Leon Scroggins | bdff8a7 | 2011-02-11 15:49:04 -0500 | [diff] [blame] | 258 | AddBookmarkPage.DEFAULT_FOLDER_ID, true); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 259 | } else if (mAllButton == v) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 260 | mUiController.bookmarksOrHistoryPicker(false); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 261 | } else if (mSearchButton == v) { |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 262 | mUi.editUrl(true); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 263 | } else if (mStopButton == v) { |
| 264 | stopOrRefresh(); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 265 | } else if (mGoButton == v) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 266 | if (!TextUtils.isEmpty(mUrlInput.getText())) { |
| 267 | onAction(mUrlInput.getText().toString(), null, |
Michael Kolb | 257cc2c | 2010-12-09 09:45:52 -0800 | [diff] [blame] | 268 | UrlInputView.TYPED); |
Michael Kolb | 1ce7813 | 2010-09-23 15:50:53 -0700 | [diff] [blame] | 269 | } |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 270 | } else if (mClearButton == v) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 271 | clearOrClose(); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 272 | } else if (mVoiceSearch == v) { |
| 273 | mUiController.startVoiceSearch(); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame^] | 274 | } else { |
| 275 | super.onClick(v); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 276 | } |
| 277 | } |
| 278 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 279 | @Override |
| 280 | void setFavicon(Bitmap icon) { } |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 281 | |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 282 | private void clearOrClose() { |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 283 | if (TextUtils.isEmpty(mUrlInput.getUserText())) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 284 | // close |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 285 | mUrlInput.clearFocus(); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 286 | } else { |
| 287 | // clear |
| 288 | mUrlInput.setText(""); |
| 289 | } |
| 290 | } |
| 291 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame^] | 292 | @Override |
| 293 | protected void setFocusState(boolean focus) { |
| 294 | super.setFocusState(focus); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 295 | if (focus) { |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 296 | mSearchButton.setVisibility(View.GONE); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 297 | mStar.setVisibility(View.GONE); |
| 298 | mClearButton.setVisibility(View.VISIBLE); |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 299 | mUrlIcon.setImageResource(R.drawable.ic_search_holo_dark); |
Michael Kolb | 60a68f5 | 2011-02-24 11:02:52 -0800 | [diff] [blame] | 300 | updateSearchMode(false); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 301 | } else { |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 302 | mGoButton.setVisibility(View.GONE); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 303 | mVoiceSearch.setVisibility(View.GONE); |
| 304 | mStar.setVisibility(View.VISIBLE); |
| 305 | mClearButton.setVisibility(View.GONE); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 306 | if (mUseQuickControls) { |
| 307 | mSearchButton.setVisibility(View.GONE); |
| 308 | } else { |
| 309 | mSearchButton.setVisibility(View.VISIBLE); |
| 310 | } |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 311 | mUrlIcon.setImageResource(mInVoiceMode ? |
| 312 | R.drawable.ic_search_holo_dark |
| 313 | : R.drawable.ic_web_holo_dark); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 317 | private void stopOrRefresh() { |
| 318 | if (mInLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 319 | mUiController.stopLoading(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 320 | } else { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 321 | mUiController.getCurrentTopWebView().reload(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 322 | } |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | /** |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 326 | * Update the progress, from 0 to 100. |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 327 | */ |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 328 | @Override |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 329 | void setProgress(int newProgress) { |
Michael Kolb | bd018d4 | 2010-12-15 15:43:39 -0800 | [diff] [blame] | 330 | boolean blockvisuals = mUseQuickControls && isEditingUrl(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 331 | if (newProgress >= PROGRESS_MAX) { |
Michael Kolb | bd018d4 | 2010-12-15 15:43:39 -0800 | [diff] [blame] | 332 | if (!blockvisuals) { |
| 333 | mProgressView.setProgress(PageProgressView.MAX_PROGRESS); |
| 334 | mProgressView.setVisibility(View.GONE); |
| 335 | mStopButton.setImageDrawable(mReloadDrawable); |
| 336 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 337 | mInLoad = false; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 338 | } else { |
| 339 | if (!mInLoad) { |
Michael Kolb | bd018d4 | 2010-12-15 15:43:39 -0800 | [diff] [blame] | 340 | if (!blockvisuals) { |
| 341 | mProgressView.setVisibility(View.VISIBLE); |
| 342 | mStopButton.setImageDrawable(mStopDrawable); |
| 343 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 344 | mInLoad = true; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 345 | } |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 346 | mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS |
| 347 | / PROGRESS_MAX); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 348 | } |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame^] | 351 | @Override |
| 352 | protected void updateSearchMode(boolean userEdited) { |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 353 | setSearchMode(!userEdited || TextUtils.isEmpty(mUrlInput.getUserText())); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 354 | } |
| 355 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame^] | 356 | @Override |
| 357 | protected void setSearchMode(boolean voiceSearchEnabled) { |
Michael Kolb | 793e05e | 2011-01-11 15:17:31 -0800 | [diff] [blame] | 358 | boolean showvoicebutton = voiceSearchEnabled && |
Michael Kolb | 736990c | 2011-03-20 10:01:20 -0700 | [diff] [blame] | 359 | mUiController.supportsVoiceSearch(); |
Michael Kolb | 793e05e | 2011-01-11 15:17:31 -0800 | [diff] [blame] | 360 | mVoiceSearch.setVisibility(showvoicebutton ? View.VISIBLE : |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 361 | View.GONE); |
| 362 | mGoButton.setVisibility(voiceSearchEnabled ? View.GONE : |
| 363 | View.VISIBLE); |
| 364 | } |
| 365 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 366 | @Override |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 367 | public void setInVoiceMode(boolean voicemode, List<String> voiceResults) { |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame^] | 368 | super.setInVoiceMode(voicemode, voiceResults); |
Michael Kolb | 3aaef25 | 2011-03-09 18:13:56 -0800 | [diff] [blame] | 369 | if (voicemode) { |
| 370 | mUrlIcon.setImageDrawable(mSearchButton.getDrawable()); |
| 371 | } |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 372 | } |
| 373 | |
John Reck | 117f07d | 2011-01-24 09:39:03 -0800 | [diff] [blame] | 374 | @Override |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 375 | public View focusSearch(View focused, int dir) { |
| 376 | if (FOCUS_DOWN == dir && hasFocus()) { |
| 377 | return getCurrentWebView(); |
| 378 | } |
| 379 | return super.focusSearch(focused, dir); |
| 380 | } |
| 381 | |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 382 | } |