1+ package com.omega_r.libs.omegaintentbuilder.builders
2+
3+ import android.content.Context
4+ import android.content.Intent
5+ import android.provider.AlarmClock.*
6+
7+ class AlarmIntentBuilder : BaseActivityBuilder () {
8+ private var message: String? = null
9+ private var hour: Int? = null
10+ private var minutes: Int? = null
11+ private var ringtone: String? = null
12+ private var skipUI: Boolean = false
13+ private var vibrate: Boolean? = null
14+ private var ringtoneSilent: Boolean = false
15+
16+ /* *
17+ * Set custom message for the alarm.
18+ * <p>
19+ * The value is a {@link String}.
20+ * </p>
21+ *
22+ * @param message String
23+ * @return This AlarmIntentBuilder for method chaining
24+ */
25+ fun message (message : String ): AlarmIntentBuilder {
26+ this .message = message
27+ return this
28+ }
29+
30+ /* *
31+ * Set the hour of the alarm.
32+ * <p>
33+ * The value is an {@link Integer} and ranges from 1 to 86400 (24 hours).
34+ * </p>
35+ *
36+ * @param hour String
37+ * @return This AlarmIntentBuilder for method chaining
38+ */
39+ fun hour (hour : Int ): AlarmIntentBuilder {
40+ this .hour = hour
41+ return this
42+ }
43+
44+ /* *
45+ * Set the minutes of the alarm.
46+ *
47+ * @param minutes String
48+ * @return This AlarmIntentBuilder for method chaining
49+ */
50+ fun minutes (minutes : Int ): AlarmIntentBuilder {
51+ this .minutes = minutes
52+ return this
53+ }
54+
55+ /* *
56+ * Set a ringtone to be played with this alarm.
57+ *
58+ * This value is a {@link String} and can either be set to {@link #VALUE_RINGTONE_SILENT} or
59+ * to a content URI of the media to be played. If not specified or the URI doesn't exist,
60+ * {@code "content://settings/system/alarm_alert} will be used.
61+ *
62+ * @param ringtone String
63+ * @return This AlarmIntentBuilder for method chaining
64+ */
65+ fun ringtone (ringtone : String ): AlarmIntentBuilder {
66+ this .ringtone = ringtone
67+ return this
68+ }
69+
70+ /* *
71+ * If true, the application is asked to bypass any intermediate UI. If false, the application
72+ * may display intermediate UI like a confirmation dialog or settings.
73+ *
74+ * @return This AlarmIntentBuilder for method chaining
75+ */
76+ fun skipUI (): AlarmIntentBuilder {
77+ skipUI = true
78+ return this
79+ }
80+
81+ /* *
82+ * Set whether or not to activate the device vibrator.
83+ *
84+ * The value is a {@link Boolean}. The default is {@code true}.
85+ *
86+ * @return This AlarmIntentBuilder for method chaining
87+ */
88+ @JvmOverloads
89+ fun vibrate (vibrate : Boolean = true): AlarmIntentBuilder {
90+ this .vibrate = vibrate
91+ return this
92+ }
93+
94+ /* *
95+ * Bundle extra value: Indicates no ringtone should be played.
96+ *
97+ * @return This AlarmIntentBuilder for method chaining
98+ */
99+ fun ringtoneSilent (): AlarmIntentBuilder {
100+ ringtoneSilent = true
101+ return this
102+ }
103+
104+ override fun createIntent (context : Context ): Intent {
105+ return Intent (ACTION_SET_ALARM ).apply {
106+ message?.let {
107+ putExtra(EXTRA_MESSAGE , it)
108+ }
109+
110+ hour?.let {
111+ putExtra(EXTRA_HOUR , it)
112+ }
113+
114+ minutes?.let {
115+ putExtra(EXTRA_MINUTES , it)
116+ }
117+
118+ ringtone?.let {
119+ putExtra(EXTRA_RINGTONE , it)
120+ }
121+
122+ if (skipUI) {
123+ putExtra(EXTRA_SKIP_UI , skipUI)
124+ }
125+
126+ vibrate?.let {
127+ putExtra(EXTRA_VIBRATE , it)
128+ }
129+
130+ if (ringtoneSilent) {
131+ putExtra(VALUE_RINGTONE_SILENT , ringtoneSilent)
132+ }
133+
134+ }
135+ }
136+
137+ }
0 commit comments