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 | |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 19 | import com.android.browser.UI.DropdownChangeListener; |
Michael Kolb | 3aaef25 | 2011-03-09 18:13:56 -0800 | [diff] [blame] | 20 | import com.android.browser.autocomplete.SuggestedTextController.TextChangeWatcher; |
Michael Kolb | 793e05e | 2011-01-11 15:17:31 -0800 | [diff] [blame] | 21 | import com.android.browser.search.SearchEngine; |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 22 | |
Michael Kolb | 0c425da | 2011-05-19 14:35:45 -0700 | [diff] [blame] | 23 | import android.animation.Animator; |
| 24 | import android.animation.Animator.AnimatorListener; |
| 25 | import android.animation.AnimatorSet; |
| 26 | import android.animation.ObjectAnimator; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 27 | import android.app.Activity; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 28 | import android.content.Context; |
Michael Kolb | 0c425da | 2011-05-19 14:35:45 -0700 | [diff] [blame] | 29 | import android.content.res.Configuration; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 30 | import android.content.res.Resources; |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 31 | import android.graphics.Bitmap; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 32 | import android.graphics.drawable.Drawable; |
Michael Kolb | 1ce7813 | 2010-09-23 15:50:53 -0700 | [diff] [blame] | 33 | import android.text.TextUtils; |
John Reck | f94df7e | 2011-03-14 16:28:56 -0700 | [diff] [blame] | 34 | import android.view.ContextThemeWrapper; |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 35 | import android.view.KeyEvent; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 36 | import android.view.LayoutInflater; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 37 | import android.view.View; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 38 | import android.view.View.OnClickListener; |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 39 | import android.view.View.OnFocusChangeListener; |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 40 | import android.view.ViewGroup; |
John Reck | f94df7e | 2011-03-14 16:28:56 -0700 | [diff] [blame] | 41 | import android.view.animation.Animation; |
| 42 | import android.view.animation.Animation.AnimationListener; |
| 43 | import android.view.animation.AnimationUtils; |
Michael Kolb | b6bc32c | 2010-12-10 11:51:54 -0800 | [diff] [blame] | 44 | import android.webkit.WebView; |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 45 | import android.widget.AbsoluteLayout; |
John Reck | f94df7e | 2011-03-14 16:28:56 -0700 | [diff] [blame] | 46 | import android.widget.ArrayAdapter; |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 47 | import android.widget.Button; |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 48 | import android.widget.FrameLayout; |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 49 | import android.widget.ImageButton; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 50 | import android.widget.ImageView; |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 51 | import android.widget.ProgressBar; |
John Reck | f94df7e | 2011-03-14 16:28:56 -0700 | [diff] [blame] | 52 | import android.widget.Spinner; |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 53 | import android.widget.TextView; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 54 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 55 | import java.util.List; |
| 56 | |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 57 | /** |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 58 | * tabbed title bar for xlarge screen browser |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 59 | */ |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 60 | public class TitleBarXLarge extends TitleBarBase |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 61 | implements OnClickListener, OnFocusChangeListener, TextChangeWatcher, |
| 62 | DeviceAccountLogin.AutoLoginCallback { |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 63 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 64 | private XLargeUi mUi; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 65 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 66 | private Drawable mStopDrawable; |
| 67 | private Drawable mReloadDrawable; |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 68 | |
Michael Kolb | 3f65c38 | 2010-08-20 15:31:16 -0700 | [diff] [blame] | 69 | private View mContainer; |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 70 | private ImageButton mBackButton; |
| 71 | private ImageButton mForwardButton; |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 72 | private ImageView mStar; |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 73 | private ImageView mUrlIcon; |
| 74 | private ImageView mSearchButton; |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 75 | private View mUrlContainer; |
Michael Kolb | 0c425da | 2011-05-19 14:35:45 -0700 | [diff] [blame] | 76 | private View mNavButtons; |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 77 | private View mGoButton; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 78 | private ImageView mStopButton; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 79 | private View mAllButton; |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 80 | private View mClearButton; |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 81 | private ImageView mVoiceSearch; |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 82 | private PageProgressView mProgressView; |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 83 | private Drawable mFocusDrawable; |
| 84 | private Drawable mUnfocusDrawable; |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 85 | // Auto-login UI |
| 86 | private View mAutoLogin; |
John Reck | f94df7e | 2011-03-14 16:28:56 -0700 | [diff] [blame] | 87 | private Spinner mAutoLoginAccount; |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 88 | private Button mAutoLoginLogin; |
| 89 | private ProgressBar mAutoLoginProgress; |
| 90 | private TextView mAutoLoginError; |
| 91 | private ImageButton mAutoLoginCancel; |
| 92 | private DeviceAccountLogin mAutoLoginHandler; |
John Reck | f94df7e | 2011-03-14 16:28:56 -0700 | [diff] [blame] | 93 | private ArrayAdapter<String> mAccountsAdapter; |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 94 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 95 | private boolean mInLoad; |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 96 | private boolean mUseQuickControls; |
Michael Kolb | 0c425da | 2011-05-19 14:35:45 -0700 | [diff] [blame] | 97 | private boolean mHideNavButtons; |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 98 | |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 99 | public TitleBarXLarge(Activity activity, UiController controller, |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 100 | XLargeUi ui) { |
John Reck | 9202673 | 2011-02-15 10:12:30 -0800 | [diff] [blame] | 101 | super(activity, controller, ui); |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 102 | mUi = ui; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 103 | Resources resources = activity.getResources(); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 104 | mStopDrawable = resources.getDrawable(R.drawable.ic_stop_holo_dark); |
| 105 | mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_holo_dark); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 106 | mFocusDrawable = resources.getDrawable( |
| 107 | R.drawable.textfield_active_holo_dark); |
| 108 | mUnfocusDrawable = resources.getDrawable( |
| 109 | R.drawable.textfield_default_holo_dark); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 110 | mInVoiceMode = false; |
Michael Kolb | 3aaef25 | 2011-03-09 18:13:56 -0800 | [diff] [blame] | 111 | initLayout(activity); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 112 | } |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 113 | |
John Reck | 1605bef | 2011-01-10 18:11:18 -0800 | [diff] [blame] | 114 | private void initLayout(Context context) { |
Michael Kolb | 0c425da | 2011-05-19 14:35:45 -0700 | [diff] [blame] | 115 | Resources res = mContext.getResources(); |
| 116 | mHideNavButtons = res.getBoolean(R.bool.hide_nav_buttons); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 117 | LayoutInflater factory = LayoutInflater.from(context); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 118 | factory.inflate(R.layout.url_bar, this); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 119 | |
Michael Kolb | 3f65c38 | 2010-08-20 15:31:16 -0700 | [diff] [blame] | 120 | mContainer = findViewById(R.id.taburlbar); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 121 | mUrlInput = (UrlInputView) findViewById(R.id.url_focused); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 122 | mAllButton = findViewById(R.id.all_btn); |
| 123 | // TODO: Change enabled states based on whether you can go |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 124 | // back/forward. Probably should be done inside onPageStarted. |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 125 | mBackButton = (ImageButton) findViewById(R.id.back); |
| 126 | mForwardButton = (ImageButton) findViewById(R.id.forward); |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 127 | mUrlIcon = (ImageView) findViewById(R.id.url_icon); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 128 | mStar = (ImageView) findViewById(R.id.star); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 129 | mStopButton = (ImageView) findViewById(R.id.stop); |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 130 | mSearchButton = (ImageView) findViewById(R.id.search); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 131 | mLockIcon = (ImageView) findViewById(R.id.lock); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 132 | mGoButton = findViewById(R.id.go); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 133 | mClearButton = findViewById(R.id.clear); |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 134 | mVoiceSearch = (ImageView) findViewById(R.id.voicesearch); |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 135 | mProgressView = (PageProgressView) findViewById(R.id.progress); |
Michael Kolb | 0c425da | 2011-05-19 14:35:45 -0700 | [diff] [blame] | 136 | mNavButtons = findViewById(R.id.navbuttons); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 137 | mUrlContainer = findViewById(R.id.urlbar_focused); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 138 | mBackButton.setOnClickListener(this); |
| 139 | mForwardButton.setOnClickListener(this); |
| 140 | mStar.setOnClickListener(this); |
| 141 | mAllButton.setOnClickListener(this); |
| 142 | mStopButton.setOnClickListener(this); |
| 143 | mSearchButton.setOnClickListener(this); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 144 | mGoButton.setOnClickListener(this); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 145 | mClearButton.setOnClickListener(this); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 146 | mVoiceSearch.setOnClickListener(this); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 147 | mUrlInput.setUrlInputListener(this); |
| 148 | mUrlInput.setContainer(mUrlContainer); |
| 149 | mUrlInput.setController(mUiController); |
| 150 | mUrlInput.setOnFocusChangeListener(this); |
| 151 | mUrlInput.setSelectAllOnFocus(true); |
Narayan Kamath | 80aad8d | 2011-02-23 12:01:13 +0000 | [diff] [blame] | 152 | mUrlInput.addQueryTextWatcher(this); |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 153 | mAutoLogin = findViewById(R.id.autologin); |
John Reck | f94df7e | 2011-03-14 16:28:56 -0700 | [diff] [blame] | 154 | mAutoLoginAccount = (Spinner) findViewById(R.id.autologin_account); |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 155 | mAutoLoginLogin = (Button) findViewById(R.id.autologin_login); |
| 156 | mAutoLoginLogin.setOnClickListener(this); |
| 157 | mAutoLoginProgress = |
| 158 | (ProgressBar) findViewById(R.id.autologin_progress); |
| 159 | mAutoLoginError = (TextView) findViewById(R.id.autologin_error); |
| 160 | mAutoLoginCancel = |
| 161 | (ImageButton) mAutoLogin.findViewById(R.id.autologin_close); |
| 162 | mAutoLoginCancel.setOnClickListener(this); |
| 163 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 164 | setFocusState(false); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 165 | } |
| 166 | |
Michael Kolb | 0c425da | 2011-05-19 14:35:45 -0700 | [diff] [blame] | 167 | @Override |
| 168 | public void onConfigurationChanged(Configuration config) { |
| 169 | super.onConfigurationChanged(config); |
| 170 | Resources res = mContext.getResources(); |
| 171 | mHideNavButtons = res.getBoolean(R.bool.hide_nav_buttons); |
| 172 | if (mUrlInput.hasFocus()) { |
| 173 | if (mHideNavButtons && (mNavButtons.getVisibility() == View.VISIBLE)) { |
| 174 | int aw = mNavButtons.getMeasuredWidth(); |
| 175 | mNavButtons.setVisibility(View.GONE); |
| 176 | mNavButtons.setAlpha(0f); |
| 177 | mNavButtons.setTranslationX(-aw); |
| 178 | } else if (!mHideNavButtons && (mNavButtons.getVisibility() == View.GONE)) { |
| 179 | mNavButtons.setVisibility(View.VISIBLE); |
| 180 | mNavButtons.setAlpha(1f); |
| 181 | mNavButtons.setTranslationX(0); |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 186 | void updateNavigationState(Tab tab) { |
| 187 | WebView web = tab.getWebView(); |
| 188 | if (web != null) { |
| 189 | mBackButton.setImageResource(web.canGoBack() |
| 190 | ? R.drawable.ic_back_holo_dark |
| 191 | : R.drawable.ic_back_disabled_holo_dark); |
| 192 | mForwardButton.setImageResource(web.canGoForward() |
| 193 | ? R.drawable.ic_forward_holo_dark |
| 194 | : R.drawable.ic_forward_disabled_holo_dark); |
| 195 | } |
| 196 | } |
| 197 | |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 198 | void updateAutoLogin(Tab tab, boolean animate) { |
| 199 | DeviceAccountLogin login = tab.getDeviceAccountLogin(); |
| 200 | if (login != null) { |
| 201 | mAutoLoginHandler = login; |
| 202 | mAutoLogin.setVisibility(View.VISIBLE); |
John Reck | f94df7e | 2011-03-14 16:28:56 -0700 | [diff] [blame] | 203 | ContextThemeWrapper wrapper = new ContextThemeWrapper(mContext, |
| 204 | android.R.style.Theme_Holo_Light); |
| 205 | mAccountsAdapter = new ArrayAdapter<String>(wrapper, |
| 206 | android.R.layout.simple_spinner_item, login.getAccountNames()); |
| 207 | mAccountsAdapter.setDropDownViewResource( |
| 208 | android.R.layout.simple_spinner_dropdown_item); |
| 209 | mAutoLoginAccount.setAdapter(mAccountsAdapter); |
| 210 | mAutoLoginAccount.setSelection(0); |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 211 | mAutoLoginAccount.setEnabled(true); |
| 212 | mAutoLoginLogin.setEnabled(true); |
| 213 | mAutoLoginProgress.setVisibility(View.GONE); |
| 214 | mAutoLoginError.setVisibility(View.GONE); |
| 215 | switch (login.getState()) { |
| 216 | case DeviceAccountLogin.PROCESSING: |
| 217 | mAutoLoginAccount.setEnabled(false); |
| 218 | mAutoLoginLogin.setEnabled(false); |
| 219 | mAutoLoginProgress.setVisibility(View.VISIBLE); |
| 220 | break; |
| 221 | case DeviceAccountLogin.FAILED: |
| 222 | mAutoLoginProgress.setVisibility(View.GONE); |
| 223 | mAutoLoginError.setVisibility(View.VISIBLE); |
| 224 | break; |
| 225 | case DeviceAccountLogin.INITIAL: |
| 226 | break; |
| 227 | default: |
| 228 | throw new IllegalStateException(); |
| 229 | } |
Michael Kolb | 8a4c382 | 2011-03-15 14:52:05 -0700 | [diff] [blame] | 230 | if (mUseQuickControls) { |
| 231 | mUi.showTitleBar(); |
| 232 | } else { |
| 233 | if (animate) { |
| 234 | mAutoLogin.startAnimation(AnimationUtils.loadAnimation( |
| 235 | getContext(), R.anim.autologin_enter)); |
| 236 | } |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 237 | } |
| 238 | } else { |
| 239 | mAutoLoginHandler = null; |
Michael Kolb | 8a4c382 | 2011-03-15 14:52:05 -0700 | [diff] [blame] | 240 | if (mUseQuickControls) { |
| 241 | mUi.hideTitleBar(); |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 242 | mAutoLogin.setVisibility(View.GONE); |
Michael Kolb | 2ba24b9 | 2011-03-17 10:59:10 -0700 | [diff] [blame] | 243 | mUi.refreshWebView(); |
Michael Kolb | 8a4c382 | 2011-03-15 14:52:05 -0700 | [diff] [blame] | 244 | } else { |
| 245 | if (animate) { |
| 246 | hideAutoLogin(); |
| 247 | } else if (mAutoLogin.getAnimation() == null) { |
| 248 | mAutoLogin.setVisibility(View.GONE); |
Michael Kolb | 2ba24b9 | 2011-03-17 10:59:10 -0700 | [diff] [blame] | 249 | mUi.refreshWebView(); |
Michael Kolb | 8a4c382 | 2011-03-15 14:52:05 -0700 | [diff] [blame] | 250 | } |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | } |
| 254 | |
Michael Kolb | 8a4c382 | 2011-03-15 14:52:05 -0700 | [diff] [blame] | 255 | boolean inAutoLogin() { |
| 256 | return mAutoLoginHandler != null; |
| 257 | } |
| 258 | |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 259 | private ViewGroup.LayoutParams makeLayoutParams() { |
| 260 | if (mUseQuickControls) { |
| 261 | return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, |
| 262 | LayoutParams.WRAP_CONTENT); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 263 | } else { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 264 | return new AbsoluteLayout.LayoutParams( |
| 265 | LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, |
| 266 | 0, 0); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | |
Michael Kolb | 29ccf8a | 2011-02-23 16:13:24 -0800 | [diff] [blame] | 270 | @Override |
| 271 | public int getEmbeddedHeight() { |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 272 | int height = mContainer.getHeight(); |
| 273 | if (mAutoLogin.getVisibility() == View.VISIBLE) { |
| 274 | height += mAutoLogin.getHeight(); |
| 275 | } |
| 276 | return height; |
Michael Kolb | 29ccf8a | 2011-02-23 16:13:24 -0800 | [diff] [blame] | 277 | } |
| 278 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 279 | void setUseQuickControls(boolean useQuickControls) { |
| 280 | mUseQuickControls = useQuickControls; |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 281 | setLayoutParams(makeLayoutParams()); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | void setShowProgressOnly(boolean progress) { |
Michael Kolb | 8a4c382 | 2011-03-15 14:52:05 -0700 | [diff] [blame] | 285 | if (progress && !inAutoLogin()) { |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 286 | mContainer.setVisibility(View.GONE); |
| 287 | } else { |
| 288 | mContainer.setVisibility(View.VISIBLE); |
| 289 | } |
| 290 | } |
| 291 | |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 292 | @Override |
| 293 | public void onFocusChange(View view, boolean hasFocus) { |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 294 | // if losing focus and not in touch mode, leave as is |
| 295 | if (hasFocus || view.isInTouchMode() || mUrlInput.needsUpdate()) { |
| 296 | setFocusState(hasFocus); |
| 297 | mUrlContainer.setBackgroundDrawable(hasFocus |
| 298 | ? mFocusDrawable : mUnfocusDrawable); |
| 299 | } |
| 300 | if (hasFocus) { |
| 301 | mUrlInput.forceIme(); |
| 302 | if (mInVoiceMode) { |
| 303 | mUrlInput.forceFilter(); |
| 304 | } |
| 305 | } else if (!mUrlInput.needsUpdate()) { |
| 306 | mUrlInput.dismissDropDown(); |
| 307 | mUrlInput.hideIME(); |
Michael Kolb | 2a56eca | 2011-02-25 09:45:06 -0800 | [diff] [blame] | 308 | if (mUseQuickControls) { |
| 309 | mUi.hideTitleBar(); |
| 310 | } |
Narayan Kamath | c93a2a9 | 2011-03-15 11:33:52 +0000 | [diff] [blame] | 311 | |
| 312 | if (mUrlInput.getText().length() == 0) { |
| 313 | Tab currentTab = mUiController.getTabControl().getCurrentTab(); |
| 314 | if (currentTab != null) { |
| 315 | mUrlInput.setText(currentTab.getUrl(), false); |
| 316 | } |
| 317 | } |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 318 | } |
| 319 | mUrlInput.clearNeedsUpdate(); |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 320 | } |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 321 | |
John Reck | 94b7e04 | 2011-02-15 15:02:33 -0800 | [diff] [blame] | 322 | @Override |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 323 | public void setCurrentUrlIsBookmark(boolean isBookmark) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 324 | mStar.setActivated(isBookmark); |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 325 | } |
| 326 | |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 327 | /** |
| 328 | * called from the Ui when the user wants to edit |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 329 | * @param clearInput clear the input field |
| 330 | */ |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 331 | void startEditingUrl(boolean clearInput) { |
Michael Kolb | bd018d4 | 2010-12-15 15:43:39 -0800 | [diff] [blame] | 332 | // editing takes preference of progress |
| 333 | mContainer.setVisibility(View.VISIBLE); |
| 334 | if (mUseQuickControls) { |
| 335 | mProgressView.setVisibility(View.GONE); |
| 336 | } |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 337 | if (!mUrlInput.hasFocus()) { |
| 338 | mUrlInput.requestFocus(); |
| 339 | } |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 340 | if (clearInput) { |
| 341 | mUrlInput.setText(""); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 342 | } else if (mInVoiceMode) { |
| 343 | mUrlInput.showDropDown(); |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | |
| 347 | boolean isEditingUrl() { |
| 348 | return mUrlInput.hasFocus(); |
| 349 | } |
| 350 | |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 351 | void stopEditingUrl() { |
| 352 | mUrlInput.clearFocus(); |
| 353 | } |
| 354 | |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 355 | private void hideAutoLogin() { |
| 356 | Animation anim = AnimationUtils.loadAnimation( |
| 357 | getContext(), R.anim.autologin_exit); |
| 358 | anim.setAnimationListener(new AnimationListener() { |
| 359 | @Override public void onAnimationEnd(Animation a) { |
| 360 | mAutoLogin.setVisibility(View.GONE); |
Michael Kolb | 2ba24b9 | 2011-03-17 10:59:10 -0700 | [diff] [blame] | 361 | mUi.refreshWebView(); |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 362 | } |
| 363 | @Override public void onAnimationStart(Animation a) {} |
| 364 | @Override public void onAnimationRepeat(Animation a) {} |
| 365 | }); |
| 366 | mAutoLogin.startAnimation(anim); |
| 367 | } |
| 368 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 369 | @Override |
| 370 | public void onClick(View v) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 371 | if (mBackButton == v) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 372 | mUiController.getCurrentTopWebView().goBack(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 373 | } else if (mForwardButton == v) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 374 | mUiController.getCurrentTopWebView().goForward(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 375 | } else if (mStar == v) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 376 | mUiController.bookmarkCurrentPage( |
Leon Scroggins | bdff8a7 | 2011-02-11 15:49:04 -0500 | [diff] [blame] | 377 | AddBookmarkPage.DEFAULT_FOLDER_ID, true); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 378 | } else if (mAllButton == v) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 379 | mUiController.bookmarksOrHistoryPicker(false); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 380 | } else if (mSearchButton == v) { |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 381 | mUi.editUrl(true); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 382 | } else if (mStopButton == v) { |
| 383 | stopOrRefresh(); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 384 | } else if (mGoButton == v) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 385 | if (!TextUtils.isEmpty(mUrlInput.getText())) { |
| 386 | onAction(mUrlInput.getText().toString(), null, |
Michael Kolb | 257cc2c | 2010-12-09 09:45:52 -0800 | [diff] [blame] | 387 | UrlInputView.TYPED); |
Michael Kolb | 1ce7813 | 2010-09-23 15:50:53 -0700 | [diff] [blame] | 388 | } |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 389 | } else if (mClearButton == v) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 390 | clearOrClose(); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 391 | } else if (mVoiceSearch == v) { |
| 392 | mUiController.startVoiceSearch(); |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 393 | } else if (mAutoLoginCancel == v) { |
| 394 | if (mAutoLoginHandler != null) { |
| 395 | mAutoLoginHandler.cancel(); |
| 396 | mAutoLoginHandler = null; |
| 397 | } |
| 398 | hideAutoLogin(); |
| 399 | } else if (mAutoLoginLogin == v) { |
| 400 | if (mAutoLoginHandler != null) { |
| 401 | mAutoLoginAccount.setEnabled(false); |
| 402 | mAutoLoginLogin.setEnabled(false); |
| 403 | mAutoLoginProgress.setVisibility(View.VISIBLE); |
| 404 | mAutoLoginError.setVisibility(View.GONE); |
John Reck | f94df7e | 2011-03-14 16:28:56 -0700 | [diff] [blame] | 405 | mAutoLoginHandler.login( |
| 406 | mAutoLoginAccount.getSelectedItemPosition(), this); |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 407 | } |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 411 | @Override |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 412 | public void loginFailed() { |
| 413 | mAutoLoginAccount.setEnabled(true); |
| 414 | mAutoLoginLogin.setEnabled(true); |
| 415 | mAutoLoginProgress.setVisibility(View.GONE); |
| 416 | mAutoLoginError.setVisibility(View.VISIBLE); |
| 417 | } |
| 418 | |
| 419 | @Override |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 420 | void setFavicon(Bitmap icon) { } |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 421 | |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 422 | private void clearOrClose() { |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 423 | if (TextUtils.isEmpty(mUrlInput.getUserText())) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 424 | // close |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 425 | mUrlInput.clearFocus(); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 426 | } else { |
| 427 | // clear |
| 428 | mUrlInput.setText(""); |
| 429 | } |
| 430 | } |
| 431 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 432 | private void setFocusState(boolean focus) { |
| 433 | if (focus) { |
Michael Kolb | 0c425da | 2011-05-19 14:35:45 -0700 | [diff] [blame] | 434 | if (mHideNavButtons) { |
| 435 | hideNavButtons(); |
| 436 | } |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 437 | mUrlInput.setDropDownWidth(mUrlContainer.getWidth()); |
| 438 | mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft()); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 439 | mSearchButton.setVisibility(View.GONE); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 440 | mStar.setVisibility(View.GONE); |
| 441 | mClearButton.setVisibility(View.VISIBLE); |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 442 | mUrlIcon.setImageResource(R.drawable.ic_search_holo_dark); |
Michael Kolb | 60a68f5 | 2011-02-24 11:02:52 -0800 | [diff] [blame] | 443 | updateSearchMode(false); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 444 | } else { |
Michael Kolb | 0c425da | 2011-05-19 14:35:45 -0700 | [diff] [blame] | 445 | if (mHideNavButtons) { |
| 446 | showNavButtons(); |
| 447 | } |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 448 | mGoButton.setVisibility(View.GONE); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 449 | mVoiceSearch.setVisibility(View.GONE); |
| 450 | mStar.setVisibility(View.VISIBLE); |
| 451 | mClearButton.setVisibility(View.GONE); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 452 | if (mUseQuickControls) { |
| 453 | mSearchButton.setVisibility(View.GONE); |
| 454 | } else { |
| 455 | mSearchButton.setVisibility(View.VISIBLE); |
| 456 | } |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 457 | mUrlIcon.setImageResource(mInVoiceMode ? |
| 458 | R.drawable.ic_search_holo_dark |
| 459 | : R.drawable.ic_web_holo_dark); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 460 | } |
| 461 | } |
| 462 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 463 | private void stopOrRefresh() { |
| 464 | if (mInLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 465 | mUiController.stopLoading(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 466 | } else { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 467 | mUiController.getCurrentTopWebView().reload(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 468 | } |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | /** |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 472 | * Update the progress, from 0 to 100. |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 473 | */ |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 474 | @Override |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 475 | void setProgress(int newProgress) { |
Michael Kolb | bd018d4 | 2010-12-15 15:43:39 -0800 | [diff] [blame] | 476 | boolean blockvisuals = mUseQuickControls && isEditingUrl(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 477 | if (newProgress >= PROGRESS_MAX) { |
Michael Kolb | bd018d4 | 2010-12-15 15:43:39 -0800 | [diff] [blame] | 478 | if (!blockvisuals) { |
| 479 | mProgressView.setProgress(PageProgressView.MAX_PROGRESS); |
| 480 | mProgressView.setVisibility(View.GONE); |
| 481 | mStopButton.setImageDrawable(mReloadDrawable); |
| 482 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 483 | mInLoad = false; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 484 | } else { |
| 485 | if (!mInLoad) { |
Michael Kolb | bd018d4 | 2010-12-15 15:43:39 -0800 | [diff] [blame] | 486 | if (!blockvisuals) { |
| 487 | mProgressView.setVisibility(View.VISIBLE); |
| 488 | mStopButton.setImageDrawable(mStopDrawable); |
| 489 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 490 | mInLoad = true; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 491 | } |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 492 | mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS |
| 493 | / PROGRESS_MAX); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 494 | } |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Michael Kolb | 60a68f5 | 2011-02-24 11:02:52 -0800 | [diff] [blame] | 497 | private void updateSearchMode(boolean userEdited) { |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 498 | setSearchMode(!userEdited || TextUtils.isEmpty(mUrlInput.getUserText())); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | private void setSearchMode(boolean voiceSearchEnabled) { |
Michael Kolb | 793e05e | 2011-01-11 15:17:31 -0800 | [diff] [blame] | 502 | SearchEngine searchEngine = BrowserSettings.getInstance() |
| 503 | .getSearchEngine(); |
| 504 | boolean showvoicebutton = voiceSearchEnabled && |
| 505 | (searchEngine != null && searchEngine.supportsVoiceSearch()); |
| 506 | mVoiceSearch.setVisibility(showvoicebutton ? View.VISIBLE : |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 507 | View.GONE); |
| 508 | mGoButton.setVisibility(voiceSearchEnabled ? View.GONE : |
| 509 | View.VISIBLE); |
| 510 | } |
| 511 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 512 | @Override |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 513 | /* package */ void setDisplayTitle(String title) { |
John Reck | 4851f9e | 2010-12-22 16:40:36 -0800 | [diff] [blame] | 514 | if (!isEditingUrl()) { |
| 515 | mUrlInput.setText(title, false); |
| 516 | } |
Michael Kolb | 7b20ddd | 2010-10-14 15:03:28 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 519 | // UrlInput text watcher |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 520 | |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 521 | @Override |
Narayan Kamath | 80aad8d | 2011-02-23 12:01:13 +0000 | [diff] [blame] | 522 | public void onTextChanged(String newText) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 523 | if (mUrlInput.hasFocus()) { |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 524 | // check if input field is empty and adjust voice search state |
Michael Kolb | 60a68f5 | 2011-02-24 11:02:52 -0800 | [diff] [blame] | 525 | updateSearchMode(true); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 526 | // clear voice mode when user types |
| 527 | setInVoiceMode(false, null); |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 528 | } |
| 529 | } |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 530 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 531 | // voicesearch |
| 532 | |
| 533 | @Override |
| 534 | public void setInVoiceMode(boolean voicemode) { |
| 535 | setInVoiceMode(voicemode, null); |
| 536 | } |
| 537 | |
| 538 | public void setInVoiceMode(boolean voicemode, List<String> voiceResults) { |
| 539 | mInVoiceMode = voicemode; |
| 540 | mUrlInput.setVoiceResults(voiceResults); |
Michael Kolb | 3aaef25 | 2011-03-09 18:13:56 -0800 | [diff] [blame] | 541 | if (voicemode) { |
| 542 | mUrlIcon.setImageDrawable(mSearchButton.getDrawable()); |
| 543 | } |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 544 | } |
| 545 | |
John Reck | 117f07d | 2011-01-24 09:39:03 -0800 | [diff] [blame] | 546 | @Override |
| 547 | void setIncognitoMode(boolean incognito) { |
| 548 | mUrlInput.setIncognitoMode(incognito); |
| 549 | } |
Michael Kolb | 47171d8 | 2011-01-28 10:34:15 -0800 | [diff] [blame] | 550 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 551 | @Override |
| 552 | public View focusSearch(View focused, int dir) { |
| 553 | if (FOCUS_DOWN == dir && hasFocus()) { |
| 554 | return getCurrentWebView(); |
| 555 | } |
| 556 | return super.focusSearch(focused, dir); |
| 557 | } |
| 558 | |
Narayan Kamath | 67b8c1b | 2011-03-09 20:47:52 +0000 | [diff] [blame] | 559 | void clearCompletions() { |
| 560 | mUrlInput.setSuggestedText(null); |
| 561 | } |
| 562 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 563 | @Override |
| 564 | public boolean dispatchKeyEventPreIme(KeyEvent evt) { |
| 565 | if (evt.getKeyCode() == KeyEvent.KEYCODE_BACK) { |
| 566 | // catch back key in order to do slightly more cleanup than usual |
| 567 | mUrlInput.clearFocus(); |
| 568 | return true; |
| 569 | } |
| 570 | return super.dispatchKeyEventPreIme(evt); |
| 571 | } |
| 572 | |
| 573 | private WebView getCurrentWebView() { |
| 574 | Tab t = mUi.getActiveTab(); |
| 575 | if (t != null) { |
| 576 | return t.getWebView(); |
| 577 | } else { |
| 578 | return null; |
| 579 | } |
| 580 | } |
| 581 | |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 582 | void registerDropdownChangeListener(DropdownChangeListener d) { |
| 583 | mUrlInput.registerDropdownChangeListener(d); |
| 584 | } |
Michael Kolb | 0c425da | 2011-05-19 14:35:45 -0700 | [diff] [blame] | 585 | |
| 586 | private void hideNavButtons() { |
| 587 | int awidth = mNavButtons.getMeasuredWidth(); |
| 588 | Animator anim1 = ObjectAnimator.ofFloat(mNavButtons, "translationX", 0, - awidth); |
| 589 | Animator anim2 = ObjectAnimator.ofInt(mUrlContainer, "left", mUrlContainer.getLeft(), |
| 590 | mUrlContainer.getPaddingLeft()); |
| 591 | Animator anim3 = ObjectAnimator.ofFloat(mNavButtons, "alpha", 1f, 0f); |
| 592 | AnimatorSet combo = new AnimatorSet(); |
| 593 | combo.playTogether(anim1, anim2, anim3); |
| 594 | combo.addListener(new AnimatorListener() { |
| 595 | |
| 596 | @Override |
| 597 | public void onAnimationCancel(Animator animation) { |
| 598 | } |
| 599 | |
| 600 | @Override |
| 601 | public void onAnimationEnd(Animator animation) { |
| 602 | mNavButtons.setVisibility(View.GONE); |
| 603 | } |
| 604 | |
| 605 | @Override |
| 606 | public void onAnimationRepeat(Animator animation) { |
| 607 | } |
| 608 | |
| 609 | @Override |
| 610 | public void onAnimationStart(Animator animation) { |
| 611 | } |
| 612 | }); |
| 613 | combo.setDuration(150); |
| 614 | combo.start(); |
| 615 | } |
| 616 | |
| 617 | private void showNavButtons() { |
| 618 | int awidth = mNavButtons.getMeasuredWidth(); |
| 619 | Animator anim1 = ObjectAnimator.ofFloat(mNavButtons, "translationX", -awidth, 0); |
| 620 | Animator anim2 = ObjectAnimator.ofInt(mUrlContainer, "left", 0, awidth); |
| 621 | Animator anim3 = ObjectAnimator.ofFloat(mNavButtons, "alpha", 0f, 1f); |
| 622 | AnimatorSet combo = new AnimatorSet(); |
| 623 | combo.playTogether(anim1, anim2, anim3); |
| 624 | mNavButtons.setVisibility(View.VISIBLE); |
| 625 | combo.setDuration(150); |
| 626 | combo.start(); |
| 627 | } |
| 628 | |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 629 | } |