Code example for WebView

Methods: clearViewgetSettingssetBackgroundColor, getContext, getWidth, setDrawingCacheEnabled, setTag, setVisibility

0
	} 
 
	public void load(String url) {
		this.url = url;
 
		wv.clearView();
		wv.setTag(url);
 
		if (android.os.Build.VERSION.SDK_INT <= 10) {
			wv.setDrawingCacheEnabled(true);
		} 
 
		fixWebviewTip(wv.getContext());
 
		WebSettings ws = wv.getSettings();
		ws.setSupportZoom(zoom);
		ws.setBuiltInZoomControls(zoom);
 
		if (!control) {
			disableZoomControl(wv);
		} 
 
		ws.setJavaScriptEnabled(true);
		ws.setAllowFileAccess(true);
		if (android.os.Build.VERSION.SDK_INT >= 11)
			ws.setAllowContentAccess(true);
		ws.setCacheMode(WebSettings.LOAD_DEFAULT);
		wv.setBackgroundColor(color);
 
		if (splash != null) {
			splash.setVisibility(View.VISIBLE);
			wv.setVisibility(View.INVISIBLE);
		} 
 
		if (wv.getWidth() > 0) {
			setup(); 
		} else { 
			delaySetup(); 
		} 
 
	} 
 
	public void reset() { 
		this.url = null;
		if (splash != null) {
			splash.setVisibility(View.VISIBLE);
			wv.setVisibility(View.INVISIBLE);
		} 
	} 
 
	private void delaySetup() { 
		wv.setPictureListener(new PictureListener() {
 
			@Override 
			public void onNewPicture(WebView view, Picture picture) {
				wv.setPictureListener(null);
				setup(); 
			} 
 
		}); 
 
		wv.loadData("<html></html>", "text/html", "utf-8");
		wv.setBackgroundColor(color);
 
	} 
 
	private void setup() { 
		String source = getSource(wv.getContext());
		String html = source.replace("@src", url).replace("@color",
				Integer.toHexString(color));
 
		wv.setWebViewClient(this);
 
		wv.loadDataWithBaseURL(null, html, "text/html", "utf-8", null);
		wv.setBackgroundColor(color);
 
	} 
 
	public void done(WebView view) {
		if (splash != null) {
			splash.setVisibility(View.INVISIBLE);
			view.setVisibility(View.VISIBLE);
		} 
		view.setWebViewClient(null);
	} 
 
	@Override 
	public void onPageFinished(WebView view, String url) {
	} 
 
	@Override 
	public void onReceivedError(WebView view, int errorCode,
			String description, String failingUrl) {
	} 
 
	@Override 
	public void onScaleChanged(WebView view, float oldScale, float newScale) {
	} 
 
	private static void disableZoomControl(WebView wv) {
 
		if (android.os.Build.VERSION.SDK_INT < 11)
			return; 
 
		WebSettings ws = wv.getSettings();
		AQUtility.invokeHandler(ws, "setDisplayZoomControls", false, false,
				new Class[] { boolean.class }, false);
 
	} 
} 
Stop searching for code, let great code find you!  Add Codota to your java IDE