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

Commit 3dbf55c3 authored by Gilles Debunne's avatar Gilles Debunne
Browse files

TextView's color transparency is taken into account.

Unless it has a background, the TextView will be able to support
alpha (text, cursor and highlighted text colors).

Background colored spans should be detected and should also multiply
their alpha by mCurrentAlpha.

Bug 3144861

Change-Id: If640895b8c0b25dc00b909a0a118b68fac0cfd76
parent ac1325bc
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -257586,7 +257586,7 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="arg0" type="T">
<parameter name="t" type="T">
</parameter>
</method>
</interface>
@@ -262045,7 +262045,7 @@
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 synchronized="true"
 static="false"
 final="false"
 deprecated="not deprecated"
@@ -262060,7 +262060,7 @@
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 synchronized="true"
 static="false"
 final="false"
 deprecated="not deprecated"
@@ -262194,7 +262194,7 @@
 return="java.beans.PropertyChangeListener[]"
 abstract="false"
 native="false"
 synchronized="false"
 synchronized="true"
 static="false"
 final="false"
 deprecated="not deprecated"
@@ -262207,7 +262207,7 @@
 return="java.beans.PropertyChangeListener[]"
 abstract="false"
 native="false"
 synchronized="false"
 synchronized="true"
 static="false"
 final="false"
 deprecated="not deprecated"
@@ -262218,7 +262218,7 @@
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 synchronized="true"
 static="false"
 final="false"
 deprecated="not deprecated"
@@ -262231,7 +262231,7 @@
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 synchronized="true"
 static="false"
 final="false"
 deprecated="not deprecated"
@@ -262246,7 +262246,7 @@
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 synchronized="true"
 static="false"
 final="false"
 deprecated="not deprecated"
+13 −12
Original line number Diff line number Diff line
@@ -16,6 +16,10 @@

package android.view;

import com.android.internal.R;
import com.android.internal.util.Predicate;
import com.android.internal.view.menu.MenuBuilder;

import android.content.ClipData;
import android.content.Context;
import android.content.res.Configuration;
@@ -54,6 +58,7 @@ import android.util.PoolableManager;
import android.util.Pools;
import android.util.SparseArray;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.MeasureSpec;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityEventSource;
import android.view.accessibility.AccessibilityManager;
@@ -63,9 +68,6 @@ import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.widget.ScrollBarDrawable;
import com.android.internal.R;
import com.android.internal.util.Predicate;
import com.android.internal.view.menu.MenuBuilder;

import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
@@ -2805,7 +2807,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility

    /**
     * Gets the current list of listeners for layout changes.
     * @return
     */
    public List<OnLayoutChangeListener> getOnLayoutChangeListeners() {
        return mOnLayoutChangeListeners;
@@ -5448,8 +5449,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
                if ((mRight - mLeft) != mPrevWidth || (mBottom - mTop) != mPrevHeight) {
                    mPrevWidth = mRight - mLeft;
                    mPrevHeight = mBottom - mTop;
                    mPivotX = (float) mPrevWidth / 2f;
                    mPivotY = (float) mPrevHeight / 2f;
                    mPivotX = mPrevWidth / 2f;
                    mPivotY = mPrevHeight / 2f;
                }
            }
            mMatrix.reset();
@@ -10423,8 +10424,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
                root.getLastTouchPoint(thumbSize);

                okay = mAttachInfo.mSession.performDrag(mAttachInfo.mWindow, token,
                        (float) thumbSize.x, (float) thumbSize.y,
                        (float) thumbTouchPoint.x, (float) thumbTouchPoint.y, data);
                        thumbSize.x, thumbSize.y,
                        thumbTouchPoint.x, thumbTouchPoint.y, data);
                if (ViewDebug.DEBUG_DRAG) Log.d(VIEW_LOG_TAG, "performDrag returned " + okay);
            }
        } catch (Exception e) {
@@ -11299,8 +11300,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility

        public final Interpolator scrollBarInterpolator = new Interpolator(1, 2);

        private final float[] mOpaque = { 255.0f };
        private final float[] mTransparent = { 0.0f };
        private static final float[] OPAQUE = { 255 };
        private static final float[] TRANSPARENT = { 0.0f };
        
        /**
         * When fading should start. This time moves into the future every time
@@ -11360,11 +11361,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
                Interpolator interpolator = scrollBarInterpolator;

                // Start opaque
                interpolator.setKeyFrame(framesCount++, nextFrame, mOpaque);
                interpolator.setKeyFrame(framesCount++, nextFrame, OPAQUE);

                // End transparent
                nextFrame += scrollBarFadeDuration;
                interpolator.setKeyFrame(framesCount, nextFrame, mTransparent);
                interpolator.setKeyFrame(framesCount, nextFrame, TRANSPARENT);

                state = FADING;

+18 −4
Original line number Diff line number Diff line
@@ -208,7 +208,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
    static final boolean DEBUG_EXTRACT = false;
    
    private static final int PRIORITY = 100;

    private int mCurrentAlpha = 255;

    final int[] mTempCoords = new int[2];
@@ -4066,7 +4065,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener

    @Override
    protected boolean onSetAlpha(int alpha) {
        if (mMovement == null && getBackground() == null) {
        // Alpha is supported if and only if the drawing can be done in one pass.
        // TODO text with spans with a background color currently do not respect this alpha.
        if (getBackground() == null) {
            mCurrentAlpha = alpha;
            final Drawables dr = mDrawables;
            if (dr != null) {
@@ -4077,6 +4078,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            }
            return true;
        }

        mCurrentAlpha = 255;
        return false;
    }

@@ -4256,7 +4259,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        }

        mTextPaint.setColor(color);
        mTextPaint.setAlpha(mCurrentAlpha);
        if (mCurrentAlpha != 255) {
            // If set, the alpha will override the color's alpha. Multiply the alphas.
            mTextPaint.setAlpha((mCurrentAlpha * Color.alpha(color)) / 255);
        }
        mTextPaint.drawableState = getDrawableState();

        canvas.save();
@@ -4334,6 +4340,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener

                        // XXX should pass to skin instead of drawing directly
                        mHighlightPaint.setColor(cursorcolor);
                        if (mCurrentAlpha != 255) {
                            mHighlightPaint.setAlpha(
                                    (mCurrentAlpha * Color.alpha(cursorcolor)) / 255);
                        }
                        mHighlightPaint.setStyle(Paint.Style.STROKE);

                        highlight = mHighlightPath;
@@ -4347,6 +4357,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener

                    // XXX should pass to skin instead of drawing directly
                    mHighlightPaint.setColor(mHighlightColor);
                    if (mCurrentAlpha != 255) {
                        mHighlightPaint.setAlpha(
                                (mCurrentAlpha * Color.alpha(mHighlightColor)) / 255);
                    }
                    mHighlightPaint.setStyle(Paint.Style.FILL);

                    highlight = mHighlightPath;