Closed Aoi-hosizora closed 5 years ago
记录,鸵鸟算法+1
/**
* 具体保存笔记过程,SavingFileAsNote()用
* @param Path
* @param mnote
*/
private void SavingDocxPdfAsNote(final boolean isSaveAsDocx, final String Path, final Note mnote) {
ShowLogE("SavingDocxAsNote", "Path: " + Path);
class HasDismiss {
private boolean dismiss = false;
HasDismiss() {}
void setDismiss() { this.dismiss = true; }
boolean getDismiss() { return this.dismiss; }
}
final HasDismiss isHasDismiss = new HasDismiss();
String Msg = String.format(getResources().getString(R.string.VMNoteActivity_SavingDataMessage), isSaveAsDocx ? "Docx" : "Pdf", Path);
savingDialog.setTitle(getResources().getString(R.string.VMNoteActivity_SavingData));
savingDialog.setMessage(Msg);
savingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
// 取消保存
isHasDismiss.setDismiss();
}
});
savingDialog.show();
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(200);
}
catch (InterruptedException ex) {
ex.printStackTrace();
}
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
if (isSaveAsDocx)
ToDocUtil.CreateDocxByNote(Path, mnote.getTitle(), mnote.getContent(), true);
else
ToDocUtil.CreatePdfByNote(Path, mnote.getTitle(), mnote.getContent(), true);
if (!isHasDismiss.getDismiss()) {
if (savingDialog != null)
savingDialog.dismiss();
Toast.makeText(ViewModifyNoteActivity.this, "文件 " + Path + " 保存成功。", Toast.LENGTH_SHORT).show();
}
else {
ShowLogE("SavingDocxPdfAsNote", "Saning is HasDismiss");
File f = new File(Path);
if (f.exists())
f.delete();
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
});
}
}).start();
}