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:
		| @@ -91,7 +91,14 @@ namespace keepass2android | |||||||
| 		private int _pos; | 		private int _pos; | ||||||
|  |  | ||||||
| 		AppTask _appTask; | 		AppTask _appTask; | ||||||
| 		private List<TextView> _protectedTextViews; |  | ||||||
|  | 	    struct ProtectedTextviewGroup | ||||||
|  | 	    { | ||||||
|  | 	        public TextView ProtectedField; | ||||||
|  | 	        public TextView VisibleProtectedField; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  | 		private List<ProtectedTextviewGroup> _protectedTextViews; | ||||||
| 		private IMenu _menu; | 		private IMenu _menu; | ||||||
|  |  | ||||||
| 		private readonly Dictionary<string, List<IPopupMenuItem>> _popupMenuItems = | 		private readonly Dictionary<string, List<IPopupMenuItem>> _popupMenuItems = | ||||||
| @@ -476,13 +483,23 @@ namespace keepass2android | |||||||
| 			RelativeLayout valueViewContainer = | 			RelativeLayout valueViewContainer = | ||||||
| 				(RelativeLayout) LayoutInflater.Inflate(Resource.Layout.entry_extrastring_value, null); | 				(RelativeLayout) LayoutInflater.Inflate(Resource.Layout.entry_extrastring_value, null); | ||||||
| 			var valueView = valueViewContainer.FindViewById<TextView>(Resource.Id.entry_extra); | 			var valueView = valueViewContainer.FindViewById<TextView>(Resource.Id.entry_extra); | ||||||
|  | 		    var valueViewVisible = valueViewContainer.FindViewById<TextView>(Resource.Id.entry_extra_visible); | ||||||
| 		    if (value != null) | 		    if (value != null) | ||||||
|  | 		    { | ||||||
| 		        valueView.Text = value; | 		        valueView.Text = value; | ||||||
| 			SetPasswordTypeface(valueView); |                 valueViewVisible.Text = value; | ||||||
|  |  | ||||||
|  |             } | ||||||
|  | 		    SetPasswordTypeface(valueViewVisible); | ||||||
| 		    if (isProtected) | 		    if (isProtected) | ||||||
| 		    { | 		    { | ||||||
| 				RegisterProtectedTextView(valueView); | 		        RegisterProtectedTextView(valueView, valueViewVisible); | ||||||
| 				valueView.TransformationMethod = PasswordTransformationMethod.Instance; | 		        //valueView.TransformationMethod = PasswordTransformationMethod.Instance; | ||||||
|  |                  | ||||||
|  | 		    } | ||||||
|  | 		    else | ||||||
|  | 		    { | ||||||
|  | 		        valueView.Visibility = ViewStates.Gone; | ||||||
| 		    } | 		    } | ||||||
|  |  | ||||||
| 			layout.AddView(valueViewContainer); | 			layout.AddView(valueViewContainer); | ||||||
| @@ -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() | 		protected void FillData() | ||||||
| 		{ | 		{ | ||||||
| 			_protectedTextViews = new List<TextView>(); | 			_protectedTextViews = new List<ProtectedTextviewGroup>(); | ||||||
| 			ImageView iv = (ImageView) FindViewById(Resource.Id.icon); | 			ImageView iv = (ImageView) FindViewById(Resource.Id.icon); | ||||||
| 			if (iv != null) | 			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_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_url, Resource.Id.entryfield_container_url, PwDefs.UrlField); | ||||||
| 			PopulateStandardText(Resource.Id.entry_password, Resource.Id.entryfield_container_password, PwDefs.PasswordField); | 			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)); | 		     | ||||||
| 			SetPasswordTypeface(FindViewById<TextView>(Resource.Id.entry_password)); |             RegisterProtectedTextView(FindViewById<TextView>(Resource.Id.entry_password), FindViewById<TextView>(Resource.Id.entry_password_visible)); | ||||||
|  |  | ||||||
| 			RegisterTextPopup(FindViewById<RelativeLayout> (Resource.Id.groupname_container), | 			RegisterTextPopup(FindViewById<RelativeLayout> (Resource.Id.groupname_container), | ||||||
| 				              FindViewById (Resource.Id.entry_group_name), KeyGroupFullPath); | 				              FindViewById (Resource.Id.entry_group_name), KeyGroupFullPath); | ||||||
| @@ -821,8 +838,16 @@ namespace keepass2android | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 	    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); | 			View container = FindViewById(containerViewId); | ||||||
|  | 		    foreach (int viewId in viewIds) | ||||||
|  | 		    { | ||||||
| 		        TextView tv = (TextView) FindViewById(viewId); | 		        TextView tv = (TextView) FindViewById(viewId); | ||||||
| 		        if (String.IsNullOrEmpty(text)) | 		        if (String.IsNullOrEmpty(text)) | ||||||
| 		        { | 		        { | ||||||
| @@ -835,13 +860,20 @@ namespace keepass2android | |||||||
|  |  | ||||||
| 		        } | 		        } | ||||||
| 		    } | 		    } | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 	    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); | 			String value = Entry.Strings.ReadSafe(key); | ||||||
| 			value = SprEngine.Compile(value, new SprContext(Entry, App.Kp2a.GetDb().KpDatabase, SprCompileFlags.All)); | 			value = SprEngine.Compile(value, new SprContext(Entry, App.Kp2a.GetDb().KpDatabase, SprCompileFlags.All)); | ||||||
| 			PopulateText(viewId, containerViewId, value); | 			PopulateText(viewIds, containerViewId, value); | ||||||
| 			_stringViews.Add(key, new StandardStringView(viewId, containerViewId, this)); | 			_stringViews.Add(key, new StandardStringView(viewIds, containerViewId, this)); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		private void PopulateGroupText(int viewId, int containerViewId, String key) | 		private void PopulateGroupText(int viewId, int containerViewId, String key) | ||||||
| @@ -853,7 +885,7 @@ namespace keepass2android | |||||||
| 				groupName = Entry.ParentGroup.GetFullPath(); | 				groupName = Entry.ParentGroup.GetFullPath(); | ||||||
| 			} | 			} | ||||||
| 			PopulateText(viewId, containerViewId, groupName); | 			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() | 		private void RequiresRefresh() | ||||||
| @@ -932,20 +964,15 @@ namespace keepass2android | |||||||
|  |  | ||||||
| 		private void SetPasswordStyle() | 		private void SetPasswordStyle() | ||||||
| 		{ | 		{ | ||||||
| 			foreach (TextView password in _protectedTextViews) | 			foreach (ProtectedTextviewGroup group in _protectedTextViews) | ||||||
| 			{ | 			{ | ||||||
|  |  | ||||||
| 				if (_showPassword) |                 group.VisibleProtectedField.Visibility = _showPassword ? ViewStates.Visible : ViewStates.Gone; | ||||||
| 				{ |                 group.ProtectedField.Visibility = !_showPassword ? ViewStates.Visible : ViewStates.Gone; | ||||||
| 					//password.TransformationMethod = null; |  | ||||||
| 					password.InputType = password.InputType = InputTypes.ClassText | InputTypes.TextVariationVisiblePassword; | 				SetPasswordTypeface(group.VisibleProtectedField); | ||||||
| 					SetPasswordTypeface(password); |  | ||||||
| 				} |                 group.ProtectedField.InputType = InputTypes.ClassText | InputTypes.TextVariationPassword; | ||||||
| 				else |  | ||||||
| 				{ |  | ||||||
| 					//password.TransformationMethod = PasswordTransformationMethod.Instance; |  | ||||||
| 					password.InputType = InputTypes.ClassText | InputTypes.TextVariationPassword; |  | ||||||
| 				} |  | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,4 +1,6 @@ | |||||||
| using System; | using System; | ||||||
|  | using System.Collections.Generic; | ||||||
|  | using System.Linq; | ||||||
| using Android.App; | using Android.App; | ||||||
| using Android.Views; | using Android.Views; | ||||||
| using Android.Widget; | using Android.Widget; | ||||||
| @@ -7,13 +9,13 @@ namespace keepass2android | |||||||
| { | { | ||||||
| 	internal class StandardStringView : IStringView | 	internal class StandardStringView : IStringView | ||||||
| 	{ | 	{ | ||||||
| 		private readonly int _viewId; | 		private readonly List<int> _viewIds; | ||||||
| 		private readonly int _containerViewId; | 		private readonly int _containerViewId; | ||||||
| 		private readonly Activity _activity; | 		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; | 			_containerViewId = containerViewId; | ||||||
| 			_activity = activity; | 			_activity = activity; | ||||||
| 		} | 		} | ||||||
| @@ -23,7 +25,9 @@ namespace keepass2android | |||||||
| 			set | 			set | ||||||
| 			{ | 			{ | ||||||
| 				View container = _activity.FindViewById(_containerViewId); | 				View container = _activity.FindViewById(_containerViewId); | ||||||
| 				TextView tv = (TextView) _activity.FindViewById(_viewId); | 			    foreach (int viewId in _viewIds) | ||||||
|  | 			    { | ||||||
|  | 			        TextView tv = (TextView) _activity.FindViewById(viewId); | ||||||
| 			        if (String.IsNullOrEmpty(value)) | 			        if (String.IsNullOrEmpty(value)) | ||||||
| 			        { | 			        { | ||||||
| 			            container.Visibility = tv.Visibility = ViewStates.Gone; | 			            container.Visibility = tv.Visibility = ViewStates.Gone; | ||||||
| @@ -34,9 +38,10 @@ namespace keepass2android | |||||||
| 			            tv.Text = value; | 			            tv.Text = value; | ||||||
| 			        } | 			        } | ||||||
| 			    } | 			    } | ||||||
|  | 			} | ||||||
| 			get | 			get | ||||||
| 			{ | 			{ | ||||||
| 				TextView tv = (TextView) _activity.FindViewById(_viewId); | 				TextView tv = (TextView) _activity.FindViewById(_viewIds.First()); | ||||||
| 				return tv.Text; | 				return tv.Text; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -22,4 +22,11 @@ | |||||||
| 		android:typeface="monospace" | 		android:typeface="monospace" | ||||||
| 		android:layout_toLeftOf="@id/extra_vdots" | 		android:layout_toLeftOf="@id/extra_vdots" | ||||||
| 		style="@style/EntryItem" /> | 		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> | </RelativeLayout> | ||||||
| @@ -174,6 +174,12 @@ | |||||||
|             android:typeface="monospace" |             android:typeface="monospace" | ||||||
|             android:layout_toLeftOf="@id/password_vdots" |             android:layout_toLeftOf="@id/password_vdots" | ||||||
|             style="@style/EntryItem" /> |             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> |       </RelativeLayout> | ||||||
|     </LinearLayout> |     </LinearLayout> | ||||||
|   </LinearLayout> |   </LinearLayout> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Philipp Crocoll
					Philipp Crocoll