KeyboardEditText.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by TheFinestArtist on 9/24/15. | |
*/ | |
public class KeyboardEditText extends EditText { | |
public KeyboardEditText(Context context) { | |
super(context); | |
} | |
public KeyboardEditText(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
public KeyboardEditText(Context context, AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
} | |
@Override | |
public void setOnTouchListener(OnTouchListener l) { | |
super.setOnTouchListener(l); | |
} | |
@Override | |
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { | |
super.onFocusChanged(focused, direction, previouslyFocusedRect); | |
if (listener != null) | |
listener.onStateChanged(this, true); | |
} | |
@Override | |
public boolean onKeyPreIme(int keyCode, @NonNull KeyEvent event) { | |
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK | |
&& event.getAction() == KeyEvent.ACTION_UP) { | |
if (listener != null) | |
listener.onStateChanged(this, false); | |
// Hide cursor | |
setFocusable(false); | |
// Set EditText to be focusable again | |
setFocusable(true); | |
setFocusableInTouchMode(true); | |
} | |
return super.onKeyPreIme(keyCode, event); | |
} | |
/** | |
* Keyboard Listener | |
*/ | |
KeyboardListener listener; | |
public void setOnKeyboardListener(KeyboardListener listener) { | |
this.listener = listener; | |
} | |
public interface KeyboardListener { | |
void onStateChanged(KeyboardEditText keyboardEditText, boolean showing); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment