@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); }
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; }
@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); }
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); }
@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); }
@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); }
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); }
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); }
@Override public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) { return sHelper.onTouchEvent(widget, buffer, event) || Touch.onTouchEvent(widget, buffer, event); }
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); }
@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); }
@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); }
@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); }
@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); }
@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); }
@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); }
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); }
@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); }
@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); }