diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/text/TextUtils.java | 2 | ||||
-rw-r--r-- | core/java/android/text/style/EasyEditSpan.java | 85 | ||||
-rw-r--r-- | core/java/android/widget/Editor.java | 73 |
3 files changed, 14 insertions, 146 deletions
diff --git a/core/java/android/text/TextUtils.java b/core/java/android/text/TextUtils.java index 2ab9bf8..1508d10 100644 --- a/core/java/android/text/TextUtils.java +++ b/core/java/android/text/TextUtils.java @@ -757,7 +757,7 @@ public class TextUtils { break; case EASY_EDIT_SPAN: - readSpan(p, sp, new EasyEditSpan(p)); + readSpan(p, sp, new EasyEditSpan()); break; case LOCALE_SPAN: diff --git a/core/java/android/text/style/EasyEditSpan.java b/core/java/android/text/style/EasyEditSpan.java index 03b4f60..2feb719 100644 --- a/core/java/android/text/style/EasyEditSpan.java +++ b/core/java/android/text/style/EasyEditSpan.java @@ -16,7 +16,6 @@ package android.text.style; -import android.app.PendingIntent; import android.os.Parcel; import android.text.ParcelableSpan; import android.text.TextUtils; @@ -26,62 +25,12 @@ import android.widget.TextView; * Provides an easy way to edit a portion of text. * <p> * The {@link TextView} uses this span to allow the user to delete a chuck of text in one click. - * <p> - * {@link TextView} removes the span when the user deletes the whole text or modifies it. - * <p> - * This span can be also used to receive notification when the user deletes or modifies the text; + * the text. {@link TextView} removes this span as soon as the text is edited, or the cursor moves. */ public class EasyEditSpan implements ParcelableSpan { - /** - * The extra key field in the pending intent that describes how the text changed. - * - * @see #TEXT_DELETED - * @see #TEXT_MODIFIED - * @see #getPendingIntent() - */ - public static final String EXTRA_TEXT_CHANGED_TYPE = - "android.text.style.EXTRA_TEXT_CHANGED_TYPE"; - - /** - * The value of {@link #EXTRA_TEXT_CHANGED_TYPE} when the text wrapped by this span is deleted. - */ - public static final int TEXT_DELETED = 1; - - /** - * The value of {@link #EXTRA_TEXT_CHANGED_TYPE} when the text wrapped by this span is modified. - */ - public static final int TEXT_MODIFIED = 2; - - private final PendingIntent mPendingIntent; - - private boolean mDeleteEnabled; - - /** - * Creates the span. No intent is sent when the wrapped text is modified or - * deleted. - */ public EasyEditSpan() { - mPendingIntent = null; - mDeleteEnabled = true; - } - - /** - * @param pendingIntent The intent will be sent when the wrapped text is deleted or modified. - * When the pending intent is sent, {@link #EXTRA_TEXT_CHANGED_TYPE} is - * added in the intent to describe how the text changed. - */ - public EasyEditSpan(PendingIntent pendingIntent) { - mPendingIntent = pendingIntent; - mDeleteEnabled = true; - } - - /** - * Constructor called from {@link TextUtils} to restore the span. - */ - public EasyEditSpan(Parcel source) { - mPendingIntent = source.readParcelable(null); - mDeleteEnabled = (source.readByte() == 1); + // Empty } @Override @@ -91,39 +40,11 @@ public class EasyEditSpan implements ParcelableSpan { @Override public void writeToParcel(Parcel dest, int flags) { - dest.writeParcelable(mPendingIntent, 0); - dest.writeByte((byte) (mDeleteEnabled ? 1 : 0)); + // Empty } @Override public int getSpanTypeId() { return TextUtils.EASY_EDIT_SPAN; } - - /** - * @return True if the {@link TextView} should offer the ability to delete the text. - * - * @hide - */ - public boolean isDeleteEnabled() { - return mDeleteEnabled; - } - - /** - * Enables or disables the deletion of the text. - * - * @hide - */ - public void setDeleteEnabled(boolean value) { - mDeleteEnabled = value; - } - - /** - * @return the pending intent to send when the wrapped text is deleted or modified. - * - * @hide - */ - public PendingIntent getPendingIntent() { - return mPendingIntent; - } } diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index dc305a5..862e2c8 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -20,8 +20,6 @@ import com.android.internal.util.ArrayUtils; import com.android.internal.widget.EditableInputConnection; import android.R; -import android.app.PendingIntent; -import android.app.PendingIntent.CanceledException; import android.content.ClipData; import android.content.ClipData.Item; import android.content.Context; @@ -1892,23 +1890,10 @@ public class Editor { // Make sure there is only at most one EasyEditSpan in the text if (mPopupWindow.mEasyEditSpan != null) { - mPopupWindow.mEasyEditSpan.setDeleteEnabled(false); + text.removeSpan(mPopupWindow.mEasyEditSpan); } mPopupWindow.setEasyEditSpan((EasyEditSpan) span); - mPopupWindow.setOnDeleteListener(new EasyEditDeleteListener() { - @Override - public void onDeleteClick(EasyEditSpan span) { - Editable editable = (Editable) mTextView.getText(); - int start = editable.getSpanStart(span); - int end = editable.getSpanEnd(span); - if (start >= 0 && end >= 0) { - sendNotification(EasyEditSpan.TEXT_DELETED, span); - mTextView.deleteText_internal(start, end); - } - editable.removeSpan(span); - } - }); if (mTextView.getWindowVisibility() != View.VISIBLE) { // The window is not visible yet, ignore the text change. @@ -1942,10 +1927,8 @@ public class Editor { @Override public void onSpanChanged(Spannable text, Object span, int previousStart, int previousEnd, int newStart, int newEnd) { - if (mPopupWindow != null && span instanceof EasyEditSpan) { - EasyEditSpan easyEditSpan = (EasyEditSpan) span; - sendNotification(EasyEditSpan.TEXT_MODIFIED, easyEditSpan); - text.removeSpan(easyEditSpan); + if (mPopupWindow != null && span == mPopupWindow.mEasyEditSpan) { + text.removeSpan(mPopupWindow.mEasyEditSpan); } } @@ -1955,31 +1938,6 @@ public class Editor { mTextView.removeCallbacks(mHidePopup); } } - - private void sendNotification(int textChangedType, EasyEditSpan span) { - try { - PendingIntent pendingIntent = span.getPendingIntent(); - if (pendingIntent != null) { - Intent intent = new Intent(); - intent.putExtra(EasyEditSpan.EXTRA_TEXT_CHANGED_TYPE, textChangedType); - pendingIntent.send(mTextView.getContext(), 0, intent); - } - } catch (CanceledException e) { - // This should not happen, as we should try to send the intent only once. - Log.w(TAG, "PendingIntent for notification cannot be sent", e); - } - } - } - - /** - * Listens for the delete event triggered by {@link EasyEditPopupWindow}. - */ - private interface EasyEditDeleteListener { - - /** - * Clicks the delete pop-up. - */ - void onDeleteClick(EasyEditSpan span); } /** @@ -1992,7 +1950,6 @@ public class Editor { com.android.internal.R.layout.text_edit_action_popup_text; private TextView mDeleteTextView; private EasyEditSpan mEasyEditSpan; - private EasyEditDeleteListener mOnDeleteListener; @Override protected void createPopupWindow() { @@ -2027,26 +1984,16 @@ public class Editor { mEasyEditSpan = easyEditSpan; } - private void setOnDeleteListener(EasyEditDeleteListener listener) { - mOnDeleteListener = listener; - } - @Override public void onClick(View view) { - if (view == mDeleteTextView - && mEasyEditSpan != null && mEasyEditSpan.isDeleteEnabled() - && mOnDeleteListener != null) { - mOnDeleteListener.onDeleteClick(mEasyEditSpan); - } - } - - @Override - public void hide() { - if (mEasyEditSpan != null) { - mEasyEditSpan.setDeleteEnabled(false); + if (view == mDeleteTextView) { + Editable editable = (Editable) mTextView.getText(); + int start = editable.getSpanStart(mEasyEditSpan); + int end = editable.getSpanEnd(mEasyEditSpan); + if (start >= 0 && end >= 0) { + mTextView.deleteText_internal(start, end); + } } - mOnDeleteListener = null; - super.hide(); } @Override |