Code example for WebView: Displaying web pages

Methods: loadUrlsetPictureListenersetWebViewClient

0
	} 
 
	@Override 
	public AndrRaster html(IBRectangle s, BResourceLocator rl) throws IOException {
		final AndrRaster ret = raster(s);
		final WebView webview = new WebView(AndrPlatform.context());
		webview.setWebViewClient( new WebViewClient(){
			@Override 
			public void onPageFinished(WebView view, String url) {
				view.capturePicture();
			} 
		}); 
		 
		final Runnable runable = new Runnable(){
			private int _times = 4;
			private int DELAY = 1000;
			public void run() { 
				Canvas canvas = new Canvas( ret.bitmap() );
				canvas.drawLine(0, 0, ret.bitmap().getWidth(), ret.bitmap().getHeight(), new Paint() );
				webview.draw(canvas);
				BPlatform.instance().game().screen().refresh(); 
				_times--;
				if( _times > 0 ){
					BPlatform.instance().game().animator().post(DELAY,this);
				} 
				else{ 
					ViewGroup viewGroup = (ViewGroup)webview.getParent();
					if( viewGroup != null ){
						viewGroup.removeView(webview);
					} 
				} 
			}; 
		}; 
		 
		webview.setPictureListener(new PictureListener(){
			@Override 
			public void onNewPicture(WebView view, Picture picture) {
				BPlatform.instance().game().animator().post(runable);
			} 
		}); 
		 
		 
		int b = (int) s.h();
		int r = (int) s.w();
		int t = 0;
		int l = 0;
		AndrScreen screen = (AndrScreen)AndrPlatform.instance().game().screen();
		FrameLayout v = screen.layout();
		v.addView(webview, new FrameLayout.LayoutParams(r, b) );
		screen.bringViewToFront();
		 
//		view.setLayoutParams( new ViewGroup.LayoutParams(r, b)); 
//		view.measure(MeasureSpec.makeMeasureSpec(r, MeasureSpec.EXACTLY),  
//                 	 MeasureSpec.makeMeasureSpec(b, MeasureSpec.EXACTLY)); 
//		view.layout(l, t, r, b); 
		 
		URL u = null;
		if( rl.url() != null ){
			u = rl.url();
		} 
		if( u == null ){
			u = BPlatform.instance().platformURL( rl );
		} 
		String str = u.toExternalForm();
		webview.loadUrl(str);
		 
		BPlatform.instance().game().animator().addAnimation( new BProgressAnimation(ret) );
		 
		return ret;
	} 
Experience pair programming with AI  Get Codota for Java