use of android.text.Editable in project TypedPreferences by johnjohndoe.
the class MainActivity method onUserInputSubmit.
@OnClick(R.id.submit_user_input)
public void onUserInputSubmit() {
Editable userInput = userInputEditText.getText();
if (!TextUtils.isEmpty(userInput)) {
String text = userInput.toString();
storageValueTextView.setText(text);
}
}
use of android.text.Editable in project Android-CollapsibleSearchMenu by johnkil.
the class CollapsibleMenuUtils method addSearchMenuItem.
/**
* Adding collapsible search menu item to the menu.
*
* @param menu
* @param isLightTheme - true if use light them for ActionBar, else false
* @return menu item
*/
public static MenuItem addSearchMenuItem(Menu menu, boolean isLightTheme, final OnQueryTextListener onQueryChangeListener) {
final MenuItem menuItem = menu.add(Menu.NONE, R.id.collapsible_search_menu_item, Menu.NONE, R.string.search_go);
menuItem.setIcon(isLightTheme ? R.drawable.ic_action_search_holo_light : R.drawable.ic_action_search_holo_dark).setActionView(isLightTheme ? R.layout.search_view_holo_light : R.layout.search_view_holo_dark).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
final View searchView = menuItem.getActionView();
final AutoCompleteTextView editText = (AutoCompleteTextView) searchView.findViewById(R.id.search_src_text);
final TextWatcher textWatcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
onQueryChangeListener.onQueryTextChange(charSequence.toString());
}
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void afterTextChanged(Editable editable) {
}
};
final TextView.OnEditorActionListener onEditorActionListener = new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_SEARCH || keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
onQueryChangeListener.onQueryTextSubmit(textView.getText().toString());
return true;
}
return false;
}
};
menuItem.setOnActionExpandListener(new OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
editText.addTextChangedListener(textWatcher);
editText.setOnEditorActionListener(onEditorActionListener);
editText.requestFocus();
showKeyboard(editText);
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
editText.setText(null);
editText.removeTextChangedListener(textWatcher);
// editText.clearFocus();
hideKeyboard(editText);
return true;
}
});
final View searchPlate = searchView.findViewById(R.id.search_plate);
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, final boolean hasFocus) {
searchView.post(new Runnable() {
public void run() {
searchPlate.getBackground().setState(hasFocus ? new int[] { android.R.attr.state_focused } : new int[] { android.R.attr.state_empty });
searchView.invalidate();
}
});
}
});
final ImageView closeBtn = (ImageView) menuItem.getActionView().findViewById(R.id.search_close_btn);
closeBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!TextUtils.isEmpty(editText.getText())) {
editText.setText(null);
} else {
menuItem.collapseActionView();
}
}
});
return menuItem;
}
use of android.text.Editable in project ToolBarLib by jjhesk.
the class MaterialSearchView method initSearchView.
protected void initSearchView() {
mSearchSrcTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
onSubmitQuery();
return true;
}
});
mSearchSrcTextView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
mUserQuery = s;
startFilter(s);
MaterialSearchView.this.onTextChanged(s);
}
@Override
public void afterTextChanged(Editable s) {
}
});
mSearchSrcTextView.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
showKeyboard(mSearchSrcTextView);
showSuggestions();
}
}
});
}
use of android.text.Editable in project Jota-Text-Editor-old by jiro-aqua.
the class TextView method onCreateInputConnection.
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
if (onCheckIsTextEditor()) {
if (mInputMethodState == null) {
mInputMethodState = new InputMethodState();
}
outAttrs.inputType = mInputType;
if (mInputContentType != null) {
outAttrs.imeOptions = mInputContentType.imeOptions;
outAttrs.privateImeOptions = mInputContentType.privateImeOptions;
outAttrs.actionLabel = mInputContentType.imeActionLabel;
outAttrs.actionId = mInputContentType.imeActionId;
outAttrs.extras = mInputContentType.extras;
} else {
outAttrs.imeOptions = EditorInfo.IME_NULL;
}
if ((outAttrs.imeOptions & EditorInfo.IME_MASK_ACTION) == EditorInfo.IME_ACTION_UNSPECIFIED) {
if (focusSearch(FOCUS_DOWN) != null) {
// An action has not been set, but the enter key will move to
// the next focus, so set the action to that.
outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT;
} else {
// An action has not been set, and there is no focus to move
// to, so let's just supply a "done" action.
outAttrs.imeOptions |= EditorInfo.IME_ACTION_DONE;
}
if (!shouldAdvanceFocusOnEnter()) {
outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_ENTER_ACTION;
}
}
if ((outAttrs.inputType & (InputType.TYPE_MASK_CLASS | InputType.TYPE_TEXT_FLAG_MULTI_LINE)) == (InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE)) {
// Multi-line text editors should always show an enter key.
outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_ENTER_ACTION;
}
outAttrs.hintText = mHint;
if (mText instanceof Editable) {
InputConnection ic = new EditableInputConnection(this);
outAttrs.initialSelStart = getSelectionStart();
outAttrs.initialSelEnd = getSelectionEnd();
outAttrs.initialCapsMode = ic.getCursorCapsMode(mInputType);
// patch by matthias.gruenewald@googlemail.com
if (!mDontUseSoftkeyWithHardkey || getResources().getConfiguration().hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
InputMethodManager imm = InputMethodManager.peekInstance();
if (imm != null) {
imm.showSoftInput(this, 0);
}
}
return ic;
}
}
return null;
}
use of android.text.Editable in project Jota-Text-Editor-old by jiro-aqua.
the class TextView method onKeyUp.
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
// Jota Text Editor
// if (!isEnabled()) {
// return super.onKeyUp(keyCode, event);
// }
hideControllers();
stopTextSelectionMode();
switch(keyCode) {
case KeyEvent.KEYCODE_DPAD_CENTER:
/*
* If there is a click listener, just call through to
* super, which will invoke it.
*
* If there isn't a click listener, try to show the soft
* input method. (It will also
* call performClick(), but that won't do anything in
* this case.)
*/
if (mOnClickListener == null) {
if (mMovement != null && mText instanceof Editable && mLayout != null && onCheckIsTextEditor()) {
// patch by matthias.gruenewald@googlemail.com
if (!mDontUseSoftkeyWithHardkey || getResources().getConfiguration().hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(this, 0);
}
}
}
// Jota Text Editor
return false;
case KeyEvent.KEYCODE_ENTER:
// mEnterKeyIsDown = false;// Jota Text Editor
if (mInputContentType != null && mInputContentType.onEditorActionListener != null && mInputContentType.enterDown) {
mInputContentType.enterDown = false;
if (mInputContentType.onEditorActionListener.onEditorAction(this, EditorInfo.IME_NULL, event)) {
return true;
}
}
if ((event.getFlags() & KeyEvent.FLAG_EDITOR_ACTION) != 0 || shouldAdvanceFocusOnEnter()) {
/*
* If there is a click listener, just call through to
* super, which will invoke it.
*
* If there isn't a click listener, try to advance focus,
* but still call through to super, which will reset the
* pressed state and longpress state. (It will also
* call performClick(), but that won't do anything in
* this case.)
*/
if (mOnClickListener == null) {
View v = focusSearch(FOCUS_DOWN);
if (v != null) {
if (!v.requestFocus(FOCUS_DOWN)) {
throw new IllegalStateException("focus search returned a view " + "that wasn't able to take focus!");
}
// super.onKeyUp(keyCode, event);
return true;
} else if ((event.getFlags() & KeyEvent.FLAG_EDITOR_ACTION) != 0) {
// No target for next focus, but make sure the IME
// if this came from it.
InputMethodManager imm = InputMethodManager.peekInstance();
if (imm != null) {
imm.hideSoftInputFromWindow(getWindowToken(), 0);
}
}
}
// return super.onKeyUp(keyCode, event);
return false;
}
break;
}
if (mInput != null)
if (mInput.onKeyUp(this, (Editable) mText, keyCode, event))
return true;
if (mMovement != null && mLayout != null)
if (mMovement.onKeyUp(this, (Spannable) mText, keyCode, event))
return true;
return super.onKeyUp(keyCode, event);
}
Aggregations