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