Exemplo n.º 1
0
 public override void OnReceive(Context context, Intent intent)
 {
     if (intent != null)
     {
         GefenceManager gefenceManager = null;
         string         action         = intent.Action;
         LocationResult locationResult = LocationResult.ExtractResult(intent);
         if (locationResult != null && action.Equals(ACTION_PROCESS_LOCATIOM))
         {
             var lastloc = locationResult.LastLocation;
             if (GefenceLocation.gefenceModel != null && GefenceLocation.gefenceModel.Status == "From")
             {
                 if ((GefenceLocation.gefenceModel.FromLat - GefenceLocation.gefenceModel.Radius < lastloc.Latitude && GefenceLocation.gefenceModel.FromLat + GefenceLocation.gefenceModel.Radius > lastloc.Latitude) &&
                     (GefenceLocation.gefenceModel.FromLng - GefenceLocation.gefenceModel.Radius < lastloc.Longitude && GefenceLocation.gefenceModel.FromLng + GefenceLocation.gefenceModel.Radius > lastloc.Longitude))
                 {
                     gefenceManager = new GefenceManager();
                     GefenceLocation.gefenceModel.Status = "To";
                     gefenceManager.GoDriveTo(GefenceLocation.gefenceModel.ToLat, GefenceLocation.gefenceModel.ToLng);
                 }
             }
             else if (GefenceLocation.gefenceModel != null && GefenceLocation.gefenceModel.Status == "To")
             {
                 if ((GefenceLocation.gefenceModel.ToLat - GefenceLocation.gefenceModel.Radius < lastloc.Latitude && GefenceLocation.gefenceModel.ToLat + GefenceLocation.gefenceModel.Radius > lastloc.Latitude) &&
                     (GefenceLocation.gefenceModel.ToLng - GefenceLocation.gefenceModel.Radius < lastloc.Longitude && GefenceLocation.gefenceModel.ToLng + GefenceLocation.gefenceModel.Radius > lastloc.Longitude))
                 {
                     GefenceLocation.gefenceModel.Status = "None";
                     GefenceLocation.gefenceModel.PendingIntent.Cancel();
                     GefenceLocation.gefenceModel = null;
                     if (MainActivity.GetInstance() == null)
                     {
                         MainActivity mainActivity = new MainActivity();
                         mainActivity.Intent = new Intent(context, typeof(MainActivity));
                         mainActivity.Intent.AddFlags(ActivityFlags.NewTask);
                         context.StartActivity(mainActivity.Intent);
                     }
                     else
                     {
                         context.StartActivity(MainActivity.GetInstance().Intent);
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        private static async void LocationsUpdated_Event(object sender, CLLocationsUpdatedEventArgs e)
        {
            if (true)
            {
                if (gefenceModel == null)
                {
                    if (!GefenceLocation.ResetGeofnceModel())
                    {
                        return;
                    }
                }
                int            index          = GefenceLocation.gefenceModel.OrderMobile.OnePointForAddressOrders.FindIndex(one => one == GefenceLocation.gefenceModel.OnePointForAddressOrder);
                GefenceManager gefenceManager = new GefenceManager();
                if (GefenceLocation.gefenceModel.OrderMobile.OnePointForAddressOrders.Count - 1 == index)
                {
                    if ((GefenceLocation.gefenceModel.OnePointForAddressOrder.Lat - 0.00073 < e.Locations[0].Coordinate.Latitude && GefenceLocation.gefenceModel.OnePointForAddressOrder.Lat + 0.00073 > e.Locations[0].Coordinate.Latitude) &&
                        (GefenceLocation.gefenceModel.OnePointForAddressOrder.Lng - 0.00073 < e.Locations[0].Coordinate.Longitude && GefenceLocation.gefenceModel.OnePointForAddressOrder.Lng + 0.00073 > e.Locations[0].Coordinate.Longitude))
                    {
                        if (GefenceLocation.gefenceModel.IsNewOrder)
                        {
                            await gefenceManager.RecurentStatusOrder(GefenceLocation.gefenceModel.OrderMobile.ID, "NewOrder");
                        }
                        else
                        {
                            await gefenceManager.RecurentStatusOrder(GefenceLocation.gefenceModel.OrderMobile.ID, "NewOrderAndEndOrder");
                        }
                        gefenceModel.LocMgr.StopUpdatingLocation();
                        gefenceModel = null;
                        //ComponentName receiver = new ComponentName(context, this.Class);
                        //PackageManager pm = context.PackageManager;
                        //pm.SetComponentEnabledSetting(receiver, ComponentEnabledState.Disabled, ComponentEnableOption.DontKillApp);
                        //if (MainActivity.GetInstance() == null)
                        //{
                        //    MainActivity mainActivity = new MainActivity();
                        //    mainActivity.Intent = new Intent(context, typeof(MainActivity));
                        //    mainActivity.Intent.AddFlags(ActivityFlags.NewTask);
                        //    context.StartActivity(mainActivity.Intent);
                        //}
                        //else
                        //{
                        //    context.StartActivity(MainActivity.GetInstance().Intent);
                        //}
                    }
                    else if ((GefenceLocation.gefenceModel.OnePointForAddressOrder.Lat - 0.0022 < e.Locations[0].Coordinate.Latitude && GefenceLocation.gefenceModel.OnePointForAddressOrder.Lat + 0.0022 > e.Locations[0].Coordinate.Latitude) &&
                             (GefenceLocation.gefenceModel.OnePointForAddressOrder.Lng - 0.0022 < e.Locations[0].Coordinate.Longitude && GefenceLocation.gefenceModel.OnePointForAddressOrder.Lng + 0.0022 > e.Locations[0].Coordinate.Longitude) && !GefenceLocation.gefenceModel.IsNewOrder)
                    {
                        await gefenceManager.RecurentStatusOrder(GefenceLocation.gefenceModel.OrderMobile.ID, "NewOrder");

                        GefenceLocation.gefenceModel.IsNewOrder = true;
                    }
                }
                else
                {
                    if (GefenceLocation.gefenceModel.OnePointForAddressOrder.Type == "Start")
                    {
                        if ((GefenceLocation.gefenceModel.OnePointForAddressOrder.Lat - 0.00073 < e.Locations[0].Coordinate.Latitude && GefenceLocation.gefenceModel.OnePointForAddressOrder.Lat + 0.00073 > e.Locations[0].Coordinate.Latitude) &&
                            (GefenceLocation.gefenceModel.OnePointForAddressOrder.Lng - 0.00073 < e.Locations[0].Coordinate.Longitude && GefenceLocation.gefenceModel.OnePointForAddressOrder.Lng + 0.00073 > e.Locations[0].Coordinate.Longitude))
                        {
                            await gefenceManager.RecurentStatusOrder(GefenceLocation.gefenceModel.OrderMobile.ID, "CompletePoint");

                            GefenceLocation.gefenceModel.OnePointForAddressOrder = GefenceLocation.gefenceModel.OrderMobile.OnePointForAddressOrders[index + 1];
                            gefenceManager.GoDriveTo(GefenceLocation.gefenceModel.OnePointForAddressOrder.Lat, GefenceLocation.gefenceModel.OnePointForAddressOrder.Lng);
                        }
                    }
                    else if (GefenceLocation.gefenceModel.OnePointForAddressOrder.Type == "End")
                    {
                        if ((GefenceLocation.gefenceModel.OnePointForAddressOrder.Lat - 0.00073 < e.Locations[0].Coordinate.Latitude && GefenceLocation.gefenceModel.OnePointForAddressOrder.Lat + 0.00073 > e.Locations[0].Coordinate.Latitude) &&
                            (GefenceLocation.gefenceModel.OnePointForAddressOrder.Lng - 0.00073 < e.Locations[0].Coordinate.Longitude && GefenceLocation.gefenceModel.OnePointForAddressOrder.Lng + 0.00073 > e.Locations[0].Coordinate.Longitude))
                        {
                            await gefenceManager.RecurentStatusOrder(GefenceLocation.gefenceModel.OrderMobile.ID, "CompletePoint");

                            GefenceLocation.gefenceModel.OnePointForAddressOrder = GefenceLocation.gefenceModel.OrderMobile.OnePointForAddressOrders[index + 1];
                            gefenceManager.GoDriveTo(GefenceLocation.gefenceModel.OnePointForAddressOrder.Lat, GefenceLocation.gefenceModel.OnePointForAddressOrder.Lng);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public override async void OnReceive(Context context, Intent intent)
        {
            var cm = (ConnectivityManager)context.GetSystemService(Context.ConnectivityService);

            if (intent != null && (cm.ActiveNetworkInfo == null ? false : cm.ActiveNetworkInfo.IsConnected))
            {
                if (GefenceLocation.gefenceModel == null)
                {
                    if (!GefenceLocation.ResetGeofnceModel())
                    {
                        ComponentName  receiver = new ComponentName(context, this.Class);
                        PackageManager pm       = context.PackageManager;
                        pm.SetComponentEnabledSetting(receiver, ComponentEnabledState.Disabled, ComponentEnableOption.DontKillApp);
                        return;
                    }
                }
                GefenceManager gefenceManager = null;
                string         action         = intent.Action;
                LocationResult locationResult = LocationResult.ExtractResult(intent);
                if (locationResult != null && action.Equals(ACTION_PROCESS_LOCATIOM))
                {
                    gefenceManager = new GefenceManager();
                    var lastloc = locationResult.LastLocation;
                    int index   = GefenceLocation.gefenceModel.OrderMobile.OnePointForAddressOrders.FindIndex(one => one == GefenceLocation.gefenceModel.OnePointForAddressOrder);
                    if (GefenceLocation.gefenceModel.OrderMobile.OnePointForAddressOrders.Count - 1 == index)
                    {
                        if ((GefenceLocation.gefenceModel.OnePointForAddressOrder.Lat - 0.00073 < lastloc.Latitude && GefenceLocation.gefenceModel.OnePointForAddressOrder.Lat + 0.00073 > lastloc.Latitude) &&
                            (GefenceLocation.gefenceModel.OnePointForAddressOrder.Lng - 0.00073 < lastloc.Longitude && GefenceLocation.gefenceModel.OnePointForAddressOrder.Lng + 0.00073 > lastloc.Longitude))
                        {
                            if (GefenceLocation.gefenceModel.IsNewOrder)
                            {
                                await gefenceManager.RecurentStatusOrder(GefenceLocation.gefenceModel.OrderMobile.ID, "NewOrder");
                            }
                            else
                            {
                                await gefenceManager.RecurentStatusOrder(GefenceLocation.gefenceModel.OrderMobile.ID, "NewOrderAndEndOrder");
                            }
                            ComponentName  receiver = new ComponentName(context, this.Class);
                            PackageManager pm       = context.PackageManager;
                            pm.SetComponentEnabledSetting(receiver, ComponentEnabledState.Disabled, ComponentEnableOption.DontKillApp);
                            if (MainActivity.GetInstance() == null)
                            {
                                MainActivity mainActivity = new MainActivity();
                                mainActivity.Intent = new Intent(context, typeof(MainActivity));
                                mainActivity.Intent.AddFlags(ActivityFlags.NewTask);
                                context.StartActivity(mainActivity.Intent);
                            }
                            else
                            {
                                context.StartActivity(MainActivity.GetInstance().Intent);
                            }
                        }
                        else if ((GefenceLocation.gefenceModel.OnePointForAddressOrder.Lat - 0.0022 < lastloc.Latitude && GefenceLocation.gefenceModel.OnePointForAddressOrder.Lat + 0.0022 > lastloc.Latitude) &&
                                 (GefenceLocation.gefenceModel.OnePointForAddressOrder.Lng - 0.0022 < lastloc.Longitude && GefenceLocation.gefenceModel.OnePointForAddressOrder.Lng + 0.0022 > lastloc.Longitude) && !GefenceLocation.gefenceModel.IsNewOrder)
                        {
                            await gefenceManager.RecurentStatusOrder(GefenceLocation.gefenceModel.OrderMobile.ID, "NewOrder");

                            GefenceLocation.gefenceModel.IsNewOrder = true;
                        }
                    }
                    else
                    {
                        if (GefenceLocation.gefenceModel.OnePointForAddressOrder.Type == "Start")
                        {
                            if ((GefenceLocation.gefenceModel.OnePointForAddressOrder.Lat - 0.00073 < lastloc.Latitude && GefenceLocation.gefenceModel.OnePointForAddressOrder.Lat + 0.00073 > lastloc.Latitude) &&
                                (GefenceLocation.gefenceModel.OnePointForAddressOrder.Lng - 0.00073 < lastloc.Longitude && GefenceLocation.gefenceModel.OnePointForAddressOrder.Lng + 0.00073 > lastloc.Longitude))
                            {
                                await gefenceManager.RecurentStatusOrder(GefenceLocation.gefenceModel.OrderMobile.ID, "CompletePoint");

                                GefenceLocation.gefenceModel.OnePointForAddressOrder = GefenceLocation.gefenceModel.OrderMobile.OnePointForAddressOrders[index + 1];
                                gefenceManager.GoDriveTo(GefenceLocation.gefenceModel.OnePointForAddressOrder.Lat, GefenceLocation.gefenceModel.OnePointForAddressOrder.Lng);
                            }
                        }
                        else if (GefenceLocation.gefenceModel.OnePointForAddressOrder.Type == "End")
                        {
                            if ((GefenceLocation.gefenceModel.OnePointForAddressOrder.Lat - 0.00073 < lastloc.Latitude && GefenceLocation.gefenceModel.OnePointForAddressOrder.Lat + 0.00073 > lastloc.Latitude) &&
                                (GefenceLocation.gefenceModel.OnePointForAddressOrder.Lng - 0.00073 < lastloc.Longitude && GefenceLocation.gefenceModel.OnePointForAddressOrder.Lng + 0.00073 > lastloc.Longitude))
                            {
                                await gefenceManager.RecurentStatusOrder(GefenceLocation.gefenceModel.OrderMobile.ID, "CompletePoint");

                                GefenceLocation.gefenceModel.OnePointForAddressOrder = GefenceLocation.gefenceModel.OrderMobile.OnePointForAddressOrders[index + 1];
                                gefenceManager.GoDriveTo(GefenceLocation.gefenceModel.OnePointForAddressOrder.Lat, GefenceLocation.gefenceModel.OnePointForAddressOrder.Lng);
                            }
                        }
                    }
                }
            }
        }