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