本文整理汇总了Java中android.widget.TextView.getTotalPaddingLeft方法的典型用法代码示例。如果您正苦于以下问题:Java TextView.getTotalPaddingLeft方法的具体用法?Java TextView.getTotalPaddingLeft怎么用?Java TextView.getTotalPaddingLeft使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.TextView
的用法示例。
在下文中一共展示了TextView.getTotalPaddingLeft方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPressedSpan
import android.widget.TextView; //导入方法依赖的package包/类
public ITouchableSpan getPressedSpan(TextView textView, Spannable spannable, MotionEvent event) {
int x = (int) event.getX();
int y = (int) event.getY();
x -= textView.getTotalPaddingLeft();
y -= textView.getTotalPaddingTop();
x += textView.getScrollX();
y += textView.getScrollY();
Layout layout = textView.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
if (x < layout.getLineLeft(line) || x > layout.getLineRight(line)) {
// 实际上没点到任何内容
off = -1;
}
ITouchableSpan[] link = spannable.getSpans(off, off, ITouchableSpan.class);
ITouchableSpan touchedSpan = null;
if (link.length > 0) {
touchedSpan = link[0];
}
return touchedSpan;
}
示例2: onTouchEvent
import android.widget.TextView; //导入方法依赖的package包/类
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
if (event.getAction() == 1) {
this.mLinkClicked = false;
this.mClickedLink = null;
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 = (ClickableSpan[]) buffer.getSpans(off, off, ClickableSpan
.class);
if (link.length != 0) {
SensibleUrlSpan span = link[0];
this.mLinkClicked = span.onClickSpan(widget);
this.mClickedLink = span.getURL();
return this.mLinkClicked;
}
}
super.onTouchEvent(widget, buffer, event);
return false;
}
示例3: onTouchEvent
import android.widget.TextView; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
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);
MathSpannable[] spans = buffer.getSpans(off, off, MathSpannable.class);
if (spans.length != 0) {
return spans[0].onTouchEvent(event);
}
return false;
}
示例4: textTouchEvent
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 微博文本触摸监听处理
*
* @param textView 点击的TextView
* @param event
* @return true:点击事件被处理;false:点击事件未被处理,向上冒泡
*/
private boolean textTouchEvent(TextView textView, MotionEvent event) {
boolean ret = false;
CharSequence text = textView.getText();
Spannable sText = Spannable.Factory.getInstance().newSpannable(text);
int action = event.getAction();
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
int y = (int) event.getY();
x -= textView.getTotalPaddingLeft();
y -= textView.getTotalPaddingTop();
x += textView.getScrollX();
y += textView.getScrollY();
Layout layout = textView.getLayout();
int line = layout.getLineForVertical(y);
int offset = layout.getOffsetForHorizontal(line, x);
ClickableSpan[] links = sText.getSpans(offset, offset, ClickableSpan.class);
if (links.length != 0) {
if (action == MotionEvent.ACTION_UP) {
links[0].onClick(textView);
}
ret = true;
}
}
return ret;
}
示例5: onTouchEvent
import android.widget.TextView; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
int action = event.getActionMasked();
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 {
Selection.setSelection(buffer, buffer.getSpanStart(link[0]),
buffer.getSpanEnd(link[0]));
}
return true;
} else {
Selection.removeSelection(buffer);
}
}
return false;
}
示例6: onTouchEvent
import android.widget.TextView; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer,
MotionEvent event) {
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 super.onTouchEvent(widget, buffer, event);
}
示例7: onTouchEvent
import android.widget.TextView; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
//http://stackoverflow.com/questions/1697084/handle-textview-link-click-in-my-android-app
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);
URLSpan[] link = buffer.getSpans(off, off, URLSpan.class);
if (link.length > 0) {
URLSpan span = link[0];
String url = span.getURL();
Spanned s = (Spanned) widget.getText();
int start = s.getSpanStart(span);
int end = s.getSpanEnd(span);
//http://stackoverflow.com/a/19750721/895797
String title = null;
if (start != -1 && end != -1) {
CharSequence wordThatWasClicked = s.subSequence(start, end);
title = wordThatWasClicked.toString();
}
onLinkClicked(widget, url, title);
return true;
}
}
return super.onTouchEvent(widget, buffer, event);
}
示例8: onTouchEvent
import android.widget.TextView; //导入方法依赖的package包/类
@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);
}
示例9: onTouchEvent
import android.widget.TextView; //导入方法依赖的package包/类
@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();
}
return true;
} else {
Selection.removeSelection(buffer);
}
}
return super.onTouchEvent(widget, buffer, event);
}
示例10: onTouchEvent
import android.widget.TextView; //导入方法依赖的package包/类
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
int action = event.getAction();
if (action == 1 || action == 0) {
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);
MyURLSpan[] link = (MyURLSpan[]) buffer.getSpans(off, off, MyURLSpan.class);
if (link.length != 0) {
if (action == 1) {
if (!this.mHasPerformedLongPress) {
link[0].onClick(widget);
}
this.pressed = false;
this.lastEvent = new float[2];
} else if (action == 0) {
this.pressed = true;
this.lastEvent[0] = event.getX();
this.lastEvent[1] = event.getY();
checkForLongClick(link, widget);
}
return true;
}
} else if (action == 2) {
float[] position = new float[]{event.getX(), event.getY()};
if (Math.sqrt(Math.hypot((double) Math.abs(this.lastEvent[0] - position[0]), (double)
Math.abs(this.lastEvent[1] - position[1]))) > ((double) 6)) {
this.pressed = false;
}
} else if (action == 3) {
this.pressed = false;
this.lastEvent = new float[2];
} else {
this.pressed = false;
this.lastEvent = new float[2];
}
return super.onTouchEvent(widget, buffer, event);
}
示例11: onTouchEvent
import android.widget.TextView; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_UP ||
action == MotionEvent.ACTION_DOWN ||
action == MotionEvent.ACTION_MOVE ||
action == MotionEvent.ACTION_CANCEL) {
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);
ImageTextSpan[] link = buffer.getSpans(off, off, ImageTextSpan.class);
if (link.length > 0) {
ImageTextSpan imageTextSpan = link[0];
int spanStart = buffer.getSpanStart(imageTextSpan);
int spanEnd = buffer.getSpanEnd(imageTextSpan);
int showTextLength = imageTextSpan.getShowTextLength();
int top = layout.getLineTop(line);
int bottom = layout.getLineTop(line + 1);
float left = layout.getPrimaryHorizontal(spanStart);
float right = layout.getPrimaryHorizontal(spanStart + showTextLength);
if (imageTextSpan.isCanClick() && (x >= left && x <= right) /*(off >= spanStart && off <= spanStart + showTextLength)*/) {
if (action == MotionEvent.ACTION_UP) {
imageTextSpan.onTouchUp(widget);
imageTextSpan.onClick(widget);
isTouchInSpan = false;
} else if (action == MotionEvent.ACTION_DOWN) {
isTouchInSpan = true;
imageTextSpan.onTouchDown(widget, event.getX(), event.getY());
if (showSelectionSpanBgColor) {
Selection.setSelection(buffer,
spanStart,
spanEnd);
}
} else if (action == MotionEvent.ACTION_MOVE) {
//link[0].onTouchMove(widget, event.getX(), event.getY());
//return super.onTouchEvent(widget, buffer, event);
} else {
isTouchInSpan = false;
imageTextSpan.onTouchCancel(widget, event.getX(), event.getY());
//return super.onTouchEvent(widget, buffer, event);
}
} else {
Selection.removeSelection(buffer);
}
return isTouchInSpan;
} else {
Selection.removeSelection(buffer);
}
}
return super.onTouchEvent(widget, buffer, event);
}
示例12: onTouchEvent
import android.widget.TextView; //导入方法依赖的package包/类
@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);
}
示例13: onTouchEvent
import android.widget.TextView; //导入方法依赖的package包/类
@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);
LongClickableSpan[] link = buffer.getSpans(off, off, LongClickableSpan.class);
if (link.length != 0) {
long currTime = System.currentTimeMillis();
LongClickableSpan l = link[0];
int ls = buffer.getSpanStart(l);
int le = buffer.getSpanEnd(l);
// 判断点击的点是否在Image范围内
ClickableImageSpan[] is = buffer.getSpans(ls, le, ClickableImageSpan.class);
if (is.length > 0) {
if (!is[0].clicked(x)) {
Selection.removeSelection(buffer);
return false;
}
} else if (off < layout.getOffsetToLeftOf(ls) || off > layout.getOffsetToLeftOf(le + 1)) {
// 判断点击位置是否在链接范围内
Selection.removeSelection(buffer);
return false;
}
if (action == MotionEvent.ACTION_UP) {
// 如果按下时间超过500毫秒,触发长按事件
if (currTime - lastTime > MIN_INTERVAL) {
if (!l.onLongClick(widget)) {
// onLongClick返回false代表事件未处理,交由onClick处理
l.onClick(widget);
}
} else {
l.onClick(widget);
}
} else {
Selection.setSelection(buffer,
ls, le);
}
lastTime = currTime;
return true;
} else {
Selection.removeSelection(buffer);
return false;
}
}
return super.onTouchEvent(widget, buffer, event);
}
示例14: onTouchEvent
import android.widget.TextView; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(TextView widget, Spannable text, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// 这里得到的x , y值只是相对于屏幕的位置
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 location = layout.getOffsetForHorizontal(layout.getLineForVertical(y), x);
clickableSpans = text.getSpans(location, location, ClickableSpan.class);
if (clickableSpans.length > 0) {
isClickTextView = false;
LogUtil.e("点击clickSpan位置");
// 选中点击位置
// Selection.setSelection(text, text.getSpanStart(clickableSpans[0]), text.getSpanEnd(clickableSpans[0]));
text.setSpan(colorSpan = new BackgroundColorSpan(selectedColor), text.getSpanStart(clickableSpans[0]), text.getSpanEnd(clickableSpans[0]), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return true;
} else {
isClickTextView = true;
widget.setBackgroundColor(Color.parseColor("#979595"));
LogUtil.e("点击的是正常textView的文字");
}
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
if (clickableSpans.length > 0) {
LogUtil.e("点击span的up11");
// 设置点击时间
clickableSpans[0].onClick(widget);
text.removeSpan(colorSpan);
// Selection.removeSelection(text);
return true;
} else {
LogUtil.e("点击textView文字的up11");
widget.setBackgroundColor(Color.parseColor("#00000000"));
}
break;
default:
if (colorSpan != null) {
text.removeSpan(colorSpan);
// Selection.removeSelection(text);
return true;
} else {
widget.setBackgroundColor(Color.parseColor("#00000000"));
}
break;
}
return super.onTouchEvent(widget, text, event);
}
示例15: onTouchEvent
import android.widget.TextView; //导入方法依赖的package包/类
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);
}