Guest User

Untitled

a guest
Dec 8th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. package net.gangneux.dev.jrmgxlibview;
  2.  
  3. import android.content.Context;
  4. import android.graphics.Canvas;
  5. import android.util.AttributeSet;
  6. import android.util.Log;
  7. import android.view.Surface;
  8. import android.view.ViewGroup;
  9. import android.webkit.WebChromeClient;
  10. import android.webkit.WebView;
  11. import android.webkit.WebViewClient;
  12.  
  13. /**
  14. * Created by jerome on 30/10/2016.
  15. */
  16. public class JrmgxWebView extends WebView {
  17.  
  18. private Surface surface = null;
  19.  
  20. // Inherit
  21.  
  22. public JrmgxWebView(Context context) {
  23. super(context);
  24. Log.i("JrmgxWebView.java", "Constructor with context");
  25. }
  26.  
  27. public JrmgxWebView(Context context, AttributeSet attrs) {
  28. super(context, attrs);
  29. Log.i("JrmgxWebView.java", "Constructor with context + attrs");
  30. }
  31.  
  32. public JrmgxWebView(Context context, AttributeSet attrs, int defStyleAttr) {
  33. super(context, attrs, defStyleAttr);
  34. Log.i("JrmgxWebView.java", "Constructor with context + attrs + styleAttr");
  35. }
  36.  
  37. // Custom
  38.  
  39. public long lastUpdateTime = 0;
  40. public int width = 512;
  41. public int height = 512;
  42. public boolean hasUpdate = false;
  43.  
  44. public JrmgxWebView(Context context, int width, int height) {
  45. super(context);
  46. this.width = width;
  47. this.height = height;
  48. Log.i("JrmgxWebView.java", "Constructor with context + width + height = " + width + " + " + height);
  49.  
  50. //setWebChromeClient( new WebChromeClient(){} );
  51. //setWebViewClient( new WebViewClient() );
  52.  
  53. /*
  54. setWebChromeClient(new WebChromeClient());
  55. getSettings().setJavaScriptEnabled(true);
  56. getSettings().setDomStorageEnabled(true);
  57.  
  58. setWebViewClient(new WebViewClient() {
  59. public boolean shouldOverrideUrlLoading(WebView view,String url) {
  60. return false;
  61. }
  62. });
  63. */
  64.  
  65. setLayoutParams(new ViewGroup.LayoutParams(width, height));
  66. }
  67.  
  68. void setSurface(Surface surface) {
  69. Log.i("JrmgxWebView.java", "setSurface");
  70. this.surface = surface;
  71. }
  72.  
  73. @Override
  74. public void loadUrl(String url) {
  75. Log.i("JrmgxWebView.java", "load url " + url);
  76. super.loadUrl(url);
  77. }
  78.  
  79. @Override
  80. public void loadData(String data, String mimeType, String encoding) {
  81. super.loadData(data, mimeType, encoding);
  82. }
  83.  
  84. public void loadData(String data) {
  85. Log.i("JrmgxWebView.java", "load data with: " + data);
  86. super.loadData(data, "text/html; charset=utf-8", "UTF-8");
  87. }
  88.  
  89. @Override
  90. protected void onDraw(Canvas canvas) {
  91. Log.i("JrmgxWebView.java", "onDraw");
  92.  
  93. /*if (lastUpdateTime == 0) {
  94. lastUpdateTime = System.currentTimeMillis();
  95. }
  96.  
  97. if (System.currentTimeMillis() - lastUpdateTime < 33) {
  98. return; // Skip frame-rate
  99. }
  100.  
  101. lastUpdateTime = System.currentTimeMillis();
  102. hasUpdate = true;*/
  103.  
  104. if (surface != null) {
  105. try {
  106. final Canvas surfaceCanvas = surface.lockCanvas(null);
  107. //surfaceCanvas.save();
  108. //surfaceCanvas.translate(0, 0); // TODO scrolling
  109. super.onDraw(surfaceCanvas);
  110. //surfaceCanvas.restore();
  111. surface.unlockCanvasAndPost(surfaceCanvas);
  112. Log.i("JrmgxWebView.java", "onDraw not null + success");
  113. }
  114. catch (Exception e) {
  115. Log.e("JrmgxWebView.java", "onDraw exception " + e.getMessage());
  116. }
  117. }
  118. //super.onDraw(canvas);
  119. /* GVR (samsung)
  120. Canvas attachedCanvas = mSceneObject.lockCanvas();
  121. // translate canvas to reflect view scrolling
  122. attachedCanvas.scale(attachedCanvas.getWidth() / (float) canvas.getWidth(),
  123. attachedCanvas.getHeight() / (float) canvas.getHeight());
  124. attachedCanvas.translate(-getScrollX(), -getScrollY());
  125. // draw the view to provided canvas
  126. super.draw(attachedCanvas);
  127. */
  128. }
  129. }
Add Comment
Please, Sign In to add comment