// New state used to change background based on whether this TextView is multiline.
private static final int[] MULTILINE_STATE_SET = { R.attr.state_multiline };
+ // Accessibility action to share selected text.
+ private static final int ACCESSIBILITY_ACTION_SHARE = 0x10000000;
+
// System wide time for last cut, copy or text changed action.
static long sLastCutCopyOrTextChangedTime;
}
String getSelectedText() {
- if (hasSelection()) {
- return String.valueOf(mText.subSequence(getSelectionStart(), getSelectionEnd()));
+ if (!hasSelection()) {
+ return null;
}
- return null;
+
+ final int start = getSelectionStart();
+ final int end = getSelectionEnd();
+ return String.valueOf(
+ start > end ? mText.subSequence(end, start) : mText.subSequence(start, end));
}
/**
if (canCut()) {
info.addAction(AccessibilityNodeInfo.ACTION_CUT);
}
+ if (canShare()) {
+ info.addAction(new AccessibilityNodeInfo.AccessibilityAction(
+ ACCESSIBILITY_ACTION_SHARE,
+ getResources().getString(com.android.internal.R.string.share)));
+ }
}
// Check for known input filter types.
ensureIterableTextForAccessibilitySelectable();
return super.performAccessibilityActionInternal(action, arguments);
}
+ case ACCESSIBILITY_ACTION_SHARE: {
+ if (isFocused() && canShare()) {
+ if (onTextContextMenuItem(ID_SHARE)) {
+ return true;
+ }
+ }
+ } return false;
default: {
return super.performAccessibilityActionInternal(action, arguments);
}
// controllers interact with how selection behaves.
if (mEditor != null) {
mEditor.hideCursorAndSpanControllers();
+ mEditor.stopTextActionMode();
}
CharSequence text = getIterableTextForAccessibility();
if (Math.min(start, end) >= 0 && Math.max(start, end) <= text.length()) {