blob: 2c255344e8cc63c5d007954c0d6509c16466f7a1 [file] [log] [blame]
Leon Scroggins81db3662009-06-04 17:45:11 -04001/*
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
17package com.android.browser;
18
19import android.content.Context;
Leon Scroggins11e71b12010-01-25 10:40:38 -050020import android.content.Intent;
21import android.content.pm.PackageManager;
22import android.content.pm.ResolveInfo;
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -040023import android.content.res.Resources;
24import android.graphics.Bitmap;
25import android.graphics.Color;
Leon Scroggins1f005d32009-08-10 17:36:42 -040026import android.graphics.Rect;
Leon Scroggins62e8f942009-09-03 15:08:54 -040027import android.graphics.drawable.Animatable;
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -040028import android.graphics.drawable.BitmapDrawable;
Leon Scroggins81db3662009-06-04 17:45:11 -040029import android.graphics.drawable.Drawable;
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -040030import android.graphics.drawable.LayerDrawable;
31import android.graphics.drawable.PaintDrawable;
Leon Scrogginsc6fa1102009-09-21 10:40:01 -040032import android.os.Handler;
33import android.os.Message;
Leon Scroggins11e71b12010-01-25 10:40:38 -050034import android.speech.RecognizerIntent;
Leon Scrogginsf48d44e2010-02-05 16:41:49 -050035import android.text.SpannableString;
36import android.text.Spanned;
Leon Scroggins76e16862010-02-08 14:39:34 -050037import android.text.TextUtils;
Leon Scrogginsf48d44e2010-02-05 16:41:49 -050038import android.text.style.ImageSpan;
Leon Scroggins9535cee2010-03-15 20:37:16 -040039import android.util.DisplayMetrics;
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -040040import android.util.TypedValue;
Leon Scrogginsc6fa1102009-09-21 10:40:01 -040041import android.view.ContextMenu;
Leon Scrogginse4b3bda2009-06-09 15:46:41 -040042import android.view.LayoutInflater;
Leon Scrogginsc6fa1102009-09-21 10:40:01 -040043import android.view.MenuInflater;
Leon Scroggins68579392009-09-15 15:31:54 -040044import android.view.MotionEvent;
Leon Scrogginse4b3bda2009-06-09 15:46:41 -040045import android.view.View;
Leon Scroggins68579392009-09-15 15:31:54 -040046import android.view.ViewConfiguration;
Leon Scroggins81db3662009-06-04 17:45:11 -040047import android.widget.ImageView;
48import android.widget.LinearLayout;
49import android.widget.ProgressBar;
50import android.widget.TextView;
Leon Scroggins81db3662009-06-04 17:45:11 -040051
Leon Scroggins1fe13a52010-02-09 15:31:26 -050052import com.android.common.speech.LoggingEvents;
53
Leon Scroggins1f005d32009-08-10 17:36:42 -040054/**
55 * This class represents a title bar for a particular "tab" or "window" in the
56 * browser.
57 */
Leon Scrogginse4b3bda2009-06-09 15:46:41 -040058public class TitleBar extends LinearLayout {
Leon Scroggins81db3662009-06-04 17:45:11 -040059 private TextView mTitle;
Leon Scroggins1f005d32009-08-10 17:36:42 -040060 private Drawable mCloseDrawable;
61 private ImageView mRtButton;
Leon Scroggins62e8f942009-09-03 15:08:54 -040062 private Drawable mCircularProgress;
Leon Scroggins81db3662009-06-04 17:45:11 -040063 private ProgressBar mHorizontalProgress;
Leon Scrogginsf4bb18a2009-09-11 18:37:53 -040064 private ImageView mFavicon;
Leon Scroggins62e8f942009-09-03 15:08:54 -040065 private ImageView mLockIcon;
Leon Scrogginsb3b04f72010-03-03 17:17:18 -050066 private ImageView mStopButton;
Leon Scrogginsa81a7642009-08-31 17:05:41 -040067 private Drawable mBookmarkDrawable;
Leon Scroggins11e71b12010-01-25 10:40:38 -050068 private Drawable mVoiceDrawable;
Leon Scroggins81db3662009-06-04 17:45:11 -040069 private boolean mInLoad;
Leon Scrogginsa81a7642009-08-31 17:05:41 -040070 private BrowserActivity mBrowserActivity;
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -040071 private Drawable mGenericFavicon;
72 private int mIconDimension;
Leon Scroggins68579392009-09-15 15:31:54 -040073 private View mTitleBg;
Leon Scrogginsc6fa1102009-09-21 10:40:01 -040074 private MyHandler mHandler;
Leon Scroggins11e71b12010-01-25 10:40:38 -050075 private Intent mVoiceSearchIntent;
76 private boolean mInVoiceMode;
Leon Scroggins58d56c62010-01-28 15:12:40 -050077 private Drawable mVoiceModeBackground;
78 private Drawable mNormalBackground;
Leon Scrogginsb3b04f72010-03-03 17:17:18 -050079 private Drawable mLoadingBackground;
Leon Scrogginsf48d44e2010-02-05 16:41:49 -050080 private ImageSpan mArcsSpan;
Leon Scrogginscd663ea2010-03-31 14:50:47 -040081 private int mLeftMargin;
82 private int mRightMargin;
Leon Scrogginsc6fa1102009-09-21 10:40:01 -040083
84 private static int LONG_PRESS = 1;
Leon Scroggins81db3662009-06-04 17:45:11 -040085
Leon Scroggins68579392009-09-15 15:31:54 -040086 public TitleBar(BrowserActivity context) {
Leon Scroggins1f005d32009-08-10 17:36:42 -040087 super(context, null);
Leon Scrogginsc6fa1102009-09-21 10:40:01 -040088 mHandler = new MyHandler();
Leon Scroggins81db3662009-06-04 17:45:11 -040089 LayoutInflater factory = LayoutInflater.from(context);
90 factory.inflate(R.layout.title_bar, this);
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -040091 mBrowserActivity = context;
Leon Scroggins81db3662009-06-04 17:45:11 -040092
93 mTitle = (TextView) findViewById(R.id.title);
Leon Scrogginsa81a7642009-08-31 17:05:41 -040094 mTitle.setCompoundDrawablePadding(5);
Leon Scroggins81db3662009-06-04 17:45:11 -040095
Leon Scroggins68579392009-09-15 15:31:54 -040096 mTitleBg = findViewById(R.id.title_bg);
Leon Scroggins62e8f942009-09-03 15:08:54 -040097 mLockIcon = (ImageView) findViewById(R.id.lock);
Leon Scrogginsf4bb18a2009-09-11 18:37:53 -040098 mFavicon = (ImageView) findViewById(R.id.favicon);
Leon Scrogginsb3b04f72010-03-03 17:17:18 -050099 mStopButton = (ImageView) findViewById(R.id.stop);
Leon Scroggins62e8f942009-09-03 15:08:54 -0400100
Leon Scrogginsa81a7642009-08-31 17:05:41 -0400101 mRtButton = (ImageView) findViewById(R.id.rt_btn);
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400102 Resources resources = context.getResources();
103 mCircularProgress = (Drawable) resources.getDrawable(
Leon Scroggins62e8f942009-09-03 15:08:54 -0400104 com.android.internal.R.drawable.search_spinner);
Leon Scroggins9535cee2010-03-15 20:37:16 -0400105 DisplayMetrics metrics = resources.getDisplayMetrics();
Leon Scrogginscd663ea2010-03-31 14:50:47 -0400106 mLeftMargin = (int) TypedValue.applyDimension(
107 TypedValue.COMPLEX_UNIT_DIP, 8f, metrics);
108 mRightMargin = (int) TypedValue.applyDimension(
109 TypedValue.COMPLEX_UNIT_DIP, 6f, metrics);
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400110 mIconDimension = (int) TypedValue.applyDimension(
Leon Scroggins9535cee2010-03-15 20:37:16 -0400111 TypedValue.COMPLEX_UNIT_DIP, 20f, metrics);
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400112 mCircularProgress.setBounds(0, 0, mIconDimension, mIconDimension);
Leon Scroggins81db3662009-06-04 17:45:11 -0400113 mHorizontalProgress = (ProgressBar) findViewById(
114 R.id.progress_horizontal);
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400115 mGenericFavicon = context.getResources().getDrawable(
116 R.drawable.app_web_browser_sm);
Leon Scroggins11e71b12010-01-25 10:40:38 -0500117 mVoiceSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
118 mVoiceSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
119 RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
Mike LeBeau9f677bc2010-04-01 14:57:10 -0700120 // This extra tells voice search not to send the application id in its
121 // results intent - http://b/2546173
122 //
123 // TODO: Make a constant for this extra.
124 mVoiceSearchIntent.putExtra("android.speech.extras.SEND_APPLICATION_ID_EXTRA", false);
Leon Scroggins11e71b12010-01-25 10:40:38 -0500125 PackageManager pm = context.getPackageManager();
126 ResolveInfo ri = pm.resolveActivity(mVoiceSearchIntent,
127 PackageManager.MATCH_DEFAULT_ONLY);
128 if (ri == null) {
129 mVoiceSearchIntent = null;
130 } else {
131 mVoiceDrawable = resources.getDrawable(
132 android.R.drawable.ic_btn_speak_now);
133 }
Leon Scroggins11e71b12010-01-25 10:40:38 -0500134 mBookmarkDrawable = mRtButton.getDrawable();
Leon Scroggins58d56c62010-01-28 15:12:40 -0500135 mVoiceModeBackground = resources.getDrawable(
Leon Scrogginsf48d44e2010-02-05 16:41:49 -0500136 R.drawable.title_voice);
Leon Scroggins58d56c62010-01-28 15:12:40 -0500137 mNormalBackground = mTitleBg.getBackground();
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500138 mLoadingBackground = resources.getDrawable(R.drawable.title_loading);
Leon Scrogginsf48d44e2010-02-05 16:41:49 -0500139 mArcsSpan = new ImageSpan(context, R.drawable.arcs,
140 ImageSpan.ALIGN_BASELINE);
Leon Scrogginse4b3bda2009-06-09 15:46:41 -0400141 }
142
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400143 private class MyHandler extends Handler {
144 public void handleMessage(Message msg) {
145 if (msg.what == LONG_PRESS) {
146 // Prevent the normal action from happening by setting the title
147 // bar's state to false.
148 mTitleBg.setPressed(false);
149 // Need to call a special method on BrowserActivity for when the
150 // fake title bar is up, because its ViewGroup does not show a
151 // context menu.
152 mBrowserActivity.showTitleBarContextMenu();
153 }
154 }
155 };
156
157 @Override
Leon Scroggins4e9f89b2010-02-22 16:54:14 -0500158 public void createContextMenu(ContextMenu menu) {
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400159 MenuInflater inflater = mBrowserActivity.getMenuInflater();
160 inflater.inflate(R.menu.title_context, menu);
Leon Scroggins4e9f89b2010-02-22 16:54:14 -0500161 mBrowserActivity.onCreateContextMenu(menu, this, null);
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400162 }
163
Leon Scroggins68579392009-09-15 15:31:54 -0400164 @Override
165 public boolean onTouchEvent(MotionEvent event) {
Leon Scrogginsbf083d22010-03-22 10:54:04 -0400166 ImageView button = mInLoad ? mStopButton : mRtButton;
Leon Scroggins68579392009-09-15 15:31:54 -0400167 switch (event.getAction()) {
168 case MotionEvent.ACTION_DOWN:
169 // Make all touches hit either the textfield or the button,
170 // depending on which side of the right edge of the textfield
171 // they hit.
172 if ((int) event.getX() > mTitleBg.getRight()) {
Leon Scrogginsbf083d22010-03-22 10:54:04 -0400173 button.setPressed(true);
Leon Scroggins68579392009-09-15 15:31:54 -0400174 } else {
175 mTitleBg.setPressed(true);
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400176 mHandler.sendMessageDelayed(mHandler.obtainMessage(
177 LONG_PRESS),
178 ViewConfiguration.getLongPressTimeout());
Leon Scroggins68579392009-09-15 15:31:54 -0400179 }
180 break;
181 case MotionEvent.ACTION_MOVE:
182 int slop = ViewConfiguration.get(mBrowserActivity)
183 .getScaledTouchSlop();
184 if ((int) event.getY() > getHeight() + slop) {
185 // We only trigger the actions in ACTION_UP if one or the
186 // other is pressed. Since the user moved off the title
187 // bar, mark both as not pressed.
188 mTitleBg.setPressed(false);
Leon Scrogginsbf083d22010-03-22 10:54:04 -0400189 button.setPressed(false);
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400190 mHandler.removeMessages(LONG_PRESS);
Leon Scroggins68579392009-09-15 15:31:54 -0400191 break;
192 }
193 int x = (int) event.getX();
194 int titleRight = mTitleBg.getRight();
195 if (mTitleBg.isPressed() && x > titleRight + slop) {
196 mTitleBg.setPressed(false);
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400197 mHandler.removeMessages(LONG_PRESS);
Leon Scrogginsbf083d22010-03-22 10:54:04 -0400198 } else if (button.isPressed() && x < titleRight - slop) {
199 button.setPressed(false);
Leon Scroggins68579392009-09-15 15:31:54 -0400200 }
201 break;
202 case MotionEvent.ACTION_CANCEL:
Leon Scrogginsbf083d22010-03-22 10:54:04 -0400203 button.setPressed(false);
Leon Scroggins68579392009-09-15 15:31:54 -0400204 mTitleBg.setPressed(false);
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400205 mHandler.removeMessages(LONG_PRESS);
Leon Scroggins68579392009-09-15 15:31:54 -0400206 break;
207 case MotionEvent.ACTION_UP:
Leon Scrogginsbf083d22010-03-22 10:54:04 -0400208 if (button.isPressed()) {
Leon Scroggins11e71b12010-01-25 10:40:38 -0500209 if (mInVoiceMode) {
Leon Scroggins1fe13a52010-02-09 15:31:26 -0500210 if (mBrowserActivity.getTabControl().getCurrentTab()
211 .voiceSearchSourceIsGoogle()) {
212 Intent i = new Intent(
213 LoggingEvents.ACTION_LOG_EVENT);
214 i.putExtra(LoggingEvents.EXTRA_EVENT,
215 LoggingEvents.VoiceSearch.RETRY);
216 mBrowserActivity.sendBroadcast(i);
217 }
Leon Scroggins11e71b12010-01-25 10:40:38 -0500218 mBrowserActivity.startActivity(mVoiceSearchIntent);
219 } else if (mInLoad) {
Leon Scroggins68579392009-09-15 15:31:54 -0400220 mBrowserActivity.stopLoading();
221 } else {
222 mBrowserActivity.bookmarksOrHistoryPicker(false);
223 }
Leon Scrogginsbf083d22010-03-22 10:54:04 -0400224 button.setPressed(false);
Leon Scroggins68579392009-09-15 15:31:54 -0400225 } else if (mTitleBg.isPressed()) {
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400226 mHandler.removeMessages(LONG_PRESS);
Leon Scroggins58d56c62010-01-28 15:12:40 -0500227 if (mInVoiceMode) {
Leon Scroggins1fe13a52010-02-09 15:31:26 -0500228 if (mBrowserActivity.getTabControl().getCurrentTab()
229 .voiceSearchSourceIsGoogle()) {
230 Intent i = new Intent(
231 LoggingEvents.ACTION_LOG_EVENT);
232 i.putExtra(LoggingEvents.EXTRA_EVENT,
233 LoggingEvents.VoiceSearch.N_BEST_REVEAL);
234 mBrowserActivity.sendBroadcast(i);
235 }
Leon Scroggins58d56c62010-01-28 15:12:40 -0500236 mBrowserActivity.showVoiceSearchResults(
Leon Scrogginsea754072010-02-08 14:08:30 -0500237 mTitle.getText().toString().trim());
Leon Scroggins58d56c62010-01-28 15:12:40 -0500238 } else {
Leon Scroggins8ad29922010-02-16 12:33:55 -0500239 mBrowserActivity.editUrl();
Leon Scroggins58d56c62010-01-28 15:12:40 -0500240 }
Leon Scroggins68579392009-09-15 15:31:54 -0400241 mTitleBg.setPressed(false);
242 }
243 break;
244 default:
245 break;
246 }
247 return true;
Leon Scroggins81db3662009-06-04 17:45:11 -0400248 }
249
Leon Scroggins1f005d32009-08-10 17:36:42 -0400250 /**
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400251 * Set a new Bitmap for the Favicon.
Leon Scroggins1f005d32009-08-10 17:36:42 -0400252 */
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400253 /* package */ void setFavicon(Bitmap icon) {
254 Drawable[] array = new Drawable[3];
255 array[0] = new PaintDrawable(Color.BLACK);
256 PaintDrawable p = new PaintDrawable(Color.WHITE);
257 array[1] = p;
258 if (icon == null) {
259 array[2] = mGenericFavicon;
260 } else {
261 array[2] = new BitmapDrawable(icon);
Leon Scrogginsa81a7642009-08-31 17:05:41 -0400262 }
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400263 LayerDrawable d = new LayerDrawable(array);
264 d.setLayerInset(1, 1, 1, 1, 1);
265 d.setLayerInset(2, 2, 2, 2, 2);
Leon Scrogginsf4bb18a2009-09-11 18:37:53 -0400266 mFavicon.setImageDrawable(d);
Leon Scroggins81db3662009-06-04 17:45:11 -0400267 }
268
Leon Scroggins1f005d32009-08-10 17:36:42 -0400269 /**
Leon Scroggins11e71b12010-01-25 10:40:38 -0500270 * Change the TitleBar to or from voice mode. If there is no package to
271 * handle voice search, the TitleBar cannot be set to voice mode.
272 */
273 /* package */ void setInVoiceMode(boolean inVoiceMode) {
274 if (mInVoiceMode == inVoiceMode) return;
275 mInVoiceMode = inVoiceMode && mVoiceSearchIntent != null;
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500276 Drawable titleDrawable;
Leon Scroggins11e71b12010-01-25 10:40:38 -0500277 if (mInVoiceMode) {
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500278 mRtButton.setImageDrawable(mVoiceDrawable);
Leon Scroggins58d56c62010-01-28 15:12:40 -0500279 titleDrawable = mVoiceModeBackground;
Leon Scroggins76e16862010-02-08 14:39:34 -0500280 mTitle.setEllipsize(null);
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500281 mRtButton.setVisibility(View.VISIBLE);
282 mStopButton.setVisibility(View.GONE);
Leon Scroggins11e71b12010-01-25 10:40:38 -0500283 } else {
Leon Scroggins58d56c62010-01-28 15:12:40 -0500284 if (mInLoad) {
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500285 titleDrawable = mLoadingBackground;
286 mRtButton.setVisibility(View.GONE);
287 mStopButton.setVisibility(View.VISIBLE);
Leon Scroggins58d56c62010-01-28 15:12:40 -0500288 } else {
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500289 titleDrawable = mNormalBackground;
290 mRtButton.setVisibility(View.VISIBLE);
291 mStopButton.setVisibility(View.GONE);
292 mRtButton.setImageDrawable(mBookmarkDrawable);
Leon Scroggins58d56c62010-01-28 15:12:40 -0500293 }
Leon Scroggins76e16862010-02-08 14:39:34 -0500294 mTitle.setEllipsize(TextUtils.TruncateAt.END);
Leon Scroggins11e71b12010-01-25 10:40:38 -0500295 }
Leon Scrogginsf48d44e2010-02-05 16:41:49 -0500296 mTitle.setSingleLine(!mInVoiceMode);
Leon Scroggins58d56c62010-01-28 15:12:40 -0500297 mTitleBg.setBackgroundDrawable(titleDrawable);
Leon Scrogginscd663ea2010-03-31 14:50:47 -0400298 mTitleBg.setPadding(mLeftMargin, 0, mRightMargin, 0);
Leon Scroggins11e71b12010-01-25 10:40:38 -0500299 }
300
301 /**
Leon Scroggins1f005d32009-08-10 17:36:42 -0400302 * Set the Drawable for the lock icon, or null to hide it.
303 */
Leon Scroggins81db3662009-06-04 17:45:11 -0400304 /* package */ void setLock(Drawable d) {
Leon Scroggins62e8f942009-09-03 15:08:54 -0400305 if (null == d) {
306 mLockIcon.setVisibility(View.GONE);
307 } else {
308 mLockIcon.setImageDrawable(d);
309 mLockIcon.setVisibility(View.VISIBLE);
Leon Scroggins81db3662009-06-04 17:45:11 -0400310 }
311 }
312
Leon Scroggins1f005d32009-08-10 17:36:42 -0400313 /**
314 * Update the progress, from 0 to 100.
315 */
Leon Scroggins81db3662009-06-04 17:45:11 -0400316 /* package */ void setProgress(int newProgress) {
Nicolas Roard1382b492009-09-16 21:50:06 +0100317 if (newProgress >= mHorizontalProgress.getMax()) {
Leon Scrogginsf4bb18a2009-09-11 18:37:53 -0400318 mTitle.setCompoundDrawables(null, null, null, null);
Leon Scroggins62e8f942009-09-03 15:08:54 -0400319 ((Animatable) mCircularProgress).stop();
320 mHorizontalProgress.setVisibility(View.INVISIBLE);
Leon Scroggins11e71b12010-01-25 10:40:38 -0500321 if (!mInVoiceMode) {
Leon Scrogginsa81a7642009-08-31 17:05:41 -0400322 mRtButton.setImageDrawable(mBookmarkDrawable);
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500323 mRtButton.setVisibility(View.VISIBLE);
324 mStopButton.setVisibility(View.GONE);
325 mTitleBg.setBackgroundDrawable(mNormalBackground);
Leon Scrogginscd663ea2010-03-31 14:50:47 -0400326 mTitleBg.setPadding(mLeftMargin, 0, mRightMargin, 0);
Leon Scroggins1f005d32009-08-10 17:36:42 -0400327 }
Leon Scroggins81db3662009-06-04 17:45:11 -0400328 mInLoad = false;
329 } else {
Leon Scroggins81db3662009-06-04 17:45:11 -0400330 mHorizontalProgress.setProgress(newProgress);
Nicolas Roard1382b492009-09-16 21:50:06 +0100331 if (!mInLoad && getWindowToken() != null) {
332 // checking the window token lets us be sure that we
333 // are attached to a window before starting the animation,
334 // preventing a potential race condition
335 // (fix for bug http://b/2115736)
Leon Scrogginsf4bb18a2009-09-11 18:37:53 -0400336 mTitle.setCompoundDrawables(null, null, mCircularProgress,
Leon Scroggins62e8f942009-09-03 15:08:54 -0400337 null);
338 ((Animatable) mCircularProgress).start();
339 mHorizontalProgress.setVisibility(View.VISIBLE);
Leon Scroggins11e71b12010-01-25 10:40:38 -0500340 if (!mInVoiceMode) {
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500341 mTitleBg.setBackgroundDrawable(mLoadingBackground);
Leon Scrogginscd663ea2010-03-31 14:50:47 -0400342 mTitleBg.setPadding(mLeftMargin, 0, mRightMargin, 0);
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500343 mRtButton.setVisibility(View.GONE);
344 mStopButton.setVisibility(View.VISIBLE);
Leon Scroggins62e8f942009-09-03 15:08:54 -0400345 }
346 mInLoad = true;
Leon Scrogginse4b3bda2009-06-09 15:46:41 -0400347 }
Leon Scroggins81db3662009-06-04 17:45:11 -0400348 }
349 }
350
Leon Scroggins1f005d32009-08-10 17:36:42 -0400351 /**
Leon Scroggins58d56c62010-01-28 15:12:40 -0500352 * Update the text displayed in the title bar.
353 * @param title String to display. If null, the loading string will be
354 * shown.
Leon Scroggins1f005d32009-08-10 17:36:42 -0400355 */
Leon Scroggins58d56c62010-01-28 15:12:40 -0500356 /* package */ void setDisplayTitle(String title) {
357 if (title == null) {
Leon Scrogginsa81a7642009-08-31 17:05:41 -0400358 mTitle.setText(R.string.title_bar_loading);
Leon Scrogginsd7c3dd52009-07-20 13:38:47 -0400359 } else {
Leon Scrogginsf48d44e2010-02-05 16:41:49 -0500360 if (mInVoiceMode) {
361 // Add two spaces. The second one will be replaced with an
362 // image, and the first one will put space between it and the
363 // text
364 SpannableString spannable = new SpannableString(title + " ");
365 int end = spannable.length();
366 spannable.setSpan(mArcsSpan, end - 1, end,
367 Spanned.SPAN_MARK_POINT);
368 mTitle.setText(spannable);
369 } else {
370 mTitle.setText(title);
371 }
Leon Scrogginsd7c3dd52009-07-20 13:38:47 -0400372 }
Leon Scroggins81db3662009-06-04 17:45:11 -0400373 }
374
375 /* package */ void setToTabPicker() {
376 mTitle.setText(R.string.tab_picker_title);
377 setFavicon(null);
378 setLock(null);
Leon Scroggins81db3662009-06-04 17:45:11 -0400379 mHorizontalProgress.setVisibility(View.GONE);
Leon Scroggins81db3662009-06-04 17:45:11 -0400380 }
381}