blob: ee6aa9c09f6497501858662a2eb2a362186353f7 [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 Scroggins9535cee2010-03-15 20:37:16 -040047import android.view.ViewGroup;
Leon Scroggins81db3662009-06-04 17:45:11 -040048import android.widget.ImageView;
49import android.widget.LinearLayout;
50import android.widget.ProgressBar;
51import android.widget.TextView;
Leon Scroggins81db3662009-06-04 17:45:11 -040052
Leon Scroggins1fe13a52010-02-09 15:31:26 -050053import com.android.common.speech.LoggingEvents;
54
Leon Scroggins1f005d32009-08-10 17:36:42 -040055/**
56 * This class represents a title bar for a particular "tab" or "window" in the
57 * browser.
58 */
Leon Scrogginse4b3bda2009-06-09 15:46:41 -040059public class TitleBar extends LinearLayout {
Leon Scroggins81db3662009-06-04 17:45:11 -040060 private TextView mTitle;
Leon Scroggins1f005d32009-08-10 17:36:42 -040061 private Drawable mCloseDrawable;
62 private ImageView mRtButton;
Leon Scroggins62e8f942009-09-03 15:08:54 -040063 private Drawable mCircularProgress;
Leon Scroggins81db3662009-06-04 17:45:11 -040064 private ProgressBar mHorizontalProgress;
Leon Scrogginsf4bb18a2009-09-11 18:37:53 -040065 private ImageView mFavicon;
Leon Scroggins62e8f942009-09-03 15:08:54 -040066 private ImageView mLockIcon;
Leon Scrogginsb3b04f72010-03-03 17:17:18 -050067 private ImageView mStopButton;
Leon Scrogginsa81a7642009-08-31 17:05:41 -040068 private Drawable mBookmarkDrawable;
Leon Scroggins11e71b12010-01-25 10:40:38 -050069 private Drawable mVoiceDrawable;
Leon Scroggins81db3662009-06-04 17:45:11 -040070 private boolean mInLoad;
Leon Scrogginsa81a7642009-08-31 17:05:41 -040071 private BrowserActivity mBrowserActivity;
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -040072 private Drawable mGenericFavicon;
73 private int mIconDimension;
Leon Scroggins68579392009-09-15 15:31:54 -040074 private View mTitleBg;
Leon Scrogginsc6fa1102009-09-21 10:40:01 -040075 private MyHandler mHandler;
Leon Scroggins11e71b12010-01-25 10:40:38 -050076 private Intent mVoiceSearchIntent;
77 private boolean mInVoiceMode;
Leon Scroggins58d56c62010-01-28 15:12:40 -050078 private Drawable mVoiceModeBackground;
79 private Drawable mNormalBackground;
Leon Scrogginsb3b04f72010-03-03 17:17:18 -050080 private Drawable mLoadingBackground;
Leon Scrogginsf48d44e2010-02-05 16:41:49 -050081 private ImageSpan mArcsSpan;
Leon Scroggins9535cee2010-03-15 20:37:16 -040082 private int mExtraMargin;
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();
106 mExtraMargin = (int) TypedValue.applyDimension(
107 TypedValue.COMPLEX_UNIT_DIP, 6.5f, metrics);
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400108 mIconDimension = (int) TypedValue.applyDimension(
Leon Scroggins9535cee2010-03-15 20:37:16 -0400109 TypedValue.COMPLEX_UNIT_DIP, 20f, metrics);
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400110 mCircularProgress.setBounds(0, 0, mIconDimension, mIconDimension);
Leon Scroggins81db3662009-06-04 17:45:11 -0400111 mHorizontalProgress = (ProgressBar) findViewById(
112 R.id.progress_horizontal);
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400113 mGenericFavicon = context.getResources().getDrawable(
114 R.drawable.app_web_browser_sm);
Leon Scroggins11e71b12010-01-25 10:40:38 -0500115 mVoiceSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
116 mVoiceSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
117 RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
118 PackageManager pm = context.getPackageManager();
119 ResolveInfo ri = pm.resolveActivity(mVoiceSearchIntent,
120 PackageManager.MATCH_DEFAULT_ONLY);
121 if (ri == null) {
122 mVoiceSearchIntent = null;
123 } else {
124 mVoiceDrawable = resources.getDrawable(
125 android.R.drawable.ic_btn_speak_now);
126 }
Leon Scroggins11e71b12010-01-25 10:40:38 -0500127 mBookmarkDrawable = mRtButton.getDrawable();
Leon Scroggins58d56c62010-01-28 15:12:40 -0500128 mVoiceModeBackground = resources.getDrawable(
Leon Scrogginsf48d44e2010-02-05 16:41:49 -0500129 R.drawable.title_voice);
Leon Scroggins58d56c62010-01-28 15:12:40 -0500130 mNormalBackground = mTitleBg.getBackground();
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500131 mLoadingBackground = resources.getDrawable(R.drawable.title_loading);
Leon Scrogginsf48d44e2010-02-05 16:41:49 -0500132 mArcsSpan = new ImageSpan(context, R.drawable.arcs,
133 ImageSpan.ALIGN_BASELINE);
Leon Scrogginse4b3bda2009-06-09 15:46:41 -0400134 }
135
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400136 private class MyHandler extends Handler {
137 public void handleMessage(Message msg) {
138 if (msg.what == LONG_PRESS) {
139 // Prevent the normal action from happening by setting the title
140 // bar's state to false.
141 mTitleBg.setPressed(false);
142 // Need to call a special method on BrowserActivity for when the
143 // fake title bar is up, because its ViewGroup does not show a
144 // context menu.
145 mBrowserActivity.showTitleBarContextMenu();
146 }
147 }
148 };
149
150 @Override
Leon Scroggins4e9f89b2010-02-22 16:54:14 -0500151 public void createContextMenu(ContextMenu menu) {
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400152 MenuInflater inflater = mBrowserActivity.getMenuInflater();
153 inflater.inflate(R.menu.title_context, menu);
Leon Scroggins4e9f89b2010-02-22 16:54:14 -0500154 mBrowserActivity.onCreateContextMenu(menu, this, null);
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400155 }
156
Leon Scroggins68579392009-09-15 15:31:54 -0400157 @Override
158 public boolean onTouchEvent(MotionEvent event) {
159 switch (event.getAction()) {
160 case MotionEvent.ACTION_DOWN:
161 // Make all touches hit either the textfield or the button,
162 // depending on which side of the right edge of the textfield
163 // they hit.
164 if ((int) event.getX() > mTitleBg.getRight()) {
165 mRtButton.setPressed(true);
166 } else {
167 mTitleBg.setPressed(true);
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400168 mHandler.sendMessageDelayed(mHandler.obtainMessage(
169 LONG_PRESS),
170 ViewConfiguration.getLongPressTimeout());
Leon Scroggins68579392009-09-15 15:31:54 -0400171 }
172 break;
173 case MotionEvent.ACTION_MOVE:
174 int slop = ViewConfiguration.get(mBrowserActivity)
175 .getScaledTouchSlop();
176 if ((int) event.getY() > getHeight() + slop) {
177 // We only trigger the actions in ACTION_UP if one or the
178 // other is pressed. Since the user moved off the title
179 // bar, mark both as not pressed.
180 mTitleBg.setPressed(false);
181 mRtButton.setPressed(false);
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400182 mHandler.removeMessages(LONG_PRESS);
Leon Scroggins68579392009-09-15 15:31:54 -0400183 break;
184 }
185 int x = (int) event.getX();
186 int titleRight = mTitleBg.getRight();
187 if (mTitleBg.isPressed() && x > titleRight + slop) {
188 mTitleBg.setPressed(false);
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400189 mHandler.removeMessages(LONG_PRESS);
Leon Scroggins68579392009-09-15 15:31:54 -0400190 } else if (mRtButton.isPressed() && x < titleRight - slop) {
191 mRtButton.setPressed(false);
192 }
193 break;
194 case MotionEvent.ACTION_CANCEL:
195 mRtButton.setPressed(false);
196 mTitleBg.setPressed(false);
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400197 mHandler.removeMessages(LONG_PRESS);
Leon Scroggins68579392009-09-15 15:31:54 -0400198 break;
199 case MotionEvent.ACTION_UP:
200 if (mRtButton.isPressed()) {
Leon Scroggins11e71b12010-01-25 10:40:38 -0500201 if (mInVoiceMode) {
Leon Scroggins1fe13a52010-02-09 15:31:26 -0500202 if (mBrowserActivity.getTabControl().getCurrentTab()
203 .voiceSearchSourceIsGoogle()) {
204 Intent i = new Intent(
205 LoggingEvents.ACTION_LOG_EVENT);
206 i.putExtra(LoggingEvents.EXTRA_EVENT,
207 LoggingEvents.VoiceSearch.RETRY);
208 mBrowserActivity.sendBroadcast(i);
209 }
Leon Scroggins11e71b12010-01-25 10:40:38 -0500210 mBrowserActivity.startActivity(mVoiceSearchIntent);
211 } else if (mInLoad) {
Leon Scroggins68579392009-09-15 15:31:54 -0400212 mBrowserActivity.stopLoading();
213 } else {
214 mBrowserActivity.bookmarksOrHistoryPicker(false);
215 }
216 mRtButton.setPressed(false);
217 } else if (mTitleBg.isPressed()) {
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400218 mHandler.removeMessages(LONG_PRESS);
Leon Scroggins58d56c62010-01-28 15:12:40 -0500219 if (mInVoiceMode) {
Leon Scroggins1fe13a52010-02-09 15:31:26 -0500220 if (mBrowserActivity.getTabControl().getCurrentTab()
221 .voiceSearchSourceIsGoogle()) {
222 Intent i = new Intent(
223 LoggingEvents.ACTION_LOG_EVENT);
224 i.putExtra(LoggingEvents.EXTRA_EVENT,
225 LoggingEvents.VoiceSearch.N_BEST_REVEAL);
226 mBrowserActivity.sendBroadcast(i);
227 }
Leon Scroggins58d56c62010-01-28 15:12:40 -0500228 mBrowserActivity.showVoiceSearchResults(
Leon Scrogginsea754072010-02-08 14:08:30 -0500229 mTitle.getText().toString().trim());
Leon Scroggins58d56c62010-01-28 15:12:40 -0500230 } else {
Leon Scroggins8ad29922010-02-16 12:33:55 -0500231 mBrowserActivity.editUrl();
Leon Scroggins58d56c62010-01-28 15:12:40 -0500232 }
Leon Scroggins68579392009-09-15 15:31:54 -0400233 mTitleBg.setPressed(false);
234 }
235 break;
236 default:
237 break;
238 }
239 return true;
Leon Scroggins81db3662009-06-04 17:45:11 -0400240 }
241
Leon Scroggins1f005d32009-08-10 17:36:42 -0400242 /**
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400243 * Set a new Bitmap for the Favicon.
Leon Scroggins1f005d32009-08-10 17:36:42 -0400244 */
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400245 /* package */ void setFavicon(Bitmap icon) {
246 Drawable[] array = new Drawable[3];
247 array[0] = new PaintDrawable(Color.BLACK);
248 PaintDrawable p = new PaintDrawable(Color.WHITE);
249 array[1] = p;
250 if (icon == null) {
251 array[2] = mGenericFavicon;
252 } else {
253 array[2] = new BitmapDrawable(icon);
Leon Scrogginsa81a7642009-08-31 17:05:41 -0400254 }
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400255 LayerDrawable d = new LayerDrawable(array);
256 d.setLayerInset(1, 1, 1, 1, 1);
257 d.setLayerInset(2, 2, 2, 2, 2);
Leon Scrogginsf4bb18a2009-09-11 18:37:53 -0400258 mFavicon.setImageDrawable(d);
Leon Scroggins81db3662009-06-04 17:45:11 -0400259 }
260
Leon Scroggins1f005d32009-08-10 17:36:42 -0400261 /**
Leon Scroggins11e71b12010-01-25 10:40:38 -0500262 * Change the TitleBar to or from voice mode. If there is no package to
263 * handle voice search, the TitleBar cannot be set to voice mode.
264 */
265 /* package */ void setInVoiceMode(boolean inVoiceMode) {
266 if (mInVoiceMode == inVoiceMode) return;
267 mInVoiceMode = inVoiceMode && mVoiceSearchIntent != null;
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500268 Drawable titleDrawable;
Leon Scroggins9535cee2010-03-15 20:37:16 -0400269 ViewGroup.MarginLayoutParams params
270 = (ViewGroup.MarginLayoutParams) mTitleBg.getLayoutParams();
Leon Scroggins11e71b12010-01-25 10:40:38 -0500271 if (mInVoiceMode) {
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500272 mRtButton.setImageDrawable(mVoiceDrawable);
Leon Scroggins58d56c62010-01-28 15:12:40 -0500273 titleDrawable = mVoiceModeBackground;
Leon Scroggins76e16862010-02-08 14:39:34 -0500274 mTitle.setEllipsize(null);
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500275 mRtButton.setVisibility(View.VISIBLE);
276 mStopButton.setVisibility(View.GONE);
Leon Scroggins9535cee2010-03-15 20:37:16 -0400277 if (params != null) {
278 params.setMargins(0, 0, 0, 0);
279 }
Leon Scroggins11e71b12010-01-25 10:40:38 -0500280 } else {
Leon Scroggins58d56c62010-01-28 15:12:40 -0500281 if (mInLoad) {
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500282 titleDrawable = mLoadingBackground;
283 mRtButton.setVisibility(View.GONE);
284 mStopButton.setVisibility(View.VISIBLE);
Leon Scroggins9535cee2010-03-15 20:37:16 -0400285 ViewGroup.MarginLayoutParams stopParams
286 = (ViewGroup.MarginLayoutParams)
287 mStopButton.getLayoutParams();
288 if (stopParams != null) {
289 stopParams.setMargins(0,0,0, mExtraMargin);
290 }
291 if (params != null) {
292 params.setMargins(0, 0, 0, mExtraMargin);
293 }
Leon Scroggins58d56c62010-01-28 15:12:40 -0500294 } else {
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500295 titleDrawable = mNormalBackground;
296 mRtButton.setVisibility(View.VISIBLE);
297 mStopButton.setVisibility(View.GONE);
298 mRtButton.setImageDrawable(mBookmarkDrawable);
Leon Scroggins9535cee2010-03-15 20:37:16 -0400299 if (params != null) {
300 params.setMargins(0, 0, 0, 0);
301 }
Leon Scroggins58d56c62010-01-28 15:12:40 -0500302 }
Leon Scroggins76e16862010-02-08 14:39:34 -0500303 mTitle.setEllipsize(TextUtils.TruncateAt.END);
Leon Scroggins11e71b12010-01-25 10:40:38 -0500304 }
Leon Scrogginsf48d44e2010-02-05 16:41:49 -0500305 mTitle.setSingleLine(!mInVoiceMode);
Leon Scroggins58d56c62010-01-28 15:12:40 -0500306 mTitleBg.setBackgroundDrawable(titleDrawable);
Leon Scroggins11e71b12010-01-25 10:40:38 -0500307 }
308
309 /**
Leon Scroggins1f005d32009-08-10 17:36:42 -0400310 * Set the Drawable for the lock icon, or null to hide it.
311 */
Leon Scroggins81db3662009-06-04 17:45:11 -0400312 /* package */ void setLock(Drawable d) {
Leon Scroggins62e8f942009-09-03 15:08:54 -0400313 if (null == d) {
314 mLockIcon.setVisibility(View.GONE);
315 } else {
316 mLockIcon.setImageDrawable(d);
317 mLockIcon.setVisibility(View.VISIBLE);
Leon Scroggins81db3662009-06-04 17:45:11 -0400318 }
319 }
320
Leon Scroggins1f005d32009-08-10 17:36:42 -0400321 /**
322 * Update the progress, from 0 to 100.
323 */
Leon Scroggins81db3662009-06-04 17:45:11 -0400324 /* package */ void setProgress(int newProgress) {
Leon Scroggins9535cee2010-03-15 20:37:16 -0400325 ViewGroup.MarginLayoutParams params
326 = (ViewGroup.MarginLayoutParams) mTitleBg.getLayoutParams();
Nicolas Roard1382b492009-09-16 21:50:06 +0100327 if (newProgress >= mHorizontalProgress.getMax()) {
Leon Scrogginsf4bb18a2009-09-11 18:37:53 -0400328 mTitle.setCompoundDrawables(null, null, null, null);
Leon Scroggins62e8f942009-09-03 15:08:54 -0400329 ((Animatable) mCircularProgress).stop();
330 mHorizontalProgress.setVisibility(View.INVISIBLE);
Leon Scroggins11e71b12010-01-25 10:40:38 -0500331 if (!mInVoiceMode) {
Leon Scrogginsa81a7642009-08-31 17:05:41 -0400332 mRtButton.setImageDrawable(mBookmarkDrawable);
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500333 mRtButton.setVisibility(View.VISIBLE);
334 mStopButton.setVisibility(View.GONE);
335 mTitleBg.setBackgroundDrawable(mNormalBackground);
Leon Scroggins9535cee2010-03-15 20:37:16 -0400336 // Set the margin for the textfield to 0, which is appropriate
337 // for the normal background
338 if (params != null) {
339 params.setMargins(0, 0, 0, 0);
340 }
Leon Scroggins1f005d32009-08-10 17:36:42 -0400341 }
Leon Scroggins81db3662009-06-04 17:45:11 -0400342 mInLoad = false;
343 } else {
Leon Scroggins81db3662009-06-04 17:45:11 -0400344 mHorizontalProgress.setProgress(newProgress);
Nicolas Roard1382b492009-09-16 21:50:06 +0100345 if (!mInLoad && getWindowToken() != null) {
346 // checking the window token lets us be sure that we
347 // are attached to a window before starting the animation,
348 // preventing a potential race condition
349 // (fix for bug http://b/2115736)
Leon Scrogginsf4bb18a2009-09-11 18:37:53 -0400350 mTitle.setCompoundDrawables(null, null, mCircularProgress,
Leon Scroggins62e8f942009-09-03 15:08:54 -0400351 null);
352 ((Animatable) mCircularProgress).start();
353 mHorizontalProgress.setVisibility(View.VISIBLE);
Leon Scroggins11e71b12010-01-25 10:40:38 -0500354 if (!mInVoiceMode) {
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500355 mTitleBg.setBackgroundDrawable(mLoadingBackground);
356 mRtButton.setVisibility(View.GONE);
357 mStopButton.setVisibility(View.VISIBLE);
Leon Scroggins9535cee2010-03-15 20:37:16 -0400358 // Set a margin for the bottom of the textfield and the stop
359 // button so that the total height matches that of the
360 // title bar when the normal background is showing.
361 if (params != null) {
362 params.setMargins(0,0,0, mExtraMargin);
363 }
364 ViewGroup.MarginLayoutParams stopParams
365 = (ViewGroup.MarginLayoutParams)
366 mStopButton.getLayoutParams();
367 if (stopParams != null) {
368 stopParams.setMargins(0,0,0, mExtraMargin);
369 }
Leon Scroggins62e8f942009-09-03 15:08:54 -0400370 }
371 mInLoad = true;
Leon Scrogginse4b3bda2009-06-09 15:46:41 -0400372 }
Leon Scroggins81db3662009-06-04 17:45:11 -0400373 }
374 }
375
Leon Scroggins1f005d32009-08-10 17:36:42 -0400376 /**
Leon Scroggins58d56c62010-01-28 15:12:40 -0500377 * Update the text displayed in the title bar.
378 * @param title String to display. If null, the loading string will be
379 * shown.
Leon Scroggins1f005d32009-08-10 17:36:42 -0400380 */
Leon Scroggins58d56c62010-01-28 15:12:40 -0500381 /* package */ void setDisplayTitle(String title) {
382 if (title == null) {
Leon Scrogginsa81a7642009-08-31 17:05:41 -0400383 mTitle.setText(R.string.title_bar_loading);
Leon Scrogginsd7c3dd52009-07-20 13:38:47 -0400384 } else {
Leon Scrogginsf48d44e2010-02-05 16:41:49 -0500385 if (mInVoiceMode) {
386 // Add two spaces. The second one will be replaced with an
387 // image, and the first one will put space between it and the
388 // text
389 SpannableString spannable = new SpannableString(title + " ");
390 int end = spannable.length();
391 spannable.setSpan(mArcsSpan, end - 1, end,
392 Spanned.SPAN_MARK_POINT);
393 mTitle.setText(spannable);
394 } else {
395 mTitle.setText(title);
396 }
Leon Scrogginsd7c3dd52009-07-20 13:38:47 -0400397 }
Leon Scroggins81db3662009-06-04 17:45:11 -0400398 }
399
400 /* package */ void setToTabPicker() {
401 mTitle.setText(R.string.tab_picker_title);
402 setFavicon(null);
403 setLock(null);
Leon Scroggins81db3662009-06-04 17:45:11 -0400404 mHorizontalProgress.setVisibility(View.GONE);
Leon Scroggins81db3662009-06-04 17:45:11 -0400405 }
406}