Closed seregin-pro closed 4 years ago
Hi,
i don't know if i can help you with all your problems.
1) Actually i don't even know what setAccessibilityDelegate() does :). I can only provide the methods of WebView. I think your request (e.g. implementing this manually) is out of scope.
But depending on your use case i may can help you otherwise. What are trying to archive? E. g. getting selected text would be no problem (at least not as plain text).
I need to get selection text for rotation screen to save it.
For Edittext I did it like this:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); etContentView(R.layout.activity_main);
// get saved data and restore selected text before rotation screen
if (savedInstanceState != null) {
selectionTextStart = savedInstanceState.getInt("selectionTextStart");
selectionTextEnd = savedInstanceState.getInt("selectionTextEnd");
}
final EditText editText = findViewById(R.id.editText);
editText.setAccessibilityDelegate(new View.AccessibilityDelegate() {
// When cursor position changed sendAccessibilityEvent will add new position selected text
// touch anywhre on text or change position orange text slider
public void sendAccessibilityEvent(View view, int eventType) {
super.sendAccessibilityEvent(view, eventType);
selectionTextStart = editText.getSelectionStart();
selectionTextStart = editText.getSelectionStart();
}
});
}
protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState);
outState.putString(Constant.TEXT, text);
outState.putInt("selectionTextStart", selectionTextStart); // put before rotation a screen
outState.putInt("selectionTextEnd", selectionTextEnd); // put before rotation a screen
}
I will try to do somethig with WebView
Image 1. I selected text. Image 2. I have this result after rotation screen. I need selected text like Image 1
I hope you understand my English.
Just released version 2.0.15 (should be visible at maximum in two hours).
The font bug should be fixed now. Thanks for reporting it to me!
To restoring the selection:
That's not that easy.
I tried saving selected range with var rangeToRestore = window.getSelection().getRangeAt(0)
. (See https://gist.github.com/dantaex/543e721be845c18d2f92652c0ebe06aa .)
But restoring with window.getSelection().addRange(rangeToRestore)
does not work as after setting html it's a new document and therefore backed up anchor element is not valid anymore.
What could work is using the JavaScript library rangy as suggested here: https://stackoverflow.com/questions/39566611/how-can-i-save-and-restore-selection-range-in-javascript
But as i already spent enough time on this, this is something what you would have to do. If you implement it and give me a pull request, i'd be glad to integrate it.
Cheers.
I just added it in AndroidManifest.xml in my It is work but I go on test it yet.
<activity android:name=".EditorActivity" android:configChanges="keyboardHidden|orientation|screenSize"> </activity>
Hello.
Example for Edittext
EditText edittext = findViewById(R.id.title); int currentCursor = 0;
editText.setAccessibilityDelegate(new View.AccessibilityDelegate() { public void sendAccessibilityEvent(View view, int eventType) { super.sendAccessibilityEvent(view, eventType); if (eventType == AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED) { currentCursor = editText.getSelectionStart(); } } });