Numpad key listener set
This commit is contained in:
parent
881b4dcf83
commit
68fb80b42b
@ -39,7 +39,7 @@ public abstract class Numpad extends TableLayout {
|
|||||||
|
|
||||||
public interface KeyListener {
|
public interface KeyListener {
|
||||||
void onNumberInput(String number);
|
void onNumberInput(String number);
|
||||||
void onCollapse(); // TODO: useless?
|
void onCollapse();
|
||||||
void onBackspace(String newStr);
|
void onBackspace(String newStr);
|
||||||
void onLongBackspace();
|
void onLongBackspace();
|
||||||
}
|
}
|
||||||
@ -107,6 +107,18 @@ public abstract class Numpad extends TableLayout {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected final void buildCollapse(int r, int c) {
|
||||||
|
mCollapse = (ImageButton) buildButton(R.layout.numpad_collapse, r, c);
|
||||||
|
|
||||||
|
mCollapse.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
checkKeyListenerSet();
|
||||||
|
mKeyListener.onCollapse();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
protected final void newRow() {
|
protected final void newRow() {
|
||||||
TableRow newRow = new TableRow(getContext());
|
TableRow newRow = new TableRow(getContext());
|
||||||
newRow.setLayoutParams(new TableRow.LayoutParams());
|
newRow.setLayoutParams(new TableRow.LayoutParams());
|
||||||
|
|||||||
@ -5,8 +5,10 @@ import android.util.AttributeSet;
|
|||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Phillip Hsu on 6/2/2016.
|
* Couldn't figure out how to draw the numpad over the system keyboard, so
|
||||||
|
* the callback interface provided here is of no use to us.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public class AlarmEditText extends android.support.v7.widget.AppCompatEditText {
|
public class AlarmEditText extends android.support.v7.widget.AppCompatEditText {
|
||||||
|
|
||||||
private OnBackPressListener mOnBackPressListener;
|
private OnBackPressListener mOnBackPressListener;
|
||||||
|
|||||||
@ -430,12 +430,12 @@ public class AlarmNumpad extends Numpad {
|
|||||||
|
|
||||||
newRow();
|
newRow();
|
||||||
buildBackspace(getChildCount() - 1, 2);
|
buildBackspace(getChildCount() - 1, 2);
|
||||||
// buildCollapse(getChildCount() - 1, 0);
|
buildCollapse(getChildCount() - 1, 0);
|
||||||
// The FAB is wrapped in a FrameLayout
|
// The FAB is wrapped in a FrameLayout
|
||||||
FrameLayout frame = (FrameLayout)
|
FrameLayout frame = (FrameLayout)
|
||||||
buildButton(R.layout.numpad_fab, getChildCount() - 1, 1);
|
buildButton(R.layout.numpad_fab, getChildCount() - 1, 1);
|
||||||
fab = (FloatingActionButton) frame.getChildAt(0);
|
fab = (FloatingActionButton) frame.getChildAt(0);
|
||||||
//fab.setBackgroundTintList(getResources().getColorStateList(R.color.on_enabled_change_fab));
|
fab.setBackgroundTintList(getResources().getColorStateList(R.color.on_enabled_change_fab));
|
||||||
|
|
||||||
fab.setEnabled(false);
|
fab.setEnabled(false);
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,7 @@ import static com.philliphsu.clock2.DaysOfWeek.NUM_DAYS;
|
|||||||
import static com.philliphsu.clock2.DaysOfWeek.SATURDAY;
|
import static com.philliphsu.clock2.DaysOfWeek.SATURDAY;
|
||||||
import static com.philliphsu.clock2.DaysOfWeek.SUNDAY;
|
import static com.philliphsu.clock2.DaysOfWeek.SUNDAY;
|
||||||
|
|
||||||
public class EditAlarmActivity extends BaseActivity implements AlarmEditText.OnBackPressListener {
|
public class EditAlarmActivity extends BaseActivity implements AlarmNumpad.KeyListener {
|
||||||
private static final String TAG = "EditAlarmActivity";
|
private static final String TAG = "EditAlarmActivity";
|
||||||
public static final String EXTRA_ALARM_ID = "com.philliphsu.clock2.editalarm.extra.ALARM_ID";
|
public static final String EXTRA_ALARM_ID = "com.philliphsu.clock2.editalarm.extra.ALARM_ID";
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ public class EditAlarmActivity extends BaseActivity implements AlarmEditText.OnB
|
|||||||
@Bind(R.id.save) Button mSave;
|
@Bind(R.id.save) Button mSave;
|
||||||
@Bind(R.id.delete) Button mDelete;
|
@Bind(R.id.delete) Button mDelete;
|
||||||
@Bind(R.id.on_off) SwitchCompat mSwitch;
|
@Bind(R.id.on_off) SwitchCompat mSwitch;
|
||||||
@Bind(R.id.input_time) AlarmEditText mTimeText;
|
@Bind(R.id.input_time) EditText mTimeText;
|
||||||
@Bind({R.id.day0, R.id.day1, R.id.day2, R.id.day3, R.id.day4, R.id.day5, R.id.day6})
|
@Bind({R.id.day0, R.id.day1, R.id.day2, R.id.day3, R.id.day4, R.id.day5, R.id.day6})
|
||||||
ToggleButton[] mDays;
|
ToggleButton[] mDays;
|
||||||
@Bind(R.id.label) EditText mLabel;
|
@Bind(R.id.label) EditText mLabel;
|
||||||
@ -98,8 +98,8 @@ public class EditAlarmActivity extends BaseActivity implements AlarmEditText.OnB
|
|||||||
mSelectedRingtoneUri = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM);
|
mSelectedRingtoneUri = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM);
|
||||||
mNumpad.setVisibility(View.VISIBLE);
|
mNumpad.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
mNumpad.setKeyListener(this);
|
||||||
updateRingtoneButtonText();
|
updateRingtoneButtonText();
|
||||||
mTimeText.setOnBackPressListener(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -139,11 +139,43 @@ public class EditAlarmActivity extends BaseActivity implements AlarmEditText.OnB
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Handle back press when virtual keyboard is shown */
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPress() {
|
public void onBackPressed() {
|
||||||
// TODO: Hide your numpad.
|
if (mNumpad.getVisibility() == View.VISIBLE) {
|
||||||
mNumpad.setVisibility(View.GONE);
|
mNumpad.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
super.onBackPressed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAcceptChanges() {
|
||||||
|
mNumpad.setVisibility(View.GONE);
|
||||||
|
mSwitch.setChecked(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNumberInput(String formattedInput) {
|
||||||
|
mTimeText.setText(formattedInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCollapse() {
|
||||||
|
mNumpad.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackspace(String newStr) {
|
||||||
|
mTimeText.setText(newStr);
|
||||||
|
if (!mNumpad.checkTimeValid() && mSwitch.isChecked()) {
|
||||||
|
mSwitch.setChecked(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLongBackspace() {
|
||||||
|
mTimeText.setText("");
|
||||||
|
mSwitch.setChecked(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnTouch(R.id.input_time)
|
@OnTouch(R.id.input_time)
|
||||||
|
|||||||
@ -74,7 +74,7 @@
|
|||||||
android:layout_centerVertical="true"/>
|
android:layout_centerVertical="true"/>
|
||||||
|
|
||||||
<!-- TODO: Find out how to get a touch ripple; foreground attr didn't work -->
|
<!-- TODO: Find out how to get a touch ripple; foreground attr didn't work -->
|
||||||
<com.philliphsu.clock2.editalarm.AlarmEditText
|
<EditText
|
||||||
android:id="@+id/input_time"
|
android:id="@+id/input_time"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|||||||
4
app/src/main/res/layout/numpad_collapse.xml
Normal file
4
app/src/main/res/layout/numpad_collapse.xml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ImageButton xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
style="@style/NumpadButton"
|
||||||
|
android:src="@drawable/ic_collapse_24dp"/>
|
||||||
Loading…
Reference in New Issue
Block a user