Quick note about Antti-Brax / Divers (Kidinov ). It works great if you try to use it with the PostView API 23 text-based interface, you will have problems because guess that Google actually added a hidden UndoManager (android.content.UndoManager) and did not document it or made it not obvious that it was there. But if you have a hard / bluetooth keyboard in Marshmallow or Nougat and press ^ Z or SHIFT- ^ Z, you will get undo / redo.
The problem arises if you already use the Antti-Brax class with EditText, and you also bind it to ^ Z and shift- ^ Z, you will run into problems with someone using a hard keyboard. Namely: ^ Z will call BOTH native and Antti-Brax undo, which will lead to two cancellations at the same time, which is not very good. And after a few of them, you are likely to get a crash outside.
A possible solution I found is to subclass TextView / TextEdit / whatever and intercept the cancel / redo calls from TextView so that they don't start as follows:
@Override public boolean onTextContextMenuItem(int id) { int ID_UNDO, ID_REDO; try { ID_UNDO = android.R.id.undo; ID_REDO = android.R.id.redo; } catch (Resources.NotFoundException e) { ID_UNDO = 16908338;
These magic identification numbers were found here and are used only as a backup if the values โโof android.R.id.undo are not found. (it may also be reasonable to assume that if there are no values, the function is not there, but in any case ...)
This is not the best solution, because both tracker cancellations are still there, and both work in the background. But at least you wonโt run them both at the same time with Z. This is the best I could think of until it is officially documented and the getUndoManager () methods of TextView are no longer hidden ...
Why they made a function that you cannot turn off (or even know whether it was there or not) "live" in the released Android, I canโt say.
I just opened an issue on an Android tracker if someone wants to follow this.
source share