From 84875553159a200902745b124627f7107ce62526 Mon Sep 17 00:00:00 2001 From: Philipp Crocoll Date: Mon, 22 Jan 2018 12:48:40 +0100 Subject: [PATCH] fix issue with displaying long passwords by using two different TextViews for the visible and "protected" password view, toggling visibility instead of InputType. Fixes #96. --- src/keepass2android/EntryActivity.cs | 111 +++++++++++------- .../StandardStringView.cs | 33 +++--- .../layout/entry_extrastring_value.xml | 7 ++ .../Resources/layout/entry_view_contents.xml | 6 + 4 files changed, 101 insertions(+), 56 deletions(-) diff --git a/src/keepass2android/EntryActivity.cs b/src/keepass2android/EntryActivity.cs index a3c1a621..f07d4b0a 100644 --- a/src/keepass2android/EntryActivity.cs +++ b/src/keepass2android/EntryActivity.cs @@ -91,7 +91,14 @@ namespace keepass2android private int _pos; AppTask _appTask; - private List _protectedTextViews; + + struct ProtectedTextviewGroup + { + public TextView ProtectedField; + public TextView VisibleProtectedField; + } + + private List _protectedTextViews; private IMenu _menu; private readonly Dictionary> _popupMenuItems = @@ -476,14 +483,24 @@ namespace keepass2android RelativeLayout valueViewContainer = (RelativeLayout) LayoutInflater.Inflate(Resource.Layout.entry_extrastring_value, null); var valueView = valueViewContainer.FindViewById(Resource.Id.entry_extra); - if (value != null) - valueView.Text = value; - SetPasswordTypeface(valueView); - if (isProtected) - { - RegisterProtectedTextView(valueView); - valueView.TransformationMethod = PasswordTransformationMethod.Instance; - } + var valueViewVisible = valueViewContainer.FindViewById(Resource.Id.entry_extra_visible); + if (value != null) + { + valueView.Text = value; + valueViewVisible.Text = value; + + } + SetPasswordTypeface(valueViewVisible); + if (isProtected) + { + RegisterProtectedTextView(valueView, valueViewVisible); + //valueView.TransformationMethod = PasswordTransformationMethod.Instance; + + } + else + { + valueView.Visibility = ViewStates.Gone; + } layout.AddView(valueViewContainer); var stringView = new ExtraStringView(layout, valueView, keyView); @@ -599,9 +616,9 @@ namespace keepass2android - private void RegisterProtectedTextView(TextView protectedTextView) + private void RegisterProtectedTextView(TextView protectedTextView, TextView visibleTextView) { - _protectedTextViews.Add(protectedTextView); + _protectedTextViews.Add(new ProtectedTextviewGroup { ProtectedField = protectedTextView, VisibleProtectedField = visibleTextView}); } @@ -687,7 +704,7 @@ namespace keepass2android protected void FillData() { - _protectedTextViews = new List(); + _protectedTextViews = new List(); ImageView iv = (ImageView) FindViewById(Resource.Id.icon); if (iv != null) { @@ -704,9 +721,9 @@ namespace keepass2android PopulateStandardText(Resource.Id.entry_user_name, Resource.Id.entryfield_container_username, PwDefs.UserNameField); PopulateStandardText(Resource.Id.entry_url, Resource.Id.entryfield_container_url, PwDefs.UrlField); - PopulateStandardText(Resource.Id.entry_password, Resource.Id.entryfield_container_password, PwDefs.PasswordField); - RegisterProtectedTextView(FindViewById(Resource.Id.entry_password)); - SetPasswordTypeface(FindViewById(Resource.Id.entry_password)); + PopulateStandardText(new List { Resource.Id.entry_password, Resource.Id.entry_password_visible}, Resource.Id.entryfield_container_password, PwDefs.PasswordField); + + RegisterProtectedTextView(FindViewById(Resource.Id.entry_password), FindViewById(Resource.Id.entry_password_visible)); RegisterTextPopup(FindViewById (Resource.Id.groupname_container), FindViewById (Resource.Id.entry_group_name), KeyGroupFullPath); @@ -820,28 +837,43 @@ namespace keepass2android textView.Typeface = _passwordFont; } - private void PopulateText(int viewId, int containerViewId, String text) + private void PopulateText(int viewId, int containerViewId, String text) + { + PopulateText(new List {viewId}, containerViewId, text); + } + + + private void PopulateText(List viewIds, int containerViewId, String text) { View container = FindViewById(containerViewId); - TextView tv = (TextView) FindViewById(viewId); - if (String.IsNullOrEmpty(text)) - { - container.Visibility = tv.Visibility = ViewStates.Gone; - } - else - { - container.Visibility = tv.Visibility = ViewStates.Visible; - tv.Text = text; + foreach (int viewId in viewIds) + { + TextView tv = (TextView) FindViewById(viewId); + if (String.IsNullOrEmpty(text)) + { + container.Visibility = tv.Visibility = ViewStates.Gone; + } + else + { + container.Visibility = tv.Visibility = ViewStates.Visible; + tv.Text = text; - } + } + } } - private void PopulateStandardText(int viewId, int containerViewId, String key) + private void PopulateStandardText(int viewId, int containerViewId, String key) + { + PopulateStandardText(new List {viewId}, containerViewId, key); + } + + + private void PopulateStandardText(List viewIds, int containerViewId, String key) { String value = Entry.Strings.ReadSafe(key); value = SprEngine.Compile(value, new SprContext(Entry, App.Kp2a.GetDb().KpDatabase, SprCompileFlags.All)); - PopulateText(viewId, containerViewId, value); - _stringViews.Add(key, new StandardStringView(viewId, containerViewId, this)); + PopulateText(viewIds, containerViewId, value); + _stringViews.Add(key, new StandardStringView(viewIds, containerViewId, this)); } private void PopulateGroupText(int viewId, int containerViewId, String key) @@ -853,7 +885,7 @@ namespace keepass2android groupName = Entry.ParentGroup.GetFullPath(); } PopulateText(viewId, containerViewId, groupName); - _stringViews.Add (key, new StandardStringView (viewId, containerViewId, this)); + _stringViews.Add (key, new StandardStringView (new List{viewId}, containerViewId, this)); } private void RequiresRefresh() @@ -932,20 +964,15 @@ namespace keepass2android private void SetPasswordStyle() { - foreach (TextView password in _protectedTextViews) + foreach (ProtectedTextviewGroup group in _protectedTextViews) { - if (_showPassword) - { - //password.TransformationMethod = null; - password.InputType = password.InputType = InputTypes.ClassText | InputTypes.TextVariationVisiblePassword; - SetPasswordTypeface(password); - } - else - { - //password.TransformationMethod = PasswordTransformationMethod.Instance; - password.InputType = InputTypes.ClassText | InputTypes.TextVariationPassword; - } + group.VisibleProtectedField.Visibility = _showPassword ? ViewStates.Visible : ViewStates.Gone; + group.ProtectedField.Visibility = !_showPassword ? ViewStates.Visible : ViewStates.Gone; + + SetPasswordTypeface(group.VisibleProtectedField); + + group.ProtectedField.InputType = InputTypes.ClassText | InputTypes.TextVariationPassword; } } diff --git a/src/keepass2android/EntryActivityClasses/StandardStringView.cs b/src/keepass2android/EntryActivityClasses/StandardStringView.cs index bcbcb019..c307a3c2 100644 --- a/src/keepass2android/EntryActivityClasses/StandardStringView.cs +++ b/src/keepass2android/EntryActivityClasses/StandardStringView.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using Android.App; using Android.Views; using Android.Widget; @@ -7,13 +9,13 @@ namespace keepass2android { internal class StandardStringView : IStringView { - private readonly int _viewId; + private readonly List _viewIds; private readonly int _containerViewId; private readonly Activity _activity; - public StandardStringView(int viewId, int containerViewId, Activity activity) + public StandardStringView(List viewIds, int containerViewId, Activity activity) { - _viewId = viewId; + _viewIds = viewIds; _containerViewId = containerViewId; _activity = activity; } @@ -23,20 +25,23 @@ namespace keepass2android set { View container = _activity.FindViewById(_containerViewId); - TextView tv = (TextView) _activity.FindViewById(_viewId); - if (String.IsNullOrEmpty(value)) - { - container.Visibility = tv.Visibility = ViewStates.Gone; - } - else - { - container.Visibility = tv.Visibility = ViewStates.Visible; - tv.Text = value; - } + foreach (int viewId in _viewIds) + { + TextView tv = (TextView) _activity.FindViewById(viewId); + if (String.IsNullOrEmpty(value)) + { + container.Visibility = tv.Visibility = ViewStates.Gone; + } + else + { + container.Visibility = tv.Visibility = ViewStates.Visible; + tv.Text = value; + } + } } get { - TextView tv = (TextView) _activity.FindViewById(_viewId); + TextView tv = (TextView) _activity.FindViewById(_viewIds.First()); return tv.Text; } } diff --git a/src/keepass2android/Resources/layout/entry_extrastring_value.xml b/src/keepass2android/Resources/layout/entry_extrastring_value.xml index b5d14fe1..0bc1272e 100644 --- a/src/keepass2android/Resources/layout/entry_extrastring_value.xml +++ b/src/keepass2android/Resources/layout/entry_extrastring_value.xml @@ -22,4 +22,11 @@ android:typeface="monospace" android:layout_toLeftOf="@id/extra_vdots" style="@style/EntryItem" /> + \ No newline at end of file diff --git a/src/keepass2android/Resources/layout/entry_view_contents.xml b/src/keepass2android/Resources/layout/entry_view_contents.xml index 8c05ad38..4d08fa4f 100644 --- a/src/keepass2android/Resources/layout/entry_view_contents.xml +++ b/src/keepass2android/Resources/layout/entry_view_contents.xml @@ -174,6 +174,12 @@ android:typeface="monospace" android:layout_toLeftOf="@id/password_vdots" style="@style/EntryItem" /> +