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