Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 06a40d3e authored by Evan Charlton's avatar Evan Charlton
Browse files

Add an option to only dismiss alarm on long-press of the button

Allow the user to optionally present the alarm with a dual-mode button.
When enabled, a single button is presented and the alarm is only dismissed
when the button is long-pressed, making it harder to accidentally dismiss
and alarm.

Change-Id: I25c61c152ccd985c8e0e80db5c74db079ed5bb53
parent d44bd8f9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@

            <!-- blank stretchable view -->
            <View
                android:id="@+id/spacer"
                android:layout_width="2dip"
                android:layout_height="2dip"
                android:layout_gravity="fill_horizontal"
+8 −2
Original line number Diff line number Diff line
@@ -81,6 +81,9 @@
    <!-- Button labels on the alarm dialog: Snooze -->
    <string name="alarm_alert_snooze_text">Snooze</string>

    <!-- Button labels on the alarm dialog: Snooze & dismiss (when dual-mode button enabled) -->
    <string name="alarm_alert_snooze_text_dual_mode">Snooze (hold to dismiss)</string>

    <!-- Toast that appears after Alarm is snoozed from the Alarm
         dialog. Says the alarm will snooze for xxx minutes.  -->
    <string name="alarm_alert_snooze_set">Snoozing for <xliff:g id="minutes">%d</xliff:g> minutes.</string>
@@ -320,6 +323,9 @@
    <string name="color_picker_green">Green</string>
    <string name="color_picker_blue">Blue</string>

</resources>

    <!-- Settings strings for dual-mode button -->
    <string name="use_dual_mode_button">Dual-mode snooze</string>
    <string name="use_dual_mode_button_on">Long-press the snooze button to dismiss the alarm</string>
    <string name="use_dual_mode_button_off">Separate snooze and dismiss buttons</string>

</resources>
 No newline at end of file
+8 −2
Original line number Diff line number Diff line
@@ -73,4 +73,10 @@
				android.targetClass="com.android.alarmclock.ColorPicker"/>
    </PreferenceScreen>

    <CheckBoxPreference
        android:key="use_dual_mode_button"
        android:title="@string/use_dual_mode_button"
        android:summaryOn="@string/use_dual_mode_button_on"
        android:summaryOff="@string/use_dual_mode_button_off" />

</PreferenceScreen>
+30 −8
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.LayoutInflater;
import android.view.ViewStub;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
@@ -52,6 +53,8 @@ public class AlarmAlertFullScreen extends Activity {
    private static final String DEFAULT_VOLUME_BEHAVIOR = "2";
    protected static final String SCREEN_OFF = "screen_off";

    private static final String KEY_DUAL_MODE_BUTTON = "use_dual_mode_button";

    protected Alarm mAlarm;
    private int mVolumeBehavior;

@@ -118,7 +121,8 @@ public class AlarmAlertFullScreen extends Activity {
    private void updateLayout() {
        LayoutInflater inflater = LayoutInflater.from(this);

        setContentView(inflater.inflate(R.layout.alarm_alert, null));
        View contentView = inflater.inflate(R.layout.alarm_alert, null);
        setContentView(contentView);

        /* snooze behavior: pop a snooze confirmation view, kick alarm
           manager. */
@@ -130,13 +134,31 @@ public class AlarmAlertFullScreen extends Activity {
            }
        });

        boolean dualModeButtonEnabled = PreferenceManager.getDefaultSharedPreferences(this)
                .getBoolean(KEY_DUAL_MODE_BUTTON, false);

        View dismiss = findViewById(R.id.dismiss);

        if (dualModeButtonEnabled) {
            snooze.setOnLongClickListener(new Button.OnLongClickListener() {
                        @Override
                        public boolean onLongClick(View v) {
                            dismiss(false);
                            return true;
                        }
                    });
            snooze.setText(R.string.alarm_alert_snooze_text_dual_mode);
            dismiss.setVisibility(View.GONE);
            findViewById(R.id.spacer).setVisibility(View.GONE);
        } else {
            /* dismiss button: close notification */
        findViewById(R.id.dismiss).setOnClickListener(
            dismiss.setOnClickListener(
                    new Button.OnClickListener() {
                        public void onClick(View v) {
                            dismiss(false);
                        }
                    });
        }

        /* Set the title from the passed in alarm */
        setTitle();