下面列出了怎么用android.webkit.WebHistoryItem的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public boolean canGoBackOrForward(int steps) {
int increment = steps < 0 ? -1 : 1;
WebBackForwardList list = copyBackForwardList();
int count = 0;
int startIdx = list.getCurrentIndex();
for (int i = startIdx + increment; i < list.getSize() && i >= 0; i += increment) {
WebHistoryItem item = list.getItemAtIndex(i);
if (!item.getOriginalUrl().startsWith("data:")) {
count += increment;
if (count == steps) {
return true;
}
}
}
return false;
}
@Override
public void goBackOrForward(int steps) {
int increment = steps < 0 ? -1 : 1;
WebBackForwardList list = copyBackForwardList();
int count = 0;
int intCount = 0;
int startIdx = list.getCurrentIndex();
for (int i = startIdx + increment; i < list.getSize() && i >= 0; i += increment) {
intCount += increment;
WebHistoryItem item = list.getItemAtIndex(i);
if (!item.getOriginalUrl().startsWith("data:")) {
count += increment;
if (count == steps) {
super.goBackOrForward(intCount);
return;
}
}
}
}
private boolean isWebViewSane() {
String url = unprepared.view.getUrl();
WebHistoryItem current = unprepared.view.copyBackForwardList().getCurrentItem();
boolean getUrlReady = url != null;
boolean webHistoryReady = current != null;
if (getUrlReady && webHistoryReady) {
String historyUrl = current.getUrl();
boolean viewAndHistoryMatch = urlAndHistoryUrlMatch(url, historyUrl);
boolean nonZeroContentHeight = unprepared.view.getContentHeight() != 0;
boolean progressComplete = unprepared.view.getProgress() == 100;
sanityMessage =
String.format(
"viewAndHistoryUrlsMatch: %s, nonZeroContentHeight: %s, progressComplete: %s",
viewAndHistoryMatch, nonZeroContentHeight, progressComplete);
return viewAndHistoryMatch && progressComplete && nonZeroContentHeight;
} else {
sanityMessage =
String.format(
"view.getUrl() != null: %s view.copyBackForwardList().getCurrentItem() != null: %s",
getUrlReady, webHistoryReady);
}
return false;
}
/**
* Browse to relative entry with sanity check on value
* @param relative relative addition or subtraction of browsing index
*/
private void loadSessionUrl(int relative)
{
WebBackForwardList sessionHistory = web3.copyBackForwardList();
int newIndex = sessionHistory.getCurrentIndex() + relative;
if (newIndex < sessionHistory.getSize())
{
WebHistoryItem newItem = sessionHistory.getItemAtIndex(newIndex);
if (newItem != null)
{
urlTv.setText(newItem.getUrl());
}
}
}
private void getWebTitle(WebView view){
WebBackForwardList forwardList = view.copyBackForwardList();
WebHistoryItem item = forwardList.getCurrentItem();
if (item != null) {
tvTitle.setText(item.getTitle());
// X5LogUtils.i("-------onReceivedTitle----getWebTitle---"+item.getTitle());
}
}
private void getWebTitle(WebView view){
WebBackForwardList forwardList = view.copyBackForwardList();
WebHistoryItem item = forwardList.getCurrentItem();
if (item != null) {
tvTitle.setText(item.getTitle());
// X5LogUtils.i("-------onReceivedTitle----getWebTitle---"+item.getTitle());
}
}
private void getWebTitle(WebView view){
WebBackForwardList forwardList = view.copyBackForwardList();
WebHistoryItem item = forwardList.getCurrentItem();
if (item != null) {
tvTitle.setText(item.getTitle());
// X5LogUtils.i("-------onReceivedTitle----getWebTitle---"+item.getTitle());
}
}
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 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;
}
/**
* Indicate if the browser's back list contains a book gallery
* Used to determine the display of the "back to latest gallery" button
*
* @param backForwardList Back list to examine
* @return Index of the latest book gallery in the list; -1 if none has been detected
*/
private int backListContainsGallery(@NonNull final WebBackForwardList backForwardList) {
for (int i = backForwardList.getCurrentIndex() - 1; i >= 0; i--) {
WebHistoryItem item = backForwardList.getItemAtIndex(i);
if (webClient.isBookGallery(item.getUrl())) return i;
}
return -1;
}
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 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 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 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 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 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 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;
}
private boolean ingoreWebViewBackNavigation(WebView vpaidWebView) {
if (vpaidWebView != null) {
WebBackForwardList mWebBackForwardList = vpaidWebView.copyBackForwardList();
if (mWebBackForwardList == null) {
return false;
}
WebHistoryItem historyItem = mWebBackForwardList.getItemAtIndex(mWebBackForwardList.getCurrentIndex() - 1);
if (historyItem == null) {
return false;
}
String historyUrl = historyItem.getUrl();
if (historyUrl != null && historyUrl.equalsIgnoreCase(VpaidClient.EMPTY_URL)) {
return true;
}
}
return false;
}