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

Commit 6a3ef39f authored by Evan Charlton's avatar Evan Charlton
Browse files

Desk Clock can launch a user-specified application.

The Desk Clock can now launch an application in addition to standard alarm
functionality.

The user also has the ability to optionally not show the snooze/dismiss
dialog and notification, but only if the alarm is silent and without vibrate
enabled.

Change-Id: I6bfad143d28b541ce264cf724c4ce7efb6a1ca54
parent 528fbdfe
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -55,6 +55,24 @@
    <!-- Default label to display for an alarm -->
    <string name="default_label">Alarm</string>

    <!-- Setting label on Set alarm screen: Application to launch -->
    <string name="application">Application</string>

    <!-- Title on the application picker -->
    <string name="application_title">App to launch</string>

    <!-- Option to not launch an application -->
    <string name="application_none">None</string>

	<!-- Setting label on Set alarm screen: Show dialog -->
	<string name="no_dialog">Hide dialog</string>

	<!-- Summary when dialog is hidden -->
	<string name="no_dialog_on">No snooze/dismiss dialog</string>

	<!-- Summary when dialog will be shown -->
	<string name="no_dialog_off">Snooze/dismiss dialog will be shown</string>

    <!-- Preference category on Alarm Settings screen: Set alarm -->
    <string name="set_alarm">Set alarm</string>

+9 −0
Original line number Diff line number Diff line
@@ -40,4 +40,13 @@
        android:persistent="false"
        android:title="@string/label"
        android:dialogTitle="@string/label" />
    <Preference android:key="intent"
        android:persistent="false"
        android:title="@string/application" />
    <CheckBoxPreference android:key="no_dialog"
        android:persistent="true"
        android:title="@string/no_dialog"
        android:defaultValue="false"
        android:summaryOn="@string/no_dialog_on"
        android:summaryOff="@string/no_dialog_off" />
</PreferenceScreen>
+36 −2
Original line number Diff line number Diff line
@@ -17,14 +17,16 @@
package com.android.deskclock;

import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.provider.BaseColumns;
import android.text.format.DateFormat;
import android.text.TextUtils;

import java.net.URISyntaxException;
import java.text.DateFormatSymbols;
import java.util.Calendar;

@@ -59,6 +61,8 @@ public final class Alarm implements Parcelable {
        p.writeString(label);
        p.writeParcelable(alert, flags);
        p.writeInt(silent ? 1 : 0);
        p.writeString(intent);
        p.writeInt(noDialog ? 1 : 0);
    }
    //////////////////////////////
    // end Parcelable apis
@@ -123,6 +127,18 @@ public final class Alarm implements Parcelable {
         */
        public static final String ALERT = "alert";

        /**
         * Intent to fire when alarm triggers
         * <P>Type: STRING</P>
         */
        public static final String INTENT = "intent";

        /**
         * Option to show dialog or not
         * <P>Type: BOOLEAN</P>
         */
        public static final String NO_DIALOG = "no_dialog";

        /**
         * The default sort order for this table
         */
@@ -134,7 +150,7 @@ public final class Alarm implements Parcelable {

        static final String[] ALARM_QUERY_COLUMNS = {
            _ID, HOUR, MINUTES, DAYS_OF_WEEK, ALARM_TIME,
            ENABLED, VIBRATE, MESSAGE, ALERT };
            ENABLED, VIBRATE, MESSAGE, ALERT, INTENT, NO_DIALOG };

        /**
         * These save calls to cursor.getColumnIndexOrThrow()
@@ -149,6 +165,8 @@ public final class Alarm implements Parcelable {
        public static final int ALARM_VIBRATE_INDEX = 6;
        public static final int ALARM_MESSAGE_INDEX = 7;
        public static final int ALARM_ALERT_INDEX = 8;
        public static final int ALARM_INTENT_INDEX = 9;
        public static final int ALARM_NO_DIALOG_INDEX = 10;
    }
    //////////////////////////////
    // End column definitions
@@ -165,6 +183,8 @@ public final class Alarm implements Parcelable {
    public String     label;
    public Uri        alert;
    public boolean    silent;
    public String     intent;
    public boolean    noDialog;

    public Alarm(Cursor c) {
        id = c.getInt(Columns.ALARM_ID_INDEX);
@@ -193,6 +213,18 @@ public final class Alarm implements Parcelable {
                        RingtoneManager.TYPE_ALARM);
            }
        }
        String intentString = c.getString(Columns.ALARM_INTENT_INDEX);
        if (!TextUtils.isEmpty(intentString)) {
            try {
                // Try and parse the URI, see if it breaks.
                Intent.parseUri(intentString, Intent.URI_INTENT_SCHEME);
                // If it's an invalid URI, the exception will short-circuit.
                intent = intentString;
            } catch (URISyntaxException e) {
                intent = null;
            }
        }
        noDialog = c.getInt(Columns.ALARM_NO_DIALOG_INDEX) == 1;
    }

    public Alarm(Parcel p) {
@@ -206,6 +238,8 @@ public final class Alarm implements Parcelable {
        label = p.readString();
        alert = (Uri) p.readParcelable(null);
        silent = p.readInt() == 1;
        intent = p.readString();
        noDialog = p.readInt() == 1;
    }

    // Creates a default alarm at the current time.
+10 −7
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ public class AlarmProvider extends ContentProvider {

    private static class DatabaseHelper extends SQLiteOpenHelper {
        private static final String DATABASE_NAME = "alarms.db";
        private static final int DATABASE_VERSION = 5;
        private static final int DATABASE_VERSION = 7;

        public DatabaseHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
@@ -61,14 +61,17 @@ public class AlarmProvider extends ContentProvider {
                       "enabled INTEGER, " +
                       "vibrate INTEGER, " +
                       "message TEXT, " +
                       "alert TEXT);");
                       "alert TEXT, " +
                       "intent TEXT," +
                       "no_dialog INTEGER);");

            // insert default alarms
            String insertMe = "INSERT INTO alarms " +
                    "(hour, minutes, daysofweek, alarmtime, enabled, vibrate, message, alert) " +
                    "VALUES ";
            db.execSQL(insertMe + "(8, 30, 31, 0, 0, 1, '', '');");
            db.execSQL(insertMe + "(9, 00, 96, 0, 0, 1, '', '');");
            String insertMe = "INSERT INTO alarms "
                    + "(hour, minutes, daysofweek, alarmtime, enabled, vibrate, "
                    + "message, alert, intent, no_dialog) "
                    + "VALUES ";
            db.execSQL(insertMe + "(8, 30, 31, 0, 0, 1, '', '', '', 0);");
            db.execSQL(insertMe + "(9, 00, 96, 0, 0, 1, '', '', '', 0);");
        }

        @Override
+65 −45
Original line number Diff line number Diff line
@@ -26,7 +26,9 @@ import android.content.Intent;
import android.content.BroadcastReceiver;
import android.database.Cursor;
import android.os.Parcel;
import android.text.TextUtils;

import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.util.Date;

@@ -103,6 +105,28 @@ public class AlarmReceiver extends BroadcastReceiver {
            c = AlarmAlertFullScreen.class;
        }

        // If there's an intent specified, start that activity.
        if (!TextUtils.isEmpty(alarm.intent)) {
            try {
                Intent alarmActivity = Intent.parseUri(alarm.intent, Intent.URI_INTENT_SCHEME);
                alarmActivity.setFlags(alarmActivity.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(alarmActivity);
            } catch (URISyntaxException e) {
                // Silently fail since the intent failed to parse.
            }
        } else {
            Log.i("Empty or null intent!");
        }

        if (!alarm.silent) {
            // Play the alarm alert and vibrate the device.
            Intent playAlarm = new Intent(Alarms.ALARM_ALERT_ACTION);
            playAlarm.putExtra(Alarms.ALARM_INTENT_EXTRA, alarm);
            context.startService(playAlarm);
        }

        if (!alarm.noDialog) {
            // User has decided to disable the dialog
            /* launch UI, explicitly stating that this is not due to user action
             * so that the current app's notification management is not disturbed */
            Intent alarmAlert = new Intent(context, c);
@@ -122,11 +146,6 @@ public class AlarmReceiver extends BroadcastReceiver {
                Alarms.setNextAlert(context);
            }
            
        // Play the alarm alert and vibrate the device.
        Intent playAlarm = new Intent(Alarms.ALARM_ALERT_ACTION);
        playAlarm.putExtra(Alarms.ALARM_INTENT_EXTRA, alarm);
        context.startService(playAlarm);

            // Trigger a notification that, when clicked, will show the alarm alert
            // dialog. No need to check for fullscreen since this will always be
            // launched from a user action.
@@ -152,6 +171,7 @@ public class AlarmReceiver extends BroadcastReceiver {
            NotificationManager nm = getNotificationManager(context);
            nm.notify(alarm.id, n);
        }
    }

    private NotificationManager getNotificationManager(Context context) {
        return (NotificationManager)
Loading