Revert "Remove obsolete workaround for ClickableSpan a11y"
This commit breaks ub-setupwizard-master build
Test: ./gradlew connectedAndroidTest test
This reverts commit 1dcf260b55
.
This commit is contained in:
parent
0372df3e1f
commit
ee3beb6434
|
@ -16,21 +16,14 @@
|
|||
|
||||
package com.android.setupwizardlib.util;
|
||||
|
||||
import static android.support.v4.os.BuildCompat.isAtLeastO;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.view.AccessibilityDelegateCompat;
|
||||
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
|
||||
import android.support.v4.view.accessibility.AccessibilityNodeProviderCompat;
|
||||
import android.support.v4.widget.ExploreByTouchHelper;
|
||||
import android.text.Layout;
|
||||
import android.text.Spanned;
|
||||
import android.text.style.ClickableSpan;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
@ -39,10 +32,6 @@ import java.util.List;
|
|||
/**
|
||||
* An accessibility delegate that allows {@link android.text.style.ClickableSpan} to be focused and
|
||||
* clicked by accessibility services.
|
||||
* <p>
|
||||
* <strong>Note: </strong> From Android O on, there is native support for ClickableSpan
|
||||
* accessibility, so this class is not needed (and indeed has no effect.)
|
||||
* </p>
|
||||
*
|
||||
* <p />Sample usage:
|
||||
* <pre>
|
||||
|
@ -65,135 +54,19 @@ import java.util.List;
|
|||
* @see com.android.setupwizardlib.view.RichTextView
|
||||
* @see android.support.v4.widget.ExploreByTouchHelper
|
||||
*/
|
||||
public class LinkAccessibilityHelper extends AccessibilityDelegateCompat {
|
||||
public class LinkAccessibilityHelper extends ExploreByTouchHelper {
|
||||
|
||||
private static final String TAG = "LinkAccessibilityHelper";
|
||||
|
||||
private final TextView mView;
|
||||
private final Rect mTempRect = new Rect();
|
||||
private final ExploreByTouchHelper mExploreByTouchHelper;
|
||||
|
||||
public LinkAccessibilityHelper(TextView view) {
|
||||
if (!isAtLeastO()) {
|
||||
// Pre-O, we essentially extend ExploreByTouchHelper to expose a virtual view hierarchy
|
||||
mExploreByTouchHelper = new ExploreByTouchHelper(view) {
|
||||
@Override
|
||||
protected int getVirtualViewAt(float x, float y) {
|
||||
return this.getVirtualViewAt(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void getVisibleVirtualViews(List<Integer> virtualViewIds) {
|
||||
this.getVisibleVirtualViews(virtualViewIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPopulateEventForVirtualView(int virtualViewId,
|
||||
AccessibilityEvent event) {
|
||||
this.onPopulateEventForVirtualView(virtualViewId, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPopulateNodeForVirtualView(int virtualViewId,
|
||||
AccessibilityNodeInfoCompat infoCompat) {
|
||||
this.onPopulateNodeForVirtualView(virtualViewId, infoCompat);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onPerformActionForVirtualView(int virtualViewId, int action,
|
||||
Bundle arguments) {
|
||||
return this.onPerformActionForVirtualView(virtualViewId, action, arguments);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
mExploreByTouchHelper = null;
|
||||
}
|
||||
super(view);
|
||||
mView = view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendAccessibilityEvent(View host, int eventType) {
|
||||
if (mExploreByTouchHelper != null) {
|
||||
mExploreByTouchHelper.sendAccessibilityEvent(host, eventType);
|
||||
} else {
|
||||
super.sendAccessibilityEvent(host, eventType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendAccessibilityEventUnchecked(View host, AccessibilityEvent event) {
|
||||
if (mExploreByTouchHelper != null) {
|
||||
mExploreByTouchHelper.sendAccessibilityEventUnchecked(host, event);
|
||||
} else {
|
||||
super.sendAccessibilityEventUnchecked(host, event);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
|
||||
return (mExploreByTouchHelper != null)
|
||||
? mExploreByTouchHelper.dispatchPopulateAccessibilityEvent(host, event)
|
||||
: super.dispatchPopulateAccessibilityEvent(host, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
|
||||
if (mExploreByTouchHelper != null) {
|
||||
mExploreByTouchHelper.onPopulateAccessibilityEvent(host, event);
|
||||
} else {
|
||||
super.onPopulateAccessibilityEvent(host, event);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
|
||||
if (mExploreByTouchHelper != null) {
|
||||
mExploreByTouchHelper.onInitializeAccessibilityEvent(host, event);
|
||||
} else {
|
||||
super.onInitializeAccessibilityEvent(host, event);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
|
||||
if (mExploreByTouchHelper != null) {
|
||||
mExploreByTouchHelper.onInitializeAccessibilityNodeInfo(host, info);
|
||||
} else {
|
||||
super.onInitializeAccessibilityNodeInfo(host, info);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child,
|
||||
AccessibilityEvent event) {
|
||||
return (mExploreByTouchHelper != null)
|
||||
? mExploreByTouchHelper.onRequestSendAccessibilityEvent(host, child, event)
|
||||
: super.onRequestSendAccessibilityEvent(host, child, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View host) {
|
||||
return (mExploreByTouchHelper != null)
|
||||
? mExploreByTouchHelper.getAccessibilityNodeProvider(host)
|
||||
: super.getAccessibilityNodeProvider(host);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performAccessibilityAction(View host, int action, Bundle args) {
|
||||
return (mExploreByTouchHelper != null)
|
||||
? mExploreByTouchHelper.performAccessibilityAction(host, action, args)
|
||||
: super.performAccessibilityAction(host, action, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegated to {@link ExploreByTouchHelper}
|
||||
*/
|
||||
public final boolean dispatchHoverEvent(MotionEvent event) {
|
||||
return (mExploreByTouchHelper != null) ? mExploreByTouchHelper.dispatchHoverEvent(event)
|
||||
: false;
|
||||
}
|
||||
|
||||
protected int getVirtualViewAt(float x, float y) {
|
||||
final CharSequence text = mView.getText();
|
||||
if (text instanceof Spanned) {
|
||||
|
@ -205,9 +78,10 @@ public class LinkAccessibilityHelper extends AccessibilityDelegateCompat {
|
|||
return spannedText.getSpanStart(linkSpan);
|
||||
}
|
||||
}
|
||||
return ExploreByTouchHelper.INVALID_ID;
|
||||
return INVALID_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void getVisibleVirtualViews(List<Integer> virtualViewIds) {
|
||||
final CharSequence text = mView.getText();
|
||||
if (text instanceof Spanned) {
|
||||
|
@ -220,6 +94,7 @@ public class LinkAccessibilityHelper extends AccessibilityDelegateCompat {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPopulateEventForVirtualView(int virtualViewId, AccessibilityEvent event) {
|
||||
final ClickableSpan span = getSpanForOffset(virtualViewId);
|
||||
if (span != null) {
|
||||
|
@ -230,6 +105,7 @@ public class LinkAccessibilityHelper extends AccessibilityDelegateCompat {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPopulateNodeForVirtualView(int virtualViewId,
|
||||
AccessibilityNodeInfoCompat info) {
|
||||
final ClickableSpan span = getSpanForOffset(virtualViewId);
|
||||
|
@ -250,6 +126,7 @@ public class LinkAccessibilityHelper extends AccessibilityDelegateCompat {
|
|||
info.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onPerformActionForVirtualView(int virtualViewId, int action,
|
||||
Bundle arguments) {
|
||||
if (action == AccessibilityNodeInfoCompat.ACTION_CLICK) {
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
package com.android.setupwizardlib.test;
|
||||
|
||||
import static android.support.v4.os.BuildCompat.isAtLeastO;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
@ -59,7 +57,6 @@ public class LinkAccessibilityHelperTest {
|
|||
|
||||
@Test
|
||||
public void testGetVirtualViewAt() {
|
||||
if (isAtLeastO()) return;
|
||||
initTextView();
|
||||
final int virtualViewId = mHelper.getVirtualViewAt(dp2Px(15), dp2Px(10));
|
||||
assertEquals("Virtual view ID should be 1", 1, virtualViewId);
|
||||
|
@ -67,7 +64,6 @@ public class LinkAccessibilityHelperTest {
|
|||
|
||||
@Test
|
||||
public void testGetVirtualViewAtHost() {
|
||||
if (isAtLeastO()) return;
|
||||
initTextView();
|
||||
final int virtualViewId = mHelper.getVirtualViewAt(dp2Px(100), dp2Px(100));
|
||||
assertEquals("Virtual view ID should be INVALID_ID",
|
||||
|
@ -76,7 +72,6 @@ public class LinkAccessibilityHelperTest {
|
|||
|
||||
@Test
|
||||
public void testGetVisibleVirtualViews() {
|
||||
if (isAtLeastO()) return;
|
||||
initTextView();
|
||||
List<Integer> virtualViewIds = new ArrayList<>();
|
||||
mHelper.getVisibleVirtualViews(virtualViewIds);
|
||||
|
@ -87,7 +82,6 @@ public class LinkAccessibilityHelperTest {
|
|||
|
||||
@Test
|
||||
public void testOnPopulateEventForVirtualView() {
|
||||
if (isAtLeastO()) return;
|
||||
initTextView();
|
||||
AccessibilityEvent event = AccessibilityEvent.obtain();
|
||||
mHelper.onPopulateEventForVirtualView(1, event);
|
||||
|
@ -101,7 +95,6 @@ public class LinkAccessibilityHelperTest {
|
|||
|
||||
@Test
|
||||
public void testOnPopulateEventForVirtualViewHost() {
|
||||
if (isAtLeastO()) return;
|
||||
initTextView();
|
||||
AccessibilityEvent event = AccessibilityEvent.obtain();
|
||||
mHelper.onPopulateEventForVirtualView(ExploreByTouchHelper.INVALID_ID, event);
|
||||
|
@ -114,7 +107,6 @@ public class LinkAccessibilityHelperTest {
|
|||
|
||||
@Test
|
||||
public void testOnPopulateNodeForVirtualView() {
|
||||
if (isAtLeastO()) return;
|
||||
initTextView();
|
||||
AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain();
|
||||
mHelper.onPopulateNodeForVirtualView(1, info);
|
||||
|
@ -133,7 +125,6 @@ public class LinkAccessibilityHelperTest {
|
|||
|
||||
@Test
|
||||
public void testNullLayout() {
|
||||
if (isAtLeastO()) return;
|
||||
initTextView();
|
||||
// Setting the padding will cause the layout to be null-ed out.
|
||||
mTextView.setPadding(1, 1, 1, 1);
|
||||
|
@ -151,7 +142,6 @@ public class LinkAccessibilityHelperTest {
|
|||
|
||||
@Test
|
||||
public void testRtlLayout() {
|
||||
if (isAtLeastO()) return;
|
||||
SpannableStringBuilder ssb = new SpannableStringBuilder("מכונה בתרגום");
|
||||
ssb.setSpan(LINK_SPAN, 1, 2, 0 /* flags */);
|
||||
initTextView(ssb);
|
||||
|
@ -171,7 +161,6 @@ public class LinkAccessibilityHelperTest {
|
|||
|
||||
@Test
|
||||
public void testMultilineLink() {
|
||||
if (isAtLeastO()) return;
|
||||
SpannableStringBuilder ssb = new SpannableStringBuilder(
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
|
||||
+ "Praesent accumsan efficitur eros eu porttitor.");
|
||||
|
@ -193,7 +182,6 @@ public class LinkAccessibilityHelperTest {
|
|||
|
||||
@Test
|
||||
public void testRtlMultilineLink() {
|
||||
if (isAtLeastO()) return;
|
||||
String iwLoremIpsum = "אחר על רביעי אקטואליה. לוח דת אחרות המקובל רומנית, מיזמים מועמדים "
|
||||
+ "האנציקלופדיה בה צ'ט. מתן מה שנורו לערוך ייִדיש, בקר או החול אנתרופולוגיה, עוד "
|
||||
+ "דפים המחשב מיזמים ב.";
|
||||
|
@ -217,7 +205,6 @@ public class LinkAccessibilityHelperTest {
|
|||
|
||||
@Test
|
||||
public void testBidiMultilineLink() {
|
||||
if (isAtLeastO()) return;
|
||||
String iwLoremIpsum = "אחר על רביעי אקטואליה. לוח דת אחרות המקובל רומנית, מיזמים מועמדים "
|
||||
+ "האנציקלופדיה בה צ'ט. מתן מה שנורו לערוך ייִדיש, בקר או החול אנתרופולוגיה, עוד "
|
||||
+ "דפים המחשב מיזמים ב.";
|
||||
|
|
Loading…
Reference in a new issue