package org.cocos2dx.lib;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.opengl.GLSurfaceView.EGLConfigChooser;
import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.preference.PreferenceManager.OnActivityResultListener;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
import java.util.Iterator;
import java.util.Set;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLDisplay;

public abstract class Cocos2dxActivity
  extends Activity
  implements Cocos2dxHelper.Cocos2dxHelperListener
{
  private static final String TAG = Cocos2dxActivity.class.getSimpleName();
  private static Cocos2dxActivity sContext = null;
  protected FrameLayout mFrameLayout = null;
  private int[] mGLContextAttrs = null;
  private Cocos2dxGLSurfaceView mGLSurfaceView = null;
  private Cocos2dxHandler mHandler = null;
  private Cocos2dxVideoHelper mVideoHelper = null;
  private Cocos2dxWebViewHelper mWebViewHelper = null;
  
  public static Context getContext()
  {
    return sContext;
  }
  
  private static native int[] getGLContextAttrs();
  
  private static final boolean isAndroidEmulator()
  {
    String str = Build.MODEL;
    Log.d(TAG, "model=" + str);
    str = Build.PRODUCT;
    Log.d(TAG, "product=" + str);
    boolean bool = false;
    if (str != null) {
      if ((str.equals("sdk")) || (str.contains("_sdk")) || (str.contains("sdk_"))) {
        break label114;
      }
    }
    label114:
    for (bool = false;; bool = true)
    {
      Log.d(TAG, "isEmulator=" + bool);
      return bool;
    }
  }
  
  public void init()
  {
    ViewGroup.LayoutParams localLayoutParams = new ViewGroup.LayoutParams(-1, -1);
    this.mFrameLayout = new FrameLayout(this);
    this.mFrameLayout.setLayoutParams(localLayoutParams);
    localLayoutParams = new ViewGroup.LayoutParams(-1, -2);
    Cocos2dxEditText localCocos2dxEditText = new Cocos2dxEditText(this);
    localCocos2dxEditText.setLayoutParams(localLayoutParams);
    this.mFrameLayout.addView(localCocos2dxEditText);
    this.mGLSurfaceView = onCreateView();
    this.mFrameLayout.addView(this.mGLSurfaceView);
    if (isAndroidEmulator()) {
      this.mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
    }
    this.mGLSurfaceView.setCocos2dxRenderer(new Cocos2dxRenderer());
    this.mGLSurfaceView.setCocos2dxEditText(localCocos2dxEditText);
    setContentView(this.mFrameLayout);
  }
  
  protected void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
  {
    Iterator localIterator = Cocos2dxHelper.getOnActivityResultListeners().iterator();
    for (;;)
    {
      if (!localIterator.hasNext())
      {
        super.onActivityResult(paramInt1, paramInt2, paramIntent);
        return;
      }
      ((PreferenceManager.OnActivityResultListener)localIterator.next()).onActivityResult(paramInt1, paramInt2, paramIntent);
    }
  }
  
  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    onLoadNativeLibraries();
    sContext = this;
    this.mHandler = new Cocos2dxHandler(this);
    Cocos2dxHelper.init(this);
    this.mGLContextAttrs = getGLContextAttrs();
    init();
    if (this.mVideoHelper == null) {
      this.mVideoHelper = new Cocos2dxVideoHelper(this, this.mFrameLayout);
    }
    if (this.mWebViewHelper == null) {
      this.mWebViewHelper = new Cocos2dxWebViewHelper(this.mFrameLayout);
    }
  }
  
  public Cocos2dxGLSurfaceView onCreateView()
  {
    Cocos2dxGLSurfaceView localCocos2dxGLSurfaceView = new Cocos2dxGLSurfaceView(this);
    if (this.mGLContextAttrs[3] > 0) {
      localCocos2dxGLSurfaceView.getHolder().setFormat(-3);
    }
    localCocos2dxGLSurfaceView.setEGLConfigChooser(new GLSurfaceView.EGLConfigChooser()
    {
      protected int[] configAttribs;
      
      private int findConfigAttrib(EGL10 paramAnonymousEGL10, EGLDisplay paramAnonymousEGLDisplay, EGLConfig paramAnonymousEGLConfig, int paramAnonymousInt1, int paramAnonymousInt2)
      {
        int[] arrayOfInt = new int[1];
        if (paramAnonymousEGL10.eglGetConfigAttrib(paramAnonymousEGLDisplay, paramAnonymousEGLConfig, paramAnonymousInt1, arrayOfInt)) {
          paramAnonymousInt2 = arrayOfInt[0];
        }
        return paramAnonymousInt2;
      }
      
      public EGLConfig chooseConfig(EGL10 paramAnonymousEGL10, EGLDisplay paramAnonymousEGLDisplay)
      {
        int[] arrayOfInt1 = new int[1];
        if (paramAnonymousEGL10.eglGetConfigs(paramAnonymousEGLDisplay, null, 0, arrayOfInt1))
        {
          EGLConfig[] arrayOfEGLConfig = new EGLConfig[arrayOfInt1[0]];
          int i = this.configAttribs[0];
          int j = this.configAttribs[1];
          int k = this.configAttribs[2];
          int m = this.configAttribs[3];
          int n = this.configAttribs[4];
          int i1 = this.configAttribs[5];
          int[] arrayOfInt2 = new int[1];
          int i2 = arrayOfInt1[0];
          paramAnonymousEGL10.eglChooseConfig(paramAnonymousEGLDisplay, new int[] { 12324, i, 12323, j, 12322, k, 12321, m, 12325, n, 12326, i1, 12352, 4, 12344 }, arrayOfEGLConfig, i2, arrayOfInt2);
          if (arrayOfInt2[0] > 0) {
            return selectConfig(paramAnonymousEGL10, paramAnonymousEGLDisplay, arrayOfEGLConfig, this.configAttribs);
          }
          int[] arrayOfInt3 = new int[15];
          arrayOfInt3[0] = 12324;
          arrayOfInt3[1] = 5;
          arrayOfInt3[2] = 12323;
          arrayOfInt3[3] = 6;
          arrayOfInt3[4] = 12322;
          arrayOfInt3[5] = 5;
          arrayOfInt3[6] = 12321;
          arrayOfInt3[8] = 12325;
          arrayOfInt3[10] = 12326;
          arrayOfInt3[12] = 12352;
          arrayOfInt3[13] = 4;
          arrayOfInt3[14] = 12344;
          int[] arrayOfInt4 = new int[15];
          arrayOfInt4[0] = 12324;
          arrayOfInt4[1] = 4;
          arrayOfInt4[2] = 12323;
          arrayOfInt4[3] = 4;
          arrayOfInt4[4] = 12322;
          arrayOfInt4[5] = 4;
          arrayOfInt4[6] = 12321;
          arrayOfInt4[7] = 4;
          arrayOfInt4[8] = 12325;
          arrayOfInt4[10] = 12326;
          arrayOfInt4[12] = 12352;
          arrayOfInt4[13] = 4;
          arrayOfInt4[14] = 12344;
          if (this.configAttribs[3] == 0)
          {
            paramAnonymousEGL10.eglChooseConfig(paramAnonymousEGLDisplay, arrayOfInt3, arrayOfEGLConfig, arrayOfInt1[0], arrayOfInt2);
            arrayOfInt1 = new int[6];
            arrayOfInt1[0] = 5;
            arrayOfInt1[1] = 6;
            arrayOfInt1[2] = 5;
          }
          while (arrayOfInt2[0] > 0)
          {
            return selectConfig(paramAnonymousEGL10, paramAnonymousEGLDisplay, arrayOfEGLConfig, arrayOfInt1);
            paramAnonymousEGL10.eglChooseConfig(paramAnonymousEGLDisplay, arrayOfInt4, arrayOfEGLConfig, arrayOfInt1[0], arrayOfInt2);
            arrayOfInt1 = new int[6];
            arrayOfInt1[0] = 4;
            arrayOfInt1[1] = 4;
            arrayOfInt1[2] = 4;
            arrayOfInt1[3] = 4;
          }
          Log.e("device_policy", "Can not select an EGLConfig for rendering.");
          return null;
        }
        Log.e("device_policy", "Can not select an EGLConfig for rendering.");
        return null;
      }
      
      public EGLConfig selectConfig(EGL10 paramAnonymousEGL10, EGLDisplay paramAnonymousEGLDisplay, EGLConfig[] paramAnonymousArrayOfEGLConfig, int[] paramAnonymousArrayOfInt)
      {
        int j = paramAnonymousArrayOfEGLConfig.length;
        int i = 0;
        for (;;)
        {
          EGLConfig localEGLConfig;
          if (i >= j) {
            localEGLConfig = null;
          }
          int k;
          int m;
          int n;
          int i1;
          do
          {
            return localEGLConfig;
            localEGLConfig = paramAnonymousArrayOfEGLConfig[i];
            k = findConfigAttrib(paramAnonymousEGL10, paramAnonymousEGLDisplay, localEGLConfig, 12325, 0);
            m = findConfigAttrib(paramAnonymousEGL10, paramAnonymousEGLDisplay, localEGLConfig, 12326, 0);
            if ((k < paramAnonymousArrayOfInt[4]) || (m < paramAnonymousArrayOfInt[5])) {
              break;
            }
            k = findConfigAttrib(paramAnonymousEGL10, paramAnonymousEGLDisplay, localEGLConfig, 12324, 0);
            m = findConfigAttrib(paramAnonymousEGL10, paramAnonymousEGLDisplay, localEGLConfig, 12323, 0);
            n = findConfigAttrib(paramAnonymousEGL10, paramAnonymousEGLDisplay, localEGLConfig, 12322, 0);
            i1 = findConfigAttrib(paramAnonymousEGL10, paramAnonymousEGLDisplay, localEGLConfig, 12321, 0);
          } while ((k >= paramAnonymousArrayOfInt[0]) && (m >= paramAnonymousArrayOfInt[1]) && (n >= paramAnonymousArrayOfInt[2]) && (i1 >= paramAnonymousArrayOfInt[3]));
          i += 1;
        }
      }
    });
    return localCocos2dxGLSurfaceView;
  }
  
  protected void onDestroy()
  {
    super.onDestroy();
  }
  
  protected void onLoadNativeLibraries()
  {
    try
    {
      System.loadLibrary(getPackageManager().getApplicationInfo(getPackageName(), 128).metaData.getString("android.app.lib_name"));
      return;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }
  
  protected void onPause()
  {
    super.onPause();
    Cocos2dxHelper.onPause();
    this.mGLSurfaceView.onPause();
  }
  
  protected void onResume()
  {
    super.onResume();
    Cocos2dxHelper.onResume();
    this.mGLSurfaceView.onResume();
  }
  
  public void runOnGLThread(Runnable paramRunnable)
  {
    this.mGLSurfaceView.queueEvent(paramRunnable);
  }
  
  public void setKeepScreenOn(final boolean paramBoolean)
  {
    runOnUiThread(new Runnable()
    {
      public void run()
      {
        Cocos2dxActivity.this.mGLSurfaceView.setKeepScreenOn(paramBoolean);
      }
    });
  }
  
  public void showDialog(String paramString1, String paramString2)
  {
    Message localMessage = new Message();
    localMessage.what = 1;
    localMessage.obj = new Cocos2dxHandler.DialogMessage(paramString1, paramString2);
    this.mHandler.sendMessage(localMessage);
  }
  
  public void showEditTextDialog(String paramString1, String paramString2, int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    Message localMessage = new Message();
    localMessage.what = 2;
    localMessage.obj = new Cocos2dxHandler.EditBoxMessage(paramString1, paramString2, paramInt1, paramInt2, paramInt3, paramInt4);
    this.mHandler.sendMessage(localMessage);
  }
}


/* Location:              /home/enzo/Documents/hacking/malwares/viking-horde/classes.jar!/org/cocos2dx/lib/Cocos2dxActivity.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */