Skip to content

Commit

Permalink
Dismiss or snooze alarms by swiping or tapping - Fix #58
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackyHawky committed Jun 12, 2024
1 parent b94632e commit 93d9c7b
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 3 deletions.
13 changes: 10 additions & 3 deletions app/src/main/java/com/best/deskclock/alarms/AlarmActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public void onServiceDisconnected(ComponentName name) {
private AlarmVolumeButtonBehavior mPowerBehavior;
private int mCurrentHourColor;
private int mTextColor;
private boolean isSwipeActionEnabled;
private boolean mReceiverRegistered;
/**
* Whether the AlarmService is currently bound
Expand Down Expand Up @@ -269,7 +270,12 @@ protected void onCreate(Bundle savedInstanceState) {
mCurrentHourColor = getColor(R.color.md_theme_background);
getWindow().setBackgroundDrawable(new ColorDrawable(mCurrentHourColor));

mAlarmButton.setOnTouchListener(this);
isSwipeActionEnabled = DataModel.getDataModel().isSwipeActionEnabled();
if (isSwipeActionEnabled) {
mAlarmButton.setOnTouchListener(this);
} else {
mAlarmButton.setOnTouchListener(null);
}
mSnoozeButton.setOnClickListener(this);
mDismissButton.setOnClickListener(this);

Expand Down Expand Up @@ -381,8 +387,9 @@ public void onClick(View view) {
}
LOGGER.v("onClick: %s", view);

// If in accessibility mode, allow snooze/dismiss by double tapping on respective icons.
if (isAccessibilityEnabled()) {
// If in accessibility mode or if alarm swiping is disabled in settings,
// allow snooze/dismiss by tapping on respective icons.
if (isAccessibilityEnabled() || !isSwipeActionEnabled) {
if (view == mSnoozeButton) {
snooze();
} else if (view == mDismissButton) {
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/best/deskclock/data/DataModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,14 @@ public boolean getShowHomeClock() {
return mSettingsModel.getShowHomeClock();
}

/**
* @return {@code true} if swipe action is enabled to dismiss or snooze alarms. {@code false} otherwise.
*/
public boolean isSwipeActionEnabled() {
enforceMainLooper();
return mSettingsModel.isSwipeActionEnabled();
}

/**
* @return the display order of the weekdays, which can start with {@link Calendar#SATURDAY},
* {@link Calendar#SUNDAY} or {@link Calendar#MONDAY}
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/best/deskclock/data/SettingsDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static com.best.deskclock.data.Weekdays.Order.SAT_TO_FRI;
import static com.best.deskclock.data.Weekdays.Order.SUN_TO_SAT;
import static com.best.deskclock.settings.AlarmSettingsActivity.KEY_DEFAULT_ALARM_RINGTONE;
import static com.best.deskclock.settings.AlarmSettingsActivity.KEY_SWIPE_ACTION;
import static com.best.deskclock.settings.InterfaceCustomizationActivity.DEFAULT_ACCENT_COLOR;
import static com.best.deskclock.settings.InterfaceCustomizationActivity.KEY_DEFAULT_DARK_MODE;
import static com.best.deskclock.settings.InterfaceCustomizationActivity.SYSTEM_THEME;
Expand Down Expand Up @@ -376,6 +377,13 @@ static long getTimerCrescendoDuration(SharedPreferences prefs) {
return Integer.parseInt(crescendoSeconds) * DateUtils.SECOND_IN_MILLIS;
}

/**
* @return {@code true} if swipe action is enabled to dismiss or snooze alarms. {@code false} otherwise.
*/
static boolean isSwipeActionEnabled(SharedPreferences pref) {
return pref.getBoolean(KEY_SWIPE_ACTION, true);
}

/**
* @return the display order of the weekdays, which can start with {@link Calendar#SATURDAY},
* {@link Calendar#SUNDAY} or {@link Calendar#MONDAY}
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/best/deskclock/data/SettingsModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ long getTimerCrescendoDuration() {
return SettingsDAO.getTimerCrescendoDuration(mPrefs);
}

boolean isSwipeActionEnabled() {
return SettingsDAO.isSwipeActionEnabled(mPrefs);
}

Weekdays.Order getWeekdayOrder() {
return SettingsDAO.getWeekdayOrder(mPrefs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreferenceCompat;

import com.best.deskclock.R;
import com.best.deskclock.Utils;
Expand All @@ -30,6 +31,7 @@ public class AlarmSettingsActivity extends CollapsingToolbarBaseActivity {
public static final String KEY_AUTO_SILENCE = "auto_silence";
public static final String KEY_ALARM_SNOOZE = "snooze_duration";
public static final String KEY_ALARM_CRESCENDO = "alarm_crescendo_duration";
public static final String KEY_SWIPE_ACTION = "key_swipe_action";
public static final String KEY_VOLUME_BUTTONS = "volume_button_setting";
public static final String DEFAULT_VOLUME_BEHAVIOR = "0";
public static final String VOLUME_BEHAVIOR_SNOOZE = "1";
Expand Down Expand Up @@ -85,6 +87,8 @@ public boolean onPreferenceChange(Preference pref, Object newValue) {
updateAutoSnoozeSummary((ListPreference) pref, delay);
}

case KEY_SWIPE_ACTION -> Utils.setVibrationTime(requireContext(), 50);

case KEY_ALARM_SNOOZE, KEY_ALARM_CRESCENDO, KEY_VOLUME_BUTTONS, KEY_POWER_BUTTONS,
KEY_FLIP_ACTION, KEY_SHAKE_ACTION, KEY_WEEK_START -> {
final ListPreference preference = (ListPreference) pref;
Expand Down Expand Up @@ -125,6 +129,10 @@ private void refresh() {

refreshListPreference(Objects.requireNonNull(findPreference(KEY_ALARM_CRESCENDO)));

final SwitchPreferenceCompat swipeActionPref = findPreference(KEY_SWIPE_ACTION);
Objects.requireNonNull(swipeActionPref).setChecked(DataModel.getDataModel().isSwipeActionEnabled());
swipeActionPref.setOnPreferenceChangeListener(this);

final ListPreference volumeButtonsPref = findPreference(KEY_VOLUME_BUTTONS);
Objects.requireNonNull(volumeButtonsPref).setSummary(volumeButtonsPref.getEntry());
volumeButtonsPref.setOnPreferenceChangeListener(this);
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
<string name="silent_default_alarm_ringtone" msgid="6012855475009670997">"La sonnerie d\'alarme par défaut est silencieuse."</string>
<string name="change_setting_action" msgid="1224356633832430160">"Modifier"</string>
<string name="alarms_blocked_by_dnd" msgid="6089433757505898969">"L\'appareil est défini sur \"Aucune interruption\"."</string>
<string name="swipe_action_title">Glisser pour répéter ou arrêter les alarmes</string>
<string name="volume_button_setting_title" msgid="6937131248843413357">"Boutons du volume"</string>
<string-array name="volume_button_setting_entries">
<item msgid="7972756698723318690">"Répéter"</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@
<string name="change_setting_action">Change</string>
<!-- Text to display when do-not-disturb is blocking alarms. [CHAR LIMIT=60] -->
<string name="alarms_blocked_by_dnd">Device is set to total silence</string>
<!-- Title of the setting to enable swiping to dismiss or snooze alarms -->
<string name="swipe_action_title">Swipe to dismiss or snooze alarms</string>
<!-- Title of the setting to change hardware button behavior. This string
should be changed for each piece of hardware. [CHAR LIMIT=20] -->
<string name="volume_button_setting_title">Volume buttons</string>
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/xml/settings_alarm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@
app:allowDividerAbove="false"
app:iconSpaceReserved="false">

<SwitchPreferenceCompat
android:key="key_swipe_action"
android:layout="@layout/settings_preference_layout"
android:title="@string/swipe_action_title"
android:defaultValue="true"
app:iconSpaceReserved="false"
app:singleLineTitle="false" />

<ListPreference
android:key="volume_button_setting"
android:layout="@layout/settings_preference_layout"
Expand Down

0 comments on commit 93d9c7b

Please sign in to comment.