summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/current.txt1
-rw-r--r--api/system-current.txt1
-rw-r--r--core/java/android/widget/Editor.java17
-rw-r--r--core/java/android/widget/TextView.java5
-rw-r--r--core/res/res/values/attrs.xml2
-rw-r--r--core/res/res/values/public.xml5
6 files changed, 28 insertions, 3 deletions
diff --git a/api/current.txt b/api/current.txt
index 80ca6cc..a9cd058 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -297,6 +297,7 @@ package android {
field public static final int allowParallelSyncs = 16843570; // 0x1010332
field public static final int allowSingleTap = 16843353; // 0x1010259
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 alphabeticShortcut = 16843235; // 0x10101e3
field public static final int alwaysDrawnWithCache = 16842991; // 0x10100ef
diff --git a/api/system-current.txt b/api/system-current.txt
index 8ec0bb0..52586ed 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -369,6 +369,7 @@ package android {
field public static final int allowParallelSyncs = 16843570; // 0x1010332
field public static final int allowSingleTap = 16843353; // 0x1010259
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 alphabeticShortcut = 16843235; // 0x10101e3
field public static final int alwaysDrawnWithCache = 16842991; // 0x10100ef
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index 1ba11da..7e0dfa0 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -131,6 +131,7 @@ public class Editor {
private final UndoManager mUndoManager = new UndoManager();
private UndoOwner mUndoOwner = mUndoManager.getOwner(UNDO_OWNER_TAG, this);
final InputFilter mUndoInputFilter = new UndoInputFilter(this);
+ boolean mAllowUndo = true;
// Cursor Controllers.
InsertionPointCursorController mInsertionPointCursorController;
@@ -243,20 +244,26 @@ public class Editor {
boolean canUndo() {
UndoOwner[] owners = { mUndoOwner };
- return mUndoManager.countUndos(owners) > 0;
+ return mAllowUndo && mUndoManager.countUndos(owners) > 0;
}
boolean canRedo() {
UndoOwner[] owners = { mUndoOwner };
- return mUndoManager.countRedos(owners) > 0;
+ return mAllowUndo && mUndoManager.countRedos(owners) > 0;
}
void undo() {
+ if (!mAllowUndo) {
+ return;
+ }
UndoOwner[] owners = { mUndoOwner };
mUndoManager.undo(owners, 1); // Undo 1 action.
}
void redo() {
+ if (!mAllowUndo) {
+ return;
+ }
UndoOwner[] owners = { mUndoOwner };
mUndoManager.redo(owners, 1); // Redo 1 action.
}
@@ -4223,6 +4230,12 @@ public class Editor {
Log.d(TAG, "filter: source=" + source + " (" + start + "-" + end + ") " +
"dest=" + dest + " (" + dstart + "-" + dend + ")");
}
+
+ if (!mEditor.mAllowUndo) {
+ if (DEBUG_UNDO) Log.d(TAG, "filter: undo is disabled");
+ return null;
+ }
+
final UndoManager um = mEditor.mUndoManager;
if (um.isInUndo()) {
if (DEBUG_UNDO) Log.d(TAG, "filter: skipping, currently performing undo/redo");
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 2d0a9cb..632f5c7 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -1055,6 +1055,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
inputType = a.getInt(attr, EditorInfo.TYPE_NULL);
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:
createEditorIfNeeded();
mEditor.createInputContentTypeIfNeeded();
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index b3c60ad..30ce271 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -4215,6 +4215,8 @@
<enum name="marquee_forever" value="-1" />
</attr>
<attr name="inputType" />
+ <!-- Whether undo should be allowed for editable text. Defaults to true. -->
+ <attr name="allowUndo" format="boolean" />
<attr name="imeOptions" />
<!-- An addition content type description to supply to the input
method attached to the text view, which is private to the
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 37f8232..16f0676 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -2649,5 +2649,8 @@
<public type="id" name="undo" />
<!-- Context menu ID for the "Redo" menu item to redo the last text edit operation. -->
<public type="id" name="redo" />
-
+
+ <!-- TextView attribute to control undo behavior. -->
+ <public type="attr" name="allowUndo" />
+
</resources>