diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Constants.java b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Constants.java index d57c55b6..ee5bacf6 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Constants.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Constants.java @@ -61,7 +61,7 @@ public class Constants { } public enum TapMode { - NOTHING, REVEAL, COPY, COPY_BACKGROUND + NOTHING, REVEAL, COPY, COPY_BACKGROUND, SEND_KEYSTROKES } public enum LabelDisplay { diff --git a/app/src/main/java/org/shadowice/flocke/andotp/View/EntriesCardAdapter.java b/app/src/main/java/org/shadowice/flocke/andotp/View/EntriesCardAdapter.java index 6afff91c..5f1c0e0c 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/View/EntriesCardAdapter.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/View/EntriesCardAdapter.java @@ -26,6 +26,7 @@ import android.annotation.SuppressLint; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; +import android.content.Intent; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.net.Uri; @@ -317,6 +318,10 @@ public class EntriesCardAdapter extends RecyclerView.Adapter establishPinIfNeeded(position); copyHandler(position, text, true); break; + case SEND_KEYSTROKES: + establishPinIfNeeded(position); + sendKeystrokes(position); + break; default: // If tap-to-reveal is disabled a single tab still needs to establish the PIN if (!settings.getTapToReveal()) @@ -340,6 +345,10 @@ public class EntriesCardAdapter extends RecyclerView.Adapter establishPinIfNeeded(position); copyHandler(position, text, true); break; + case SEND_KEYSTROKES: + establishPinIfNeeded(position); + sendKeystrokes(position); + break; default: break; } @@ -669,6 +678,19 @@ public class EntriesCardAdapter extends RecyclerView.Adapter .show(); } + // sends the current OTP code via a "Send Action" with the MIME type "text/x-keystrokes" + // other apps (eg. https://github.com/KDE/kdeconnect-android ) can listen for this and handle + // the current code on their own (eg. sending it to a connected device/browser/...) + private void sendKeystrokes(final int pos) { + String otp = displayedEntries.get(pos).getCurrentOTP(); + Intent sendIntent = new Intent(Intent.ACTION_SEND); + sendIntent.setType("text/x-keystrokes"); + sendIntent.putExtra(Intent.EXTRA_TEXT, otp); + if (sendIntent.resolveActivity(this.context.getPackageManager()) != null) { + this.context.startActivity(sendIntent); + } + } + private void showQRCode(final int pos) { Uri uri = displayedEntries.get(pos).toUri(); if (uri != null) { @@ -727,6 +749,9 @@ public class EntriesCardAdapter extends RecyclerView.Adapter } else if (id == R.id.menu_popup_show_qr_code) { showQRCode(pos); return true; + } else if (id == R.id.menu_send_keystrokes) { + sendKeystrokes(pos); + return true; } else { return false; } diff --git a/app/src/main/res/menu/menu_popup.xml b/app/src/main/res/menu/menu_popup.xml index 95a0088e..541a889b 100644 --- a/app/src/main/res/menu/menu_popup.xml +++ b/app/src/main/res/menu/menu_popup.xml @@ -22,4 +22,8 @@ android:id="@+id/menu_popup_remove" android:title="@string/menu_popup_remove" /> + + \ No newline at end of file diff --git a/app/src/main/res/values-de/strings_main.xml b/app/src/main/res/values-de/strings_main.xml index 751398f3..176ce808 100644 --- a/app/src/main/res/values-de/strings_main.xml +++ b/app/src/main/res/values-de/strings_main.xml @@ -45,6 +45,8 @@ Bild ändern Entfernen Zeige QR-Code + Als Keystrokes teilen + Weitere Optionen Weitere Optionen für %1$s diff --git a/app/src/main/res/values-de/strings_settings.xml b/app/src/main/res/values-de/strings_settings.xml index 84878ba4..6ee40bc8 100644 --- a/app/src/main/res/values-de/strings_settings.xml +++ b/app/src/main/res/values-de/strings_settings.xml @@ -137,6 +137,7 @@ Anzeigen/Verstecken Kopieren Kopieren und in den Hintergrund wechseln + Als Keystrokes teilen Beschriftung diff --git a/app/src/main/res/values/settings.xml b/app/src/main/res/values/settings.xml index 944249e4..30518aa7 100644 --- a/app/src/main/res/values/settings.xml +++ b/app/src/main/res/values/settings.xml @@ -133,6 +133,7 @@ reveal copy copy_background + send_keystrokes diff --git a/app/src/main/res/values/strings_main.xml b/app/src/main/res/values/strings_main.xml index c19999fe..2f067254 100644 --- a/app/src/main/res/values/strings_main.xml +++ b/app/src/main/res/values/strings_main.xml @@ -62,6 +62,7 @@ Remove Show QR Code Enter pin + Share as Keystrokes More options diff --git a/app/src/main/res/values/strings_settings.xml b/app/src/main/res/values/strings_settings.xml index b41f6ee3..61d71ea7 100644 --- a/app/src/main/res/values/strings_settings.xml +++ b/app/src/main/res/values/strings_settings.xml @@ -205,6 +205,7 @@ Reveal/Hide Copy Copy and go to background + Share as Keystrokes