mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 11:12:15 -05:00
fixes to clipboard management
This commit is contained in:
parent
7a2e1e42d9
commit
df6933bfb8
@ -20,6 +20,7 @@ import org.spongycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.spongycastle.openpgp.PGPException;
|
||||
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.thialfihar.android.apg.provider.DataProvider;
|
||||
import org.thialfihar.android.apg.utils.Compatibility;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
@ -29,7 +30,6 @@ import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.text.ClipboardManager;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
@ -275,13 +275,16 @@ public class DecryptActivity extends BaseActivity {
|
||||
mReturnResult = true;
|
||||
}
|
||||
|
||||
if (mSource.getCurrentView().getId() == R.id.sourceMessage &&
|
||||
mMessage.getText().length() == 0) {
|
||||
ClipboardManager clip = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||||
if (mSource.getCurrentView().getId() == R.id.sourceMessage
|
||||
&& mMessage.getText().length() == 0) {
|
||||
|
||||
CharSequence clipboardText = Compatibility.getClipboardText(this);
|
||||
|
||||
String data = "";
|
||||
Matcher matcher = Apg.PGP_MESSAGE.matcher(clip.getText());
|
||||
if (clipboardText != null) {
|
||||
Matcher matcher = Apg.PGP_MESSAGE.matcher(clipboardText);
|
||||
if (!matcher.matches()) {
|
||||
matcher = Apg.PGP_SIGNED_MESSAGE.matcher(clip.getText());
|
||||
matcher = Apg.PGP_SIGNED_MESSAGE.matcher(clipboardText);
|
||||
}
|
||||
if (matcher.matches()) {
|
||||
data = matcher.group(1);
|
||||
@ -289,6 +292,7 @@ public class DecryptActivity extends BaseActivity {
|
||||
Toast.makeText(this, R.string.usingClipboardContent, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mSignatureLayout.setVisibility(View.GONE);
|
||||
mSignatureLayout.setOnClickListener(new OnClickListener() {
|
||||
@ -334,8 +338,8 @@ public class DecryptActivity extends BaseActivity {
|
||||
|
||||
updateSource();
|
||||
|
||||
if (mSource.getCurrentView().getId() == R.id.sourceMessage &&
|
||||
(mMessage.getText().length() > 0 || mData != null || mContentUri != null)) {
|
||||
if (mSource.getCurrentView().getId() == R.id.sourceMessage
|
||||
&& (mMessage.getText().length() > 0 || mData != null || mContentUri != null)) {
|
||||
mDecryptButton.performClick();
|
||||
}
|
||||
}
|
||||
@ -411,8 +415,9 @@ public class DecryptActivity extends BaseActivity {
|
||||
if (mInputFilename.startsWith("file")) {
|
||||
File file = new File(mInputFilename);
|
||||
if (!file.exists() || !file.isFile()) {
|
||||
Toast.makeText(this, getString(R.string.errorMessage,
|
||||
getString(R.string.error_fileNotFound)),
|
||||
Toast.makeText(
|
||||
this,
|
||||
getString(R.string.errorMessage, getString(R.string.error_fileNotFound)),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
@ -450,8 +455,8 @@ public class DecryptActivity extends BaseActivity {
|
||||
mAssumeSymmetricEncryption = true;
|
||||
}
|
||||
|
||||
if (getSecretKeyId() == Id.key.symmetric ||
|
||||
Apg.getCachedPassPhrase(getSecretKeyId()) == null) {
|
||||
if (getSecretKeyId() == Id.key.symmetric
|
||||
|| Apg.getCachedPassPhrase(getSecretKeyId()) == null) {
|
||||
showDialog(Id.dialog.pass_phrase);
|
||||
} else {
|
||||
if (mDecryptTarget == Id.target.file) {
|
||||
@ -468,8 +473,8 @@ public class DecryptActivity extends BaseActivity {
|
||||
error = "" + e;
|
||||
}
|
||||
if (error != null) {
|
||||
Toast.makeText(this, getString(R.string.errorMessage, error),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(this, getString(R.string.errorMessage, error), Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
@ -522,22 +527,22 @@ public class DecryptActivity extends BaseActivity {
|
||||
if (mSignedOnly) {
|
||||
data = Apg.verifyText(this, in, out, this);
|
||||
} else {
|
||||
data = Apg.decrypt(this, in, out, Apg.getCachedPassPhrase(getSecretKeyId()),
|
||||
this, mAssumeSymmetricEncryption);
|
||||
data = Apg.decrypt(this, in, out, Apg.getCachedPassPhrase(getSecretKeyId()), this,
|
||||
mAssumeSymmetricEncryption);
|
||||
}
|
||||
|
||||
out.close();
|
||||
|
||||
if (mDataDestination.getStreamFilename() != null) {
|
||||
data.putString(Apg.EXTRA_RESULT_URI, "content://" + DataProvider.AUTHORITY +
|
||||
"/data/" + mDataDestination.getStreamFilename());
|
||||
data.putString(Apg.EXTRA_RESULT_URI, "content://" + DataProvider.AUTHORITY
|
||||
+ "/data/" + mDataDestination.getStreamFilename());
|
||||
} else if (mDecryptTarget == Id.target.message) {
|
||||
if (mReturnBinary) {
|
||||
data.putByteArray(Apg.EXTRA_DECRYPTED_DATA,
|
||||
((ByteArrayOutputStream) out).toByteArray());
|
||||
} else {
|
||||
data.putString(Apg.EXTRA_DECRYPTED_MESSAGE,
|
||||
new String(((ByteArrayOutputStream) out).toByteArray()));
|
||||
data.putString(Apg.EXTRA_DECRYPTED_MESSAGE, new String(
|
||||
((ByteArrayOutputStream) out).toByteArray()));
|
||||
}
|
||||
}
|
||||
} catch (PGPException e) {
|
||||
@ -588,7 +593,8 @@ public class DecryptActivity extends BaseActivity {
|
||||
|
||||
String error = data.getString(Apg.EXTRA_ERROR);
|
||||
if (error != null) {
|
||||
Toast.makeText(this, getString(R.string.errorMessage, error), Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(this, getString(R.string.errorMessage, error), Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -642,7 +648,8 @@ public class DecryptActivity extends BaseActivity {
|
||||
mSignatureStatusImage.setImageResource(R.drawable.overlay_ok);
|
||||
} else if (data.getBoolean(Apg.EXTRA_SIGNATURE_UNKNOWN)) {
|
||||
mSignatureStatusImage.setImageResource(R.drawable.overlay_error);
|
||||
Toast.makeText(this, R.string.unknownSignatureKeyTouchToLookUp, Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(this, R.string.unknownSignatureKeyTouchToLookUp, Toast.LENGTH_LONG)
|
||||
.show();
|
||||
} else {
|
||||
mSignatureStatusImage.setImageResource(R.drawable.overlay_error);
|
||||
}
|
||||
@ -708,8 +715,7 @@ public class DecryptActivity extends BaseActivity {
|
||||
switch (id) {
|
||||
case Id.dialog.output_filename: {
|
||||
return FileDialog.build(this, getString(R.string.title_decryptToFile),
|
||||
getString(R.string.specifyFileToDecryptTo),
|
||||
mOutputFilename,
|
||||
getString(R.string.specifyFileToDecryptTo), mOutputFilename,
|
||||
new FileDialog.OnClickListener() {
|
||||
public void onOkClick(String filename, boolean checked) {
|
||||
removeDialog(Id.dialog.output_filename);
|
||||
@ -720,11 +726,8 @@ public class DecryptActivity extends BaseActivity {
|
||||
public void onCancelClick() {
|
||||
removeDialog(Id.dialog.output_filename);
|
||||
}
|
||||
},
|
||||
getString(R.string.filemanager_titleSave),
|
||||
getString(R.string.filemanager_btnSave),
|
||||
null,
|
||||
Id.request.output_filename);
|
||||
}, getString(R.string.filemanager_titleSave),
|
||||
getString(R.string.filemanager_btnSave), null, Id.request.output_filename);
|
||||
}
|
||||
|
||||
case Id.dialog.lookup_unknown_key: {
|
||||
@ -732,21 +735,19 @@ public class DecryptActivity extends BaseActivity {
|
||||
|
||||
alert.setIcon(android.R.drawable.ic_dialog_alert);
|
||||
alert.setTitle(R.string.title_unknownSignatureKey);
|
||||
alert.setMessage(getString(R.string.lookupUnknownKey, Apg.getSmallFingerPrint(mUnknownSignatureKeyId)));
|
||||
alert.setMessage(getString(R.string.lookupUnknownKey,
|
||||
Apg.getSmallFingerPrint(mUnknownSignatureKeyId)));
|
||||
|
||||
alert.setPositiveButton(android.R.string.ok,
|
||||
new DialogInterface.OnClickListener() {
|
||||
alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
removeDialog(Id.dialog.lookup_unknown_key);
|
||||
Intent intent = new Intent(DecryptActivity.this,
|
||||
KeyServerQueryActivity.class);
|
||||
Intent intent = new Intent(DecryptActivity.this, KeyServerQueryActivity.class);
|
||||
intent.setAction(Apg.Intent.LOOK_UP_KEY_ID);
|
||||
intent.putExtra(Apg.EXTRA_KEY_ID, mUnknownSignatureKeyId);
|
||||
startActivityForResult(intent, Id.request.look_up_key_id);
|
||||
}
|
||||
});
|
||||
alert.setNegativeButton(android.R.string.cancel,
|
||||
new DialogInterface.OnClickListener() {
|
||||
alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
removeDialog(Id.dialog.lookup_unknown_key);
|
||||
PausableThread thread = getRunningThread();
|
||||
|
@ -23,6 +23,7 @@ import org.spongycastle.openpgp.PGPSecretKey;
|
||||
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.thialfihar.android.apg.provider.DataProvider;
|
||||
import org.thialfihar.android.apg.utils.Choice;
|
||||
import org.thialfihar.android.apg.utils.Compatibility;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
@ -30,7 +31,6 @@ import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.text.ClipboardManager;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.animation.AnimationUtils;
|
||||
@ -881,8 +881,7 @@ public class EncryptActivity extends BaseActivity {
|
||||
switch (mEncryptTarget) {
|
||||
case Id.target.clipboard: {
|
||||
String message = data.getString(Apg.EXTRA_ENCRYPTED_MESSAGE);
|
||||
ClipboardManager clip = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||||
clip.setText(message);
|
||||
Compatibility.copyToClipboard(this, message);
|
||||
Toast.makeText(this, R.string.encryptionToClipboardSuccessful,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
|
@ -23,9 +23,6 @@ import org.thialfihar.android.apg.provider.KeyRings;
|
||||
import org.thialfihar.android.apg.provider.Keys;
|
||||
import org.thialfihar.android.apg.provider.UserIds;
|
||||
|
||||
import com.google.zxing.integration.android.IntentIntegrator;
|
||||
import com.google.zxing.integration.android.IntentResult;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.SearchManager;
|
||||
@ -201,20 +198,21 @@ public class KeyListActivity extends BaseActivity {
|
||||
Object keyRing = Apg.getKeyRing(keyRingId);
|
||||
if (keyRing != null) {
|
||||
if (keyRing instanceof PGPPublicKeyRing) {
|
||||
userId = Apg.getMainUserIdSafe(this, Apg.getMasterKey((PGPPublicKeyRing) keyRing));
|
||||
userId = Apg.getMainUserIdSafe(this,
|
||||
Apg.getMasterKey((PGPPublicKeyRing) keyRing));
|
||||
} else {
|
||||
userId = Apg.getMainUserIdSafe(this, Apg.getMasterKey((PGPSecretKeyRing) keyRing));
|
||||
userId = Apg.getMainUserIdSafe(this,
|
||||
Apg.getMasterKey((PGPSecretKeyRing) keyRing));
|
||||
}
|
||||
}
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.warning);
|
||||
builder.setMessage(getString(mKeyType == Id.type.public_key ?
|
||||
R.string.keyDeletionConfirmation :
|
||||
R.string.secretKeyDeletionConfirmation, userId));
|
||||
builder.setMessage(getString(
|
||||
mKeyType == Id.type.public_key ? R.string.keyDeletionConfirmation
|
||||
: R.string.secretKeyDeletionConfirmation, userId));
|
||||
builder.setIcon(android.R.drawable.ic_dialog_alert);
|
||||
builder.setPositiveButton(R.string.btn_delete,
|
||||
new DialogInterface.OnClickListener() {
|
||||
builder.setPositiveButton(R.string.btn_delete, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
deleteKey(keyRingId);
|
||||
removeDialog(Id.dialog.delete_key);
|
||||
@ -231,8 +229,7 @@ public class KeyListActivity extends BaseActivity {
|
||||
|
||||
case Id.dialog.import_keys: {
|
||||
return FileDialog.build(this, getString(R.string.title_importKeys),
|
||||
getString(R.string.specifyFileToImportFrom),
|
||||
mImportFilename,
|
||||
getString(R.string.specifyFileToImportFrom), mImportFilename,
|
||||
new FileDialog.OnClickListener() {
|
||||
public void onOkClick(String filename, boolean checked) {
|
||||
removeDialog(Id.dialog.import_keys);
|
||||
@ -244,11 +241,9 @@ public class KeyListActivity extends BaseActivity {
|
||||
public void onCancelClick() {
|
||||
removeDialog(Id.dialog.import_keys);
|
||||
}
|
||||
},
|
||||
getString(R.string.filemanager_titleOpen),
|
||||
}, getString(R.string.filemanager_titleOpen),
|
||||
getString(R.string.filemanager_btnOpen),
|
||||
getString(R.string.label_deleteAfterImport),
|
||||
Id.request.filename);
|
||||
getString(R.string.label_deleteAfterImport), Id.request.filename);
|
||||
}
|
||||
|
||||
case Id.dialog.export_key: {
|
||||
@ -257,17 +252,15 @@ public class KeyListActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
case Id.dialog.export_keys: {
|
||||
String title = (singleKeyExport ?
|
||||
getString(R.string.title_exportKey) :
|
||||
getString(R.string.title_exportKeys));
|
||||
String title = (singleKeyExport ? getString(R.string.title_exportKey)
|
||||
: getString(R.string.title_exportKeys));
|
||||
|
||||
final int thisDialogId = (singleKeyExport ? Id.dialog.export_key : Id.dialog.export_keys);
|
||||
final int thisDialogId = (singleKeyExport ? Id.dialog.export_key
|
||||
: Id.dialog.export_keys);
|
||||
|
||||
return FileDialog.build(this, title,
|
||||
getString(mKeyType == Id.type.public_key ?
|
||||
R.string.specifyFileToExportTo :
|
||||
R.string.specifyFileToExportSecretKeysTo),
|
||||
mExportFilename,
|
||||
getString(mKeyType == Id.type.public_key ? R.string.specifyFileToExportTo
|
||||
: R.string.specifyFileToExportSecretKeysTo), mExportFilename,
|
||||
new FileDialog.OnClickListener() {
|
||||
public void onOkClick(String filename, boolean checked) {
|
||||
removeDialog(thisDialogId);
|
||||
@ -278,11 +271,8 @@ public class KeyListActivity extends BaseActivity {
|
||||
public void onCancelClick() {
|
||||
removeDialog(thisDialogId);
|
||||
}
|
||||
},
|
||||
getString(R.string.filemanager_titleSave),
|
||||
getString(R.string.filemanager_btnSave),
|
||||
null,
|
||||
Id.request.filename);
|
||||
}, getString(R.string.filemanager_titleSave),
|
||||
getString(R.string.filemanager_btnSave), null, Id.request.filename);
|
||||
}
|
||||
|
||||
default: {
|
||||
@ -328,13 +318,14 @@ public class KeyListActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
if (mTask == Id.task.import_keys) {
|
||||
data = Apg.importKeyRings(this, mKeyType, new InputData(importInputStream, size), this);
|
||||
data = Apg.importKeyRings(this, mKeyType, new InputData(importInputStream, size),
|
||||
this);
|
||||
} else {
|
||||
Vector<Integer> keyRingIds = new Vector<Integer>();
|
||||
if (mSelectedItem == -1) {
|
||||
keyRingIds = Apg.getKeyRingIds(mKeyType == Id.type.public_key ?
|
||||
Id.database.type_public :
|
||||
Id.database.type_secret);
|
||||
keyRingIds = Apg
|
||||
.getKeyRingIds(mKeyType == Id.type.public_key ? Id.database.type_public
|
||||
: Id.database.type_secret);
|
||||
} else {
|
||||
int keyRingId = mListAdapter.getKeyRingId(mSelectedItem);
|
||||
keyRingIds.add(keyRingId);
|
||||
@ -391,8 +382,7 @@ public class KeyListActivity extends BaseActivity {
|
||||
|
||||
String error = data.getString(Apg.EXTRA_ERROR);
|
||||
if (error != null) {
|
||||
Toast.makeText(KeyListActivity.this,
|
||||
getString(R.string.errorMessage, error),
|
||||
Toast.makeText(KeyListActivity.this, getString(R.string.errorMessage, error),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
int added = data.getInt("added");
|
||||
@ -408,8 +398,7 @@ public class KeyListActivity extends BaseActivity {
|
||||
} else {
|
||||
message = getString(R.string.noKeysAddedOrUpdated);
|
||||
}
|
||||
Toast.makeText(KeyListActivity.this, message,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(KeyListActivity.this, message, Toast.LENGTH_SHORT).show();
|
||||
if (bad > 0) {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
||||
|
||||
@ -440,8 +429,7 @@ public class KeyListActivity extends BaseActivity {
|
||||
|
||||
String error = data.getString(Apg.EXTRA_ERROR);
|
||||
if (error != null) {
|
||||
Toast.makeText(KeyListActivity.this,
|
||||
getString(R.string.errorMessage, error),
|
||||
Toast.makeText(KeyListActivity.this, getString(R.string.errorMessage, error),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
int exported = data.getInt("exported");
|
||||
@ -450,11 +438,10 @@ public class KeyListActivity extends BaseActivity {
|
||||
message = getString(R.string.keyExported);
|
||||
} else if (exported > 0) {
|
||||
message = getString(R.string.keysExported, exported);
|
||||
} else{
|
||||
} else {
|
||||
message = getString(R.string.noKeysExported);
|
||||
}
|
||||
Toast.makeText(KeyListActivity.this, message,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(KeyListActivity.this, message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -516,22 +503,19 @@ public class KeyListActivity extends BaseActivity {
|
||||
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
mDatabase = Apg.getDatabase().db();
|
||||
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
|
||||
qb.setTables(KeyRings.TABLE_NAME + " INNER JOIN " + Keys.TABLE_NAME + " ON " +
|
||||
"(" + KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " +
|
||||
Keys.TABLE_NAME + "." + Keys.KEY_RING_ID + " AND " +
|
||||
Keys.TABLE_NAME + "." + Keys.IS_MASTER_KEY + " = '1'" +
|
||||
") " +
|
||||
" INNER JOIN " + UserIds.TABLE_NAME + " ON " +
|
||||
"(" + Keys.TABLE_NAME + "." + Keys._ID + " = " +
|
||||
UserIds.TABLE_NAME + "." + UserIds.KEY_ID + " AND " +
|
||||
UserIds.TABLE_NAME + "." + UserIds.RANK + " = '0')");
|
||||
qb.setTables(KeyRings.TABLE_NAME + " INNER JOIN " + Keys.TABLE_NAME + " ON " + "("
|
||||
+ KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " + Keys.TABLE_NAME + "."
|
||||
+ Keys.KEY_RING_ID + " AND " + Keys.TABLE_NAME + "." + Keys.IS_MASTER_KEY
|
||||
+ " = '1'" + ") " + " INNER JOIN " + UserIds.TABLE_NAME + " ON " + "("
|
||||
+ Keys.TABLE_NAME + "." + Keys._ID + " = " + UserIds.TABLE_NAME + "."
|
||||
+ UserIds.KEY_ID + " AND " + UserIds.TABLE_NAME + "." + UserIds.RANK
|
||||
+ " = '0')");
|
||||
|
||||
if (searchString != null && searchString.trim().length() > 0) {
|
||||
String[] chunks = searchString.trim().split(" +");
|
||||
qb.appendWhere("EXISTS (SELECT tmp." + UserIds._ID + " FROM " +
|
||||
UserIds.TABLE_NAME + " AS tmp WHERE " +
|
||||
"tmp." + UserIds.KEY_ID + " = " +
|
||||
Keys.TABLE_NAME + "." + Keys._ID);
|
||||
qb.appendWhere("EXISTS (SELECT tmp." + UserIds._ID + " FROM " + UserIds.TABLE_NAME
|
||||
+ " AS tmp WHERE " + "tmp." + UserIds.KEY_ID + " = " + Keys.TABLE_NAME
|
||||
+ "." + Keys._ID);
|
||||
for (int i = 0; i < chunks.length; ++i) {
|
||||
qb.appendWhere(" AND tmp." + UserIds.USER_ID + " LIKE ");
|
||||
qb.appendWhereEscapeString("%" + chunks[i] + "%");
|
||||
@ -539,32 +523,22 @@ public class KeyListActivity extends BaseActivity {
|
||||
qb.appendWhere(")");
|
||||
}
|
||||
|
||||
mCursor = qb.query(mDatabase,
|
||||
new String[] {
|
||||
KeyRings.TABLE_NAME + "." + KeyRings._ID, // 0
|
||||
mCursor = qb.query(mDatabase, new String[] { KeyRings.TABLE_NAME + "." + KeyRings._ID, // 0
|
||||
KeyRings.TABLE_NAME + "." + KeyRings.MASTER_KEY_ID, // 1
|
||||
UserIds.TABLE_NAME + "." + UserIds.USER_ID, // 2
|
||||
},
|
||||
KeyRings.TABLE_NAME + "." + KeyRings.TYPE + " = ?",
|
||||
new String[] { "" + (mKeyType == Id.type.public_key ?
|
||||
Id.database.type_public : Id.database.type_secret) },
|
||||
null, null, UserIds.TABLE_NAME + "." + UserIds.USER_ID + " ASC");
|
||||
}, KeyRings.TABLE_NAME + "." + KeyRings.TYPE + " = ?", new String[] { ""
|
||||
+ (mKeyType == Id.type.public_key ? Id.database.type_public
|
||||
: Id.database.type_secret) }, null, null, UserIds.TABLE_NAME + "."
|
||||
+ UserIds.USER_ID + " ASC");
|
||||
|
||||
// content provider way for reference, might have to go back to it sometime:
|
||||
/*Uri contentUri = null;
|
||||
if (mKeyType == Id.type.secret_key) {
|
||||
contentUri = Apg.CONTENT_URI_SECRET_KEY_RINGS;
|
||||
} else {
|
||||
contentUri = Apg.CONTENT_URI_PUBLIC_KEY_RINGS;
|
||||
}
|
||||
mCursor = getContentResolver().query(
|
||||
contentUri,
|
||||
new String[] {
|
||||
DataProvider._ID, // 0
|
||||
DataProvider.MASTER_KEY_ID, // 1
|
||||
DataProvider.USER_ID, // 2
|
||||
},
|
||||
null, null, null);*/
|
||||
/*
|
||||
* Uri contentUri = null; if (mKeyType == Id.type.secret_key) { contentUri =
|
||||
* Apg.CONTENT_URI_SECRET_KEY_RINGS; } else { contentUri =
|
||||
* Apg.CONTENT_URI_PUBLIC_KEY_RINGS; } mCursor = getContentResolver().query( contentUri,
|
||||
* new String[] { DataProvider._ID, // 0 DataProvider.MASTER_KEY_ID, // 1
|
||||
* DataProvider.USER_ID, // 2 }, null, null, null);
|
||||
*/
|
||||
|
||||
startManagingCursor(mCursor);
|
||||
rebuild(false);
|
||||
@ -595,19 +569,15 @@ public class KeyListActivity extends BaseActivity {
|
||||
|
||||
mCursor.moveToPosition(groupPosition);
|
||||
children = new Vector<KeyChild>();
|
||||
Cursor c = mDatabase.query(Keys.TABLE_NAME,
|
||||
new String[] {
|
||||
Keys._ID, // 0
|
||||
Cursor c = mDatabase.query(Keys.TABLE_NAME, new String[] { Keys._ID, // 0
|
||||
Keys.KEY_ID, // 1
|
||||
Keys.IS_MASTER_KEY, // 2
|
||||
Keys.ALGORITHM, // 3
|
||||
Keys.KEY_SIZE, // 4
|
||||
Keys.CAN_SIGN, // 5
|
||||
Keys.CAN_ENCRYPT, // 6
|
||||
},
|
||||
Keys.KEY_RING_ID + " = ?",
|
||||
new String[] { mCursor.getString(0) },
|
||||
null, null, Keys.RANK + " ASC");
|
||||
}, Keys.KEY_RING_ID + " = ?", new String[] { mCursor.getString(0) }, null, null,
|
||||
Keys.RANK + " ASC");
|
||||
|
||||
int masterKeyId = -1;
|
||||
long fingerPrintId = -1;
|
||||
@ -624,13 +594,9 @@ public class KeyListActivity extends BaseActivity {
|
||||
|
||||
if (masterKeyId != -1) {
|
||||
children.insertElementAt(new KeyChild(Apg.getFingerPrint(fingerPrintId), true), 0);
|
||||
c = mDatabase.query(UserIds.TABLE_NAME,
|
||||
new String[] {
|
||||
UserIds.USER_ID, // 0
|
||||
},
|
||||
UserIds.KEY_ID + " = ? AND " + UserIds.RANK + " > 0",
|
||||
new String[] { "" + masterKeyId },
|
||||
null, null, UserIds.RANK + " ASC");
|
||||
c = mDatabase.query(UserIds.TABLE_NAME, new String[] { UserIds.USER_ID, // 0
|
||||
}, UserIds.KEY_ID + " = ? AND " + UserIds.RANK + " > 0", new String[] { ""
|
||||
+ masterKeyId }, null, null, UserIds.RANK + " ASC");
|
||||
|
||||
for (int i = 0; i < c.getCount(); ++i) {
|
||||
c.moveToPosition(i);
|
||||
@ -713,9 +679,8 @@ public class KeyListActivity extends BaseActivity {
|
||||
return view;
|
||||
}
|
||||
|
||||
public View getChildView(int groupPosition, int childPosition,
|
||||
boolean isLastChild, View convertView,
|
||||
ViewGroup parent) {
|
||||
public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
|
||||
View convertView, ViewGroup parent) {
|
||||
mCursor.moveToPosition(groupPosition);
|
||||
|
||||
Vector<KeyChild> children = getChildrenOfGroup(groupPosition);
|
||||
@ -759,8 +724,8 @@ public class KeyListActivity extends BaseActivity {
|
||||
case KeyChild.FINGER_PRINT: {
|
||||
view = mInflater.inflate(R.layout.key_list_child_item_user_id, null);
|
||||
TextView userId = (TextView) view.findViewById(R.id.userId);
|
||||
userId.setText(getString(R.string.fingerprint) + ":\n" +
|
||||
child.fingerPrint.replace(" ", "\n"));
|
||||
userId.setText(getString(R.string.fingerprint) + ":\n"
|
||||
+ child.fingerPrint.replace(" ", "\n"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -18,9 +18,6 @@ package org.thialfihar.android.apg;
|
||||
|
||||
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
||||
|
||||
import com.google.zxing.integration.android.IntentIntegrator;
|
||||
import com.google.zxing.integration.android.IntentResult;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.ContextMenu;
|
||||
@ -41,26 +38,25 @@ public class PublicKeyListActivity extends KeyListActivity {
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
menu.add(0, Id.menu.option.import_keys, 0, R.string.menu_importKeys)
|
||||
.setIcon(android.R.drawable.ic_menu_add);
|
||||
menu.add(0, Id.menu.option.export_keys, 1, R.string.menu_exportKeys)
|
||||
.setIcon(android.R.drawable.ic_menu_save);
|
||||
menu.add(1, Id.menu.option.search, 2, R.string.menu_search)
|
||||
.setIcon(android.R.drawable.ic_menu_search);
|
||||
menu.add(1, Id.menu.option.preferences, 3, R.string.menu_preferences)
|
||||
.setIcon(android.R.drawable.ic_menu_preferences);
|
||||
menu.add(1, Id.menu.option.about, 4, R.string.menu_about)
|
||||
.setIcon(android.R.drawable.ic_menu_info_details);
|
||||
menu.add(1, Id.menu.option.scanQRCode, 5, R.string.menu_scanQRCode)
|
||||
.setIcon(android.R.drawable.ic_menu_add);
|
||||
menu.add(0, Id.menu.option.import_keys, 0, R.string.menu_importKeys).setIcon(
|
||||
android.R.drawable.ic_menu_add);
|
||||
menu.add(0, Id.menu.option.export_keys, 1, R.string.menu_exportKeys).setIcon(
|
||||
android.R.drawable.ic_menu_save);
|
||||
menu.add(1, Id.menu.option.search, 2, R.string.menu_search).setIcon(
|
||||
android.R.drawable.ic_menu_search);
|
||||
menu.add(1, Id.menu.option.preferences, 3, R.string.menu_preferences).setIcon(
|
||||
android.R.drawable.ic_menu_preferences);
|
||||
menu.add(1, Id.menu.option.about, 4, R.string.menu_about).setIcon(
|
||||
android.R.drawable.ic_menu_info_details);
|
||||
menu.add(1, Id.menu.option.scanQRCode, 5, R.string.menu_scanQRCode).setIcon(
|
||||
android.R.drawable.ic_menu_add);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
ExpandableListView.ExpandableListContextMenuInfo info =
|
||||
(ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
|
||||
ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
|
||||
int type = ExpandableListView.getPackedPositionType(info.packedPosition);
|
||||
|
||||
if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
|
||||
@ -165,8 +161,8 @@ public class PublicKeyListActivity extends KeyListActivity {
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
switch (requestCode) {
|
||||
case Id.request.look_up_key_id: {
|
||||
if (resultCode == RESULT_CANCELED || data == null ||
|
||||
data.getStringExtra(Apg.EXTRA_TEXT) == null) {
|
||||
if (resultCode == RESULT_CANCELED || data == null
|
||||
|| data.getStringExtra(Apg.EXTRA_TEXT) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
79
src/org/thialfihar/android/apg/utils/Compatibility.java
Normal file
79
src/org/thialfihar/android/apg/utils/Compatibility.java
Normal file
@ -0,0 +1,79 @@
|
||||
package org.thialfihar.android.apg.utils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
public class Compatibility {
|
||||
|
||||
private static final String clipboardLabel = "APG";
|
||||
|
||||
/**
|
||||
* Wrapper around ClipboardManager based on Android version using Reflection API, from
|
||||
* http://www.projectsexception.com/blog/?p=87
|
||||
*
|
||||
* @param context
|
||||
* @param text
|
||||
*/
|
||||
public static void copyToClipboard(Context context, String text) {
|
||||
Object clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
try {
|
||||
if ("android.text.ClipboardManager".equals(clipboard.getClass().getName())) {
|
||||
Method method = clipboard.getClass().getMethod("setText", CharSequence.class);
|
||||
method.invoke(clipboard, text);
|
||||
} else if ("android.content.ClipboardManager".equals(clipboard.getClass().getName())) {
|
||||
Class<?> clazz = Class.forName("android.content.ClipData");
|
||||
Method method = clazz.getMethod("newPlainText", CharSequence.class,
|
||||
CharSequence.class);
|
||||
Object clip = method.invoke(null, clipboardLabel, text);
|
||||
method = clipboard.getClass().getMethod("setPrimaryClip", clazz);
|
||||
method.invoke(clipboard, clip);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e("ProjectsException", "There was and error copying the text to the clipboard: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper around ClipboardManager based on Android version using Reflection API
|
||||
*
|
||||
* @param context
|
||||
* @param text
|
||||
*/
|
||||
public static CharSequence getClipboardText(Context context) {
|
||||
Object clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
try {
|
||||
if ("android.text.ClipboardManager".equals(clipboard.getClass().getName())) {
|
||||
// CharSequence text = clipboard.getText();
|
||||
Method method = clipboard.getClass().getMethod("getText");
|
||||
Object text = method.invoke(clipboard);
|
||||
|
||||
return (CharSequence) text;
|
||||
} else if ("android.content.ClipboardManager".equals(clipboard.getClass().getName())) {
|
||||
// ClipData clipData = clipboard.getPrimaryClip();
|
||||
Method methodGetPrimaryClip = clipboard.getClass().getMethod("getPrimaryClip");
|
||||
Object clipData = methodGetPrimaryClip.invoke(clipboard);
|
||||
|
||||
// ClipData.Item clipDataItem = clipData.getItemAt(0);
|
||||
Method methodGetItemAt = clipData.getClass().getMethod("getItemAt", Integer.TYPE);
|
||||
Object clipDataItem = methodGetItemAt.invoke(clipData, 0);
|
||||
|
||||
// CharSequence text = clipDataItem.coerceToText(context);
|
||||
Method methodGetString = clipDataItem.getClass().getMethod("coerceToText",
|
||||
Context.class);
|
||||
Object text = methodGetString.invoke(clipDataItem, context);
|
||||
|
||||
return (CharSequence) text;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e("ProjectsException", "There was and error getting the text from the clipboard: "
|
||||
+ e.getMessage());
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user