Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 1 | /* |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 2 | * Copyright (C) 2011 The Android Open Source Project |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [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 | */ |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 16 | package com.android.browser; |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 17 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 18 | import android.content.Context; |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 19 | import android.content.res.Resources; |
| 20 | import android.graphics.drawable.Drawable; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 21 | import android.util.AttributeSet; |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 22 | import android.util.TypedValue; |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 23 | import android.view.View; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 24 | import org.codeaurora.swe.WebView; |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 25 | import org.codeaurora.swe.util.Activator; |
| 26 | import org.codeaurora.swe.util.Observable; |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 27 | |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 28 | import android.widget.ImageView; |
| 29 | import android.widget.TextView; |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 30 | import com.android.browser.UrlInputView.StateListener; |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 31 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 32 | public class NavigationBarPhone extends NavigationBarBase implements |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 33 | StateListener { |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 34 | |
Michael Kolb | c16c595 | 2011-03-29 15:37:03 -0700 | [diff] [blame] | 35 | private ImageView mStopButton; |
Michael Kolb | 94ec527 | 2011-08-31 16:23:57 -0700 | [diff] [blame] | 36 | private ImageView mMagnify; |
| 37 | private ImageView mClearButton; |
Michael Kolb | 0b12912 | 2012-06-04 16:31:58 -0700 | [diff] [blame] | 38 | private ImageView mVoiceButton; |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 39 | private Drawable mStopDrawable; |
| 40 | private Drawable mRefreshDrawable; |
Michael Kolb | 30adae6 | 2011-07-29 13:37:05 -0700 | [diff] [blame] | 41 | private String mStopDescription; |
| 42 | private String mRefreshDescription; |
John Reck | 8ac4290 | 2011-06-29 16:14:34 -0700 | [diff] [blame] | 43 | private View mTabSwitcher; |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 44 | private TextView mTabText; |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 45 | private View mComboIcon; |
John Reck | 419f6b4 | 2011-08-16 16:10:51 -0700 | [diff] [blame] | 46 | private View mIncognitoIcon; |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 47 | private float mTabSwitcherInitialTextSize = 0; |
| 48 | private float mTabSwitcherCompressedTextSize = 0; |
| 49 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 50 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 51 | public NavigationBarPhone(Context context) { |
| 52 | super(context); |
| 53 | } |
| 54 | |
| 55 | public NavigationBarPhone(Context context, AttributeSet attrs) { |
| 56 | super(context, attrs); |
| 57 | } |
| 58 | |
| 59 | public NavigationBarPhone(Context context, AttributeSet attrs, int defStyle) { |
| 60 | super(context, attrs, defStyle); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | @Override |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 64 | protected void onFinishInflate() { |
| 65 | super.onFinishInflate(); |
Michael Kolb | c16c595 | 2011-03-29 15:37:03 -0700 | [diff] [blame] | 66 | mStopButton = (ImageView) findViewById(R.id.stop); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 67 | mStopButton.setOnClickListener(this); |
Michael Kolb | 94ec527 | 2011-08-31 16:23:57 -0700 | [diff] [blame] | 68 | mClearButton = (ImageView) findViewById(R.id.clear); |
| 69 | mClearButton.setOnClickListener(this); |
Michael Kolb | 0b12912 | 2012-06-04 16:31:58 -0700 | [diff] [blame] | 70 | mVoiceButton = (ImageView) findViewById(R.id.voice); |
| 71 | mVoiceButton.setOnClickListener(this); |
Michael Kolb | 94ec527 | 2011-08-31 16:23:57 -0700 | [diff] [blame] | 72 | mMagnify = (ImageView) findViewById(R.id.magnify); |
John Reck | 8ac4290 | 2011-06-29 16:14:34 -0700 | [diff] [blame] | 73 | mTabSwitcher = findViewById(R.id.tab_switcher); |
| 74 | mTabSwitcher.setOnClickListener(this); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 75 | mTabText = (TextView) findViewById(R.id.tab_switcher_text); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 76 | mComboIcon = findViewById(R.id.iconcombo); |
Michael Kolb | 315d502 | 2011-10-13 12:47:11 -0700 | [diff] [blame] | 77 | mComboIcon.setOnClickListener(this); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 78 | setFocusState(false); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 79 | Resources res = getContext().getResources(); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 80 | mStopDrawable = res.getDrawable(R.drawable.ic_action_stop); |
| 81 | mRefreshDrawable = res.getDrawable(R.drawable.ic_action_reload); |
Michael Kolb | 30adae6 | 2011-07-29 13:37:05 -0700 | [diff] [blame] | 82 | mStopDescription = res.getString(R.string.accessibility_button_stop); |
| 83 | mRefreshDescription = res.getString(R.string.accessibility_button_refresh); |
John Reck | 67f3363 | 2011-06-17 16:23:42 -0700 | [diff] [blame] | 84 | mUrlInput.setContainer(this); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 85 | mUrlInput.setStateListener(this); |
John Reck | 419f6b4 | 2011-08-16 16:10:51 -0700 | [diff] [blame] | 86 | mIncognitoIcon = findViewById(R.id.incognito_icon); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 87 | |
| 88 | if (mTabSwitcherInitialTextSize == 0) { |
| 89 | mTabSwitcherInitialTextSize = mTabText.getTextSize(); |
| 90 | mTabSwitcherCompressedTextSize = (float) (mTabSwitcherInitialTextSize / 1.2); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public void setTitleBar(TitleBar titleBar) { |
| 96 | super.setTitleBar(titleBar); |
| 97 | Activator.activate( |
| 98 | new Observable.Observer() { |
| 99 | @Override |
| 100 | public void onChange(Object... params) { |
| 101 | if ((Integer)params[0] > 9) { |
| 102 | mTabText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTabSwitcherCompressedTextSize); |
| 103 | } else { |
| 104 | mTabText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTabSwitcherInitialTextSize); |
| 105 | } |
| 106 | |
| 107 | mTabText.setText(Integer.toString((Integer) params[0])); |
| 108 | } |
| 109 | }, |
| 110 | mUiController.getTabControl().getTabCountObservable()); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | @Override |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 114 | public void onProgressStarted() { |
| 115 | super.onProgressStarted(); |
| 116 | if (mStopButton.getDrawable() != mStopDrawable) { |
| 117 | mStopButton.setImageDrawable(mStopDrawable); |
Michael Kolb | 30adae6 | 2011-07-29 13:37:05 -0700 | [diff] [blame] | 118 | mStopButton.setContentDescription(mStopDescription); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 119 | if (mStopButton.getVisibility() != View.VISIBLE) { |
| 120 | mComboIcon.setVisibility(View.GONE); |
| 121 | mStopButton.setVisibility(View.VISIBLE); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 122 | } |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
| 126 | @Override |
| 127 | public void onProgressStopped() { |
| 128 | super.onProgressStopped(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 129 | mStopButton.setImageDrawable(mRefreshDrawable); |
Michael Kolb | 30adae6 | 2011-07-29 13:37:05 -0700 | [diff] [blame] | 130 | mStopButton.setContentDescription(mRefreshDescription); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 131 | if (!isEditingUrl()) { |
| 132 | mComboIcon.setVisibility(View.VISIBLE); |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 133 | } |
Michael Kolb | 5e8f2b9 | 2011-07-19 13:22:32 -0700 | [diff] [blame] | 134 | onStateChanged(mUrlInput.getState()); |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 137 | /** |
| 138 | * Update the text displayed in the title bar. |
| 139 | * @param title String to display. If null, the new tab string will be |
| 140 | * shown. |
| 141 | */ |
| 142 | @Override |
| 143 | void setDisplayTitle(String title) { |
John Reck | 434e9f8 | 2011-08-10 18:16:52 -0700 | [diff] [blame] | 144 | mUrlInput.setTag(title); |
John Reck | 67f3363 | 2011-06-17 16:23:42 -0700 | [diff] [blame] | 145 | if (!isEditingUrl()) { |
Vivek Sekhar | 60dca80 | 2014-06-27 14:48:30 -0700 | [diff] [blame] | 146 | // add for carrier requirement - show title from native instead of url |
| 147 | Tab currentTab = mUiController.getTabControl().getCurrentTab(); |
| 148 | if (currentTab != null && currentTab.getTitle() != null) { |
| 149 | mUrlInput.setText(currentTab.getTitle(), false); |
| 150 | } else if (title == null) { |
John Reck | 67f3363 | 2011-06-17 16:23:42 -0700 | [diff] [blame] | 151 | mUrlInput.setText(R.string.new_tab); |
| 152 | } else { |
Bijan Amirzada | e75909d | 2014-05-06 14:18:54 -0700 | [diff] [blame] | 153 | mUrlInput.setText(UrlUtils.stripUrl(title), false); |
John Reck | 67f3363 | 2011-06-17 16:23:42 -0700 | [diff] [blame] | 154 | } |
| 155 | mUrlInput.setSelection(0); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 156 | } |
| 157 | } |
| 158 | |
| 159 | @Override |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 160 | public void onClick(View v) { |
| 161 | if (v == mStopButton) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 162 | if (mTitleBar.isInLoad()) { |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 163 | mUiController.stopLoading(); |
| 164 | } else { |
| 165 | WebView web = mBaseUi.getWebView(); |
| 166 | if (web != null) { |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 167 | stopEditingUrl(); |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 168 | Tab currentTab = mUiController.getTabControl().getCurrentTab(); |
| 169 | if (currentTab.hasCrashed) { |
| 170 | currentTab.replaceCrashView(web, currentTab.getViewContainer()); |
| 171 | } |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 172 | web.reload(); |
| 173 | } |
| 174 | } |
John Reck | 8ac4290 | 2011-06-29 16:14:34 -0700 | [diff] [blame] | 175 | } else if (v == mTabSwitcher) { |
Michael Kolb | 20be26d | 2011-07-18 16:38:02 -0700 | [diff] [blame] | 176 | ((PhoneUi) mBaseUi).toggleNavScreen(); |
Michael Kolb | 94ec527 | 2011-08-31 16:23:57 -0700 | [diff] [blame] | 177 | } else if (mClearButton == v) { |
| 178 | mUrlInput.setText(""); |
Michael Kolb | 315d502 | 2011-10-13 12:47:11 -0700 | [diff] [blame] | 179 | } else if (mComboIcon == v) { |
| 180 | mUiController.showPageInfo(); |
Michael Kolb | 0b12912 | 2012-06-04 16:31:58 -0700 | [diff] [blame] | 181 | } else if (mVoiceButton == v) { |
| 182 | mUiController.startVoiceRecognizer(); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 183 | } else { |
| 184 | super.onClick(v); |
| 185 | } |
| 186 | } |
| 187 | |
John Reck | 5889190 | 2011-08-11 17:48:53 -0700 | [diff] [blame] | 188 | @Override |
John Reck | 434e9f8 | 2011-08-10 18:16:52 -0700 | [diff] [blame] | 189 | public void onFocusChange(View view, boolean hasFocus) { |
Panos Thomas | 6ea3a42 | 2014-10-09 23:42:59 -0700 | [diff] [blame] | 190 | if (view == mUrlInput && !hasFocus) { |
| 191 | setDisplayTitle(mUrlInput.getText().toString()); |
John Reck | 434e9f8 | 2011-08-10 18:16:52 -0700 | [diff] [blame] | 192 | } |
| 193 | super.onFocusChange(view, hasFocus); |
| 194 | } |
| 195 | |
| 196 | @Override |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 197 | public void onStateChanged(int state) { |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 198 | super.onStateChanged(state); |
Michael Kolb | e721cc3 | 2012-06-26 15:26:59 -0700 | [diff] [blame] | 199 | mVoiceButton.setVisibility(View.GONE); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 200 | switch(state) { |
| 201 | case StateListener.STATE_NORMAL: |
| 202 | mComboIcon.setVisibility(View.VISIBLE); |
| 203 | mStopButton.setVisibility(View.GONE); |
Michael Kolb | 94ec527 | 2011-08-31 16:23:57 -0700 | [diff] [blame] | 204 | mClearButton.setVisibility(View.GONE); |
| 205 | mMagnify.setVisibility(View.GONE); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 206 | mTabSwitcher.setVisibility(View.VISIBLE); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 207 | mTabText.setVisibility(View.VISIBLE); |
Pankaj Garg | 7b279f6 | 2014-08-12 14:47:18 -0700 | [diff] [blame] | 208 | if (mUiController != null) { |
| 209 | mUiController.setWindowDimming(0f); |
| 210 | } |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 211 | break; |
| 212 | case StateListener.STATE_HIGHLIGHTED: |
| 213 | mComboIcon.setVisibility(View.GONE); |
| 214 | mStopButton.setVisibility(View.VISIBLE); |
Michael Kolb | 94ec527 | 2011-08-31 16:23:57 -0700 | [diff] [blame] | 215 | mClearButton.setVisibility(View.GONE); |
Michael Kolb | e721cc3 | 2012-06-26 15:26:59 -0700 | [diff] [blame] | 216 | if ((mUiController != null) && mUiController.supportsVoice()) { |
| 217 | mVoiceButton.setVisibility(View.VISIBLE); |
| 218 | } |
Michael Kolb | 94ec527 | 2011-08-31 16:23:57 -0700 | [diff] [blame] | 219 | mMagnify.setVisibility(View.GONE); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 220 | mTabSwitcher.setVisibility(View.GONE); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 221 | mTabText.setVisibility(View.GONE); |
Pankaj Garg | 7b279f6 | 2014-08-12 14:47:18 -0700 | [diff] [blame] | 222 | |
Panos Thomas | 6ea3a42 | 2014-10-09 23:42:59 -0700 | [diff] [blame] | 223 | if (!mUrlInput.getText().toString().equals(mUrlInput.getTag())) { |
| 224 | // only change text if different |
| 225 | mUrlInput.setText((String) mUrlInput.getTag(), false); |
| 226 | mUrlInput.selectAll(); |
| 227 | } |
Pankaj Garg | 7b279f6 | 2014-08-12 14:47:18 -0700 | [diff] [blame] | 228 | |
| 229 | if (mUiController != null) { |
| 230 | mUiController.setWindowDimming(0.75f); |
| 231 | } |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 232 | break; |
| 233 | case StateListener.STATE_EDITED: |
| 234 | mComboIcon.setVisibility(View.GONE); |
| 235 | mStopButton.setVisibility(View.GONE); |
Michael Kolb | 94ec527 | 2011-08-31 16:23:57 -0700 | [diff] [blame] | 236 | mClearButton.setVisibility(View.VISIBLE); |
| 237 | mMagnify.setVisibility(View.VISIBLE); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 238 | mTabSwitcher.setVisibility(View.GONE); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 239 | mTabText.setVisibility(View.GONE); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 240 | break; |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 241 | } |
| 242 | } |
John Reck | 419f6b4 | 2011-08-16 16:10:51 -0700 | [diff] [blame] | 243 | |
| 244 | @Override |
| 245 | public void onTabDataChanged(Tab tab) { |
| 246 | super.onTabDataChanged(tab); |
Enrico Ros | d6efa97 | 2014-12-02 19:49:59 -0800 | [diff] [blame^] | 247 | boolean isPrivate = tab.isPrivateBrowsingEnabled(); |
| 248 | mIncognitoIcon.setVisibility(isPrivate ? View.VISIBLE : View.GONE); |
| 249 | // change the background to a darker tone to reflect the 'incognito' state |
| 250 | setBackgroundColor(getResources().getColor(isPrivate ? |
| 251 | R.color.NavigationBarBackgroundIncognito : R.color.NavigationBarBackground)); |
| 252 | |
John Reck | 419f6b4 | 2011-08-16 16:10:51 -0700 | [diff] [blame] | 253 | } |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 254 | } |