import android.os.RemoteException;
import android.preference.PreferenceManager;
-import com.radiusnetworks.ibeacon.*;
-import com.radiusnetworks.ibeacon.client.*;
-import com.radiusnetworks.ibeacon.service.*;
-
-public class Task extends Service implements IBeaconConsumer, RangeNotifier, MonitorNotifier
+public class Task extends Service
{
/* Private data */
private Messenger messenger;
- private IBeaconManager ibeacon;
+ private Beacon beacon;
+ private Sensors sensors;
+ private boolean running;
- /* Private methods */
- private void tellMain(CMD.Response cmd, Object value)
+ /* Public methods */
+ public void tellMain(CMD.Response cmd, Object value)
{
try {
android.os.Message msg = android.os.Message.obtain();
}
}
- private void notify(String text, int icon)
+ public void notify(String text, int icon)
{
// Notify Main
this.tellMain(CMD.Response.NOTIFY, text);
// Notification bar
- //Notification note = new Notification(icon, null, 0);
- //Intent intent = new Intent(this, Main.class);
- //PendingIntent pend = PendingIntent.getActivity(this, 0, intent, 0);
- //note.setLatestEventInfo(this, "iBeaconNav!", text, pend);
- //PendingIntent pend = PendingIntent.getActivity(this, 0, intent, 0);
-
Notification note = new Notification.Builder(this)
.setContentTitle("iBeaconNav!")
.setContentText("iBeaconNav!")
this.startForeground(1, note);
}
+ public boolean isRunning()
+ {
+ return this.running;
+ }
+
+ /* Private methods */
private void handle(CMD.Command cmd, Messenger mgr)
{
// Validate messenger
case REGISTER:
Util.debug("Task: handle - register");
this.messenger = mgr;
+ this.tellMain(CMD.Response.REGISTER, this);
break;
// Create client thread
case CONNECT:
Util.debug("Task: handle - connect");
+ this.running = true;
this.notify("Connected", android.R.drawable.presence_online);
- this.ibeacon = IBeaconManager.getInstanceForApplication(this);
- this.ibeacon.bind(this);
//this.ibeacon.setBackgroundMode(this, false);
break;
case DISCONNECT:
Util.debug("Task: handle - register");
//this.ibeacon.setBackgroundMode(this, true);
- this.ibeacon.unBind(this);
- this.ibeacon = null;
+ this.running = false;
this.stopForeground(true);
break;
- }
- }
- /* Public methods */
- public boolean isRunning()
- {
- return this.ibeacon != null;
+ // Reset heading
+ case RSTHEAD:
+ this.sensors.reset_heading();
+ break;
+
+ // Reset distance
+ case RSTDST:
+ this.sensors.reset_distance();
+ break;
+
+ }
}
/* Service Methods */
{
Util.debug("Task: onCreate");
super.onCreate();
- IBeaconManager.LOG_DEBUG = true;
+ this.beacon = new Beacon(this);
+ this.sensors = new Sensors(this);
}
@Override
Util.debug("Task: onBind");
return null;
}
-
- /* IBeaconConsumer Methods */
- @Override
- public void onIBeaconServiceConnect() {
- Util.debug("Task: onIBeaconServiceConnect");
-
- this.ibeacon.setRangeNotifier(this);
- this.ibeacon.setMonitorNotifier(this);
-
- try {
- Region region = new Region("iBeaconNavMonitoringId", null, null, null);
- this.ibeacon.startRangingBeaconsInRegion(region);
- this.ibeacon.startMonitoringBeaconsInRegion(region);
- } catch (RemoteException e) {
- Util.debug("Task: onIBeaconServiceConnect - error");
- }
- }
-
- /* RangeNotifier Methods */
- @Override
- public void didRangeBeaconsInRegion(Collection<IBeacon> iBeacons, Region region) {
- Util.debug("Task: didRangeBeaconsInRegion");
- }
-
- /* MonitorNotifier Methods */
- @Override
- public void didEnterRegion(Region region) {
- Util.debug("Task: didEnterRegion");
- }
-
- @Override
- public void didExitRegion(Region region) {
- Util.debug("Task: didExitRegion");
- }
-
- @Override
- public void didDetermineStateForRegion(int state, Region region) {
- Util.debug("Task: didDetermineStateForRegion");
- }
}