PushBeaconService.java 4.78 KB
package com.arellomobile.android.push;

import android.annotation.TargetApi;
import android.app.Service;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.RemoteException;
import com.pushwoosh.support.v4.app.LocalBroadcastManager;
import com.radiusnetworks.ibeacon.IBeaconConsumer;
import com.radiusnetworks.ibeacon.IBeaconManager;
import com.radiusnetworks.ibeacon.MonitorNotifier;
import com.radiusnetworks.ibeacon.Region;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.json.JSONObject;

@TargetApi(9)
public class PushBeaconService
  extends Service
  implements IBeaconConsumer, MonitorNotifier
{
  public static final String BACKGROUND_MODE = "backgroundMode";
  private static final Map<Region, Runnable> g = new ConcurrentHashMap();
  private IBeaconManager a = IBeaconManager.getInstanceForApplication(this);
  private JSONObject b;
  private List<Region> c;
  private Integer d;
  private Handler e;
  private HandlerThread f;
  
  private static String a(Region paramRegion)
  {
    return "Region: " + paramRegion.getProximityUuid() + ", major: " + paramRegion.getMajor() + ", minor: " + paramRegion.getMinor();
  }
  
  public void didDetermineStateForRegion(int paramInt, Region paramRegion) {}
  
  public void didEnterRegion(Region paramRegion)
  {
    PushManager.processBeacon(getApplicationContext(), paramRegion.getProximityUuid(), paramRegion.getMajor().toString(), null, "came");
    Object localObject = new Intent("beacon");
    ((Intent)localObject).putExtra("Status", "Add " + a(paramRegion));
    LocalBroadcastManager.getInstance(this).sendBroadcast((Intent)localObject);
    if (this.d.intValue() > 0)
    {
      localObject = new b(paramRegion);
      this.e.postDelayed((Runnable)localObject, this.d.intValue() * 1000);
      g.put(paramRegion, localObject);
    }
  }
  
  public void didExitRegion(Region paramRegion)
  {
    Object localObject = (Runnable)g.remove(paramRegion);
    if (localObject != null) {
      this.e.removeCallbacks((Runnable)localObject);
    }
    PushManager.processBeacon(getApplicationContext(), paramRegion.getProximityUuid(), paramRegion.getMajor().toString(), null, "cameout");
    localObject = new Intent("beacon");
    ((Intent)localObject).putExtra("Status", "Remove " + a(paramRegion));
    LocalBroadcastManager.getInstance(this).sendBroadcast((Intent)localObject);
  }
  
  public IBinder onBind(Intent paramIntent)
  {
    return null;
  }
  
  public void onCreate()
  {
    super.onCreate();
    this.f = new HandlerThread(getPackageName());
    this.f.start();
    this.e = new Handler(this.f.getLooper());
  }
  
  public void onDestroy()
  {
    try
    {
      Iterator localIterator = this.c.iterator();
      while (localIterator.hasNext())
      {
        Region localRegion = (Region)localIterator.next();
        this.a.stopRangingBeaconsInRegion(localRegion);
        this.e.removeCallbacks((Runnable)g.get(localRegion));
      }
      return;
    }
    catch (RemoteException localRemoteException)
    {
      this.f.quit();
      this.a.unBind(this);
      super.onDestroy();
    }
  }
  
  public void onIBeaconServiceConnect()
  {
    this.a.setMonitorNotifier(this);
    try
    {
      Iterator localIterator = this.c.iterator();
      while (localIterator.hasNext())
      {
        Region localRegion = (Region)localIterator.next();
        this.a.startMonitoringBeaconsInRegion(localRegion);
      }
      return;
    }
    catch (RemoteException localRemoteException) {}
  }
  
  public int onStartCommand(Intent paramIntent, int paramInt1, int paramInt2)
  {
    super.onStartCommand(paramIntent, paramInt1, paramInt2);
    if (paramIntent.hasExtra("backgroundMode"))
    {
      this.a.setBackgroundMode(this, paramIntent.getBooleanExtra("backgroundMode", true));
      return 1;
    }
    new a((byte)0).execute(new Void[0]);
    return 1;
  }
  
  final class a
    extends AsyncTask<Void, Void, JSONObject>
  {
    private a() {}
    
    private JSONObject a()
    {
      try
      {
        JSONObject localJSONObject = DeviceFeature2_5.getBeacons(PushBeaconService.this);
        return localJSONObject;
      }
      catch (Exception localException) {}
      return new JSONObject();
    }
  }
  
  final class b
    implements Runnable
  {
    private Region b;
    
    public b(Region paramRegion)
    {
      this.b = paramRegion;
    }
    
    public final void run()
    {
      PushBeaconService.a().remove(this.b);
      PushBeaconService.a(PushBeaconService.this, this.b);
    }
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/arellomobile/android/push/PushBeaconService.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */