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


Java EditText.getSelectionStart方法代碼示例

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


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

示例1: input

import android.widget.EditText; //導入方法依賴的package包/類
public static void input(EditText editText, String emoji) {
    if (editText == null || TextUtils.isEmpty(emoji)) {
        return;
    }
    int start = editText.getSelectionStart();
    int end = editText.getSelectionEnd();
    if (start < 0) {
        editText.append(emoji);
    } else {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
            int length = getEditTextMaxLength(editText);
            if(length>0 && start+emoji.length() > length){
                return;
            }
        }
        editText.getText().replace(Math.min(start, end), Math.max(start, end), emoji, 0, emoji.length());
        if(editText.getText().length() < start+emoji.length()){
            editText.getText().delete(Math.min(start, end), editText.getText().length());
        }
    }
}
 
開發者ID:nickyangjun,項目名稱:EasyEmoji,代碼行數:22,代碼來源:EmojiUtil.java

示例2: onBackPress

import android.widget.EditText; //導入方法依賴的package包/類
private void onBackPress(EditText editText) {
    int selection = editText.getSelectionStart();
    if (selection == 0) {
        int viewIndex = allLayout.indexOfChild(editText);
        View v = allLayout.getChildAt(viewIndex - 1);

        if (v != null) {
            if (v instanceof EditText) {
                if ((int) v.getTag() != 1) {
                    String s1 = editText.getText().toString();
                    EditText q = (EditText) v;
                    String s2 = q.getText().toString();
                    allLayout.removeView(editText);
                    q.setText(s1 + s2);
                    q.requestFocus();
                    q.setSelection(s2.length(), s2.length());
                    lastEditText = q;
                }
            } else if (v instanceof ImageView) {
                allLayout.removeView(v);
            }

        }
    }

}
 
開發者ID:appteam-nith,項目名稱:Hillffair17,代碼行數:27,代碼來源:EditorView.java

示例3: getSelectionRange

import android.widget.EditText; //導入方法依賴的package包/類
@JSMethod
public void getSelectionRange(String callbackId) {
  EditText hostView;
  Map<String, Object> result = new HashMap<>(2);
  if ((hostView = getHostView()) != null) {
    int start = hostView.getSelectionStart();
    int end = hostView.getSelectionEnd();

    if (!hostView.hasFocus()) {
      //The default behavior, same as iOS and web
      start = 0;
      end = 0;
    }

    result.put(Constants.Name.SELECTION_START, start);
    result.put(Constants.Name.SELECTION_END, end);
  }
  WXBridgeManager.getInstance().callback(getInstanceId(), callbackId, result, false);
}
 
開發者ID:weexext,項目名稱:ucar-weex-core,代碼行數:20,代碼來源:AbstractEditComponent.java

示例4: getStatement

import android.widget.EditText; //導入方法依賴的package包/類
/**
 * " Search back from the cursor position till meeting '{' or ';'.
 * " '{' means statement start, ';' means end of a previous statement.
 *
 * @return statement before cursor
 * " Note: It's the base for parsing. And It's OK for most cases.
 */
@NonNull
private String getStatement(EditText editor) {
    String lineBeforeCursor = getCurrentLine(editor);
    if (lineBeforeCursor.matches("^\\s*(import|package)\\s+")) {
        return lineBeforeCursor;
    }
    int oldCursor = editor.getSelectionStart();
    int newCursor = oldCursor;
    while (true) {
        if (newCursor == 0) break;
        char c = editor.getText().charAt(newCursor);
        if (c == '{' || c == '}' || c == ';') {
            newCursor++;
            break;
        }
        newCursor--;
    }
    String statement = editor.getText().subSequence(newCursor, oldCursor).toString();
    return mergeLine(statement);
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:28,代碼來源:AutoCompleteProvider.java

示例5: input2OSC

import android.widget.EditText; //導入方法依賴的package包/類
public static void input2OSC(EditText editText, Emojicon emojicon) {
    if (editText == null || emojicon == null) {
        return;
    }
    int start = editText.getSelectionStart();
    int end = editText.getSelectionEnd();
    if (start < 0) {
        // 沒有多選時,直接在當前光標處添加
        editText.append(emojicon.getRemote());
    } else {
        // 將已選中的部分替換為表情(當長按文字時會多選刷中很多文字)
        String str = emojicon.getRemote();
        editText.getText().replace(Math.min(start, end),
                Math.max(start, end), str, 0, str.length());
    }
}
 
開發者ID:fengdongfei,項目名稱:CXJPadProject,代碼行數:17,代碼來源:InputHelper.java

示例6: addCode

import android.widget.EditText; //導入方法依賴的package包/類
public static void addCode(@NonNull EditText editText) {
    try {
        String source = editText.getText().toString();
        int selectionStart = editText.getSelectionStart();
        int selectionEnd = editText.getSelectionEnd();
        String substring = source.substring(selectionStart, selectionEnd);
        String result;
        if (hasNewLine(source, selectionStart))
            result = "```\n" + substring + "\n```\n";
        else
            result = "\n```\n" + substring + "\n```\n";

        editText.getText().replace(selectionStart, selectionEnd, result);
        editText.setSelection(result.length() + selectionStart - 5);

    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:duyp,項目名稱:mvvm-template,代碼行數:20,代碼來源:MarkDownProvider.java

示例7: input2OSC

import android.widget.EditText; //導入方法依賴的package包/類
/**
 * 輸入Emoji表情到 EditText
 *
 * @param editText EditText
 * @param emojicon Emojicon
 */
public static void input2OSC(EditText editText, Emojicon emojicon) {
    if (editText == null || emojicon == null) {
        return;
    }
    int start = editText.getSelectionStart();
    int end = editText.getSelectionEnd();
    if (start < 0) {
        // 沒有多選時,直接在當前光標處添加
        editText.append(displayEmoji(editText.getResources(),
                emojicon.getRemote(), (int) editText.getTextSize()));
    } else {
        // 將已選中的部分替換為表情(當長按文字時會多選刷中很多文字)
        Spannable str = displayEmoji(editText.getResources(),
                emojicon.getRemote(), (int) editText.getTextSize());
        editText.getText().replace(Math.min(start, end),
                Math.max(start, end), str, 0, str.length());
    }
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:25,代碼來源:InputHelper.java

示例8: addQuote

import android.widget.EditText; //導入方法依賴的package包/類
public static void addQuote(@NonNull EditText editText) {
    String source = editText.getText().toString();
    int selectionStart = editText.getSelectionStart();
    int selectionEnd = editText.getSelectionEnd();
    String substring = source.substring(selectionStart, selectionEnd);
    String result;
    if (hasNewLine(source, selectionStart)) {
        result = "> " + substring;
    } else {
        result = "\n> " + substring;

    }
    editText.getText().replace(selectionStart, selectionEnd, result);
    editText.setSelection(result.length() + selectionStart);

}
 
開發者ID:duyp,項目名稱:mvvm-template,代碼行數:17,代碼來源:MarkDownProvider.java

示例9: getCommonEmoticonClickListener

import android.widget.EditText; //導入方法依賴的package包/類
public static EmoticonClickListener getCommonEmoticonClickListener(final EditText editText) {
        return new EmoticonClickListener() {
            @Override
            public void onEmoticonClick(Object o, int actionType, boolean isDelBtn) {
                if (isDelBtn) {
                    PublishUtils.delClick(editText);
                } else {
                    if (o == null) {
                        return;
                    }
                    if (actionType == Constants.EMOTICON_CLICK_TEXT) {
                        String content = null;
//                        if (o instanceof EmojiBean) {
//                            content = ((EmojiBean) o).emoji;
//                        } else
                        if (o instanceof EmoticonEntity) {
                            content = ((EmoticonEntity) o).getContent();
                        }

                        if (TextUtils.isEmpty(content)) {
                            return;
                        }
                        int index = editText.getSelectionStart();
                        Editable editable = editText.getText();
                        editable.insert(index, content);
                    }
                }
            }
        };
    }
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:31,代碼來源:PublishUtils.java

示例10: EditTextSelectionState

import android.widget.EditText; //導入方法依賴的package包/類
public EditTextSelectionState(@NonNull EditText editText) {
    mEditText = editText;
    mFocused = editText.hasFocus();
    int selectionStart = editText.getSelectionStart();
    int selectionEnd = editText.getSelectionEnd();
    if (selectionStart > selectionEnd && selectionStart != -1 && selectionEnd != -1) {
        mSelectionStart = selectionEnd;
        mSelectionEnd = selectionStart;
    } else {
        mSelectionStart = selectionStart;
        mSelectionEnd = selectionEnd;
    }
}
 
開發者ID:TryGhost,項目名稱:Ghost-Android,代碼行數:14,代碼來源:EditTextSelectionState.java

示例11: replaceBodySelectionTextTo

import android.widget.EditText; //導入方法依賴的package包/類
@Override
public void replaceBodySelectionTextTo(String replyText) {
    if (nonNull(mInputController)) {
        EditText edit = mInputController.getInputField();

        int selectionStart = edit.getSelectionStart();
        int selectionEnd = edit.getSelectionEnd();
        edit.getText().replace(selectionStart, selectionEnd, replyText);
    }
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:11,代碼來源:CommentsFragment.java

示例12: input

import android.widget.EditText; //導入方法依賴的package包/類
public static void input(EditText editText, Emojicon emojicon) {
    if (editText == null || emojicon == null) {
        return;
    }

    int start = editText.getSelectionStart();
    int end = editText.getSelectionEnd();
    if (start < 0) {
        editText.append(emojicon.getEmoji());
    } else {
        editText.getText().replace(Math.min(start, end), Math.max(start, end), emojicon.getEmoji(), 0, emojicon.getEmoji().length());
    }
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:14,代碼來源:EmojiconsPopup.java

示例13: insertChip

import android.widget.EditText; //導入方法依賴的package包/類
private void insertChip(int type) {
    EditText editText = mTextFormatBar.getEditText();
    int sStart = editText.getSelectionStart();
    int sEnd = editText.getSelectionEnd();
    SpannableString ss = new SpannableString(" ");
    ss.setSpan(new MessageBuilder.MetaChipSpan(this, type), 0, 1, MessageBuilder.FORMAT_SPAN_FLAGS);
    editText.getText().replace(sStart, sEnd, ss);
    refreshExamples();
}
 
開發者ID:MCMrARM,項目名稱:revolution-irc,代碼行數:10,代碼來源:MessageFormatSettingsActivity.java

示例14: insert2Input

import android.widget.EditText; //導入方法依賴的package包/類
void insert2Input(String strToInsert)	{
	EditText txtInput = (EditText)findViewById(R.id.edtSmartMathInput);
	int nSelectionStart = txtInput.getSelectionStart();
	int nSelectionEnd = txtInput.getSelectionEnd();
	if (nSelectionStart < 0 || nSelectionEnd < 0
			|| nSelectionStart > txtInput.getText().length()
			|| nSelectionEnd > txtInput.getText().length()
			|| nSelectionStart > nSelectionEnd)	{	// invalid selection
		txtInput.setText(strToInsert);
		txtInput.setSelection(txtInput.getText().length());
	} else	{	// valid selection, insert the text
		txtInput.getText().replace(nSelectionStart, nSelectionEnd, strToInsert);
		txtInput.setSelection(nSelectionStart + strToInsert.length());
	}
}
 
開發者ID:woshiwpa,項目名稱:SmartMath,代碼行數:16,代碼來源:ActivitySmartCalc.java

示例15: addItalic

import android.widget.EditText; //導入方法依賴的package包/類
public static void addItalic(@NonNull EditText editText) {
    String source = editText.getText().toString();
    int selectionStart = editText.getSelectionStart();
    int selectionEnd = editText.getSelectionEnd();
    String substring = source.substring(selectionStart, selectionEnd);
    String result = "_" + substring + "_ ";
    editText.getText().replace(selectionStart, selectionEnd, result);
    editText.setSelection(result.length() + selectionStart - 2);

}
 
開發者ID:duyp,項目名稱:mvvm-template,代碼行數:11,代碼來源:MarkDownProvider.java


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