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