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; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 36 | import android.widget.ImageView; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 37 | |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 38 | /** |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 39 | * tabbed title bar for xlarge screen browser |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 40 | */ |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 41 | public class TitleBarXLarge extends TitleBarBase |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 42 | implements UrlInputListener, OnClickListener, OnFocusChangeListener, |
| 43 | TextWatcher { |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 44 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 45 | private static final int PROGRESS_MAX = 100; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 46 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 47 | private UiController mUiController; |
| 48 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 49 | private Drawable mStopDrawable; |
| 50 | private Drawable mReloadDrawable; |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 51 | |
Michael Kolb | 3f65c38 | 2010-08-20 15:31:16 -0700 | [diff] [blame] | 52 | private View mContainer; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 53 | private View mBackButton; |
| 54 | private View mForwardButton; |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 55 | private ImageView mStar; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 56 | private View mSearchButton; |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 57 | private View mUrlContainer; |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 58 | private View mGoButton; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 59 | private ImageView mStopButton; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 60 | private View mAllButton; |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 61 | private View mClearButton; |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 62 | private View mVoiceSearch; |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 63 | private PageProgressView mProgressView; |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 64 | private UrlInputView mUrlInput; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 65 | private boolean mInLoad; |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 66 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 67 | public TitleBarXLarge(Activity activity, UiController controller) { |
| 68 | super(activity); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 69 | mUiController = controller; |
| 70 | Resources resources = activity.getResources(); |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 71 | mStopDrawable = resources.getDrawable(R.drawable.ic_stop_normal); |
| 72 | mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_normal); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 73 | rebuildLayout(activity, true); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 74 | } |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 75 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 76 | private void rebuildLayout(Context context, boolean rebuildData) { |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 77 | LayoutInflater factory = LayoutInflater.from(context); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 78 | factory.inflate(R.layout.url_bar, this); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 79 | |
Michael Kolb | 3f65c38 | 2010-08-20 15:31:16 -0700 | [diff] [blame] | 80 | mContainer = findViewById(R.id.taburlbar); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 81 | mUrlInput = (UrlInputView) findViewById(R.id.url_focused); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 82 | mAllButton = findViewById(R.id.all_btn); |
| 83 | // TODO: Change enabled states based on whether you can go |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 84 | // back/forward. Probably should be done inside onPageStarted. |
| 85 | mBackButton = findViewById(R.id.back); |
| 86 | mForwardButton = findViewById(R.id.forward); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 87 | mStar = (ImageView) findViewById(R.id.star); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 88 | mStopButton = (ImageView) findViewById(R.id.stop); |
| 89 | mSearchButton = findViewById(R.id.search); |
| 90 | mLockIcon = (ImageView) findViewById(R.id.lock); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 91 | mGoButton = findViewById(R.id.go); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 92 | mClearButton = findViewById(R.id.clear); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 93 | mVoiceSearch = findViewById(R.id.voicesearch); |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 94 | mProgressView = (PageProgressView) findViewById(R.id.progress); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 95 | mUrlContainer = findViewById(R.id.urlbar_focused); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 96 | mBackButton.setOnClickListener(this); |
| 97 | mForwardButton.setOnClickListener(this); |
| 98 | mStar.setOnClickListener(this); |
| 99 | mAllButton.setOnClickListener(this); |
| 100 | mStopButton.setOnClickListener(this); |
| 101 | mSearchButton.setOnClickListener(this); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 102 | mGoButton.setOnClickListener(this); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 103 | mClearButton.setOnClickListener(this); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 104 | mUrlContainer.setOnClickListener(this); |
| 105 | mUrlInput.setUrlInputListener(this); |
| 106 | mUrlInput.setContainer(mUrlContainer); |
| 107 | mUrlInput.setController(mUiController); |
| 108 | mUrlInput.setOnFocusChangeListener(this); |
| 109 | mUrlInput.setSelectAllOnFocus(true); |
| 110 | mUrlInput.addTextChangedListener(this); |
| 111 | setUrlMode(false); |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public void onFocusChange(View view, boolean hasFocus) { |
| 116 | setUrlMode(hasFocus); |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 117 | } |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 118 | |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 119 | public void setCurrentUrlIsBookmark(boolean isBookmark) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 120 | mStar.setActivated(isBookmark); |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 121 | } |
| 122 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 123 | @Override |
| 124 | public void onClick(View v) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 125 | if (mBackButton == v) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 126 | mUiController.getCurrentTopWebView().goBack(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 127 | } else if (mForwardButton == v) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 128 | mUiController.getCurrentTopWebView().goForward(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 129 | } else if (mStar == v) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 130 | mUiController.bookmarkCurrentPage( |
Leon Scroggins | 88d0803 | 2010-10-21 15:17:10 -0400 | [diff] [blame] | 131 | AddBookmarkPage.DEFAULT_FOLDER_ID); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 132 | } else if (mAllButton == v) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 133 | mUiController.bookmarksOrHistoryPicker(false); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 134 | } else if (mSearchButton == v) { |
| 135 | search(); |
| 136 | } else if (mStopButton == v) { |
| 137 | stopOrRefresh(); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 138 | } else if (mGoButton == v) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 139 | if (!TextUtils.isEmpty(mUrlInput.getText())) { |
| 140 | onAction(mUrlInput.getText().toString(), null, |
Michael Kolb | 257cc2c | 2010-12-09 09:45:52 -0800 | [diff] [blame] | 141 | UrlInputView.TYPED); |
Michael Kolb | 1ce7813 | 2010-09-23 15:50:53 -0700 | [diff] [blame] | 142 | } |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 143 | } else if (mClearButton == v) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 144 | clearOrClose(); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | |
Michael Kolb | 3f65c38 | 2010-08-20 15:31:16 -0700 | [diff] [blame] | 148 | int getHeightWithoutProgress() { |
| 149 | return mContainer.getHeight(); |
| 150 | } |
| 151 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 152 | @Override |
| 153 | void setFavicon(Bitmap icon) { } |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 154 | |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 155 | private void clearOrClose() { |
| 156 | if (TextUtils.isEmpty(mUrlInput.getText())) { |
| 157 | // close |
| 158 | setUrlMode(false); |
| 159 | } else { |
| 160 | // clear |
| 161 | mUrlInput.setText(""); |
| 162 | } |
| 163 | } |
| 164 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 165 | // UrlInputListener implementation |
| 166 | |
| 167 | @Override |
Michael Kolb | 257cc2c | 2010-12-09 09:45:52 -0800 | [diff] [blame] | 168 | public void onAction(String text, String extra, String source) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 169 | mUiController.getCurrentTopWebView().requestFocus(); |
| 170 | ((BaseUi) mUiController.getUi()).hideFakeTitleBar(); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 171 | Intent i = new Intent(); |
| 172 | i.setAction(Intent.ACTION_SEARCH); |
| 173 | i.putExtra(SearchManager.QUERY, text); |
John Reck | 40f720e | 2010-11-10 11:57:04 -0800 | [diff] [blame] | 174 | if (extra != null) { |
| 175 | i.putExtra(SearchManager.EXTRA_DATA_KEY, extra); |
| 176 | } |
Michael Kolb | 257cc2c | 2010-12-09 09:45:52 -0800 | [diff] [blame] | 177 | if (source != null) { |
| 178 | Bundle appData = new Bundle(); |
| 179 | appData.putString(com.android.common.Search.SOURCE, source); |
| 180 | i.putExtra(SearchManager.APP_DATA, appData); |
| 181 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 182 | mUiController.handleNewIntent(i); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 183 | setUrlMode(false); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 184 | setDisplayTitle(text); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | @Override |
| 188 | public void onDismiss() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 189 | mUiController.getCurrentTopWebView().requestFocus(); |
| 190 | ((BaseUi) mUiController.getUi()).hideFakeTitleBar(); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 191 | setUrlMode(false); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 192 | setDisplayTitle(mUiController.getCurrentWebView().getUrl()); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | @Override |
| 196 | public void onEdit(String text) { |
Michael Kolb | 7b20ddd | 2010-10-14 15:03:28 -0700 | [diff] [blame] | 197 | setDisplayTitle(text, true); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 198 | if (text != null) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 199 | mUrlInput.setSelection(text.length()); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 203 | private void setUrlMode(boolean focused) { |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 204 | if (focused) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 205 | mUrlInput.setDropDownWidth(mUrlContainer.getWidth()); |
| 206 | mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft()); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 207 | mSearchButton.setVisibility(View.GONE); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 208 | mStar.setVisibility(View.GONE); |
| 209 | mClearButton.setVisibility(View.VISIBLE); |
| 210 | updateSearchMode(); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 211 | } else { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 212 | mUrlInput.clearFocus(); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 213 | mSearchButton.setVisibility(View.VISIBLE); |
| 214 | mGoButton.setVisibility(View.GONE); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 215 | mVoiceSearch.setVisibility(View.GONE); |
| 216 | mStar.setVisibility(View.VISIBLE); |
| 217 | mClearButton.setVisibility(View.GONE); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 218 | } |
| 219 | } |
| 220 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 221 | private void search() { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 222 | mUrlInput.requestFocus(); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 223 | setDisplayTitle(""); |
Michael Kolb | ffce12c | 2010-12-06 19:05:25 -0800 | [diff] [blame] | 224 | setUrlMode(true); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 227 | private void stopOrRefresh() { |
| 228 | if (mInLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 229 | mUiController.stopLoading(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 230 | } else { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 231 | mUiController.getCurrentTopWebView().reload(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 232 | } |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | /** |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 236 | * Update the progress, from 0 to 100. |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 237 | */ |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 238 | @Override |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 239 | void setProgress(int newProgress) { |
| 240 | if (newProgress >= PROGRESS_MAX) { |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 241 | mProgressView.setProgress(PageProgressView.MAX_PROGRESS); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 242 | mProgressView.setVisibility(View.GONE); |
| 243 | mInLoad = false; |
| 244 | mStopButton.setImageDrawable(mReloadDrawable); |
| 245 | } else { |
| 246 | if (!mInLoad) { |
| 247 | mProgressView.setVisibility(View.VISIBLE); |
| 248 | mInLoad = true; |
| 249 | mStopButton.setImageDrawable(mStopDrawable); |
| 250 | } |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 251 | mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS |
| 252 | / PROGRESS_MAX); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 253 | } |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 256 | private void updateSearchMode() { |
| 257 | setSearchMode(TextUtils.isEmpty(mUrlInput.getText())); |
| 258 | } |
| 259 | |
| 260 | private void setSearchMode(boolean voiceSearchEnabled) { |
| 261 | mVoiceSearch.setVisibility(voiceSearchEnabled ? View.VISIBLE : |
| 262 | View.GONE); |
| 263 | mGoButton.setVisibility(voiceSearchEnabled ? View.GONE : |
| 264 | View.VISIBLE); |
| 265 | } |
| 266 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 267 | @Override |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 268 | /* package */ void setDisplayTitle(String title) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 269 | mUrlInput.setText(title, false); |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 270 | } |
| 271 | |
Michael Kolb | 7b20ddd | 2010-10-14 15:03:28 -0700 | [diff] [blame] | 272 | void setDisplayTitle(String title, boolean filter) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 273 | mUrlInput.setText(title, filter); |
Michael Kolb | 7b20ddd | 2010-10-14 15:03:28 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 276 | // UrlInput text watcher |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 277 | |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 278 | @Override |
| 279 | public void afterTextChanged(Editable s) { |
| 280 | if (mUrlInput.hasFocus()) { |
| 281 | // check if url input is empty and adjust voice search state |
| 282 | updateSearchMode(); |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 283 | } |
| 284 | } |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame^] | 285 | |
| 286 | @Override |
| 287 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| 288 | } |
| 289 | |
| 290 | @Override |
| 291 | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| 292 | } |
| 293 | |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 294 | } |