internal Settings Read() { Settings settings; try { Java.IO.File file = new Java.IO.File(dataDir); if (file.Exists()) { settings = ReadSpecialFolder(); } else { settings = ReadDefault(); } file.Dispose(); return(settings); } catch (System.Exception ex) { #region Logging LogRuntimeAttribute.InLogFiles(typeof(CrudSettings), ex); #endregion return(null); } finally { } }
internal bool Delete() { try { bool isDeleteFile = false; Java.IO.File file = new Java.IO.File(dataDir); isDeleteFile = file.Delete(); file.Dispose(); return(isDeleteFile); } catch (System.Exception ex) { #region Logging LogRuntimeAttribute.InLogFiles(typeof(CrudSettings), ex); #endregion return(false); } finally { } }
public static List <ClipData.Item> AsClipDataItems(this IMimeItemCollection mimeItemCollection) { ClipboardContentProvider.Clear(); var result = new List <ClipData.Item>(); string text = null; string html = null; // this has to happen because GMAIL will only paste the first "text/html" AND it won't parse correctly unless it is supplied as ClipData.Item(string,string) foreach (var item in mimeItemCollection.Items) { if (text == null && item.MimeType == "text/plain") { text = item.Value as string; } else if (html == null && item.MimeType == "text/html") { html = item.Value as string; } } if (html != null) { result.Add(new ClipData.Item(text ?? html, html)); } else if (text != null) { result.Add(new ClipData.Item(text)); } foreach (var item in mimeItemCollection.Items) { ClipData.Item androidClipItem = null; // The following block was added to support copying images by intent. // However, I have yet to see where it actually works with 3rd party apps. // Maybe I'm not doing it right? // START OF BLOCK if (item.MimeType.StartsWith("image/", StringComparison.InvariantCultureIgnoreCase) || item.Value is FileInfo) { Java.IO.File file = null; if (item.Value is FileInfo fileInfo) { file = new Java.IO.File(fileInfo.FullName); } else if (item.Value is byte[] byteArray && MimeSharp.Current.Extension(item.MimeType) is List <string> extensions && extensions.Count > 0) { var ext = extensions[0]; var fileName = Guid.NewGuid() + "." + ext; var dir = P42.Utils.Environment.TemporaryStoragePath; var path = Path.Combine(dir, fileName); System.IO.File.WriteAllBytes(path, byteArray); file = new Java.IO.File(path); } if (file != null && file.Exists()) { Android.Net.Uri uri = Android.Net.Uri.FromFile(file); var intent = new Intent(Intent.ActionSend); intent.SetType(item.MimeType); intent.PutExtra(Intent.ExtraStream, uri); intent.SetFlags(ActivityFlags.GrantReadUriPermission); androidClipItem = new ClipData.Item(intent); } file?.Dispose(); } if (androidClipItem == null) { // END OF BLOCK androidClipItem = ClipboardContentProvider.AddAsClipDataItem(item); } result.Add(androidClipItem); } return(result); }
public static async void InLogFiles(Type type, Exception exception) { string pathCurrentFolder = String.Empty; string pathCurrentFile = String.Empty; settings = Settings.Instance; try { if (settings.IsLogErrorStorage == true) { TypeInfo typeInfo = type.GetTypeInfo(); TypeAttributes typeAttributes = typeInfo.Attributes; object[] attributes = typeInfo.GetCustomAttributes(true); if (attributes != null) { foreach (var item in attributes) { if (item.ToString() == (typeof(LogRuntimeAttribute)).FullName) { LogRuntimeAttribute logRun = (LogRuntimeAttribute)item; pathCurrentFolder = logRun.PathFolder; pathCurrentFile = logRun.PathFile; break; } } } PermissionStatus status = await Permissions.CheckStatusAsync <Permissions.StorageWrite>(); if (status == PermissionStatus.Granted) { if (pathCurrentFile != String.Empty) { Java.IO.File file = new Java.IO.File(pathCurrentFolder); file.Mkdir(); file = new Java.IO.File(pathCurrentFile); file.CreateNewFile(); FileWriter writer = new FileWriter(file); writer.Write(exception.ToString()); writer.Flush(); file.Dispose(); writer.Close(); writer.Dispose(); } } } } catch (System.Exception ex) { } finally { } }