private async void GetImages(AppPreferences ap)
        {
            if (!String.IsNullOrEmpty(imageNames[0]))
            {
                Bitmap bit = ap.SetImageBitmap(ap.CreateDirectoryForPictures() + "/" + imageNames[0]);
                if (bit != null)
                {
                    pictureHolder.SetImageBitmap(bit);
                }
                else if (bit == null && !String.IsNullOrEmpty(imageNames[0]))
                {
                    PictureViewModel pictureViewModel = new PictureViewModel();
                    Models.Picture   picture          = await pictureViewModel.ExecuteGetPictureCommand(imageNames[0]);

                    if (picture != null)
                    {
                        var _bit = ap.StringToBitMap(picture.File);
                        if (_bit != null)
                        {
                            ap.SaveImage(_bit, imageNames[0]);
                        }
                        pictureHolder.SetImageBitmap(_bit);
                    }
                }
            }
        }
        private async void GetImages(AppPreferences ap)
        {
            if (!String.IsNullOrEmpty(imageNames[0]))
            {
                Bitmap bit = ap.SetImageBitmap(_dir + "/" + imageNames[0]);
                if (bit != null)
                {
                    facilityPhoto.SetImageBitmap(bit);
                }
                else if (bit == null && !String.IsNullOrEmpty(imageNames[0]))
                {
                    PictureViewModel pictureViewModel = new PictureViewModel();
                    Models.Picture   picture          = await pictureViewModel.ExecuteGetPictureCommand(imageNames[0]);

                    if (picture != null)
                    {
                        var _bit = ap.StringToBitMap(picture.File);
                        if (_bit != null)
                        {
                            ap.SaveImage(_bit, imageNames[0]);
                        }
                        facilityPhoto.SetImageBitmap(_bit);
                    }
                }
            }
            if (imageNames.Count > 1)
            {
                Bitmap bit = ap.SetImageBitmap(_dir + "/" + imageNames[1]);
                if (bit != null)
                {
                    secondFacilityPhoto.SetImageBitmap(bit);
                }
                else if (bit == null && !String.IsNullOrEmpty(imageNames[1]))
                {
                    PictureViewModel pictureViewModel = new PictureViewModel();
                    Models.Picture   picture          = await pictureViewModel.ExecuteGetPictureCommand(imageNames[1]);

                    if (picture != null)
                    {
                        var _bit = ap.StringToBitMap(picture.File);
                        if (_bit != null)
                        {
                            ap.SaveImage(_bit, imageNames[1]);
                        }
                        secondFacilityPhoto.SetImageBitmap(_bit);
                    }
                }
            }
        }
Esempio n. 3
0
        // Replace the contents of a view (invoked by the layout manager)
        public async override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
        {
            var            item           = viewModel.Facilities[position];
            Context        mContext       = Android.App.Application.Context;
            AppPreferences appPreferences = new AppPreferences(mContext);

            // Replace the contents of the view with that element
            var myHolder = holder as MyViewHolder;

            myHolder.FacilityName.Text = item.Name;
            myHolder.ClientCode.Text   = item.ClientCode;
            myHolder.Button.Click     += (sender, e) => {
                Submit_Click(item);
            };
            myHolder.Location.LongClick += (sender, e) => {
                Open_Map(item.Location.GPSCoordinates.Latitude, item.Location.GPSCoordinates.Longitude);
            };
            if (item.Location != null)
            {
                myHolder.StreetAddress.Text = String.Format("Address: {0}", item.Location.StreetAddress);
                myHolder.Suburb.Text        = String.Format("               {0}", item.Location.Suburb);
                if (item.Location.GPSCoordinates != null)
                {
                    myHolder.Location.Text = String.Format("Lat: {0} Long: {1}", item.Location.GPSCoordinates.Latitude, item.Location.GPSCoordinates.Longitude);
                }
            }

            myHolder.Location.Text = String.Format("Lat: {0} Long: {1}", 0, 0);
            if (item.Location != null)
            {
                if (item.Location.GPSCoordinates != null)
                {
                    myHolder.Location.Text = String.Format("Lat: {0} Long: {1}", item.Location.GPSCoordinates.Latitude, item.Location.GPSCoordinates.Longitude);
                }
            }

            if (item.IDPicture != null)
            {
                List <string> imageNames = item.IDPicture.Split(',').ToList();

                AppPreferences ap  = new AppPreferences(Android.App.Application.Context);
                Bitmap         bit = ap.SetImageBitmap(ap.CreateDirectoryForPictures() + "/" + imageNames[0]);
                if (bit != null)
                {
                    myHolder.ImageView.SetImageBitmap(bit);
                }
                else
                {
                    PictureViewModel pictureViewModel = new PictureViewModel();
                    Models.Picture   picture          = await pictureViewModel.ExecuteGetPictureCommand(imageNames[0]);

                    if (picture != null)
                    {
                        var _bit = ap.StringToBitMap(picture.File);
                        if (_bit != null)
                        {
                            myHolder.ImageView.SetImageBitmap(_bit);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        protected async override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            building  = new Building();
            ViewModel = new BuildingsViewModel();
            AppPreferences ap = new AppPreferences(Android.App.Application.Context);

            facilityId = Convert.ToInt32(ap.GetFacilityId());
            userId     = Convert.ToInt32(ap.GetUserId());

            var data = Intent.GetStringExtra("data");

            // Create your application here

            saveButton            = FindViewById <FloatingActionButton>(Resource.Id.save_button);
            occupationYear        = FindViewById <EditText>(Resource.Id.etb_occupationyear);
            occupationyearLayout  = FindViewById <TextInputLayout>(Resource.Id.occupationyear_layout);
            gpscAddLocationButton = FindViewById <FloatingActionButton>(Resource.Id.gpscaddlocation_button);
            locationLinearlayout  = FindViewById <LinearLayout>(Resource.Id.blocation_linearlayout);
            tvbLatitude           = FindViewById <TextView>(Resource.Id.tvb_latitude);
            tvbLongitude          = FindViewById <TextView>(Resource.Id.tvb_longitude);
            buildingPhoto         = FindViewById <ImageView>(Resource.Id.imgb_buildingphoto);
            _GPSCoordinates       = new GPSCoordinate();
            buildingName          = FindViewById <EditText>(Resource.Id.etb_name);
            buildingType          = FindViewById <Spinner>(Resource.Id.sf_buildingtype);
            buildingstandard      = FindViewById <Spinner>(Resource.Id.sf_buildingstandard);
            utilisationStatus     = FindViewById <EditText>(Resource.Id.etb_utilisationstatus);
            nooOfFoors            = FindViewById <EditText>(Resource.Id.etb_nooffloors);
            totalFootprintAream2  = FindViewById <EditText>(Resource.Id.etb_totalfootprintaream2);
            totalImprovedaAeam2   = FindViewById <EditText>(Resource.Id.etb_totalimprovedaream2);
            heritage                = FindViewById <Switch>(Resource.Id.sf_heritage);
            disabledAccesss         = FindViewById <Spinner>(Resource.Id.sf_disabledaccesss);
            disabledComment         = FindViewById <EditText>(Resource.Id.etb_disabledcomment);
            constructionDescription = FindViewById <EditText>(Resource.Id.etb_constructiondescription);
            accuracyMessage         = FindViewById <TextView>(Resource.Id.accuracy_message);
            refashAccuracy          = FindViewById <FloatingActionButton>(Resource.Id.refreshaccuracy_button);
            refashAccuracy.Click   += RefashAccuracy_Click;


            _dir = ap.CreateDirectoryForPictures();
            Android.Content.Res.ColorStateList csl = new Android.Content.Res.ColorStateList(new int[][] { new int[0] }, new int[] { Android.Graphics.Color.ParseColor("#008000") }); gpscAddLocationButton.BackgroundTintList = csl;
            locationLinearlayout.Visibility = ViewStates.Gone;

            if (data != null)
            {
                building = Newtonsoft.Json.JsonConvert.DeserializeObject <Building>(data);
                isEdit   = true;
                SupportActionBar.Title = "Edit Building";
                occupationYear.Text    = building.OccupationYear;
                if (building.GPSCoordinates != null)
                {
                    tvbLatitude.Text  = "Lat: " + building.GPSCoordinates.Latitude;
                    tvbLongitude.Text = "Long: " + building.GPSCoordinates.Longitude;
                    _GPSCoordinates   = building.GPSCoordinates;
                    locationLinearlayout.Visibility = ViewStates.Visible;
                }
                buildingName.Text = building.BuildingName;
                buildingType.SetSelection(GetIndex(buildingType, building.BuildingType));
                buildingstandard.SetSelection(GetIndex(buildingstandard, building.BuildingStandard));
                disabledAccesss.SetSelection(GetIndex(disabledAccesss, building.DisabledAccess));
                utilisationStatus.Text       = building.Status;
                nooOfFoors.Text              = Convert.ToString(building.NumberOfFloors);
                totalFootprintAream2.Text    = Convert.ToString(building.FootPrintArea);
                totalImprovedaAeam2.Text     = Convert.ToString(building.ImprovedArea);
                heritage.Checked             = building.Heritage;
                disabledComment.Text         = building.DisabledComment;
                constructionDescription.Text = building.ConstructionDescription;

                Bitmap bit = SetImageBitmap(_dir + "/" + building.Photo);
                if (bit != null)
                {
                    buildingPhoto.SetImageBitmap(bit);
                }
                else if (bit == null && !String.IsNullOrEmpty(building.Photo))
                {
                    PictureViewModel pictureViewModel = new PictureViewModel();
                    Models.Picture   picture          = await pictureViewModel.ExecuteGetPictureCommand(building.Photo);

                    if (picture != null)
                    {
                        var _bit = ap.StringToBitMap(picture.File);
                        if (_bit != null)
                        {
                            SaveImage(_bit, building.Photo);
                        }
                        buildingPhoto.SetImageBitmap(_bit);
                    }
                }
            }
            else
            {
                SupportActionBar.Title = "Add New Building";
            }
            saveButton.Click += SaveButton_Click;
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.SetHomeButtonEnabled(true);
            gpscAddLocationButton.Click += AddLocation_Click;
            buildingPhoto.Click         += (sender, e) => { ShowImage_Click(); };

            GPSTracker GPSTracker = new GPSTracker();

            Android.Locations.Location location = GPSTracker.GPSCoordinate();
            if (location != null)
            {
                accuracyMessage.Text = String.Format("Accurate to {0} Meters", location.Accuracy.ToString());
            }
        }
        protected async override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            building       = new Building();
            ViewModel      = new BuildingsViewModel();
            appPreferences = new AppPreferences(Application.Context);
            facilityId     = Convert.ToInt32(appPreferences.GetFacilityId());
            userId         = Convert.ToInt32(appPreferences.GetUserId());
            helpers        = new UIHelpers();
            var data = Intent.GetStringExtra("data");

            occupationYear        = FindViewById <EditText>(Resource.Id.etb_occupationyear);
            occupationyearLayout  = FindViewById <TextInputLayout>(Resource.Id.occupationyear_layout);
            gpscAddLocationButton = FindViewById <ImageView>(Resource.Id.gpscaddlocation_button);
            tvblatLang            = FindViewById <TextView>(Resource.Id.tvf_latLang);
            buildingPhoto         = FindViewById <ImageView>(Resource.Id.imgb_buildingphoto);
            _GPSCoordinates       = new GPSCoordinate();
            buildingName          = FindViewById <EditText>(Resource.Id.etb_name);
            buildingType          = FindViewById <Spinner>(Resource.Id.sf_buildingtype);
            buildingstandard      = FindViewById <Spinner>(Resource.Id.sf_buildingstandard);
            utilisationStatus     = FindViewById <EditText>(Resource.Id.etb_utilisationstatus);
            nooOfFoors            = FindViewById <EditText>(Resource.Id.etb_nooffloors);
            totalFootprintAream2  = FindViewById <EditText>(Resource.Id.etb_totalfootprintaream2);
            totalImprovedaAeam2   = FindViewById <EditText>(Resource.Id.etb_totalimprovedaream2);
            heritage                = FindViewById <Switch>(Resource.Id.sf_heritage);
            disabledAccesss         = FindViewById <Spinner>(Resource.Id.sf_disabledaccesss);
            disabledComment         = FindViewById <EditText>(Resource.Id.etb_disabledcomment);
            constructionDescription = FindViewById <EditText>(Resource.Id.etb_constructiondescription);
            accuracyMessage         = FindViewById <TextView>(Resource.Id.accuracy_message);
            refashAccuracy          = FindViewById <ImageView>(Resource.Id.refreshaccuracy_button);
            refashAccuracy.Click   += RefashAccuracy_Click;

            _dir = appPreferences.CreateDirectoryForPictures();

            if (data != null)
            {
                building = Newtonsoft.Json.JsonConvert.DeserializeObject <Building>(data);
                isEdit   = true;
                SupportActionBar.Title = "Edit Building";
                occupationYear.Text    = building.OccupationYear;
                if (building.GPSCoordinates != null)
                {
                    tvblatLang.Text = "Lat: " + building.GPSCoordinates.Latitude + " Long: " + building.GPSCoordinates.Longitude;
                    _GPSCoordinates = building.GPSCoordinates;
                }
                buildingName.Text = building.BuildingName;
                buildingType.SetSelection(helpers.GetSpinnerIndex(buildingType, building.BuildingType));
                buildingstandard.SetSelection(helpers.GetSpinnerIndex(buildingstandard, building.BuildingStandard));
                disabledAccesss.SetSelection(helpers.GetSpinnerIndex(disabledAccesss, building.DisabledAccess));
                utilisationStatus.Text       = building.Status;
                nooOfFoors.Text              = Convert.ToString(building.NumberOfFloors);
                totalFootprintAream2.Text    = Convert.ToString(building.FootPrintArea);
                totalImprovedaAeam2.Text     = Convert.ToString(building.ImprovedArea);
                heritage.Checked             = building.Heritage;
                disabledComment.Text         = building.DisabledComment;
                constructionDescription.Text = building.ConstructionDescription;

                Bitmap bit = SetImageBitmap(_dir + "/" + building.Photo);
                if (bit != null)
                {
                    buildingPhoto.SetImageBitmap(bit);
                }
                else if (bit == null && !String.IsNullOrEmpty(building.Photo))
                {
                    PictureViewModel pictureViewModel = new PictureViewModel();
                    Models.Picture   picture          = await pictureViewModel.ExecuteGetPictureCommand(building.Photo);

                    if (picture != null)
                    {
                        var _bit = appPreferences.StringToBitMap(picture.File);
                        if (_bit != null)
                        {
                            SaveImage(_bit, building.Photo);
                        }
                        buildingPhoto.SetImageBitmap(_bit);
                    }
                }
            }
            else
            {
                SupportActionBar.Title = "Add New Building";
            }
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.SetHomeButtonEnabled(true);
            gpscAddLocationButton.Click += AddLocation_Click;
            buildingPhoto.Click         += (sender, e) => { ShowImage_Click(); };

            GPSTracker GPSTracker = new GPSTracker();

            Android.Locations.Location location = GPSTracker.GPSCoordinate();
            if (location != null)
            {
                accuracyMessage.Text = String.Format("Accurate to {0} Meters", location.Accuracy.ToString());
            }

            Toolbar.MenuItemClick += (sender, e) =>
            {
                var itemTitle = e.Item.TitleFormatted;
                switch (itemTitle.ToString())
                {
                case "Log Out":
                    var intent = new Intent(this, typeof(LoginActivity));
                    appPreferences.SaveUserId("0");
                    StartActivity(intent);
                    break;

                case "Save":
                    SaveBuilding();
                    break;
                }
            };
        }