Focus grabber given focus correctly now

This commit is contained in:
Phillip Hsu 2016-07-16 13:59:54 -07:00
parent 0a7c007da4
commit d4de3b507f
3 changed files with 38 additions and 3 deletions

View File

@ -78,7 +78,16 @@ public abstract class GridLayoutNumpad extends GridLayout implements View.OnClic
mOnInputChangeListener = onInputChangeListener; mOnInputChangeListener = onInputChangeListener;
} }
protected final void enable(int lowerLimitInclusive, int upperLimitExclusive) { /**
* Provided only for subclasses so they can retrieve the registered listener
* and fire any custom OnInputChange events they may have defined.
*/
protected final OnInputChangeListener getOnInputChangeListener() {
return mOnInputChangeListener;
}
@CallSuper
protected void enable(int lowerLimitInclusive, int upperLimitExclusive) {
if (lowerLimitInclusive < 0 || upperLimitExclusive > mButtons.length) if (lowerLimitInclusive < 0 || upperLimitExclusive > mButtons.length)
throw new IndexOutOfBoundsException("Upper limit out of range"); throw new IndexOutOfBoundsException("Upper limit out of range");

View File

@ -54,6 +54,17 @@ public class NumpadTimePicker extends GridLayoutNumpad implements TimePicker {
@Bind(R.id.fab) FloatingActionButton mFab; @Bind(R.id.fab) FloatingActionButton mFab;
@Bind(R.id.backspace) ImageButton mBackspace; @Bind(R.id.backspace) ImageButton mBackspace;
/**
* Provides additional APIs to configure clients' display output.
*/
public interface OnInputChangeListener extends GridLayoutNumpad.OnInputChangeListener {
/**
* Called when this numpad's buttons are all disabled, indicating no further
* digits can be inserted.
*/
void onInputDisabled();
}
public NumpadTimePicker(Context context) { public NumpadTimePicker(Context context) {
super(context); super(context);
init(); init();
@ -74,6 +85,14 @@ public class NumpadTimePicker extends GridLayoutNumpad implements TimePicker {
return R.layout.content_numpad_time_picker; return R.layout.content_numpad_time_picker;
} }
@Override
protected void enable(int lowerLimitInclusive, int upperLimitExclusive) {
super.enable(lowerLimitInclusive, upperLimitExclusive);
if (lowerLimitInclusive == 0 && upperLimitExclusive == 0) {
((OnInputChangeListener) getOnInputChangeListener()).onInputDisabled();
}
}
@Override @Override
protected void onDigitInserted(String newDigit) { protected void onDigitInserted(String newDigit) {
// Append the new digit(s) to the formatter // Append the new digit(s) to the formatter

View File

@ -142,6 +142,12 @@ public class NumpadTimePickerDialog extends DialogFragment implements NumpadTime
updateInputText(""); updateInputText("");
} }
@Override
public void onInputDisabled() {
// Steals the focus from the EditText
mFocusGrabber.requestFocus();
}
@OnTouch(R.id.input_time) @OnTouch(R.id.input_time)
boolean captureTouchOnEditText() { boolean captureTouchOnEditText() {
// Capture touch events on the EditText field, because we want it to do nothing. // Capture touch events on the EditText field, because we want it to do nothing.
@ -157,8 +163,9 @@ public class NumpadTimePickerDialog extends DialogFragment implements NumpadTime
mInputField.setText(inputText); mInputField.setText(inputText);
// Move the cursor // Move the cursor
mInputField.setSelection(mInputField.length()); mInputField.setSelection(mInputField.length());
if (mNumpad.count() == mNumpad.capacity()) { if (mFocusGrabber.isFocused()) {
mFocusGrabber.requestFocus(); // Return focus to the EditText
mInputField.requestFocus();
} }
} }
} }