package com.ikea.shared.store.service;

import android.content.Context;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.Builder;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.location.FusedLocationProviderApi;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import com.ikea.shared.LibConfig;
import com.ikea.shared.location.event.CurrentLocationUpdateEvent;
import com.ikea.shared.util.L;
import com.squareup.otto.Bus;

public class CurrentLocation
  implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener
{
  private static final long MIN_TIME_BW_UPDATES = 1000L;
  private Bus mBus;
  Context mContext;
  private Location mCurrentLocation;
  private GoogleApiClient mGoogleApiClient;
  protected final Handler mHandler = new Handler();
  private Runnable mLocationNotFoundRunnable;
  private LocationRequest mLocationRequest;

  public CurrentLocation(Context paramContext)
  {
    this.mContext = paramContext;
    this.mBus = LibConfig.i().bus();
  }

  public void connect()
  {
    this.mGoogleApiClient.connect();
    if (this.mHandler != null)
    {
      this.mLocationNotFoundRunnable = new Runnable()
      {
        public void run()
        {
          CurrentLocation.access$002(CurrentLocation.this, null);
        }
      };
      this.mHandler.postDelayed(this.mLocationNotFoundRunnable, 30000L);
    }
  }

  public void init()
  {
    this.mLocationRequest = LocationRequest.create();
    this.mLocationRequest.setPriority(100);
    this.mLocationRequest.setInterval(1000L);
    this.mLocationRequest.setFastestInterval(1000L);
    this.mGoogleApiClient = new GoogleApiClient.Builder(this.mContext).addApi(LocationServices.API).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
  }

  public void onConnected(Bundle paramBundle)
  {
    this.mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(this.mGoogleApiClient);
    LocationServices.FusedLocationApi.requestLocationUpdates(this.mGoogleApiClient, this.mLocationRequest, this);
    if (this.mCurrentLocation != null)
    {
      if ((this.mHandler != null) && (this.mLocationNotFoundRunnable != null))
        this.mHandler.removeCallbacks(this.mLocationNotFoundRunnable);
      this.mBus.post(new CurrentLocationUpdateEvent(this.mCurrentLocation));
    }
  }

  public void onConnectionFailed(ConnectionResult paramConnectionResult)
  {
  }

  public void onConnectionSuspended(int paramInt)
  {
    L.I("GoogleApiClient connection has been suspend");
  }

  public void onLocationChanged(Location paramLocation)
  {
    if ((this.mHandler != null) && (this.mLocationNotFoundRunnable != null))
      this.mHandler.removeCallbacks(this.mLocationNotFoundRunnable);
    if (this.mCurrentLocation == null)
    {
      this.mCurrentLocation = paramLocation;
      this.mBus.post(new CurrentLocationUpdateEvent(this.mCurrentLocation));
    }
    if ((this.mGoogleApiClient.isConnected()) && (this.mCurrentLocation != null))
    {
      LocationServices.FusedLocationApi.removeLocationUpdates(this.mGoogleApiClient, this);
      this.mGoogleApiClient.disconnect();
    }
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.ikea.shared.store.service.CurrentLocation
 * JD-Core Version:    0.6.2
 */