|
15 | 15 | package com.imgtec.hobbyist.fragments.menu;
|
16 | 16 |
|
17 | 17 | import android.app.Activity;
|
| 18 | +import android.app.AlertDialog; |
18 | 19 | import android.content.Context;
|
| 20 | +import android.content.DialogInterface; |
19 | 21 | import android.content.Intent;
|
20 | 22 | import android.content.IntentFilter;
|
21 | 23 | import android.graphics.Color;
|
|
60 | 62 | import com.google.android.gms.maps.model.MarkerOptions;
|
61 | 63 | import com.google.android.gms.maps.model.Polyline;
|
62 | 64 | import com.google.android.gms.maps.model.PolylineOptions;
|
| 65 | +import com.imgtec.flow.Flow; |
63 | 66 | import com.imgtec.flow.MessagingEvent;
|
64 | 67 | import com.imgtec.flow.client.users.DataStore;
|
65 | 68 | import com.imgtec.flow.client.users.DataStoreItem;
|
66 | 69 | import com.imgtec.flow.client.users.DataStoreItems;
|
67 | 70 | import com.imgtec.hobbyist.R;
|
68 | 71 | import com.imgtec.hobbyist.activities.ActivitiesAndFragmentsHelper;
|
69 | 72 | import com.imgtec.hobbyist.activities.FlowActivity;
|
| 73 | +import com.imgtec.hobbyist.flow.AlertListener; |
70 | 74 | import com.imgtec.hobbyist.flow.AsyncMessage;
|
71 | 75 | import com.imgtec.hobbyist.flow.AsyncMessageListener;
|
72 | 76 | import com.imgtec.hobbyist.flow.DevicePresenceListener;
|
| 77 | +import com.imgtec.hobbyist.flow.FlowEntities; |
73 | 78 | import com.imgtec.hobbyist.flow.FlowHelper;
|
74 | 79 | import com.imgtec.hobbyist.flow.GPSReading;
|
75 | 80 | import com.imgtec.hobbyist.flow.Geofence;
|
|
90 | 95 | import java.text.ParseException;
|
91 | 96 | import java.text.SimpleDateFormat;
|
92 | 97 | import java.util.ArrayList;
|
| 98 | +import java.util.Arrays; |
| 99 | +import java.util.Collections; |
| 100 | +import java.util.Comparator; |
93 | 101 | import java.util.Date;
|
94 | 102 | import java.util.HashMap;
|
95 | 103 | import java.util.Iterator;
|
|
105 | 113 | public class InteractiveModeFragment extends NDListeningFragment implements
|
106 | 114 | BackgroundExecutor.Callbacks<List<GPSReading>>, GooglePlayServicesClient.ConnectionCallbacks,
|
107 | 115 | GooglePlayServicesClient.OnConnectionFailedListener, LocationListener, AsyncMessageListener,
|
108 |
| - DevicePresenceListener { |
| 116 | + DevicePresenceListener, AlertListener { |
109 | 117 |
|
110 | 118 | // **************** Constants *********************
|
111 | 119 | public static final String TAG = "InteractiveModeFragment";
|
@@ -244,6 +252,7 @@ public void onResume() {
|
244 | 252 | flowHelper.addDevicePresenceListener(this);
|
245 | 253 | connectionReceiver = new ConnectivityReceiver(new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
|
246 | 254 | connectionReceiver.register(appContext);
|
| 255 | + |
247 | 256 | //online = true;
|
248 | 257 | fetchWiFireLocation();
|
249 | 258 | sendCommand("GET GEOFENCE", null, new CommandResponseHandler() {
|
@@ -325,6 +334,7 @@ public void onPause() {
|
325 | 334 | private void initFlowHelper() {
|
326 | 335 | flowHelper = FlowHelper.getInstance(getActivity());
|
327 | 336 | flowHelper.setAsyncMessageListener(this);
|
| 337 | + flowHelper.setAlertListener(this); |
328 | 338 | }
|
329 | 339 |
|
330 | 340 | public void initUI() {
|
@@ -602,7 +612,31 @@ public void run() {
|
602 | 612 | //fetchWiFireLocation();
|
603 | 613 | }
|
604 | 614 |
|
605 |
| - private interface CommandResponseHandler { |
| 615 | + @Override |
| 616 | + public void onAlertReceived(AsyncMessage asyncMsg) { |
| 617 | + if (asyncMsg.getNode("type").equals("GEOFENCE ESCAPED")) { |
| 618 | + getActivity().runOnUiThread(new Runnable() { |
| 619 | + @Override |
| 620 | + public void run() { |
| 621 | + new AlertDialog.Builder(getActivity()) |
| 622 | + .setTitle("Escaped Geofence") |
| 623 | + .setMessage("The GPS has been detected outside the geofence!") |
| 624 | + .setNeutralButton("OK", |
| 625 | + new DialogInterface.OnClickListener() { |
| 626 | + public void onClick(DialogInterface dialog, int id) { |
| 627 | + dialog.cancel(); |
| 628 | + } |
| 629 | + }) |
| 630 | + .setIcon(android.R.drawable.ic_dialog_alert) |
| 631 | + .show(); |
| 632 | + } |
| 633 | + }); |
| 634 | + } |
| 635 | + Log.e("onAlertReceived", asyncMsg.buildXml()); |
| 636 | + Log.e("onAlertReceived", asyncMsg.getNode("type")); |
| 637 | + } |
| 638 | + |
| 639 | + private interface CommandResponseHandler { |
606 | 640 | void onCommandResponse(AsyncMessage response);
|
607 | 641 | }
|
608 | 642 | private void fetchWiFireLocation() {
|
|
0 commit comments