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

Commit 4899e66d authored by Alan Viverette's avatar Alan Viverette Committed by Android (Google) Code Review
Browse files

Merge "Add touch feedback to edit text"

parents 6b2c07cb c3f35b01
Loading
Loading
Loading
Loading
+3 −6
Original line number Diff line number Diff line
@@ -4737,13 +4737,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    private void manageFocusHotspot(boolean focused, View v) {
        if (mBackground != null && mBackground.supportsHotspots()) {
            final Rect r = new Rect();
            if (v != null) {
            if (!focused && v != null) {
                v.getBoundsOnScreen(r);
                final int[] location = new int[2];
                getLocationOnScreen(location);
                r.offset(-location[0], -location[1]);
            } else {
                r.set(mLeft, mTop, mRight, mBottom);
                r.set(0, 0, mRight - mLeft, mBottom - mTop);
            }
            final float x = r.exactCenterX();
@@ -4858,16 +4858,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        if ((mPrivateFlags & PFLAG_FOCUSED) != 0) {
            mPrivateFlags &= ~PFLAG_FOCUSED;
            if (hasFocus()) {
                manageFocusHotspot(false, focused);
            }
            if (propagate && mParent != null) {
                mParent.clearChildFocus(this);
            }
            onFocusChanged(false, 0, null);
            manageFocusHotspot(false, focused);
            refreshDrawableState();
            if (propagate && (!refocus || !rootViewRequestFocus())) {
+21 −24
Original line number Diff line number Diff line
@@ -14,29 +14,26 @@
     limitations under the License.
-->

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_window_focused="false" android:state_enabled="true">
<touch-feedback xmlns:android="http://schemas.android.com/apk/res/android"
    android:tint="?attr/colorControlActivated">
    <item>
        <selector>
            <item android:state_window_focused="false">
                <nine-patch android:src="@drawable/textfield_default_qntm_alpha"
                    android:tint="?attr/colorControlNormal" />
            </item>
    <item android:state_window_focused="false" android:state_enabled="false">
            <item android:state_enabled="false">
                <nine-patch android:src="@drawable/textfield_default_qntm_alpha"
                    android:tint="?attr/colorControlNormal" />
            </item>
    <item android:state_enabled="true" android:state_focused="true">
        <nine-patch android:src="@drawable/textfield_activated_qntm_alpha"
            android:tint="?attr/colorControlActivated" />
    </item>
    <item android:state_enabled="true" android:state_activated="true">
        <nine-patch android:src="@drawable/textfield_activated_qntm_alpha"
            android:tint="?attr/colorControlActivated" />
    </item>
    <item android:state_enabled="true">
            <item android:state_focused="false" android:state_activated="false">
                <nine-patch android:src="@drawable/textfield_default_qntm_alpha"
                    android:tint="?attr/colorControlNormal" />
            </item>
            <item>
        <nine-patch android:src="@drawable/textfield_default_qntm_alpha"
                <nine-patch android:src="@drawable/textfield_activated_qntm_alpha"
                    android:tint="?attr/colorControlNormal" />
            </item>
        </selector>
    </item>
</touch-feedback>
+24 −8
Original line number Diff line number Diff line
@@ -63,26 +63,30 @@ class Ripple {
    /** Whether the center is within the parent bounds. */
    private boolean mInside;

    /** Whether to pulse this ripple. */
    boolean mPulse;
    
    /** Enter state. A value in [0...1] or -1 if not set. */
    private float mEnterState = -1;
    float mEnterState = -1;

    /** Exit state. A value in [0...1] or -1 if not set. */
    private float mExitState = -1;
    float mExitState = -1;

    /** Outside state. A value in [0...1] or -1 if not set. */
    private float mOutsideState = -1;
    float mOutsideState = -1;

    /** Pulse state. A value in [0...1] or -1 if not set. */
    private float mPulseState = -1;
    float mPulseState = -1;

    /**
     * Creates a new ripple with the specified parent bounds, padding, initial
     * position, and screen density.
     */
    public Ripple(Rect bounds, Rect padding, float x, float y, float density) {
    public Ripple(Rect bounds, Rect padding, float x, float y, float density, boolean pulse) {
        mBounds = bounds;
        mPadding = padding;
        mInside = mBounds.contains((int) x, (int) y);
        mPulse = pulse;

        mX = x;
        mY = y;
@@ -115,6 +119,16 @@ class Ripple {
        }
    }

    public void onBoundsChanged() {
        final boolean inside = mBounds.contains((int) mX, (int) mY);
        if (mInside != inside) {
            if (mAnimator != null) {
                mAnimator.outside();
            }
            mInside = inside;
        }
    }

    public RippleAnimator animate() {
        if (mAnimator == null) {
            mAnimator = new RippleAnimator(this);
@@ -308,9 +322,11 @@ class Ripple {
                    MathUtils.constrain((currentTime - mOutsideTime) / (float) OUTSIDE_DURATION, 0, 1));

            // Pulse is a little more complicated.
            if (mTarget.mPulse) {
                final long pulseTime = (currentTime - mEnterTime - ENTER_DURATION - PULSE_DELAY);
                mTarget.mPulseState = pulseTime < 0 ? -1
                        : (pulseTime % (PULSE_INTERVAL + PULSE_DURATION)) / (float) PULSE_DURATION;
            }
        }
    }
}
+13 −1
Original line number Diff line number Diff line
@@ -111,6 +111,16 @@ public class TouchFeedbackDrawable extends LayerDrawable {
        return false;
    }

    @Override
    protected void onBoundsChange(Rect bounds) {
        super.onBoundsChange(bounds);

        final int N = mActiveRipplesCount;
        for (int i = 0; i < N; i++) {
            mActiveRipples[i].onBoundsChanged();
        }
    }

    @Override
    public boolean setVisible(boolean visible, boolean restart) {
        if (!visible) {
@@ -291,7 +301,9 @@ public class TouchFeedbackDrawable extends LayerDrawable {
                y = bounds.exactCenterY();
            }

            final Ripple newRipple = new Ripple(bounds, padding, x, y, mDensity);
            // TODO: Clean this up in the API.
            final boolean pulse = (id != R.attr.state_focused);
            final Ripple newRipple = new Ripple(bounds, padding, x, y, mDensity, pulse);
            newRipple.animate().enter();

            mActiveRipples[mActiveRipplesCount++] = newRipple;