@SuppressWarnings("deprecation")
    public SketchSurfaceViewGL(
        Context context, int wide, int high, Class<? extends PGraphicsOpenGL> clazz) {
      super(context);

      // Check if the system supports OpenGL ES 2.0.
      final ActivityManager activityManager =
          (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
      final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
      final boolean supportsGLES2 = configurationInfo.reqGlEsVersion >= 0x20000;

      if (!supportsGLES2) {
        throw new RuntimeException("OpenGL ES 2.0 is not supported by this device.");
      }

      surfaceHolder = getHolder();
      // are these two needed?
      surfaceHolder.addCallback(this);
      surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_GPU);

      // The PGraphics object needs to be created here so the renderer is not
      // null. This is required because PApplet.onResume events (which call
      // this.onResume() and thus require a valid renderer) are triggered
      // before surfaceChanged() is ever called.

      if (clazz.equals(PGraphics2D.class)) { // P2D
        g3 = new PGraphics2D();
      } else if (clazz.equals(PGraphics3D.class)) { // P3D
        g3 = new PGraphics3D();
      } else { // something that extends P2D, P3D, or PGraphicsOpenGL
        try {
          Constructor<? extends PGraphicsOpenGL> constructor = clazz.getConstructor();
          g3 = constructor.newInstance();
        } catch (Exception exception) {
          throw new RuntimeException(
              "Error: Failed to initialize custom OpenGL renderer", exception);
        }
      }

      // set it up
      g3.setParent(sketch);
      g3.setPrimary(true);
      // Set semi-arbitrary size; will be set properly when surfaceChanged() called
      g3.setSize(wide, high);

      // Tells the default EGLContextFactory and EGLConfigChooser to create an GLES2 context.
      setEGLContextClientVersion(2);

      int quality = sketch.sketchQuality();
      if (1 < quality) {
        setEGLConfigChooser(((PGLES) g3.pgl).getConfigChooser(quality));
      }

      // The renderer can be set only once.
      setRenderer(((PGLES) g3.pgl).getRenderer());
      setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

      // assign this g to the PApplet
      sketch.g = g3;

      setFocusable(true);
      setFocusableInTouchMode(true);
      requestFocus();
    }