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

Commit 676fb52e authored by Jorge Ruesga's avatar Jorge Ruesga Committed by Gerrit Code Review
Browse files

Fix 5734: Set alarm clock to switch profile (from ics - NEW)

ics: http://review.cyanogenmod.com/#/c/20271/2

This change creates a new setting for the alarm, that allows to associate
a profile with an alarm, and change to this profile when the alarm triggers.

Update change for reflect new profiles status (enabled/disabled)

NOTE: The database of alarms is upgrading from version 6 to version 7, so all
alarms are resetting with this change.

Change-Id: I3d20f0e406b23c1d4c8d873434c331b3425971e4
parent 6a340cbd
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -11,8 +11,6 @@ LOCAL_PACKAGE_NAME := DeskClock

LOCAL_OVERRIDES_PACKAGES := AlarmClock

LOCAL_SDK_VERSION := current

include $(BUILD_PACKAGE)

# Use the following include to make our test apk.
+13 −0
Original line number Diff line number Diff line
@@ -331,6 +331,19 @@
    <!-- Label on the main screen control used to set alarm when there is already an existing alarm [CHAR LIMIT=30]-->
    <string name="control_set_alarm_with_existing">Alarm set: <xliff:g id="time">%s</xliff:g></string>

    <!-- Setting labels on Set alarm screen: Select profile to change to -->
    <string name="alarm_profile">Profile</string>

    <!-- Option of profile setting of the alarm: No change to profile -->
    <string name="alarm_profile_no_change_profile">No change profile</string>

    <!-- Summary of alarm profile: No change profile -->
    <string name="alarm_profile_summary_no_change">No change to profile when alarm triggers</string>

    <!-- Summary of alarm profile: Change profile to -->
    <string name="alarm_profile_summary_change_to">When alarm triggers, the profile will be changed to
        <xliff:g id="profile">%s</xliff:g></string>

</resources>

+4 −0
Original line number Diff line number Diff line
@@ -33,6 +33,10 @@
        android:persistent="false"
        android:showDefault="false"
        android:showSilent="true" />
    <com.android.deskclock.ProfilePreference
        android:persistent="false"
        android:key="profile"
        android:title="@string/alarm_profile" />
    <CheckBoxPreference android:key="vibrate"
        android:persistent="false"
        android:title="@string/alarm_vibrate"/>
+31 −1
Original line number Diff line number Diff line
@@ -21,11 +21,13 @@ import android.database.Cursor;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Parcel;
import android.os.ParcelUuid;
import android.os.Parcelable;
import android.provider.BaseColumns;

import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.UUID;

public final class Alarm implements Parcelable {

@@ -59,6 +61,8 @@ public final class Alarm implements Parcelable {
        p.writeParcelable(alert, flags);
        p.writeInt(silent ? 1 : 0);
        p.writeInt(incvol ? 1 : 0);
        ParcelUuid uuid = new ParcelUuid(profile);
        uuid.writeToParcel(p, 0);
    }
    //////////////////////////////
    // end Parcelable apis
@@ -129,6 +133,12 @@ public final class Alarm implements Parcelable {
         */
        public static final String INCVOL = "incvol";

        /**
         * Profile to change to when alarm triggers
         * <P>Type: STRING</P>
         */
         public static final String PROFILE = "profile";

        /**
         * The default sort order for this table
         */
@@ -140,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, INCVOL };
            ENABLED, VIBRATE, MESSAGE, ALERT, INCVOL, PROFILE };

        /**
         * These save calls to cursor.getColumnIndexOrThrow()
@@ -156,6 +166,7 @@ public final class Alarm implements Parcelable {
        public static final int ALARM_MESSAGE_INDEX = 7;
        public static final int ALARM_ALERT_INDEX = 8;
        public static final int ALARM_INCVOL_INDEX = 9;
        public static final int ALARM_PROFILE_INDEX = 10;
    }
    //////////////////////////////
    // End column definitions
@@ -173,6 +184,13 @@ public final class Alarm implements Parcelable {
    public Uri        alert;
    public boolean    silent;
    public boolean    incvol;
    public UUID       profile;

    /**
     * @hide
     */
    protected static final UUID NO_PROFILE =
            UUID.fromString("00000000-0000-0000-0000-000000000000");

    public Alarm(Cursor c) {
        id = c.getInt(Columns.ALARM_ID_INDEX);
@@ -202,6 +220,16 @@ public final class Alarm implements Parcelable {
            }
        }
        incvol = c.getInt(Columns.ALARM_INCVOL_INDEX) == 1;
        String profileString = c.getString(Columns.ALARM_PROFILE_INDEX);
        if (profileString == null || profileString.equals(NO_PROFILE)) {
            profile = NO_PROFILE;
        } else {
            try {
                profile = UUID.fromString(profileString);
            } catch (Exception e) {
                profile = NO_PROFILE;
            }
        }
    }

    public Alarm(Parcel p) {
@@ -216,6 +244,7 @@ public final class Alarm implements Parcelable {
        alert = (Uri) p.readParcelable(null);
        silent = p.readInt() == 1;
        incvol = p.readInt() == 1;
        profile = ParcelUuid.CREATOR.createFromParcel(p).getUuid();
    }

    // Creates a default alarm at the current time.
@@ -229,6 +258,7 @@ public final class Alarm implements Parcelable {
        daysOfWeek = new DaysOfWeek(0);
        alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
        incvol = false;
        profile = NO_PROFILE;
    }

    public String getLabelOrDefault(Context context) {
+8 −5
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ import android.net.Uri;
class AlarmDatabaseHelper extends SQLiteOpenHelper {

    private static final String DATABASE_NAME = "alarms.db";
    private static final int DATABASE_VERSION = 6;
    private static final int DATABASE_VERSION = 7;

    public AlarmDatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
@@ -49,14 +49,17 @@ class AlarmDatabaseHelper extends SQLiteOpenHelper {
                   "vibrate INTEGER, " +
                   "message TEXT, " +
                   "alert TEXT, " +
                   "incvol INTEGER);");
                   "incvol INTEGER, " +
                   "profile TEXT);");

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

    @Override
Loading