Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 19 | import com.android.common.speech.LoggingEvents; |
| 20 | |
| 21 | import android.app.Activity; |
Leon Scroggins | 11e71b1 | 2010-01-25 10:40:38 -0500 | [diff] [blame] | 22 | import android.content.Intent; |
| 23 | import android.content.pm.PackageManager; |
| 24 | import android.content.pm.ResolveInfo; |
Leon Scroggins | 3bbb6ca | 2009-09-09 12:51:10 -0400 | [diff] [blame] | 25 | import android.content.res.Resources; |
Leon Scroggins | 62e8f94 | 2009-09-03 15:08:54 -0400 | [diff] [blame] | 26 | import android.graphics.drawable.Animatable; |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 27 | import android.graphics.drawable.Drawable; |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 28 | import android.os.Handler; |
| 29 | import android.os.Message; |
Leon Scroggins | 11e71b1 | 2010-01-25 10:40:38 -0500 | [diff] [blame] | 30 | import android.speech.RecognizerIntent; |
Leon Scroggins | f48d44e | 2010-02-05 16:41:49 -0500 | [diff] [blame] | 31 | import android.text.SpannableString; |
| 32 | import android.text.Spanned; |
Leon Scroggins | 76e1686 | 2010-02-08 14:39:34 -0500 | [diff] [blame] | 33 | import android.text.TextUtils; |
Leon Scroggins | f48d44e | 2010-02-05 16:41:49 -0500 | [diff] [blame] | 34 | import android.text.style.ImageSpan; |
Leon Scroggins | 9535cee | 2010-03-15 20:37:16 -0400 | [diff] [blame] | 35 | import android.util.DisplayMetrics; |
Leon Scroggins | 3bbb6ca | 2009-09-09 12:51:10 -0400 | [diff] [blame] | 36 | import android.util.TypedValue; |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 37 | import android.view.ContextMenu; |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 38 | import android.view.LayoutInflater; |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 39 | import android.view.MenuInflater; |
Leon Scroggins | 6857939 | 2009-09-15 15:31:54 -0400 | [diff] [blame] | 40 | import android.view.MotionEvent; |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 41 | import android.view.View; |
Leon Scroggins | 6857939 | 2009-09-15 15:31:54 -0400 | [diff] [blame] | 42 | import android.view.ViewConfiguration; |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 43 | import android.widget.ImageView; |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 44 | import android.widget.ProgressBar; |
| 45 | import android.widget.TextView; |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 46 | |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 47 | /** |
| 48 | * This class represents a title bar for a particular "tab" or "window" in the |
| 49 | * browser. |
| 50 | */ |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 51 | public class TitleBar extends TitleBarBase { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 52 | |
| 53 | private Activity mActivity; |
| 54 | private UiController mController; |
| 55 | private TextView mTitle; |
| 56 | private ImageView mRtButton; |
| 57 | private Drawable mCircularProgress; |
| 58 | private ProgressBar mHorizontalProgress; |
| 59 | private ImageView mStopButton; |
| 60 | private Drawable mBookmarkDrawable; |
| 61 | private Drawable mVoiceDrawable; |
| 62 | private boolean mInLoad; |
| 63 | private View mTitleBg; |
| 64 | private MyHandler mHandler; |
| 65 | private Intent mVoiceSearchIntent; |
| 66 | private boolean mInVoiceMode; |
| 67 | private Drawable mVoiceModeBackground; |
| 68 | private Drawable mNormalBackground; |
| 69 | private Drawable mLoadingBackground; |
| 70 | private ImageSpan mArcsSpan; |
| 71 | private int mLeftMargin; |
| 72 | private int mRightMargin; |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 73 | |
| 74 | private static int LONG_PRESS = 1; |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 75 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 76 | public TitleBar(Activity activity, UiController controller) { |
| 77 | super(activity); |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 78 | mHandler = new MyHandler(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 79 | LayoutInflater factory = LayoutInflater.from(activity); |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 80 | factory.inflate(R.layout.title_bar, this); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 81 | mActivity = activity; |
| 82 | mController = controller; |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 83 | |
| 84 | mTitle = (TextView) findViewById(R.id.title); |
Leon Scroggins | a81a764 | 2009-08-31 17:05:41 -0400 | [diff] [blame] | 85 | mTitle.setCompoundDrawablePadding(5); |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 86 | |
Leon Scroggins | 6857939 | 2009-09-15 15:31:54 -0400 | [diff] [blame] | 87 | mTitleBg = findViewById(R.id.title_bg); |
Leon Scroggins | 62e8f94 | 2009-09-03 15:08:54 -0400 | [diff] [blame] | 88 | mLockIcon = (ImageView) findViewById(R.id.lock); |
Leon Scroggins | f4bb18a | 2009-09-11 18:37:53 -0400 | [diff] [blame] | 89 | mFavicon = (ImageView) findViewById(R.id.favicon); |
Leon Scroggins | b3b04f7 | 2010-03-03 17:17:18 -0500 | [diff] [blame] | 90 | mStopButton = (ImageView) findViewById(R.id.stop); |
Leon Scroggins | 62e8f94 | 2009-09-03 15:08:54 -0400 | [diff] [blame] | 91 | |
Leon Scroggins | a81a764 | 2009-08-31 17:05:41 -0400 | [diff] [blame] | 92 | mRtButton = (ImageView) findViewById(R.id.rt_btn); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 93 | Resources resources = activity.getResources(); |
| 94 | mCircularProgress = resources.getDrawable( |
Leon Scroggins | 62e8f94 | 2009-09-03 15:08:54 -0400 | [diff] [blame] | 95 | com.android.internal.R.drawable.search_spinner); |
Leon Scroggins | 9535cee | 2010-03-15 20:37:16 -0400 | [diff] [blame] | 96 | DisplayMetrics metrics = resources.getDisplayMetrics(); |
Leon Scroggins | cd663ea | 2010-03-31 14:50:47 -0400 | [diff] [blame] | 97 | mLeftMargin = (int) TypedValue.applyDimension( |
| 98 | TypedValue.COMPLEX_UNIT_DIP, 8f, metrics); |
| 99 | mRightMargin = (int) TypedValue.applyDimension( |
| 100 | TypedValue.COMPLEX_UNIT_DIP, 6f, metrics); |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 101 | int iconDimension = (int) TypedValue.applyDimension( |
Leon Scroggins | 9535cee | 2010-03-15 20:37:16 -0400 | [diff] [blame] | 102 | TypedValue.COMPLEX_UNIT_DIP, 20f, metrics); |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 103 | mCircularProgress.setBounds(0, 0, iconDimension, iconDimension); |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 104 | mHorizontalProgress = (ProgressBar) findViewById( |
| 105 | R.id.progress_horizontal); |
Leon Scroggins | 11e71b1 | 2010-01-25 10:40:38 -0500 | [diff] [blame] | 106 | mVoiceSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 107 | mVoiceSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, |
| 108 | RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH); |
Mike LeBeau | 9f677bc | 2010-04-01 14:57:10 -0700 | [diff] [blame] | 109 | // This extra tells voice search not to send the application id in its |
| 110 | // results intent - http://b/2546173 |
| 111 | // |
| 112 | // TODO: Make a constant for this extra. |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 113 | mVoiceSearchIntent.putExtra("android.speech.extras.SEND_APPLICATION_ID_EXTRA", |
| 114 | false); |
| 115 | PackageManager pm = activity.getPackageManager(); |
Leon Scroggins | 11e71b1 | 2010-01-25 10:40:38 -0500 | [diff] [blame] | 116 | ResolveInfo ri = pm.resolveActivity(mVoiceSearchIntent, |
| 117 | PackageManager.MATCH_DEFAULT_ONLY); |
| 118 | if (ri == null) { |
| 119 | mVoiceSearchIntent = null; |
| 120 | } else { |
| 121 | mVoiceDrawable = resources.getDrawable( |
| 122 | android.R.drawable.ic_btn_speak_now); |
| 123 | } |
Leon Scroggins | 11e71b1 | 2010-01-25 10:40:38 -0500 | [diff] [blame] | 124 | mBookmarkDrawable = mRtButton.getDrawable(); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 125 | mVoiceModeBackground = resources.getDrawable( |
Leon Scroggins | f48d44e | 2010-02-05 16:41:49 -0500 | [diff] [blame] | 126 | R.drawable.title_voice); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 127 | mNormalBackground = mTitleBg.getBackground(); |
Leon Scroggins | b3b04f7 | 2010-03-03 17:17:18 -0500 | [diff] [blame] | 128 | mLoadingBackground = resources.getDrawable(R.drawable.title_loading); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 129 | mArcsSpan = new ImageSpan(activity, R.drawable.arcs, |
Leon Scroggins | f48d44e | 2010-02-05 16:41:49 -0500 | [diff] [blame] | 130 | ImageSpan.ALIGN_BASELINE); |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 131 | } |
| 132 | |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 133 | private class MyHandler extends Handler { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 134 | @Override |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 135 | public void handleMessage(Message msg) { |
| 136 | if (msg.what == LONG_PRESS) { |
| 137 | // Prevent the normal action from happening by setting the title |
| 138 | // bar's state to false. |
| 139 | mTitleBg.setPressed(false); |
| 140 | // Need to call a special method on BrowserActivity for when the |
| 141 | // fake title bar is up, because its ViewGroup does not show a |
| 142 | // context menu. |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 143 | // TODO: |
| 144 | // this test is not valid for all UIs; fix later |
| 145 | if (getParent() != null) { |
| 146 | mActivity.openContextMenu(TitleBar.this); |
| 147 | } |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | }; |
| 151 | |
| 152 | @Override |
Leon Scroggins | 4e9f89b | 2010-02-22 16:54:14 -0500 | [diff] [blame] | 153 | public void createContextMenu(ContextMenu menu) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 154 | MenuInflater inflater = mActivity.getMenuInflater(); |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 155 | inflater.inflate(R.menu.title_context, menu); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 156 | mActivity.onCreateContextMenu(menu, this, null); |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 157 | } |
| 158 | |
Leon Scroggins | 6857939 | 2009-09-15 15:31:54 -0400 | [diff] [blame] | 159 | @Override |
| 160 | public boolean onTouchEvent(MotionEvent event) { |
Leon Scroggins | bf083d2 | 2010-03-22 10:54:04 -0400 | [diff] [blame] | 161 | ImageView button = mInLoad ? mStopButton : mRtButton; |
Leon Scroggins | 6857939 | 2009-09-15 15:31:54 -0400 | [diff] [blame] | 162 | switch (event.getAction()) { |
| 163 | case MotionEvent.ACTION_DOWN: |
| 164 | // Make all touches hit either the textfield or the button, |
| 165 | // depending on which side of the right edge of the textfield |
| 166 | // they hit. |
| 167 | if ((int) event.getX() > mTitleBg.getRight()) { |
Leon Scroggins | bf083d2 | 2010-03-22 10:54:04 -0400 | [diff] [blame] | 168 | button.setPressed(true); |
Leon Scroggins | 6857939 | 2009-09-15 15:31:54 -0400 | [diff] [blame] | 169 | } else { |
| 170 | mTitleBg.setPressed(true); |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 171 | mHandler.sendMessageDelayed(mHandler.obtainMessage( |
| 172 | LONG_PRESS), |
| 173 | ViewConfiguration.getLongPressTimeout()); |
Leon Scroggins | 6857939 | 2009-09-15 15:31:54 -0400 | [diff] [blame] | 174 | } |
| 175 | break; |
| 176 | case MotionEvent.ACTION_MOVE: |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 177 | int slop = ViewConfiguration.get(mActivity) |
Leon Scroggins | 6857939 | 2009-09-15 15:31:54 -0400 | [diff] [blame] | 178 | .getScaledTouchSlop(); |
| 179 | if ((int) event.getY() > getHeight() + slop) { |
| 180 | // We only trigger the actions in ACTION_UP if one or the |
| 181 | // other is pressed. Since the user moved off the title |
| 182 | // bar, mark both as not pressed. |
| 183 | mTitleBg.setPressed(false); |
Leon Scroggins | bf083d2 | 2010-03-22 10:54:04 -0400 | [diff] [blame] | 184 | button.setPressed(false); |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 185 | mHandler.removeMessages(LONG_PRESS); |
Leon Scroggins | 6857939 | 2009-09-15 15:31:54 -0400 | [diff] [blame] | 186 | break; |
| 187 | } |
| 188 | int x = (int) event.getX(); |
| 189 | int titleRight = mTitleBg.getRight(); |
| 190 | if (mTitleBg.isPressed() && x > titleRight + slop) { |
| 191 | mTitleBg.setPressed(false); |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 192 | mHandler.removeMessages(LONG_PRESS); |
Leon Scroggins | bf083d2 | 2010-03-22 10:54:04 -0400 | [diff] [blame] | 193 | } else if (button.isPressed() && x < titleRight - slop) { |
| 194 | button.setPressed(false); |
Leon Scroggins | 6857939 | 2009-09-15 15:31:54 -0400 | [diff] [blame] | 195 | } |
| 196 | break; |
| 197 | case MotionEvent.ACTION_CANCEL: |
Leon Scroggins | bf083d2 | 2010-03-22 10:54:04 -0400 | [diff] [blame] | 198 | button.setPressed(false); |
Leon Scroggins | 6857939 | 2009-09-15 15:31:54 -0400 | [diff] [blame] | 199 | mTitleBg.setPressed(false); |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 200 | mHandler.removeMessages(LONG_PRESS); |
Leon Scroggins | 6857939 | 2009-09-15 15:31:54 -0400 | [diff] [blame] | 201 | break; |
| 202 | case MotionEvent.ACTION_UP: |
Leon Scroggins | bf083d2 | 2010-03-22 10:54:04 -0400 | [diff] [blame] | 203 | if (button.isPressed()) { |
Leon Scroggins | 11e71b1 | 2010-01-25 10:40:38 -0500 | [diff] [blame] | 204 | if (mInVoiceMode) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 205 | if (mController.getTabControl().getCurrentTab() |
Leon Scroggins | 1fe13a5 | 2010-02-09 15:31:26 -0500 | [diff] [blame] | 206 | .voiceSearchSourceIsGoogle()) { |
| 207 | Intent i = new Intent( |
| 208 | LoggingEvents.ACTION_LOG_EVENT); |
| 209 | i.putExtra(LoggingEvents.EXTRA_EVENT, |
| 210 | LoggingEvents.VoiceSearch.RETRY); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 211 | mActivity.sendBroadcast(i); |
Leon Scroggins | 1fe13a5 | 2010-02-09 15:31:26 -0500 | [diff] [blame] | 212 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 213 | mActivity.startActivity(mVoiceSearchIntent); |
Leon Scroggins | 11e71b1 | 2010-01-25 10:40:38 -0500 | [diff] [blame] | 214 | } else if (mInLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 215 | mController.stopLoading(); |
Leon Scroggins | 6857939 | 2009-09-15 15:31:54 -0400 | [diff] [blame] | 216 | } else { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 217 | mController.bookmarkCurrentPage( |
Leon Scroggins | 88d0803 | 2010-10-21 15:17:10 -0400 | [diff] [blame] | 218 | AddBookmarkPage.DEFAULT_FOLDER_ID); |
Leon Scroggins | 6857939 | 2009-09-15 15:31:54 -0400 | [diff] [blame] | 219 | } |
Leon Scroggins | bf083d2 | 2010-03-22 10:54:04 -0400 | [diff] [blame] | 220 | button.setPressed(false); |
Leon Scroggins | 6857939 | 2009-09-15 15:31:54 -0400 | [diff] [blame] | 221 | } else if (mTitleBg.isPressed()) { |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 222 | mHandler.removeMessages(LONG_PRESS); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 223 | if (mInVoiceMode) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 224 | if (mController.getTabControl().getCurrentTab() |
Leon Scroggins | 1fe13a5 | 2010-02-09 15:31:26 -0500 | [diff] [blame] | 225 | .voiceSearchSourceIsGoogle()) { |
| 226 | Intent i = new Intent( |
| 227 | LoggingEvents.ACTION_LOG_EVENT); |
| 228 | i.putExtra(LoggingEvents.EXTRA_EVENT, |
| 229 | LoggingEvents.VoiceSearch.N_BEST_REVEAL); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 230 | mActivity.sendBroadcast(i); |
Leon Scroggins | 1fe13a5 | 2010-02-09 15:31:26 -0500 | [diff] [blame] | 231 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 232 | mController.showVoiceSearchResults( |
Leon Scroggins | ea75407 | 2010-02-08 14:08:30 -0500 | [diff] [blame] | 233 | mTitle.getText().toString().trim()); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 234 | } else { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 235 | mController.editUrl(); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 236 | } |
Leon Scroggins | 6857939 | 2009-09-15 15:31:54 -0400 | [diff] [blame] | 237 | mTitleBg.setPressed(false); |
| 238 | } |
| 239 | break; |
| 240 | default: |
| 241 | break; |
| 242 | } |
| 243 | return true; |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 244 | } |
| 245 | |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 246 | /** |
Leon Scroggins | 11e71b1 | 2010-01-25 10:40:38 -0500 | [diff] [blame] | 247 | * Change the TitleBar to or from voice mode. If there is no package to |
| 248 | * handle voice search, the TitleBar cannot be set to voice mode. |
| 249 | */ |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 250 | @Override |
| 251 | void setInVoiceMode(boolean inVoiceMode) { |
Leon Scroggins | 11e71b1 | 2010-01-25 10:40:38 -0500 | [diff] [blame] | 252 | if (mInVoiceMode == inVoiceMode) return; |
| 253 | mInVoiceMode = inVoiceMode && mVoiceSearchIntent != null; |
Leon Scroggins | b3b04f7 | 2010-03-03 17:17:18 -0500 | [diff] [blame] | 254 | Drawable titleDrawable; |
Leon Scroggins | 11e71b1 | 2010-01-25 10:40:38 -0500 | [diff] [blame] | 255 | if (mInVoiceMode) { |
Leon Scroggins | b3b04f7 | 2010-03-03 17:17:18 -0500 | [diff] [blame] | 256 | mRtButton.setImageDrawable(mVoiceDrawable); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 257 | titleDrawable = mVoiceModeBackground; |
Leon Scroggins | 76e1686 | 2010-02-08 14:39:34 -0500 | [diff] [blame] | 258 | mTitle.setEllipsize(null); |
Leon Scroggins | b3b04f7 | 2010-03-03 17:17:18 -0500 | [diff] [blame] | 259 | mRtButton.setVisibility(View.VISIBLE); |
| 260 | mStopButton.setVisibility(View.GONE); |
Leon Scroggins III | 1644ff6 | 2010-04-08 10:34:14 -0400 | [diff] [blame] | 261 | mTitleBg.setBackgroundDrawable(titleDrawable); |
Leon Scroggins | 7fb1a35 | 2010-04-15 10:55:02 -0400 | [diff] [blame] | 262 | mTitleBg.setPadding(mLeftMargin, mTitleBg.getPaddingTop(), |
| 263 | mRightMargin, mTitleBg.getPaddingBottom()); |
Leon Scroggins | 11e71b1 | 2010-01-25 10:40:38 -0500 | [diff] [blame] | 264 | } else { |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 265 | if (mInLoad) { |
Leon Scroggins | b3b04f7 | 2010-03-03 17:17:18 -0500 | [diff] [blame] | 266 | titleDrawable = mLoadingBackground; |
| 267 | mRtButton.setVisibility(View.GONE); |
| 268 | mStopButton.setVisibility(View.VISIBLE); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 269 | } else { |
Leon Scroggins | b3b04f7 | 2010-03-03 17:17:18 -0500 | [diff] [blame] | 270 | titleDrawable = mNormalBackground; |
| 271 | mRtButton.setVisibility(View.VISIBLE); |
| 272 | mStopButton.setVisibility(View.GONE); |
| 273 | mRtButton.setImageDrawable(mBookmarkDrawable); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 274 | } |
Leon Scroggins | 76e1686 | 2010-02-08 14:39:34 -0500 | [diff] [blame] | 275 | mTitle.setEllipsize(TextUtils.TruncateAt.END); |
Leon Scroggins III | 1644ff6 | 2010-04-08 10:34:14 -0400 | [diff] [blame] | 276 | mTitleBg.setBackgroundDrawable(titleDrawable); |
| 277 | mTitleBg.setPadding(mLeftMargin, 0, mRightMargin, 0); |
Leon Scroggins | 11e71b1 | 2010-01-25 10:40:38 -0500 | [diff] [blame] | 278 | } |
Leon Scroggins | f48d44e | 2010-02-05 16:41:49 -0500 | [diff] [blame] | 279 | mTitle.setSingleLine(!mInVoiceMode); |
Leon Scroggins | 11e71b1 | 2010-01-25 10:40:38 -0500 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | /** |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 283 | * Update the progress, from 0 to 100. |
| 284 | */ |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 285 | @Override |
| 286 | void setProgress(int newProgress) { |
Nicolas Roard | 1382b49 | 2009-09-16 21:50:06 +0100 | [diff] [blame] | 287 | if (newProgress >= mHorizontalProgress.getMax()) { |
Leon Scroggins | f4bb18a | 2009-09-11 18:37:53 -0400 | [diff] [blame] | 288 | mTitle.setCompoundDrawables(null, null, null, null); |
Leon Scroggins | 62e8f94 | 2009-09-03 15:08:54 -0400 | [diff] [blame] | 289 | ((Animatable) mCircularProgress).stop(); |
| 290 | mHorizontalProgress.setVisibility(View.INVISIBLE); |
Leon Scroggins | 11e71b1 | 2010-01-25 10:40:38 -0500 | [diff] [blame] | 291 | if (!mInVoiceMode) { |
Leon Scroggins | a81a764 | 2009-08-31 17:05:41 -0400 | [diff] [blame] | 292 | mRtButton.setImageDrawable(mBookmarkDrawable); |
Leon Scroggins | b3b04f7 | 2010-03-03 17:17:18 -0500 | [diff] [blame] | 293 | mRtButton.setVisibility(View.VISIBLE); |
| 294 | mStopButton.setVisibility(View.GONE); |
| 295 | mTitleBg.setBackgroundDrawable(mNormalBackground); |
Leon Scroggins | cd663ea | 2010-03-31 14:50:47 -0400 | [diff] [blame] | 296 | mTitleBg.setPadding(mLeftMargin, 0, mRightMargin, 0); |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 297 | } |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 298 | mInLoad = false; |
| 299 | } else { |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 300 | mHorizontalProgress.setProgress(newProgress); |
Nicolas Roard | 1382b49 | 2009-09-16 21:50:06 +0100 | [diff] [blame] | 301 | if (!mInLoad && getWindowToken() != null) { |
| 302 | // checking the window token lets us be sure that we |
| 303 | // are attached to a window before starting the animation, |
| 304 | // preventing a potential race condition |
| 305 | // (fix for bug http://b/2115736) |
Leon Scroggins | f4bb18a | 2009-09-11 18:37:53 -0400 | [diff] [blame] | 306 | mTitle.setCompoundDrawables(null, null, mCircularProgress, |
Leon Scroggins | 62e8f94 | 2009-09-03 15:08:54 -0400 | [diff] [blame] | 307 | null); |
| 308 | ((Animatable) mCircularProgress).start(); |
| 309 | mHorizontalProgress.setVisibility(View.VISIBLE); |
Leon Scroggins | 11e71b1 | 2010-01-25 10:40:38 -0500 | [diff] [blame] | 310 | if (!mInVoiceMode) { |
Leon Scroggins | b3b04f7 | 2010-03-03 17:17:18 -0500 | [diff] [blame] | 311 | mTitleBg.setBackgroundDrawable(mLoadingBackground); |
Leon Scroggins | cd663ea | 2010-03-31 14:50:47 -0400 | [diff] [blame] | 312 | mTitleBg.setPadding(mLeftMargin, 0, mRightMargin, 0); |
Leon Scroggins | b3b04f7 | 2010-03-03 17:17:18 -0500 | [diff] [blame] | 313 | mRtButton.setVisibility(View.GONE); |
| 314 | mStopButton.setVisibility(View.VISIBLE); |
Leon Scroggins | 62e8f94 | 2009-09-03 15:08:54 -0400 | [diff] [blame] | 315 | } |
| 316 | mInLoad = true; |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 317 | } |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 321 | /** |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 322 | * Update the text displayed in the title bar. |
John Reck | ef07426 | 2010-12-02 16:09:14 -0800 | [diff] [blame^] | 323 | * @param title String to display. If null, the new tab string will be |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 324 | * shown. |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 325 | */ |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 326 | @Override |
| 327 | void setDisplayTitle(String title) { |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 328 | if (title == null) { |
John Reck | ef07426 | 2010-12-02 16:09:14 -0800 | [diff] [blame^] | 329 | mTitle.setText(R.string.new_tab); |
Leon Scroggins | d7c3dd5 | 2009-07-20 13:38:47 -0400 | [diff] [blame] | 330 | } else { |
Leon Scroggins | f48d44e | 2010-02-05 16:41:49 -0500 | [diff] [blame] | 331 | if (mInVoiceMode) { |
| 332 | // Add two spaces. The second one will be replaced with an |
| 333 | // image, and the first one will put space between it and the |
| 334 | // text |
| 335 | SpannableString spannable = new SpannableString(title + " "); |
| 336 | int end = spannable.length(); |
| 337 | spannable.setSpan(mArcsSpan, end - 1, end, |
| 338 | Spanned.SPAN_MARK_POINT); |
| 339 | mTitle.setText(spannable); |
| 340 | } else { |
| 341 | mTitle.setText(title); |
| 342 | } |
Leon Scroggins | d7c3dd5 | 2009-07-20 13:38:47 -0400 | [diff] [blame] | 343 | } |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 344 | } |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 345 | } |