Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.gangneux.dev.jrmgxlibview;
- import android.content.Context;
- import android.graphics.Canvas;
- import android.util.AttributeSet;
- import android.util.Log;
- import android.view.Surface;
- import android.view.ViewGroup;
- import android.webkit.WebChromeClient;
- import android.webkit.WebView;
- import android.webkit.WebViewClient;
- /**
- * Created by jerome on 30/10/2016.
- */
- public class JrmgxWebView extends WebView {
- private Surface surface = null;
- // Inherit
- public JrmgxWebView(Context context) {
- super(context);
- Log.i("JrmgxWebView.java", "Constructor with context");
- }
- public JrmgxWebView(Context context, AttributeSet attrs) {
- super(context, attrs);
- Log.i("JrmgxWebView.java", "Constructor with context + attrs");
- }
- public JrmgxWebView(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- Log.i("JrmgxWebView.java", "Constructor with context + attrs + styleAttr");
- }
- // Custom
- public long lastUpdateTime = 0;
- public int width = 512;
- public int height = 512;
- public boolean hasUpdate = false;
- public JrmgxWebView(Context context, int width, int height) {
- super(context);
- this.width = width;
- this.height = height;
- Log.i("JrmgxWebView.java", "Constructor with context + width + height = " + width + " + " + height);
- //setWebChromeClient( new WebChromeClient(){} );
- //setWebViewClient( new WebViewClient() );
- /*
- setWebChromeClient(new WebChromeClient());
- getSettings().setJavaScriptEnabled(true);
- getSettings().setDomStorageEnabled(true);
- setWebViewClient(new WebViewClient() {
- public boolean shouldOverrideUrlLoading(WebView view,String url) {
- return false;
- }
- });
- */
- setLayoutParams(new ViewGroup.LayoutParams(width, height));
- }
- void setSurface(Surface surface) {
- Log.i("JrmgxWebView.java", "setSurface");
- this.surface = surface;
- }
- @Override
- public void loadUrl(String url) {
- Log.i("JrmgxWebView.java", "load url " + url);
- super.loadUrl(url);
- }
- @Override
- public void loadData(String data, String mimeType, String encoding) {
- super.loadData(data, mimeType, encoding);
- }
- public void loadData(String data) {
- Log.i("JrmgxWebView.java", "load data with: " + data);
- super.loadData(data, "text/html; charset=utf-8", "UTF-8");
- }
- @Override
- protected void onDraw(Canvas canvas) {
- Log.i("JrmgxWebView.java", "onDraw");
- /*if (lastUpdateTime == 0) {
- lastUpdateTime = System.currentTimeMillis();
- }
- if (System.currentTimeMillis() - lastUpdateTime < 33) {
- return; // Skip frame-rate
- }
- lastUpdateTime = System.currentTimeMillis();
- hasUpdate = true;*/
- if (surface != null) {
- try {
- final Canvas surfaceCanvas = surface.lockCanvas(null);
- //surfaceCanvas.save();
- //surfaceCanvas.translate(0, 0); // TODO scrolling
- super.onDraw(surfaceCanvas);
- //surfaceCanvas.restore();
- surface.unlockCanvasAndPost(surfaceCanvas);
- Log.i("JrmgxWebView.java", "onDraw not null + success");
- }
- catch (Exception e) {
- Log.e("JrmgxWebView.java", "onDraw exception " + e.getMessage());
- }
- }
- //super.onDraw(canvas);
- /* GVR (samsung)
- Canvas attachedCanvas = mSceneObject.lockCanvas();
- // translate canvas to reflect view scrolling
- attachedCanvas.scale(attachedCanvas.getWidth() / (float) canvas.getWidth(),
- attachedCanvas.getHeight() / (float) canvas.getHeight());
- attachedCanvas.translate(-getScrollX(), -getScrollY());
- // draw the view to provided canvas
- super.draw(attachedCanvas);
- */
- }
- }
Add Comment
Please, Sign In to add comment