public override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (resultCode == Result.Ok) { // Make it available in the gallery // Intent mediaScanIntent = new Intent (Intent.ActionMediaScannerScanFile); // Android.Net.Uri contentUri = Android.Net.Uri.FromFile (file); // mediaScanIntent.SetData (contentUri); // // Activity.SendBroadcast (mediaScanIntent); // AttendancePhoto attPhoto = new AttendancePhoto() { photoPath = file.ToString(), stamp = DateTime.Now, subType = currentPhotoSubTypes[spnPhotoSubTypes.SelectedItemPosition].id }; //Latitude and Longitude ExifInterface exif = new ExifInterface(attPhoto.photoPath); float[] lat_long = new float[2]; if (exif.GetLatLong(lat_long)) { attPhoto.latitude = lat_long [0]; attPhoto.longitude = lat_long [1]; } newAttendancePhotos.Add(attPhoto); AttendancePhotoManager.SetCurrentAttendancePhotos(newAttendancePhotos); RefreshPhotoList(); } // Dispose of the Java side bitmap. GC.Collect(); }
void RefreshContent() { llSyncItems.RemoveAllViews(); queue = (List <SyncQueue>)SyncQueueManager.GetSyncQueue(selectedDate); foreach (var q in queue) { View view = LayoutInflater.Inflate(Resource.Layout.SyncFragmentItem, null); RelativeLayout rl = view.FindViewById <RelativeLayout> (Resource.Id.sfiRelativeLayout); ImageView iv = view.FindViewById <ImageView> (Resource.Id.sfiStatusImage); TextView type = view.FindViewById <TextView> (Resource.Id.sfiTypeInfoText); TextView loc = view.FindViewById <TextView> (Resource.Id.sfiLocationText); try { if (q.isSync) { rl.SetBackgroundColor(Android.Graphics.Color.LightGreen); iv.SetImageResource(Resource.Drawable.ic_check_circle_white_36dp); type.SetTextAppearance(this, Resource.Style.text_success); loc.SetTextAppearance(this, Resource.Style.text_success_small); } else { rl.SetBackgroundColor(Android.Graphics.Color.LightPink); iv.SetImageResource(Resource.Drawable.ic_highlight_off_white_36dp); type.SetTextAppearance(this, Resource.Style.text_danger); loc.SetTextAppearance(this, Resource.Style.text_danger_small); } Attendance att = null; Pharmacy pharm = null; switch (q.type) { case SyncQueueType.sqtAttendance: att = AttendanceManager.GetAttendance(q.itemID); pharm = PharmacyManager.GetPharmacy(att.pharmacy); type.Text = string.Format(@"Тип: Посещение аптеки {0} за дату {1}", pharm.fullName, att.date.ToString(@"d")); loc.Text = string.Format(@"Размещение: {0}", q.fileLocation); break; case SyncQueueType.sqtAttendanceResult: AttendanceResult attRes = AttendanceResultManager.GetAttendanceResult(q.itemID); att = AttendanceManager.GetAttendance(attRes.attendance); pharm = PharmacyManager.GetPharmacy(att.pharmacy); type.Text = string.Format(@"Тип: Значение по препарату в посещение аптеки {0} за дату {1}", pharm.fullName, att.date.ToString(@"d")); loc.Text = string.Format(@"Размещение: {0}", q.fileLocation); break; case SyncQueueType.sqtAttendanceGPSPoint: AttendanceGPSPoint attGPS = AttendanceGPSPointManager.GetAttendanceGPSPoint(q.itemID); att = AttendanceManager.GetAttendance(attGPS.attendance); pharm = PharmacyManager.GetPharmacy(att.pharmacy); type.Text = string.Format(@"Тип: GPS значение в посещение аптеки {0} за дату {1} - lat:{2}, lon:{3}", pharm.fullName, att.date.ToString(@"d"), attGPS.latitude, attGPS.longitude); loc.Text = string.Format(@"Размещение: {0}", q.fileLocation); break; case SyncQueueType.sqtAttendancePhoto: AttendancePhoto attPho = AttendancePhotoManager.GetAttendancePhoto(q.itemID); type.Text = string.Format(@"Фото: {0}", attPho.photoPath); loc.Text = q.fileLocation; break; default: type.Text = @"Неизвестный тип файла"; type.SetTextColor(Android.Graphics.Color.DarkRed); break; } } catch (Exception ex) { type.Text = @"Error:"; loc.Text = ex.Message; } llSyncItems.AddView(view); } }
void UpLoadAttendancePhotos() { string cookieName = string.Empty; string cookieValue = string.Empty; var user = Common.GetCurrentUser(); var login = new RestClient(Settings.URLs.Host); //login.Authenticator = new SimpleAuthenticator("identifier", "*****@*****.**", "password", "q1234567"); login.Authenticator = new SimpleAuthenticator(@"identifier", user.username, @"password", user.password); login.CookieContainer = new CookieContainer(); var loginReq = new RestRequest(@"auth/local", Method.POST); var loginRes = login.Execute <User>(loginReq); User userRes = loginRes.Data; if (userRes == null) { RunOnUiThread(() => progressDialog.SetMessage(@"Не удалось пройти аутентификацию!")); } cookieName = loginRes.Cookies[0].Name; cookieValue = loginRes.Cookies[0].Value; var queueToUpload = (List <SyncQueue>)SyncQueueManager.GetSyncQueue(selectedDate); foreach (var q in queueToUpload) { try { if ((q.type == SyncQueueType.sqtAttendancePhoto) && (!q.isSync)) { //Debug.WriteLine(@"Получение информации о себе.", @"Info"); AttendancePhoto attendancePhoto = SyncQueueManager.GetAttendancePhoto(q.fileLocation); //Attendance attendance = AttendanceManager.GetAttendance (attendancePhoto.attendance); RunOnUiThread(() => progressDialog.SetMessage(string.Format(@"Загрузка фото с id {0} по посещению с id:{1}", attendancePhoto.id, attendancePhoto.attendance))); var client = new RestClient(Settings.URLs.Host); // var request = new RestRequest (@"AttendancePhoto/create?attendance={attendance}&longitude={longitude}&latitude={latitude}&stamp={stamp}", Method.POST); var request = new RestRequest(@"AttendancePhoto/create?localID={localID}&attendance={attendance}&longitude={longitude}&latitude={latitude}&subType={subType}", Method.POST); request.AddCookie(cookieName, cookieValue); request.AddUrlSegment(@"localID", attendancePhoto.id.ToString()); request.AddUrlSegment(@"attendance", attendancePhoto.attendance.ToString()); request.AddUrlSegment(@"longitude", attendancePhoto.longitude.ToString(CultureInfo.CreateSpecificCulture("en-GB"))); request.AddUrlSegment(@"latitude", attendancePhoto.latitude.ToString(CultureInfo.CreateSpecificCulture("en-GB"))); request.AddUrlSegment(@"subType", attendancePhoto.subType.ToString()); // request.AddUrlSegment(@"stamp", attendancePhoto.stamp.ToString()); request.AddFile(@"photo", File.ReadAllBytes(attendancePhoto.photoPath), Path.GetFileName(attendancePhoto.photoPath), string.Empty); var response = client.Execute(request); switch (response.StatusCode) { case HttpStatusCode.OK: case HttpStatusCode.Created: // case HttpStatusCode.U q.isSync = true; SyncQueueManager.SaveSyncQueue(q, false); // Thread.Sleep (500); RunOnUiThread(() => { progressDialog.SetMessage(string.Format(@"Фото с id {0} по посещению с id:{1}"" ЗАГРУЖЕНО!", attendancePhoto.id, attendancePhoto.attendance)); // RefreshContent(); }); continue; default: // Thread.Sleep (500); RunOnUiThread(() => progressDialog.SetMessage(@"Не удалось загрузить фото по посещению!")); // Thread.Sleep (1500); continue; } } } catch (Exception ex) { RunOnUiThread(() => progressDialog.SetMessage(@"Error : " + ex.Message)); // Thread.Sleep (1500); continue; } } }