android.text.Selection.getSelectionStart()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(249)

本文整理了Java中android.text.Selection.getSelectionStart()方法的一些代码示例,展示了Selection.getSelectionStart()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Selection.getSelectionStart()方法的具体详情如下:
包路径:android.text.Selection
类名称:Selection
方法名:getSelectionStart

Selection.getSelectionStart介绍

暂无

代码示例

代码示例来源:origin: seven332/EhViewer

int a = Selection.getSelectionStart(buffer);
int b = Selection.getSelectionEnd(buffer);

代码示例来源:origin: MichaelRocks/CallMeMaybe

public int getSelection() {
 return Selection.getSelectionStart(buffer);
}

代码示例来源:origin: baiyuliang/QRobot

/**
 * 向输入框里添加表情
 * */
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);
}

代码示例来源:origin: linkedin/Spyglass

/**
 * {@inheritDoc}
 */
@Override
public void onTextChanged(CharSequence text, int start, int before, int count) {
  if (mBlockCompletion || !(text instanceof Editable) || getTokenizer() == null) {
    return;
  }
  // If the editor tries to insert duplicated text, mark the duplicated text for deletion later
  Editable editable = (Editable) text;
  int index = Selection.getSelectionStart(editable);
  Tokenizer tokenizer = getTokenizer();
  if (tokenizer != null) {
    markDuplicatedTextForDeletionLater((Editable) text, index, tokenizer);
  }
  // Call any watchers for text changes
  sendOnTextChanged(text, start, before, count);
}

代码示例来源:origin: baiyuliang/QRobot

/**
 * 删除图标执行事件
 * 注:如果删除的是表情,在删除时实际删除的是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);
      }
    }
  }
}

代码示例来源:origin: geniusgithub/AndroidDialer

public void hideSoftKey() {
  if (DBG) {
    Log.d(LOG_TAG, "--- hidesoftkey");
  }
  if (!mEST.isFocused()) {
    return;
  }
  mSkr.mNewStart = Selection.getSelectionStart(mEST.getText());
  mSkr.mNewEnd = Selection.getSelectionEnd(mEST.getText());
  InputMethodManager imm =
      (InputMethodManager) mEST.getContext().getSystemService(
          Context.INPUT_METHOD_SERVICE);
  imm.hideSoftInputFromWindow(mEST.getWindowToken(), 0, mSkr);
}

代码示例来源:origin: MichaelRocks/CallMeMaybe

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());
  }
 }
}

代码示例来源:origin: MichaelRocks/CallMeMaybe

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);
}

代码示例来源:origin: sunhapper/SpEditTool

@Override
public boolean onKeyEvent(KeyEvent keyEvent, Spannable text) {
  if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_DEL && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
    int selectionStart = Selection.getSelectionStart(text);
    int selectionEnd = Selection.getSelectionEnd(text);
    MarkSpan[] markSpans = text.getSpans(selectionStart, selectionEnd, MarkSpan.class);
    if (markSpans != null && markSpans.length > 0) {
      MarkSpan span = markSpans[0];
      int spanStart = text.getSpanStart(span);
      int spanEnd = text.getSpanEnd(span);
      if (spanEnd == selectionStart) {
        Selection.setSelection(text, spanStart, spanEnd);
        if (needSelectionFlag()) {
          return selectionEnd == selectionStart;
        }
      }
    }
  }
  return false;
}

代码示例来源:origin: geniusgithub/AndroidDialer

public void showSoftKey(int oldSelStart, int oldSelEnd) {
  if (DBG) {
    Log.d(LOG_TAG, "--- showsoftkey");
  }
  if (!mEST.isFocused() || isSoftKeyBlocked()) {
    return;
  }
  mSkr.mNewStart = Selection.getSelectionStart(mEST.getText());
  mSkr.mNewEnd = Selection.getSelectionEnd(mEST.getText());
  InputMethodManager imm =
      (InputMethodManager) getContext().getSystemService(
          Context.INPUT_METHOD_SERVICE);
  if (imm.showSoftInput(mEST, 0, mSkr) && mSkr != null) {
    Selection.setSelection(getText(), oldSelStart, oldSelEnd);
  }
}

代码示例来源:origin: sunhapper/SpEditTool

@Override
  public void onSpanChanged(Spannable text, Object what, int ostart, int oend, int nstart, int nend) {
    if (what == Selection.SELECTION_END && oend != nstart) {
      IntegratedSpan[] spans = text.getSpans(nstart, nend, IntegratedSpan.class);
      if (spans != null && spans.length > 0) {
        IntegratedSpan integratedSpan = spans[0];
        int spanStart = text.getSpanStart(integratedSpan);
        int spanEnd = text.getSpanEnd(integratedSpan);
        int index = (Math.abs(nstart - spanEnd) > Math.abs(nstart - spanStart)) ? spanStart : spanEnd;
        Selection.setSelection(text, Selection.getSelectionStart(text), index);
      }
    }
    if (what == Selection.SELECTION_START && oend != nstart) {
      IntegratedSpan[] spans = text.getSpans(nstart, nend, IntegratedSpan.class);
      if (spans != null && spans.length > 0) {
        IntegratedSpan integratedSpan = spans[0];
        int spanStart = text.getSpanStart(integratedSpan);
        int spanEnd = text.getSpanEnd(integratedSpan);
        int index = (Math.abs(nstart - spanEnd) > Math.abs(nstart - spanStart)) ? spanStart : spanEnd;
        Selection.setSelection(text, index, Selection.getSelectionEnd(text));
      }
    }
    if (what instanceof BreakableSpan && ((BreakableSpan) what).isBreak()) {
      text.removeSpan(what);
    }
  }
}

代码示例来源:origin: PaXLiCh/FormattEditText

value.setSpan(selection, Selection.getSelectionStart(value), Selection.getSelectionEnd(value), Spanned.SPAN_MARK_MARK);

代码示例来源:origin: derry/delion

if (currentText == null) return super.commitText(text, newCursorPosition);
int selectionStart = Selection.getSelectionStart(currentText);
int selectionEnd = Selection.getSelectionEnd(currentText);
int autocompleteIndex = currentText.getSpanStart(mAutocompleteSpan);

代码示例来源:origin: geniusgithub/AndroidDialer

onStartEdit();
int oldSelStart = Selection.getSelectionStart(getText());
int oldSelEnd = Selection.getSelectionEnd(getText());
superResult = super.onTouchEvent(event);
      mManager.showSoftKey(Selection.getSelectionStart(getText()),
          Selection.getSelectionEnd(getText()));
    } else {

代码示例来源:origin: andforce/iBeebo

int a = Selection.getSelectionStart(buffer);
int b = Selection.getSelectionEnd(buffer);

代码示例来源:origin: zhe525069676/WeiBoLayout

int a = Selection.getSelectionStart(buffer);
int b = Selection.getSelectionEnd(buffer);

代码示例来源:origin: wordpress-mobile/WordPress-Editor-Android

@Override
public void afterTextChanged(Editable s) {
  int position = Selection.getSelectionStart(mContentEditText.getText());
  if ((mIsBackspace && position != 1) || mLastPosition == position || !mIsLocalDraft)
    return;

相关文章