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