From aa2b8088a41c2f32d8748361602d5e8d06f6c5b1 Mon Sep 17 00:00:00 2001 From: tjado Date: Wed, 21 Dec 2016 13:34:19 +0100 Subject: [PATCH] Deactivate vertical layout scrolling (e.g. due to very long passwords) during horizontal scrolling in a password field. Additional small adjustments in regard to the layout. --- .../tjado/passwdsafe/FileListFragment.java | 1 - .../PasswdSafeEditRecordFragment.java | 52 +++++++++++++++++++ .../passwdsafe/StorageFileListFragment.java | 1 - .../fragment_passwdsafe_edit_record.xml | 49 ++++++++++------- .../layout/fragment_passwdsafe_open_file.xml | 2 +- 5 files changed, 83 insertions(+), 22 deletions(-) diff --git a/authorizer/src/main/java/net/tjado/passwdsafe/FileListFragment.java b/authorizer/src/main/java/net/tjado/passwdsafe/FileListFragment.java index d6d4d8011..680a78499 100644 --- a/authorizer/src/main/java/net/tjado/passwdsafe/FileListFragment.java +++ b/authorizer/src/main/java/net/tjado/passwdsafe/FileListFragment.java @@ -20,7 +20,6 @@ import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; -import android.graphics.Color; import android.net.Uri; import android.os.Bundle; import android.os.Environment; diff --git a/authorizer/src/main/java/net/tjado/passwdsafe/PasswdSafeEditRecordFragment.java b/authorizer/src/main/java/net/tjado/passwdsafe/PasswdSafeEditRecordFragment.java index bebb5bb10..9631422e1 100644 --- a/authorizer/src/main/java/net/tjado/passwdsafe/PasswdSafeEditRecordFragment.java +++ b/authorizer/src/main/java/net/tjado/passwdsafe/PasswdSafeEditRecordFragment.java @@ -26,6 +26,7 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.view.MotionEvent; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; @@ -222,7 +223,35 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, TypefaceUtils.setMonospace(itsPasswordCurrent, ctx); itsPasswordInput = (TextInputLayout) rootView.findViewById(R.id.password_input); + + itsPassword = (TextView)rootView.findViewById(R.id.password); + + // disable vertical scrolling if scrolling is already in progress in the TextView + // http://stackoverflow.com/a/22609646 + // thanks to Hardik + itsPassword.setOnTouchListener(new TextView.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + int action = event.getAction(); + switch (action) { + case MotionEvent.ACTION_DOWN: + // Disallow View to intercept touch events. + v.getParent().requestDisallowInterceptTouchEvent(true); + break; + + case MotionEvent.ACTION_UP: + // Allow View to intercept touch events. + v.getParent().requestDisallowInterceptTouchEvent(false); + break; + } + + // Handle HorizontalScrollView touch events. + v.onTouchEvent(event); + return true; + } + }); + TypefaceUtils.setMonospace(itsPassword, ctx); View passwordVisibility = rootView.findViewById(R.id.password_visibility); @@ -237,6 +266,29 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, rootView.findViewById(R.id.password_confirm_input); itsPasswordConfirm = (TextView) rootView.findViewById(R.id.password_confirm); + itsPasswordConfirm.setOnTouchListener(new TextView.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + int action = event.getAction(); + switch (action) { + case MotionEvent.ACTION_DOWN: + // Disallow View to intercept touch events. + v.getParent().requestDisallowInterceptTouchEvent(true); + break; + + case MotionEvent.ACTION_UP: + // Allow View to intercept touch events. + v.getParent().requestDisallowInterceptTouchEvent(false); + break; + } + + // Handle HorizontalScrollView touch events. + v.onTouchEvent(event); + return true; + } + }); + + TypefaceUtils.setMonospace(itsPasswordConfirm, ctx); itsValidator.registerTextView(itsPasswordConfirm); diff --git a/authorizer/src/main/java/net/tjado/passwdsafe/StorageFileListFragment.java b/authorizer/src/main/java/net/tjado/passwdsafe/StorageFileListFragment.java index 4736fb32f..57e713f18 100644 --- a/authorizer/src/main/java/net/tjado/passwdsafe/StorageFileListFragment.java +++ b/authorizer/src/main/java/net/tjado/passwdsafe/StorageFileListFragment.java @@ -14,7 +14,6 @@ import android.content.Intent; import android.content.res.Resources; import android.database.Cursor; -import android.graphics.Color; import android.net.Uri; import android.os.Bundle; import android.support.annotation.Nullable; diff --git a/authorizer/src/main/res/layout/fragment_passwdsafe_edit_record.xml b/authorizer/src/main/res/layout/fragment_passwdsafe_edit_record.xml index f201350aa..827b24543 100644 --- a/authorizer/src/main/res/layout/fragment_passwdsafe_edit_record.xml +++ b/authorizer/src/main/res/layout/fragment_passwdsafe_edit_record.xml @@ -201,7 +201,9 @@ android:id="@+id/password_input" android:layout_width="match_parent" android:layout_height="wrap_content" - app:passwordToggleEnabled="false"> + app:passwordToggleEnabled="false" + android:layout_toLeftOf="@+id/password_visibility" + android:layout_toStartOf="@+id/password_visibility"> + android:src="?attr/drawableActionVisibility" + android:tint="@color/colorPrimary"/> + + + + + + + - + android:src="?attr/drawableActionNewPassword" + android:tint="@color/colorPrimary"/> - - - +