/// <summary> /// Save the current tasks to the device. /// </summary> /// <remarks> /// Example of MAM policy - allow saving to device. /// A manual check of the current MAM policy must be performed to determine whether or not saving to the device is allowed. /// NOTE: If the user's policy asks the app to encrypt files, the output of this process will also be encrypted. /// </remarks> /// <param name="doc">The formatted CSV string representation of the current tasks.</param> public void Save(string doc) { if (!MAMPolicyManager.GetPolicy(Application.Context).GetIsSaveToLocationAllowed(SaveLocation.Local, Authenticator.User)) { Toast.MakeText(Application.Context, Resource.String.err_not_allowed, ToastLength.Long).Show(); return; } // Confirm we're allowed to save to this device, ask for permission if not. ConfirmWritePermission(); // Get the default location for the export. File exportFile = new File(Android.OS.Environment.ExternalStorageDirectory, "tasks.csv"); // Now try to write the document to their device. try { PrintWriter writer = new PrintWriter(exportFile); writer.Append(doc); writer.Flush(); } catch (IOException e) { Toast.MakeText(Application.Context, e.Message, ToastLength.Long).Show(); return; } // And try to open it. Will be blocked by MAM if necessary Toast.MakeText(Application.Context, Application.Context.GetString(Resource.String.save_success, exportFile.Path), ToastLength.Short).Show(); OpenFile(exportFile); }
private void Indent(PrintWriter @out, int indent) { for (int i = 0; i < indent; ++i) { @out.Append(" "); } }
/// <summary> /// Save the file to device. /// </summary> public void SaveFile() { // Create the CSV task document string doc = TaskManager.CreateCSVDocument(); // Confirm we're allowed to save to this device, ask for permission if not. ConfirmWritePermission(); // Get the default location for the export. File exportFile = new File(Android.OS.Environment.ExternalStorageDirectory, "tasks.csv"); // Now try to write the document to their device. try { PrintWriter writer = new PrintWriter(exportFile); writer.Append(doc); writer.Flush(); } catch (IOException e) { Toast.MakeText(context, e.Message, ToastLength.Long).Show(); return; } // And try to open it. Will be blocked by MAM if necessary Toast.MakeText(context, context.GetString(Resource.String.save_success, exportFile.Path), ToastLength.Short).Show(); OpenFile(exportFile); }
private void PrepareHeidelTimeInput(PrintWriter stream, ICoreMap document) { // We really should use the full text annotation because our cleanxml can be useless. foreach (ICoreMap sentence in document.Get(typeof(CoreAnnotations.SentencesAnnotation))) { foreach (CoreLabel token in sentence.Get(typeof(CoreAnnotations.TokensAnnotation))) { string text = token.OriginalText(); stream.Append(Translate.GetOrDefault(text, text)); // HACK: will not handle contractions like "del = de + el" properly -- will be deel. // stream.append(token.after().length() > 0 ? " " : ""); // HACK: will not handle things like 12-abr-2011 which are chunked up properly into 12 - abr-2011. stream.Append(" "); } stream.Append("\n"); } }