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


Java EditText.getSelectionEnd方法代碼示例

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


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

示例1: insertAtCursor

import android.widget.EditText; //導入方法依賴的package包/類
public static void insertAtCursor(@NonNull EditText editText, @NonNull String text) {
    String oriContent = editText.getText().toString();
    int start = editText.getSelectionStart();
    int end = editText.getSelectionEnd();
    Logger.e(start, end);
    if (start >= 0 && end > 0 && start != end) {
        editText.setText(editText.getText().replace(start, end, text));
    } else {
        int index = editText.getSelectionStart() >= 0 ? editText.getSelectionStart() : 0;
        Logger.e(start, end, index);
        StringBuilder builder = new StringBuilder(oriContent);
        builder.insert(index, text);
        editText.setText(builder.toString());
        editText.setSelection(index + text.length());
    }
}
 
開發者ID:duyp,項目名稱:mvvm-template,代碼行數:17,代碼來源:MarkDownProvider.java

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

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

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

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

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

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

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

示例11: findChar

import android.widget.EditText; //導入方法依賴的package包/類
private int findChar(EditText editor, String s) {
    int selectionEnd = editor.getSelectionEnd();
    while (selectionEnd > -1 && editor.getText().charAt(selectionEnd) != s.charAt(0)) {
        selectionEnd--;
    }
    return selectionEnd;
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:8,代碼來源:AutoCompleteProvider.java

示例12: addList

import android.widget.EditText; //導入方法依賴的package包/類
public static void addList(@NonNull EditText editText, @NonNull String list) {
    String tag = list + " ";
    String source = editText.getText().toString();
    int selectionStart = editText.getSelectionStart();
    int selectionEnd = editText.getSelectionEnd();
    String substring = source.substring(0, selectionStart);
    int line = substring.lastIndexOf(10);
    if (line != -1) {
        selectionStart = line + 1;
    } else {
        selectionStart = 0;
    }
    substring = source.substring(selectionStart, selectionEnd);
    String[] split = substring.split("\n");
    StringBuilder stringBuffer = new StringBuilder();
    if (split.length > 0)
        for (String s : split) {
            if (s.length() == 0 && stringBuffer.length() != 0) {
                stringBuffer.append("\n");
                continue;
            }
            if (!s.trim().startsWith(tag)) {
                if (stringBuffer.length() > 0) stringBuffer.append("\n");
                stringBuffer.append(tag).append(s);
            } else {
                if (stringBuffer.length() > 0) stringBuffer.append("\n");
                stringBuffer.append(s);
            }
        }

    if (stringBuffer.length() == 0) {
        stringBuffer.append(tag);
    }
    editText.getText().replace(selectionStart, selectionEnd, stringBuffer.toString());
    editText.setSelection(stringBuffer.length() + selectionStart);
}
 
開發者ID:duyp,項目名稱:mvvm-template,代碼行數:37,代碼來源:MarkDownProvider.java

示例13: addHeader

import android.widget.EditText; //導入方法依賴的package包/類
public static void addHeader(@NonNull EditText editText, int level) {
    String source = editText.getText().toString();
    int selectionStart = editText.getSelectionStart();
    int selectionEnd = editText.getSelectionEnd();
    StringBuilder result = new StringBuilder();
    String substring = source.substring(selectionStart, selectionEnd);
    if (!hasNewLine(source, selectionStart))
        result.append("\n");
    IntStream.range(0, level).forEach(integer -> result.append("#"));
    result.append(" ").append(substring);
    editText.getText().replace(selectionStart, selectionEnd, result.toString());
    editText.setSelection(selectionStart + result.length());

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

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

示例15: addBold

import android.widget.EditText; //導入方法依賴的package包/類
public static void addBold(@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 - 3);

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


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