当前位置: 首页>>代码示例>>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;未经允许,请勿转载。