-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
This commit is contained in:
parent
b3a267fb47
commit
4ba6299822
3 changed files with 47 additions and 18 deletions
|
@ -28,6 +28,7 @@ import butterknife.OnTextChanged;
|
||||||
import cy.agorise.crystalwallet.R;
|
import cy.agorise.crystalwallet.R;
|
||||||
import cy.agorise.crystalwallet.application.CrystalSecurityMonitor;
|
import cy.agorise.crystalwallet.application.CrystalSecurityMonitor;
|
||||||
import cy.agorise.crystalwallet.models.GeneralSetting;
|
import cy.agorise.crystalwallet.models.GeneralSetting;
|
||||||
|
import cy.agorise.crystalwallet.util.ChildViewPager;
|
||||||
import cy.agorise.crystalwallet.util.PasswordManager;
|
import cy.agorise.crystalwallet.util.PasswordManager;
|
||||||
import cy.agorise.crystalwallet.viewmodels.GeneralSettingListViewModel;
|
import cy.agorise.crystalwallet.viewmodels.GeneralSettingListViewModel;
|
||||||
import cy.agorise.crystalwallet.viewmodels.validators.PinSecurityValidator;
|
import cy.agorise.crystalwallet.viewmodels.validators.PinSecurityValidator;
|
||||||
|
@ -45,9 +46,17 @@ public class PatternSecurityFragment extends Fragment {
|
||||||
@BindView(R.id.tvPatternText)
|
@BindView(R.id.tvPatternText)
|
||||||
TextView 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 PatternLockViewListener actualPatternListener;
|
||||||
private String patternEntered;
|
private String patternEntered;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public PatternSecurityFragment() {
|
public PatternSecurityFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
}
|
}
|
||||||
|
@ -80,6 +89,11 @@ public class PatternSecurityFragment extends Fragment {
|
||||||
return patternString;
|
return patternString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setChildViewPager(ChildViewPager childViewPager) {
|
||||||
|
this.childViewPager = childViewPager;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void removePatternListener(){
|
public void removePatternListener(){
|
||||||
if (actualPatternListener != null){
|
if (actualPatternListener != null){
|
||||||
patternLockView.removePatternLockListener(actualPatternListener);
|
patternLockView.removePatternLockListener(actualPatternListener);
|
||||||
|
@ -96,7 +110,6 @@ public class PatternSecurityFragment extends Fragment {
|
||||||
actualPatternListener = new PatternLockViewListener() {
|
actualPatternListener = new PatternLockViewListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onStarted() {
|
public void onStarted() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -96,7 +96,6 @@ public class SecuritySettingsFragment extends Fragment {
|
||||||
default:
|
default:
|
||||||
mPager.setCurrentItem(0);
|
mPager.setCurrentItem(0);
|
||||||
}
|
}
|
||||||
mPager.setSwipeLocked(true);
|
|
||||||
|
|
||||||
TabLayout tabLayout = v.findViewById(R.id.tabs);
|
TabLayout tabLayout = v.findViewById(R.id.tabs);
|
||||||
|
|
||||||
|
@ -134,7 +133,9 @@ public class SecuritySettingsFragment extends Fragment {
|
||||||
case 1:
|
case 1:
|
||||||
return new PinSecurityFragment();
|
return new PinSecurityFragment();
|
||||||
case 2:
|
case 2:
|
||||||
return new PatternSecurityFragment();
|
final PatternSecurityFragment patternSecurityFragment = new PatternSecurityFragment();
|
||||||
|
patternSecurityFragment.setChildViewPager(mPager);
|
||||||
|
return patternSecurityFragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null; //new OnConstructionFragment();
|
return null; //new OnConstructionFragment();
|
||||||
|
|
|
@ -4,6 +4,10 @@ import android.content.Context;
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.MotionEvent;
|
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.
|
* Created by xd on 1/18/18.
|
||||||
|
@ -14,36 +18,47 @@ import android.view.MotionEvent;
|
||||||
|
|
||||||
public class ChildViewPager extends ViewPager {
|
public class ChildViewPager extends ViewPager {
|
||||||
|
|
||||||
private boolean swipeLocked;
|
|
||||||
|
|
||||||
public ChildViewPager(Context context) {
|
public ChildViewPager(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
|
setMyScroller();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChildViewPager(Context context, AttributeSet attrs) {
|
public ChildViewPager(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getSwipeLocked() {
|
|
||||||
return swipeLocked;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSwipeLocked(boolean swipeLocked) {
|
|
||||||
this.swipeLocked = swipeLocked;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
return !swipeLocked && super.onTouchEvent(event);
|
// stop swipe
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onInterceptTouchEvent(MotionEvent event) {
|
public boolean onInterceptTouchEvent(MotionEvent event) {
|
||||||
return !swipeLocked && super.onInterceptTouchEvent(event);
|
// stop switching pages
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void setMyScroller() {
|
||||||
public boolean canScrollHorizontally(int direction) {
|
try {
|
||||||
return !swipeLocked && super.canScrollHorizontally(direction);
|
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*/);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue