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