Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,10 @@ object OmegaIntentBuilder {
@JvmStatic
fun recordVideo() = VideoRecordBuilder()

/**
* @return DismissAlarmIntentBuilder
*/
@JvmStatic
@RequiresApi(Build.VERSION_CODES.M)
fun dismissAlarm() = DismissAlarmIntentBuilder()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alarm(): AlarmIntentBuilder

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package com.omega_r.libs.omegaintentbuilder.builders

import android.content.Context
import android.content.Intent
import android.provider.AlarmClock.*

class DismissAlarmIntentBuilder : BaseActivityBuilder() {

private var hour: Int? = null
private var minute: Int? = null
private var isPM: Boolean? = null
private var label: String? = null
private var next: Boolean? = null

/**
* </p><p>
* The value is an {@link Integer} and ranges from 0 to 23.
* </p>
*
* @param hour Integer
* @return This DismissAlarmIntentBuilder for method chaining
*/
fun hour(hour: Int): DismissAlarmIntentBuilder {
label = null
next = null
this.hour = hour
return this
}

/**
* <p>
* The value is an {@link Integer} and ranges from 0 to 59. If not provided, it defaults to 0.
* </p>
*
* @param minute Integer
* @return This DismissAlarmIntentBuilder for method chaining
*/
fun minute(minute: Int): DismissAlarmIntentBuilder {
label = null
next = null
this.minute = minute
return this
}

/**
* <p>
* The value is an {@link Integer} and ranges from 0 to 59. If not provided, it defaults to 0.
* </p>
*
* @param isPM Integer
* @return This DismissAlarmIntentBuilder for method chaining
*/
fun isPM(isPM: Boolean): DismissAlarmIntentBuilder {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isPm

label = null
next = null
this.isPM = isPM
return this
}

/**
* Search alarm by label
*
* @param label String
* @return This DismissAlarmIntentBuilder for method chaining
*/
fun label(label: String): DismissAlarmIntentBuilder {
hour = null
minute = null
isPM = null
next = null
this.label = label
return this
}

/**
* For activate search mode NEXT
* Search next alarm
*
* @return This DismissAlarmIntentBuilder for method chaining
*/
fun next(): DismissAlarmIntentBuilder {
next = true
return this
}

/**
* <li>If exactly one active alarm exists, it is dismissed.
* <li>If more than one active alarm exists, the user is prompted to choose the alarm to
* dismiss.
*/
override fun createIntent(context: Context): Intent {
return Intent(ACTION_DISMISS_ALARM).apply {
if (hour != null && minute != null && isPM != null) {
putExtra(EXTRA_ALARM_SEARCH_MODE, ALARM_SEARCH_MODE_TIME)

hour?.let {
putExtra(EXTRA_HOUR, it)
}

minute?.let {
putExtra(EXTRA_MINUTES, it)
}

isPM?.let {
putExtra(EXTRA_IS_PM, it)
}
} else if (label != null) {
putExtra(EXTRA_ALARM_SEARCH_MODE, ALARM_SEARCH_MODE_LABEL)
putExtra(EXTRA_MESSAGE, label)
} else if (next != null) {
putExtra(EXTRA_ALARM_SEARCH_MODE, ALARM_SEARCH_MODE_NEXT)
} else {
putExtra(EXTRA_ALARM_SEARCH_MODE, ALARM_SEARCH_MODE_ALL)
}


}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ protected void onCreate(Bundle savedInstanceState) {
findViewById(R.id.button_show_timers).setOnClickListener(this);
findViewById(R.id.button_show_alarms).setOnClickListener(this);
findViewById(R.id.button_record_video).setOnClickListener(this);
findViewById(R.id.button_dismiss_alarm).setOnClickListener(this);
}

@Override
Expand Down Expand Up @@ -121,6 +122,9 @@ public void onClick(View v) {
case R.id.button_record_video:
onRecordVideoClicked();
break;
case R.id.button_dismiss_alarm:
onDismissAlarmClicked();
break;
}
}

Expand Down Expand Up @@ -343,4 +347,19 @@ private void onRecordVideoClicked() {
.startActivity(this);
}

private void onDismissAlarmClicked() {
OmegaIntentBuilder
.dismissAlarm()
//BY LABEL
//.label("It's your alarm")
//or BY TIME
//.hour(0)
//.minute(0)
//.isPM(true)
//or DISMISS NEXT
//.next()
//or SEARCH ALL
.startActivity(this);
}

}
7 changes: 7 additions & 0 deletions examples/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@
android:theme="@style/ButtonStyle"
android:text="@string/record_video"/>

<Button
android:id="@+id/button_dismiss_alarm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ButtonStyle"
android:text="@string/dismiss_alarm"/>

</LinearLayout>

</androidx.core.widget.NestedScrollView>
1 change: 1 addition & 0 deletions examples/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@
<string name="show_alarms">Show Alarms</string>
<string name="open_camera_to_record">Open Camera To Record</string>
<string name="record_video">Record Video</string>
<string name="dismiss_alarm">Dismiss Alarm</string>
</resources>