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


Java Selection.getSelectionStart方法代码示例

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


在下文中一共展示了Selection.getSelectionStart方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: format

import android.text.Selection; //导入方法依赖的package包/类
public void format(final Editable to, final int toStart, final int toEnd, final CharSequence from,
    final int fromStart, final int fromEnd) {
  final int selectionStart = Selection.getSelectionStart(to);
  final int selectionEnd = Selection.getSelectionStart(to);

  buffer.clear();
  buffer.append(to);
  if (selectionStart != -1 && selectionEnd != -1) {
    Selection.setSelection(buffer, selectionStart, selectionEnd);
  }
  buffer.replace(toStart, toEnd, from, fromStart, fromEnd);

  if (!TextUtils.isGraphic(buffer)) {
    return;
  }

  formatPhoneNumberInput(buffer);
}
 
开发者ID:MichaelRocks,项目名称:CallMeMaybe,代码行数:19,代码来源:PhoneFormatter.java

示例3: formatPhoneNumberInput

import android.text.Selection; //导入方法依赖的package包/类
private void formatPhoneNumberInput(final Editable input) {
  final int selection = Selection.getSelectionStart(buffer);
  boolean selectionPositionRemembered = false;

  asYouTypeFormatter.clear();
  String phoneNumberText = "";

  int offset = 0;
  final int length = input.length();
  while (offset < length) {
    final int codePoint = Character.codePointAt(input, offset);
    if (Character.isDigit(codePoint)) {
      final char digit = CodePoint.toDigitChar(codePoint);
      selectionPositionRemembered = selectionPositionRemembered || offset >= selection;
      phoneNumberText = asYouTypeFormatter.inputDigit(digit, !selectionPositionRemembered);
    }
    offset += Character.charCount(codePoint);
  }

  input.replace(0, input.length(), phoneNumberText);
  if (selection != -1) {
    Selection.setSelection(input,
        selectionPositionRemembered ? asYouTypeFormatter.getRememberedPosition() : phoneNumberText.length());
  }
}
 
开发者ID:MichaelRocks,项目名称:CallMeMaybe,代码行数:26,代码来源:PhoneFormatter.java

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

示例5: getCurrentCursorLine

import android.text.Selection; //导入方法依赖的package包/类
/**
 * Get current cursor line
 */
public int getCurrentCursorLine(Editable editable) {
    int selectionStartPos = Selection.getSelectionStart(editable);

    // no selection
    if (selectionStartPos < 0) return -1;

    String preSelectionStartText = editable.toString().substring(0, selectionStartPos);
    return StringUtils.countMatches(preSelectionStartText, "\n");
}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:13,代码来源:EditorFragment.java

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

示例7: getSelectionStart

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

            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

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

示例10: getSelection

import android.text.Selection; //导入方法依赖的package包/类
public int getSelection() {
  return Selection.getSelectionStart(buffer);
}
 
开发者ID:MichaelRocks,项目名称:CallMeMaybe,代码行数:4,代码来源:PhoneFormatter.java

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