當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。