blob: 0f19864749b0b0c514a8efdcfc00c6caf28edb87 [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) {
Leon Scrogginsbf083d22010-03-22 10:54:04 -0400159 ImageView button = mInLoad ? mStopButton : mRtButton;
Leon Scroggins68579392009-09-15 15:31:54 -0400160 switch (event.getAction()) {
161 case MotionEvent.ACTION_DOWN:
162 // Make all touches hit either the textfield or the button,
163 // depending on which side of the right edge of the textfield
164 // they hit.
165 if ((int) event.getX() > mTitleBg.getRight()) {
Leon Scrogginsbf083d22010-03-22 10:54:04 -0400166 button.setPressed(true);
Leon Scroggins68579392009-09-15 15:31:54 -0400167 } else {
168 mTitleBg.setPressed(true);
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400169 mHandler.sendMessageDelayed(mHandler.obtainMessage(
170 LONG_PRESS),
171 ViewConfiguration.getLongPressTimeout());
Leon Scroggins68579392009-09-15 15:31:54 -0400172 }
173 break;
174 case MotionEvent.ACTION_MOVE:
175 int slop = ViewConfiguration.get(mBrowserActivity)
176 .getScaledTouchSlop();
177 if ((int) event.getY() > getHeight() + slop) {
178 // We only trigger the actions in ACTION_UP if one or the
179 // other is pressed. Since the user moved off the title
180 // bar, mark both as not pressed.
181 mTitleBg.setPressed(false);
Leon Scrogginsbf083d22010-03-22 10:54:04 -0400182 button.setPressed(false);
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400183 mHandler.removeMessages(LONG_PRESS);
Leon Scroggins68579392009-09-15 15:31:54 -0400184 break;
185 }
186 int x = (int) event.getX();
187 int titleRight = mTitleBg.getRight();
188 if (mTitleBg.isPressed() && x > titleRight + slop) {
189 mTitleBg.setPressed(false);
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400190 mHandler.removeMessages(LONG_PRESS);
Leon Scrogginsbf083d22010-03-22 10:54:04 -0400191 } else if (button.isPressed() && x < titleRight - slop) {
192 button.setPressed(false);
Leon Scroggins68579392009-09-15 15:31:54 -0400193 }
194 break;
195 case MotionEvent.ACTION_CANCEL:
Leon Scrogginsbf083d22010-03-22 10:54:04 -0400196 button.setPressed(false);
Leon Scroggins68579392009-09-15 15:31:54 -0400197 mTitleBg.setPressed(false);
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400198 mHandler.removeMessages(LONG_PRESS);
Leon Scroggins68579392009-09-15 15:31:54 -0400199 break;
200 case MotionEvent.ACTION_UP:
Leon Scrogginsbf083d22010-03-22 10:54:04 -0400201 if (button.isPressed()) {
Leon Scroggins11e71b12010-01-25 10:40:38 -0500202 if (mInVoiceMode) {
Leon Scroggins1fe13a52010-02-09 15:31:26 -0500203 if (mBrowserActivity.getTabControl().getCurrentTab()
204 .voiceSearchSourceIsGoogle()) {
205 Intent i = new Intent(
206 LoggingEvents.ACTION_LOG_EVENT);
207 i.putExtra(LoggingEvents.EXTRA_EVENT,
208 LoggingEvents.VoiceSearch.RETRY);
209 mBrowserActivity.sendBroadcast(i);
210 }
Leon Scroggins11e71b12010-01-25 10:40:38 -0500211 mBrowserActivity.startActivity(mVoiceSearchIntent);
212 } else if (mInLoad) {
Leon Scroggins68579392009-09-15 15:31:54 -0400213 mBrowserActivity.stopLoading();
214 } else {
215 mBrowserActivity.bookmarksOrHistoryPicker(false);
216 }
Leon Scrogginsbf083d22010-03-22 10:54:04 -0400217 button.setPressed(false);
Leon Scroggins68579392009-09-15 15:31:54 -0400218 } else if (mTitleBg.isPressed()) {
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400219 mHandler.removeMessages(LONG_PRESS);
Leon Scroggins58d56c62010-01-28 15:12:40 -0500220 if (mInVoiceMode) {
Leon Scroggins1fe13a52010-02-09 15:31:26 -0500221 if (mBrowserActivity.getTabControl().getCurrentTab()
222 .voiceSearchSourceIsGoogle()) {
223 Intent i = new Intent(
224 LoggingEvents.ACTION_LOG_EVENT);
225 i.putExtra(LoggingEvents.EXTRA_EVENT,
226 LoggingEvents.VoiceSearch.N_BEST_REVEAL);
227 mBrowserActivity.sendBroadcast(i);
228 }
Leon Scroggins58d56c62010-01-28 15:12:40 -0500229 mBrowserActivity.showVoiceSearchResults(
Leon Scrogginsea754072010-02-08 14:08:30 -0500230 mTitle.getText().toString().trim());
Leon Scroggins58d56c62010-01-28 15:12:40 -0500231 } else {
Leon Scroggins8ad29922010-02-16 12:33:55 -0500232 mBrowserActivity.editUrl();
Leon Scroggins58d56c62010-01-28 15:12:40 -0500233 }
Leon Scroggins68579392009-09-15 15:31:54 -0400234 mTitleBg.setPressed(false);
235 }
236 break;
237 default:
238 break;
239 }
240 return true;
Leon Scroggins81db3662009-06-04 17:45:11 -0400241 }
242
Leon Scroggins1f005d32009-08-10 17:36:42 -0400243 /**
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400244 * Set a new Bitmap for the Favicon.
Leon Scroggins1f005d32009-08-10 17:36:42 -0400245 */
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400246 /* package */ void setFavicon(Bitmap icon) {
247 Drawable[] array = new Drawable[3];
248 array[0] = new PaintDrawable(Color.BLACK);
249 PaintDrawable p = new PaintDrawable(Color.WHITE);
250 array[1] = p;
251 if (icon == null) {
252 array[2] = mGenericFavicon;
253 } else {
254 array[2] = new BitmapDrawable(icon);
Leon Scrogginsa81a7642009-08-31 17:05:41 -0400255 }
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400256 LayerDrawable d = new LayerDrawable(array);
257 d.setLayerInset(1, 1, 1, 1, 1);
258 d.setLayerInset(2, 2, 2, 2, 2);
Leon Scrogginsf4bb18a2009-09-11 18:37:53 -0400259 mFavicon.setImageDrawable(d);
Leon Scroggins81db3662009-06-04 17:45:11 -0400260 }
261
Leon Scroggins1f005d32009-08-10 17:36:42 -0400262 /**
Leon Scroggins11e71b12010-01-25 10:40:38 -0500263 * Change the TitleBar to or from voice mode. If there is no package to
264 * handle voice search, the TitleBar cannot be set to voice mode.
265 */
266 /* package */ void setInVoiceMode(boolean inVoiceMode) {
267 if (mInVoiceMode == inVoiceMode) return;
268 mInVoiceMode = inVoiceMode && mVoiceSearchIntent != null;
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500269 Drawable titleDrawable;
Leon Scroggins9535cee2010-03-15 20:37:16 -0400270 ViewGroup.MarginLayoutParams params
271 = (ViewGroup.MarginLayoutParams) mTitleBg.getLayoutParams();
Leon Scroggins11e71b12010-01-25 10:40:38 -0500272 if (mInVoiceMode) {
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500273 mRtButton.setImageDrawable(mVoiceDrawable);
Leon Scroggins58d56c62010-01-28 15:12:40 -0500274 titleDrawable = mVoiceModeBackground;
Leon Scroggins76e16862010-02-08 14:39:34 -0500275 mTitle.setEllipsize(null);
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500276 mRtButton.setVisibility(View.VISIBLE);
277 mStopButton.setVisibility(View.GONE);
Leon Scroggins9535cee2010-03-15 20:37:16 -0400278 if (params != null) {
279 params.setMargins(0, 0, 0, 0);
280 }
Leon Scroggins11e71b12010-01-25 10:40:38 -0500281 } else {
Leon Scroggins58d56c62010-01-28 15:12:40 -0500282 if (mInLoad) {
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500283 titleDrawable = mLoadingBackground;
284 mRtButton.setVisibility(View.GONE);
285 mStopButton.setVisibility(View.VISIBLE);
Leon Scroggins9535cee2010-03-15 20:37:16 -0400286 ViewGroup.MarginLayoutParams stopParams
287 = (ViewGroup.MarginLayoutParams)
288 mStopButton.getLayoutParams();
289 if (stopParams != null) {
290 stopParams.setMargins(0,0,0, mExtraMargin);
291 }
292 if (params != null) {
293 params.setMargins(0, 0, 0, mExtraMargin);
294 }
Leon Scroggins58d56c62010-01-28 15:12:40 -0500295 } else {
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500296 titleDrawable = mNormalBackground;
297 mRtButton.setVisibility(View.VISIBLE);
298 mStopButton.setVisibility(View.GONE);
299 mRtButton.setImageDrawable(mBookmarkDrawable);
Leon Scroggins9535cee2010-03-15 20:37:16 -0400300 if (params != null) {
301 params.setMargins(0, 0, 0, 0);
302 }
Leon Scroggins58d56c62010-01-28 15:12:40 -0500303 }
Leon Scroggins76e16862010-02-08 14:39:34 -0500304 mTitle.setEllipsize(TextUtils.TruncateAt.END);
Leon Scroggins11e71b12010-01-25 10:40:38 -0500305 }
Leon Scrogginsf48d44e2010-02-05 16:41:49 -0500306 mTitle.setSingleLine(!mInVoiceMode);
Leon Scroggins58d56c62010-01-28 15:12:40 -0500307 mTitleBg.setBackgroundDrawable(titleDrawable);
Leon Scroggins11e71b12010-01-25 10:40:38 -0500308 }
309
310 /**
Leon Scroggins1f005d32009-08-10 17:36:42 -0400311 * Set the Drawable for the lock icon, or null to hide it.
312 */
Leon Scroggins81db3662009-06-04 17:45:11 -0400313 /* package */ void setLock(Drawable d) {
Leon Scroggins62e8f942009-09-03 15:08:54 -0400314 if (null == d) {
315 mLockIcon.setVisibility(View.GONE);
316 } else {
317 mLockIcon.setImageDrawable(d);
318 mLockIcon.setVisibility(View.VISIBLE);
Leon Scroggins81db3662009-06-04 17:45:11 -0400319 }
320 }
321
Leon Scroggins1f005d32009-08-10 17:36:42 -0400322 /**
323 * Update the progress, from 0 to 100.
324 */
Leon Scroggins81db3662009-06-04 17:45:11 -0400325 /* package */ void setProgress(int newProgress) {
Leon Scroggins9535cee2010-03-15 20:37:16 -0400326 ViewGroup.MarginLayoutParams params
327 = (ViewGroup.MarginLayoutParams) mTitleBg.getLayoutParams();
Nicolas Roard1382b492009-09-16 21:50:06 +0100328 if (newProgress >= mHorizontalProgress.getMax()) {
Leon Scrogginsf4bb18a2009-09-11 18:37:53 -0400329 mTitle.setCompoundDrawables(null, null, null, null);
Leon Scroggins62e8f942009-09-03 15:08:54 -0400330 ((Animatable) mCircularProgress).stop();
331 mHorizontalProgress.setVisibility(View.INVISIBLE);
Leon Scroggins11e71b12010-01-25 10:40:38 -0500332 if (!mInVoiceMode) {
Leon Scrogginsa81a7642009-08-31 17:05:41 -0400333 mRtButton.setImageDrawable(mBookmarkDrawable);
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500334 mRtButton.setVisibility(View.VISIBLE);
335 mStopButton.setVisibility(View.GONE);
336 mTitleBg.setBackgroundDrawable(mNormalBackground);
Leon Scroggins9535cee2010-03-15 20:37:16 -0400337 // Set the margin for the textfield to 0, which is appropriate
338 // for the normal background
339 if (params != null) {
340 params.setMargins(0, 0, 0, 0);
341 }
Leon Scroggins1f005d32009-08-10 17:36:42 -0400342 }
Leon Scroggins81db3662009-06-04 17:45:11 -0400343 mInLoad = false;
344 } else {
Leon Scroggins81db3662009-06-04 17:45:11 -0400345 mHorizontalProgress.setProgress(newProgress);
Nicolas Roard1382b492009-09-16 21:50:06 +0100346 if (!mInLoad && getWindowToken() != null) {
347 // checking the window token lets us be sure that we
348 // are attached to a window before starting the animation,
349 // preventing a potential race condition
350 // (fix for bug http://b/2115736)
Leon Scrogginsf4bb18a2009-09-11 18:37:53 -0400351 mTitle.setCompoundDrawables(null, null, mCircularProgress,
Leon Scroggins62e8f942009-09-03 15:08:54 -0400352 null);
353 ((Animatable) mCircularProgress).start();
354 mHorizontalProgress.setVisibility(View.VISIBLE);
Leon Scroggins11e71b12010-01-25 10:40:38 -0500355 if (!mInVoiceMode) {
Leon Scrogginsb3b04f72010-03-03 17:17:18 -0500356 mTitleBg.setBackgroundDrawable(mLoadingBackground);
357 mRtButton.setVisibility(View.GONE);
358 mStopButton.setVisibility(View.VISIBLE);
Leon Scroggins9535cee2010-03-15 20:37:16 -0400359 // Set a margin for the bottom of the textfield and the stop
360 // button so that the total height matches that of the
361 // title bar when the normal background is showing.
362 if (params != null) {
363 params.setMargins(0,0,0, mExtraMargin);
364 }
365 ViewGroup.MarginLayoutParams stopParams
366 = (ViewGroup.MarginLayoutParams)
367 mStopButton.getLayoutParams();
368 if (stopParams != null) {
369 stopParams.setMargins(0,0,0, mExtraMargin);
370 }
Leon Scroggins62e8f942009-09-03 15:08:54 -0400371 }
372 mInLoad = true;
Leon Scrogginse4b3bda2009-06-09 15:46:41 -0400373 }
Leon Scroggins81db3662009-06-04 17:45:11 -0400374 }
375 }
376
Leon Scroggins1f005d32009-08-10 17:36:42 -0400377 /**
Leon Scroggins58d56c62010-01-28 15:12:40 -0500378 * Update the text displayed in the title bar.
379 * @param title String to display. If null, the loading string will be
380 * shown.
Leon Scroggins1f005d32009-08-10 17:36:42 -0400381 */
Leon Scroggins58d56c62010-01-28 15:12:40 -0500382 /* package */ void setDisplayTitle(String title) {
383 if (title == null) {
Leon Scrogginsa81a7642009-08-31 17:05:41 -0400384 mTitle.setText(R.string.title_bar_loading);
Leon Scrogginsd7c3dd52009-07-20 13:38:47 -0400385 } else {
Leon Scrogginsf48d44e2010-02-05 16:41:49 -0500386 if (mInVoiceMode) {
387 // Add two spaces. The second one will be replaced with an
388 // image, and the first one will put space between it and the
389 // text
390 SpannableString spannable = new SpannableString(title + " ");
391 int end = spannable.length();
392 spannable.setSpan(mArcsSpan, end - 1, end,
393 Spanned.SPAN_MARK_POINT);
394 mTitle.setText(spannable);
395 } else {
396 mTitle.setText(title);
397 }
Leon Scrogginsd7c3dd52009-07-20 13:38:47 -0400398 }
Leon Scroggins81db3662009-06-04 17:45:11 -0400399 }
400
401 /* package */ void setToTabPicker() {
402 mTitle.setText(R.string.tab_picker_title);
403 setFavicon(null);
404 setLock(null);
Leon Scroggins81db3662009-06-04 17:45:11 -0400405 mHorizontalProgress.setVisibility(View.GONE);
Leon Scroggins81db3662009-06-04 17:45:11 -0400406 }
407}