Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 1 | /* |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 2 | * Copyright (C) 2011 The Android Open Source Project |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 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 | */ |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 16 | package com.android.browser; |
| 17 | |
| 18 | import android.content.Context; |
| 19 | import android.content.res.Resources; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 20 | import android.graphics.drawable.Drawable; |
Michael Kolb | 1ce7813 | 2010-09-23 15:50:53 -0700 | [diff] [blame] | 21 | import android.text.TextUtils; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 22 | import android.util.AttributeSet; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 23 | import android.view.View; |
Michael Kolb | b6bc32c | 2010-12-10 11:51:54 -0800 | [diff] [blame] | 24 | import android.webkit.WebView; |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 25 | import android.widget.ImageButton; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 26 | import android.widget.ImageView; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 27 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 28 | import java.util.List; |
| 29 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 30 | public class NavigationBarTablet extends NavigationBarBase { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 31 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 32 | private Drawable mStopDrawable; |
| 33 | private Drawable mReloadDrawable; |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 34 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 35 | private View mUrlContainer; |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 36 | private ImageButton mBackButton; |
| 37 | private ImageButton mForwardButton; |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 38 | private ImageView mStar; |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 39 | private ImageView mUrlIcon; |
| 40 | private ImageView mSearchButton; |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 41 | private View mGoButton; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 42 | private ImageView mStopButton; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 43 | private View mAllButton; |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 44 | private View mClearButton; |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 45 | private ImageView mVoiceSearch; |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 46 | private Drawable mFocusDrawable; |
| 47 | private Drawable mUnfocusDrawable; |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 48 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 49 | public NavigationBarTablet(Context context) { |
| 50 | super(context); |
| 51 | init(context); |
| 52 | } |
| 53 | |
| 54 | public NavigationBarTablet(Context context, AttributeSet attrs) { |
| 55 | super(context, attrs); |
| 56 | init(context); |
| 57 | } |
| 58 | |
| 59 | public NavigationBarTablet(Context context, AttributeSet attrs, int defStyle) { |
| 60 | super(context, attrs, defStyle); |
| 61 | init(context); |
| 62 | } |
| 63 | |
| 64 | private void init(Context context) { |
| 65 | Resources resources = context.getResources(); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 66 | mStopDrawable = resources.getDrawable(R.drawable.ic_stop_holo_dark); |
| 67 | mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_holo_dark); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 68 | mFocusDrawable = resources.getDrawable( |
| 69 | R.drawable.textfield_active_holo_dark); |
| 70 | mUnfocusDrawable = resources.getDrawable( |
| 71 | R.drawable.textfield_default_holo_dark); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 72 | } |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 73 | |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 74 | @Override |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 75 | protected void onFinishInflate() { |
| 76 | super.onFinishInflate(); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 77 | mAllButton = findViewById(R.id.all_btn); |
| 78 | // TODO: Change enabled states based on whether you can go |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 79 | // back/forward. Probably should be done inside onPageStarted. |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 80 | mBackButton = (ImageButton) findViewById(R.id.back); |
| 81 | mForwardButton = (ImageButton) findViewById(R.id.forward); |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 82 | mUrlIcon = (ImageView) findViewById(R.id.url_icon); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 83 | mStar = (ImageView) findViewById(R.id.star); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 84 | mStopButton = (ImageView) findViewById(R.id.stop); |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 85 | mSearchButton = (ImageView) findViewById(R.id.search); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 86 | mGoButton = findViewById(R.id.go); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 87 | mClearButton = findViewById(R.id.clear); |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 88 | mVoiceSearch = (ImageView) findViewById(R.id.voicesearch); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 89 | mUrlContainer = findViewById(R.id.urlbar_focused); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 90 | mBackButton.setOnClickListener(this); |
| 91 | mForwardButton.setOnClickListener(this); |
| 92 | mStar.setOnClickListener(this); |
| 93 | mAllButton.setOnClickListener(this); |
| 94 | mStopButton.setOnClickListener(this); |
| 95 | mSearchButton.setOnClickListener(this); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 96 | mGoButton.setOnClickListener(this); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 97 | mClearButton.setOnClickListener(this); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 98 | mVoiceSearch.setOnClickListener(this); |
John Reck | 4650033 | 2011-06-07 14:36:10 -0700 | [diff] [blame] | 99 | setUaSwitcher(mUrlIcon); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 100 | mUrlInput.setContainer(mUrlContainer); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public void setTitleBar(TitleBar titleBar) { |
| 105 | super.setTitleBar(titleBar); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 106 | setFocusState(false); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 107 | } |
| 108 | |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 109 | void updateNavigationState(Tab tab) { |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 110 | if (tab != null) { |
| 111 | mBackButton.setImageResource(tab.canGoBack() |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 112 | ? R.drawable.ic_back_holo_dark |
| 113 | : R.drawable.ic_back_disabled_holo_dark); |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 114 | mForwardButton.setImageResource(tab.canGoForward() |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 115 | ? R.drawable.ic_forward_holo_dark |
| 116 | : R.drawable.ic_forward_disabled_holo_dark); |
| 117 | } |
John Reck | b8b2af8 | 2011-05-20 15:58:33 -0700 | [diff] [blame] | 118 | updateUrlIcon(); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 119 | } |
| 120 | |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 121 | @Override |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 122 | public void setCurrentUrlIsBookmark(boolean isBookmark) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 123 | mStar.setActivated(isBookmark); |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 124 | } |
| 125 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 126 | @Override |
| 127 | public void onClick(View v) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 128 | if (mBackButton == v) { |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 129 | mUiController.getCurrentTab().goBack(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 130 | } else if (mForwardButton == v) { |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 131 | mUiController.getCurrentTab().goForward(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 132 | } else if (mStar == v) { |
John Reck | 3ffc5ca | 2011-06-10 15:56:06 -0700 | [diff] [blame] | 133 | mUiController.bookmarkCurrentPage(true); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 134 | } else if (mAllButton == v) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 135 | mUiController.bookmarksOrHistoryPicker(false); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 136 | } else if (mSearchButton == v) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 137 | mBaseUi.editUrl(true); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 138 | } else if (mStopButton == v) { |
| 139 | stopOrRefresh(); |
Michael Kolb | 513286f | 2010-09-09 12:55:12 -0700 | [diff] [blame] | 140 | } else if (mGoButton == v) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 141 | if (!TextUtils.isEmpty(mUrlInput.getText())) { |
| 142 | onAction(mUrlInput.getText().toString(), null, |
Michael Kolb | 257cc2c | 2010-12-09 09:45:52 -0800 | [diff] [blame] | 143 | UrlInputView.TYPED); |
Michael Kolb | 1ce7813 | 2010-09-23 15:50:53 -0700 | [diff] [blame] | 144 | } |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 145 | } else if (mClearButton == v) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 146 | clearOrClose(); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 147 | } else if (mVoiceSearch == v) { |
| 148 | mUiController.startVoiceSearch(); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 149 | } else { |
| 150 | super.onClick(v); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 154 | private void clearOrClose() { |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 155 | if (TextUtils.isEmpty(mUrlInput.getUserText())) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 156 | // close |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 157 | mUrlInput.clearFocus(); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 158 | } else { |
| 159 | // clear |
| 160 | mUrlInput.setText(""); |
| 161 | } |
| 162 | } |
| 163 | |
John Reck | b8b2af8 | 2011-05-20 15:58:33 -0700 | [diff] [blame] | 164 | void updateUrlIcon() { |
John Reck | 4650033 | 2011-06-07 14:36:10 -0700 | [diff] [blame] | 165 | mUrlIcon.setImageResource(mInVoiceMode ? |
| 166 | R.drawable.ic_search_holo_dark |
| 167 | : R.drawable.ic_web_holo_dark); |
John Reck | b8b2af8 | 2011-05-20 15:58:33 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 170 | @Override |
| 171 | protected void setFocusState(boolean focus) { |
| 172 | super.setFocusState(focus); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 173 | if (focus) { |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 174 | mSearchButton.setVisibility(View.GONE); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 175 | mStar.setVisibility(View.GONE); |
| 176 | mClearButton.setVisibility(View.VISIBLE); |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 177 | mUrlIcon.setImageResource(R.drawable.ic_search_holo_dark); |
Michael Kolb | 60a68f5 | 2011-02-24 11:02:52 -0800 | [diff] [blame] | 178 | updateSearchMode(false); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 179 | } else { |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 180 | mGoButton.setVisibility(View.GONE); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 181 | mVoiceSearch.setVisibility(View.GONE); |
| 182 | mStar.setVisibility(View.VISIBLE); |
| 183 | mClearButton.setVisibility(View.GONE); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 184 | if (mTitleBar.useQuickControls()) { |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 185 | mSearchButton.setVisibility(View.GONE); |
| 186 | } else { |
| 187 | mSearchButton.setVisibility(View.VISIBLE); |
| 188 | } |
John Reck | b8b2af8 | 2011-05-20 15:58:33 -0700 | [diff] [blame] | 189 | updateUrlIcon(); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 190 | } |
John Reck | 7e5b8b5 | 2011-06-22 13:46:25 -0700 | [diff] [blame] | 191 | mUrlContainer.setBackgroundDrawable(focus |
| 192 | ? mFocusDrawable : mUnfocusDrawable); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 195 | private void stopOrRefresh() { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 196 | if (mTitleBar.isInLoad()) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 197 | mUiController.stopLoading(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 198 | } else { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 199 | mUiController.getCurrentTopWebView().reload(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 200 | } |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 201 | } |
| 202 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 203 | @Override |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 204 | public void onProgressStarted() { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 205 | mStopButton.setImageDrawable(mStopDrawable); |
| 206 | } |
| 207 | |
| 208 | @Override |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 209 | public void onProgressStopped() { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 210 | mStopButton.setImageDrawable(mReloadDrawable); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 213 | protected void updateSearchMode(boolean userEdited) { |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 214 | setSearchMode(!userEdited || TextUtils.isEmpty(mUrlInput.getUserText())); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 215 | } |
| 216 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 217 | @Override |
| 218 | protected void setSearchMode(boolean voiceSearchEnabled) { |
Michael Kolb | 793e05e | 2011-01-11 15:17:31 -0800 | [diff] [blame] | 219 | boolean showvoicebutton = voiceSearchEnabled && |
Michael Kolb | 736990c | 2011-03-20 10:01:20 -0700 | [diff] [blame] | 220 | mUiController.supportsVoiceSearch(); |
Michael Kolb | 793e05e | 2011-01-11 15:17:31 -0800 | [diff] [blame] | 221 | mVoiceSearch.setVisibility(showvoicebutton ? View.VISIBLE : |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 222 | View.GONE); |
| 223 | mGoButton.setVisibility(voiceSearchEnabled ? View.GONE : |
| 224 | View.VISIBLE); |
| 225 | } |
| 226 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 227 | @Override |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 228 | public void setInVoiceMode(boolean voicemode, List<String> voiceResults) { |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 229 | super.setInVoiceMode(voicemode, voiceResults); |
Michael Kolb | 3aaef25 | 2011-03-09 18:13:56 -0800 | [diff] [blame] | 230 | if (voicemode) { |
| 231 | mUrlIcon.setImageDrawable(mSearchButton.getDrawable()); |
| 232 | } |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 233 | } |
| 234 | |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 235 | } |