package com.sometrik.framework;

import javax.microedition.khronos.opengles.GL10;

import android.content.Context;
import android.content.res.AssetManager;
import android.opengl.EGLConfig;
import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.DisplayMetrics;

public class MyGLRenderer implements GLSurfaceView.Renderer {

  private MyGLRenderer renderer;
  public Handler mHandler;
  AssetManager assetManager;
  MyGLSurfaceView GLView;
  FrameWork frame;
  Context context;
  float xSize;
  float ySize;
  long endTime;
  long startTime;

  public native void nativeOnDraw();

  public native void onInit(AssetManager assetManager, MyGLSurfaceView view, float xSize, float ySize, float displayScale, Boolean hasEs3);

  public native void Draw();

  public native void onResize(float xSize, float ySize);

  public native void onTouchesBegin(int fingerIndex);

  public native void onTouchesEnded(int fingerIndex);

  public native void onTouchesMoved(int fingerIndex);

  public MyGLRenderer(Context context, float x, float y) {

    frame = (FrameWork) context;
    startTime = System.currentTimeMillis();
    assetManager = context.getAssets();
    this.xSize = x;
    this.ySize = y;
  }

  public void onDrawFrame(GL10 unused) {
      // Calls onDraw in AndroidPlatform
      nativeOnDraw();
  }

  public void onSurfaceChanged(GL10 unused, int width, int height) {
    System.out.println("(Renderer) onSurfaceChanged called");
    GLES20.glViewport(0, 0, width, height);

    onResize(width, height);
  }

  @Override
  public void onSurfaceCreated(GL10 gl, javax.microedition.khronos.egl.EGLConfig config) {
    System.out.println("(Renderer)onSurfaceCreated(override) called");

    renderer = this;
    System.out.println("surface check: " + frame.getSurfaceView());

    DisplayMetrics displayMetrics = frame.getDisplayMetrics();
    System.out.println("Display scale: " + displayMetrics.scaledDensity);
    // Calls onInit in AndroidPlatform
    onInit(assetManager, frame.getSurfaceView(), xSize, ySize, displayMetrics.scaledDensity, false);

    xSize = displayMetrics.widthPixels / displayMetrics.scaledDensity;
    ySize = displayMetrics.heightPixels / displayMetrics.scaledDensity;

  }

}

@@ -99,23 +99,106 @@
 oid.
-content.Context
+app.ActivityManager;%0D%0Aimport android.content.Context;%0D%0Aimport android.content.pm.ConfigurationInfo
 ;%0D%0Ai
@@ -2172,24 +2172,517 @@
 dDensity);%0D%0A
+    final ActivityManager activityManager = (ActivityManager) frame.getSystemService(Context.ACTIVITY_SERVICE);%0D%0A    final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();%0D%0A    Boolean hasEs3;%0D%0A    if (configurationInfo.reqGlEsVersion %3E= 0x30000)%7B%0D%0A      hasEs3 = true;%0D%0A    %7D else if (configurationInfo.reqGlEsVersion %3E= 0x20000) %7B%0D%0A      hasEs3 = false;%0D%0A    %7D else %7B%0D%0A      hasEs3 = false;%0D%0A      System.out.println(%22openGLES 2 isn't supported%22);%0D%0A    %7D%0D%0A
     // Calls
@@ -2802,21 +2802,22 @@
 ensity, 
-false
+hasEs3
 );%0D%0A%0D%0A  

fix #14 Check version in java