Skip to content
Permalink
311a0767f8
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
132 lines (108 sloc) 3.86 KB
using Android.Graphics;
using Plugin.Media;
using Plugin.Media.Abstractions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UEngage.Models;
using Xamarin.Essentials;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace UEngage
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Report : ContentPage
{
public string imageLocation="";
byte[] imageBytes = null;
Xamarin.Essentials.Location location;
public Report()
{
InitializeComponent();
getlocation();
//imageLocation = "/storage/emulated/0/Android/data/com.companyname.uengage/files/Pictures/SampleImages/18112020083437.jpg";
//btnCamera.Source = ImageSource.FromFile(imageLocation);
}
private async void getlocation()
{
try
{
location = await Geolocation.GetLastKnownLocationAsync();
if (location != null)
{
lat.Text = "Latitude : " + location.Latitude.ToString();
lon.Text = "Longitude : " + location.Longitude.ToString();
//Console.WriteLine($"Latitude: {location.Latitude}, Longitude: {location.Longitude}, Altitude: {location.Altitude}");
}
}
catch (FeatureNotSupportedException fnsEx)
{
// Handle not supported on device exception
}
catch (FeatureNotEnabledException fneEx)
{
// Handle not enabled on device exception
}
catch (PermissionException pEx)
{
// Handle permission exception
}
catch (Exception ex)
{
// Unable to get location
}
}
private async void btnsubmit_Clicked(object sender, EventArgs e)
{
Report_ report = new Report_()
{
latitude = lat.Text,
Longitude = lon.Text,
Date = DateTime.Now.Date,
Description=txtDescription.Text,
Username= Constant.loggedUser.Username,
reportType = (string)defectpicker.SelectedItem,
imagePath = imageLocation,
postCode = Constant.loggedUser.Postcode
};
busyIndi.IsVisible = true;
await App.Database.SaveReportAsync(report);
await Task.Delay(1000);
busyIndi.IsVisible = false;
await DisplayAlert("", " Report submitted", "Ok");
txtDescription.Text = "";
defectpicker.SelectedIndex = -1;
btnCamera.Source = null;
}
private void btnCamera_Clicked(object sender, EventArgs e)
{
_=TakePhotoAsync();
}
async Task TakePhotoAsync()
{
await CrossMedia.Current.Initialize();
if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
await DisplayAlert("No Camera", ":( No camera available.", "OK");
return;
}
string imagename = DateTime.Now.ToString("ddMMyyyHHmmss") + ".jpg";
MediaFile file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
{
Directory = "SampleImages",
Name = imagename
});
if (file == null)
return;
//lblfilelocation.Text = "Image saved Location : " + file.Path;
imageLocation = file.Path;
btnCamera.Source = ImageSource.FromStream(() =>
{
var stream = file.GetStream();
return stream;
});
}
}
}