Implement ACTION_LONG_CLICK for accessibility am: cc02ea36b2
Change-Id: Ibea5a8589d27a3b0be5193cdb4e0dcca6f9f06b6
This commit is contained in:
@@ -24,7 +24,6 @@ import android.text.TextUtils;
|
||||
import android.text.method.ArrowKeyMovementMethod;
|
||||
import android.text.method.MovementMethod;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
|
||||
/*
|
||||
* This is supposed to be a *very* thin veneer over TextView.
|
||||
@@ -179,13 +178,4 @@ public class EditText extends TextView {
|
||||
protected boolean supportsAutoSizeText() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
@Override
|
||||
public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
|
||||
super.onInitializeAccessibilityNodeInfoInternal(info);
|
||||
if (isEnabled()) {
|
||||
info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SET_TEXT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,6 +317,7 @@ public class Editor {
|
||||
private SelectionActionModeHelper mSelectionActionModeHelper;
|
||||
|
||||
boolean mIsBeingLongClicked;
|
||||
boolean mIsBeingLongClickedByAccessibility;
|
||||
|
||||
private SuggestionsPopupWindow mSuggestionsPopupWindow;
|
||||
SuggestionRangeSpan mSuggestionRangeSpan;
|
||||
@@ -1312,6 +1313,12 @@ public class Editor {
|
||||
if (TextView.DEBUG_CURSOR) {
|
||||
logCursor("performLongClick", "handled=%s", handled);
|
||||
}
|
||||
if (mIsBeingLongClickedByAccessibility) {
|
||||
if (!handled) {
|
||||
toggleInsertionActionMode();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// Long press in empty space moves cursor and starts the insertion action mode.
|
||||
if (!handled && !isPositionOnText(mTouchState.getLastDownX(), mTouchState.getLastDownY())
|
||||
&& !mTouchState.isOnHandle() && mInsertionControllerEnabled) {
|
||||
@@ -1359,6 +1366,14 @@ public class Editor {
|
||||
return handled;
|
||||
}
|
||||
|
||||
private void toggleInsertionActionMode() {
|
||||
if (mTextActionMode != null) {
|
||||
stopTextActionMode();
|
||||
} else {
|
||||
startInsertionActionMode();
|
||||
}
|
||||
}
|
||||
|
||||
float getLastUpPositionX() {
|
||||
return mTouchState.getLastUpX();
|
||||
}
|
||||
@@ -5436,11 +5451,7 @@ public class Editor {
|
||||
config.getScaledTouchSlop());
|
||||
if (isWithinTouchSlop) {
|
||||
// Tapping on the handle toggles the insertion action mode.
|
||||
if (mTextActionMode != null) {
|
||||
stopTextActionMode();
|
||||
} else {
|
||||
startInsertionActionMode();
|
||||
}
|
||||
toggleInsertionActionMode();
|
||||
}
|
||||
} else {
|
||||
if (mTextActionMode != null) {
|
||||
|
||||
@@ -12108,6 +12108,23 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
||||
onEditorAction(getImeActionId());
|
||||
}
|
||||
} return true;
|
||||
case AccessibilityNodeInfo.ACTION_LONG_CLICK: {
|
||||
if (isLongClickable()) {
|
||||
boolean handled;
|
||||
if (isEnabled() && (mBufferType == BufferType.EDITABLE)) {
|
||||
mEditor.mIsBeingLongClickedByAccessibility = true;
|
||||
try {
|
||||
handled = performLongClick();
|
||||
} finally {
|
||||
mEditor.mIsBeingLongClickedByAccessibility = false;
|
||||
}
|
||||
} else {
|
||||
handled = performLongClick();
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
default: {
|
||||
return super.performAccessibilityActionInternal(action, arguments);
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ import android.app.Activity;
|
||||
import android.app.Instrumentation;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.os.Bundle;
|
||||
import android.support.test.uiautomator.UiDevice;
|
||||
import android.text.InputType;
|
||||
import android.text.Selection;
|
||||
@@ -75,6 +76,7 @@ import android.view.ActionMode;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
import android.view.textclassifier.SelectionEvent;
|
||||
import android.view.textclassifier.TextClassificationManager;
|
||||
import android.view.textclassifier.TextClassifier;
|
||||
@@ -357,6 +359,20 @@ public class TextViewActivityTest {
|
||||
assertFalse(textView.hasSelection());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToolbarAppearsAccessibilityLongClick() throws Throwable {
|
||||
final String text = "Toolbar appears after performing accessibility's ACTION_LONG_CLICK.";
|
||||
mActivityRule.runOnUiThread(() -> {
|
||||
final TextView textView = mActivity.findViewById(R.id.textview);
|
||||
final Bundle args = new Bundle();
|
||||
textView.performAccessibilityAction(AccessibilityNodeInfo.ACTION_LONG_CLICK, args);
|
||||
});
|
||||
mInstrumentation.waitForIdleSync();
|
||||
|
||||
sleepForFloatingToolbarPopup();
|
||||
assertFloatingToolbarIsDisplayed();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectionRemovedWhenNonselectableTextLosesFocus() throws Throwable {
|
||||
final TextLinks.TextLink textLink = addLinkifiedTextToTextView(R.id.nonselectable_textview);
|
||||
|
||||
Reference in New Issue
Block a user