From 4ba629982275441c3d5ac31ae4296a269dbce1b4 Mon Sep 17 00:00:00 2001 From: dtvv Date: Wed, 24 Oct 2018 03:56:21 -0500 Subject: [PATCH] -Search solution for the viewpager crashes actions when try to define a pattern horisontally -In the ChildViewPager of security settings disable swipe horisontally and navigation now it is by tabs -In the ChildViewPager modify the class so it can control when the swipe touch event is bloqued or not correctly --- .../fragments/PatternSecurityFragment.java | 15 ++++++- .../fragments/SecuritySettingsFragment.java | 5 ++- .../crystalwallet/util/ChildViewPager.java | 45 ++++++++++++------- 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/PatternSecurityFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/PatternSecurityFragment.java index e98d883..63e15d7 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/PatternSecurityFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/PatternSecurityFragment.java @@ -28,6 +28,7 @@ import butterknife.OnTextChanged; import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.application.CrystalSecurityMonitor; import cy.agorise.crystalwallet.models.GeneralSetting; +import cy.agorise.crystalwallet.util.ChildViewPager; import cy.agorise.crystalwallet.util.PasswordManager; import cy.agorise.crystalwallet.viewmodels.GeneralSettingListViewModel; import cy.agorise.crystalwallet.viewmodels.validators.PinSecurityValidator; @@ -45,9 +46,17 @@ public class PatternSecurityFragment extends Fragment { @BindView(R.id.tvPatternText) TextView tvPatternText; + /* + * Contains the ChildViewPager to block the viewpager when the user is using the pattern control + * */ + private ChildViewPager childViewPager; + private PatternLockViewListener actualPatternListener; private String patternEntered; + + + public PatternSecurityFragment() { // Required empty public constructor } @@ -80,6 +89,11 @@ public class PatternSecurityFragment extends Fragment { return patternString; } + public void setChildViewPager(ChildViewPager childViewPager) { + this.childViewPager = childViewPager; + } + + public void removePatternListener(){ if (actualPatternListener != null){ patternLockView.removePatternLockListener(actualPatternListener); @@ -96,7 +110,6 @@ public class PatternSecurityFragment extends Fragment { actualPatternListener = new PatternLockViewListener() { @Override public void onStarted() { - } @Override diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/SecuritySettingsFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/SecuritySettingsFragment.java index 7b5ee8c..a61d330 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/SecuritySettingsFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/SecuritySettingsFragment.java @@ -96,7 +96,6 @@ public class SecuritySettingsFragment extends Fragment { default: mPager.setCurrentItem(0); } - mPager.setSwipeLocked(true); TabLayout tabLayout = v.findViewById(R.id.tabs); @@ -134,7 +133,9 @@ public class SecuritySettingsFragment extends Fragment { case 1: return new PinSecurityFragment(); case 2: - return new PatternSecurityFragment(); + final PatternSecurityFragment patternSecurityFragment = new PatternSecurityFragment(); + patternSecurityFragment.setChildViewPager(mPager); + return patternSecurityFragment; } return null; //new OnConstructionFragment(); diff --git a/app/src/main/java/cy/agorise/crystalwallet/util/ChildViewPager.java b/app/src/main/java/cy/agorise/crystalwallet/util/ChildViewPager.java index fbac369..34f6417 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/util/ChildViewPager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/util/ChildViewPager.java @@ -4,6 +4,10 @@ import android.content.Context; import android.support.v4.view.ViewPager; import android.util.AttributeSet; import android.view.MotionEvent; +import android.view.animation.DecelerateInterpolator; +import android.widget.Scroller; + +import java.lang.reflect.Field; /** * Created by xd on 1/18/18. @@ -14,36 +18,47 @@ import android.view.MotionEvent; public class ChildViewPager extends ViewPager { - private boolean swipeLocked; - public ChildViewPager(Context context) { super(context); + + setMyScroller(); } public ChildViewPager(Context context, AttributeSet attrs) { super(context, attrs); } - public boolean getSwipeLocked() { - return swipeLocked; - } - - public void setSwipeLocked(boolean swipeLocked) { - this.swipeLocked = swipeLocked; - } - @Override public boolean onTouchEvent(MotionEvent event) { - return !swipeLocked && super.onTouchEvent(event); + // stop swipe + return false; } @Override public boolean onInterceptTouchEvent(MotionEvent event) { - return !swipeLocked && super.onInterceptTouchEvent(event); + // stop switching pages + return false; } - @Override - public boolean canScrollHorizontally(int direction) { - return !swipeLocked && super.canScrollHorizontally(direction); + private void setMyScroller() { + try { + Class viewpager = ViewPager.class; + Field scroller = viewpager.getDeclaredField("mScroller"); + scroller.setAccessible(true); + scroller.set(this, new MyScroller(getContext())); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public class MyScroller extends Scroller { + public MyScroller(Context context) { + super(context, new DecelerateInterpolator()); + } + + @Override + public void startScroll(int startX, int startY, int dx, int dy, int duration) { + super.startScroll(startX, startY, dx, dy, 350 /*1 secs*/); + } } } \ No newline at end of file