Export is cancellable now

This commit is contained in:
grait
2014-03-11 01:37:16 +05:30
parent 217f4a1cef
commit 3f649d4458
3 changed files with 52 additions and 16 deletions

View File

@@ -50,15 +50,28 @@ import android.os.Bundle;
import android.os.Environment;
public class PgpImportExport {
public interface KeychainServiceListener{
public boolean hasServiceStopped();
}
private Context mContext;
private ProgressDialogUpdater mProgress;
private KeychainServiceListener mKeychainServiceListener;
public PgpImportExport(Context context, ProgressDialogUpdater progress) {
super();
this.mContext = context;
this.mProgress = progress;
}
public PgpImportExport(Context context, ProgressDialogUpdater progress, KeychainServiceListener keychainListener){
super();
this.mContext = context;
this.mProgress = progress;
this.mKeychainServiceListener = keychainListener;
}
public void updateProgress(int message, int current, int total) {
if (mProgress != null) {
mProgress.setProgress(message, current, total);
@@ -188,8 +201,10 @@ public class PgpImportExport {
if (secretKeyRing != null) {
secretKeyRing.encode(arOutStream);
}
// Else if it's a public key get the PGPPublicKeyRing
// and encode that to the output
if(mKeychainServiceListener.hasServiceStopped()==true){
arOutStream.close();
return null;
}
} else {
updateProgress(i * 100 / rowIdsSize, 100);
PGPPublicKeyRing publicKeyRing =
@@ -198,6 +213,11 @@ public class PgpImportExport {
if (publicKeyRing != null) {
publicKeyRing.encode(arOutStream);
}
if(mKeychainServiceListener.hasServiceStopped() == true){
arOutStream.close();
return null;
}
}
arOutStream.close();