// Copyright (C) 2015 Elviss Strazdins
// This file is part of the Ouzel engine.

package lv.elviss.ouzel;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ConfigurationInfo;
import android.opengl.GLSurfaceView;
import android.os.Build;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends Activity
{
	private GLSurfaceView glSurfaceView;
	private boolean rendererSet;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);

		ActivityManager activityManager 
			= (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
		ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();

		final boolean supportsEs2 = 
			configurationInfo.reqGlEsVersion >= 0x20000 || isProbablyEmulator();

		if (supportsEs2)
		{
			glSurfaceView = new GLSurfaceView(this);

			if (isProbablyEmulator())
			{
				// Avoids crashes on startup with some emulator images.
				glSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
			}

			glSurfaceView.setEGLContextClientVersion(2);
			glSurfaceView.setRenderer(new RendererWrapper());
			rendererSet = true;
			setContentView(glSurfaceView);
		}
		else
		{
			// Should never be seen in production, since the manifest filters
			// unsupported devices.
			Toast.makeText(this, "This device does not support OpenGL ES 2.0.",
					Toast.LENGTH_LONG).show();
			return;
		}
	}

	private boolean isProbablyEmulator()
	{
		return Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD
				&& (Build.FINGERPRINT.startsWith("generic")
						|| Build.FINGERPRINT.startsWith("unknown")
						|| Build.MODEL.contains("google_sdk")
						|| Build.MODEL.contains("Emulator")
						|| Build.MODEL.contains("Android SDK built for x86"));
	}

	@Override
	protected void onPause()
	{
		super.onPause();

		if (rendererSet)
		{
			glSurfaceView.onPause();
		}
	}

	@Override
	protected void onResume()
	{
		super.onResume();

		if (rendererSet)
		{
			glSurfaceView.onResume();
		}
	}
}

@@ -447,38 +447,8 @@
 iew;
-%0A%09private boolean rendererSet;
 %0A%0A%09@
@@ -1174,31 +1174,8 @@
 ));%0A
-%09%09%09rendererSet = true;%0A
 %09%09%09s
@@ -1854,35 +1854,45 @@
 e();%0A%0A%09%09if (
-rendererSet
+glSurfaceView != null
 )%0A%09%09%7B%0A%09%09%09glS
@@ -1993,19 +1993,29 @@
 if (
-rendererSet
+glSurfaceView != null
 )%0A%09%09

Remove unneeded boolean flag