Java 类android.text.method.Touch 实例源码

项目:PSNine    文件:LocalLinkMovementMethod.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    int action = event.getAction();

    if (action == MotionEvent.ACTION_UP ||
            action == MotionEvent.ACTION_DOWN) {
        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) {
            if (action == MotionEvent.ACTION_UP) {
                link[0].onClick(widget);
            } else if (action == MotionEvent.ACTION_DOWN) {
                Selection.setSelection(buffer,
                        buffer.getSpanStart(link[0]),
                        buffer.getSpanEnd(link[0]));
            }

            return true;
        } else {
            Selection.removeSelection(buffer);
            Touch.onTouchEvent(widget, buffer, event);
            return false;
        }
    }
    return Touch.onTouchEvent(widget, buffer, event);
}
项目:SDHtmlTextView    文件:LocalLinkMovementMethod.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    int action = event.getAction();

    if (action == MotionEvent.ACTION_UP ||
            action == MotionEvent.ACTION_DOWN) {
        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) {
            if (action == MotionEvent.ACTION_UP) {
                link[0].onClick(widget);
            } else if (action == MotionEvent.ACTION_DOWN) {
                Selection.setSelection(buffer,
                        buffer.getSpanStart(link[0]),
                        buffer.getSpanEnd(link[0]));
            }

            return true;
        } else {
            Selection.removeSelection(buffer);
            Touch.onTouchEvent(widget, buffer, event);
            return false;
        }
    }
    return Touch.onTouchEvent(widget, buffer, event);
}
项目:JianshuApp    文件:LocalLinkMovementMethod.java   
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    int action = event.getAction();
    if (action != MotionEvent.ACTION_UP && action != MotionEvent.ACTION_DOWN) {
        return Touch.onTouchEvent(widget, buffer, event);
    }

    int x = (((int) event.getX()) - widget.getTotalPaddingLeft()) + widget.getScrollX();
    int y = (((int) event.getY()) - widget.getTotalPaddingTop()) + widget.getScrollY();
    Layout layout = widget.getLayout();
    int off = layout.getOffsetForHorizontal(layout.getLineForVertical(y), (float) x);
    ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
    if (link.length != 0) {
        if (action == MotionEvent.ACTION_UP) {
            link[0].onClick(widget);
        } else {
            Selection.setSelection(buffer, buffer.getSpanStart(link[0]), buffer.getSpanEnd(link[0]));
        }
        if (!(widget instanceof TextViewFixTouchConsume)) {
            return true;
        }
        ((TextViewFixTouchConsume) widget).linkHit = true;
        return true;
    }
    Selection.removeSelection(buffer);
    Touch.onTouchEvent(widget, buffer, event);
    return false;
}
项目:AndroidProjectsClient    文件:ClickableMovementMethod.java   
@Override
public boolean onTouchEvent(final TextView widget, final Spannable buffer, MotionEvent event) {
    final int action = event.getAction();

    if(action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {

        int x = (int) event.getX();
        int y = (int) event.getY();

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

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

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

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

        if(clickable.length != 0) {
            if(action == MotionEvent.ACTION_UP) {
                clickable[0].onClick(widget);
                triggerSpanHit(widget);
            }
            return true;
        } else {
            Selection.removeSelection(buffer);
            Touch.onTouchEvent(widget, buffer, event);
            return false;
        }
    }

    return Touch.onTouchEvent(widget, buffer, event);
}
项目:meishiDemo    文件:NameTouchMovementMethod.java   
public boolean onTouchEvent(TextView widget, Spannable buffer,
                            MotionEvent event) {
    int offSet = getOffsetForHorizontal(widget, event);
    ClickableSpan[] spanName = buffer.getSpans(offSet, offSet, ClickableSpan.class);
    if (spanName.length == 0) {
        Selection.removeSelection(buffer);
        return Touch.onTouchEvent(widget, buffer, event);
    }
    ClickableSpan span = spanName[0];
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            setSapnBackgroundGrayEffect(span, buffer);
            Selection.setSelection(buffer,
                    buffer.getSpanStart(span),
                    buffer.getSpanEnd(span));
            break;
        case MotionEvent.ACTION_UP:
            newClickTask(new ClickTask(span, widget));
            resetSapnBackground(span, buffer);
            break;
        case MotionEvent.ACTION_CANCEL:
            removeAllTask();
            resetSapnBackground(span, buffer);
            break;
    }
    return Touch.onTouchEvent(widget, buffer, event);
}
项目:meiShi    文件:NameTouchMovementMethod.java   
public boolean onTouchEvent(TextView widget, Spannable buffer,
                            MotionEvent event) {
    int offSet = getOffsetForHorizontal(widget, event);
    ClickableSpan[] spanName = buffer.getSpans(offSet, offSet, ClickableSpan.class);
    if (spanName.length == 0) {
        Selection.removeSelection(buffer);
        return Touch.onTouchEvent(widget, buffer, event);
    }
    ClickableSpan span = spanName[0];
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            setSapnBackgroundGrayEffect(span, buffer);
            Selection.setSelection(buffer,
                    buffer.getSpanStart(span),
                    buffer.getSpanEnd(span));
            break;
        case MotionEvent.ACTION_UP:
            newClickTask(new ClickTask(span, widget));
            resetSapnBackground(span, buffer);
            break;
        case MotionEvent.ACTION_CANCEL:
            removeAllTask();
            resetSapnBackground(span, buffer);
            break;
    }
    return Touch.onTouchEvent(widget, buffer, event);
}
项目:Slide    文件:CustomMovementMethod.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer,
                            MotionEvent event) {
    int action = event.getAction();

    if (action == MotionEvent.ACTION_UP ||
            action == MotionEvent.ACTION_DOWN) {
        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) {
            if (action == MotionEvent.ACTION_UP) {
                link[0].onClick(widget);
            } else if (action == MotionEvent.ACTION_DOWN) {
                Selection.setSelection(buffer,
                        buffer.getSpanStart(link[0]),
                        buffer.getSpanEnd(link[0]));
            }
            return true;
        }
    }

    return Touch.onTouchEvent(widget, buffer, event);
}
项目:LinkifiedTextView    文件:LinkTextView.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    int action = event.getAction();
    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
        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) {
            if (action == MotionEvent.ACTION_UP) {
                link[link.length - 1].onClick(widget);
            }

            if (widget instanceof LinkTextView) {
                ((LinkTextView) widget).hitLink = true;
            }
            return true;
        }
        else {
            Touch.onTouchEvent(widget, buffer, event);
            return false;
        }
    }
    return Touch.onTouchEvent(widget, buffer, event);
}
项目:html-textview    文件:LocalLinkMovementMethod.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    int action = event.getAction();

    if (action == MotionEvent.ACTION_UP ||
            action == MotionEvent.ACTION_DOWN) {
        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) {
            if (action == MotionEvent.ACTION_UP) {
                link[0].onClick(widget);
            } else if (action == MotionEvent.ACTION_DOWN) {
                Selection.setSelection(buffer,
                        buffer.getSpanStart(link[0]),
                        buffer.getSpanEnd(link[0]));
            }

            return true;
        } else {
            Selection.removeSelection(buffer);
            Touch.onTouchEvent(widget, buffer, event);
            return false;
        }
    }
    return Touch.onTouchEvent(widget, buffer, event);
}
项目:MyFire    文件:CircleMovementMethod.java   
public boolean onTouchEvent(TextView widget, Spannable buffer,
                            MotionEvent event) {

    int action = event.getAction();
    if(action == MotionEvent.ACTION_DOWN){
        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);

        mClickLinks = buffer.getSpans(off, off, ClickableSpan.class);
        if(mClickLinks.length > 0){
            // 点击的是Span区域,不要把点击事件传递
            setPassToTv(false);
            Selection.setSelection(buffer,
                    buffer.getSpanStart(mClickLinks[0]),
                    buffer.getSpanEnd(mClickLinks[0]));
            //设置点击区域的背景色
            mBgSpan = new BackgroundColorSpan(AppApplication.getAppResources().getColor(mClickableSpanBgClorId));
            buffer.setSpan(mBgSpan,
                    buffer.getSpanStart(mClickLinks[0]),
                    buffer.getSpanEnd(mClickLinks[0]),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }else{
            setPassToTv(true);
            // textview选中效果
            widget.setBackgroundResource(mTextViewBgColorId);
        }

    }else if(action == MotionEvent.ACTION_UP){
        if(mClickLinks.length > 0){
            mClickLinks[0].onClick(widget);
            if(mBgSpan != null){
                buffer.removeSpan(mBgSpan);
            }
        }else{
            if(mBgSpan != null){
                buffer.removeSpan(mBgSpan);
            }
        }
        Selection.removeSelection(buffer);
        widget.setBackgroundResource(DEFAULT_COLOR);
    }else if(action == MotionEvent.ACTION_MOVE){

    }else{
        if(mBgSpan != null){
            buffer.removeSpan(mBgSpan);
        }
        widget.setBackgroundResource(DEFAULT_COLOR);
    }
    return Touch.onTouchEvent(widget, buffer, event);
}
项目:Hitalk    文件:BnMovementMethod.java   
public boolean onTouchEvent(TextView widget, Spannable buffer,
                            MotionEvent event) {

    int action = event.getAction();
    if(action == MotionEvent.ACTION_DOWN){
        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);

        mClickLinks = buffer.getSpans(off, off, ClickableSpan.class);
        if(mClickLinks.length > 0){
            // 点击的是Span区域,不要把点击事件传递
            setPassToTv(false);
            Selection.setSelection(buffer,
                    buffer.getSpanStart(mClickLinks[0]),
                    buffer.getSpanEnd(mClickLinks[0]));
            //设置点击区域的背景色
            mBgSpan = new BackgroundColorSpan(clickableSpanBgClor);
            buffer.setSpan(mBgSpan,
                    buffer.getSpanStart(mClickLinks[0]),
                    buffer.getSpanEnd(mClickLinks[0]),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }else{
            setPassToTv(true);
            // textview选中效果
            widget.setBackgroundColor(textViewBgColor);
        }

    }else if(action == MotionEvent.ACTION_UP){
        if(mClickLinks.length > 0){
            mClickLinks[0].onClick(widget);
            if(mBgSpan != null){//移除点击时设置的背景span
                buffer.removeSpan(mBgSpan);
            }
        }else{

        }
        Selection.removeSelection(buffer);
        widget.setBackgroundColor(Color.TRANSPARENT);
    }else if(action == MotionEvent.ACTION_MOVE){
        //这种情况不用做处理
    }else{
        if(mBgSpan != null){//移除点击时设置的背景span
            buffer.removeSpan(mBgSpan);
        }
        widget.setBackgroundColor(Color.TRANSPARENT);
    }
    return Touch.onTouchEvent(widget, buffer, event);
}
项目:qmui    文件:QMUILinkTouchMovementMethod.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    return sHelper.onTouchEvent(widget, buffer, event)
            || Touch.onTouchEvent(widget, buffer, event);
}
项目:qmui    文件:QMUIScrollingMovementMethod.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    return sHelper.onTouchEvent(widget, buffer, event)
            || Touch.onTouchEvent(widget, buffer, event);
}
项目:CommentView    文件:TouchMovementMethod.java   
public boolean onTouchEvent(TextView widget, Spannable buffer,
                            MotionEvent event) {

    int action = event.getAction();
    if(action == MotionEvent.ACTION_DOWN){
        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);

        mClickLinks = buffer.getSpans(off, off, ClickableSpan.class);
        if(mClickLinks.length > 0){
            // 点击的是Span区域,不要把点击事件传递
            setPassToTv(false);
            Selection.setSelection(buffer,
                    buffer.getSpanStart(mClickLinks[0]),
                    buffer.getSpanEnd(mClickLinks[0]));
            //设置点击区域的背景色
            mBgSpan = new BackgroundColorSpan(mPressSpanBgColor);
            buffer.setSpan(mBgSpan,
                    buffer.getSpanStart(mClickLinks[0]),
                    buffer.getSpanEnd(mClickLinks[0]),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }else{
            setPassToTv(true);
            // textView选中效果
            widget.setBackgroundColor(mPressSpanBgColor);
        }

    }else if(action == MotionEvent.ACTION_UP){
        if(mClickLinks.length > 0){
            mClickLinks[0].onClick(widget);
            if(mBgSpan != null){//移除点击时设置的背景span
                buffer.removeSpan(mBgSpan);
            }
        }
        Selection.removeSelection(buffer);
        widget.setBackgroundColor(mTextViewBgColor);
    }else if(action == MotionEvent.ACTION_MOVE){
        //这种情况不用做处理
    }else{
        if(mBgSpan != null){//移除点击时设置的背景span
            buffer.removeSpan(mBgSpan);
        }
        widget.setBackgroundColor(mTextViewBgColor);
    }
    return Touch.onTouchEvent(widget, buffer, event);
}
项目:ShangHanLun    文件:LocalLinkMovementMethod.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer,
                            MotionEvent event) {
    int action = event.getAction();

    if (action == MotionEvent.ACTION_UP
            || action == MotionEvent.ACTION_DOWN) {
        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) {
            if (action == MotionEvent.ACTION_UP) {
                if (System.currentTimeMillis() - lastClickTime < CLICK_DELAY) {
                    link[0].onClick(widget);
                }
            } else if (action == MotionEvent.ACTION_DOWN) {
                Selection.setSelection(buffer,
                        buffer.getSpanStart(link[0]),
                        buffer.getSpanEnd(link[0]));
                lastClickTime = System.currentTimeMillis();
            }

            if (widget instanceof UILabel) {
                ((UILabel) widget).linkHit = true;
            }
            return true;
        } else {
            Selection.removeSelection(buffer);
        }
    }
    return Touch.onTouchEvent(widget, buffer, event);
}
项目:QMUI_Android    文件:QMUILinkTouchMovementMethod.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    return sHelper.onTouchEvent(widget, buffer, event)
            || Touch.onTouchEvent(widget, buffer, event);
}
项目:QMUI_Android    文件:QMUIScrollingMovementMethod.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    return sHelper.onTouchEvent(widget, buffer, event)
            || Touch.onTouchEvent(widget, buffer, event);
}
项目:Jisort    文件:LocalLinkMovementMethod.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    int action = event.getAction();

    if (action == MotionEvent.ACTION_UP ||
            action == MotionEvent.ACTION_DOWN) {
        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) {
            if (action == MotionEvent.ACTION_UP) {
                link[0].onClick(widget);
            } else if (action == MotionEvent.ACTION_DOWN) {
                Selection.setSelection(buffer,
                        buffer.getSpanStart(link[0]),
                        buffer.getSpanEnd(link[0]));
            }

            if (widget instanceof HtmlTextView) {
                ((HtmlTextView) widget).mLinkHit = true;
            }
            return true;
        } else {
            Selection.removeSelection(buffer);
            Touch.onTouchEvent(widget, buffer, event);
            return false;
        }
    }
    return Touch.onTouchEvent(widget, buffer, event);
}
项目:matterdroid    文件:AbstractHtmlTextViewLinkMovementMethod.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    int action = event.getAction();

    if (action == MotionEvent.ACTION_UP ||
            action == MotionEvent.ACTION_DOWN) {
        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) {
            if (action == MotionEvent.ACTION_UP) {
                URLSpan urlSpan = (URLSpan) link[0];
                onLinkClicked(widget, urlSpan.getURL());

            } else if (action == MotionEvent.ACTION_DOWN) {
                Selection.setSelection(buffer,
                        buffer.getSpanStart(link[0]),
                        buffer.getSpanEnd(link[0]));
            }

            if (widget instanceof HtmlTextView) {
                ((HtmlTextView) widget).linkHit = true;
            }
            return true;
        } else {
            Selection.removeSelection(buffer);
            Touch.onTouchEvent(widget, buffer, event);
            return false;
        }
    }
    return Touch.onTouchEvent(widget, buffer, event);
}
项目:BigApp_Discuz_Android    文件:TextViewFixTouchConsume.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer,
        MotionEvent event) {
    int action = event.getAction();

    if (action == MotionEvent.ACTION_UP
            || action == MotionEvent.ACTION_DOWN) {
        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) {
            if (action == MotionEvent.ACTION_UP) {
                link[0].onClick(widget);
            } else if (action == MotionEvent.ACTION_DOWN) {
                Selection.setSelection(buffer,
                        buffer.getSpanStart(link[0]),
                        buffer.getSpanEnd(link[0]));
            }

            if (widget instanceof TextViewFixTouchConsume) {
                ((TextViewFixTouchConsume) widget).linkHit = true;
            }
            return true;
        } else {
            Selection.removeSelection(buffer);
            Touch.onTouchEvent(widget, buffer, event);
            return false;
        }
    }
    return Touch.onTouchEvent(widget, buffer, event);
}
项目:BigApp_Discuz_Android    文件:WeiboTextView.java   
@Override
        public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
            int action = event.getAction();

//            LogUtils.printLog(WeiboTextView.class, "MotionEvent:" + action);

//            if (action == MotionEvent.ACTION_MOVE) {
//                isPressed = false;
//            }
            switch (action) {
                case MotionEvent.ACTION_DOWN:
                    break;
                case MotionEvent.ACTION_UP:
                    break;

                case MotionEvent.ACTION_CANCEL:
                    buffer.setSpan(new BackgroundColorSpan(0x00000000), 0, weiboTextView.length(),
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                    Selection.setSelection(buffer, 0, weiboTextView.length());
                    break;
            }


            if (action == MotionEvent.ACTION_UP ||
                    action == MotionEvent.ACTION_DOWN) {
                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) {

                    int start = buffer.getSpanStart(link[0]);
                    int end = buffer.getSpanEnd(link[0]);

//                    LogUtils.printLog(WebViewUtils.class, "start:" + start + " end:" + end);

                    if (action == MotionEvent.ACTION_UP) {
                        link[0].onClick(widget);
                        buffer.setSpan(new BackgroundColorSpan(0x00000000), start, end,
                                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                        Selection.setSelection(buffer, start, end);
                    } else if (action == MotionEvent.ACTION_DOWN) {
                        buffer.setSpan(new BackgroundColorSpan(weiboTextView.clickBgClolr), start, end,
                                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                        Selection.setSelection(buffer, start, end);
                    }

                    if (widget instanceof WeiboTextView) {
                        ((WeiboTextView) widget).linkHit = true;
                    }
                    return true;
                } else {
                    Selection.removeSelection(buffer);
                    Touch.onTouchEvent(widget, buffer, event);
                    return false;
                }
            }


            return Touch.onTouchEvent(widget, buffer, event);
        }
项目:markdown-to-spanned    文件:Markdown.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    int action = event.getAction();

    if (action == MotionEvent.ACTION_UP ||
            action == MotionEvent.ACTION_DOWN) {
        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) {
            if (action == MotionEvent.ACTION_UP) {
                link[0].onClick(widget);
            } else if (action == MotionEvent.ACTION_DOWN) {
                Selection.setSelection(buffer,
                                       buffer.getSpanStart(link[0]),
                                       buffer.getSpanEnd(link[0]));
            }

            //                  if (widget instanceof HtmlTextView) {
            //                      ((HtmlTextView) widget).mLinkHit = true;
            //                  }
            return true;
        } else {
            Selection.removeSelection(buffer);
            Touch.onTouchEvent(widget, buffer, event);
            return false;
        }
    }
    return Touch.onTouchEvent(widget, buffer, event);
}
项目:FriendCircleDemo    文件:CircleMovementMethod.java   
public boolean onTouchEvent(TextView widget, Spannable buffer,
                            MotionEvent event) {

    int action = event.getAction();
    if (action == MotionEvent.ACTION_DOWN) {
        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);

        mClickLinks = buffer.getSpans(off, off, ClickableSpan.class);
        if (mClickLinks.length > 0) {
            // 点击的是Span区域,不要把点击事件传递
            setPassToTv(false);
            Selection.setSelection(buffer,
                    buffer.getSpanStart(mClickLinks[0]),
                    buffer.getSpanEnd(mClickLinks[0]));
            //设置点击区域的背景色
            mBgSpan = new BackgroundColorSpan(getContext().getResources().getColor(mClickableSpanBgClorId));
            buffer.setSpan(mBgSpan,
                    buffer.getSpanStart(mClickLinks[0]),
                    buffer.getSpanEnd(mClickLinks[0]),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else {
            setPassToTv(true);
            // textview选中效果
            widget.setBackgroundResource(mTextViewBgColorId);
        }

    } else if (action == MotionEvent.ACTION_UP) {
        if (mClickLinks.length > 0) {
            mClickLinks[0].onClick(widget);
            if (mBgSpan != null) {
                buffer.removeSpan(mBgSpan);
            }

        } else {

        }
        Selection.removeSelection(buffer);
        widget.setBackgroundResource(DEFAULT_COLOR);
    } else if (action == MotionEvent.ACTION_MOVE) {

    } else {
        if (mBgSpan != null) {
            buffer.removeSpan(mBgSpan);
        }
        widget.setBackgroundResource(DEFAULT_COLOR);
    }
    return Touch.onTouchEvent(widget, buffer, event);
}
项目:umeng_community_android    文件:TextViewFixTouchConsume.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    int action = event.getAction();

    if (action == MotionEvent.ACTION_UP ||
            action == MotionEvent.ACTION_DOWN) {
        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) {
            if (action == MotionEvent.ACTION_UP) {
                link[0].onClick(widget);
            } else if (action == MotionEvent.ACTION_DOWN) {
                Selection.setSelection(buffer,
                        buffer.getSpanStart(link[0]),
                        buffer.getSpanEnd(link[0]));
            }

            if (widget instanceof TextViewFixTouchConsume) {
                ((TextViewFixTouchConsume) widget).mlinkHit = true;
            }
            return true;
        } else {
            Selection.removeSelection(buffer);
            Touch.onTouchEvent(widget, buffer, event);
            return false;
        }
    }
    return Touch.onTouchEvent(widget, buffer, event);
}
项目:AndroidGeek    文件:TextViewFixTouchConsume.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    int action = event.getAction();

    if (action == MotionEvent.ACTION_UP ||
            action == MotionEvent.ACTION_DOWN) {
        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) {
            if (action == MotionEvent.ACTION_UP) {
                link[0].onClick(widget);
            } else if (action == MotionEvent.ACTION_DOWN) {
                Selection.setSelection(buffer,
                        buffer.getSpanStart(link[0]),
                        buffer.getSpanEnd(link[0]));
            }

            if (widget instanceof TextViewFixTouchConsume) {
                ((TextViewFixTouchConsume) widget).mlinkHit = true;
            }
            return true;
        } else {
            Selection.removeSelection(buffer);
            Touch.onTouchEvent(widget, buffer, event);
            return false;
        }
    }
    return Touch.onTouchEvent(widget, buffer, event);
}
项目:riot-android    文件:MatrixLinkMovementMethod.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    int action = event.getAction();

    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
        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) {
            if (action == MotionEvent.ACTION_UP) {
                if (link[0] instanceof URLSpan) {
                    if (null != mListener) {
                        URLSpan span = (URLSpan) link[0];
                        mListener.onURLClick(Uri.parse(span.getURL()));
                    }
                } else {
                    link[0].onClick(widget);
                }

            } else if (action == MotionEvent.ACTION_DOWN) {
                Selection.setSelection(buffer,
                        buffer.getSpanStart(link[0]),
                        buffer.getSpanEnd(link[0]));
            }

            return true;
        } else {
            Selection.removeSelection(buffer);
            Touch.onTouchEvent(widget, buffer, event);
            return false;
        }
    }
    return Touch.onTouchEvent(widget, buffer, event);
}
项目:oschina-app    文件:TextViewFixTouchConsume.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer,
        MotionEvent event) {
    int action = event.getAction();

    if (action == MotionEvent.ACTION_UP
            || action == MotionEvent.ACTION_DOWN) {
        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) {
            if (action == MotionEvent.ACTION_UP) {
                link[0].onClick(widget);
            } else if (action == MotionEvent.ACTION_DOWN) {
                Selection.setSelection(buffer,
                        buffer.getSpanStart(link[0]),
                        buffer.getSpanEnd(link[0]));
            }

            if (widget instanceof TextViewFixTouchConsume) {
                ((TextViewFixTouchConsume) widget).linkHit = true;
            }
            return true;
        } else {
            Selection.removeSelection(buffer);
            Touch.onTouchEvent(widget, buffer, event);
            return false;
        }
    }
    return Touch.onTouchEvent(widget, buffer, event);
}
项目:ima_intellj    文件:TextViewFixTouchConsume.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer,
        MotionEvent event) {
    int action = event.getAction();

    if (action == MotionEvent.ACTION_UP
            || action == MotionEvent.ACTION_DOWN) {
        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) {
            if (action == MotionEvent.ACTION_UP) {
                link[0].onClick(widget);
            } else if (action == MotionEvent.ACTION_DOWN) {
                Selection.setSelection(buffer,
                        buffer.getSpanStart(link[0]),
                        buffer.getSpanEnd(link[0]));
            }

            if (widget instanceof TextViewFixTouchConsume) {
                ((TextViewFixTouchConsume) widget).linkHit = true;
            }
            return true;
        } else {
            Selection.removeSelection(buffer);
            Touch.onTouchEvent(widget, buffer, event);
            return false;
        }
    }
    return Touch.onTouchEvent(widget, buffer, event);
}