Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 99e6d7a1 authored by James Cook's avatar James Cook Committed by Android (Google) Code Review
Browse files

Merge "Add TextView XML attribute for undo support"

parents bcd42a8d f1dad1ea
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -297,6 +297,7 @@ package android {
    field public static final int allowParallelSyncs = 16843570; // 0x1010332
    field public static final int allowParallelSyncs = 16843570; // 0x1010332
    field public static final int allowSingleTap = 16843353; // 0x1010259
    field public static final int allowSingleTap = 16843353; // 0x1010259
    field public static final int allowTaskReparenting = 16843268; // 0x1010204
    field public static final int allowTaskReparenting = 16843268; // 0x1010204
    field public static final int allowUndo = 16844006; // 0x10104e6
    field public static final int alpha = 16843551; // 0x101031f
    field public static final int alpha = 16843551; // 0x101031f
    field public static final int alphabeticShortcut = 16843235; // 0x10101e3
    field public static final int alphabeticShortcut = 16843235; // 0x10101e3
    field public static final int alwaysDrawnWithCache = 16842991; // 0x10100ef
    field public static final int alwaysDrawnWithCache = 16842991; // 0x10100ef
+1 −0
Original line number Original line Diff line number Diff line
@@ -369,6 +369,7 @@ package android {
    field public static final int allowParallelSyncs = 16843570; // 0x1010332
    field public static final int allowParallelSyncs = 16843570; // 0x1010332
    field public static final int allowSingleTap = 16843353; // 0x1010259
    field public static final int allowSingleTap = 16843353; // 0x1010259
    field public static final int allowTaskReparenting = 16843268; // 0x1010204
    field public static final int allowTaskReparenting = 16843268; // 0x1010204
    field public static final int allowUndo = 16844006; // 0x10104e6
    field public static final int alpha = 16843551; // 0x101031f
    field public static final int alpha = 16843551; // 0x101031f
    field public static final int alphabeticShortcut = 16843235; // 0x10101e3
    field public static final int alphabeticShortcut = 16843235; // 0x10101e3
    field public static final int alwaysDrawnWithCache = 16842991; // 0x10100ef
    field public static final int alwaysDrawnWithCache = 16842991; // 0x10100ef
+15 −2
Original line number Original line Diff line number Diff line
@@ -131,6 +131,7 @@ public class Editor {
    private final UndoManager mUndoManager = new UndoManager();
    private final UndoManager mUndoManager = new UndoManager();
    private UndoOwner mUndoOwner = mUndoManager.getOwner(UNDO_OWNER_TAG, this);
    private UndoOwner mUndoOwner = mUndoManager.getOwner(UNDO_OWNER_TAG, this);
    final InputFilter mUndoInputFilter = new UndoInputFilter(this);
    final InputFilter mUndoInputFilter = new UndoInputFilter(this);
    boolean mAllowUndo = true;


    // Cursor Controllers.
    // Cursor Controllers.
    InsertionPointCursorController mInsertionPointCursorController;
    InsertionPointCursorController mInsertionPointCursorController;
@@ -243,20 +244,26 @@ public class Editor {


    boolean canUndo() {
    boolean canUndo() {
        UndoOwner[] owners = { mUndoOwner };
        UndoOwner[] owners = { mUndoOwner };
        return mUndoManager.countUndos(owners) > 0;
        return mAllowUndo && mUndoManager.countUndos(owners) > 0;
    }
    }


    boolean canRedo() {
    boolean canRedo() {
        UndoOwner[] owners = { mUndoOwner };
        UndoOwner[] owners = { mUndoOwner };
        return mUndoManager.countRedos(owners) > 0;
        return mAllowUndo && mUndoManager.countRedos(owners) > 0;
    }
    }


    void undo() {
    void undo() {
        if (!mAllowUndo) {
            return;
        }
        UndoOwner[] owners = { mUndoOwner };
        UndoOwner[] owners = { mUndoOwner };
        mUndoManager.undo(owners, 1);  // Undo 1 action.
        mUndoManager.undo(owners, 1);  // Undo 1 action.
    }
    }


    void redo() {
    void redo() {
        if (!mAllowUndo) {
            return;
        }
        UndoOwner[] owners = { mUndoOwner };
        UndoOwner[] owners = { mUndoOwner };
        mUndoManager.redo(owners, 1);  // Redo 1 action.
        mUndoManager.redo(owners, 1);  // Redo 1 action.
    }
    }
@@ -4223,6 +4230,12 @@ public class Editor {
                Log.d(TAG, "filter: source=" + source + " (" + start + "-" + end + ") " +
                Log.d(TAG, "filter: source=" + source + " (" + start + "-" + end + ") " +
                        "dest=" + dest + " (" + dstart + "-" + dend + ")");
                        "dest=" + dest + " (" + dstart + "-" + dend + ")");
            }
            }

            if (!mEditor.mAllowUndo) {
                if (DEBUG_UNDO) Log.d(TAG, "filter: undo is disabled");
                return null;
            }

            final UndoManager um = mEditor.mUndoManager;
            final UndoManager um = mEditor.mUndoManager;
            if (um.isInUndo()) {
            if (um.isInUndo()) {
                if (DEBUG_UNDO) Log.d(TAG, "filter: skipping, currently performing undo/redo");
                if (DEBUG_UNDO) Log.d(TAG, "filter: skipping, currently performing undo/redo");
+5 −0
Original line number Original line Diff line number Diff line
@@ -1055,6 +1055,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                inputType = a.getInt(attr, EditorInfo.TYPE_NULL);
                inputType = a.getInt(attr, EditorInfo.TYPE_NULL);
                break;
                break;


            case com.android.internal.R.styleable.TextView_allowUndo:
                createEditorIfNeeded();
                mEditor.mAllowUndo = a.getBoolean(attr, true);
                break;

            case com.android.internal.R.styleable.TextView_imeOptions:
            case com.android.internal.R.styleable.TextView_imeOptions:
                createEditorIfNeeded();
                createEditorIfNeeded();
                mEditor.createInputContentTypeIfNeeded();
                mEditor.createInputContentTypeIfNeeded();
+2 −0
Original line number Original line Diff line number Diff line
@@ -4215,6 +4215,8 @@
            <enum name="marquee_forever" value="-1" />
            <enum name="marquee_forever" value="-1" />
        </attr>
        </attr>
        <attr name="inputType" />
        <attr name="inputType" />
        <!-- Whether undo should be allowed for editable text. Defaults to true. -->
        <attr name="allowUndo" format="boolean" />
        <attr name="imeOptions" />
        <attr name="imeOptions" />
        <!-- An addition content type description to supply to the input
        <!-- An addition content type description to supply to the input
             method attached to the text view, which is private to the
             method attached to the text view, which is private to the
Loading