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