Java Code Examples for android.text.method.TextKeyListener#getMetaState()

The following examples show how to use android.text.method.TextKeyListener#getMetaState() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Layout.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Fills in the specified Path with a representation of a cursor
 * at the specified offset.  This will often be a vertical line
 * but can be multiple discontinuous lines in text with multiple
 * directionalities.
 */
public void getCursorPath(final int point, final Path dest, final CharSequence editingBuffer) {
    dest.reset();

    int line = getLineForOffset(point);
    int top = getLineTop(line);
    int bottom = getLineBottomWithoutSpacing(line);

    boolean clamped = shouldClampCursor(line);
    float h1 = getPrimaryHorizontal(point, clamped) - 0.5f;
    float h2 = isLevelBoundary(point) ? getSecondaryHorizontal(point, clamped) - 0.5f : h1;

    int caps = TextKeyListener.getMetaState(editingBuffer, TextKeyListener.META_SHIFT_ON) |
               TextKeyListener.getMetaState(editingBuffer, TextKeyListener.META_SELECTING);
    int fn = TextKeyListener.getMetaState(editingBuffer, TextKeyListener.META_ALT_ON);
    int dist = 0;

    if (caps != 0 || fn != 0) {
        dist = (bottom - top) >> 2;

        if (fn != 0)
            top += dist;
        if (caps != 0)
            bottom -= dist;
    }

    if (h1 < 0.5f)
        h1 = 0.5f;
    if (h2 < 0.5f)
        h2 = 0.5f;

    if (Float.compare(h1, h2) == 0) {
        dest.moveTo(h1, top);
        dest.lineTo(h1, bottom);
    } else {
        dest.moveTo(h1, top);
        dest.lineTo(h1, (top + bottom) >> 1);

        dest.moveTo(h2, (top + bottom) >> 1);
        dest.lineTo(h2, bottom);
    }

    if (caps == 2) {
        dest.moveTo(h2, bottom);
        dest.lineTo(h2 - dist, bottom + dist);
        dest.lineTo(h2, bottom);
        dest.lineTo(h2 + dist, bottom + dist);
    } else if (caps == 1) {
        dest.moveTo(h2, bottom);
        dest.lineTo(h2 - dist, bottom + dist);

        dest.moveTo(h2 - dist, bottom + dist - 0.5f);
        dest.lineTo(h2 + dist, bottom + dist - 0.5f);

        dest.moveTo(h2 + dist, bottom + dist);
        dest.lineTo(h2, bottom);
    }

    if (fn == 2) {
        dest.moveTo(h1, top);
        dest.lineTo(h1 - dist, top - dist);
        dest.lineTo(h1, top);
        dest.lineTo(h1 + dist, top - dist);
    } else if (fn == 1) {
        dest.moveTo(h1, top);
        dest.lineTo(h1 - dist, top - dist);

        dest.moveTo(h1 - dist, top - dist + 0.5f);
        dest.lineTo(h1 + dist, top - dist + 0.5f);

        dest.moveTo(h1 + dist, top - dist);
        dest.lineTo(h1, top);
    }
}
 
Example 2
Source File: Layout.java    From PowerFileExplorer with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Fills in the specified Path with a representation of a cursor
 * at the specified offset.  This will often be a vertical line
 * but can be multiple discontinous lines in text with multiple
 * directionalities.
 */
public void getCursorPath(int point, Path dest,
                          CharSequence editingBuffer) {
    dest.reset();

    int line = getLineForOffset(point);
    int top = getLineTop(line);
    int bottom = getLineTop(line+1);

    float h1 = getPrimaryHorizontal(point) - 0.5f;
    float h2 = getSecondaryHorizontal(point) - 0.5f;

    int caps = TextKeyListener.getMetaState(editingBuffer,
                                            KeyEvent.META_SHIFT_ON) |
               JotaTextKeyListener.getMetaStateSelecting(editingBuffer);
    int fn = TextKeyListener.getMetaState(editingBuffer,
                                          KeyEvent.META_ALT_ON);
    int dist = 0;

    if (caps != 0 || fn != 0) {
        dist = (bottom - top) >> 2;

        if (fn != 0)
            top += dist;
        if (caps != 0)
            bottom -= dist;
    }

    if (h1 < 0.5f)
        h1 = 0.5f;
    if (h2 < 0.5f)
        h2 = 0.5f;

    if (h1 == h2) {
        dest.moveTo(h1, top);
        dest.lineTo(h1, bottom);
    } else {
        dest.moveTo(h1, top);
        dest.lineTo(h1, (top + bottom) >> 1);

        dest.moveTo(h2, (top + bottom) >> 1);
        dest.lineTo(h2, bottom);
    }

    if (caps == 2) {
        dest.moveTo(h2, bottom);
        dest.lineTo(h2 - dist, bottom + dist);
        dest.lineTo(h2, bottom);
        dest.lineTo(h2 + dist, bottom + dist);
    } else if (caps == 1) {
        dest.moveTo(h2, bottom);
        dest.lineTo(h2 - dist, bottom + dist);

        dest.moveTo(h2 - dist, bottom + dist - 0.5f);
        dest.lineTo(h2 + dist, bottom + dist - 0.5f);

        dest.moveTo(h2 + dist, bottom + dist);
        dest.lineTo(h2, bottom);
    }

    if (fn == 2) {
        dest.moveTo(h1, top);
        dest.lineTo(h1 - dist, top - dist);
        dest.lineTo(h1, top);
        dest.lineTo(h1 + dist, top - dist);
    } else if (fn == 1) {
        dest.moveTo(h1, top);
        dest.lineTo(h1 - dist, top - dist);

        dest.moveTo(h1 - dist, top - dist + 0.5f);
        dest.lineTo(h1 + dist, top - dist + 0.5f);

        dest.moveTo(h1 + dist, top - dist);
        dest.lineTo(h1, top);
    }
}
 
Example 3
Source File: Layout.java    From JotaTextEditor with Apache License 2.0 4 votes vote down vote up
/**
 * Fills in the specified Path with a representation of a cursor
 * at the specified offset.  This will often be a vertical line
 * but can be multiple discontinous lines in text with multiple
 * directionalities.
 */
public void getCursorPath(int point, Path dest,
                          CharSequence editingBuffer) {
    dest.reset();

    int line = getLineForOffset(point);
    int top = getLineTop(line);
    int bottom = getLineTop(line+1);

    float h1 = getPrimaryHorizontal(point) - 0.5f;
    float h2 = getSecondaryHorizontal(point) - 0.5f;

    int caps = TextKeyListener.getMetaState(editingBuffer,
                                            KeyEvent.META_SHIFT_ON) |
               JotaTextKeyListener.getMetaStateSelecting(editingBuffer);
    int fn = TextKeyListener.getMetaState(editingBuffer,
                                          KeyEvent.META_ALT_ON);
    int dist = 0;

    if (caps != 0 || fn != 0) {
        dist = (bottom - top) >> 2;

        if (fn != 0)
            top += dist;
        if (caps != 0)
            bottom -= dist;
    }

    if (h1 < 0.5f)
        h1 = 0.5f;
    if (h2 < 0.5f)
        h2 = 0.5f;

    if (h1 == h2) {
        dest.moveTo(h1, top);
        dest.lineTo(h1, bottom);
    } else {
        dest.moveTo(h1, top);
        dest.lineTo(h1, (top + bottom) >> 1);

        dest.moveTo(h2, (top + bottom) >> 1);
        dest.lineTo(h2, bottom);
    }

    if (caps == 2) {
        dest.moveTo(h2, bottom);
        dest.lineTo(h2 - dist, bottom + dist);
        dest.lineTo(h2, bottom);
        dest.lineTo(h2 + dist, bottom + dist);
    } else if (caps == 1) {
        dest.moveTo(h2, bottom);
        dest.lineTo(h2 - dist, bottom + dist);

        dest.moveTo(h2 - dist, bottom + dist - 0.5f);
        dest.lineTo(h2 + dist, bottom + dist - 0.5f);

        dest.moveTo(h2 + dist, bottom + dist);
        dest.lineTo(h2, bottom);
    }

    if (fn == 2) {
        dest.moveTo(h1, top);
        dest.lineTo(h1 - dist, top - dist);
        dest.lineTo(h1, top);
        dest.lineTo(h1 + dist, top - dist);
    } else if (fn == 1) {
        dest.moveTo(h1, top);
        dest.lineTo(h1 - dist, top - dist);

        dest.moveTo(h1 - dist, top - dist + 0.5f);
        dest.lineTo(h1 + dist, top - dist + 0.5f);

        dest.moveTo(h1 + dist, top - dist);
        dest.lineTo(h1, top);
    }
}