Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 19 | import com.android.browser.UrlInputView.UrlInputListener; |
| 20 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 21 | import android.app.SearchManager; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 22 | import android.content.Context; |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 23 | import android.content.Intent; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 24 | import android.content.res.Resources; |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 25 | import android.graphics.Bitmap; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 26 | import android.graphics.drawable.Drawable; |
Michael Kolb | 1ce7813 | 2010-09-23 15:50:53 -0700 | [diff] [blame] | 27 | import android.text.TextUtils; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 28 | import android.view.ContextMenu; |
| 29 | import android.view.LayoutInflater; |
| 30 | import android.view.MenuInflater; |
| 31 | import android.view.View; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 32 | import android.view.View.OnClickListener; |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 33 | import android.view.View.OnFocusChangeListener; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 34 | import android.widget.ImageView; |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 35 | import android.widget.TextView; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 36 | |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 37 | /** |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 38 | * tabbed title bar for xlarge screen browser |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 39 | */ |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 40 | public class TitleBarXLarge extends TitleBarBase |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 41 | implements UrlInputListener, OnClickListener, OnFocusChangeListener { |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 42 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 43 | private static final int PROGRESS_MAX = 100; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 44 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 45 | private BrowserActivity mBrowserActivity; |
| 46 | private Drawable mStopDrawable; |
| 47 | private Drawable mReloadDrawable; |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 48 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 49 | |
Michael Kolb | 3f65c38 | 2010-08-20 15:31:16 -0700 | [diff] [blame] | 50 | private View mContainer; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 51 | private View mBackButton; |
| 52 | private View mForwardButton; |
| 53 | private View mStar; |
| 54 | private View mSearchButton; |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 55 | private View mFocusContainer; |
| 56 | private View mUnfocusContainer; |
| 57 | private View mGoButton; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 58 | private ImageView mStopButton; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 59 | private View mAllButton; |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 60 | private View mClearButton; |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 61 | private PageProgressView mProgressView; |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 62 | private UrlInputView mUrlFocused; |
| 63 | private TextView mUrlUnfocused; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 64 | private boolean mInLoad; |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 65 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 66 | public TitleBarXLarge(BrowserActivity context) { |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 67 | super(context); |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 68 | mBrowserActivity = context; |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 69 | Resources resources = context.getResources(); |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 70 | mStopDrawable = resources.getDrawable(R.drawable.ic_stop_normal); |
| 71 | mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_normal); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 72 | rebuildLayout(context, true); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 73 | } |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 74 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 75 | private void rebuildLayout(Context context, boolean rebuildData) { |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 76 | LayoutInflater factory = LayoutInflater.from(context); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 77 | factory.inflate(R.layout.url_bar, this); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 78 | |
Michael Kolb | 3f65c38 | 2010-08-20 15:31:16 -0700 | [diff] [blame] | 79 | mContainer = findViewById(R.id.taburlbar); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 80 | mUrlFocused = (UrlInputView) findViewById(R.id.url_focused); |
| 81 | mUrlUnfocused = (TextView) findViewById(R.id.url_unfocused); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 82 | mAllButton = findViewById(R.id.all_btn); |
| 83 | // TODO: Change enabled states based on whether you can go |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 84 | // back/forward. Probably should be done inside onPageStarted. |
| 85 | mBackButton = findViewById(R.id.back); |
| 86 | mForwardButton = findViewById(R.id.forward); |
| 87 | mStar = findViewById(R.id.star); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 88 | mStopButton = (ImageView) findViewById(R.id.stop); |
| 89 | mSearchButton = findViewById(R.id.search); |
| 90 | mLockIcon = (ImageView) findViewById(R.id.lock); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 91 | mGoButton = findViewById(R.id.go); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 92 | mClearButton = findViewById(R.id.clear); |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 93 | mProgressView = (PageProgressView) findViewById(R.id.progress); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 94 | mFocusContainer = findViewById(R.id.urlbar_focused); |
| 95 | mUnfocusContainer = findViewById(R.id.urlbar_unfocused); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 96 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 97 | mBackButton.setOnClickListener(this); |
| 98 | mForwardButton.setOnClickListener(this); |
| 99 | mStar.setOnClickListener(this); |
| 100 | mAllButton.setOnClickListener(this); |
| 101 | mStopButton.setOnClickListener(this); |
| 102 | mSearchButton.setOnClickListener(this); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 103 | mGoButton.setOnClickListener(this); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 104 | mClearButton.setOnClickListener(this); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 105 | mUrlFocused.setUrlInputListener(this); |
| 106 | mUrlUnfocused.setOnFocusChangeListener(this); |
Michael Kolb | 21ce4d2 | 2010-09-15 14:55:05 -0700 | [diff] [blame] | 107 | mUrlFocused.setContainer(mFocusContainer); |
Michael Kolb | 0506f2d | 2010-10-14 16:20:16 -0700 | [diff] [blame] | 108 | mUnfocusContainer.setOnClickListener(this); |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 109 | } |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 110 | |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 111 | public void onFocusChange(View v, boolean hasFocus) { |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 112 | if (hasFocus) { |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 113 | setUrlMode(true); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 114 | mUrlFocused.selectAll(); |
| 115 | mUrlFocused.requestFocus(); |
| 116 | mUrlFocused.setDropDownWidth(mUnfocusContainer.getWidth()); |
| 117 | mUrlFocused.setDropDownHorizontalOffset(-mUrlFocused.getLeft()); |
| 118 | } |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 121 | @Override |
| 122 | public void onClick(View v) { |
Michael Kolb | 0506f2d | 2010-10-14 16:20:16 -0700 | [diff] [blame] | 123 | if (mUnfocusContainer == v) { |
| 124 | mUrlUnfocused.requestFocus(); |
| 125 | } else if (mBackButton == v) { |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 126 | mBrowserActivity.getTopWindow().goBack(); |
| 127 | } else if (mForwardButton == v) { |
| 128 | mBrowserActivity.getTopWindow().goForward(); |
| 129 | } else if (mStar == v) { |
Leon Scroggins | 88d0803 | 2010-10-21 15:17:10 -0400 | [diff] [blame] | 130 | mBrowserActivity.bookmarkCurrentPage( |
| 131 | AddBookmarkPage.DEFAULT_FOLDER_ID); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 132 | } else if (mAllButton == v) { |
Michael Kolb | e421c24 | 2010-10-04 19:29:01 -0700 | [diff] [blame] | 133 | mBrowserActivity.bookmarksOrHistoryPicker(false); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 134 | } else if (mSearchButton == v) { |
| 135 | search(); |
| 136 | } else if (mStopButton == v) { |
| 137 | stopOrRefresh(); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 138 | } else if (mGoButton == v) { |
Michael Kolb | 1ce7813 | 2010-09-23 15:50:53 -0700 | [diff] [blame] | 139 | if (!TextUtils.isEmpty(mUrlFocused.getText())) { |
| 140 | onAction(mUrlFocused.getText().toString()); |
| 141 | } |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 142 | } else if (mClearButton == v) { |
| 143 | mUrlFocused.setText(""); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | |
Michael Kolb | 3f65c38 | 2010-08-20 15:31:16 -0700 | [diff] [blame] | 147 | int getHeightWithoutProgress() { |
| 148 | return mContainer.getHeight(); |
| 149 | } |
| 150 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 151 | @Override |
| 152 | void setFavicon(Bitmap icon) { } |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 153 | |
| 154 | // UrlInputListener implementation |
| 155 | |
| 156 | @Override |
| 157 | public void onAction(String text) { |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 158 | mBrowserActivity.getTabControl().getCurrentTopWebView().requestFocus(); |
| 159 | mBrowserActivity.hideFakeTitleBar(); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 160 | Intent i = new Intent(); |
| 161 | i.setAction(Intent.ACTION_SEARCH); |
| 162 | i.putExtra(SearchManager.QUERY, text); |
| 163 | mBrowserActivity.onNewIntent(i); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 164 | setUrlMode(false); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 165 | setDisplayTitle(text); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public void onDismiss() { |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 170 | mBrowserActivity.getTabControl().getCurrentTopWebView().requestFocus(); |
| 171 | mBrowserActivity.hideFakeTitleBar(); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 172 | setUrlMode(false); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 173 | setDisplayTitle(mBrowserActivity.getTabControl().getCurrentWebView().getUrl()); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | @Override |
| 177 | public void onEdit(String text) { |
Michael Kolb | 7b20ddd | 2010-10-14 15:03:28 -0700 | [diff] [blame] | 178 | setDisplayTitle(text, true); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 179 | if (text != null) { |
| 180 | mUrlFocused.setSelection(text.length()); |
| 181 | } |
| 182 | } |
| 183 | |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 184 | private void setUrlMode(boolean focused) { |
| 185 | swapUrlContainer(focused); |
| 186 | if (focused) { |
| 187 | mSearchButton.setVisibility(View.GONE); |
| 188 | mGoButton.setVisibility(View.VISIBLE); |
| 189 | } else { |
| 190 | mSearchButton.setVisibility(View.VISIBLE); |
| 191 | mGoButton.setVisibility(View.GONE); |
| 192 | } |
| 193 | } |
| 194 | |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 195 | private void swapUrlContainer(boolean focus) { |
| 196 | mUnfocusContainer.setVisibility(focus ? View.GONE : View.VISIBLE); |
| 197 | mFocusContainer.setVisibility(focus ? View.VISIBLE : View.GONE); |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | @Override |
| 201 | public void createContextMenu(ContextMenu menu) { |
| 202 | MenuInflater inflater = mBrowserActivity.getMenuInflater(); |
| 203 | inflater.inflate(R.menu.title_context, menu); |
| 204 | mBrowserActivity.onCreateContextMenu(menu, this, null); |
| 205 | } |
| 206 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 207 | private void search() { |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 208 | setDisplayTitle(""); |
| 209 | mUrlUnfocused.requestFocus(); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 212 | private void stopOrRefresh() { |
| 213 | if (mInLoad) { |
| 214 | mBrowserActivity.stopLoading(); |
| 215 | } else { |
| 216 | mBrowserActivity.getTopWindow().reload(); |
| 217 | } |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /** |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 221 | * Update the progress, from 0 to 100. |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 222 | */ |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 223 | @Override |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 224 | void setProgress(int newProgress) { |
| 225 | if (newProgress >= PROGRESS_MAX) { |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 226 | mProgressView.setProgress(PageProgressView.MAX_PROGRESS); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 227 | mProgressView.setVisibility(View.GONE); |
| 228 | mInLoad = false; |
| 229 | mStopButton.setImageDrawable(mReloadDrawable); |
| 230 | } else { |
| 231 | if (!mInLoad) { |
| 232 | mProgressView.setVisibility(View.VISIBLE); |
| 233 | mInLoad = true; |
| 234 | mStopButton.setImageDrawable(mStopDrawable); |
| 235 | } |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 236 | mProgressView.setProgress(newProgress * PageProgressView.MAX_PROGRESS |
| 237 | / PROGRESS_MAX); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 238 | } |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | @Override |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 242 | /* package */ void setDisplayTitle(String title) { |
Michael Kolb | 21ce4d2 | 2010-09-15 14:55:05 -0700 | [diff] [blame] | 243 | mUrlFocused.setText(title, false); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 244 | mUrlUnfocused.setText(title); |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 245 | } |
| 246 | |
Michael Kolb | 7b20ddd | 2010-10-14 15:03:28 -0700 | [diff] [blame] | 247 | void setDisplayTitle(String title, boolean filter) { |
| 248 | mUrlFocused.setText(title, filter); |
| 249 | mUrlUnfocused.setText(title); |
| 250 | } |
| 251 | |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 252 | } |