当前位置: 首页>>代码示例>>Java>>正文


Java Layout.getOffsetForHorizontal方法代码示例

本文整理汇总了Java中android.text.Layout.getOffsetForHorizontal方法的典型用法代码示例。如果您正苦于以下问题:Java Layout.getOffsetForHorizontal方法的具体用法?Java Layout.getOffsetForHorizontal怎么用?Java Layout.getOffsetForHorizontal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.text.Layout的用法示例。


在下文中一共展示了Layout.getOffsetForHorizontal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onTouchEvent

import android.text.Layout; //导入方法依赖的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;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:21,代码来源:LinkUtils.java

示例2: getPreciseOffset

import android.text.Layout; //导入方法依赖的package包/类
public static int getPreciseOffset(TextView textView, int x, int y) {
    Layout layout = textView.getLayout();
    if (layout != null) {
        int topVisibleLine = layout.getLineForVertical(y);
        int offset = layout.getOffsetForHorizontal(topVisibleLine, x);

        int offsetX = (int) layout.getPrimaryHorizontal(offset);

        if (offsetX > x) {
            return layout.getOffsetToLeftOf(offset);
        } else {
            return offset;
        }
    } else {
        return -1;
    }
}
 
开发者ID:shenhuanet,项目名称:SelectableTextProvider,代码行数:18,代码来源:TextLayoutUtil.java

示例3: pointToPosition

import android.text.Layout; //导入方法依赖的package包/类
private int pointToPosition(int x, int y) {
    x -= getCompoundPaddingLeft();
    y -= getExtendedPaddingTop();

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

    Layout layout = getLayout();
    if (layout == null) {
        return -1;
    }

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

    return off;
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:18,代码来源:RecipientsEditor.java

示例4: handleClickableSpan

import android.text.Layout; //导入方法依赖的package包/类
public static boolean handleClickableSpan(View view, Layout layout, Spanned buffer, Class<? extends Clickable> spanType, 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 -= view.getPaddingLeft();
    y -= view.getPaddingTop();

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

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

    Clickable[] link = buffer.getSpans(off, off, spanType);

    if (link.length != 0) {
      if (action == MotionEvent.ACTION_UP) {
        link[0].onClick(view);
      } else if (buffer instanceof Spannable) {
        Selection.setSelection((Spannable) buffer,
            buffer.getSpanStart(link[0]),
            buffer.getSpanEnd(link[0]));
      }
      return true;
    } else if (buffer instanceof Spannable) {
      Selection.removeSelection((Spannable) buffer);
    }
  }

  return false;
}
 
开发者ID:lsjwzh,项目名称:FastTextView,代码行数:36,代码来源:ClickableSpanUtil.java

示例5: getPressedSpan

import android.text.Layout; //导入方法依赖的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;
}
 
开发者ID:coopese,项目名称:qmui,代码行数:26,代码来源:QMUILinkTouchDecorHelper.java

示例6: onTouchEvent

import android.text.Layout; //导入方法依赖的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;
}
 
开发者ID:tranleduy2000,项目名称:floating_calc,代码行数:24,代码来源:CalculatorEditText.java

示例7: pointToPosition

import android.text.Layout; //导入方法依赖的package包/类
private int pointToPosition(int x, int y) {
    x -= getCompoundPaddingLeft();
    y -= getExtendedPaddingTop();


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

    Layout layout = getLayout();
    if (layout == null) {
        return -1;
    }

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

    return off;
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:19,代码来源:RecipientsEditor.java

示例8: handleTouchEvent

import android.text.Layout; //导入方法依赖的package包/类
public boolean handleTouchEvent(MotionEvent event) {
    int action = event.getAction();
    if (action != MotionEvent.ACTION_UP
            && action != MotionEvent.ACTION_DOWN) {
        return true;
    } else {
        int x = (int) event.getX();
        int y = (int) event.getY();

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

        x += getScrollX();
        y += getScrollY();
        Layout layout = getLayout();
        int line = layout.getLineForVertical(y);
        int offset = layout.getOffsetForHorizontal(line, x);

        float width = layout.getLineWidth(line);
        if (y > width) {
            offset = y;
        }

        if (!(getText() instanceof Spannable)) {
            return true;
        } else {
            Spannable span = (Spannable) getText();
            ClickableSpan[] clickSpan = span.getSpans(offset, offset,
                    ClickableSpan.class);
            if (clickSpan == null || clickSpan.length == 0) {
                am[] aam = span.getSpans(offset, offset, am.class);
                if (aam != null && aam.length != 0)
                    return false;
                return true;
            } else {
                return false;
            }
        }
    }
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:41,代码来源:TweetTextView.java

示例9: onTouchEvent

import android.text.Layout; //导入方法依赖的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);
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:29,代码来源:ArticleMovementMethod.java

示例10: getTouchedSpan

import android.text.Layout; //导入方法依赖的package包/类
/**
 * Gets the span that was touched.
 * @param tv {@link TextView}
 * @param span {@link Spannable}
 * @param e {@link MotionEvent}
 * @return {@link TouchableSpan}
 */
private TouchableSpan getTouchedSpan(TextView tv, Spannable span, MotionEvent e) {
    // Find the location in which the touch was made
    int x = (int)e.getX();
    int y = (int)e.getY();

    // Ignore padding
    x -= tv.getTotalPaddingLeft();
    y -= tv.getTotalPaddingTop();

    // Account for scrollable text
    x += tv.getScrollX();
    y += tv.getScrollY();

    final Layout layout = tv.getLayout();
    final int touchedLine = layout.getLineForVertical(y);
    final int touchOffset = layout.getOffsetForHorizontal(touchedLine, x);

    // Set bounds of the touched line
    touchBounds.left = layout.getLineLeft(touchedLine);
    touchBounds.top = layout.getLineTop(touchedLine);
    touchBounds.right = layout.getLineRight(touchedLine);
    touchBounds.bottom = layout.getLineBottom(touchedLine);

    // Ensure the span falls within the bounds of the touch
    TouchableSpan touchSpan = null;
    if (touchBounds.contains(x, y)) {
        // Find clickable spans that lie under the touched area
        TouchableSpan[] spans = span.getSpans(touchOffset, touchOffset, TouchableSpan.class);
        touchSpan = (spans.length > 0) ? spans[0] : null;
    }

    return touchSpan;
}
 
开发者ID:tylersuehr7,项目名称:social-text-view,代码行数:41,代码来源:AccurateMovementMethod.java

示例11: reactTagForTouch

import android.text.Layout; //导入方法依赖的package包/类
@Override
public int reactTagForTouch(float touchX, float touchY) {
  Spanned text = (Spanned) getText();
  int target = getId();

  int x = (int) touchX;
  int y = (int) touchY;

  Layout layout = getLayout();
  if (layout == null) {
    // If the layout is null, the view hasn't been properly laid out yet. Therefore, we can't find
    // the exact text tag that has been touched, and the correct tag to return is the default one.
    return target;
  }
  int line = layout.getLineForVertical(y);

  int lineStartX = (int) layout.getLineLeft(line);
  int lineEndX = (int) layout.getLineRight(line);

  // TODO(5966918): Consider extending touchable area for text spans by some DP constant
  if (x >= lineStartX && x <= lineEndX) {
    int index = layout.getOffsetForHorizontal(line, x);

    // We choose the most inner span (shortest) containing character at the given index
    // if no such span can be found we will send the textview's react id as a touch handler
    // In case when there are more than one spans with same length we choose the last one
    // from the spans[] array, since it correspond to the most inner react element
    ReactTagSpan[] spans = text.getSpans(index, index, ReactTagSpan.class);

    if (spans != null) {
      int targetSpanTextLength = text.length();
      for (int i = 0; i < spans.length; i++) {
        int spanStart = text.getSpanStart(spans[i]);
        int spanEnd = text.getSpanEnd(spans[i]);
        if (spanEnd > index && (spanEnd - spanStart) <= targetSpanTextLength) {
          target = spans[i].getReactTag();
          targetSpanTextLength = (spanEnd - spanStart);
        }
      }
    }
  }

  return target;
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:45,代码来源:ReactTextView.java

示例12: onTouchEvent

import android.text.Layout; //导入方法依赖的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);
}
 
开发者ID:nichbar,项目名称:Aequorea,代码行数:64,代码来源:LongClickableLinkMovementMethod.java

示例13: onTouchEvent

import android.text.Layout; //导入方法依赖的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);
        }
 
开发者ID:HelloChenJinJun,项目名称:TestChat,代码行数:56,代码来源:CustomMoveMethod.java

示例14: onTouchEvent

import android.text.Layout; //导入方法依赖的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) {
                try {
                    link[0].onClick(widget);
                } catch (Exception e) {
                    e.printStackTrace();
                    ToastUtil.show(R.string.not_foud_qq);
                }
                if(((URLSpan) link[0]).getURL() != null){
                    if(DonateActivity.zhifubao.startsWith(((URLSpan) link[0]).getURL())){
                        UrlCountUtil.onEvent(UrlCountUtil.CLICK_SETTINGS_ABOUT_DONATE);
                    }else if(DonateActivity.qqJump.startsWith(((URLSpan) link[0]).getURL())){
                        UrlCountUtil.onEvent(UrlCountUtil.CLICK_SETTINGS_JOIN_QQ);
                    }
                }
            } else if (action == MotionEvent.ACTION_DOWN) {
                Selection.setSelection(buffer,
                        buffer.getSpanStart(link[0]),
                        buffer.getSpanEnd(link[0]));
            }

            return true;
        } else {
            Selection.removeSelection(buffer);
        }
    }

    return super.onTouchEvent(widget, buffer, event);
}
 
开发者ID:l465659833,项目名称:Bigbang,代码行数:52,代码来源:CountLinkMovementMethod.java

示例15: onTouch

import android.text.Layout; //导入方法依赖的package包/类
@Override
public boolean onTouch(View v, MotionEvent event) {
    int action = event.getAction();
    if(!(v instanceof TextView)){
        return false;
    }
    TextView textView  = (TextView) v;
    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 off = layout.getOffsetForHorizontal(line, x);

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

        if (link.length != 0) {
            if (action == MotionEvent.ACTION_UP) {
                link[0].onClick(textView);
            } else if (action == MotionEvent.ACTION_DOWN) {
                Selection.setSelection(spannable,
                        spannable.getSpanStart(link[0]),
                        spannable.getSpanEnd(link[0]));
            }

            return true;
        } else {
            Selection.removeSelection(spannable);
        }
    }

    return false;
}
 
开发者ID:Pingsh,项目名称:Mix,代码行数:42,代码来源:TouchTextView.java


注:本文中的android.text.Layout.getOffsetForHorizontal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。