public class

Alarm

extends Thing

 java.lang.Object

androidx.appsearch.builtintypes.Thing

↳androidx.appsearch.builtintypes.Alarm

Gradle dependencies

compile group: 'androidx.appsearch', name: 'appsearch-builtin-types', version: '1.1.0-alpha05'

  • groupId: androidx.appsearch
  • artifactId: appsearch-builtin-types
  • version: 1.1.0-alpha05

Artifact androidx.appsearch:appsearch-builtin-types:1.1.0-alpha05 it located at Google repository (https://maven.google.com/)

Overview

AppSearch document representing an Alarm entity.

Summary

Fields
public static final intORIGINATING_DEVICE_SMART_PHONE

The Alarm belongs to a smart phone device.

public static final intORIGINATING_DEVICE_SMART_WATCH

The Alarm belongs to a smart watch device.

public static final intORIGINATING_DEVICE_UNKNOWN

The Alarm belongs to an unknown device.

Methods
public java.lang.StringgetBlackoutPeriodEndDate()

Returns the end time for the blackout period in ISO 8601 format.

public java.lang.StringgetBlackoutPeriodStartDate()

Returns the start date of the blackout period in ISO 8601 format.

public int[]getDaysOfWeek()

Returns the scheduled days for repeating.

public intgetHour()

Returns the hour the Alarm will fire.

public intgetMinute()

Returns the minute the Alarm will fire.

public AlarmInstancegetNextInstance()

Returns the next AlarmInstance.

public intgetOriginatingDevice()

Returns the Alarm.OriginatingDevice this alarm belongs to.

public AlarmInstancegetPreviousInstance()

Returns the previous AlarmInstance.

public java.lang.StringgetRingtone()

Returns the ringtone as a content URI to be played, or if no ringtone will be played.

public booleanisEnabled()

Returns whether or not the Alarm is active.

public booleanshouldVibrate()

Returns whether or not to activate the device vibrator when the Alarm fires.

from ThinggetAlternateNames, getCreationTimestampMillis, getDescription, getDocumentScore, getDocumentTtlMillis, getId, getImage, getName, getNamespace, getPotentialActions, getUrl
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Fields

public static final int ORIGINATING_DEVICE_UNKNOWN

The Alarm belongs to an unknown device.

public static final int ORIGINATING_DEVICE_SMART_PHONE

The Alarm belongs to a smart phone device.

public static final int ORIGINATING_DEVICE_SMART_WATCH

The Alarm belongs to a smart watch device.

Methods

public boolean isEnabled()

Returns whether or not the Alarm is active.

public int[] getDaysOfWeek()

Returns the scheduled days for repeating.

Days of the week can be MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, or SUNDAY.

If null, or if the list is empty, then the Alarm does not repeat.

public int getHour()

Returns the hour the Alarm will fire.

Hours are specified by integers from 0 to 23.

public int getMinute()

Returns the minute the Alarm will fire.

Minutes are specified by integers from 0 to 59.

public java.lang.String getBlackoutPeriodStartDate()

Returns the start date of the blackout period in ISO 8601 format. E.g.: 2022-01-14

A blackout period means the Alarm will not fire during this period.

If not set, then it indicates that the blackout period has no start time.

If neither blackoutPeriodStartDate and blackoutPeriodEndDate are set, then the blackout period is not defined.

public java.lang.String getBlackoutPeriodEndDate()

Returns the end time for the blackout period in ISO 8601 format. E.g.: 2022-01-14

A blackout period means the Alarm will not fire during this period.

If not set, then it indicates that the blackout period has no end time.

If neither blackoutPeriodStartDate and blackoutPeriodEndDate are set, then the blackout period is not defined.

public java.lang.String getRingtone()

Returns the ringtone as a content URI to be played, or if no ringtone will be played.

public boolean shouldVibrate()

Returns whether or not to activate the device vibrator when the Alarm fires.

public AlarmInstance getPreviousInstance()

Returns the previous AlarmInstance.

The previous AlarmInstance is most recent past instance that was fired. If there are no past instances, then null will be returned.

See AlarmInstance.

public AlarmInstance getNextInstance()

Returns the next AlarmInstance.

The next AlarmInstance is the immediate future instance that is scheduled to fire. If there are no future instances, then null will be returned.

See AlarmInstance.

public int getOriginatingDevice()

Returns the Alarm.OriginatingDevice this alarm belongs to.

Source

/*
 * Copyright 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.appsearch.builtintypes;

import androidx.annotation.IntDef;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.appsearch.annotation.Document;
import androidx.appsearch.utils.DateTimeFormatValidator;
import androidx.core.util.Preconditions;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Calendar;
import java.util.List;

/**
 * AppSearch document representing an {@link Alarm} entity.
 */
@Document(name = "builtin:Alarm")
public class Alarm extends Thing {
    /** The device that this {@link Alarm} belongs to. */
    @RestrictTo(RestrictTo.Scope.LIBRARY)
    @IntDef({
            ORIGINATING_DEVICE_UNKNOWN,
            ORIGINATING_DEVICE_SMART_PHONE,
            ORIGINATING_DEVICE_SMART_WATCH})
    @Retention(RetentionPolicy.SOURCE)
    public @interface OriginatingDevice {}
    /** The {@link Alarm} belongs to an unknown device. */
    public static final int ORIGINATING_DEVICE_UNKNOWN = 0;
    /** The {@link Alarm} belongs to a smart phone device. */
    public static final int ORIGINATING_DEVICE_SMART_PHONE = 1;
    /** The {@link Alarm} belongs to a smart watch device. */
    public static final int ORIGINATING_DEVICE_SMART_WATCH = 2;

    @Document.BooleanProperty
    private final boolean mEnabled;

    @Document.LongProperty
    private final int[] mDaysOfWeek;

    @Document.LongProperty
    private final int mHour;

    @Document.LongProperty
    private final int mMinute;

    @Document.StringProperty
    private final String mBlackoutPeriodStartDate;

    @Document.StringProperty
    private final String mBlackoutPeriodEndDate;

    @Document.StringProperty
    private final String mRingtone;

    @Document.BooleanProperty
    private final boolean mShouldVibrate;

    @Document.DocumentProperty
    private final AlarmInstance mPreviousInstance;

    @Document.DocumentProperty
    private final AlarmInstance mNextInstance;

    // This property was originally released as computingDevice, and the old name is maintained for
    // compatibility with existing documents. Since the field is not indexed, the impact is limited
    // to use of this field as a property path for projections and inheritance.
    // If this limitation causes problems, we should add the mComputingDevice field back, mark it
    // deprecated, leave it in the API surface, and provide a migrator for convenience of upgrading.
    @Document.LongProperty(name = "computingDevice")
    private final int mOriginatingDevice;

    Alarm(@NonNull String namespace, @NonNull String id, int documentScore,
            long creationTimestampMillis, long documentTtlMillis, @Nullable String name,
            @Nullable List<String> alternateNames, @Nullable String description,
            @Nullable String image, @Nullable String url,
            @NonNull List<PotentialAction> potentialActions,
            boolean enabled, @Nullable int[] daysOfWeek, int hour, int minute,
            @Nullable String blackoutPeriodStartDate, @Nullable String blackoutPeriodEndDate,
            @Nullable String ringtone, boolean shouldVibrate,
            @Nullable AlarmInstance previousInstance, @Nullable AlarmInstance nextInstance,
            int originatingDevice) {
        super(namespace, id, documentScore, creationTimestampMillis, documentTtlMillis, name,
                alternateNames, description, image, url, potentialActions);
        mEnabled = enabled;
        mDaysOfWeek = daysOfWeek;
        mHour = hour;
        mMinute = minute;
        mBlackoutPeriodStartDate = blackoutPeriodStartDate;
        mBlackoutPeriodEndDate = blackoutPeriodEndDate;
        mRingtone = ringtone;
        mShouldVibrate = shouldVibrate;
        mPreviousInstance = previousInstance;
        mNextInstance = nextInstance;
        mOriginatingDevice = originatingDevice;
    }

    /** Returns whether or not the {@link Alarm} is active. */
    public boolean isEnabled() {
        return mEnabled;
    }

    /**
     * Returns the scheduled days for repeating.
     *
     * <p>Days of the week can be {@link java.util.Calendar#MONDAY},
     * {@link java.util.Calendar#TUESDAY}, {@link java.util.Calendar#WEDNESDAY},
     * {@link java.util.Calendar#THURSDAY}, {@link java.util.Calendar#FRIDAY},
     * {@link java.util.Calendar#SATURDAY}, or {@link java.util.Calendar#SUNDAY}.
     *
     * <p>If null, or if the list is empty, then the {@link Alarm} does not repeat.
     */
    @Nullable
    public int[] getDaysOfWeek() {
        return mDaysOfWeek;
    }

    /**
     * Returns the hour the {@link Alarm} will fire.
     *
     * <p>Hours are specified by integers from 0 to 23.
     */
    @IntRange(from = 0, to = 23)
    public int getHour() {
        return mHour;
    }

    /**
     * Returns the minute the {@link Alarm} will fire.
     *
     * <p>Minutes are specified by integers from 0 to 59.
     */
    @IntRange(from = 0, to = 59)
    public int getMinute() {
        return mMinute;
    }

    /**
     * Returns the start date of the blackout period in ISO 8601 format.
     * E.g.: 2022-01-14
     *
     * <p>A blackout period means the {@link Alarm} will not fire during this period.
     *
     * <p>If not set, then it indicates that the blackout period has no start time.
     *
     * <p>If neither blackoutPeriodStartDate and blackoutPeriodEndDate are set, then
     * the blackout period is not defined.
     */
    @Nullable
    public String getBlackoutPeriodStartDate() {
        return mBlackoutPeriodStartDate;
    }

    /**
     * Returns the end time for the blackout period in ISO 8601 format.
     * E.g.: 2022-01-14
     *
     * <p>A blackout period means the {@link Alarm} will not fire during this period.
     *
     * <p>If not set, then it indicates that the blackout period has no end time.
     *
     * <p>If neither blackoutPeriodStartDate and blackoutPeriodEndDate are set, then
     * the blackout period is not defined.
     */
    @Nullable
    public String getBlackoutPeriodEndDate() {
        return mBlackoutPeriodEndDate;
    }

    /**
     * Returns the ringtone as a content URI to be played, or
     * {@link android.provider.AlarmClock#VALUE_RINGTONE_SILENT} if no ringtone will be played.
     */
    @Nullable
    public String getRingtone() {
        return mRingtone;
    }

    /** Returns whether or not to activate the device vibrator when the {@link Alarm} fires. */
    public boolean shouldVibrate() {
        return mShouldVibrate;
    }

    /**
     * Returns the previous {@link AlarmInstance}.
     *
     * <p>The previous {@link AlarmInstance} is most recent past instance that was fired. If
     * there are no past instances, then null will be returned.
     *
     * <p>See {@link AlarmInstance}.
     */
    @Nullable
    public AlarmInstance getPreviousInstance() {
        return mPreviousInstance;
    }

    /**
     * Returns the next {@link AlarmInstance}.
     *
     * <p>The next {@link AlarmInstance} is the immediate future instance that is scheduled to fire.
     * If there are no future instances, then null will be returned.
     *
     * <p>See {@link AlarmInstance}.
     */
    @Nullable
    public AlarmInstance getNextInstance() {
        return mNextInstance;
    }

    /** Returns the {@link OriginatingDevice} this alarm belongs to. */
    @OriginatingDevice
    public int getOriginatingDevice() {
        return mOriginatingDevice;
    }

    /** Builder for {@link Alarm}. */
    @Document.BuilderProducer
    public static final class Builder extends BuilderImpl<Builder> {
        /**
         * Constructor for {@link Alarm.Builder}.
         *
         * @param namespace Namespace for the Document. See
         * {@link Document.Namespace}.
         * @param id Unique identifier for the Document. See {@link Document.Id}.
         */
        public Builder(@NonNull String namespace, @NonNull String id) {
            super(namespace, id);
        }

        /**
         * Constructor with all the existing values.
         */
        public Builder(@NonNull Alarm alarm) {
            super(alarm);
        }
    }

    @SuppressWarnings("unchecked")
    static class BuilderImpl<T extends BuilderImpl<T>> extends Thing.BuilderImpl<T> {
        protected boolean mEnabled;
        protected int[] mDaysOfWeek;
        protected int mHour;
        protected int mMinute;
        protected String mBlackoutPeriodStartDate;
        protected String mBlackoutPeriodEndDate;
        protected String mRingtone;
        protected boolean mShouldVibrate;
        protected AlarmInstance mPreviousInstance;
        protected AlarmInstance mNextInstance;
        protected int mOriginatingDevice;

        BuilderImpl(@NonNull String namespace, @NonNull String id) {
            super(namespace, id);
        }

        BuilderImpl(@NonNull Alarm alarm) {
            super(new Thing.Builder(alarm).build());
            mEnabled = alarm.isEnabled();
            mDaysOfWeek = alarm.getDaysOfWeek();
            mHour = alarm.getHour();
            mMinute = alarm.getMinute();
            mBlackoutPeriodStartDate = alarm.getBlackoutPeriodStartDate();
            mBlackoutPeriodEndDate = alarm.getBlackoutPeriodEndDate();
            mRingtone = alarm.getRingtone();
            mShouldVibrate = alarm.shouldVibrate();
            mPreviousInstance = alarm.getPreviousInstance();
            mNextInstance = alarm.getNextInstance();
            mOriginatingDevice = alarm.getOriginatingDevice();
        }

        /** Sets whether or not the {@link Alarm} is active. */
        @NonNull
        public T setEnabled(boolean enabled) {
            mEnabled = enabled;
            return (T) this;
        }

        /**
         * Sets the scheduled days for repeating.
         *
         * <p>Days of the week can be {@link java.util.Calendar#MONDAY},
         * {@link java.util.Calendar#TUESDAY}, {@link java.util.Calendar#WEDNESDAY},
         * {@link java.util.Calendar#THURSDAY}, {@link java.util.Calendar#FRIDAY},
         * {@link java.util.Calendar#SATURDAY}, or {@link java.util.Calendar#SUNDAY}.
         *
         * <p>If not set, or if the list is empty, then the {@link Alarm} does not repeat.
         */
        @NonNull
        public T setDaysOfWeek(
                @Nullable
                @IntRange(from = Calendar.SUNDAY, to = Calendar.SATURDAY) int... daysOfWeek) {
            if (daysOfWeek != null) {
                for (int day : daysOfWeek) {
                    Preconditions.checkArgumentInRange(day, Calendar.SUNDAY, Calendar.SATURDAY,
                            "daysOfWeek");
                }
            }
            mDaysOfWeek = daysOfWeek;
            return (T) this;
        }

        /**
         * Sets the hour the {@link Alarm} will fire.
         *
         * <p>Hours are specified by integers from 0 to 23.
         */
        @NonNull
        public T setHour(@IntRange(from = 0, to = 23) int hour) {
            mHour = Preconditions.checkArgumentInRange(hour, 0, 23, "hour");
            return (T) this;
        }

        /**
         * Sets the minute the {@link Alarm} will fire.
         *
         * <p>Minutes are specified by integers from 0 to 59.
         */
        @NonNull
        public T setMinute(@IntRange(from = 0, to = 59) int minute) {
            mMinute = Preconditions.checkArgumentInRange(minute, 0, 59, "minute");
            return (T) this;
        }

        /**
         * Sets the start date for the blackout period in ISO 8601 format.
         * E.g.: 2022-01-14
         *
         * <p>A blackout period means the {@link Alarm} will not fire during this period.
         *
         * <p>If not set, then it indicates that the blackout period has no start time.
         *
         * <p>If neither blackoutPeriodStartDate and blackoutPeriodEndDate are set, then
         * the blackout period is not defined.
         */
        @NonNull
        public T setBlackoutPeriodStartDate(
                @Nullable String blackoutPeriodStartDate) {
            if (blackoutPeriodStartDate != null) {
                Preconditions.checkArgument(
                        DateTimeFormatValidator.validateISO8601Date(blackoutPeriodStartDate),
                        "blackoutPeriodStartDate must be in the format: yyyy-MM-dd");
            }
            mBlackoutPeriodStartDate = blackoutPeriodStartDate;
            return (T) this;
        }

        /**
         * Sets the end time for the blackout period in ISO 8601 format.
         * E.g.: 2022-01-14
         *
         * <p>A blackout period means the {@link Alarm} will not fire during this period.
         *
         * <p>If not set, then it indicates that the blackout period has no end time.
         *
         * <p>If neither blackoutPeriodStartDate and blackoutPeriodEndDate are set, then
         * the blackout period is not defined.
         */
        @NonNull
        public T setBlackoutPeriodEndDate(@Nullable String blackoutPeriodEndDate) {
            if (blackoutPeriodEndDate != null) {
                Preconditions.checkArgument(
                        DateTimeFormatValidator.validateISO8601Date(blackoutPeriodEndDate),
                        "blackoutPeriodEndDate must be in the format: yyyy-MM-dd");
            }
            mBlackoutPeriodEndDate = blackoutPeriodEndDate;
            return (T) this;
        }

        /**
         * Sets the content URI for the ringtone to be played, or
         * {@link android.provider.AlarmClock#VALUE_RINGTONE_SILENT} if no ringtone will be played.
         */
        @NonNull
        public T setRingtone(@Nullable String ringtone) {
            mRingtone = ringtone;
            return (T) this;
        }

        /** Sets whether or not to activate the device vibrator when the {@link Alarm} fires. */
        @NonNull
        public T setShouldVibrate(boolean shouldVibrate) {
            mShouldVibrate = shouldVibrate;
            return (T) this;
        }

        /**
         * Sets the previous {@link AlarmInstance}.
         *
         * <p>The previous {@link AlarmInstance} is most recent past instance that was fired. If
         * not set, then there are no past instances.
         *
         * <p>See {@link AlarmInstance}.
         */
        @NonNull
        public T setPreviousInstance(@Nullable AlarmInstance previousInstance) {
            mPreviousInstance = previousInstance;
            return (T) this;
        }

        /**
         * Sets the next {@link AlarmInstance}.
         *
         * <p>The next {@link AlarmInstance} is the immediate future instance that is scheduled
         * to fire. If not set, then there are no future instances.
         *
         * <p>See {@link AlarmInstance}.
         */
        @NonNull
        public T setNextInstance(@Nullable AlarmInstance nextInstance) {
            mNextInstance = nextInstance;
            return (T) this;
        }

        /** Sets the {@link OriginatingDevice} this alarm belongs to. */
        @NonNull
        public T setOriginatingDevice(@OriginatingDevice int originatingDevice) {
            mOriginatingDevice = originatingDevice;
            return (T) this;
        }

        /** Builds the {@link Alarm}. */
        @NonNull
        @Override
        public Alarm build() {
            return new Alarm(mNamespace, mId, mDocumentScore, mCreationTimestampMillis,
                    mDocumentTtlMillis, mName, mAlternateNames, mDescription, mImage, mUrl,
                    mPotentialActions,
                    mEnabled, mDaysOfWeek, mHour, mMinute, mBlackoutPeriodStartDate,
                    mBlackoutPeriodEndDate, mRingtone, mShouldVibrate, mPreviousInstance,
                    mNextInstance, mOriginatingDevice);
        }
    }
}