Bug fix: Fingerprint QuickUnlock was not working correctly

make sure bottom bar buttons don't overlap (by moving the right button down if necessary)
make sure dialog buttons are visible (by switching to vertical layout if necessary)
This commit is contained in:
Philipp Crocoll 2016-01-04 15:34:58 +01:00
parent a10a92d58d
commit 490fe1cd63
9 changed files with 70 additions and 20 deletions

View File

@ -91,10 +91,7 @@ namespace keepass2android
public static float convertDpToPixel(float dp, Context context)
{
Resources resources = context.Resources;
DisplayMetrics metrics = resources.DisplayMetrics;
float px = dp * metrics.Density;
return px;
return Util.convertDpToPixel(dp, context);
}

View File

@ -273,6 +273,7 @@ namespace keepass2android
{
FindViewById(Resource.Id.cancel_insert_element).Click += (sender, args) => StopMovingElements();
FindViewById(Resource.Id.insert_element).Click += (sender, args) => InsertElements();
Util.MoveBottomBarButtons(Resource.Id.cancel_insert_element, Resource.Id.insert_element, Resource.Id.bottom_bar, this);
}

View File

@ -1133,10 +1133,13 @@ namespace keepass2android
OnOk();
};
string label = FindViewById<Button>(Resource.Id.change_db).Text;
var changeDbButton = FindViewById<Button>(Resource.Id.change_db);
string label = changeDbButton.Text;
if (label.EndsWith("…"))
FindViewById<Button>(Resource.Id.change_db).Text = label.Substring(0, label.Length - 1);
FindViewById<Button>(Resource.Id.change_db).Click += (sender, args) => GoToFileSelectActivity();
changeDbButton.Text = label.Substring(0, label.Length - 1);
changeDbButton.Click += (sender, args) => GoToFileSelectActivity();
Util.MoveBottomBarButtons(Resource.Id.change_db, Resource.Id.pass_ok, Resource.Id.bottom_bar, this);
}
private void OnOk(bool usedFingerprintUnlock = false)
@ -2004,6 +2007,7 @@ namespace keepass2android
}
class SaveOtpAuxFileAndLoadDb : LoadDb
{
private readonly PasswordActivity _act;

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="69"
android:versionName="1.0.0 preview 2"
android:versionCode="70"
android:versionName="1.0.0 preview 3"
package="keepass2android.keepass2android"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" />

View File

@ -111,7 +111,7 @@ namespace keepass2android
EditText pwd = (EditText) FindViewById(Resource.Id.QuickUnlock_password);
pwd.SetEms(_quickUnlockLength);
Util.MoveBottomBarButtons(Resource.Id.QuickUnlock_buttonLock, Resource.Id.QuickUnlock_button, Resource.Id.bottom_bar, this);
Button btnUnlock = (Button) FindViewById(Resource.Id.QuickUnlock_button);
btnUnlock.Click += (object sender, EventArgs e) =>
@ -176,13 +176,14 @@ namespace keepass2android
public void OnFingerprintAuthSucceeded()
{
_fingerprintDec.StopListening();
var btn = FindViewById<ImageButton>(Resource.Id.fingerprintbtn);
btn.SetImageResource(Resource.Drawable.ic_fingerprint_success);
EditText pwd = (EditText)FindViewById(Resource.Id.QuickUnlock_password);
pwd.Text = ExpectedPasswordPart;
btn.PostDelayed(() =>
{
@ -199,9 +200,9 @@ namespace keepass2android
{
FingerprintUnlockMode um;
Enum.TryParse(PreferenceManager.GetDefaultSharedPreferences(this).GetString(App.Kp2a.GetDb().CurrentFingerprintModePrefKey, ""), out um);
btn.Visibility = (um == FingerprintUnlockMode.FullUnlock) ? ViewStates.Visible : ViewStates.Gone;
btn.Visibility = (um != FingerprintUnlockMode.Disabled) ? ViewStates.Visible : ViewStates.Gone;
if (um != FingerprintUnlockMode.FullUnlock)
if (um == FingerprintUnlockMode.Disabled)
{
return;
}

View File

@ -594,7 +594,7 @@
</string>
<string name="ChangeLog_1_0_0">
Version 1.0.0 - preview 2\n
Version 1.0.0 - preview 3\n
* Fingerprint Unlock (requires Android 6.0 or later)\n
* Added "work offline" mode\n
* Allow to copy entries\n

View File

@ -162,6 +162,8 @@ namespace keepass2android
{
createUrlEntry.Visibility = ViewStates.Gone;
}
Util.MoveBottomBarButtons(Resource.Id.select_other_entry, Resource.Id.add_url_entry, Resource.Id.bottom_bar, this);
}
public override bool OnSearchRequested()

View File

@ -28,6 +28,8 @@ using Android.Provider;
using Android.Views;
using Android.Widget;
using Android.Content.PM;
using Android.Content.Res;
using Android.Util;
using KeePassLib.Serialization;
using Uri = Android.Net.Uri;
@ -35,6 +37,14 @@ namespace keepass2android
{
public class Util {
public static float convertDpToPixel(float dp, Context context)
{
Resources resources = context.Resources;
DisplayMetrics metrics = resources.DisplayMetrics;
float px = dp * metrics.Density;
return px;
}
public static String GetClipboard(Context context) {
Android.Text.ClipboardManager clipboard = (Android.Text.ClipboardManager) context.GetSystemService(Context.ClipboardService);
return clipboard.Text;
@ -444,7 +454,20 @@ namespace keepass2android
}
}
public static void MoveBottomBarButtons(int btn1Id, int btn2Id, int bottomBarId, Activity context)
{
var btn1 = context.FindViewById<Button>(btn1Id);
var btn2 = context.FindViewById<Button>(btn2Id);
var rl = context.FindViewById<RelativeLayout>(bottomBarId);
rl.ViewTreeObserver.GlobalLayout += (sender, args) =>
{
if (btn1.Width + btn2.Width > rl.Width)
{
btn2.SetPadding(btn2.PaddingLeft, (int) Util.convertDpToPixel(40, context), btn2.PaddingRight, btn2.PaddingBottom);
}
};
}
}
}

View File

@ -336,18 +336,40 @@ namespace keepass2android
builder.SetMessage(GetResourceString(messageKey));
builder.SetPositiveButton(GetResourceString(yesString), yesHandler);
string yesText = GetResourceString(yesString);
builder.SetPositiveButton(yesText, yesHandler);
string noText = "";
if (noHandler != null)
builder.SetNegativeButton(GetResourceString(noString), noHandler);
{
noText = GetResourceString(noString);
builder.SetNegativeButton(noText, noHandler);
}
string cancelText = "";
if (cancelHandler != null)
{
builder.SetNeutralButton(ctx.GetString(Android.Resource.String.Cancel),
cancelText = ctx.GetString(Android.Resource.String.Cancel);
builder.SetNeutralButton(cancelText,
cancelHandler);
}
Dialog dialog = builder.Create();
AlertDialog dialog = builder.Create();
dialog.Show();
if (yesText.Length + noText.Length + cancelText.Length >= 20)
{
try
{
Button button = dialog.GetButton((int)DialogButtonType.Positive);
LinearLayout linearLayout = (LinearLayout)button.Parent;
linearLayout.Orientation = Orientation.Vertical;
}
catch (Exception e)
{
Kp2aLog.Log(e.ToString());
}
}
}
);
}