Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Two-finger scroll issue when TalkBack is active #370

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
import android.view.MotionEvent;

import com.henninghall.date_picker.ui.Accessibility;

import cn.carbswang.android.numberpickerview.library.NumberPickerView;

public class IosClone extends NumberPickerView implements Picker {
Expand Down Expand Up @@ -58,4 +62,13 @@ public View getView() {
public boolean isSpinning() {
return super.isScrolling();
}

@Override
public boolean onTouchEvent(MotionEvent event) {
if(Accessibility.shouldAllowScroll(this)){
super.onTouchEvent(event);
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.henninghall.date_picker.ui;

import android.content.Context;
import android.os.Build;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;

import com.henninghall.date_picker.DatePickerManager;
import com.henninghall.date_picker.State;
import com.henninghall.date_picker.Utils;
import com.henninghall.date_picker.wheelFunctions.WheelFunction;
Expand All @@ -12,6 +16,30 @@

public class Accessibility {

private final static AccessibilityManager systemManager =
(AccessibilityManager) DatePickerManager.context
.getApplicationContext()
.getSystemService(Context.ACCESSIBILITY_SERVICE);

/**
When TalkBack is active, user can use one finger to explore the screen
and set focus to elements. Then user can proceed to use second finger
to scroll contents of focused element.
When there's multiple pickers next to each other horizontally,
it's easy to accidentally scroll more than one picker at a time.
Following code aims to fix this issue.
*/
public static boolean shouldAllowScroll(View view){
// If TalkBack isn't active, always proceed without suppressing touch events
if (!systemManager.isTouchExplorationEnabled()) {
return true;
}
if (Build.VERSION.SDK_INT >= 21) {
return view.isAccessibilityFocused();
}
return false;
}

public static class SetAccessibilityDelegate implements WheelFunction {

private final Locale locale;
Expand Down