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

Commit 3a70b20e authored by Gilles Debunne's avatar Gilles Debunne Committed by Android (Google) Code Review
Browse files

Merge "New cursor controller in TextViews."

parents 4670268f cc3ec6cd
Loading
Loading
Loading
Loading
+112 −0
Original line number Diff line number Diff line
@@ -166294,6 +166294,29 @@
<parameter name="event" type="android.view.MotionEvent">
</parameter>
</method>
<method name="setCursorController"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="cursorController" type="android.widget.TextView.CursorController">
</parameter>
</method>
<field name="mCursorController"
 type="android.widget.TextView.CursorController"
 transient="false"
 volatile="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="protected"
>
</field>
</class>
<class name="BaseKeyListener"
 extends="android.text.method.MetaKeyKeyListener"
@@ -222813,6 +222836,95 @@
>
</method>
</class>
<interface name="TextView.CursorController"
 abstract="true"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<method name="draw"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="canvas" type="android.graphics.Canvas">
</parameter>
</method>
<method name="getOffsetX"
 return="int"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getOffsetY"
 return="int"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="hide"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="onTouchEvent"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="event" type="android.view.MotionEvent">
</parameter>
</method>
<method name="show"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="updatePosition"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
</interface>
<interface name="TextView.OnEditorActionListener"
 abstract="true"
 static="true"
+2 −2
Original line number Diff line number Diff line
@@ -21,8 +21,8 @@ import com.android.internal.util.ArrayUtils;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Paint.FontMetricsInt;
import android.graphics.RectF;
import android.text.Layout.Directions;
import android.text.Layout.TabStops;
import android.text.style.CharacterStyle;
@@ -583,7 +583,7 @@ class TextLine {
    /**
     * Returns the next valid offset within this directional run, skipping
     * conjuncts and zero-width characters.  This should not be called to walk
     * off the end of the line, since the the returned values might not be valid
     * off the end of the line, since the returned values might not be valid
     * on neighboring lines.  If the returned offset is less than zero or
     * greater than the line length, the offset should be recomputed on the
     * preceding or following line, respectively.
+62 −14
Original line number Diff line number Diff line
@@ -16,23 +16,28 @@

package android.text.method;

import android.util.Log;
import android.text.Layout;
import android.text.NoCopySpan;
import android.text.Selection;
import android.text.Spannable;
import android.view.KeyEvent;
import android.graphics.Rect;
import android.text.*;
import android.widget.TextView;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.MotionEvent;
import android.widget.TextView;
import android.widget.TextView.CursorController;

// XXX this doesn't extend MetaKeyKeyListener because the signatures
// don't match.  Need to figure that out.  Meanwhile the meta keys
// won't work in fields that don't take input.

public class
ArrowKeyMovementMethod
implements MovementMethod
{
public class ArrowKeyMovementMethod implements MovementMethod {
    /**
     * An optional controller for the cursor.
     * Use {@link #setCursorController(CursorController)} to set this field.
     */
    protected CursorController mCursorController;

    private boolean up(TextView widget, Spannable buffer) {
        boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
                        KeyEvent.META_SHIFT_ON) == 1) ||
@@ -226,13 +231,22 @@ implements MovementMethod
        return false;
    }

    public boolean onTrackballEvent(TextView widget, Spannable text,
            MotionEvent event) {
    public boolean onTrackballEvent(TextView widget, Spannable text, MotionEvent event) {
        if (mCursorController != null) {
            mCursorController.hide();
        }
        return false;
    }

    public boolean onTouchEvent(TextView widget, Spannable buffer,
                                MotionEvent event) {
    public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
        if (mCursorController != null) {
            return onTouchEventCursor(widget, buffer, event);
        } else {
            return onTouchEventStandard(widget, buffer, event);
        }
    }

    private boolean onTouchEventStandard(TextView widget, Spannable buffer, MotionEvent event) {
        int initialScrollX = -1, initialScrollY = -1;
        if (event.getAction() == MotionEvent.ACTION_UP) {
            initialScrollX = Touch.getInitialScrollX(widget, buffer);
@@ -291,6 +305,7 @@ implements MovementMethod
                              (MetaKeyKeyListener.getMetaState(buffer,
                                MetaKeyKeyListener.META_SELECTING) != 0);


                if (cap && handled) {
                    // Before selecting, make sure we've moved out of the "slop".
                    // handled will be true, if we're in select mode AND we're
@@ -420,6 +435,39 @@ implements MovementMethod
        return handled;
    }

    private boolean onTouchEventCursor(TextView widget, Spannable buffer, MotionEvent event) {
        if (widget.isFocused() && !widget.didTouchFocusSelect()) {
            switch (event.getActionMasked()) {
                case MotionEvent.ACTION_MOVE:
                    widget.cancelLongPress();

                    // Offset the current touch position (from controller to cursor)
                    final int x = (int) event.getX() + mCursorController.getOffsetX();
                    final int y = (int) event.getY() + mCursorController.getOffsetY();
                    int offset = getOffset(x, y, widget);
                    Selection.setSelection(buffer, offset);
                    mCursorController.updatePosition();
                    return true;

                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_CANCEL:
                    mCursorController = null;
                    return true;
            }
        }
        return false;
    }

    /**
     * Defines the cursor controller.
     *
     * When set, this object can be used to handle events, that can be translated in cursor updates.
     * @param cursorController A cursor controller implementation
     */
    public void setCursorController(CursorController cursorController) {
        mCursorController = cursorController;
    }

    private static class DoubleTapState implements NoCopySpan {
        long mWhen;
    }
+2 −2
Original line number Diff line number Diff line
@@ -17,9 +17,9 @@
package android.text.method;

import android.text.Layout;
import android.text.Layout.Alignment;
import android.text.NoCopySpan;
import android.text.Spannable;
import android.text.Layout.Alignment;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
@@ -102,7 +102,7 @@ public class Touch {
                                       MotionEvent event) {
        DragState[] ds;

        switch (event.getAction()) {
        switch (event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            ds = buffer.getSpans(0, buffer.length(), DragState.class);

+298 −33

File changed.

Preview size limit exceeded, changes collapsed.

Loading