Merge branch 'master' of github.com:open-keychain/open-keychain
This commit is contained in:
@@ -18,7 +18,11 @@
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
@@ -47,7 +51,20 @@ public class BackupFragment extends Fragment {
|
||||
private int mIndex;
|
||||
|
||||
static final int REQUEST_REPEAT_PASSPHRASE = 1;
|
||||
private ExportHelper mExportHelper;
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
// we won't get attached to a non-fragment activity, so the cast should be safe
|
||||
mExportHelper = new ExportHelper((FragmentActivity) activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
mExportHelper = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
@@ -80,8 +97,7 @@ public class BackupFragment extends Fragment {
|
||||
}
|
||||
|
||||
if (!includeSecretKeys) {
|
||||
ExportHelper exportHelper = new ExportHelper(activity);
|
||||
exportHelper.showExportKeysDialog(null, Constants.Path.APP_DIR_FILE, false);
|
||||
startBackup(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -136,8 +152,7 @@ public class BackupFragment extends Fragment {
|
||||
return;
|
||||
}
|
||||
|
||||
ExportHelper exportHelper = new ExportHelper(activity);
|
||||
exportHelper.showExportKeysDialog(null, Constants.Path.APP_DIR_FILE, true);
|
||||
startBackup(true);
|
||||
}
|
||||
|
||||
}.execute(activity.getContentResolver());
|
||||
@@ -167,8 +182,19 @@ public class BackupFragment extends Fragment {
|
||||
return;
|
||||
}
|
||||
|
||||
ExportHelper exportHelper = new ExportHelper(getActivity());
|
||||
exportHelper.showExportKeysDialog(null, Constants.Path.APP_DIR_FILE, true);
|
||||
startBackup(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void startBackup(boolean exportSecret) {
|
||||
File filename;
|
||||
String date = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(new Date());
|
||||
if (exportSecret) {
|
||||
filename = new File(Constants.Path.APP_DIR, "keys_" + date + ".asc");
|
||||
} else {
|
||||
filename = new File(Constants.Path.APP_DIR, "keys_" + date + ".pub.asc");
|
||||
}
|
||||
mExportHelper.showExportKeysDialog(null, filename, exportSecret);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.support.v7.widget.DefaultItemAnimator;
|
||||
@@ -222,18 +221,6 @@ public class DecryptListFragment
|
||||
}
|
||||
}
|
||||
|
||||
private void askForOutputFilename(Uri inputUri, String originalFilename, String mimeType) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||
File file = new File(inputUri.getPath());
|
||||
File parentDir = file.exists() ? file.getParentFile() : Constants.Path.APP_DIR;
|
||||
File targetFile = new File(parentDir, originalFilename);
|
||||
FileHelper.saveFile(this, getString(R.string.title_decrypt_to_file),
|
||||
getString(R.string.specify_file_to_decrypt_to), targetFile, REQUEST_CODE_OUTPUT);
|
||||
} else {
|
||||
FileHelper.saveDocument(this, mimeType, originalFilename, REQUEST_CODE_OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
switch (requestCode) {
|
||||
@@ -534,7 +521,8 @@ public class DecryptListFragment
|
||||
return true;
|
||||
}
|
||||
mCurrentInputUri = model.mInputUri;
|
||||
askForOutputFilename(model.mInputUri, metadata.getFilename(), metadata.getMimeType());
|
||||
FileHelper.saveDocument(this, metadata.getFilename(), model.mInputUri, metadata.getMimeType(),
|
||||
R.string.title_decrypt_to_file, R.string.specify_file_to_decrypt_to, REQUEST_CODE_OUTPUT);
|
||||
return true;
|
||||
case R.id.decrypt_delete:
|
||||
deleteFile(activity, model.mInputUri);
|
||||
|
||||
@@ -83,11 +83,7 @@ public class EncryptDecryptOverviewFragment extends Fragment {
|
||||
mDecryptFile.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
FileHelper.openDocument(EncryptDecryptOverviewFragment.this, "*/*", REQUEST_CODE_INPUT);
|
||||
} else {
|
||||
FileHelper.openFile(EncryptDecryptOverviewFragment.this, null, "*/*", REQUEST_CODE_INPUT);
|
||||
}
|
||||
FileHelper.openDocument(EncryptDecryptOverviewFragment.this, null, "*/*", false, REQUEST_CODE_INPUT);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@@ -196,13 +195,9 @@ public class EncryptFilesFragment
|
||||
}
|
||||
|
||||
private void addInputUri() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
FileHelper.openDocument(EncryptFilesFragment.this, "*/*", true, REQUEST_CODE_INPUT);
|
||||
} else {
|
||||
FileHelper.openFile(EncryptFilesFragment.this, mFilesAdapter.getModelCount() == 0 ?
|
||||
null : mFilesAdapter.getModelItem(mFilesAdapter.getModelCount() - 1).inputUri,
|
||||
"*/*", REQUEST_CODE_INPUT);
|
||||
}
|
||||
FileHelper.openDocument(EncryptFilesFragment.this, mFilesAdapter.getModelCount() == 0 ?
|
||||
null : mFilesAdapter.getModelItem(mFilesAdapter.getModelCount() - 1).inputUri,
|
||||
"*/*", true, REQUEST_CODE_INPUT);
|
||||
}
|
||||
|
||||
private void addInputUri(Uri inputUri) {
|
||||
@@ -230,19 +225,8 @@ public class EncryptFilesFragment
|
||||
(mEncryptFilenames ? "1" : FileHelper.getFilename(getActivity(), model.inputUri))
|
||||
+ (mUseArmor ? Constants.FILE_EXTENSION_ASC : Constants.FILE_EXTENSION_PGP_MAIN);
|
||||
Uri inputUri = model.inputUri;
|
||||
saveDocumentIntent(targetName, inputUri);
|
||||
}
|
||||
|
||||
private void saveDocumentIntent(String targetName, Uri inputUri) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||
File file = new File(inputUri.getPath());
|
||||
File parentDir = file.exists() ? file.getParentFile() : Constants.Path.APP_DIR;
|
||||
File targetFile = new File(parentDir, targetName);
|
||||
FileHelper.saveFile(this, getString(R.string.title_encrypt_to_file),
|
||||
getString(R.string.specify_file_to_encrypt_to), targetFile, REQUEST_CODE_OUTPUT);
|
||||
} else {
|
||||
FileHelper.saveDocument(this, "*/*", targetName, REQUEST_CODE_OUTPUT);
|
||||
}
|
||||
FileHelper.saveDocument(this, targetName, inputUri,
|
||||
R.string.title_encrypt_to_file, R.string.specify_file_to_encrypt_to, REQUEST_CODE_OUTPUT);
|
||||
}
|
||||
|
||||
public void addFile(Intent data) {
|
||||
|
||||
@@ -64,8 +64,8 @@ public class ImportKeysFileFragment extends Fragment {
|
||||
// open .asc or .gpg files
|
||||
// setting it to text/plain prevents Cyanogenmod's file manager from selecting asc
|
||||
// or gpg types!
|
||||
FileHelper.openFile(ImportKeysFileFragment.this, Uri.fromFile(Constants.Path.APP_DIR),
|
||||
"*/*", REQUEST_CODE_FILE);
|
||||
FileHelper.openDocument(ImportKeysFileFragment.this,
|
||||
Uri.fromFile(Constants.Path.APP_DIR), "*/*", false, REQUEST_CODE_FILE);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -252,7 +252,7 @@ public class LogDisplayFragment extends ListFragment implements OnItemClickListe
|
||||
|
||||
String message = this.getString(R.string.specify_file_to_export_log_to);
|
||||
|
||||
FileHelper.saveFile(new FileHelper.FileDialogCallback() {
|
||||
FileHelper.saveDocumentDialog(new FileHelper.FileDialogCallback() {
|
||||
@Override
|
||||
public void onFileSelected(File file, boolean checked) {
|
||||
writeToLogFile(mResult.getLog(), file);
|
||||
|
||||
@@ -82,6 +82,7 @@ import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.NfcHelper;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -423,7 +424,8 @@ public class ViewKeyActivity extends BaseNfcActivity implements
|
||||
|
||||
private void backupToFile() {
|
||||
new ExportHelper(this).showExportKeysDialog(
|
||||
mMasterKeyId, Constants.Path.APP_DIR_FILE, true);
|
||||
mMasterKeyId, new File(Constants.Path.APP_DIR,
|
||||
KeyFormattingUtils.convertKeyIdToHex(mMasterKeyId) + ".sec.asc"), true);
|
||||
}
|
||||
|
||||
private void deleteKey() {
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.os.Messenger;
|
||||
@@ -119,14 +120,19 @@ public class FileDialogFragment extends DialogFragment {
|
||||
mFilename = (EditText) view.findViewById(R.id.input);
|
||||
mFilename.setText(mFile.getName());
|
||||
mBrowse = (ImageButton) view.findViewById(R.id.btn_browse);
|
||||
mBrowse.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
// only .asc or .gpg files
|
||||
// setting it to text/plain prevents Cynaogenmod's file manager from selecting asc
|
||||
// or gpg types!
|
||||
FileHelper.openFile(FileDialogFragment.this, Uri.fromFile(mFile), "*/*", REQUEST_CODE);
|
||||
}
|
||||
});
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||
mBrowse.setVisibility(View.GONE);
|
||||
} else {
|
||||
mBrowse.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
// only .asc or .gpg files
|
||||
// setting it to text/plain prevents Cynaogenmod's file manager from selecting asc
|
||||
// or gpg types!
|
||||
FileHelper.saveDocumentKitKat(
|
||||
FileDialogFragment.this, "*/*", mFile.getName(), REQUEST_CODE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
mCheckBox = (CheckBox) view.findViewById(R.id.checkbox);
|
||||
if (checkboxText == null) {
|
||||
|
||||
Reference in New Issue
Block a user