diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/compatibility/ClipboardReflection.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/compatibility/ClipboardReflection.java
index 2f2838f70..0ac27833c 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/compatibility/ClipboardReflection.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/compatibility/ClipboardReflection.java
@@ -17,6 +17,8 @@
package org.sufficientlysecure.keychain.compatibility;
+import android.content.ClipData;
+import android.content.ClipboardManager;
import android.content.Context;
import org.sufficientlysecure.keychain.Constants;
@@ -28,72 +30,24 @@ public class ClipboardReflection {
private static final String clipboardLabel = "Keychain";
- /**
- * Wrapper around ClipboardManager based on Android version using Reflection API
- *
- * @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 methodSetText = clipboard.getClass()
- .getMethod("setText", CharSequence.class);
- methodSetText.invoke(clipboard, text);
- } else if ("android.content.ClipboardManager".equals(clipboard.getClass().getName())) {
- Class> classClipData = Class.forName("android.content.ClipData");
- Method methodNewPlainText = classClipData.getMethod("newPlainText",
- CharSequence.class, CharSequence.class);
- Object clip = methodNewPlainText.invoke(null, clipboardLabel, text);
- methodNewPlainText = clipboard.getClass()
- .getMethod("setPrimaryClip", classClipData);
- methodNewPlainText.invoke(clipboard, clip);
- }
- } catch (Exception e) {
- Log.e(Constants.TAG, "There was an error copying the text to the clipboard", e);
- }
+ ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
+
+ ClipData clip = ClipData.newPlainText(clipboardLabel, text);
+ clipboard.setPrimaryClip(clip);
+
}
- /**
- * Wrapper around ClipboardManager based on Android version using Reflection API
- *
- * @param context
- */
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 methodGetText = clipboard.getClass().getMethod("getText");
- Object text = methodGetText.invoke(clipboard);
+ ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
- 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);
-
- if (clipData == null) {
- return null;
- }
-
- // ClipData.Item clipDataItem = clipData.getItemAt(0);
- Method methodGetItemAt = clipData.getClass().getMethod("getItemAt", int.class);
- 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(Constants.TAG, "There was an error getting the text from the clipboard", e);
+ ClipData clip = clipboard.getPrimaryClip();
+ if (clip == null || clip.getItemCount() == 0) {
+ Log.e(Constants.TAG, "No clipboard data!");
return null;
}
+
+ ClipData.Item item = clip.getItemAt(0);
+ return item.coerceToText(context);
}
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java
index 93e6f9d24..57c82ef9c 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java
@@ -26,6 +26,8 @@ import java.util.List;
import java.util.Set;
import android.app.Activity;
+import android.content.ClipData;
+import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
@@ -413,8 +415,20 @@ public class EncryptFilesFragment
break;
case COPY:
- byte[] resultBytes = result.getResultBytes();
- ClipboardReflection.copyToClipboard(getActivity(), new String(resultBytes));
+ Activity activity = getActivity();
+ if (activity == null) {
+ // it's gone, there's nothing we can do here
+ return;
+ }
+
+ ClipboardManager clipMan = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
+ // ClipData clip = ClipData.newUri(getActivity().getContentResolver(),
+ // getString(R.string.label_clip_title), mOutputUris.get(0));
+ ClipData clip = new ClipData(getString(R.string.label_clip_title),
+ new String[] { "text/plain" },
+ new ClipData.Item(mOutputUris.get(0))
+ );
+ clipMan.setPrimaryClip(clip);
result.createNotify(getActivity()).show();
break;
@@ -436,32 +450,44 @@ public class EncryptFilesFragment
Notify.create(getActivity(), R.string.no_file_selected, Notify.Style.ERROR)
.show(this);
return true;
- } else if (mFilesModels.size() > 1 && mAfterEncryptAction != AfterEncryptAction.SHARE) {
- Log.e(Constants.TAG, "Aborting: mInputUris.size() > 1 && !afterEncryptAction");
- // This should be impossible...
- return true;
}
- if (mAfterEncryptAction == AfterEncryptAction.SHARE) {
- mOutputUris = new ArrayList<>();
- int filenameCounter = 1;
- for (FilesAdapter.ViewModel model : mFilesModels) {
- String targetName =
- (mEncryptFilenames ? String.valueOf(filenameCounter) : FileHelper.getFilename(getActivity(), model.inputUri))
- + (mUseArmor ? Constants.FILE_EXTENSION_ASC : Constants.FILE_EXTENSION_PGP_MAIN);
- mOutputUris.add(TemporaryStorageProvider.createFile(getActivity(), targetName));
- filenameCounter++;
- }
- return false;
- } else {
- if (mFilesModels.size() > 1) {
- Notify.create(getActivity(), R.string.error_multi_not_supported,
- Notify.Style.ERROR).show(this);
+ switch (mAfterEncryptAction) {
+ default:
+ case SHARE:
+ mOutputUris = new ArrayList<>();
+ int filenameCounter = 1;
+ for (FilesAdapter.ViewModel model : mFilesModels) {
+ String targetName = (mEncryptFilenames
+ ? String.valueOf(filenameCounter) : FileHelper.getFilename(getActivity(), model.inputUri))
+ + (mUseArmor ? Constants.FILE_EXTENSION_ASC : Constants.FILE_EXTENSION_PGP_MAIN);
+ mOutputUris.add(TemporaryStorageProvider.createFile(getActivity(), targetName));
+ filenameCounter++;
+ }
+ return false;
+
+ case SAVE:
+ if (mFilesModels.size() > 1) {
+ Notify.create(getActivity(), R.string.error_multi_files, Notify.Style.ERROR).show(this);
+ return true;
+ }
+ showOutputFileDialog();
return true;
- }
- showOutputFileDialog();
- return true;
+
+ case COPY:
+ // nothing to do here, but make sure
+ if (mFilesModels.size() > 1) {
+ Notify.create(getActivity(), R.string.error_multi_clipboard, Notify.Style.ERROR).show(this);
+ return true;
+ }
+ mOutputUris = new ArrayList<>();
+ String targetName = (mEncryptFilenames
+ ? String.valueOf(1) : FileHelper.getFilename(getActivity(), mFilesModels.get(0).inputUri))
+ + Constants.FILE_EXTENSION_ASC;
+ mOutputUris.add(TemporaryStorageProvider.createFile(getActivity(), targetName, "text/plain"));
+ return false;
}
+
}
protected SignEncryptParcel createOperationInput() {
@@ -516,7 +542,7 @@ public class EncryptFilesFragment
data.setCompressionId(CompressionAlgorithmTags.UNCOMPRESSED);
}
data.setHiddenRecipients(mHiddenRecipients);
- data.setEnableAsciiArmorOutput(mUseArmor);
+ data.setEnableAsciiArmorOutput(mAfterEncryptAction == AfterEncryptAction.COPY || mUseArmor);
data.setSymmetricEncryptionAlgorithm(PgpConstants.OpenKeychainSymmetricKeyAlgorithmTags.USE_PREFERRED);
data.setSignatureHashAlgorithm(PgpConstants.OpenKeychainSymmetricKeyAlgorithmTags.USE_PREFERRED);
@@ -622,7 +648,7 @@ public class EncryptFilesFragment
if (resultCode == Activity.RESULT_OK && data != null) {
mOutputUris = new ArrayList<>(1);
mOutputUris.add(data.getData());
- // make sure this is correct!
+ // make sure this is correct at this point
mAfterEncryptAction = AfterEncryptAction.SAVE;
cryptoOperation();
}
diff --git a/OpenKeychain/src/main/res/values-de/strings.xml b/OpenKeychain/src/main/res/values-de/strings.xml
index ea04f56b9..1dac06059 100644
--- a/OpenKeychain/src/main/res/values-de/strings.xml
+++ b/OpenKeychain/src/main/res/values-de/strings.xml
@@ -1132,7 +1132,7 @@
Schlüssel anzeigen (%s)
Nach unten wischen um von Schlüsselserver zu aktualisieren
Mindestens eine Datei zum Verschlüsseln auswählen!
- Das speichern von mehreren Dateien wird nicht unterstützt. Dies ist eine Einschränkung der aktuellen Android Version.
+ Das speichern von mehreren Dateien wird nicht unterstützt. Dies ist eine Einschränkung der aktuellen Android Version.
Schlüssel:
Um einen Schlüsselaustausch zu starten wähle auf der rechten Seite die Teilnehmer aus, drücke dann den \"Austausch starten\"-Knopf.\n\nDu wirst zusätzlich zwei Fragen gestellt bekommen um sicherzustellen, dass nur die richtigen Teilnehmer am Austausch beteiligt sind und deren Fingerabdrücke korrekt sind.
Austausch starten
diff --git a/OpenKeychain/src/main/res/values-es/strings.xml b/OpenKeychain/src/main/res/values-es/strings.xml
index 6503fe95b..a3388a2a4 100644
--- a/OpenKeychain/src/main/res/values-es/strings.xml
+++ b/OpenKeychain/src/main/res/values-es/strings.xml
@@ -1131,7 +1131,7 @@
Mostrar clave (%s)
Gesto de barrido hacia abajo para actualizar desde el servidor de claves
¡Seleccione al menos un fichero a cifrar!
- El guardado de múltiples ficheros no está soportado. Esto es una limitación de su Android actual.
+ El guardado de múltiples ficheros no está soportado. Esto es una limitación de su Android actual.
Clave:
Para iniciar un intercambio de claves, en el lado derecho elija el número de participantes, y luego pulse el botón \"Iniciar intercambio\".\n\nSe le formularán dos preguntas más para asegurar que sólo están en el intercambio los participantes debidos, y que sus huellas de validación son correctas.
Comenzar intercambio
diff --git a/OpenKeychain/src/main/res/values-fr/strings.xml b/OpenKeychain/src/main/res/values-fr/strings.xml
index 17e3fcde0..6066a420a 100644
--- a/OpenKeychain/src/main/res/values-fr/strings.xml
+++ b/OpenKeychain/src/main/res/values-fr/strings.xml
@@ -1131,7 +1131,7 @@
Montrer la clef (%s)
Glisser vers le bas pour mettre à jour à partir du serveur de clefs
Choisir au moins un fichier à chiffrer !
- L\'enregistrement des fichiers multiples n\'est pas pris en charge. Ceci est actuellement une limitation d\'Android.
+ L\'enregistrement des fichiers multiples n\'est pas pris en charge. Ceci est actuellement une limitation d\'Android.
Clef :
Pour démarrer un échange de clef, choisir le nombre de participants du côté droit, puis cliquer sur le bouton « Démarrer l\'échange ».\n\Deux questions de plus seront posées pour s\'assurer que seuls les bons participants sont dans l\'échange et que les empreintes sont correctes.
Démarrer l\'échange
diff --git a/OpenKeychain/src/main/res/values-it/strings.xml b/OpenKeychain/src/main/res/values-it/strings.xml
index 2e598a0c2..8d466b4b0 100644
--- a/OpenKeychain/src/main/res/values-it/strings.xml
+++ b/OpenKeychain/src/main/res/values-it/strings.xml
@@ -686,7 +686,7 @@ Permetti accesso?\n\nATTENZIONE: Se non sai perche\' questo schermata e\' appars
Non creare account OpenKeychain manualmente.\nPer ulteriori informazioni, vedere la Guida.
Mostra chiave (%s)
Seleziona almeno un file da codificare!
- Il salvataggio di più file non è supportato. Questa è una limitazione corrente di Android.
+ Il salvataggio di più file non è supportato. Questa è una limitazione corrente di Android.
Chiave:
diff --git a/OpenKeychain/src/main/res/values-ja/strings.xml b/OpenKeychain/src/main/res/values-ja/strings.xml
index 82ca70d67..8b09b3a94 100644
--- a/OpenKeychain/src/main/res/values-ja/strings.xml
+++ b/OpenKeychain/src/main/res/values-ja/strings.xml
@@ -1102,7 +1102,7 @@
鍵 (%s) を表示
下スワイプでキーサーバから更新します
暗号化するファイルを少なくとも1つ選択して下さい。
- 複数ファイルの保存はサポートされていません。これは現在のAndroidでの制限です。
+ 複数ファイルの保存はサポートされていません。これは現在のAndroidでの制限です。
鍵:
鍵交換の開始は、右側の参加者の番号を選択し、その後、\"交換開始\"ボタンを推します。\n\n2つ以上の質問で交換にいる右の参加者とその指紋が正しいかを確認してください。
交換開始
diff --git a/OpenKeychain/src/main/res/values-nl/strings.xml b/OpenKeychain/src/main/res/values-nl/strings.xml
index f5d079dab..e75a1684f 100644
--- a/OpenKeychain/src/main/res/values-nl/strings.xml
+++ b/OpenKeychain/src/main/res/values-nl/strings.xml
@@ -1131,7 +1131,7 @@
Toon sleutel (%s)
Veeg naar beneden om van sleutelserver te updaten
Selecteer minstens een bestand om te versleutelen!
- Opslaan van meerdere bestanden wordt niet ondersteund. Dit is een beperking van Android.
+ Opslaan van meerdere bestanden wordt niet ondersteund. Dit is een beperking van Android.
Sleutel:
Selecteer om een sleuteluitwisseling te starten het aantal deelnemers aan de rechterkant, en klik vervolgens op de knop \'Start uitwisseling\'.\n\nJe zal twee vragne gesteld worden om zeker te zijn dat enkel de juiste deelnemers zich in de uitwisseling bevinden en dat hun vingerafdrukken correct zijn.
Uitwisseling starten
diff --git a/OpenKeychain/src/main/res/values-sr/strings.xml b/OpenKeychain/src/main/res/values-sr/strings.xml
index 75bbdf480..464295152 100644
--- a/OpenKeychain/src/main/res/values-sr/strings.xml
+++ b/OpenKeychain/src/main/res/values-sr/strings.xml
@@ -1112,7 +1112,7 @@
Прикажи кључ (%s)
Превуците прстом доле да ажурирате са сервера кључева
Изаберите бар један фајл за шифровање!
- Упис више фајлова није подржан. Ово је ограничење у текућем издању Андроида.
+ Упис више фајлова није подржан. Ово је ограничење у текућем издању Андроида.
Кључ:
Да бисте почели размену кључева, са десне стране изаберите број учесника и додирните дугме „Почни размену“.\n\nБиће вам постављено још два питања да би се осигурало да су само исправни учесници у размени и да су њихови отисци тачни.
Почни размену
diff --git a/OpenKeychain/src/main/res/values-sv/strings.xml b/OpenKeychain/src/main/res/values-sv/strings.xml
index f73be4861..64aae6c79 100644
--- a/OpenKeychain/src/main/res/values-sv/strings.xml
+++ b/OpenKeychain/src/main/res/values-sv/strings.xml
@@ -873,7 +873,7 @@
Visa nyckel (%s)
Dra nedåt för att uppdatera från nyckelserver
Välj åtminstone en fil att kryptera!
- Att spara flera filer stöds ej. Detta är en begränsning i nuvarande Android.
+ Att spara flera filer stöds ej. Detta är en begränsning i nuvarande Android.
Nyckel:
]]>
diff --git a/OpenKeychain/src/main/res/values-tr/strings.xml b/OpenKeychain/src/main/res/values-tr/strings.xml
index 12115e93b..0a5cca80d 100644
--- a/OpenKeychain/src/main/res/values-tr/strings.xml
+++ b/OpenKeychain/src/main/res/values-tr/strings.xml
@@ -480,7 +480,7 @@
Anahtarı göster (%s)
Anahtar sunucudan güncelleme almak için parmağınızı aşağıya doğru kaydırın
Şifrelemek için en az bir dosya seçin!
- Birden çok dosyanın kaydedilmesi desteklenmiyor. Bu şu anki Android\'in bir kısıtlamasıdır.
+ Birden çok dosyanın kaydedilmesi desteklenmiyor. Bu şu anki Android\'in bir kısıtlamasıdır.
Anahtar:
Anahtar değiş tokuşu başlatmak için sağ taraftan katılımcıların sayısını seçin ve \"Değiş tokuşu başlat\" tuşuna tıklayın.\n\nSadece istenilen katılımcıların değişim işleminde olduğundan ve parmak izlerinin doğruluğundan emin olmak için size iki soru daha sorulacak.
diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml
index cf90caa1c..f3651371a 100644
--- a/OpenKeychain/src/main/res/values/strings.xml
+++ b/OpenKeychain/src/main/res/values/strings.xml
@@ -1264,7 +1264,8 @@
"Show key (%s)"
"Swipe down to update from keyserver"
"Select at least one file to encrypt!"
- "Saving of multiple files not supported. This is a limitation on current Android."
+ "Saving of multiple files not supported. This is a limitation on current Android."
+ "Encryption of multiple files to clipboard not supported."
"Type some text to encrypt!"
"Key:"
"To start a key exchange, choose the number of participants on the right side, then hit the “Start exchange” button.\n\nYou will be asked two more questions to make sure only the right participants are in the exchange and their fingerprints are correct."
@@ -1339,5 +1340,6 @@
Show Signed/Encrypted Content
"View in OpenKeychain"
"Error preparing data!"
+ "Encrypted Data"