当前位置:操作系统 > 安卓/Android >>

android 用webview自制带有history和download功能的浏览器

package com.mysession;
 
import java.util.ArrayList;
 import java.util.List;
 
import android.app.Activity;
 import android.content.Intent;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Matrix;
 import android.graphics.Picture;
 import android.net.Uri;
 import android.os.Bundle;
 import android.util.Log;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.webkit.CookieManager;
 import android.webkit.CookieSyncManager;
 import android.webkit.DownloadListener;
 import android.webkit.ValueCallback;
 import android.webkit.WebChromeClient;
 import android.webkit.WebHistoryItem;
 import android.webkit.WebSettings;
 import android.webkit.WebView;
 import android.webkit.WebViewClient;
 import android.widget.Button;
 import android.widget.EditText;
 import android.widget.GridView;
 import android.widget.ProgressBar;
 
import com.mysession.model.HistoryModel;
 
public class D_sessionActivity extends Activity implements OnClickListener,
         DownloadListener {
 
    private static final String TAG = "TAG";
     // private String detailUrl =
     // "http://www.google.com";
     // private String detailUrl =
     // "http://172.20.230.67:8900/iportal/servlet/GetMobileContent?&user=administrator&vol=allen_iServer&profile=myserver&password=uaABd7AZ0ThXe6WFM2FdqA%3D%3D&respFormat=html&subID=7fb249ba-1470-4663-9863-a743c740aeeb&enc=1";
 
    // private String detailUrl = "http://music.sogou.com/";
     private WebView webview;
     private Button btnLoad, btnReset, btnHistory, btnBack, btnForward;
     private EditText etUrl;
     private ProgressBar mProgressBar;
     private GridView mGridView;
     private CookieManager cookieManager;
     private BrowserHistoryAdapter browserHistoryAdapter;
     private List<HistoryModel> historyModels = new ArrayList<HistoryModel>();
 
    /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
 
        CookieSyncManager.createInstance(this);
         cookieManager = CookieManager.getInstance();
 
        webview = (WebView) findViewById(R.id.webView1);
         btnLoad = (Button) findViewById(R.id.btnLoad);
         btnReset = (Button) findViewById(R.id.btnReset);
         btnHistory = (Button) findViewById(R.id.btnHistory);
         mProgressBar = (ProgressBar) findViewById(R.id.progressBar1);
         etUrl = (EditText) findViewById(R.id.etUrl);
         btnBack = (Button) findViewById(R.id.btnBack);
         btnForward = (Button) findViewById(R.id.btnForward);
         mGridView = (GridView) findViewById(R.id.gridView1);
 
        btnLoad.setOnClickListener(this);
         btnReset.setOnClickListener(this);
         btnHistory.setOnClickListener(this);
         btnBack.setOnClickListener(this);
         btnForward.setOnClickListener(this);
 
        webview.getSettings().setJavaScriptEnabled(true);
         webview.setWebViewClient(new BirtMobileWebViewClient());
         webview.setWebChromeClient(new GeoClient());
         webview.setDownloadListener(this);
         webview.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
 
        // WebBackForwardList history = webview.copyBackForwardList();
         // if (history != null) {
         // browserHistoryAdapter = new BrowserHistoryAdapter(history, this);
         // mGridView.setAdapter(browserHistoryAdapter);
         // }
 
        webview.setVisibility(View.VISIBLE);
         mGridView.setVisibility(View.GONE);
     }
 
    @Override
     public void onClick(View v) {
         if (v == btnLoad) {
             cookieManager.setAcceptCookie(true);
             webview.setVisibility(View.VISIBLE);
             mGridView.setVisibility(View.GONE);
 
            if (!"".equalsIgnoreCase(etUrl.getText().toString())) {
                 webview.loadUrl(etUrl.getText().toString());
             }
 
        } else if (v == btnReset) {
             cookieManager.removeAllCookie();
         } else if (v == btnHistory) {
             if (webview.copyBackForwardList() == null) {
                 return;
             } else {
                 webview.setVisibility(View.GONE);
                 mGridView.setVisibility(View.VISIBLE);
 
                if (browserHistoryAdapter == null) {
           &nbs

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,