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.

This commit is contained in:
Philipp Crocoll
2018-01-22 12:48:40 +01:00
parent 304c1ef5d2
commit 8487555315
4 changed files with 101 additions and 56 deletions

View File

@@ -91,7 +91,14 @@ namespace keepass2android
private int _pos;
AppTask _appTask;
private List<TextView> _protectedTextViews;
struct ProtectedTextviewGroup
{
public TextView ProtectedField;
public TextView VisibleProtectedField;
}
private List<ProtectedTextviewGroup> _protectedTextViews;
private IMenu _menu;
private readonly Dictionary<string, List<IPopupMenuItem>> _popupMenuItems =
@@ -476,14 +483,24 @@ namespace keepass2android
RelativeLayout valueViewContainer =
(RelativeLayout) LayoutInflater.Inflate(Resource.Layout.entry_extrastring_value, null);
var valueView = valueViewContainer.FindViewById<TextView>(Resource.Id.entry_extra);
if (value != null)
valueView.Text = value;
SetPasswordTypeface(valueView);
if (isProtected)
{
RegisterProtectedTextView(valueView);
valueView.TransformationMethod = PasswordTransformationMethod.Instance;
}
var valueViewVisible = valueViewContainer.FindViewById<TextView>(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<TextView>();
_protectedTextViews = new List<ProtectedTextviewGroup>();
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<TextView>(Resource.Id.entry_password));
SetPasswordTypeface(FindViewById<TextView>(Resource.Id.entry_password));
PopulateStandardText(new List<int> { Resource.Id.entry_password, Resource.Id.entry_password_visible}, Resource.Id.entryfield_container_password, PwDefs.PasswordField);
RegisterProtectedTextView(FindViewById<TextView>(Resource.Id.entry_password), FindViewById<TextView>(Resource.Id.entry_password_visible));
RegisterTextPopup(FindViewById<RelativeLayout> (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<int> {viewId}, containerViewId, text);
}
private void PopulateText(List<int> 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<int> {viewId}, containerViewId, key);
}
private void PopulateStandardText(List<int> 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<int>{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;
}
}

View File

@@ -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<int> _viewIds;
private readonly int _containerViewId;
private readonly Activity _activity;
public StandardStringView(int viewId, int containerViewId, Activity activity)
public StandardStringView(List<int> 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;
}
}

View File

@@ -22,4 +22,11 @@
android:typeface="monospace"
android:layout_toLeftOf="@id/extra_vdots"
style="@style/EntryItem" />
<TextView
android:id="@+id/entry_extra_visible"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:typeface="monospace"
android:layout_toLeftOf="@id/extra_vdots"
style="@style/EntryItem" />
</RelativeLayout>

View File

@@ -174,6 +174,12 @@
android:typeface="monospace"
android:layout_toLeftOf="@id/password_vdots"
style="@style/EntryItem" />
<TextView
android:id="@+id/entry_password_visible"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/password_vdots"
style="@style/EntryItem" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>