summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJames Cook <jamescook@google.com>2015-02-27 22:35:14 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-02-27 22:35:15 +0000
commit99e6d7a17acc97f20f1300c25a69f8831b055ef2 (patch)
treefdbcda39166ced261d88e0b4c962425e2bff71fe /core
parentbcd42a8d5a3b63ea22d5c88c19979934bf3b70c2 (diff)
parentf1dad1ea82c5d9ca920af39b81ac6894ff692b99 (diff)
downloadframeworks_base-99e6d7a17acc97f20f1300c25a69f8831b055ef2.zip
frameworks_base-99e6d7a17acc97f20f1300c25a69f8831b055ef2.tar.gz
frameworks_base-99e6d7a17acc97f20f1300c25a69f8831b055ef2.tar.bz2
Merge "Add TextView XML attribute for undo support"
Diffstat (limited to 'core')
-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
4 files changed, 26 insertions, 3 deletions
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>