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

The following examples show how to use android.text.method.MetaKeyKeyListener#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: BaseInputConnection.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * The default implementation changes the selection position in the
 * current editable text.
 */
public boolean setSelection(int start, int end) {
    if (DEBUG) Log.v(TAG, "setSelection " + start + ", " + end);
    final Editable content = getEditable();
    if (content == null) return false;
    int len = content.length();
    if (start > len || end > len || start < 0 || end < 0) {
        // If the given selection is out of bounds, just ignore it.
        // Most likely the text was changed out from under the IME,
        // and the IME is going to have to update all of its state
        // anyway.
        return true;
    }
    if (start == end && MetaKeyKeyListener.getMetaState(content,
            MetaKeyKeyListener.META_SELECTING) != 0) {
        // If we are in selection mode, then we want to extend the
        // selection instead of replacing it.
        Selection.extendSelection(content, start);
    } else {
        Selection.setSelection(content, start, end);
    }
    return true;
}
 
Example 2
Source File: ArrowKeyMovementMethod.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
private boolean down(TextView widget, Spannable buffer) {
        boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
                        KeyEvent.META_SHIFT_ON) == 1) ||
                      (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0);
        boolean alt = MetaKeyKeyListener.getMetaState(buffer,
                        KeyEvent.META_ALT_ON) == 1;
        Layout layout = widget.getLayout();

        if (cap) {
            if (alt) {
//                Selection.extendSelection(buffer, buffer.length());
                widget.movePage(false,true);
                return true;
            } else {
                return Selection.extendDown(buffer, layout);
            }
        } else {
            if (alt) {
//                Selection.setSelection(buffer, buffer.length());
                widget.movePage(false,false);
                return true;
            } else {
                return Selection.moveDown(buffer, layout);
            }
        }
    }
 
Example 3
Source File: ArrowKeyMovementMethod.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
private boolean left(TextView widget, Spannable buffer) {
    boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
                    KeyEvent.META_SHIFT_ON) == 1) ||
                  (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0);
    boolean alt = MetaKeyKeyListener.getMetaState(buffer,
                    KeyEvent.META_ALT_ON) == 1;
    Layout layout = widget.getLayout();

    if (cap) {
        if (alt) {
            return Selection.extendToLeftEdge(buffer, layout);
        } else {
            return Selection.extendLeft(buffer, layout);
        }
    } else {
        if (alt) {
            return Selection.moveToLeftEdge(buffer, layout);
        } else {
            return Selection.moveLeft(buffer, layout);
        }
    }
}
 
Example 4
Source File: ArrowKeyMovementMethod.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
private boolean right(TextView widget, Spannable buffer) {
    boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
                    KeyEvent.META_SHIFT_ON) == 1) ||
                  (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0);
    boolean alt = MetaKeyKeyListener.getMetaState(buffer,
                    KeyEvent.META_ALT_ON) == 1;
    Layout layout = widget.getLayout();

    if (cap) {
        if (alt) {
            return Selection.extendToRightEdge(buffer, layout);
        } else {
            return Selection.extendRight(buffer, layout);
        }
    } else {
        if (alt) {
            return Selection.moveToRightEdge(buffer, layout);
        } else {
            return Selection.moveRight(buffer, layout);
        }
    }
}
 
Example 5
Source File: ArrowKeyMovementMethod.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
private boolean movehome(TextView widget, Spannable buffer, KeyEvent event) {
    boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
                    KeyEvent.META_SHIFT_ON) == 1) ||
                  (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0);
    Layout layout = widget.getLayout();

    boolean ctrl = (event.getMetaState() & mShortcutCtrlKey)!=0;

    if ( ctrl ){
        if (cap) {
            Selection.extendSelection(buffer, 0);
            return true;
        } else {
            Selection.setSelection(buffer, 0);
            return true;
        }
    }else{
        if (cap) {
            return Selection.extendToLeftEdge(buffer, layout);
        } else {
            return Selection.moveToLeftEdge(buffer, layout);
        }
    }
}
 
Example 6
Source File: ArrowKeyMovementMethod.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
private boolean moveend(TextView widget, Spannable buffer, KeyEvent event) {
    boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
                    KeyEvent.META_SHIFT_ON) == 1) ||
                  (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0);
    Layout layout = widget.getLayout();

    boolean ctrl = (event.getMetaState() & mShortcutCtrlKey)!=0;

    if ( ctrl ){
        if (cap) {
            Selection.extendSelection(buffer, buffer.length());
            return true;
        } else {
            Selection.setSelection(buffer, buffer.length());
            return true;
        }
    }else{
        if (cap) {
            return Selection.extendToRightEdge(buffer, layout);
        } else {
            return Selection.moveToRightEdge(buffer, layout);
        }
    }
}
 
Example 7
Source File: ArrowKeyMovementMethod.java    From JotaTextEditor with Apache License 2.0 6 votes vote down vote up
private boolean moveend(TextView widget, Spannable buffer, KeyEvent event) {
    boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
                    KeyEvent.META_SHIFT_ON) == 1) ||
                  (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0);
    Layout layout = widget.getLayout();

    boolean ctrl = (event.getMetaState() & mShortcutCtrlKey)!=0;

    if ( ctrl ){
        if (cap) {
            Selection.extendSelection(buffer, buffer.length());
            return true;
        } else {
            Selection.setSelection(buffer, buffer.length());
            return true;
        }
    }else{
        if (cap) {
            return Selection.extendToRightEdge(buffer, layout);
        } else {
            return Selection.moveToRightEdge(buffer, layout);
        }
    }
}
 
Example 8
Source File: ArrowKeyMovementMethod.java    From JotaTextEditor with Apache License 2.0 6 votes vote down vote up
private boolean movehome(TextView widget, Spannable buffer, KeyEvent event) {
    boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
                    KeyEvent.META_SHIFT_ON) == 1) ||
                  (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0);
    Layout layout = widget.getLayout();

    boolean ctrl = (event.getMetaState() & mShortcutCtrlKey)!=0;

    if ( ctrl ){
        if (cap) {
            Selection.extendSelection(buffer, 0);
            return true;
        } else {
            Selection.setSelection(buffer, 0);
            return true;
        }
    }else{
        if (cap) {
            return Selection.extendToLeftEdge(buffer, layout);
        } else {
            return Selection.moveToLeftEdge(buffer, layout);
        }
    }
}
 
Example 9
Source File: ArrowKeyMovementMethod.java    From JotaTextEditor with Apache License 2.0 6 votes vote down vote up
private boolean right(TextView widget, Spannable buffer) {
    boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
                    KeyEvent.META_SHIFT_ON) == 1) ||
                  (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0);
    boolean alt = MetaKeyKeyListener.getMetaState(buffer,
                    KeyEvent.META_ALT_ON) == 1;
    Layout layout = widget.getLayout();

    if (cap) {
        if (alt) {
            return Selection.extendToRightEdge(buffer, layout);
        } else {
            return Selection.extendRight(buffer, layout);
        }
    } else {
        if (alt) {
            return Selection.moveToRightEdge(buffer, layout);
        } else {
            return Selection.moveRight(buffer, layout);
        }
    }
}
 
Example 10
Source File: ArrowKeyMovementMethod.java    From JotaTextEditor with Apache License 2.0 6 votes vote down vote up
private boolean up(TextView widget, Spannable buffer) {
        boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
                        KeyEvent.META_SHIFT_ON) == 1) ||
                      (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0);
        boolean alt = MetaKeyKeyListener.getMetaState(buffer,
                        KeyEvent.META_ALT_ON) == 1;
        Layout layout = widget.getLayout();

        if (cap) {
            if (alt) {
//                Selection.extendSelection(buffer, 0);
                widget.movePage(true,true);
                return true;
            } else {
                return Selection.extendUp(buffer, layout);
            }
        } else {
            if (alt) {
//                Selection.setSelection(buffer, 0);
                widget.movePage(true,false);
                return true;
            } else {
                return Selection.moveUp(buffer, layout);
            }
        }
    }
 
Example 11
Source File: ArrowKeyMovementMethod.java    From JotaTextEditor with Apache License 2.0 6 votes vote down vote up
private boolean down(TextView widget, Spannable buffer) {
        boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
                        KeyEvent.META_SHIFT_ON) == 1) ||
                      (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0);
        boolean alt = MetaKeyKeyListener.getMetaState(buffer,
                        KeyEvent.META_ALT_ON) == 1;
        Layout layout = widget.getLayout();

        if (cap) {
            if (alt) {
//                Selection.extendSelection(buffer, buffer.length());
                widget.movePage(false,true);
                return true;
            } else {
                return Selection.extendDown(buffer, layout);
            }
        } else {
            if (alt) {
//                Selection.setSelection(buffer, buffer.length());
                widget.movePage(false,false);
                return true;
            } else {
                return Selection.moveDown(buffer, layout);
            }
        }
    }
 
Example 12
Source File: ArrowKeyMovementMethod.java    From JotaTextEditor with Apache License 2.0 6 votes vote down vote up
private boolean left(TextView widget, Spannable buffer) {
    boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
                    KeyEvent.META_SHIFT_ON) == 1) ||
                  (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0);
    boolean alt = MetaKeyKeyListener.getMetaState(buffer,
                    KeyEvent.META_ALT_ON) == 1;
    Layout layout = widget.getLayout();

    if (cap) {
        if (alt) {
            return Selection.extendToLeftEdge(buffer, layout);
        } else {
            return Selection.extendLeft(buffer, layout);
        }
    } else {
        if (alt) {
            return Selection.moveToLeftEdge(buffer, layout);
        } else {
            return Selection.moveLeft(buffer, layout);
        }
    }
}
 
Example 13
Source File: ArrowKeyMovementMethod.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
public boolean doFunction(TextView widget, Spannable buffer, int function)
{
    boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
            KeyEvent.META_SHIFT_ON) == 1) ||
          (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0);

    Log.d("=========================>","cap="+cap);

    switch( function )
    {
        case TextView.FUNCTION_CURSOR_LEFT:
            return moveLeft(widget, buffer, cap);
        case TextView.FUNCTION_CURSOR_RIGHT:
            return moveRight(widget, buffer, cap);
        case TextView.FUNCTION_CURSOR_UP:
            return moveUp(widget, buffer, cap);
        case TextView.FUNCTION_CURSOR_DOWN:
            return moveDown(widget, buffer, cap);
        case TextView.FUNCTION_PAGE_UP:
            return movePageUp(widget, buffer, cap);
        case TextView.FUNCTION_PAGE_DOWN:
            return movePageDown(widget, buffer, cap);
        case TextView.FUNCTION_HOME:
            return moveHome(widget, buffer, cap);
        case TextView.FUNCTION_END:
            return moveEnd(widget, buffer, cap);
        case TextView.FUNCTION_TOP:
            return moveTop(widget, buffer, cap);
        case TextView.FUNCTION_BOTTOM:
            return moveBottom(widget, buffer, cap);
    }
    return false;
}
 
Example 14
Source File: ArrowKeyMovementMethod.java    From JotaTextEditor with Apache License 2.0 5 votes vote down vote up
private boolean voldown(TextView widget, Spannable buffer) {
    boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
                    KeyEvent.META_SHIFT_ON) == 1) ||
                  (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0);
    if (cap) {
        widget.movePage(false,true);
        return true;
    } else {
        widget.movePage(false,false);
        return true;
    }
}
 
Example 15
Source File: ArrowKeyMovementMethod.java    From JotaTextEditor with Apache License 2.0 5 votes vote down vote up
private boolean volup(TextView widget, Spannable buffer) {
    boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
                    KeyEvent.META_SHIFT_ON) == 1) ||
                  (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0);
    if (cap) {
        widget.movePage(true,true);
        return true;
    } else {
        widget.movePage(true,false);
        return true;
    }
}
 
Example 16
Source File: ArrowKeyMovementMethod.java    From JotaTextEditor with Apache License 2.0 5 votes vote down vote up
public boolean doFunction(TextView widget, Spannable buffer, int function)
{
    boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
            KeyEvent.META_SHIFT_ON) == 1) ||
          (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0);

    Log.d("=========================>","cap="+cap);

    switch( function )
    {
        case TextView.FUNCTION_CURSOR_LEFT:
            return moveLeft(widget, buffer, cap);
        case TextView.FUNCTION_CURSOR_RIGHT:
            return moveRight(widget, buffer, cap);
        case TextView.FUNCTION_CURSOR_UP:
            return moveUp(widget, buffer, cap);
        case TextView.FUNCTION_CURSOR_DOWN:
            return moveDown(widget, buffer, cap);
        case TextView.FUNCTION_PAGE_UP:
            return movePageUp(widget, buffer, cap);
        case TextView.FUNCTION_PAGE_DOWN:
            return movePageDown(widget, buffer, cap);
        case TextView.FUNCTION_HOME:
            return moveHome(widget, buffer, cap);
        case TextView.FUNCTION_END:
            return moveEnd(widget, buffer, cap);
        case TextView.FUNCTION_TOP:
            return moveTop(widget, buffer, cap);
        case TextView.FUNCTION_BOTTOM:
            return moveBottom(widget, buffer, cap);
    }
    return false;
}
 
Example 17
Source File: ArrowKeyMovementMethod.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
private boolean voldown(TextView widget, Spannable buffer) {
    boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
                    KeyEvent.META_SHIFT_ON) == 1) ||
                  (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0);
    if (cap) {
        widget.movePage(false,true);
        return true;
    } else {
        widget.movePage(false,false);
        return true;
    }
}
 
Example 18
Source File: ArrowKeyMovementMethod.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
private boolean volup(TextView widget, Spannable buffer) {
    boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
                    KeyEvent.META_SHIFT_ON) == 1) ||
                  (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0);
    if (cap) {
        widget.movePage(true,true);
        return true;
    } else {
        widget.movePage(true,false);
        return true;
    }
}
 
Example 19
Source File: JotaTextKeyListener.java    From PowerFileExplorer with GNU General Public License v3.0 4 votes vote down vote up
public static final int getMetaStateSelecting(CharSequence text) {
    return MetaKeyKeyListener.getMetaState(text, META_SELECTING);
}
 
Example 20
Source File: JotaTextKeyListener.java    From JotaTextEditor with Apache License 2.0 4 votes vote down vote up
public static final int getMetaStateSelecting(CharSequence text) {
    return MetaKeyKeyListener.getMetaState(text, META_SELECTING);
}