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