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