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


Java Selection.getSelectionEnd方法代码示例

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


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

示例1: onBeforeNotifyDataSetChanged

import android.text.Selection; //导入方法依赖的package包/类
public void onBeforeNotifyDataSetChanged() {
	if (SUPPORTED) {
		HANDLER.removeMessages(MESSAGE_SEND_RESET);
		HANDLER.removeMessages(MESSAGE_RESET);
		HANDLER.removeMessages(MESSAGE_START_SELECTION);
		if (selectionActionMode != null) {
			final CharSequence text = selectionTextView.getText();
			futureSelectionIdentifier = selectionIdentifier;
			futureSelectionStart = Selection.getSelectionStart(text);
			futureSelectionEnd = Selection.getSelectionEnd(text);
			selectionActionMode.finish();
			selectionActionMode = null;
			selectionIdentifier = null;
			selectionTextView = null;
		}
	}
}
 
开发者ID:syntafin,项目名称:TenguChat,代码行数:18,代码来源:ListSelectionManager.java

示例2: onTextChanged

import android.text.Selection; //导入方法依赖的package包/类
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
    Editable editable = editText.getText();
    int len = editable.length();
    int maxLen = maxLeng;
    if (len > maxLen) {
        int selEndIndex = Selection.getSelectionEnd(editable);
        String str = editable.toString();
        String newStr = str.substring(0, maxLen);
        editText.setText(newStr);
        editable = editText.getText();
        int newLen = editable.length();
        if (selEndIndex > newLen) {
            selEndIndex = editable.length();
        }
        Selection.setSelection(editable, selEndIndex);
    } else if (len == maxLen) {
        btn.setClickable(true);
        btn.setTextColor(Color.BLACK);
    } else if (len < maxLen) {
        btn.setClickable(false);
        btn.setTextColor(Color.GRAY);

    }
}
 
开发者ID:Qrilee,项目名称:DevAsimpleApp,代码行数:26,代码来源:PhoneNumWatcher.java

示例3: delete

import android.text.Selection; //导入方法依赖的package包/类
/**
 * 删除图标执行事件
 * 注:如果删除的是表情,在删除时实际删除的是tempText即图片占位的字符串,所以必需一次性删除掉tempText,才能将图片删除
 * */
public static void delete(EditText input) {
	if (input.getText().length() != 0) {
		int iCursorEnd = Selection.getSelectionEnd(input.getText());
		int iCursorStart = Selection.getSelectionStart(input.getText());
		if (iCursorEnd > 0) {
			if (iCursorEnd == iCursorStart) {
				if (isDeletePng(input,iCursorEnd)) {
					String st = "[p/_000.png]";
					((Editable) input.getText()).delete(
							iCursorEnd - st.length(), iCursorEnd);
				} else {
					((Editable) input.getText()).delete(iCursorEnd - 1,
							iCursorEnd);
				}
			} else {
				((Editable) input.getText()).delete(iCursorStart,
						iCursorEnd);
			}
		}
	}
}
 
开发者ID:cowthan,项目名称:AyoSunny,代码行数:26,代码来源:ExpressionUtil.java

示例4: insert

import android.text.Selection; //导入方法依赖的package包/类
/**
 * 向输入框里添加表情
 * */
public static void insert(EditText input,CharSequence text) {
	int iCursorStart = Selection.getSelectionStart((input.getText()));
	int iCursorEnd = Selection.getSelectionEnd((input.getText()));
	if (iCursorStart != iCursorEnd) {
		((Editable) input.getText()).replace(iCursorStart, iCursorEnd, "");
	}
	int iCursor = Selection.getSelectionEnd((input.getText()));
	((Editable) input.getText()).insert(iCursor, text);
}
 
开发者ID:cowthan,项目名称:AyoSunny,代码行数:13,代码来源:ExpressionUtil.java

示例5: getSelectionEnd

import android.text.Selection; //导入方法依赖的package包/类
public int getSelectionEnd() {
    // returns -1 if no selection
    return Selection.getSelectionEnd(mTextStorage);
}
 
开发者ID:suragch,项目名称:mongol-library,代码行数:5,代码来源:MongolTextView.java

示例6: commitText

import android.text.Selection; //导入方法依赖的package包/类
@Override
public boolean commitText(CharSequence text, int newCursorPosition) {
    Editable currentText = getText();
    if (currentText == null) return super.commitText(text, newCursorPosition);

    int selectionStart = Selection.getSelectionStart(currentText);
    int selectionEnd = Selection.getSelectionEnd(currentText);
    int autocompleteIndex = currentText.getSpanStart(mAutocompleteSpan);
    // If the text being committed is a single character that matches the next character
    // in the selection (assumed to be the autocomplete text), we only move the text
    // selection instead clearing the autocomplete text causing flickering as the
    // autocomplete text will appear once the next suggestions are received.
    //
    // To be confident that the selection is an autocomplete, we ensure the selection
    // is at least one character and the end of the selection is the end of the
    // currently entered text.
    if (newCursorPosition == 1 && selectionStart > 0 && selectionStart != selectionEnd
            && selectionEnd >= currentText.length()
            && autocompleteIndex == selectionStart
            && text.length() == 1) {
        currentText.getChars(selectionStart, selectionStart + 1, mTempSelectionChar, 0);
        if (mTempSelectionChar[0] == text.charAt(0)) {

            // Since the text isn't changing, TalkBack won't read out the typed characters.
            // To work around this, explicitly send an accessibility event. crbug.com/416595
            if (mAccessibilityManager != null && mAccessibilityManager.isEnabled()) {
                AccessibilityEvent event = AccessibilityEvent.obtain(
                        AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED);
                event.setFromIndex(selectionStart);
                event.setRemovedCount(0);
                event.setAddedCount(1);
                event.setBeforeText(currentText.toString().substring(0, selectionStart));
                sendAccessibilityEventUnchecked(event);
            }

            setAutocompleteText(
                    currentText.subSequence(0, selectionStart + 1),
                    currentText.subSequence(selectionStart + 1, selectionEnd));
            if (!mInBatchEditMode) {
                notifyAutocompleteTextStateChanged(false);
            }
            return true;
        }
    }

    boolean retVal = super.commitText(text, newCursorPosition);

    // Ensure the autocomplete span is removed if it is no longer valid after committing the
    // text.
    if (getText().getSpanStart(mAutocompleteSpan) >= 0) clearAutocompleteSpanIfInvalid();

    return retVal;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:54,代码来源:UrlBar.java

示例7: action

import android.text.Selection; //导入方法依赖的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

示例8: commitText

import android.text.Selection; //导入方法依赖的package包/类
@Override
public boolean commitText(CharSequence text, int newCursorPosition) {
    Editable currentText = getText();
    if (currentText == null) return super.commitText(text, newCursorPosition);

    int selectionStart = Selection.getSelectionStart(currentText);
    int selectionEnd = Selection.getSelectionEnd(currentText);
    int autocompleteIndex = currentText.getSpanStart(mAutocompleteSpan);
    // If the text being committed is a single character that matches the next character
    // in the selection (assumed to be the autocomplete text), we only move the text
    // selection instead clearing the autocomplete text causing flickering as the
    // autocomplete text will appear once the next suggestions are received.
    //
    // To be confident that the selection is an autocomplete, we ensure the selection
    // is at least one character and the end of the selection is the end of the
    // currently entered text.
    if (newCursorPosition == 1 && selectionStart > 0 && selectionStart != selectionEnd
            && selectionEnd >= currentText.length()
            && autocompleteIndex == selectionStart
            && text.length() == 1) {
        currentText.getChars(selectionStart, selectionStart + 1, mTempSelectionChar, 0);
        if (mTempSelectionChar[0] == text.charAt(0)) {

            // Since the text isn't changing, TalkBack won't read out the typed characters.
            // To work around this, explicitly send an accessibility event. crbug.com/416595
            if (mAccessibilityManager != null && mAccessibilityManager.isEnabled()) {
                AccessibilityEvent event = AccessibilityEvent.obtain(
                        AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED);
                event.setFromIndex(selectionStart);
                event.setRemovedCount(0);
                event.setAddedCount(1);
                event.setBeforeText(currentText.toString().substring(0, selectionStart));
                sendAccessibilityEventUnchecked(event);
            }

            if (mLocationBarTextWatcher != null) {
                mLocationBarTextWatcher.beforeTextChanged(currentText, 0, 0, 0);
            }
            setAutocompleteText(
                    currentText.subSequence(0, selectionStart + 1),
                    currentText.subSequence(selectionStart + 1, selectionEnd));
            if (mLocationBarTextWatcher != null) {
                mLocationBarTextWatcher.afterTextChanged(currentText);
            }
            return true;
        }
    }
    return super.commitText(text, newCursorPosition);
}
 
开发者ID:Smalinuxer,项目名称:Vafrinn,代码行数:50,代码来源:UrlBar.java


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