public override bool OnShowFileChooser(Android.Webkit.WebView webView, IValueCallback filePathCallback, FileChooserParams fileChooserParams) { List <string> items = new List <string>() { AppResources.CameraFileChooser, AppResources.GaleriePhotoFileChooser, AppResources.DocumentFileChooser }; string selectedItem = items[0]; int resultCode = 0; var appActivity = context as MainActivity; new AlertDialog.Builder(appActivity) .SetSingleChoiceItems(items.ToArray(), 0, (sender, e) => { selectedItem = items[e.Which]; System.Diagnostics.Debug.WriteLine(selectedItem); }) .SetPositiveButton("OK", (sender, e) => { Intent intent = null; if (selectedItem == AppResources.CameraFileChooser) { intent = new Intent(MediaStore.ActionImageCapture); CreateDirectoryForPictures(); _file = new File(_dir, String.Format("Pic_{0}.png", NoSeqGenerator.Generate())); intent.PutExtra(MediaStore.ExtraOutput, Android.Net.Uri.FromFile(_file)); resultCode = CAMERA_RESULTCODE; } else if (selectedItem == AppResources.GaleriePhotoFileChooser) { intent = new Intent(Intent.ActionGetContent); intent.SetType("image/*"); resultCode = IMAGE_CHOOSER_RESULTCODE; } else if (selectedItem == AppResources.DocumentFileChooser) { intent = fileChooserParams.CreateIntent(); resultCode = FILECHOOSER_RESULTCODE; } if (intent != null) { intent.PutExtra("PheidiParams", JsonConvert.SerializeObject(FileChooserPheidiParams)); mUploadMessage = filePathCallback; appActivity.StartActivity(intent, resultCode, OnActivityResult); } }).Show(); return(true); }
public void SaveSystemCredentials(string username, string password) { if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password)) { Account account = new Account { Username = NoSeqGenerator.Generate() }; account.Properties.Add("Password", password); account.Properties.Add("IsSystem", true.ToString()); account.Properties.Add("ServerNoseq", ""); account.Properties.Add("Username", username); AccountStore.Create().Save(account, App.AppName); } }
/// <summary> /// Saves the credentials. /// </summary> /// <param name="username">Username.</param> /// <param name="password">Password.</param> public string SaveCredentials(string username, string password, string systemCredentialsNoseq) { string noseq = ""; if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password)) { noseq = NoSeqGenerator.Generate(); Account account = new Account { Username = noseq }; account.Properties.Add("Password", password); account.Properties.Add("IsSystem", false.ToString()); account.Properties.Add("ServerNoseq", App.CurrentServer.Noseq); account.Properties.Add("Username", username); account.Properties.Add("SystemCredentialsNoseq", systemCredentialsNoseq); AccountStore.Create(Forms.Context).Save(account, App.AppName); } return noseq; }
static public void ImageImport(UIImagePickerControllerSourceType sourceType, NSUrlRequest request) { var imagePicker = new UIImagePickerController { SourceType = sourceType }; imagePicker.FinishedPickingMedia += (send, ev) => { var image = (UIImage)ev.Info.ObjectForKey(new NSString("UIImagePickerControllerOriginalImage")); var filename = String.Format("Pic_{0}.png", NoSeqGenerator.Generate()); var filepath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), filename); using (NSData imageData = image.AsPNG()) { Byte[] byteArray = new Byte[imageData.Length]; System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, byteArray, 0, Convert.ToInt32(imageData.Length)); App.FileHelper.SaveImage(filepath, byteArray); } UIApplication.SharedApplication.KeyWindow.RootViewController.DismissViewController(true, null); var imageEditor = new PheidiTOCropViewController(image); imageEditor.OnEditFinished(() => { var param = request.Body.ToString().Split('&'); PheidiParams pp = new PheidiParams(); int index = 0; for (int i = 0; i < param.Length; i++) { if (param[i].Contains("pheidiparams")) { pp.Load(WebUtility.UrlDecode(param[i])); index = i; } } image = imageEditor.FinalImage; if (image != null) { using (NSData imageData = image.AsJPEG()) { Byte[] byteArray = new Byte[imageData.Length]; System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, byteArray, 0, Convert.ToInt32(imageData.Length)); App.FileHelper.SaveImage(filepath, byteArray); } if (App.NetworkManager.GetHostServerState() == NetworkState.Reachable && (App.NetworkManager.GetNetworkState() == NetworkState.ReachableViaWiFiNetwork || App.WifiOnlyEnabled == false)) { Task.Run(async() => { await UploadImageToServer(image, filename, filepath, pp); }); } else { string title = ""; string message = ""; if (App.NetworkManager.GetHostServerState() == NetworkState.NotReachable) { title = AppResources.Alerte_ImageUploadHoteInacessibleTitle; message = AppResources.Alerte_ImageUploadHoteInacessibleMessage; } else if (App.WifiOnlyEnabled) { title = AppResources.Alerte_ImageUploadPasDeWifiTitle; message = AppResources.Alerte_ImageUploadPasDeWifiMessage; } App.NotificationManager.DisplayAlert(message, title, "OK", () => { }); Task.Run(async() => { var iu = new ImageUpload() { FileName = filename, FilePath = filepath, Field = pp["FIELD"], QueryFieldValue = pp["NOSEQ"], User = App.UserNoseq, ServerNoseq = App.CurrentServer.Noseq }; await DatabaseHelper.Database.SaveItemAsync(iu); }); } } }); UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(imageEditor, true, () => { }); }; imagePicker.Canceled += (send, ev2) => { UIApplication.SharedApplication.KeyWindow.RootViewController.DismissViewController(true, null); }; UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(imagePicker, true, null); }