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


Java Layout.getLineForVertical方法代码示例

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


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

示例1: 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

示例2: textTouchEvent

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

示例3: 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

示例4: 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

示例5: 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

示例6: onTouchEvent

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

示例7: 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) {
                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);
}
 
开发者ID:fengdongfei,项目名称:CXJPadProject,代码行数:41,代码来源:LinkMovementClickMethod.java

示例8: 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) {
                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);
}
 
开发者ID:RanKKI,项目名称:PSNine,代码行数:40,代码来源:LocalLinkMovementMethod.java

示例9: onTouchEvent

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

示例10: findOffsetForPosition

import android.text.Layout; //导入方法依赖的package包/类
private Option<Integer> findOffsetForPosition(float x, float y) {

        if (childView == null || childView.getLayout() == null) {
            return none();
        }

        Layout layout = this.childView.getLayout();
        int line = layout.getLineForVertical((int) y);

        return option(layout.getOffsetForHorizontal(line, x));
    }
 
开发者ID:ceji-longquan,项目名称:ceji_android,代码行数:12,代码来源:BookView.java

示例11: 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

示例12: 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

示例13: onTouchEvent

import android.text.Layout; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
    if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG, event);

    Layout layout = this.getLayout();

    if (layout != null) {
        int line = layout.getLineForVertical((int) event.getY() - getTotalPaddingTop());
        int offset = getOffsetForPosition(event.getX(), event.getY());

        if (isEventOnText(event, layout, line) && getText() != null && getText() instanceof Spanned) {
            Spanned spanned = (Spanned) getText();

            ClickableSpan[] links = spanned.getSpans(offset, offset, ClickableSpan.class);

            if (links.length > 0) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    return true;

                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                    links[0].onClick(this);

                } else {
                    return super.onTouchEvent(event);
                }
            }
        }
    }

    return super.onTouchEvent(event);
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:32,代码来源:TextViewWithLinks.java

示例14: 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

示例15: 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


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