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

Commit 91a08cfc authored by Gilles Debunne's avatar Gilles Debunne
Browse files

Rationalized singleLine in TextView, take 2.

Same as CL 77435, but without the default singleLine value change.

Change-Id: I04794ed72716bbe5a285d2bbbb3f536308e5972f
parent 010e2c29
Loading
Loading
Loading
Loading
+16 −37
Original line number Diff line number Diff line
@@ -791,10 +791,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                    ? inputType : EditorInfo.TYPE_CLASS_TEXT;
        } else if (inputType != EditorInfo.TYPE_NULL) {
            setInputType(inputType, true);
            singleLine = (inputType&(EditorInfo.TYPE_MASK_CLASS
                            | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE)) !=
                    (EditorInfo.TYPE_CLASS_TEXT
                            | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE);
            // If set, the input type overrides what was set using the deprecated singleLine flag.
            singleLine = !isMultilineInputType(inputType);
        } else if (phone) {
            mInput = DialerKeyListener.getInstance();
            mInputType = inputType = EditorInfo.TYPE_CLASS_PHONE;
@@ -813,9 +811,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            TextKeyListener.Capitalize cap;

            inputType = EditorInfo.TYPE_CLASS_TEXT;
            if (!singleLine) {
                inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE;
            }

            switch (autocap) {
            case 1:
@@ -843,9 +838,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        } else if (editable) {
            mInput = TextKeyListener.getInstance();
            mInputType = EditorInfo.TYPE_CLASS_TEXT;
            if (!singleLine) {
                mInputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE;
            }
        } else {
            mInput = null;

@@ -888,13 +880,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            drawableLeft, drawableTop, drawableRight, drawableBottom);
        setCompoundDrawablePadding(drawablePadding);

        if (singleLine) {
            setSingleLine();

            if (mInput == null && ellipsize < 0) {
        setSingleLine(singleLine);
        if (singleLine && mInput == null && ellipsize < 0) {
                ellipsize = 3; // END
        }
        }

        switch (ellipsize) {
            case 1:
@@ -1157,14 +1146,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            } catch (IncompatibleClassChangeError e) {
                mInputType = EditorInfo.TYPE_CLASS_TEXT;
            }
            if ((mInputType&EditorInfo.TYPE_MASK_CLASS)
                    == EditorInfo.TYPE_CLASS_TEXT) {
                if (mSingleLine) {
                    mInputType &= ~EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE;
                } else {
                    mInputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE;
                }
            }
            setSingleLine(mSingleLine);
        } else {
            mInputType = EditorInfo.TYPE_NULL;
        }
@@ -2992,6 +2974,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        return mHint;
    }

    private boolean isMultilineInputType(int type) {
        return (type & (EditorInfo.TYPE_MASK_CLASS | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE)) ==
            (EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE);
    }

    /**
     * Set the type of the content with a constant as defined for
     * {@link EditorInfo#inputType}.  This will take care of changing
@@ -3028,17 +3015,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            }
        }
        
        boolean multiLine = (type&(EditorInfo.TYPE_MASK_CLASS
                        | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE)) ==
                (EditorInfo.TYPE_CLASS_TEXT
                        | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE);
        boolean singleLine = !isMultilineInputType(type);
        
        // We need to update the single line mode if it has changed or we
        // were previously in password mode.
        if (mSingleLine == multiLine || forceUpdate) {
        if (mSingleLine != singleLine || forceUpdate) {
            // Change single line mode, but only change the transformation if
            // we are not in password mode.
            applySingleLine(!multiLine, !isPassword);
            applySingleLine(singleLine, !isPassword);
        }
        
        InputMethodManager imm = InputMethodManager.peekInstance();
@@ -4746,10 +4730,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                    outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_ENTER_ACTION;
                }
            }
            if ((outAttrs.inputType & (InputType.TYPE_MASK_CLASS
                    | InputType.TYPE_TEXT_FLAG_MULTI_LINE))
                    == (InputType.TYPE_CLASS_TEXT
                            | InputType.TYPE_TEXT_FLAG_MULTI_LINE)) {
            if (isMultilineInputType(outAttrs.inputType)) {
                // Multi-line text editors should always show an enter key.
                outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_ENTER_ACTION;
            }
@@ -6092,8 +6073,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
     */
    @android.view.RemotableViewMethod
    public void setSingleLine(boolean singleLine) {
        if ((mInputType&EditorInfo.TYPE_MASK_CLASS)
                == EditorInfo.TYPE_CLASS_TEXT) {
        if ((mInputType & EditorInfo.TYPE_MASK_CLASS) == EditorInfo.TYPE_CLASS_TEXT) {
            if (singleLine) {
                mInputType &= ~EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE;
            } else {
@@ -6109,8 +6089,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            setLines(1);
            setHorizontallyScrolling(true);
            if (applyTransformation) {
                setTransformationMethod(SingleLineTransformationMethod.
                                        getInstance());
                setTransformationMethod(SingleLineTransformationMethod.getInstance());
            }
        } else {
            setMaxLines(Integer.MAX_VALUE);