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

Commit 1b916301 authored by Luca Zanolin's avatar Luca Zanolin Committed by Android (Google) Code Review
Browse files

Revert "Enable correction/deleting notification via EasyEditSpan."

This reverts commit 8cd8135b

Change-Id: I6361cc47d58281ab37cb9ae0a67541b43f873147
parent 8cd8135b
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -22969,13 +22969,9 @@ package android.text.style {
  public class EasyEditSpan implements android.text.ParcelableSpan {
    ctor public EasyEditSpan();
    ctor public EasyEditSpan(android.app.PendingIntent);
    ctor public EasyEditSpan(android.os.Parcel);
    method public int describeContents();
    method public int getSpanTypeId();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final java.lang.String ACTION_TEXT_DELETED = "android.text.style.TEXT_DELETED";
    field public static final java.lang.String ACTION_TEXT_MODIFIED = "android.text.style.TEXT_MODIFIED";
  }
  public class ForegroundColorSpan extends android.text.style.CharacterStyle implements android.text.ParcelableSpan android.text.style.UpdateAppearance {
+1 −1
Original line number Diff line number Diff line
@@ -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:
+3 −82
Original line number Diff line number Diff line
@@ -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;
    }
}
+10 −63
Original line number Diff line number Diff line
@@ -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);
            }
            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);
                }

        @Override
        public void hide() {
            if (mEasyEditSpan != null) {
                mEasyEditSpan.setDeleteEnabled(false);
            }
            mOnDeleteListener = null;
            super.hide();
        }

        @Override