package com.ikea.kompis.scan;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.OrientationEventListener;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import com.ikea.kompis.BaseCustomFontActivity;
import com.ikea.kompis.util.UiUtil;
import com.metaio.sdk.MetaioDebug;
import com.metaio.sdk.MetaioSurfaceView;
import com.metaio.sdk.MetaioSurfaceView.Callback;
import com.metaio.sdk.SensorsComponentAndroid;
import com.metaio.sdk.jni.Camera;
import com.metaio.sdk.jni.ERENDER_SYSTEM;
import com.metaio.sdk.jni.ESCREEN_ROTATION;
import com.metaio.sdk.jni.IGeometry;
import com.metaio.sdk.jni.IMetaioSDKAndroid;
import com.metaio.sdk.jni.IMetaioSDKCallback;
import com.metaio.sdk.jni.MetaioSDK;
import com.metaio.tools.Memory;
import com.metaio.tools.Screen;

@TargetApi(10)
public abstract class ARViewActivity extends BaseCustomFontActivity
  implements MetaioSurfaceView.Callback, View.OnTouchListener
{
  public static final int JELLY_BEAN_MR1 = 17;
  protected boolean mActivityIsPaused;
  protected View mGUIView;
  private OrientationEventListener mOrientationEventListener;
  protected boolean mRendererInitialized;
  protected SensorsComponentAndroid mSensors;
  protected MetaioSurfaceView mSurfaceView;
  protected IMetaioSDKAndroid metaioSDK;

  protected abstract int getGUILayout();

  protected abstract IMetaioSDKCallback getMetaioSDKCallbackHandler();

  protected abstract void loadContents();

  protected void loadNativeLibs()
    throws UnsatisfiedLinkError
  {
    IMetaioSDKAndroid.loadNativeLibs();
    MetaioDebug.log(4, "MetaioSDK libs loaded for " + com.metaio.tools.SystemInfo.getDeviceABI() + " using " + com.metaio.sdk.jni.SystemInfo.getAvailableCPUCores() + " CPU cores");
  }

  public void onConfigurationChanged(Configuration paramConfiguration)
  {
    UiUtil.applyLocaleString(this, false);
    super.onConfigurationChanged(paramConfiguration);
    ESCREEN_ROTATION localESCREEN_ROTATION = Screen.getRotation(this);
    this.metaioSDK.setScreenRotation(localESCREEN_ROTATION);
    MetaioDebug.log("onConfigurationChanged: " + localESCREEN_ROTATION);
  }

  @SuppressLint({"InlinedApi", "NewApi"})
  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    getWindow().addFlags(128);
    MetaioDebug.log("ARViewActivity.onCreate");
    this.metaioSDK = null;
    this.mSurfaceView = null;
    this.mRendererInitialized = false;
    do
    {
      try
      {
        loadNativeLibs();
        this.metaioSDK = MetaioSDK.CreateMetaioSDKAndroid(this, getResources().getString(2131165796));
        if (this.metaioSDK == null)
          throw new Exception("Unsupported platform!");
      }
      catch (Exception localException)
      {
        MetaioDebug.log(6, "ARViewActivity.onCreate: failed to create or intialize Metaio SDK: " + localException.getMessage());
        finish();
        return;
      }
      this.mSensors = new SensorsComponentAndroid(getApplicationContext());
      this.metaioSDK.registerSensorsComponent(this.mSensors);
      int i = getGUILayout();
      if (i != 0)
      {
        this.mGUIView = View.inflate(this, i, null);
        if (this.mGUIView == null)
          MetaioDebug.log(6, "ARViewActivity: error inflating the given layout: " + i);
      }
    }
    while (Build.VERSION.SDK_INT < 17);
    this.mOrientationEventListener = new OrientationEventListener(this, 3)
    {
      public void onOrientationChanged(int paramAnonymousInt)
      {
        if (ARViewActivity.this.metaioSDK != null)
        {
          ESCREEN_ROTATION localESCREEN_ROTATION = Screen.getRotation(ARViewActivity.this);
          ARViewActivity.this.metaioSDK.setScreenRotation(localESCREEN_ROTATION);
        }
      }
    };
    if (this.mOrientationEventListener.canDetectOrientation())
    {
      this.mOrientationEventListener.enable();
      return;
    }
    this.mOrientationEventListener.disable();
  }

  protected void onDestroy()
  {
    super.onDestroy();
    MetaioDebug.log("ARViewActivity.onDestroy");
    if (this.mOrientationEventListener != null)
      this.mOrientationEventListener.disable();
    if (this.metaioSDK != null)
    {
      this.metaioSDK.delete();
      this.metaioSDK = null;
    }
    MetaioDebug.log("ARViewActivity.onDestroy releasing sensors");
    if (this.mSensors != null)
    {
      this.mSensors.registerCallback(null);
      this.mSensors.release();
      this.mSensors.delete();
      this.mSensors = null;
    }
    ViewGroup localViewGroup = (ViewGroup)findViewById(16908290);
    Memory.unbindViews(localViewGroup);
    localViewGroup.removeAllViews();
    this.mSurfaceView = null;
    System.runFinalization();
    System.gc();
  }

  public void onDrawFrame()
  {
    try
    {
      this.metaioSDK.render();
      return;
    }
    catch (Exception localException)
    {
      MetaioDebug.log(6, "ARViewActivity.onDrawFrame: Rendering failed with error " + localException.getMessage());
    }
  }

  protected abstract void onGeometryTouched(IGeometry paramIGeometry);

  public void onLowMemory()
  {
    MetaioDebug.log(6, "Low memory");
    MetaioDebug.logMemory(getApplicationContext());
  }

  @SuppressLint({"InlinedApi", "NewApi"})
  protected void onPause()
  {
    super.onPause();
    MetaioDebug.log("ARViewActivity.onPause");
    if (this.mSurfaceView != null)
      this.mSurfaceView.onPause();
    this.mActivityIsPaused = true;
    this.metaioSDK.pause();
  }

  @SuppressLint({"InlinedApi", "NewApi"})
  protected void onResume()
  {
    super.onResume();
    MetaioDebug.log("ARViewActivity.onResume");
    this.metaioSDK.resume();
    this.mActivityIsPaused = false;
    if (this.mSurfaceView == null)
    {
      MetaioDebug.log("ARViewActivity.onResume: creating new MetaioSurfaceView");
      this.mSurfaceView = new MetaioSurfaceView(this);
      this.mSurfaceView.registerCallback(this);
      this.mSurfaceView.setKeepScreenOn(true);
      this.mSurfaceView.setOnTouchListener(this);
      if (Build.VERSION.SDK_INT >= 11)
        this.mSurfaceView.setPreserveEGLContextOnPause(true);
    }
    if (this.mSurfaceView.getParent() == null)
    {
      MetaioDebug.log("ARViewActivity.onResume: addContentView(mSurfaceView)");
      FrameLayout.LayoutParams localLayoutParams = new FrameLayout.LayoutParams(-1, -1);
      addContentView(this.mSurfaceView, localLayoutParams);
      this.mSurfaceView.setZOrderMediaOverlay(true);
      if (this.mGUIView != null)
      {
        if (this.mGUIView.getParent() == null)
        {
          MetaioDebug.log("ARViewActivity.onResume: addContentView(mGUIView)");
          addContentView(this.mGUIView, new ViewGroup.LayoutParams(-1, -1));
        }
        this.mGUIView.bringToFront();
      }
    }
    this.mSurfaceView.onResume();
  }

  protected void onStart()
  {
    super.onStart();
    MetaioDebug.log("ARViewActivity.onStart");
    try
    {
      setContentView(new FrameLayout(this));
      if (!this.mActivityIsPaused)
        startCamera();
      return;
    }
    catch (Exception localException)
    {
      MetaioDebug.log(6, "Error creating views: " + localException.getMessage());
      MetaioDebug.printStackTrace(6, localException);
    }
  }

  protected void onStop()
  {
    super.onStop();
    MetaioDebug.log("ARViewActivity.onStop");
  }

  public void onSurfaceChanged(int paramInt1, int paramInt2)
  {
    MetaioDebug.log("ARViewActivity.onSurfaceChanged: " + paramInt1 + ", " + paramInt2);
    this.metaioSDK.resizeRenderer(paramInt1, paramInt2);
  }

  public void onSurfaceCreated()
  {
    MetaioDebug.log("ARViewActivity.onSurfaceCreated: " + this.mSurfaceView);
    MetaioDebug.log("ARViewActivity.onSurfaceCreated: GL thread: " + Thread.currentThread().getId());
    try
    {
      if (!this.mRendererInitialized)
      {
        MetaioDebug.log("ARViewActivity.onSurfaceCreated: initializing renderer...");
        ESCREEN_ROTATION localESCREEN_ROTATION = Screen.getRotation(this);
        this.metaioSDK.setScreenRotation(localESCREEN_ROTATION);
        this.metaioSDK.initializeRenderer(this.mSurfaceView.getWidth(), this.mSurfaceView.getHeight(), localESCREEN_ROTATION, ERENDER_SYSTEM.ERENDER_SYSTEM_OPENGL_ES_2_0);
        this.mRendererInitialized = true;
        IMetaioSDKCallback localIMetaioSDKCallback = getMetaioSDKCallbackHandler();
        if (localIMetaioSDKCallback != null)
          this.metaioSDK.registerCallback(localIMetaioSDKCallback);
        this.mSurfaceView.queueEvent(new Runnable()
        {
          public void run()
          {
            ARViewActivity.this.loadContents();
          }
        });
        return;
      }
      MetaioDebug.log("ARViewActivity.onSurfaceCreated: Reloading OpenGL resources...");
      this.metaioSDK.reloadOpenGLResources();
      return;
    }
    catch (Exception localException)
    {
      MetaioDebug.log(6, "ARViewActivity.onSurfaceCreated: " + localException.getMessage());
    }
  }

  public void onSurfaceDestroyed()
  {
    MetaioDebug.log("ARViewActivity.onSurfaceDestroyed: " + this.mSurfaceView);
    this.mSurfaceView = null;
  }

  public boolean onTouch(View paramView, MotionEvent paramMotionEvent)
  {
    if (paramMotionEvent.getAction() == 1)
      MetaioDebug.log("ARViewActivity touched at: " + paramMotionEvent.toString());
    try
    {
      int i = (int)paramMotionEvent.getX();
      int j = (int)paramMotionEvent.getY();
      IGeometry localIGeometry = this.metaioSDK.getGeometryFromViewportCoordinates(i, j, true);
      if (localIGeometry != null)
      {
        MetaioDebug.log("ARViewActivity geometry found: " + localIGeometry);
        onGeometryTouched(localIGeometry);
      }
      return true;
    }
    catch (Exception localException)
    {
      MetaioDebug.log(6, "onTouch: " + localException.getMessage());
      MetaioDebug.printStackTrace(6, localException);
    }
    return true;
  }

  protected void startCamera()
  {
    this.metaioSDK.startCamera(Camera.FACE_BACK);
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.ikea.kompis.scan.ARViewActivity
 * JD-Core Version:    0.6.2
 */