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