Skip to content

Commit

Permalink
reactivate QR scanning capabilities by using GMS CodeScanner (instead…
Browse files Browse the repository at this point in the history
… of ZXing which is no longer compatible with new .net Android); copy resource string from KP2AKeyboard project to app such that it can be used in the manifest.
  • Loading branch information
PhilippC committed Jan 7, 2025
1 parent 0e3ef76 commit a672e9b
Show file tree
Hide file tree
Showing 44 changed files with 418 additions and 227 deletions.
101 changes: 83 additions & 18 deletions src/keepass2android-appSdkStyle/EntryEditActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ You should have received a copy of the GNU General Public License
using System.Text;
using Android.Content.Res;
using Android.Database;
using Android.Gms.Tasks;
using Android.Graphics;
using Android.Graphics.Drawables;
using Android.Runtime;
Expand All @@ -53,6 +54,10 @@ You should have received a copy of the GNU General Public License
using Uri = Android.Net.Uri;
using Resource = keepass2android_appSdkStyle.Resource;
using Google.Android.Material.TextField;
using Xamarin.Google.MLKit.Vision.Barcode.Common;
using Xamarin.Google.MLKit.Vision.CodeScanner;
using Console = System.Console;
using Task = Android.Gms.Tasks.Task;

namespace keepass2android
{
Expand Down Expand Up @@ -1150,25 +1155,30 @@ private void EditTotpString(View sender)

dlgView.FindViewById<Button>(Resource.Id.totp_scan).Click += async (object o, EventArgs args) =>
{
/*TODO Restore this
var scanner = new ZXing..MobileBarcodeScanner();
var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
options.PossibleFormats = new List<ZXing.BarcodeFormat>() { ZXing.BarcodeFormat.QR_CODE };
var result = await scanner.Scan(options);
if (result?.Text?.StartsWith("otpauth://") == true)
{
dialog.Dismiss();
var targetField = ((TextView)((View)sender.Parent).FindViewById(Resource.Id.value));
targetField.Text = result.Text;
}
else
{
Toast.MakeText(this, "Scanned code should contain an otpauth:// text.", ToastLength.Long).Show();
}
*/
Toast.MakeText(this, "QR Scanner must be restored", ToastLength.Long).Show();
GmsBarcodeScannerOptions options = new GmsBarcodeScannerOptions.Builder()
.SetBarcodeFormats(Barcode.FormatQrCode)
.Build();
var scanner = GmsBarcodeScanning.GetClient(this, options);

scanner.StartScan()
.AddOnSuccessListener(new SuccessListener((barcode) =>
{
if (barcode.RawValue?.StartsWith("otpauth://") == true)
{
dialog.Dismiss();
var targetField = ((TextView)((View)sender.Parent).FindViewById(Resource.Id.value));
targetField.Text = barcode.RawValue;
}
else
{
Toast.MakeText(this, "Scanned code should contain an otpauth:// text.", ToastLength.Long).Show();
}
}))
.AddOnFailureListener(new FailureListener((e) =>
{
Console.WriteLine($"Scan failed: {e.Message}");
}));


};

Expand Down Expand Up @@ -1550,6 +1560,61 @@ protected override void OnPause()
}
}

internal class BarcodeScanningFailureListener : Java.Lang.Object, IOnFailureListener
{
public BarcodeScanningFailureListener(Activity activity)
{

}

public void OnFailure(Java.Lang.Exception e)
{
Toast.MakeText(Application.Context, "Barcode scanning failed", ToastLength.Long).Show();
}
}

internal class BarcodeScanningCancelledListener : Java.Lang.Object, IOnCanceledListener
{
public BarcodeScanningCancelledListener(Activity activity)
{

}

public void OnCanceled()
{
Toast.MakeText(Application.Context, "Barcode scanning cancelled", ToastLength.Long).Show();
}
}
public class SuccessListener : Object, IOnSuccessListener
{
private readonly Action<Barcode> _onSuccess;

public SuccessListener(Action<Barcode> onSuccess)
{
_onSuccess = onSuccess;
}

public void OnSuccess(Object result)
{
_onSuccess?.Invoke((Barcode)result);
}
}

public class FailureListener : Java.Lang.Object, IOnFailureListener
{
private readonly Action<Exception> _onFailure;

public FailureListener(Action<Exception> onFailure)
{
_onFailure = onFailure;
}

public void OnFailure(Java.Lang.Exception e)
{
_onFailure?.Invoke(e);
}
}

public class DefaultEdit : EditModeBase
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
android:roundIcon="@mipmap/ic_launcher_online_round"
android:networkSecurityConfig="@xml/network_security_config"
>
<meta-data
android:name="com.google.mlkit.vision.DEPENDENCIES"
android:value="barcode_ui"/>

<uses-library
android:name="org.apache.http.legacy"
Expand Down Expand Up @@ -89,7 +92,7 @@
</intent-filter>
<meta-data android:name="android.view.im" android:resource="@xml/method" />
</service>
<activity android:name="keepass2android.softkeyboard.LatinIMESettings" android:label="english_ime_settings" android:exported="true">
<activity android:name="keepass2android.softkeyboard.LatinIMESettings" android:label="@string/english_ime_settings" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@

>

<meta-data
android:name="com.google.mlkit.vision.DEPENDENCIES"
android:value="barcode_ui"/>

<uses-library
android:name="org.apache.http.legacy"
android:required="false"/>
Expand Down Expand Up @@ -93,7 +97,7 @@
</intent-filter>
<meta-data android:name="android.view.im" android:resource="@xml/method" />
</service>
<activity android:name="keepass2android.softkeyboard.LatinIMESettings" android:label="english_ime_settings" android:exported="true">
<activity android:name="keepass2android.softkeyboard.LatinIMESettings" android:label="@string/english_ime_settings" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
android:icon="@mipmap/ic_launcher_offline"
android:networkSecurityConfig="@xml/network_security_config"
>

<meta-data
android:name="com.google.mlkit.vision.DEPENDENCIES"
android:value="barcode_ui"/>

<uses-library
android:name="org.apache.http.legacy"
android:required="false"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--Generated by crowdin.net-->
<?xml version='1.0' encoding='utf-8'?>
<resources>
<string name="about_feedback">التعليقات</string>
<string name="AboutText">Keepass2Android هو مدير كلمات سر يتيح القراءة والكتابة على قواعد بيانات KeePass 2.x على نظام الـAndroid.</string>
Expand Down Expand Up @@ -753,4 +752,6 @@
<string name="AutofillWarning_Intro">أنت على وشك إدراج بيانات اعتماد للنطاق \"%1$s\" في التطبيق \"%2$s\".</string>
<string name="AutofillWarning_FillDomainInUntrustedApp">إذا كنت تثق في \"%2$s\" بالانتماء إلى \"%1$s\" أو كنت تثق في التطبيق \"%2$s\" لعدم إساءة استخدام بيانات الاعتماد (e. . لأنه تطبيق متصفح موثوق به)، من المفضل المتابعة. إذا لم يكن الأمر كذلك ، يرجى الإلغاء .</string>
<string name="AutofillWarning_trustAsBrowser">قبول دائمًا في \"%1$s\"</string>
</resources>
<string name="english_ime_settings">إعدادات لوحة مفاتيح Keepass2Android</string>

</resources>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--Generated by crowdin.net-->
<?xml version='1.0' encoding='utf-8'?>
<resources>
<string name="about_feedback">Əks əlaqə</string>
<string name="accept">Qəbul et</string>
Expand Down Expand Up @@ -83,4 +82,6 @@
<string name="AutofillWarning_title">Təhlükəsizlik xəbərdarlığı: Tanınmayan domen/tətbiq bağlantısı</string>
<string name="AutofillWarning_Intro">\"%2$s\" tətbiqinə \"%1$s\" domeni üçün kimlik məlumatlarını daxil edirsiniz.</string>
<string name="AutofillWarning_trustAsBrowser">\"%1$s\" səyyahında həmişə qəbul et</string>
</resources>
<string name="english_ime_settings">Android klaviatura tənzimləmələri</string>

</resources>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--Generated by crowdin.net-->
<?xml version='1.0' encoding='utf-8'?>
<resources>
<string name="about_feedback">Зваротная сувязь</string>
<string name="AboutText">Keepass2Android - кіраўнік пароляў для Android з паўнавартаснай падтрымкай базаў даных KeePass 2.x.</string>
Expand Down Expand Up @@ -812,4 +811,6 @@
<string name="AutofillWarning_Intro">Вы хочаце ўставіць уліковыя даныя для дамена \"%1$s\" у праграму \"%2$s\".</string>
<string name="AutofillWarning_FillDomainInUntrustedApp">Калі ёсць упэўненасць, што \"%2$s\" належыць \"%1$s\" або вы давяраеце \"%2$s\", не злоўжывайце ўліковымі данымі (напрыклад, гэта давераная праграма браўзера). Калі ўсё добра, можна працягнуць. Калі не, скасуйце.</string>
<string name="AutofillWarning_trustAsBrowser">Заўсёды ўхваляць у \"%1$s\"</string>
</resources>
<string name="english_ime_settings">Налады клавіятуры Android</string>

</resources>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--Generated by crowdin.net-->
<?xml version='1.0' encoding='utf-8'?>
<resources>
<string name="about_feedback">Отзив</string>
<string name="AboutText">Keepass2Android е мениджър за пароли който осигурява достъп четене/записване до KeePass 2.x база данни на Android.</string>
Expand Down Expand Up @@ -464,4 +463,6 @@
<item>KP2A Private/Public key</item>
<item>Custom Private key</item>
</string-array>
</resources>
<string name="english_ime_settings">Настройки на клавиатурата на Keepass2Android</string>

</resources>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--Generated by crowdin.net-->
<?xml version='1.0' encoding='utf-8'?>
<resources>
<string name="about_feedback">Suggeriments</string>
<string name="AboutText">Keepass2Android és una implementació per Android de KeePass password manager.</string>
Expand Down Expand Up @@ -721,4 +720,6 @@
<string name="switch_ime_text">Si us plau, activa el teclat Keepass2Android.</string>
<string name="switch_ime_reopen">Reintenta</string>
<string name="AutofillWarning_trustAsBrowser">Acceptar sempre en \"%1$s\"</string>
</resources>
<string name="english_ime_settings">Configuració del teclat d\'Keepass2Android</string>

</resources>
11 changes: 6 additions & 5 deletions src/keepass2android-appSdkStyle/Resources/values-cs/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--Generated by crowdin.net-->
<?xml version='1.0' encoding='utf-8'?>
<resources>
<string name="about_feedback">Zpětná vazba</string>
<string name="AboutText">Keepass2Android je správce hesel pro práci se soubory KeePass 2.x. na platformě Android.</string>
Expand Down Expand Up @@ -679,9 +678,9 @@
• Ujistěte se, že jste použili správný typ hesla. Ujistěte se, že tento typ odpovídá typu použitému při vytváření databáze.\n
• Ujistěte se, že jste použili správný soubor databáze.</string>
<string name="HintLocalBackupInvalidCompositeKey"> \n
&#8226; Nápověda: Pokud si myslíte že by soubor databáze mohl být poškozený, nebo si nepamatujete hlavní klíč, můžete zkusit poslední úspěšně otevřenou verzi souboru kliknutím \"%1$s\" a zvolením místní zálohy.</string>
Nápověda: Pokud si myslíte že by soubor databáze mohl být poškozený, nebo si nepamatujete hlavní klíč, můžete zkusit poslední úspěšně otevřenou verzi souboru kliknutím \"%1$s\" a zvolením místní zálohy.</string>
<string name="HintLocalBackupOtherError"> \n
&#8226; Nápověda: Keepass2Android uložil poslední úspěšně otevřenou verzi souboru do interního úložiště. Můžete ji otevřít klepnutím na \"%1$s\" a výběrem místní zálohy.
Nápověda: Keepass2Android uložil poslední úspěšně otevřenou verzi souboru do interního úložiště. Můžete ji otevřít klepnutím na \"%1$s\" a výběrem místní zálohy.
</string>
<string name="CorruptDatabaseHelp"> Soubor je poškozený. \n
Zde je několik rad, které vám mohou pomoci zjistit příčinu problému:\n
Expand Down Expand Up @@ -1151,4 +1150,6 @@ První veřejné vydání
<string name="AutofillWarning_Intro">Chystáte se vložit přihlašovací údaje pro doménu \"%1$s\" do aplikace \"%2$s\".</string>
<string name="AutofillWarning_FillDomainInUntrustedApp">Pokud věříte že \"%2$s\" patří k \"%1$s\", nebo důvěřujete \"%2$s\" že nezneužije přihlašovací údaje (např. pokud se jedná o důvěryhodný prohlížeč), můžete pokračovat. Pokud tomu tak není, zrušte prosím tuto akci.</string>
<string name="AutofillWarning_trustAsBrowser">Přijmout vždy v \"%1$s\"</string>
</resources>
<string name="english_ime_settings">Nastavení klávesnice Keepass2Android</string>

</resources>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--Generated by crowdin.net-->
<?xml version='1.0' encoding='utf-8'?>
<resources>
<string name="about_feedback">Tilbagemelding</string>
<string name="AboutText">Keepass2Android er en adgangskodehåndterings-app, der giver læse-/skriveadgang til KeePass 2.x-databaser på Android.</string>
Expand Down Expand Up @@ -819,4 +818,6 @@
<string name="AutofillWarning_Intro">Du er ved at indsætte legitimationsoplysninger for domæne \"%1$s\" i appen \"%2$s\".</string>
<string name="AutofillWarning_FillDomainInUntrustedApp">Hvis du stoler på at \"%2$s\" tilhører \"%1$s\", eller du stoler på at app\'en \"%2$s\" ikke misbruger legitimationsoplysningerne (f.eks. fordi det er en betroet browser app), er det ok at fortsætte. Ellers bedes du annullere.</string>
<string name="AutofillWarning_trustAsBrowser">Accepter altid i \"%1$s\"</string>
</resources>
<string name="english_ime_settings">Indstillinger for Keepass2Android-tastatur</string>

</resources>
11 changes: 6 additions & 5 deletions src/keepass2android-appSdkStyle/Resources/values-de/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--Generated by crowdin.net-->
<?xml version='1.0' encoding='utf-8'?>
<resources>
<string name="about_feedback">Feedback</string>
<string name="AboutText">Keepass2Android ist ein Passwortmanager mit Lese- und Schreib-Zugriff auf KeePass 2.x Datenbanken.</string>
Expand Down Expand Up @@ -681,9 +680,9 @@ Der Android Robot wird genutzt und wurde modifiziert basierend auf Arbeiten, die
• Sicherstellen, dass die richtige Datenbankdatei gewählt wurde.
</string>
<string name="HintLocalBackupInvalidCompositeKey"> \n
&#8226; Tipp: Wenn die Vermutung besteht, die eigene Datenbankdatei könnte beschädigt sein oder sich nach einer Änderung nicht mehr an den Hauptschlüssel erinnern wird, kann man es mit der zuletzt erfolgreich geöffnete Dateiversion versuchen, indem auf „%1$s“ getippt und die lokale Sicherung ausgewählt wird.</string>
Tipp: Wenn die Vermutung besteht, die eigene Datenbankdatei könnte beschädigt sein oder sich nach einer Änderung nicht mehr an den Hauptschlüssel erinnern wird, kann man es mit der zuletzt erfolgreich geöffnete Dateiversion versuchen, indem auf „%1$s“ getippt und die lokale Sicherung ausgewählt wird.</string>
<string name="HintLocalBackupOtherError">\n
&#8226; Tipp: Keepass2Android hat die zuletzt erfolgreich geöffnete Dateiversion im internen Speicher gesichert. Diese kann geöffnet werden, indem „%1$s“ angetippt und das lokale Backup gewählte wird.</string>
Tipp: Keepass2Android hat die zuletzt erfolgreich geöffnete Dateiversion im internen Speicher gesichert. Diese kann geöffnet werden, indem „%1$s“ angetippt und das lokale Backup gewählte wird.</string>
<string name="CorruptDatabaseHelp">Die Datei ist beschädigt.\n
Anbei einige Tipps, die bei der Diagnose des Problems helfen können:\n

Expand Down Expand Up @@ -1145,4 +1144,6 @@ Erstes öffentliches Release</string>
<string name="AutofillWarning_Intro">Hiermit werden Anmeldeinformationen für die Domäne „%1$s“ in die Anwendung „%2$s“ eingefügt.</string>
<string name="AutofillWarning_FillDomainInUntrustedApp">Wenn darauf vertraut wird, dass „%2$s“ zu „%1$s“ gehört, oder wenn darauf vertraut wird, dass die App „%2$s“ die Anmeldeinformationen nicht missbraucht (z. B. weil es sich um eine vertrauenswürdige Browser-App handelt), kann fortgefahren werden. Falls nicht, bitte abbrechen.</string>
<string name="AutofillWarning_trustAsBrowser">Für „%1$s“ immer akzeptieren</string>
</resources>
<string name="english_ime_settings">Keepass2Android-Tastatureinstellungen</string>

</resources>
Loading

0 comments on commit a672e9b

Please sign in to comment.