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