List of usage examples for android.webkit WebBackForwardList getCurrentIndex
public abstract int getCurrentIndex();
From source file:com.ronnywu.browserview.view.Lv2GoBackBrowserView.java
/** * onBackPressed ???,?? onBackPressed,onKeyDown. * onBackPressed , -1 , null ./*from w w w . ja v a2 s .c o m*/ * * @param keyCode code * @return ?. */ public boolean backPressed(int keyCode, KeyEvent event) { if (keyCode != KeyEvent.KEYCODE_BACK) { // ??,???, return super.onKeyDown(keyCode, event); } WebBackForwardList webBackForwardList = copyBackForwardList(); int currentIndex = webBackForwardList.getCurrentIndex(); if (browserGoBackListener != null) { int goBackSize = 0; if (currentIndex <= 0) { return false; } for (int i = currentIndex; i > 0; i--) { goBackSize--; // ?0,??, false,?. if (goBackSize + currentIndex < 0) { return false; } String url = webBackForwardList.getItemAtIndex(i - 1).getUrl(); String title = webBackForwardList.getItemAtIndex(i - 1).getTitle(); if (browserGoBackListener.canGoBack(url, title)) { goBackOrForward(goBackSize); break; } } return true; } else { if (currentIndex <= 0) { return false; } String goBackUrl = webBackForwardList.getItemAtIndex(currentIndex - 1).getUrl(); if (jumpingUrls != null && jumpingUrls.size() > 0) { for (ArrayMap.Entry<String, String> entry : jumpingUrls.entrySet()) { // ?URL?,?? String jumpingUrl = entry.getKey(); // ?URL?????2 String jumpingDispose = entry.getValue(); // regex: ?scheme if (jumpingUrl.startsWith("regex:")) { // ?? if (goBackUrl.matches(jumpingUrl.replace("regex:", ""))) { // switch,??java6?? // Switch?? // noinspection IfCanBeSwitch return doJupingDispose(jumpingDispose); } // ????,??? } else { // URL??? if (jumpingUrl.equals(goBackUrl)) { // switch,??java6?? // noinspection IfCanBeSwitch return doJupingDispose(jumpingDispose); } // URL?????,??? } } } // ?,???,? if ((keyCode == KeyEvent.KEYCODE_BACK || keyCode == -1) && canGoBack() && currentIndex > 0) { goBack(); return true; } else { return false; } } }
From source file:com.robandjen.comicsapp.FullscreenActivity.java
@Override public void onBackPressed() { ComicsWebView wv = (ComicsWebView) findViewById(R.id.fullscreen_content); if (wv.canGoBack()) { //I couldn't remove every URL from the list, so stop when I hit //about:blank, I'm all the way back then WebBackForwardList bdl = wv.copyBackForwardList(); final int cur = bdl.getCurrentIndex() - 1; if (cur >= 0) { WebHistoryItem whi = bdl.getItemAtIndex(cur); String url = whi.getUrl(); if (!url.equals("about:blank")) { wv.goBack();/*from w ww.jav a 2 s.c om*/ } } } }
From source file:dev.memento.MementoBrowser.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebview.canGoBack()) { // Get the previous URL to update our internal copy WebBackForwardList list = mWebview.copyBackForwardList(); int curr = list.getCurrentIndex(); WebHistoryItem item = list.getItemAtIndex(curr - 1); Bitmap favicon = item.getFavicon(); if (favicon == null) Log.d(LOG_TAG, "No favicon in WebHistoryItem - null"); else/*from w w w . j a v a 2s. c o m*/ Log.d(LOG_TAG, "WebHistoryItem favicon W = " + favicon.getWidth()); mOriginalUrl = item.getUrl(); Log.d(LOG_TAG, "GO BACK TO " + mOriginalUrl); mWebview.goBack(); return true; } return super.onKeyDown(keyCode, event); }
From source file:dev.memento.MainActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { // Back button goes back to previous page or memento if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebview.canGoBack()) { // Get the previous URL to update our internal copy WebBackForwardList list = mWebview.copyBackForwardList(); int curr = list.getCurrentIndex(); WebHistoryItem item = list.getItemAtIndex(curr - 1); String url = item.getUrl(); if (Log.LOG) Log.d(LOG_TAG, "GO BACK TO " + url); mWebview.goBack();//from w ww . j a va2s .c o m // Reset to today because it might be confusing to set to other dates setChosenDate(mToday); // Just in case mMementoProgressBar.setVisibility(View.GONE); if (Log.LOG) Log.d(LOG_TAG, "mWebHistory size = " + mWebHistory.size()); if (mWebHistory.isEmpty()) { if (Log.LOG) Log.e(LOG_TAG, "Stack maintaining page dates is empty!"); } else { ExWebHistoryItem item2 = mWebHistory.pop(); // Remove current if (Log.LOG) Log.d(LOG_TAG, "!! Removed item " + item2 + " from stack"); if (!mWebHistory.isEmpty()) { item2 = mWebHistory.peek(); // Previous if (Log.LOG) Log.d(LOG_TAG, "!! Top item is " + item2); } mCurrentMemento = item2.getMemento(); if (Log.LOG) Log.d(LOG_TAG, "mCurrentMemento = " + mCurrentMemento); if (mCurrentMemento == null) mDateDisplayed = mToday; else mDateDisplayed = mCurrentMemento.getDateTime(); if (Log.LOG) Log.d(LOG_TAG, "!! Back to date " + mDateDisplayed); refreshDisplayedDate(); // Indicate the user pressed the back button mUserPressedBack = true; // Should be able to press if it's not today mNowButton.setEnabled(mToday.compareDateTo(mDateDisplayed) != 0); //if (mCurrentMemento != null && !mCurrentMemento.getUrl().equals(url) && // !url.equals(mOriginalUrl)) { if (!mOriginalUrl.equals(item2.getOriginalUrl())) { mOriginalUrl = item2.getOriginalUrl(); if (Log.LOG) Log.d(LOG_TAG, "** Clearing list of old mementos"); if (Log.LOG) Log.d(LOG_TAG, "mOriginalUrl = " + mOriginalUrl); mMementos.clear(); } } return true; } return super.onKeyDown(keyCode, event); }
From source file:android.webkit.cts.WebViewTest.java
private boolean checkWebBackForwardList(WebBackForwardList list, String currUrl, int currIndex, int size) { return (list != null) && (list.getSize() == size) && (list.getCurrentIndex() == currIndex) && list.getItemAtIndex(currIndex).getUrl().equals(currUrl); }
From source file:android.webkit.cts.WebViewTest.java
@UiThreadTest public void testSaveAndRestoreState() throws Throwable { if (!NullWebViewUtils.isWebViewAvailable()) { return;//from ww w. j a v a 2 s.c o m } // nothing to save assertNull(mWebView.saveState(new Bundle())); startWebServer(false); String url1 = mWebServer.getAssetUrl(TestHtmlConstants.HTML_URL1); String url2 = mWebServer.getAssetUrl(TestHtmlConstants.HTML_URL2); String url3 = mWebServer.getAssetUrl(TestHtmlConstants.HTML_URL3); // make a history list mOnUiThread.loadUrlAndWaitForCompletion(url1); pollingCheckWebBackForwardList(url1, 0, 1); mOnUiThread.loadUrlAndWaitForCompletion(url2); pollingCheckWebBackForwardList(url2, 1, 2); mOnUiThread.loadUrlAndWaitForCompletion(url3); pollingCheckWebBackForwardList(url3, 2, 3); // save the list Bundle bundle = new Bundle(); WebBackForwardList saveList = mWebView.saveState(bundle); assertNotNull(saveList); assertEquals(3, saveList.getSize()); assertEquals(2, saveList.getCurrentIndex()); assertEquals(url1, saveList.getItemAtIndex(0).getUrl()); assertEquals(url2, saveList.getItemAtIndex(1).getUrl()); assertEquals(url3, saveList.getItemAtIndex(2).getUrl()); // change the content to a new "blank" web view without history final WebView newWebView = new WebView(getActivity()); WebBackForwardList copyListBeforeRestore = newWebView.copyBackForwardList(); assertNotNull(copyListBeforeRestore); assertEquals(0, copyListBeforeRestore.getSize()); // restore the list final WebBackForwardList restoreList = newWebView.restoreState(bundle); assertNotNull(restoreList); assertEquals(3, restoreList.getSize()); assertEquals(2, saveList.getCurrentIndex()); // wait for the list items to get inflated new PollingCheck(TEST_TIMEOUT) { @Override protected boolean check() { return restoreList.getItemAtIndex(0).getUrl() != null && restoreList.getItemAtIndex(1).getUrl() != null && restoreList.getItemAtIndex(2).getUrl() != null; } }.run(); assertEquals(url1, restoreList.getItemAtIndex(0).getUrl()); assertEquals(url2, restoreList.getItemAtIndex(1).getUrl()); assertEquals(url3, restoreList.getItemAtIndex(2).getUrl()); WebBackForwardList copyListAfterRestore = newWebView.copyBackForwardList(); assertNotNull(copyListAfterRestore); assertEquals(3, copyListAfterRestore.getSize()); assertEquals(2, copyListAfterRestore.getCurrentIndex()); assertEquals(url1, copyListAfterRestore.getItemAtIndex(0).getUrl()); assertEquals(url2, copyListAfterRestore.getItemAtIndex(1).getUrl()); assertEquals(url3, copyListAfterRestore.getItemAtIndex(2).getUrl()); }