John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | */ |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 16 | package com.android.browser; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 17 | |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 18 | import android.app.Activity; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 19 | import android.app.SearchManager; |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 20 | import android.content.ActivityNotFoundException; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
| 23 | import android.graphics.Bitmap; |
| 24 | import android.graphics.drawable.Drawable; |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 25 | import android.net.Uri; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 26 | import android.os.Bundle; |
Narayan Kamath | f3174a5 | 2011-11-17 14:43:32 +0000 | [diff] [blame] | 27 | import android.text.Editable; |
| 28 | import android.text.TextWatcher; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 29 | import android.util.AttributeSet; |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 30 | import android.util.Log; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 31 | import android.view.KeyEvent; |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 32 | import android.view.Menu; |
| 33 | import android.view.MenuItem; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 34 | import android.view.View; |
| 35 | import android.view.View.OnClickListener; |
| 36 | import android.view.View.OnFocusChangeListener; |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 37 | import android.view.ViewConfiguration; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 38 | import android.widget.ImageView; |
| 39 | import android.widget.LinearLayout; |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 40 | import android.widget.PopupMenu; |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 41 | import android.widget.Toast; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 42 | |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 43 | import com.android.browser.R; |
| 44 | import com.android.browser.UrlInputView.UrlInputListener; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 45 | |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 46 | import java.io.UnsupportedEncodingException; |
kaiyiz | 950eca2 | 2013-08-08 11:01:28 +0800 | [diff] [blame] | 47 | import java.net.URISyntaxException; |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 48 | |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 49 | import org.codeaurora.swe.WebView; |
| 50 | |
John Reck | 42229bc | 2011-08-19 13:26:43 -0700 | [diff] [blame] | 51 | public class NavigationBarBase extends LinearLayout implements |
| 52 | OnClickListener, UrlInputListener, OnFocusChangeListener, |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 53 | TextWatcher, UrlInputView.StateListener, |
| 54 | PopupMenu.OnMenuItemClickListener, PopupMenu.OnDismissListener { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 55 | |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 56 | private final static String TAG = "NavigationBarBase"; |
| 57 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 58 | protected BaseUi mBaseUi; |
| 59 | protected TitleBar mTitleBar; |
| 60 | protected UiController mUiController; |
| 61 | protected UrlInputView mUrlInput; |
Axesh R. Ajmera | 2e24124 | 2014-05-19 15:53:38 -0700 | [diff] [blame] | 62 | protected LocationButton mLocationButton; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 63 | |
| 64 | private ImageView mFavicon; |
| 65 | private ImageView mLockIcon; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 66 | |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 67 | private View mMore; |
| 68 | private PopupMenu mPopupMenu; |
| 69 | private boolean mOverflowMenuShowing; |
| 70 | private boolean mNeedsMenu; |
Axesh R. Ajmera | 2e24124 | 2014-05-19 15:53:38 -0700 | [diff] [blame] | 71 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 72 | public NavigationBarBase(Context context) { |
| 73 | super(context); |
| 74 | } |
| 75 | |
| 76 | public NavigationBarBase(Context context, AttributeSet attrs) { |
| 77 | super(context, attrs); |
| 78 | } |
| 79 | |
| 80 | public NavigationBarBase(Context context, AttributeSet attrs, int defStyle) { |
| 81 | super(context, attrs, defStyle); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | protected void onFinishInflate() { |
| 86 | super.onFinishInflate(); |
| 87 | mLockIcon = (ImageView) findViewById(R.id.lock); |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 88 | mLocationButton = (LocationButton) findViewById(R.id.location_button); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 89 | mFavicon = (ImageView) findViewById(R.id.favicon); |
| 90 | mUrlInput = (UrlInputView) findViewById(R.id.url); |
| 91 | mUrlInput.setUrlInputListener(this); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 92 | mUrlInput.setOnFocusChangeListener(this); |
| 93 | mUrlInput.setSelectAllOnFocus(true); |
Narayan Kamath | f3174a5 | 2011-11-17 14:43:32 +0000 | [diff] [blame] | 94 | mUrlInput.addTextChangedListener(this); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 95 | mMore = findViewById(R.id.more_browser_settings); |
| 96 | mMore.setOnClickListener(this); |
| 97 | mNeedsMenu = !ViewConfiguration.get(getContext()).hasPermanentMenuKey(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | public void setTitleBar(TitleBar titleBar) { |
| 101 | mTitleBar = titleBar; |
| 102 | mBaseUi = mTitleBar.getUi(); |
| 103 | mUiController = mTitleBar.getUiController(); |
Michael Kolb | b2e91fd | 2011-07-14 13:47:29 -0700 | [diff] [blame] | 104 | mUrlInput.setController(mUiController); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | public void setLock(Drawable d) { |
| 108 | if (mLockIcon == null) return; |
| 109 | if (d == null) { |
| 110 | mLockIcon.setVisibility(View.GONE); |
| 111 | } else { |
| 112 | mLockIcon.setImageDrawable(d); |
| 113 | mLockIcon.setVisibility(View.VISIBLE); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | public void setFavicon(Bitmap icon) { |
| 118 | if (mFavicon == null) return; |
| 119 | mFavicon.setImageDrawable(mBaseUi.getFaviconDrawable(icon)); |
| 120 | } |
| 121 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 122 | @Override |
| 123 | public void onClick(View v) { |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 124 | if (mMore == v) { |
| 125 | showMenu(mMore); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | void showMenu(View anchor) { |
| 130 | Activity activity = mUiController.getActivity(); |
| 131 | if (mPopupMenu == null) { |
| 132 | mPopupMenu = new PopupMenu(getContext(), anchor); |
| 133 | mPopupMenu.setOnMenuItemClickListener(this); |
| 134 | mPopupMenu.setOnDismissListener(this); |
| 135 | if (!activity.onCreateOptionsMenu(mPopupMenu.getMenu())) { |
| 136 | mPopupMenu = null; |
| 137 | return; |
| 138 | } |
| 139 | } |
| 140 | Menu menu = mPopupMenu.getMenu(); |
| 141 | |
| 142 | if (mUiController instanceof Controller) { |
| 143 | Controller controller = (Controller) mUiController; |
| 144 | if (controller.onPrepareOptionsMenu(menu)) { |
| 145 | mOverflowMenuShowing = true; |
| 146 | } |
| 147 | } |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public void onFocusChange(View view, boolean hasFocus) { |
| 152 | // if losing focus and not in touch mode, leave as is |
| 153 | if (hasFocus || view.isInTouchMode() || mUrlInput.needsUpdate()) { |
| 154 | setFocusState(hasFocus); |
| 155 | } |
| 156 | if (hasFocus) { |
| 157 | mBaseUi.showTitleBar(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 158 | } else if (!mUrlInput.needsUpdate()) { |
| 159 | mUrlInput.dismissDropDown(); |
| 160 | mUrlInput.hideIME(); |
| 161 | if (mUrlInput.getText().length() == 0) { |
| 162 | Tab currentTab = mUiController.getTabControl().getCurrentTab(); |
| 163 | if (currentTab != null) { |
John Reck | 434e9f8 | 2011-08-10 18:16:52 -0700 | [diff] [blame] | 164 | setDisplayTitle(currentTab.getUrl()); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | mBaseUi.suggestHideTitleBar(); |
| 168 | } |
| 169 | mUrlInput.clearNeedsUpdate(); |
| 170 | } |
| 171 | |
| 172 | protected void setFocusState(boolean focus) { |
| 173 | } |
| 174 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 175 | public boolean isEditingUrl() { |
| 176 | return mUrlInput.hasFocus(); |
| 177 | } |
| 178 | |
| 179 | void stopEditingUrl() { |
Michael Kolb | 0b12912 | 2012-06-04 16:31:58 -0700 | [diff] [blame] | 180 | WebView currentTopWebView = mUiController.getCurrentTopWebView(); |
| 181 | if (currentTopWebView != null) { |
| 182 | currentTopWebView.requestFocus(); |
| 183 | } |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | void setDisplayTitle(String title) { |
| 187 | if (!isEditingUrl()) { |
Michael Kolb | 29aab40 | 2012-05-29 17:22:35 -0700 | [diff] [blame] | 188 | if (!title.equals(mUrlInput.getText().toString())) { |
| 189 | mUrlInput.setText(title, false); |
| 190 | } |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 194 | void setIncognitoMode(boolean incognito) { |
| 195 | mUrlInput.setIncognitoMode(incognito); |
| 196 | } |
| 197 | |
| 198 | void clearCompletions() { |
Narayan Kamath | f3174a5 | 2011-11-17 14:43:32 +0000 | [diff] [blame] | 199 | mUrlInput.dismissDropDown(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | // UrlInputListener implementation |
| 203 | |
| 204 | /** |
| 205 | * callback from suggestion dropdown |
| 206 | * user selected a suggestion |
| 207 | */ |
| 208 | @Override |
| 209 | public void onAction(String text, String extra, String source) { |
Michael Kolb | 0b12912 | 2012-06-04 16:31:58 -0700 | [diff] [blame] | 210 | stopEditingUrl(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 211 | if (UrlInputView.TYPED.equals(source)) { |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 212 | String url = null; |
Panos Thomas | 4bdb525 | 2014-11-13 16:20:11 -0800 | [diff] [blame] | 213 | boolean wap2estore = BrowserConfig.getInstance(getContext()) |
| 214 | .hasFeature(BrowserConfig.Feature.WAP2ESTORE); |
Vivek Sekhar | 5e63147 | 2014-03-31 23:59:10 -0700 | [diff] [blame] | 215 | if ((wap2estore && isEstoreTypeUrl(text)) || isRtspTypeUrl(text) |
| 216 | || isMakeCallTypeUrl(text)) { |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 217 | url = text; |
| 218 | } else { |
| 219 | url = UrlUtils.smartUrlFilter(text, false); |
| 220 | } |
| 221 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 222 | Tab t = mBaseUi.getActiveTab(); |
| 223 | // Only shortcut javascript URIs for now, as there is special |
| 224 | // logic in UrlHandler for other schemas |
| 225 | if (url != null && t != null && url.startsWith("javascript:")) { |
| 226 | mUiController.loadUrl(t, url); |
| 227 | setDisplayTitle(text); |
| 228 | return; |
| 229 | } |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 230 | |
| 231 | // add for carrier wap2estore feature |
| 232 | if (url != null && t != null && wap2estore && isEstoreTypeUrl(url)) { |
Vivek Sekhar | b54614f | 2014-05-01 19:03:37 -0700 | [diff] [blame] | 233 | if (handleEstoreTypeUrl(url)) { |
| 234 | setDisplayTitle(text); |
| 235 | return; |
| 236 | } |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 237 | } |
kaiyiz | 950eca2 | 2013-08-08 11:01:28 +0800 | [diff] [blame] | 238 | // add for rtsp scheme feature |
| 239 | if (url != null && t != null && isRtspTypeUrl(url)) { |
| 240 | if (handleRtspTypeUrl(url)) { |
Vivek Sekhar | b54614f | 2014-05-01 19:03:37 -0700 | [diff] [blame] | 241 | setDisplayTitle(text); |
kaiyiz | 950eca2 | 2013-08-08 11:01:28 +0800 | [diff] [blame] | 242 | return; |
| 243 | } |
| 244 | } |
Vivek Sekhar | 5e63147 | 2014-03-31 23:59:10 -0700 | [diff] [blame] | 245 | // add for "wtai://wp/mc;" scheme feature |
| 246 | if (url != null && t != null && isMakeCallTypeUrl(url)) { |
| 247 | if (handleMakeCallTypeUrl(url)) { |
| 248 | return; |
| 249 | } |
| 250 | } |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 251 | } |
| 252 | Intent i = new Intent(); |
Michael Kolb | 5ff5c8b | 2012-05-03 11:37:58 -0700 | [diff] [blame] | 253 | String action = Intent.ACTION_SEARCH; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 254 | i.setAction(action); |
| 255 | i.putExtra(SearchManager.QUERY, text); |
| 256 | if (extra != null) { |
| 257 | i.putExtra(SearchManager.EXTRA_DATA_KEY, extra); |
| 258 | } |
| 259 | if (source != null) { |
| 260 | Bundle appData = new Bundle(); |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 261 | appData.putString("source", source); |
| 262 | i.putExtra("source", appData); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 263 | } |
| 264 | mUiController.handleNewIntent(i); |
| 265 | setDisplayTitle(text); |
| 266 | } |
| 267 | |
Vivek Sekhar | 5e63147 | 2014-03-31 23:59:10 -0700 | [diff] [blame] | 268 | private boolean isMakeCallTypeUrl(String url) { |
| 269 | String utf8Url = null; |
| 270 | try { |
| 271 | utf8Url = new String(url.getBytes("UTF-8"), "UTF-8"); |
| 272 | } catch (UnsupportedEncodingException e) { |
| 273 | Log.e(TAG, "err " + e); |
| 274 | } |
| 275 | if (utf8Url != null && utf8Url.startsWith(UrlHandler.SCHEME_WTAI_MC)) { |
| 276 | return true; |
| 277 | } |
| 278 | return false; |
| 279 | } |
| 280 | |
| 281 | private boolean handleMakeCallTypeUrl(String url) { |
| 282 | // wtai://wp/mc;number |
| 283 | // number=string(phone-number) |
| 284 | if (url.startsWith(UrlHandler.SCHEME_WTAI_MC)) { |
| 285 | Intent intent = new Intent(Intent.ACTION_VIEW, |
| 286 | Uri.parse(WebView.SCHEME_TEL + |
| 287 | url.substring(UrlHandler.SCHEME_WTAI_MC.length()))); |
| 288 | getContext().startActivity(intent); |
| 289 | // before leaving BrowserActivity, close the empty child tab. |
| 290 | // If a new tab is created through JavaScript open to load this |
| 291 | // url, we would like to close it as we will load this url in a |
| 292 | // different Activity. |
| 293 | Tab current = mUiController.getCurrentTab(); |
| 294 | if (current != null |
| 295 | && current.getWebView().copyBackForwardList().getSize() == 0) { |
| 296 | mUiController.closeCurrentTab(); |
| 297 | } |
| 298 | return true; |
| 299 | } |
| 300 | return false; |
| 301 | } |
| 302 | |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 303 | private boolean isEstoreTypeUrl(String url) { |
Vivek Sekhar | b54614f | 2014-05-01 19:03:37 -0700 | [diff] [blame] | 304 | if (url != null && url.startsWith("estore:")) { |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 305 | return true; |
| 306 | } |
| 307 | return false; |
| 308 | } |
| 309 | |
Vivek Sekhar | b54614f | 2014-05-01 19:03:37 -0700 | [diff] [blame] | 310 | private boolean handleEstoreTypeUrl(String url) { |
| 311 | if (url.getBytes().length > 256) { |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 312 | Toast.makeText(getContext(), R.string.estore_url_warning, Toast.LENGTH_LONG).show(); |
Vivek Sekhar | b54614f | 2014-05-01 19:03:37 -0700 | [diff] [blame] | 313 | return false; |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 314 | } |
Vivek Sekhar | b54614f | 2014-05-01 19:03:37 -0700 | [diff] [blame] | 315 | |
| 316 | Intent intent; |
| 317 | // perform generic parsing of the URI to turn it into an Intent. |
| 318 | try { |
| 319 | intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME); |
| 320 | } catch (URISyntaxException ex) { |
| 321 | Log.w("Browser", "Bad URI " + url + ": " + ex.getMessage()); |
| 322 | return false; |
| 323 | } |
| 324 | |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 325 | try { |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 326 | getContext().startActivity(intent); |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 327 | } catch (ActivityNotFoundException ex) { |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 328 | String downloadUrl = getContext().getResources().getString(R.string.estore_homepage); |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 329 | mUiController.loadUrl(mBaseUi.getActiveTab(), downloadUrl); |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 330 | Toast.makeText(getContext(), R.string.download_estore_app, Toast.LENGTH_LONG).show(); |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 331 | } |
Vivek Sekhar | b54614f | 2014-05-01 19:03:37 -0700 | [diff] [blame] | 332 | |
| 333 | return true; |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 334 | } |
| 335 | |
kaiyiz | 950eca2 | 2013-08-08 11:01:28 +0800 | [diff] [blame] | 336 | private boolean isRtspTypeUrl(String url) { |
| 337 | String utf8Url = null; |
| 338 | try { |
| 339 | utf8Url = new String(url.getBytes("UTF-8"), "UTF-8"); |
| 340 | } catch (UnsupportedEncodingException e) { |
| 341 | Log.e(TAG, "err " + e); |
| 342 | } |
| 343 | if (utf8Url != null && utf8Url.startsWith("rtsp://")) { |
| 344 | return true; |
| 345 | } |
| 346 | return false; |
| 347 | } |
| 348 | |
| 349 | private boolean handleRtspTypeUrl(String url) { |
| 350 | Intent intent; |
| 351 | // perform generic parsing of the URI to turn it into an Intent. |
| 352 | try { |
| 353 | intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME); |
| 354 | } catch (URISyntaxException ex) { |
| 355 | Log.w("Browser", "Bad URI " + url + ": " + ex.getMessage()); |
| 356 | return false; |
| 357 | } |
| 358 | |
| 359 | try { |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 360 | getContext().startActivity(intent); |
kaiyiz | 950eca2 | 2013-08-08 11:01:28 +0800 | [diff] [blame] | 361 | } catch (ActivityNotFoundException ex) { |
| 362 | Log.w("Browser", "No resolveActivity " + url); |
| 363 | return false; |
| 364 | } |
| 365 | return true; |
| 366 | } |
| 367 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 368 | @Override |
| 369 | public void onDismiss() { |
| 370 | final Tab currentTab = mBaseUi.getActiveTab(); |
| 371 | mBaseUi.hideTitleBar(); |
| 372 | post(new Runnable() { |
| 373 | public void run() { |
| 374 | clearFocus(); |
Michael Kolb | 5ff5c8b | 2012-05-03 11:37:58 -0700 | [diff] [blame] | 375 | if (currentTab != null) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 376 | setDisplayTitle(currentTab.getUrl()); |
| 377 | } |
| 378 | } |
| 379 | }); |
| 380 | } |
| 381 | |
| 382 | /** |
| 383 | * callback from the suggestion dropdown |
| 384 | * copy text to input field and stay in edit mode |
| 385 | */ |
| 386 | @Override |
| 387 | public void onCopySuggestion(String text) { |
| 388 | mUrlInput.setText(text, true); |
| 389 | if (text != null) { |
| 390 | mUrlInput.setSelection(text.length()); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | public void setCurrentUrlIsBookmark(boolean isBookmark) { |
| 395 | } |
| 396 | |
| 397 | @Override |
| 398 | public boolean dispatchKeyEventPreIme(KeyEvent evt) { |
| 399 | if (evt.getKeyCode() == KeyEvent.KEYCODE_BACK) { |
| 400 | // catch back key in order to do slightly more cleanup than usual |
Michael Kolb | 0b12912 | 2012-06-04 16:31:58 -0700 | [diff] [blame] | 401 | stopEditingUrl(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 402 | } |
| 403 | return super.dispatchKeyEventPreIme(evt); |
| 404 | } |
| 405 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 406 | /** |
| 407 | * called from the Ui when the user wants to edit |
| 408 | * @param clearInput clear the input field |
| 409 | */ |
Michael Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 410 | void startEditingUrl(boolean clearInput, boolean forceIME) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 411 | // editing takes preference of progress |
| 412 | setVisibility(View.VISIBLE); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 413 | if (!mUrlInput.hasFocus()) { |
| 414 | mUrlInput.requestFocus(); |
| 415 | } |
| 416 | if (clearInput) { |
| 417 | mUrlInput.setText(""); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 418 | } |
Michael Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 419 | if (forceIME) { |
Michael Kolb | 4bb6fcb | 2012-04-13 14:25:27 -0700 | [diff] [blame] | 420 | mUrlInput.showIME(); |
| 421 | } |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | public void onProgressStarted() { |
| 425 | } |
| 426 | |
| 427 | public void onProgressStopped() { |
| 428 | } |
| 429 | |
John Reck | 419f6b4 | 2011-08-16 16:10:51 -0700 | [diff] [blame] | 430 | public void onTabDataChanged(Tab tab) { |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 431 | mLocationButton.onTabDataChanged(tab); |
John Reck | 419f6b4 | 2011-08-16 16:10:51 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Michael Kolb | 0b12912 | 2012-06-04 16:31:58 -0700 | [diff] [blame] | 434 | public void onVoiceResult(String s) { |
| 435 | startEditingUrl(true, true); |
| 436 | onCopySuggestion(s); |
| 437 | } |
| 438 | |
Narayan Kamath | f3174a5 | 2011-11-17 14:43:32 +0000 | [diff] [blame] | 439 | @Override |
| 440 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { } |
| 441 | |
| 442 | @Override |
Michael Kolb | 5ff5c8b | 2012-05-03 11:37:58 -0700 | [diff] [blame] | 443 | public void onTextChanged(CharSequence s, int start, int before, int count) { } |
Narayan Kamath | f3174a5 | 2011-11-17 14:43:32 +0000 | [diff] [blame] | 444 | |
| 445 | @Override |
| 446 | public void afterTextChanged(Editable s) { } |
Michael Kolb | 0b12912 | 2012-06-04 16:31:58 -0700 | [diff] [blame] | 447 | |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 448 | @Override |
| 449 | public void onStateChanged(int state) { |
| 450 | switch(state) { |
| 451 | case STATE_NORMAL: |
| 452 | mMore.setVisibility(mNeedsMenu ? View.VISIBLE : View.GONE); |
| 453 | break; |
| 454 | case STATE_HIGHLIGHTED: |
| 455 | mMore.setVisibility(View.GONE); |
| 456 | break; |
| 457 | case STATE_EDITED: |
| 458 | mMore.setVisibility(View.GONE); |
| 459 | break; |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | public boolean isMenuShowing() { |
| 464 | return mOverflowMenuShowing; |
| 465 | } |
| 466 | |
| 467 | |
| 468 | @Override |
| 469 | public void onDismiss(PopupMenu popupMenu) { |
| 470 | if (popupMenu == mPopupMenu) { |
| 471 | onMenuHidden(); |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | private void onMenuHidden() { |
| 476 | mOverflowMenuShowing = false; |
| 477 | mBaseUi.showTitleBarForDuration(); |
| 478 | } |
| 479 | |
| 480 | |
| 481 | @Override |
| 482 | public boolean onMenuItemClick(MenuItem item) { |
| 483 | return mUiController.onOptionsItemSelected(item); |
| 484 | } |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 485 | } |