當前位置: 首頁>>代碼示例>>Java>>正文


Java TextView.getTotalPaddingTop方法代碼示例

本文整理匯總了Java中android.widget.TextView.getTotalPaddingTop方法的典型用法代碼示例。如果您正苦於以下問題:Java TextView.getTotalPaddingTop方法的具體用法?Java TextView.getTotalPaddingTop怎麽用?Java TextView.getTotalPaddingTop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.widget.TextView的用法示例。


在下文中一共展示了TextView.getTotalPaddingTop方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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;
}
 
開發者ID:tranleduy2000,項目名稱:floating_calc,代碼行數:24,代碼來源:CalculatorEditText.java

示例2: onTouchEvent

import android.widget.TextView; //導入方法依賴的package包/類
@Override
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);

        ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
        if (link.length != 0) {
            link[0].onClick(widget);
            return true;
        } else {
            Selection.removeSelection(buffer);
        }
    }

    return super.onTouchEvent(widget, buffer, event);
}
 
開發者ID:alidili,項目名稱:Demos,代碼行數:29,代碼來源:TouchLinkMovementMethod.java

示例3: 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);
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:29,代碼來源:ArticleMovementMethod.java

示例4: getTouchedSpan

import android.widget.TextView; //導入方法依賴的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

示例5: getLineAtCoordinate

import android.widget.TextView; //導入方法依賴的package包/類
/**
 * method invoked from getOffsetForPosition() in order to get the line number on which the user long-pressed
 * @param textView2 fragment textView
 * @param y         y coordinate of the touch event
 * @return          line number
 */
private int getLineAtCoordinate(TextView textView2, float y) {
    y -= textView2.getTotalPaddingTop();
    y = Math.max(0.0f, y);
    y = Math.min(textView2.getHeight() - textView2.getTotalPaddingBottom() - 1, y);
    y += textView2.getScrollY();
    return textView2.getLayout().getLineForVertical((int) y);
}
 
開發者ID:Visions-Team,項目名稱:eBread,代碼行數:14,代碼來源:ShowDocumentFragment.java

示例6: 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);
}
 
開發者ID:Commit451,項目名稱:InternalLinkMovementMethod,代碼行數:38,代碼來源:InternalLinkMovementMethod.java

示例7: 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);
}
 
開發者ID:RanKKI,項目名稱:PSNine,代碼行數:40,代碼來源:LocalLinkMovementMethod.java

示例8: 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);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:39,代碼來源:LongClickableLinkMovementMethod.java

示例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);
}
 
開發者ID:fengdongfei,項目名稱:CXJPadProject,代碼行數:41,代碼來源:LinkMovementClickMethod.java

示例10: action

import android.widget.TextView; //導入方法依賴的package包/類
private boolean action(int what, TextView widget, Spannable buffer) {
    Layout layout = widget.getLayout();
    int padding = widget.getTotalPaddingTop() + widget.getTotalPaddingBottom();
    int areatop = widget.getScrollY();
    int areabot = (widget.getHeight() + areatop) - padding;
    int linetop = layout.getLineForVertical(areatop);
    int linebot = layout.getLineForVertical(areabot);
    int first = layout.getLineStart(linetop);
    int last = layout.getLineEnd(linebot);
    MyURLSpan[] candidates = (MyURLSpan[]) buffer.getSpans(first, last, MyURLSpan.class);
    int a = Selection.getSelectionStart(buffer);
    int b = Selection.getSelectionEnd(buffer);
    int selStart = Math.min(a, b);
    int selEnd = Math.max(a, b);
    if (selStart < 0 && buffer.getSpanStart(FROM_BELOW) >= 0) {
        selEnd = buffer.length();
        selStart = selEnd;
    }
    if (selStart > last) {
        selEnd = ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED;
        selStart = ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED;
    }
    if (selEnd < first) {
        selEnd = -1;
        selStart = -1;
    }
    int beststart;
    int bestend;
    int i;
    switch (what) {
        case 1:
            if (selStart != selEnd) {
                MyURLSpan[] link = (MyURLSpan[]) buffer.getSpans(selStart, selEnd, MyURLSpan
                        .class);
                if (link.length == 1) {
                    link[0].onClick(widget);
                    break;
                }
                return false;
            }
            return false;
        case 2:
            beststart = -1;
            bestend = -1;
            for (i = 0; i < candidates.length; i++) {
                int end = buffer.getSpanEnd(candidates[i]);
                if ((end < selEnd || selStart == selEnd) && end > bestend) {
                    beststart = buffer.getSpanStart(candidates[i]);
                    bestend = end;
                }
            }
            if (beststart >= 0) {
                Selection.setSelection(buffer, bestend, beststart);
                return true;
            }
            break;
        case 3:
            beststart = ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED;
            bestend = ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED;
            for (i = 0; i < candidates.length; i++) {
                int start = buffer.getSpanStart(candidates[i]);
                if ((start > selStart || selStart == selEnd) && start < beststart) {
                    beststart = start;
                    bestend = buffer.getSpanEnd(candidates[i]);
                }
            }
            if (bestend < Integer.MAX_VALUE) {
                Selection.setSelection(buffer, beststart, bestend);
                return true;
            }
            break;
    }
    return false;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:75,代碼來源:LongClickableLinkMovementMethod.java

示例11: 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(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);
}
 
開發者ID:wp521,項目名稱:MyFire,代碼行數:61,代碼來源:CircleMovementMethod.java

示例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);
}
 
開發者ID:hh-in-zhuzhou,項目名稱:ShangHanLun,代碼行數:46,代碼來源:LocalLinkMovementMethod.java

示例13: 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);
        }
 
開發者ID:HelloChenJinJun,項目名稱:TestChat,代碼行數:56,代碼來源:CustomMoveMethod.java

示例14: 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);
}
 
開發者ID:zuoweitan,項目名稱:Hitalk,代碼行數:59,代碼來源:BnMovementMethod.java

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

    LongClickCopySpan longClickCopySpan[] = buffer.getSpans(off, off, LongClickCopySpan.class);
    if (longClickCopySpan.length != 0) {
      LongClickCopySpan aSingleSpan = longClickCopySpan[0];
      if (action == MotionEvent.ACTION_DOWN) {
        Selection.setSelection(buffer, buffer.getSpanStart(aSingleSpan),
                buffer.getSpanEnd(aSingleSpan));
        aSingleSpan.setHighlighted(true,
                ContextCompat.getColor(widget.getContext(), R.color.touch_highlight));
      } else {
        Selection.removeSelection(buffer);
        aSingleSpan.setHighlighted(false, Color.TRANSPARENT);
      }

      this.currentSpan = aSingleSpan;
      this.widget = widget;
      return gestureDetector.onTouchEvent(event);
    }
  } else if (action == MotionEvent.ACTION_CANCEL) {
    // Remove Selections.
    LongClickCopySpan[] spans = buffer.getSpans(Selection.getSelectionStart(buffer),
            Selection.getSelectionEnd(buffer), LongClickCopySpan.class);
    for (LongClickCopySpan aSpan : spans) {
      aSpan.setHighlighted(false, Color.TRANSPARENT);
    }
    Selection.removeSelection(buffer);
    return gestureDetector.onTouchEvent(event);
  }
  return super.onTouchEvent(widget, buffer, event);
}
 
開發者ID:CableIM,項目名稱:Cable-Android,代碼行數:49,代碼來源:LongClickMovementMethod.java


注:本文中的android.widget.TextView.getTotalPaddingTop方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。