Beispiel #1
0
        /// <inheritdoc />
        /// <summary>
        ///     Load the contents of the file from the Android file system. Uses
        ///     the async .NET APIs for reading bytes from a file.
        /// </summary>
        /// <returns></returns>
        public virtual async Task <int> ReadFileAsync(IGenerateNameOfFile fileName)
        {
            var backingFile = fileName.GetAbsolutePathToFile(DefaultFilename);

            if (backingFile == null || !File.Exists(backingFile))
            {
                return(0);
            }

            var count = 0;

            using (var reader = new StreamReader(backingFile, true))
            {
                string line;
                while ((line = await reader.ReadLineAsync()) != null)
                {
                    if (int.TryParse(line, out var newcount))
                    {
                        count = newcount;
                    }
                }
            }

            return(count);
        }
Beispiel #2
0
        public static string ReadFile(IGenerateNameOfFile filePath, string fileName)
        {
            string backingFile = filePath.GetAbsolutePathToFile(fileName);

            if (backingFile == null || !File.Exists(backingFile))
            {
                return(string.Empty);
            }

            return(File.ReadAllText(backingFile));
        }
Beispiel #3
0
        public static void WriteFile(IGenerateNameOfFile filePath, string fileName, string json)
        {
            string backingFile = filePath.GetAbsolutePathToFile(fileName);

            if (backingFile == null)
            {
                return;
            }

            File.WriteAllText(backingFile, json);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            App.Initialize();

            this.PerformRuntimePermissionCheckForLocation(REQUEST_PERMISSIONS_LOCATION);

            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.MapLayout);

            _searchMarkerEditText      = FindViewById <TextView>(Resource.Id.searchMarkerEditText);
            _searchMarkerButton        = FindViewById <Button>(Resource.Id.searchMarkerButton);
            _searchMarkerButton.Click += HandleOnSearchMarkerButtonClick;

            _currentLocationButton        = FindViewById <Button>(Resource.Id.currentLocationButton);
            _currentLocationButton.Click += HandleOnCurrentLocationButtonClick;

            InitializeLocationManager();

            if (Environment.MediaMounted.Equals(Environment.ExternalStorageState))
            {
                _filenameGenerator = new ExternalStorageFilenameGenerator(this);
            }
            else
            {
                _filenameGenerator = new InternalCacheFilenameGenerator(this);
            }

            if (RequestExternalStoragePermissionIfNecessary(RC_READ_EXTERNAL_STORAGE_PERMISSION))
            {
                string json = FileHelper.ReadFile(_filenameGenerator, _defaultFilename);

                if (!string.IsNullOrWhiteSpace(json))
                {
                    _markers = JsonConvert.DeserializeObject <List <MarkerInfo> >(json);
                }
            }

            _isGooglePlayServicesInstalled = TestIfGooglePlayServicesIsInstalled();

            if (!_isGooglePlayServicesInstalled)
            {
                Log.Error(Resources.GetString(Resource.String.app_name), Resources.GetString(Resource.String.googleServiceNotInstalled));
                return;
            }

            Messenger.Default.Register <MarkerMessage>(this, ReceiveMarkerInfo);

            var mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);

            mapFragment.GetMapAsync(this);
        }
        void InitializeDependencies()
        {
            fileStorage = new CountOfClicksFileStorage();

            if (Environment.MediaMounted.Equals(Environment.ExternalStorageState))
            {
                filenameGenerator = new ExternalStorageFilenameGenerator(this);
            }
            else
            {
                filenameGenerator = new InternalCacheFilenameGenerator(this);
            }

            Log.Info(TAG, "Using the " + filenameGenerator.GetType().Name + " for the internal storage.");
        }
Beispiel #6
0
        /// <summary>
        ///     Writes the number to a text file  using the async
        ///     .NET APIs for write the contents to the filesystem.
        /// </summary>
        /// <param name="fileName">The name (but not the path) of the text file that will be written to.</param>
        /// <param name="count">A number that will be written to a text file.</param>
        /// <returns></returns>
        public virtual async Task WriteFileAsync(IGenerateNameOfFile fileName, int count)
        {
            var backingFile = fileName.GetAbsolutePathToFile(DefaultFilename);

            if (backingFile == null)
            {
                // For reasons beyond the control/responsibilty of this class,
                // there is no path to the backing storage file. Don't do anything.
                return;
            }

            using (var writer = File.CreateText(backingFile))
            {
                await writer.WriteLineAsync(count.ToString());
            }
        }
Beispiel #7
0
 /// <summary>
 ///     Resets the count to zero and will delete the backing text file.
 /// </summary>
 /// <param name="filename"></param>
 public Task DeleteFileAsync(IGenerateNameOfFile filename)
 {
     Count = 0;
     return(Task.Run(() => { File.Delete(filename.GetAbsolutePathToFile(DefaultFilename)); }));
 }
Beispiel #8
0
 /// <summary>
 ///     Will display th name of the backing text file in the specified TextView.
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="view"></param>
 public void DisplayPathIn(IGenerateNameOfFile fileName, TextView view)
 {
     view.Text = fileName.GetAbsolutePathToFile(DefaultFilename);
 }