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