Java Code Examples for android.widget.EditText#hasFocus()

The following examples show how to use android.widget.EditText#hasFocus() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractEditComponent.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: MatchTemplate.java    From BuildmLearn-Toolkit-Android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static boolean validated(Context context, EditText first_list_title, EditText second_list_title) {
    if (first_list_title == null || second_list_title == null) {
        return false;
    }

    String first_list_titleText = first_list_title.getText().toString().trim();
    String second_list_titleText = second_list_title.getText().toString().trim();

    if (first_list_titleText.equals("")) {
        first_list_title.hasFocus();
        first_list_title.setError(context.getString(R.string.match_first_list_title));
        return false;
    } else if (second_list_titleText.equals("")) {
        second_list_title.hasFocus();
        second_list_title.setError(context.getString(R.string.match_second_list_title));
        return false;
    } else if (second_list_titleText.equals(first_list_titleText)){
        Toast.makeText(context, "Two options cannot be same.", Toast.LENGTH_SHORT).show();
        return false;
    }

    return true;
}
 
Example 3
Source File: BaseActivity.java    From FuAgoraDemoDroid with MIT License 5 votes vote down vote up
public void openIME(final EditText v) {
    final boolean focus = v.requestFocus();
    if (v.hasFocus()) {
        final Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            @Override
            public void run() {
                InputMethodManager mgr = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                boolean result = mgr.showSoftInput(v, InputMethodManager.SHOW_FORCED);
                log.debug("openIME " + focus + " " + result);
            }
        });
    }
}
 
Example 4
Source File: EditTextSelectionState.java    From quill with MIT License 5 votes vote down vote up
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;
    }
}
 
Example 5
Source File: InputPanel.java    From NIM_Android_UIKit with MIT License 5 votes vote down vote up
/**
 * 显示发送或更多
 *
 * @param editText
 */
private void checkSendButtonEnable(EditText editText) {
    if (isRobotSession) {
        return;
    }
    String textMessage = editText.getText().toString();
    if (!TextUtils.isEmpty(StringUtil.removeBlanks(textMessage)) && editText.hasFocus()) {
        moreFuntionButtonInInputBar.setVisibility(View.GONE);
        sendMessageButtonInInputBar.setVisibility(View.VISIBLE);
    } else {
        sendMessageButtonInInputBar.setVisibility(View.GONE);
        moreFuntionButtonInInputBar.setVisibility(View.VISIBLE);
    }
}
 
Example 6
Source File: MatchTemplate.java    From BuildmLearn-Toolkit-Android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static boolean validated(Context context, EditText title, EditText first_list_title, EditText second_list_title) {
    if (title == null || first_list_title == null || second_list_title == null) {
        return false;
    }

    String titleText = title.getText().toString().trim();
    String first_list_titleText = first_list_title.getText().toString().trim();
    String second_list_titleText = second_list_title.getText().toString().trim();

    if ("".equals(titleText)) {
        title.hasFocus();
        title.setError(context.getString(R.string.match_main_title));
        return false;
    } else if ("".equals(first_list_titleText)) {
        first_list_title.hasFocus();
        first_list_title.setError(context.getString(R.string.match_first_list_title));
        return false;
    } else if ("".equals(second_list_titleText)) {
        second_list_title.hasFocus();
        second_list_title.setError(context.getString(R.string.match_second_list_title));
        return false;
    } else if (first_list_titleText.equalsIgnoreCase(second_list_titleText)){
        Toast.makeText(context, "Title of two lists cannot be same.", Toast.LENGTH_SHORT).show();
        return false;
    }

    return true;
}