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