Skip to content

Commit b1f6af9

Browse files
Merge pull request #111 from Omega-R/feature/timer_intent_builder
Feature/timer intent builder
2 parents d27a025 + c1f9910 commit b1f6af9

6 files changed

Lines changed: 93 additions & 0 deletions

File tree

core/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<uses-permission android:name="android.permission.INTERNET"/>
66
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
77
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
8+
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
89

910
<application>
1011
<provider

core/src/main/java/com/omega_r/libs/omegaintentbuilder/OmegaIntentBuilder.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ package com.omega_r.libs.omegaintentbuilder
1414
import android.app.Activity
1515
import android.app.Service
1616
import android.net.Uri
17+
import android.os.Build
18+
import androidx.annotation.RequiresApi
1719
import com.omega_r.libs.omegaintentbuilder.builders.*
1820
import com.omega_r.libs.omegaintentbuilder.builders.pick.PickBuilder
1921
import com.omega_r.libs.omegaintentbuilder.builders.share.EmailIntentBuilder
@@ -141,6 +143,13 @@ object OmegaIntentBuilder {
141143
@JvmStatic
142144
fun insertContact() = InsertContactIntentBuilder()
143145

146+
/**
147+
* @return AlarmIntentBuilder
148+
*/
149+
@JvmStatic
150+
@RequiresApi(Build.VERSION_CODES.KITKAT)
151+
fun createTimer() = TimerIntentBuilder()
152+
144153
/**
145154
* @return SearchWebIntentBuilder
146155
*/
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 TimerIntentBuilder : BaseActivityBuilder() {
8+
private var message: String? = null
9+
private var seconds: Int? = null
10+
private var skipUI: Boolean? = null
11+
12+
/**
13+
* Set custom message for the timer.
14+
* <p>
15+
* The value is a {@link String}.
16+
* </p>
17+
*
18+
* @param message String
19+
* @return This TimerIntentBuilder for method chaining
20+
*/
21+
fun message(message: String): TimerIntentBuilder {
22+
this.message = message
23+
return this
24+
}
25+
26+
/**
27+
* Set the length of the timer in seconds.
28+
*
29+
* @param seconds String
30+
* @return This TimerIntentBuilder for method chaining
31+
*/
32+
fun seconds(seconds: Int): TimerIntentBuilder {
33+
this.seconds = seconds
34+
return this
35+
}
36+
37+
/**
38+
* Bundle extra: Whether or not to display an activity after performing the action.
39+
* If true, the application is asked to bypass any intermediate UI. If false, the application
40+
* may display intermediate UI like a confirmation dialog or settings.
41+
*
42+
* @param skipUI Boolean
43+
* @return This TimerIntentBuilder for method chaining
44+
*/
45+
fun skipUI(skipUI: Boolean): TimerIntentBuilder {
46+
this.skipUI = skipUI
47+
return this
48+
}
49+
50+
override fun createIntent(context: Context): Intent {
51+
return Intent(ACTION_SET_TIMER).apply {
52+
message?.let {
53+
putExtra(EXTRA_MESSAGE, it)
54+
}
55+
56+
seconds?.let {
57+
putExtra(EXTRA_LENGTH, it)
58+
}
59+
60+
skipUI?.let {
61+
putExtra(EXTRA_SKIP_UI, it)
62+
}
63+
64+
}
65+
}
66+
67+
}

examples/src/main/java/com/omega_r/omegaintentbuilder/MainActivity.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,12 @@ private void onSearchWebClicked() {
287287
.startActivity(this);
288288
}
289289

290+
private void onCreateTimerClicked() {
291+
OmegaIntentBuilder
292+
.createTimer()
293+
.message("It's your timer")
294+
.seconds(5)
295+
.startActivity(this);
296+
}
297+
290298
}

examples/src/main/res/layout/activity_main.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@
153153
android:theme="@style/ButtonStyle"
154154
android:text="@string/insert_contact"/>
155155

156+
<Button
157+
android:id="@+id/button_create_timer"
158+
android:layout_width="match_parent"
159+
android:layout_height="wrap_content"
160+
android:theme="@style/ButtonStyle"
161+
android:text="@string/create_timer"/>
162+
156163
</LinearLayout>
157164

158165
</androidx.core.widget.NestedScrollView>

examples/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<string name="service_extra">Extras to Service</string>
2222
<string name="title_activity_tab">TabActivity</string>
2323
<string name="fragment_extra">Extras to Fragment</string>
24+
<string name="create_timer">Create Timer</string>
2425
<string name="insert_contact">Insert Contact</string>
2526
<string name="search_web">Search Web</string>
2627
</resources>

0 commit comments

Comments
 (0)