package com.metaio.cloud.plugin.view;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.location.Location;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Looper;
import android.support.v4.content.LocalBroadcastManager;
import android.view.OrientationEventListener;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.RelativeLayout.LayoutParams;
import com.metaio.cloud.plugin.MetaioCloudPlugin;
import com.metaio.cloud.plugin.MetaioCloudPlugin.Settings;
import com.metaio.cloud.plugin.data.MetaioCloudDataManager;
import com.metaio.cloud.plugin.data.MetaioCloudDataManager.Callback;
import com.metaio.cloud.plugin.data.RemoteAssetsManager;
import com.metaio.cloud.plugin.util.MetaioCloudUtils;
import com.metaio.sdk.GestureHandlerAndroid;
import com.metaio.sdk.MetaioDebug;
import com.metaio.sdk.MetaioSurfaceView;
import com.metaio.sdk.MetaioSurfaceView.Callback;
import com.metaio.sdk.MetaioWorldPOIManagerCallback;
import com.metaio.sdk.SensorsComponentAndroid;
import com.metaio.sdk.SensorsComponentAndroid.Callback;
import com.metaio.sdk.jni.ARELSceneOptionVector;
import com.metaio.sdk.jni.ASWorldReturnCode;
import com.metaio.sdk.jni.AS_MetaioWorldRequestCommand;
import com.metaio.sdk.jni.BoundingBox;
import com.metaio.sdk.jni.ByteBuffer;
import com.metaio.sdk.jni.Camera;
import com.metaio.sdk.jni.CameraVector;
import com.metaio.sdk.jni.DataSourceEvent;
import com.metaio.sdk.jni.EENV_MAP_FORMAT;
import com.metaio.sdk.jni.ERENDER_SYSTEM;
import com.metaio.sdk.jni.ESCREEN_ROTATION;
import com.metaio.sdk.jni.IARELDatasourceDelegate;
import com.metaio.sdk.jni.IARELObject;
import com.metaio.sdk.jni.IARELObjectVector;
import com.metaio.sdk.jni.IGeometry;
import com.metaio.sdk.jni.IMetaioSDKAndroid;
import com.metaio.sdk.jni.IMetaioWorldPOIManager;
import com.metaio.sdk.jni.ISensorsComponent;
import com.metaio.sdk.jni.JunaioDataSource;
import com.metaio.sdk.jni.LLACoordinate;
import com.metaio.sdk.jni.MetaioSDK;
import com.metaio.sdk.jni.MetaioWorldChannel;
import com.metaio.sdk.jni.MetaioWorldChannelVector;
import com.metaio.sdk.jni.MetaioWorldRequest;
import com.metaio.sdk.jni.PathOrURL;
import com.metaio.sdk.jni.Vector2d;
import com.metaio.sdk.jni.Vector2di;
import com.metaio.sdk.jni.Vector3d;
import com.metaio.tools.Screen;
import com.metaio.tools.SystemInfo;
import com.metaio.tools.io.AssetsManager;
import java.io.File;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Semaphore;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class ARMetaioCloudPluginManager
  implements MetaioSurfaceView.Callback, MetaioCloudDataManager.Callback, SensorsComponentAndroid.Callback
{
  public static final int MESSAGE_AREL_COMPLETE = 1;
  public static final int MESSAGE_PROCESS_URL = 0;
  public static final String NOTIFICATION_SOUND = "NOTIFICATION";
  public static final int REQUEST_ADD_CALENDAR_EVENT = 1006;
  public static final int REQUEST_CHANNEL_FILTER = 1000;
  public static final int REQUEST_CHANNEL_FILTER_URL = 1001;
  public static final int REQUEST_POI_CONTEXT = 1002;
  public static final int REQUEST_VIDEO_PLAY = 1005;
  public static final int REQUEST_VISUAL_SEARCH = 1003;
  public static final int REQUEST_WEBSITE = 1004;
  public static LLACoordinate mLastSearchedLLA;
  public static boolean mShowChannelFilter;
  private final BroadcastReceiver POIManagerBroadcastReceiver = new BroadcastReceiver()
  {
    public void onReceive(Context paramAnonymousContext, Intent paramAnonymousIntent)
    {
      String str = paramAnonymousIntent.getStringExtra("url");
      if (str != null)
      {
        ARMetaioCloudPluginManager.this.mLockDataSource.lock();
        ARMetaioCloudPluginManager.this.mPOIManager.processURL(str);
        ARMetaioCloudPluginManager.this.mLockDataSource.unlock();
      }
    }
  };
  private final BroadcastReceiver clearCacheBroadcastReceiver = new BroadcastReceiver()
  {
    public void onReceive(Context paramAnonymousContext, Intent paramAnonymousIntent)
    {
      try
      {
        ARMetaioCloudPluginManager.this.mWebview.clearCache(true);
        MetaioCloudPlugin.log("AREL webview cache cleared");
        return;
      }
      catch (Exception localException)
      {
        MetaioCloudPlugin.log("Error clearing AREL webview cache");
      }
    }
  };
  private MetaioWorldChannel mChannel;
  public boolean mChannelFinishedLoading;
  private final Activity mContext;
  private ARELDatasourceCallback mDatasourceCallback;
  private GestureHandlerAndroid mGestureHandlerAndroid;
  public boolean mInvalidateAll;
  public boolean mInvalidated;
  public boolean mIsInLiveMode = true;
  private Camera mLastCameraConfig;
  public Lock mLockDataSource;
  public MetaioSurfaceView mMetaioSurfaceView;
  private MetaioWorldPOIManagerCallback mMetaioWorldPOIManagerCallback;
  private OrientationListener mOrientationListener;
  public boolean mPOIDetailOpenedState;
  private IMetaioWorldPOIManager mPOIManager;
  public int mPedingChannelLoad;
  public boolean mRendererInitialized;
  boolean mScanModeEnabled;
  public boolean mStereoRenderingEnabled = false;
  public boolean mVisualSearchRequestRunning;
  public WebView mWebview;
  private IMetaioSDKAndroid metaioSDK;

  public ARMetaioCloudPluginManager(Activity paramActivity)
  {
    this.mContext = paramActivity;
  }

  private void createAllViews()
  {
    this.mMetaioSurfaceView = null;
    this.mContext.setContentView(new FrameLayout(this.mContext));
    initMetaioSDK();
  }

  @TargetApi(11)
  private void initMetaioSDK()
  {
    startCamera(null);
    if (this.mMetaioSurfaceView != null)
    {
      ((ViewGroup)this.mMetaioSurfaceView.getParent()).removeView(this.mMetaioSurfaceView);
      this.mMetaioSurfaceView = null;
    }
    this.mMetaioSurfaceView = new MetaioSurfaceView(this.mContext);
    this.mMetaioSurfaceView.registerCallback(this);
    this.mMetaioSurfaceView.setKeepScreenOn(true);
    if (Build.VERSION.SDK_INT >= 11)
      this.mMetaioSurfaceView.setLayerType(1, null);
    FrameLayout.LayoutParams localLayoutParams = new FrameLayout.LayoutParams(-1, -1);
    MetaioCloudPlugin.log("ARMetaioCloudPluginManager.addContentView(mMetaioSurfaceView) layout: " + localLayoutParams.width + ", " + localLayoutParams.height);
    this.mContext.addContentView(this.mMetaioSurfaceView, localLayoutParams);
    this.mMetaioSurfaceView.setZOrderMediaOverlay(true);
    int[] arrayOfInt = new int[2];
    this.mMetaioSurfaceView.getLocationInWindow(arrayOfInt);
    MetaioDebug.log("mMetaioSurfaceView.getLocationOnWindow " + arrayOfInt[0] + "," + arrayOfInt[1]);
  }

  private void setScreenRotation(final ESCREEN_ROTATION paramESCREEN_ROTATION)
  {
    if (Looper.getMainLooper().getThread() == Thread.currentThread())
      if (this.mPOIManager != null)
        this.mPOIManager.setScreenRotation(paramESCREEN_ROTATION);
    while (this.mMetaioSurfaceView == null)
      return;
    this.mMetaioSurfaceView.post(new Runnable()
    {
      public void run()
      {
        if (ARMetaioCloudPluginManager.this.mPOIManager != null)
        {
          if ((Build.BRAND.equalsIgnoreCase("moverio")) && (Build.PRODUCT.contains("EPSON_embt2")))
            ARMetaioCloudPluginManager.this.mPOIManager.setScreenRotation(ESCREEN_ROTATION.ESCREEN_ROTATION_0);
        }
        else
          return;
        ARMetaioCloudPluginManager.this.mPOIManager.setScreenRotation(paramESCREEN_ROTATION);
      }
    });
  }

  private void startCamera(Camera paramCamera)
  {
    int i = 0;
    CameraVector localCameraVector;
    if (this.metaioSDK != null)
    {
      localCameraVector = this.metaioSDK.getCameraList();
      if (localCameraVector.size() > 0L)
        if ((paramCamera == null) || (this.mScanModeEnabled))
          break label98;
    }
    label141: 
    while (true)
    {
      if (MetaioCloudPlugin.Settings.cameraWidth > -1)
        paramCamera.setResolution(new Vector2di(MetaioCloudPlugin.Settings.cameraWidth, MetaioCloudPlugin.Settings.cameraHeight));
      MetaioCloudPlugin.log(4, "Starting Camera " + paramCamera.getFriendlyName());
      this.metaioSDK.startCamera(paramCamera);
      return;
      label98: paramCamera = localCameraVector.get(0);
      while (true)
      {
        if (i >= localCameraVector.size())
          break label141;
        if (localCameraVector.get(i).getFacing() == Camera.FACE_BACK)
        {
          paramCamera = localCameraVector.get(i);
          break;
        }
        i++;
      }
    }
  }

  public MetaioWorldChannel getChannel()
  {
    return this.mChannel;
  }

  public GestureHandlerAndroid getGestureHandler()
  {
    return this.mGestureHandlerAndroid;
  }

  public MetaioWorldPOIManagerCallback getMetaioWorldPOIManagerCallback()
  {
    return new MetaioWorldPOIManagerCallback(this.mContext);
  }

  public BoundingBox getRadarBoundingBox()
  {
    return this.mPOIManager.getRadarBoundingBox();
  }

  public float getRotationOffset()
  {
    int i = 7.$SwitchMap$com$metaio$sdk$jni$ESCREEN_ROTATION[this.metaioSDK.getScreenRotation().ordinal()];
    float f = 0.0F;
    switch (i)
    {
    default:
    case 1:
    case 2:
    case 3:
    }
    while (true)
    {
      if (SystemInfo.getDeviceDefaultOrientation(this.mContext.getApplicationContext()) == 2)
        f -= 90.0F;
      return f;
      f = 90.0F;
      continue;
      f = 180.0F;
      continue;
      f = -90.0F;
    }
  }

  public final WebView initARELWebView(ViewGroup paramViewGroup)
  {
    this.mWebview = new WebView(this.mContext);
    this.mMetaioWorldPOIManagerCallback.initWebView(this.mWebview);
    if (paramViewGroup != null)
    {
      RelativeLayout.LayoutParams localLayoutParams1 = new RelativeLayout.LayoutParams(-1, -1);
      this.mWebview.setLayoutParams(localLayoutParams1);
      paramViewGroup.addView(this.mWebview, 0);
    }
    while (true)
    {
      return this.mWebview;
      RelativeLayout.LayoutParams localLayoutParams2 = new RelativeLayout.LayoutParams(-1, -1);
      this.mContext.addContentView(this.mWebview, localLayoutParams2);
    }
  }

  public void invalidateAll()
  {
    this.mInvalidateAll = true;
  }

  public boolean isSomethingAt(float paramFloat1, float paramFloat2)
  {
    return this.metaioSDK.getGeometryFromViewportCoordinates((int)paramFloat1, (int)paramFloat2) != null;
  }

  public void onActivityConfigurationChanged(Configuration paramConfiguration)
  {
    MetaioCloudPlugin.log("Lifecycle", "onConfigurationChanged: " + paramConfiguration.toString());
    setScreenRotation(Screen.getRotation(this.mContext));
  }

  public void onActivityCreated()
  {
    try
    {
      IMetaioSDKAndroid.loadNativeLibs();
      this.mInvalidated = false;
      this.mLockDataSource = new ReentrantLock();
      MetaioCloudPlugin.log("Lifecycle", getClass().getSimpleName() + ".onActivityCreated");
    }
    catch (Exception localException1)
    {
      try
      {
        this.mChannel = null;
        this.metaioSDK = null;
        this.mRendererInitialized = false;
        this.mChannelFinishedLoading = false;
        this.mGestureHandlerAndroid = null;
        this.mOrientationListener = new OrientationListener(this.mContext);
        this.mDatasourceCallback = new ARELDatasourceCallback();
        this.mPOIManager = null;
        this.mPOIDetailOpenedState = false;
        this.mScanModeEnabled = false;
        this.mPedingChannelLoad = -1;
        Vector2d localVector2d = new Vector2d();
        MetaioCloudPlugin.getSensorsManager(this.mContext.getApplicationContext());
        MetaioCloudPlugin.getSensorsManager(this.mContext.getApplicationContext()).registerCallback(this);
        MetaioDebug.logPrivate(3, "Creating Metaio SDK instance...");
        this.mMetaioWorldPOIManagerCallback = getMetaioWorldPOIManagerCallback();
        this.mPOIManager = MetaioSDK.CreateMetaioWorldPOIManager(this.mMetaioWorldPOIManagerCallback, this.mDatasourceCallback, MetaioCloudPlugin.getDataSource(), MetaioCloudPlugin.getSensorsManager(this.mContext), localVector2d, Screen.getRotation(this.mContext), this.mContext);
        this.metaioSDK = this.mPOIManager.getMetaioSDKAndroidInstance();
        this.mMetaioWorldPOIManagerCallback.setPOIManager(this.mPOIManager);
        localVector2d.delete();
        IntentFilter localIntentFilter1 = new IntentFilter(this.mContext.getPackageName() + ".PROCESSURL");
        LocalBroadcastManager.getInstance(this.mContext).registerReceiver(this.POIManagerBroadcastReceiver, localIntentFilter1);
        IntentFilter localIntentFilter2 = new IntentFilter(this.mContext.getPackageName() + ".CLEAR_AREL_CACHE");
        LocalBroadcastManager.getInstance(this.mContext).registerReceiver(this.clearCacheBroadcastReceiver, localIntentFilter2);
        return;
        localException1 = localException1;
        MetaioDebug.log(6, "Could't load the essential MetaioSDK native libraries");
      }
      catch (Exception localException2)
      {
        MetaioDebug.log(6, "Failed to create ARMetaioCloudPluginManager." + localException2.getMessage());
        MetaioDebug.printStackTrace(6, localException2);
        this.mPOIManager = null;
        this.metaioSDK = null;
        this.mContext.finish();
      }
    }
  }

  public void onActivityDestroyed()
  {
    MetaioCloudPlugin.log("Lifecycle", getClass().getSimpleName() + ".onActivityDestroyed");
    try
    {
      this.mRendererInitialized = false;
      this.mMetaioWorldPOIManagerCallback.onActivityDestroy();
      if (this.metaioSDK != null)
      {
        this.metaioSDK.delete();
        this.metaioSDK = null;
      }
      if (this.mLastCameraConfig != null)
      {
        this.mLastCameraConfig.delete();
        this.mLastCameraConfig = null;
      }
      LocalBroadcastManager.getInstance(this.mContext).unregisterReceiver(this.POIManagerBroadcastReceiver);
      LocalBroadcastManager.getInstance(this.mContext).unregisterReceiver(this.clearCacheBroadcastReceiver);
      if (this.mPOIManager != null)
      {
        MetaioCloudPlugin.log("Deleting POI Manager");
        this.mPOIManager.delete();
        this.mPOIManager = null;
      }
      MetaioCloudPlugin.releaseDataSource();
      if (this.mDatasourceCallback != null)
      {
        MetaioCloudPlugin.log("Deleting ARELDatasourceCallback");
        this.mDatasourceCallback.delete();
        this.mDatasourceCallback = null;
      }
      if (this.mMetaioWorldPOIManagerCallback != null)
      {
        MetaioCloudPlugin.log("Deleting MetaioWorldPOIManagerCallback");
        this.mMetaioWorldPOIManagerCallback.delete();
        this.mMetaioWorldPOIManagerCallback = null;
      }
      if (this.mGestureHandlerAndroid != null)
      {
        this.mGestureHandlerAndroid.delete();
        this.mGestureHandlerAndroid = null;
      }
      MetaioCloudPlugin.releaseSensorsManager();
      this.mOrientationListener = null;
      return;
    }
    catch (Exception localException)
    {
      MetaioCloudPlugin.log(6, "Error cleaning ARMetaioCloudPluginManager: " + localException.getMessage());
      MetaioDebug.printStackTrace(6, localException);
    }
  }

  @TargetApi(11)
  public void onActivityPaused()
  {
    MetaioCloudPlugin.log("Lifecycle", getClass().getSimpleName() + ".onActivityPaused");
    try
    {
      if (this.mMetaioSurfaceView != null)
      {
        MetaioCloudPlugin.log("Lifecycle", "ARMetaioCloudPluginManager.onPause: pausing MetaioSurfaceView");
        this.mMetaioSurfaceView.onPause();
      }
      this.mLastCameraConfig = this.metaioSDK.getCamera();
      MetaioCloudPlugin.log("Lifecycle", "ARMetaioCloudPluginManager.onPause: stopping camera");
      this.metaioSDK.stopCamera();
      this.mMetaioWorldPOIManagerCallback.onActivityPause();
      this.mLockDataSource.lock();
      MetaioCloudPlugin.getDataSource().cancelAllRequests();
      this.mLockDataSource.unlock();
      MetaioCloudPlugin.getSensorsManager(this.mContext.getApplicationContext()).pause();
      this.mWebview.onPause();
      return;
    }
    catch (Exception localException)
    {
      while (true)
        MetaioCloudPlugin.log(6, "Lifecycle", "ARMetaioCloudPluginManager.onPause: " + localException.getMessage());
    }
  }

  public void onActivityRestarted()
  {
    MetaioCloudPlugin.log("Lifecycle", getClass().getSimpleName() + ".onActivityRestarted");
    MetaioCloudPlugin.getDataManager().registerCallback(this);
    if (this.mChannel == null);
    while (this.mChannelFinishedLoading)
      return;
    reloadPOIs();
  }

  public void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
  {
    MetaioCloudPlugin.log("Lifecycle", "ARMetaioCloudPluginManager.onActivityResult: " + paramInt1 + ", " + paramInt2);
    this.mMetaioWorldPOIManagerCallback.onActivityResult(paramInt1, paramInt2, paramIntent);
  }

  @TargetApi(11)
  public void onActivityResumed()
  {
    MetaioCloudPlugin.log("Lifecycle", getClass().getSimpleName() + ".onActivityResumed");
    this.mVisualSearchRequestRunning = false;
    MetaioCloudPlugin.getSensorsManager(this.mContext.getApplicationContext()).resume();
    while (true)
    {
      try
      {
        if (this.mMetaioSurfaceView != null)
        {
          if (this.mIsInLiveMode)
          {
            MetaioCloudPlugin.log("Lifecycle", "ARMetaioCloudPluginManager.onResume: resuming MetaioSurfaceView");
            this.mMetaioSurfaceView.onResume();
            StringBuilder localStringBuilder = new StringBuilder().append("ARMetaioCloudPluginManager.onResume: starting camera ");
            Camera localCamera = this.mLastCameraConfig;
            boolean bool = false;
            if (localCamera != null)
              bool = true;
            MetaioCloudPlugin.log("Lifecycle", bool);
            startCamera(this.mLastCameraConfig);
            this.mWebview.onResume();
            this.mMetaioWorldPOIManagerCallback.onActivityResume();
            return;
          }
          MetaioCloudPlugin.log("Lifecycle", "ARMetaioCloudPluginManager.onResume: NOT resuming MetaioSurfaceView because is not visible");
          continue;
        }
      }
      catch (Exception localException)
      {
        MetaioCloudPlugin.log(6, "ARMetaioCloudPluginManager.onResume(): " + localException.getMessage());
        return;
      }
      MetaioCloudPlugin.log(6, "Lifecycle", "Recovering views. This should not happen");
      createAllViews();
    }
  }

  public void onActivityStarted()
  {
    MetaioCloudPlugin.log("Lifecycle", getClass().getSimpleName() + ".onActivityStarted");
    MetaioCloudPlugin.log("Was showing a POI detail? " + this.mPOIDetailOpenedState);
    MetaioCloudPlugin.getSensorsManager(this.mContext.getApplicationContext()).registerCallback(this);
    this.mOrientationListener.enable();
    createAllViews();
  }

  public void onActivityStopped()
  {
    MetaioCloudPlugin.log("Lifecycle", getClass().getSimpleName() + ".onActivityStopped");
    MetaioCloudPlugin.getDataManager().registerCallback(null);
    this.mOrientationListener.disable();
    this.mPOIManager.stopAllMovieTextures();
    if (this.mMetaioSurfaceView != null)
    {
      this.mMetaioSurfaceView.registerCallback(null);
      ((ViewGroup)this.mMetaioSurfaceView.getParent()).removeView(this.mMetaioSurfaceView);
      this.mMetaioSurfaceView = null;
    }
    if (this.metaioSDK != null)
      this.metaioSDK.stopCamera();
    if (MetaioCloudPlugin.isDebuggable)
      MetaioDebug.logMemory(this.mContext.getApplicationContext());
  }

  public void onChannelWillChange(long paramLong)
  {
    MetaioCloudPlugin.log(4, "onChannelWillChange");
    File localFile = AssetsManager.getAssetPathAsFile(this.mContext.getApplicationContext(), "junaio/env_map.png");
    if (localFile != null)
    {
      MetaioCloudPlugin.log("Loading environment map: " + localFile);
      boolean bool = this.metaioSDK.loadEnvironmentMap(localFile, EENV_MAP_FORMAT.EEMF_LATLONG);
      MetaioCloudPlugin.log("Environment map loaded: " + bool);
    }
    while (true)
    {
      if (this.mLastCameraConfig != null)
      {
        this.mLastCameraConfig.delete();
        this.mLastCameraConfig = null;
      }
      this.mPedingChannelLoad = ((int)paramLong);
      this.mMetaioWorldPOIManagerCallback.releaseMediaPlayers();
      this.mMetaioWorldPOIManagerCallback.stopSound(null, null, null, false);
      return;
      MetaioCloudPlugin.log(5, "Environment map not found in the application assets");
    }
  }

  public void onCodeDetected(String paramString1, String paramString2)
  {
    MetaioCloudPlugin.log("onCodeDetected " + paramString1 + " " + paramString2);
  }

  public void onDrawFrame()
  {
    this.mLockDataSource.lock();
    if (this.mRendererInitialized)
      this.mPOIManager.onDrawFrame();
    this.mLockDataSource.unlock();
  }

  public void onGravitySensorChanged(float[] paramArrayOfFloat)
  {
  }

  public void onHeadingSensorChanged(float[] paramArrayOfFloat)
  {
  }

  public void onLocationSensorChanged(LLACoordinate paramLLACoordinate)
  {
    MetaioCloudPlugin.log("Metaio Sensors", "MetaioCloudViewActivity.onLocationSensorChanged: " + paramLLACoordinate);
    if (this.mChannel == null);
    while (true)
    {
      return;
      try
      {
        if ((this.mChannel.getLla()) || (this.mChannel.getGlue()) || (this.mChannel.getVisualSearch()))
        {
          MetaioCloudPlugin.log(5, "Metaio Sensors", "MetaioCloudViewActivity.onLocationSensorChanged: channel is LLA, Glue or Visual Search or refresh disabled ");
          return;
        }
      }
      catch (Exception localException)
      {
        MetaioCloudPlugin.log(6, "Metaio Sensors", "onLocationChanged: " + localException.getMessage());
        return;
      }
      int i;
      if (mLastSearchedLLA != null)
      {
        float[] arrayOfFloat = new float[3];
        Location.distanceBetween(mLastSearchedLLA.getLatitude(), mLastSearchedLLA.getLongitude(), paramLLACoordinate.getLatitude(), paramLLACoordinate.getLongitude(), arrayOfFloat);
        MetaioCloudPlugin.log("Metaio Sensors", "onLocationSensorChanged: Relative distance between previous and current location is " + arrayOfFloat[0]);
        if (arrayOfFloat[0] > 100.0F)
        {
          MetaioCloudPlugin.log("Metaio Sensors", "onLocationSensorChanged: Relative distance between previous and current location is " + arrayOfFloat[0]);
          i = 1;
        }
      }
      while (i != 0)
      {
        MetaioCloudPlugin.log("Metaio Sensors", "Updating POIs based on location update...");
        reloadPOIs();
        return;
        if (this.mChannel.getLla())
        {
          if (MetaioCloudPlugin.getDataSource().getAllPOIsForMapAndList().size() == 0L)
            i = 1;
          else
            invalidateAll();
        }
        else
          i = 0;
      }
    }
  }

  public void onObjectAdded(IARELObject paramIARELObject)
  {
    try
    {
      paramIARELObject.delete();
      return;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  public void onObjectRemoved(IARELObject paramIARELObject)
  {
    try
    {
      paramIARELObject.delete();
      return;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  public void onRemoveContent()
  {
  }

  public void onRequestCancelled(MetaioWorldRequest paramMetaioWorldRequest)
  {
    if (paramMetaioWorldRequest != null)
    {
      MetaioCloudPlugin.log("Metaio Data", "MetaioCloudViewActivity onRequestCancelled :" + paramMetaioWorldRequest.getCommand());
      this.mLockDataSource.lock();
      switch (7.$SwitchMap$com$metaio$sdk$jni$AS_MetaioWorldRequestCommand[paramMetaioWorldRequest.getCommand().ordinal()])
      {
      case 5:
      default:
      case 1:
      case 2:
      case 3:
      case 4:
      case 6:
      }
    }
    while (true)
    {
      this.mLockDataSource.unlock();
      return;
      if (paramMetaioWorldRequest.getTag() <= 0)
        MetaioCloudPlugin.getDataSource().onMetaioWorldRequestFinished(ASWorldReturnCode.AS_WORLD_API_REQUESTCANCELED.swigValue(), paramMetaioWorldRequest);
    }
  }

  public void onRequestCompleted(MetaioWorldRequest paramMetaioWorldRequest, int paramInt)
  {
    MetaioCloudPlugin.log("Metaio Data", "ARMetaioCloudPluginManager onRequestCompleted :" + paramMetaioWorldRequest.getCommand());
    String str;
    if ((paramMetaioWorldRequest.getCommand() == AS_MetaioWorldRequestCommand.AS_MetaioWorldRequestType_POI_VISUAL_SEARCH) || (paramMetaioWorldRequest.getCommand() == AS_MetaioWorldRequestCommand.AS_MetaioWorldRequestType_CHANNELS_VISUAL_SEARCH))
    {
      this.mVisualSearchRequestRunning = false;
      if (paramInt != ASWorldReturnCode.AS_WORLD_API_SUCCESS.swigValue())
      {
        MetaioCloudPlugin.log("Request completed with error: " + paramInt);
        str = MetaioCloudPlugin.getDataManager().getLastNetworkErrorMessage(this.mContext.getApplicationContext());
        if (paramInt != ASWorldReturnCode.AS_WORLD_API_USER_AGENT_NOT_REGISTERED.swigValue())
          break label232;
        showAlert("This application " + this.mContext.getPackageName() + " has not been registered yet. You can register for free at http://dev.metaio.com/login");
      }
      label147: this.mLockDataSource.lock();
      switch (7.$SwitchMap$com$metaio$sdk$jni$AS_MetaioWorldRequestCommand[paramMetaioWorldRequest.getCommand().ordinal()])
      {
      default:
      case 1:
      case 2:
      case 3:
      case 4:
      case 5:
      case 6:
      }
    }
    while (true)
    {
      this.mLockDataSource.unlock();
      return;
      if (paramMetaioWorldRequest.getCommand() != AS_MetaioWorldRequestCommand.AS_MetaioWorldRequestType_CHANNELS_MANAGE_GET)
        break;
      this.mChannelFinishedLoading = false;
      break;
      label232: showToast(str);
      break label147;
      if (paramMetaioWorldRequest.getTag() <= 0)
        MetaioCloudPlugin.getDataSource().onMetaioWorldRequestFinished(paramInt, paramMetaioWorldRequest);
    }
  }

  public void onRequestStarted()
  {
    MetaioCloudPlugin.log("Metaio Data", "ARMetaioCloudPluginManager onRequestStarted");
  }

  public void onSceneReady()
  {
    MetaioCloudPlugin.log("onSceneReady");
    MetaioCloudPlugin.getRemoteAssetsManager(this.mContext.getApplicationContext()).saveHashMaps();
  }

  public void onServerEvent(DataSourceEvent paramDataSourceEvent)
  {
  }

  public void onSurfaceChanged(int paramInt1, int paramInt2)
  {
    MetaioCloudPlugin.log("Metaio Surface", getClass().getSimpleName() + ".onSurfaceChanged");
    if ((this.mPOIManager == null) || (this.metaioSDK == null))
    {
      MetaioCloudPlugin.log(5, "Metaio Surface", "ARMetaioCloudPluginManager.onSurfaceChanged mPOIManager: " + this.mPOIManager + ", mUnifeyeMobile: " + this.metaioSDK);
      return;
    }
    MetaioDebug.log("ARMetaioCloudPluginManager.onSurfaceChanged: " + paramInt1 + ", " + paramInt2);
    this.metaioSDK.resizeRenderer(paramInt1, paramInt2);
    setRadarProperties(IGeometry.ANCHOR_TR, new Vector3d(0.0F, 0.0F, 0.0F), new Vector3d(1.0F, 1.0F, 1.0F));
  }

  public void onSurfaceCreated()
  {
    MetaioCloudPlugin.log("Metaio Surface", "ARMetaioCloudPluginManager.onSurfaceCreated");
    try
    {
      if (!this.mRendererInitialized)
      {
        this.mRendererInitialized = this.mPOIManager.initializeRenderer(this.mMetaioSurfaceView.getWidth(), this.mMetaioSurfaceView.getHeight(), Screen.getRotation(this.mContext), ERENDER_SYSTEM.ERENDER_SYSTEM_OPENGL_ES_2_0);
        this.mGestureHandlerAndroid = new GestureHandlerAndroid(this.metaioSDK, GestureHandlerAndroid.GESTURE_ALL, this.mWebview, this.mMetaioSurfaceView);
        this.mPOIManager.setGestureHandler(this.mGestureHandlerAndroid);
        this.mWebview.setOnTouchListener(this.mGestureHandlerAndroid);
      }
      while (true)
      {
        if (this.mIsInLiveMode)
          this.mMetaioSurfaceView.onResume();
        MetaioDebug.log("ARMetaioCloudPluginManager.onSurfaceCreated");
        return;
        MetaioDebug.log("ARMetaioCloudPluginManager.onSurfaceCreated: Reloading OpenGL resources...");
        this.mGestureHandlerAndroid.setGLSurfaceView(this.mMetaioSurfaceView);
        this.metaioSDK.reloadOpenGLResources();
      }
    }
    catch (Exception localException)
    {
      MetaioDebug.log(6, "ARMetaioCloudPluginManager.onSurfaceCreated: " + localException.getMessage());
    }
  }

  public void onSurfaceDestroyed()
  {
    MetaioCloudPlugin.log("Metaio Surface", "ARMetaioCloudPluginManager.onSurfaceDestroyed");
    if (this.metaioSDK != null)
      this.mPOIManager.stopAllMovieTextures();
  }

  public void onVisualSearchDone(MetaioWorldChannelVector paramMetaioWorldChannelVector, ByteBuffer paramByteBuffer, boolean paramBoolean)
  {
    MetaioCloudPlugin.log("ARMetaioCloudPluginManager.onVisualSearchDone " + paramMetaioWorldChannelVector.size());
    this.mVisualSearchRequestRunning = false;
  }

  public void pickObject(IARELObject paramIARELObject, boolean paramBoolean)
  {
    this.mPOIManager.onObjectPicked(paramIARELObject, paramBoolean);
  }

  public void reloadPOIs()
  {
    this.mWebview.clearCache(true);
    this.mWebview.reload();
    if (this.mChannel == null)
    {
      MetaioCloudPlugin.log("reloadPOIs: Channel is null");
      return;
    }
    MetaioCloudPlugin.log("Reloading POIs");
    this.mLockDataSource.lock();
    MetaioCloudPlugin.getDataSource().removeContent();
    MetaioCloudPlugin.resetSensorsManager();
    mLastSearchedLLA = MetaioCloudPlugin.getSensorsManager(this.mContext).getLocation();
    MetaioCloudPlugin.log("Reloading POIs nearby: " + mLastSearchedLLA);
    if ((MetaioCloudPlugin.getDataSource().getCurrentChannelID() <= 0) && (this.mChannel != null))
      MetaioCloudPlugin.getDataSource().setChannel(this.mChannel);
    MetaioCloudPlugin.getDataSource().loadPOIsFromChannelID((int)this.mChannel.getChannelID());
    this.mLockDataSource.unlock();
  }

  @Deprecated
  public void searchPOIs()
  {
    reloadPOIs();
  }

  public void setChannel(int paramInt)
  {
    setChannel(paramInt, null);
  }

  public void setChannel(int paramInt, Map<String, String> paramMap)
  {
    MetaioCloudPlugin.log("setChannel (with filters)" + paramInt);
    this.mLockDataSource.lock();
    MetaioCloudPlugin.getDataSource().cancelAllRequests();
    MetaioCloudPlugin.getDataSource().clearAllFilterParameters();
    if (paramMap != null)
    {
      Iterator localIterator = paramMap.keySet().iterator();
      while (localIterator.hasNext())
      {
        String str = (String)localIterator.next();
        MetaioCloudPlugin.getDataSource().setFilterValue(str, (String)paramMap.get(str));
      }
    }
    MetaioCloudPlugin.getDataSource().loadPOIsAndChannelInformationForID(paramInt);
    this.mLockDataSource.unlock();
    this.mContext.runOnUiThread(new Runnable()
    {
      public void run()
      {
        ARMetaioCloudPluginManager.this.mWebview.loadUrl("about:blank");
      }
    });
  }

  public void setChannel(MetaioWorldChannel paramMetaioWorldChannel)
  {
    this.mChannel = paramMetaioWorldChannel;
  }

  public void setRadarProperties(int paramInt, Vector3d paramVector3d1, Vector3d paramVector3d2)
  {
    this.mPOIManager.setRadarProperties(paramInt, paramVector3d1, paramVector3d2);
  }

  public void setRadarRadius(float paramFloat)
  {
    if (this.mPOIManager != null)
      this.mPOIManager.setDistanceLimit(paramFloat);
  }

  public void setRadarViewVisibility(boolean paramBoolean)
  {
  }

  public void setSeeThrough(boolean paramBoolean)
  {
    this.metaioSDK.setSeeThrough(paramBoolean);
    this.metaioSDK.setSeeThroughColor(0L, 0L, 0L, 255L);
  }

  public void setStereoRendering(boolean paramBoolean)
  {
    this.mStereoRenderingEnabled = paramBoolean;
    this.metaioSDK.setStereoRendering(this.mStereoRenderingEnabled);
  }

  public void shareScreenshot(ByteBuffer paramByteBuffer, boolean paramBoolean)
  {
    this.mMetaioWorldPOIManagerCallback.shareScreenshot(paramByteBuffer, paramBoolean);
  }

  public void showAlert(String paramString)
  {
    AlertDialog.Builder localBuilder = new AlertDialog.Builder(this.mContext);
    localBuilder.setTitle(null).setMessage(paramString).setNegativeButton("Accept", new DialogInterface.OnClickListener()
    {
      public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
      {
        if (paramAnonymousDialogInterface != null)
          paramAnonymousDialogInterface.dismiss();
        ARMetaioCloudPluginManager.this.mContext.finish();
      }
    }).setPositiveButton("Save information", new DialogInterface.OnClickListener()
    {
      public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
      {
        Intent localIntent = new Intent("android.intent.action.SEND");
        localIntent.addCategory("android.intent.category.DEFAULT");
        localIntent.setType("text/plain");
        localIntent.putExtra("android.intent.extra.SUBJECT", "JunaioPlugin");
        localIntent.putExtra("android.intent.extra.TEXT", "You can register your application for free here: http://dev.metaio.com/login \n\n Your Application ID: " + ARMetaioCloudPluginManager.this.mContext.getPackageName());
        Intent.createChooser(localIntent, "Choose");
        if (paramAnonymousDialogInterface != null)
          paramAnonymousDialogInterface.dismiss();
      }
    });
    localBuilder.show();
  }

  public void showChannelFilter()
  {
  }

  public void showProgress(boolean paramBoolean)
  {
  }

  public void showProgressBar(float paramFloat, boolean paramBoolean)
  {
  }

  public void showToast(String paramString)
  {
    MetaioCloudUtils.showToast(this.mContext, paramString);
  }

  public void showVisualSearchResults()
  {
  }

  public void startScanMode()
  {
    MetaioCloudPlugin.log("SCAN", "Start scan mode and scanModeEnabled is " + this.mScanModeEnabled);
    if (!this.mScanModeEnabled)
    {
      this.mLockDataSource.lock();
      startCamera(null);
      MetaioCloudPlugin.getDataSource().setScanModeEnabled(true);
      this.mPOIManager.setContinuousVisualSearchEnabled(true);
      MetaioCloudPlugin.getSensorsManager(this.mContext.getApplicationContext()).start(ISensorsComponent.SENSOR_GRAVITY | ISensorsComponent.SENSOR_DEVICE_MOVEMENT);
      this.mScanModeEnabled = true;
      this.mLockDataSource.unlock();
    }
  }

  public void stopScanMode()
  {
    MetaioCloudPlugin.log("SCAN", "Stop scan mode and scanModeEnabled is " + this.mScanModeEnabled);
    if (this.mScanModeEnabled)
    {
      this.mLockDataSource.lock();
      MetaioCloudPlugin.getDataSource().setScanModeEnabled(false);
      this.mPOIManager.setContinuousVisualSearchEnabled(false);
      MetaioCloudPlugin.getSensorsManager(this.mContext.getApplicationContext()).stop(ISensorsComponent.SENSOR_GRAVITY | ISensorsComponent.SENSOR_DEVICE_MOVEMENT);
      this.mLockDataSource.unlock();
      this.mScanModeEnabled = false;
    }
  }

  public void takeScreenshot()
  {
    MetaioCloudPlugin.log("Requesting screenshot. ");
    this.mPOIManager.processURL("arel://scene/shareScreenshot");
  }

  public void trackAPIUsage(int paramInt, String paramString1, String paramString2, float paramFloat)
  {
  }

  public void updateGUI()
  {
  }

  public class ARELDatasourceCallback extends IARELDatasourceDelegate
  {
    public ARELDatasourceCallback()
    {
    }

    public void loadARELWebPage(final PathOrURL paramPathOrURL)
    {
      MetaioCloudPlugin.log("ARELDatasourceCallback", "ARELDatasourceCallback.loadARELWebPage " + paramPathOrURL.asStringForLogging());
      final Semaphore localSemaphore = new Semaphore(0);
      ARMetaioCloudPluginManager.this.mContext.runOnUiThread(new Runnable()
      {
        public void run()
        {
          if (paramPathOrURL.isPath())
            ARMetaioCloudPluginManager.this.mWebview.loadUrl("file://" + paramPathOrURL.asPath().getAbsolutePath());
          while (true)
          {
            localSemaphore.release();
            return;
            ARMetaioCloudPluginManager.this.mWebview.loadUrl(paramPathOrURL.asURL());
          }
        }
      });
      try
      {
        localSemaphore.acquire();
        return;
      }
      catch (InterruptedException localInterruptedException)
      {
        MetaioCloudPlugin.log("ARELDatasourceCallback.loadARELWebPage: " + localInterruptedException.getMessage());
      }
    }

    public void logAPIUsage(int paramInt, String paramString1, String paramString2, float paramFloat)
    {
      MetaioCloudPlugin.log("ARELDatasourceCallback", "ARELDatasourceCallback.logAPIUsage");
      ARMetaioCloudPluginManager.this.trackAPIUsage(paramInt, paramString1, paramString2, paramFloat);
    }

    public void onActivityChanged(final boolean paramBoolean1, final boolean paramBoolean2, final float paramFloat)
    {
      Runnable local7 = new Runnable()
      {
        public void run()
        {
          ARMetaioCloudPluginManager.this.showProgress(paramBoolean1);
          ARMetaioCloudPluginManager.this.showProgressBar(100.0F * paramFloat, paramBoolean2);
        }
      };
      if (ARMetaioCloudPluginManager.this.mMetaioSurfaceView != null)
        ARMetaioCloudPluginManager.this.mMetaioSurfaceView.post(local7);
      while (true)
      {
        StringBuilder localStringBuilder = new StringBuilder().append("ARELDatasourceCallback ");
        Object[] arrayOfObject = new Object[3];
        arrayOfObject[0] = Boolean.valueOf(paramBoolean1);
        arrayOfObject[1] = Boolean.valueOf(paramBoolean2);
        arrayOfObject[2] = Float.valueOf(paramFloat);
        MetaioCloudPlugin.log("ARELDatasourceCallback", String.format("onActivityChanged displayActivityView: %b displayProgressBar %b %f", arrayOfObject));
        return;
        ARMetaioCloudPluginManager.this.mContext.runOnUiThread(local7);
      }
    }

    public void onChannelDataLoaded(MetaioWorldChannel paramMetaioWorldChannel)
    {
      MetaioCloudPlugin.log("ARELDatasourceCallback", "ARELDatasourceCallback.onChannelDataLoaded " + paramMetaioWorldChannel.getChannelID());
      ARMetaioCloudPluginManager.this.mChannelFinishedLoading = true;
      if (ARMetaioCloudPluginManager.this.mChannel != null)
      {
        ARMetaioCloudPluginManager.this.mChannel.delete();
        ARMetaioCloudPluginManager.access$502(ARMetaioCloudPluginManager.this, null);
      }
      ARMetaioCloudPluginManager.access$502(ARMetaioCloudPluginManager.this, new MetaioWorldChannel(paramMetaioWorldChannel));
      ARMetaioCloudPluginManager.this.mContext.runOnUiThread(new Runnable()
      {
        public void run()
        {
          ARMetaioCloudPluginManager.this.updateGUI();
        }
      });
    }

    public void onChannelWillChange(long paramLong)
    {
      MetaioCloudPlugin.log("ARELDatasourceCallback", "ARELDatasourceCallback.onChannelWillChange: " + paramLong);
      ARMetaioCloudPluginManager.this.onChannelWillChange(paramLong);
    }

    public void onChannelsVisualSearchDone(final MetaioWorldChannelVector paramMetaioWorldChannelVector, final ByteBuffer paramByteBuffer, final boolean paramBoolean)
    {
      MetaioCloudPlugin.log("ARELDatasourceCallback", "ARELDatasourceCallback.onChannelsVisualSearchDone " + paramMetaioWorldChannelVector.size());
      final MetaioWorldChannelVector localMetaioWorldChannelVector = new MetaioWorldChannelVector();
      for (int i = 0; i < paramMetaioWorldChannelVector.size(); i++)
      {
        MetaioCloudPlugin.log(paramMetaioWorldChannelVector.get(i).getChannelID() + " - " + paramMetaioWorldChannelVector.get(i).getName());
        localMetaioWorldChannelVector.add(new MetaioWorldChannel(paramMetaioWorldChannelVector.get(i)));
      }
      ARMetaioCloudPluginManager.this.mContext.runOnUiThread(new Runnable()
      {
        public void run()
        {
          MetaioCloudPlugin.log("ARELDatasourceCallback.onChannelsVisualSearchDone.runOnUiThread " + paramMetaioWorldChannelVector.size());
          ARMetaioCloudPluginManager.this.onVisualSearchDone(localMetaioWorldChannelVector, paramByteBuffer, paramBoolean);
        }
      });
    }

    public void onDataSourceEvent(DataSourceEvent paramDataSourceEvent)
    {
      ARMetaioCloudPluginManager.this.onServerEvent(paramDataSourceEvent);
    }

    public void onDidAddObject(IARELObject paramIARELObject)
    {
      MetaioCloudPlugin.log("ARELDatasourceCallback", "ARELDatasourceCallback.onDidAddObject " + paramIARELObject.getName() + " visible on radar: " + paramIARELObject.isVisibleOnRadar() + " visible on map" + paramIARELObject.isVisibleOnMapList());
      final IARELObject localIARELObject = paramIARELObject.clone();
      ARMetaioCloudPluginManager.this.mContext.runOnUiThread(new Runnable()
      {
        public void run()
        {
          ARMetaioCloudPluginManager.this.onObjectAdded(localIARELObject);
        }
      });
    }

    public void onDidRemoveContent(boolean paramBoolean)
    {
      MetaioCloudPlugin.log("ARELDatasourceCallback", "ARELDatasourceCallback.onDidRemoveContent channel cleared: " + paramBoolean);
    }

    public void onScanModeEnabled(boolean paramBoolean)
    {
      super.onScanModeEnabled(paramBoolean);
      if (paramBoolean)
      {
        ARMetaioCloudPluginManager.this.startScanMode();
        return;
      }
      ARMetaioCloudPluginManager.this.stopScanMode();
    }

    public void onSceneOptionsParsed(ARELSceneOptionVector paramARELSceneOptionVector)
    {
      MetaioCloudPlugin.log("ARELDatasourceCallback", "ARELDatasourceCallback.onSceneOptionsParsed");
      super.onSceneOptionsParsed(paramARELSceneOptionVector);
    }

    public void onSceneReady()
    {
      MetaioCloudPlugin.log("ARELDatasourceCallback", "ARELDatasourceCallback.onSceneReady ");
      ARMetaioCloudPluginManager.this.mChannelFinishedLoading = true;
      ARMetaioCloudPluginManager.this.mPedingChannelLoad = -1;
      ARMetaioCloudPluginManager.this.mPOIManager.setDistanceLimit(-1.0F);
      ARMetaioCloudPluginManager.this.mContext.runOnUiThread(new Runnable()
      {
        public void run()
        {
          ARMetaioCloudPluginManager.this.onSceneReady();
        }
      });
    }

    public void onWillRemoveContent()
    {
      MetaioCloudPlugin.log("ARELDatasourceCallback", "ARELDatasourceCallback.onWillRemoveContent");
      ARMetaioCloudPluginManager.this.mMetaioWorldPOIManagerCallback.stopSound(null, null, null, false);
      if (ARMetaioCloudPluginManager.this.metaioSDK.getCamera().getFacing() == Camera.FACE_FRONT)
        ARMetaioCloudPluginManager.this.startCamera(null);
      ARMetaioCloudPluginManager.this.mContext.runOnUiThread(new Runnable()
      {
        public void run()
        {
          ARMetaioCloudPluginManager.this.mWebview.loadUrl("about:blank");
          ARMetaioCloudPluginManager.this.onRemoveContent();
        }
      });
    }

    public void onWillRemoveObject(IARELObject paramIARELObject)
    {
      MetaioCloudPlugin.log("ARELDatasourceCallback", "ARELDatasourceCallback.onWillRemoveObject " + paramIARELObject.getName());
      IARELObject localIARELObject = paramIARELObject.clone();
      ARMetaioCloudPluginManager.this.onObjectRemoved(localIARELObject);
    }
  }

  class OrientationListener extends OrientationEventListener
  {
    private ESCREEN_ROTATION mScreenRotation = Screen.getRotation(ARMetaioCloudPluginManager.this.mContext);

    public OrientationListener(Context arg2)
    {
      super();
    }

    public void onOrientationChanged(int paramInt)
    {
      ESCREEN_ROTATION localESCREEN_ROTATION = Screen.getRotation(ARMetaioCloudPluginManager.this.mContext);
      if (localESCREEN_ROTATION != this.mScreenRotation)
      {
        this.mScreenRotation = localESCREEN_ROTATION;
        ARMetaioCloudPluginManager.this.setScreenRotation(this.mScreenRotation);
      }
    }
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.metaio.cloud.plugin.view.ARMetaioCloudPluginManager
 * JD-Core Version:    0.6.2
 */