Changed interaction dynamics in EditAlarmActivity
This commit is contained in:
parent
7432a057b3
commit
3c3b9bf129
@ -35,6 +35,9 @@ import butterknife.OnClick;
|
||||
import butterknife.OnTouch;
|
||||
|
||||
import static android.text.format.DateFormat.getTimeFormat;
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static com.philliphsu.clock2.util.KeyboardUtils.hideKeyboard;
|
||||
import static com.philliphsu.clock2.util.Preconditions.checkNotNull;
|
||||
|
||||
public class EditAlarmActivity extends BaseActivity implements
|
||||
@ -148,25 +151,18 @@ public class EditAlarmActivity extends BaseActivity implements
|
||||
mPresenter.onBackspace("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showRingtonePickerDialog() {
|
||||
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALARM)
|
||||
.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false)
|
||||
// The ringtone to show as selected when the dialog is opened
|
||||
.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, mSelectedRingtoneUri)
|
||||
// Whether to show "Default" item in the list
|
||||
.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, false); // TODO: false?
|
||||
// The ringtone that plays when default option is selected
|
||||
//.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, DEFAULT_TONE);
|
||||
startActivityForResult(intent, REQUEST_PICK_RINGTONE);
|
||||
}
|
||||
|
||||
@OnTouch(R.id.input_time)
|
||||
boolean touch(MotionEvent event) {
|
||||
if (event.getActionMasked() == MotionEvent.ACTION_UP && mNumpad.getVisibility() != View.VISIBLE) {
|
||||
if (event.getActionMasked() == MotionEvent.ACTION_UP) {
|
||||
hideKeyboard(this); // If not open, does nothing.
|
||||
mPresenter.focusTimeText();
|
||||
if (mNumpad.getVisibility() != View.VISIBLE) {
|
||||
// TODO: If keyboard was open, consider adding delay to opening the numpad.
|
||||
// Otherwise, it opens immediately behind the keyboard as it is still animating
|
||||
// out of the window.
|
||||
mPresenter.showNumpad();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -204,6 +200,14 @@ public class EditAlarmActivity extends BaseActivity implements
|
||||
return false;
|
||||
}
|
||||
|
||||
@OnTouch(R.id.label)
|
||||
boolean touchLabel(MotionEvent event) {
|
||||
if (event.getActionMasked() == MotionEvent.ACTION_UP && mNumpad.getVisibility() == VISIBLE) {
|
||||
mPresenter.hideNumpad();
|
||||
}
|
||||
return false; // don't capture
|
||||
}
|
||||
|
||||
@OnCheckedChanged(R.id.on_off)
|
||||
void onChecked(boolean checked) {
|
||||
if (checked && mTimeText.length() == 0) {
|
||||
@ -328,7 +332,7 @@ public class EditAlarmActivity extends BaseActivity implements
|
||||
|
||||
@Override
|
||||
public void showNumpad(boolean show) {
|
||||
mNumpad.setVisibility(show ? View.VISIBLE : View.GONE);
|
||||
mNumpad.setVisibility(show ? VISIBLE : GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -389,6 +393,31 @@ public class EditAlarmActivity extends BaseActivity implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showRingtonePickerDialog() {
|
||||
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALARM)
|
||||
.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false)
|
||||
// The ringtone to show as selected when the dialog is opened
|
||||
.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, mSelectedRingtoneUri)
|
||||
// Whether to show "Default" item in the list
|
||||
.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, false); // TODO: false?
|
||||
// The ringtone that plays when default option is selected
|
||||
//.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, DEFAULT_TONE);
|
||||
startActivityForResult(intent, REQUEST_PICK_RINGTONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showTimeTextFocused(boolean focused) {
|
||||
if (focused) {
|
||||
mTimeText.requestFocus();
|
||||
// Move cursor to end
|
||||
mTimeText.setSelection(mTimeText.length());
|
||||
} else {
|
||||
mTimeText.clearFocus(); // TODO: not cleared! focus needs to go to a neighboring view.
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scheduleAlarm(Alarm alarm) {
|
||||
AlarmUtils.scheduleAlarm(this, alarm);
|
||||
|
||||
@ -16,6 +16,7 @@ public interface EditAlarmContract {
|
||||
void setTimeTextHint();
|
||||
void showTimeText(String timeText);
|
||||
void showTimeTextPostBackspace(String newStr);
|
||||
void showTimeTextFocused(boolean focused);
|
||||
int getHour();
|
||||
int getMinutes();
|
||||
boolean isEnabled();
|
||||
@ -38,5 +39,6 @@ public interface EditAlarmContract {
|
||||
void openRingtonePickerDialog();
|
||||
void setTimeTextHint();
|
||||
void onNumberInput(String formattedInput);
|
||||
void focusTimeText();
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,6 +152,11 @@ public class EditAlarmPresenter implements EditAlarmContract.Presenter {
|
||||
mView.showTimeText(formattedInput);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void focusTimeText() {
|
||||
mView.showTimeTextFocused(true);
|
||||
}
|
||||
|
||||
private void showDetails() {
|
||||
if (mAlarm != null) {
|
||||
mView.showTime(mAlarm.hour(), mAlarm.minutes());
|
||||
@ -167,8 +172,10 @@ public class EditAlarmPresenter implements EditAlarmContract.Presenter {
|
||||
}
|
||||
// Editing so don't show
|
||||
mView.showNumpad(false);
|
||||
mView.showTimeTextFocused(false);
|
||||
} else {
|
||||
// TODO default values
|
||||
mView.showTimeTextFocused(true);
|
||||
mView.showRingtone(""); // gets default ringtone
|
||||
mView.showNumpad(true);
|
||||
}
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
package com.philliphsu.clock2.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
/**
|
||||
* Created by Phillip Hsu on 6/5/2016.
|
||||
*/
|
||||
public class KeyboardUtils {
|
||||
|
||||
public static void hideKeyboard(Activity a) {
|
||||
View view = a.getCurrentFocus();
|
||||
if (view != null) {
|
||||
InputMethodManager imm = (InputMethodManager)
|
||||
a.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user