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

Commit 9b9ccd4d authored by Steve Kondik's avatar Steve Kondik
Browse files

Part two in the "wake my lazy ass up series". Add option to require

keyguard unlock to dismiss or snooze alarm.

I should probably buy a Clocky.
parent ad9a3ed8
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -246,6 +246,10 @@
         respond. This is a sign of an error; if the weather widget is not
         present on the device, we show nothing at all. -->
    <string name="weather_fetch_failure">Weather information currently unavailable.</string>

    <string name="alarm_requires_unlock_title">Alarm requires unlock</string>
    <string name="alarm_requires_unlock_summary">Must unlock phone to disable or snooze alarm</string>
</resources>


+5 −0
Original line number Diff line number Diff line
@@ -23,6 +23,11 @@
        android:title="@string/alarm_in_silent_mode_title"
        android:summary="@string/alarm_in_silent_mode_summary" />

    <CheckBoxPreference
        android:key="alarm_requires_unlock"
        android:title="@string/alarm_requires_unlock_title"
        android:summary="@string/alarm_requires_unlock_summary" />

    <VolumePreference
        android:title="@string/alarm_volume_title"
        android:summary="@string/alarm_volume_summary"
+14 −11
Original line number Diff line number Diff line
@@ -16,29 +16,26 @@

package com.android.deskclock;

import java.util.Calendar;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.LayoutInflater;
import android.view.Window;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.Toast;
import android.widget.TextView;

import java.util.Calendar;
import android.widget.Toast;

/**
 * Alarm Clock alarm alert: pops visible indicator and plays alarm
@@ -77,11 +74,17 @@ public class AlarmAlert extends Activity {
                        DEFAULT_VOLUME_BEHAVIOR);
        mVolumeBehavior = Integer.parseInt(vol);

        final boolean requireUnlock = Settings.System.getInt(getContentResolver(), SettingsActivity.KEY_ALARM_REQUIRES_UNLOCK, 0) == 1;
        
        requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
        
        if (!requireUnlock) {
        	getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
        }
        
        updateLayout();

        // Register to get the alarm killed intent.
+9 −1
Original line number Diff line number Diff line
@@ -40,6 +40,9 @@ public class SettingsActivity extends PreferenceActivity
            "snooze_duration";
    static final String KEY_VOLUME_BEHAVIOR =
            "volume_button_setting";
    static final String KEY_ALARM_REQUIRES_UNLOCK = 
    		"alarm_requires_unlock";
    
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
@@ -73,6 +76,11 @@ public class SettingsActivity extends PreferenceActivity
                    ringerModeStreamTypes);

            return true;
            
        } else if (KEY_ALARM_REQUIRES_UNLOCK.equals(preference.getKey())) {
        	CheckBoxPreference pref = (CheckBoxPreference) preference;
        	Settings.System.putInt(getContentResolver(), KEY_ALARM_REQUIRES_UNLOCK, pref.isChecked() ? 1 : 0);
        	return true;
        }

        return super.onPreferenceTreeClick(preferenceScreen, preference);