我想在Android Studio的函数中使用progress dialog。在执行代码之前,此表单将出现:
protected boolean encryptFile() {
/*
* set input file name
*/
String encryptFileName = mEditText.getText().toString();
/*
* set hint
*/
String hint = mHintText.getText().toString();
if(hint.isEmpty()){hint=null;}
/*
* set password
*/
String password = mPassText.getText().toString();
/*
* select encrypted file name
*/
String encryptedFileName = mEditText.getText().toString()+".enc";
if(hint!=null){
encryptedFileName = mEditText.getText().toString() + "(hint-" +hint+ ").enc";
}
/*
* Encrypt
*/
try {
AESCrypt crypt = new AESCrypt(password);
crypt.encrypt(2, encryptFileName, encryptedFileName);
return true;
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (GeneralSecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
public void encrypt(int version, String fromPath, String toPath)
throws IOException, GeneralSecurityException {
InputStream in = null;
OutputStream out = null;
try {
in = new BufferedInputStream(new FileInputStream(fromPath));
debug("Opened for reading: " + fromPath);
out = new BufferedOutputStream(new FileOutputStream(toPath));
debug("Opened for writing: " + toPath);
encrypt(version, in, out);
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
}