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