コード例 #1
0
        // functions called when the back button is pressed
        public override void OnBackPressed()
        {
            StopService();  // Stop the Location service if it running
            MySettings.Save(mainsave);

            base.OnBackPressed();
        }
コード例 #2
0
 // Ok Button action for changing the Units
 private void OkMeasurementAction(object sender, DialogClickEventArgs e)
 {
     if (ListPosition == 0)
     {
         // If switching from metric to Imperial then convert all the text on screen.
         if (mainsave.Measurement == MySettings.MeasurementSystem.Metric)
         {
             MaxSpeedFloat = MaxSpeedFloat * .621371;
             Speed         = Speed * .621371;
             MaxSpeed.Text = "Max Speed: " + MaxSpeedFloat.ToString("0.00") + " MPH";
             speed.Text    = "Speed: " + Speed.ToString("0.00") + " MPH";
             elev          = elev * 3.28; // Get the Ft Equivalent of Altitude's Meters
             Altitude.Text = "Elevation: " + elev.ToString("0.0") + "Ft";
         }
         // Change unit system in the User settings
         mainsave.Measurement = MySettings.MeasurementSystem.Imperial;
     }
     else
     {
         // If switching from imperial to metric then convert all the text on screen
         if (mainsave.Measurement == MySettings.MeasurementSystem.Imperial)
         {
             MaxSpeedFloat = MaxSpeedFloat * 1.60934;
             Speed         = Speed * 1.60934;
             MaxSpeed.Text = "Max Speed: " + MaxSpeedFloat.ToString("0.00") + " KPH";
             speed.Text    = "Speed: " + Speed.ToString("0.00") + " KPH";
             elev          = elev * .3048;
             Altitude.Text = "Elevation: " + elev.ToString("0.0") + "m";
         }
         // Change unit system in user settings
         mainsave.Measurement = MySettings.MeasurementSystem.Metric;
     }
     MySettings.Save(mainsave);
 }
コード例 #3
0
        public static MySettings Load()
        {
            Stream     stream  = null;
            MySettings Profile = null;

            try
            {
                IFormatter formatter = new BinaryFormatter();
                stream = new FileStream(Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "mcbsettings.mcb92"), FileMode.Open, FileAccess.Read, FileShare.None);
                int version = (int)formatter.Deserialize(stream);
                Profile = (MySettings)formatter.Deserialize(stream);
            }
            catch
            {
                // do nothing, just ignore any possible errors
                System.Diagnostics.Debug.WriteLine("DID NOT LOAD CORRECTLY");
            }
            finally
            {
                if (null != stream)
                {
                    stream.Close();
                }
            }
            return(Profile);
        }
コード例 #4
0
        public static void Save(MySettings set)
        {
            Stream stream = null;

            try
            {
                IFormatter formatter = new BinaryFormatter();
                stream = new FileStream(Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "mcbsettings.mcb92"), FileMode.Create, FileAccess.Write, FileShare.None);
                formatter.Serialize(stream, VERSION);
                formatter.Serialize(stream, set);

                System.Diagnostics.Debug.WriteLine("CREATED A SAVE FILE");
            }
            catch
            {
                // No Save File Created
                System.Diagnostics.Debug.WriteLine("DID NOT CREATE A SAVE FILE");
            }
            finally
            {
                if (null != stream)
                {
                    stream.Close();
                }
            }
        }
コード例 #5
0
        private readonly System.Threading.Timer _timer; // timer used in polling the update data

        // Create a Layer that will update the position of the rater using a DynamicMemoryProvider
        public AnimatedPointsWithAutoUpdateLayer(ref MySettings settings)
            : base(new DynamicMemoryProvider())
        {
            Style = new SymbolStyle {
                Fill = { Color = settings.ReturnColor() }, SymbolScale = .5
            };                                                                                        // Set the symbol color and size used to represent the Vehicle on the map
            _timer = new System.Threading.Timer(arg => UpdateData(), this, 0, 3000);                  // Set the timer to update the data from DynamicMemoryProvider
        }
コード例 #6
0
        public static Map CreateMap(ref MySettings Settings)
        {
            Map map = new Map();                                                                    // Declare the map variable

            map.Layers.Add(OpenStreetMap.CreateTileLayer());                                        // Create map after determining if there is an offline or online one available
            map.Layers.Add(new AnimatedPointsWithAutoUpdateLayer(ref Settings)
            {
                Name = "Vehicle Location"
            });                                                                                      // Create the Layer for the Raters Location and add it Layers
            return(map);                                                                             // Return the map
        }
コード例 #7
0
        // Called when the user clicks on OK for the Color selector dialog
        private void OkColorAction(object sender, DialogClickEventArgs e)
        {
            // Change color in user settings
            mainsave.color = mainsave.List2DotColor(ListPosition);

            // Save user settings
            MySettings.Save(mainsave);

            // Change the dot on the map to the new color
            mapCtrl.Map.Layers[1].Style = new SymbolStyle {
                Fill = { Color = mainsave.ReturnColor() }, SymbolScale = .4
            };
        }
コード例 #8
0
        // Checks if we have GPS permissions
        private void FirstRun()
        {
            const string PREFS_NAME         = "PrefsFile";
            const string PrefVersionCodeKey = "version_code";
            int          DoesntExist        = -1;

            // Get Current Version of Application
            int currentVersionCode = Application.Context.PackageManager.GetPackageInfo(Application.Context.ApplicationContext.PackageName, 0).VersionCode;


            ISharedPreferences prefs = GetSharedPreferences(PREFS_NAME, FileCreationMode.Private);
            int savedVersionCode     = prefs.GetInt(PrefVersionCodeKey, DoesntExist);

            // If current version then its a normal run.
            if (currentVersionCode == savedVersionCode)
            {
                mainsave = MySettings.Load();
            }
            else if (savedVersionCode == DoesntExist)
            {
                // New Install or User Cleared Shared Preferences
                mainsave = new MySettings();
                MySettings.Save(mainsave);
            }
            else if (currentVersionCode > savedVersionCode)
            {
                mainsave = MySettings.Load();
                // Upgrade of Application
            }

            // Update shared preferences with current version code
            prefs.Edit().PutInt(PrefVersionCodeKey, currentVersionCode).Apply();



            if (CheckSelfPermission(Android.Manifest.Permission.AccessFineLocation) != (int)Permission.Granted)
            {
                System.Threading.Tasks.Task.Run(() =>
                {
                    RequestPermissions(new string[] { Android.Manifest.Permission.AccessFineLocation }, 1);
                }).ConfigureAwait(true);
                speed.Text = "Location Service Needs to Be Allowed";
            }
            else
            {
                AllowMapToLoad = true;
            }
        }
コード例 #9
0
        // Gets called after OnCreate() according to Android Lifecycle. Checks and Starts Location service if allowed
        protected override void OnResume()
        {
            mainsave = MySettings.Load();
            if (AllowMapToLoad == true) // If Location Service is Allowed
            {
                LocService();           // Start Location Service
            }
            System.Threading.Tasks.Task.Run(() =>
            {
                mapCtrl.Map = MapFunctions.CreateMap(ref mainsave); // Create the Map
                mapCtrl.Map.NavigateTo(18);                         // Set Inital Zoom Level to be Fairly Close
            });
            if (mainsave.Measurement == MySettings.MeasurementSystem.Imperial)
            {
                MaxSpeed.Text = "Max Speed: " + MaxSpeedFloat + " MPH";
            }
            else
            {
                MaxSpeed.Text = "Max Speed: " + MaxSpeedFloat + " KPH";
            }

            base.OnResume();
        }
コード例 #10
0
 // Will Stop location service when user switches to another app. OnResume will be called to restart location service if the navigate back
 protected override void OnPause()
 {
     StopService();
     MySettings.Save(mainsave);
     base.OnPause();
 }