public void onPageFinished(WebView view) { if (!mIsOnReceivedTitle && mWebChromeClient != null) { WebBackForwardList list = null; try { list = view.copyBackForwardList(); } catch (NullPointerException e) { if (LogUtils.isDebug()) { e.printStackTrace(); } } if (list != null && list.getSize() > 0 && list.getCurrentIndex() >= 0 && list.getItemAtIndex(list.getCurrentIndex()) != null) { String previousTitle = list.getItemAtIndex(list.getCurrentIndex()).getTitle(); mWebChromeClient.onReceivedTitle(view, previousTitle); } } }
private void _backEvent() { if (this.mWebView != null && this.mWebView.canGoBack()) { this.mWebView.stopLoading(); LogInfo.log("+->", "mWebView-->>back" + this.mWebView.getUrl()); WebBackForwardList list = this.mWebView.copyBackForwardList(); if (list.getCurrentIndex() <= 0) { this.pullDownUrlText.setText(String.format(getString(R.string.supplied_by), new Object[]{getUrlTitle(list.getItemAtIndex(0).getUrl())})); } else { this.pullDownUrlText.setText(String.format(getString(R.string.supplied_by), new Object[]{getUrlTitle(list.getItemAtIndex(list.getCurrentIndex() - 1).getUrl())})); this.titleView.setText(list.getItemAtIndex(list.getCurrentIndex() - 1).getTitle()); } this.mWebView.goBack(); if (!this.close.isShown()) { this.close.setVisibility(0); } } else if ("floatBallActive".equals(this.web_flag)) { finish(); } else { finish(); } }
@Override public void backAction() { String curUrl = webView.getUrl(); boolean isExit = true; if (!TextUtils.isEmpty(curUrl)) { if (webView.canGoBack()) { WebBackForwardList backList = webView.copyBackForwardList(); if (backList != null && backList.getCurrentIndex() == 1) { isExit = false; loadLocalHtml(articleBean.getBody()); } } } if (isExit) { mActivity.finish(); } }
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) { WebBackForwardList webBFL = webView.copyBackForwardList(); int i = webBFL.getCurrentIndex(); do { i--; } while (i >= 0 && webView.getOriginalUrl() .equals(webBFL.getItemAtIndex(i).getOriginalUrl())); if (webView.canGoBackOrForward(i - webBFL.getCurrentIndex())) { webView.goBackOrForward(i - webBFL.getCurrentIndex()); } else { super.onBackPressed(); } return true; } return false; }
public WebBackForwardList copyBackForwardList(){ //mWebView.saveState() WebBackForwardList wbfl = mWebView.copyBackForwardList(); //mWebView.s return wbfl; }
@Override public void onBackPressedSupport() { if (nswvDetailContent.canGoBack()) { //获取webView的浏览记录 WebBackForwardList mWebBackForwardList = nswvDetailContent.copyBackForwardList(); //这里的判断是为了让页面在有上一个页面的情况下,跳转到上一个html页面,而不是退出当前activity if (mWebBackForwardList.getCurrentIndex() > 0) { nswvDetailContent.goBack(); return; } } super.onBackPressedSupport(); }
public void onClick(View v) { int id = v.getId(); if (id == R.id.close_iv) { finish(); } else if (id == R.id.back_iv) { if (this.mWebView.canGoBack()) { LogInfo.log("+->", "mWebView-->>back" + this.mWebView.getUrl()); WebBackForwardList list = this.mWebView.copyBackForwardList(); if (list.getCurrentIndex() <= 0) { this.pullDownUrlText.setText(String.format(getString(R.string.supplied_by), new Object[]{getUrlTitle(list.getItemAtIndex(0).getUrl())})); this.titleView.setText(list.getItemAtIndex(0).getTitle()); } else { this.pullDownUrlText.setText(String.format(getString(R.string.supplied_by), new Object[]{getUrlTitle(list.getItemAtIndex(list.getCurrentIndex() - 1).getUrl())})); this.titleView.setText(list.getItemAtIndex(list.getCurrentIndex() - 1).getTitle()); } this.mWebView.goBack(); if (!this.close.isShown()) { this.close.setVisibility(0); } } else if ("floatBallActive".equals(this.web_flag)) { finish(); } else { finish(); } } UIsUtils.hideSoftkeyboard(this); }
public void printBackForwardList() { WebBackForwardList currentList = this.copyBackForwardList(); int currentSize = currentList.getSize(); for(int i = 0; i < currentSize; ++i) { WebHistoryItem item = currentList.getItemAtIndex(i); String url = item.getUrl(); LOG.d(TAG, "The URL at index: " + Integer.toString(i) + " is " + url ); } }
public boolean startOfHistory() { WebBackForwardList currentList = this.copyBackForwardList(); WebHistoryItem item = currentList.getItemAtIndex(0); if( item!=null){ // Null-fence in case they haven't called loadUrl yet (CB-2458) String url = item.getUrl(); String currentUrl = this.getUrl(); LOG.d(TAG, "The current URL is: " + currentUrl); LOG.d(TAG, "The URL at item 0 is: " + url); return currentUrl.equals(url); } return false; }
public WebBackForwardList restoreState(Bundle savedInstanceState) { WebBackForwardList myList = super.restoreState(savedInstanceState); Log.d(TAG, "WebView restoration crew now restoring!"); //Initialize the plugin manager once more this.pluginManager.init(); return myList; }
private void back() { if (webView.canGoBack()) { WebBackForwardList mWebBackForwardList = webView.copyBackForwardList(); String historyUrl = mWebBackForwardList.getItemAtIndex(mWebBackForwardList.getCurrentIndex()-1).getUrl(); webView.goBack(); SearchText.setText(historyUrl); } }
private void forward() { if (webView.canGoForward()) { WebBackForwardList mWebBackForwardList = webView.copyBackForwardList(); String historyUrl = mWebBackForwardList.getItemAtIndex(mWebBackForwardList.getCurrentIndex()+1).getUrl(); webView.goForward(); SearchText.setText(webView.getUrl()); } }
@Override public void restoreWebViewState(Session session) { final Bundle stateData = session.getWebViewState(); final WebBackForwardList backForwardList = stateData != null ? super.restoreState(stateData) : null; final String desiredURL = session.getUrl().getValue(); client.restoreState(stateData); client.notifyCurrentURL(desiredURL); // Pages are only added to the back/forward list when loading finishes. If a new page is // loading when the Activity is paused/killed, then that page won't be in the list, // and needs to be restored separately to the history list. We detect this by checking // whether the last fully loaded page (getCurrentItem()) matches the last page that the // WebView was actively loading (which was retrieved during onSaveInstanceState(): // WebView.getUrl() always returns the currently loading or loaded page). // If the app is paused/killed before the initial page finished loading, then the entire // list will be null - so we need to additionally check whether the list even exists. if (backForwardList != null && backForwardList.getCurrentItem().getUrl().equals(desiredURL)) { // restoreState doesn't actually load the current page, it just restores navigation history, // so we also need to explicitly reload in this case: reload(); } else { loadUrl(desiredURL); } }
@Override public void goBack() { WebBackForwardList list = mWebView.copyBackForwardList(); int curIndex = list.getCurrentIndex(); WebHistoryItem curItem = list.getCurrentItem(); WebHistoryItem prevItem = list.getItemAtIndex(curIndex - 1); int steps = 0; if (prevItem != null) { steps--; if (prevItem.getUrl().equals(JoyWeb.getCookie())) { prevItem = list.getItemAtIndex(curIndex - 2); if (prevItem != null) { steps--; if (UriUtils.isEquals(prevItem.getUrl(), curItem.getUrl())) { prevItem = list.getItemAtIndex(curIndex - 3); if (prevItem != null) { steps--; goBackOrForward(steps); } else { mBaseView.finish(); } return; } goBackOrForward(steps); } else { mBaseView.finish(); } return; } if (goBackOrForward(steps)) { return; } } mBaseView.finish(); }
@Override public void goForward() { WebBackForwardList list = mWebView.copyBackForwardList(); int curIndex = list.getCurrentIndex(); WebHistoryItem curItem = list.getCurrentItem(); WebHistoryItem nextItem = list.getItemAtIndex(curIndex + 1); int steps = 0; if (nextItem != null) { steps++; if (nextItem.getUrl().equals(JoyWeb.getCookie())) { nextItem = list.getItemAtIndex(curIndex + 2); if (nextItem != null) { steps++; if (UriUtils.isEquals(nextItem.getUrl(), curItem.getUrl())) { nextItem = list.getItemAtIndex(curIndex + 3); if (nextItem != null) { steps++; goBackOrForward(steps); } else { mBaseView.showToast(R.string.toast_no_next_page); } return; } if (goBackOrForward(steps)) { return; } } } if (goBackOrForward(steps)) { return; } } mBaseView.showToast(R.string.toast_no_next_page); }
private void onGoBackClick(boolean needFinish) { if (getWebWidget().canGoBack()) { if (getWebWidget().isCookieStatusNone()) { //如果没有种cookie,直接back getWebWidget().goBack(); } else { //如果加载过cookie,则最早的历史纪录是cookieurl,不能back WebBackForwardList list = getWebWidget().copyBackForwardList(); if (list != null && list.getCurrentIndex() > 1) { if (mUseBottomBanner && list.getCurrentIndex() == 2) {// TODO 跳过loading页,直接关闭。暂时先这么写 finish(); return; } getWebWidget().goBack(); } else { if (needFinish) finish(); } } } else { if (needFinish) finish(); } }