Example usage for android.text.method ArrowKeyMovementMethod ArrowKeyMovementMethod

List of usage examples for android.text.method ArrowKeyMovementMethod ArrowKeyMovementMethod

Introduction

In this page you can find the example usage for android.text.method ArrowKeyMovementMethod ArrowKeyMovementMethod.

Prototype

ArrowKeyMovementMethod

Source Link

Usage

From source file:org.openintents.notepad.NoteEditor.java

@Override
protected void onResume() {
    super.onResume();
    if (DEBUG) {//  w  ww.j  av a  2  s . co m
        Log.d(TAG, "onResume");
    }

    if (DEBUG) {
        Log.d(TAG, "mDecrypted: " + mDecryptedText);
    }

    // Set auto-link on or off, based on the current setting.
    int autoLink = PreferenceActivity.getAutoLinkFromPreference(this);

    mText.setAutoLinkMask(autoLink);

    mEncrypted = 0;

    if (mState == STATE_EDIT || (mState == STATE_INSERT) || mState == STATE_EDIT_EXTERNAL_NOTE) {
        getNoteFromContentProvider();
    } else if (mState == STATE_EDIT_NOTE_FROM_SDCARD) {
        getNoteFromFile();
    }

    if (mEncrypted == 0 || mDecryptedText != null) {
        applyInsertText();
    }

    // Make sure that we don't use the link movement method.
    // Instead, we need a blend between the arrow key movement (for regular
    // navigation) and
    // the link movement (so the user can click on links).
    mText.setMovementMethod(new ArrowKeyMovementMethod() {
        public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
            // This block is copied and pasted from LinkMovementMethod's
            // onTouchEvent (without the part that actually changes the
            // selection).
            int action = event.getAction();

            if (action == MotionEvent.ACTION_UP) {
                int x = (int) event.getX();
                int y = (int) event.getY();

                x -= widget.getTotalPaddingLeft();
                y -= widget.getTotalPaddingTop();

                x += widget.getScrollX();
                y += widget.getScrollY();

                Layout layout = widget.getLayout();
                int line = layout.getLineForVertical(y);
                int off = layout.getOffsetForHorizontal(line, x);

                ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);

                if (link.length != 0) {
                    link[0].onClick(widget);
                    return true;
                }
            }

            return super.onTouchEvent(widget, buffer, event);
        }
    });

    setTheme(loadTheme());

    startupSearch();
}