-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new module that contains convenience Kotlin Time accessors to And…
…roid SDK APIs
- Loading branch information
Showing
14 changed files
with
131 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
plugins { | ||
id("android-library-base") | ||
id("kotlin-library-unit-test") | ||
id("android-library-release") | ||
} | ||
|
||
dependencies { | ||
api(project(":dachlatten-datetime")) | ||
|
||
compileOnly(libs.kotlinx.datetime) | ||
compileOnly(libs.androidx.core) | ||
compileOnly(libs.androidx.compose.animation) | ||
compileOnly(libs.android.support.annotations) | ||
|
||
testImplementation(libs.kotlinx.datetime) | ||
} |
11 changes: 11 additions & 0 deletions
11
...atten-datetime-android/src/main/kotlin/de/sipgate/dachlatten/datetime/AnimationSpecExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package de.sipgate.dachlatten.datetime | ||
|
||
import androidx.compose.animation.core.StartOffsetType | ||
import kotlin.time.Duration | ||
|
||
@Suppress("unused") | ||
fun StartOffset(offset: Duration, offsetType: StartOffsetType = StartOffsetType.Delay) = | ||
androidx.compose.animation.core.StartOffset( | ||
offsetMillis = offset.inWholeMilliseconds.toInt(), | ||
offsetType = offsetType | ||
) |
File renamed without changes.
28 changes: 28 additions & 0 deletions
28
dachlatten-datetime-android/src/main/kotlin/de/sipgate/dachlatten/datetime/HandlerExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package de.sipgate.dachlatten.datetime | ||
|
||
import android.os.Handler | ||
import kotlin.time.Duration | ||
import androidx.core.os.postDelayed | ||
|
||
/** | ||
* Version of [Handler.postDelayed] which re-orders the parameters, allowing the action to be placed | ||
* outside of parentheses and takes {Duration}s. | ||
* | ||
* ``` | ||
* handler.postDelayed(200.milliseconds) { | ||
* doSomething() | ||
* } | ||
* ``` | ||
* | ||
* @return the created Runnable | ||
*/ | ||
@Suppress("unused") | ||
inline fun Handler.postDelayed( | ||
delay: Duration, | ||
token: Any? = null, | ||
crossinline action: () -> Unit | ||
) = postDelayed( | ||
delayInMillis = delay.inWholeMilliseconds, | ||
token = token, | ||
action = action | ||
) |
12 changes: 12 additions & 0 deletions
12
...me-android/src/main/kotlin/de/sipgate/dachlatten/datetime/NotificationCompatBuilderExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package de.sipgate.dachlatten.datetime | ||
|
||
import androidx.core.app.NotificationCompat.Builder | ||
import kotlin.time.Duration | ||
|
||
@Suppress("unused") | ||
fun Builder.setTimeoutAfter(duration: Duration): Builder = | ||
setTimeoutAfter(duration.inWholeMilliseconds) | ||
|
||
@Suppress("unused") | ||
fun Builder.setVibrate(pattern: Array<Duration>?): Builder = | ||
setVibrate(pattern?.map { it.inWholeMilliseconds }?.toLongArray()) |
9 changes: 9 additions & 0 deletions
9
...atten-datetime-android/src/main/kotlin/de/sipgate/dachlatten/datetime/ToneGeneratorExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package de.sipgate.dachlatten.datetime | ||
|
||
import android.media.ToneGenerator | ||
import kotlin.time.Duration | ||
|
||
@Suppress("unused") | ||
fun ToneGenerator.startTone(toneType: Int, duration: Duration) = startTone( | ||
toneType, duration.inWholeMilliseconds.toInt() | ||
) |
8 changes: 8 additions & 0 deletions
8
...atten-datetime-android/src/main/kotlin/de/sipgate/dachlatten/datetime/ValueAnimatorExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package de.sipgate.dachlatten.datetime | ||
|
||
import android.animation.ValueAnimator | ||
import kotlin.time.Duration | ||
|
||
@Suppress("unused") | ||
fun ValueAnimator.setDuration(duration: Duration): ValueAnimator = | ||
setDuration(duration.inWholeMilliseconds) |
21 changes: 21 additions & 0 deletions
21
...e-android/src/main/kotlin/de/sipgate/dachlatten/datetime/VibrationEffectCompositionExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package de.sipgate.dachlatten.datetime | ||
|
||
import android.os.Build | ||
import android.os.VibrationEffect.Composition | ||
import androidx.annotation.FloatRange | ||
import androidx.annotation.RequiresApi | ||
import kotlin.time.Duration | ||
|
||
@Suppress("unused") | ||
@RequiresApi(Build.VERSION_CODES.R) | ||
fun Composition.addPrimitive( | ||
primitiveId: Int, | ||
@FloatRange(from = 0.0, to = 1.0) scale: Float, | ||
delay: Duration | ||
) { | ||
addPrimitive( | ||
/* primitiveId = */ primitiveId, | ||
/* scale = */ scale, | ||
/* delay = */ delay.inWholeMilliseconds.toInt() | ||
) | ||
} |
15 changes: 15 additions & 0 deletions
15
...ten-datetime-android/src/main/kotlin/de/sipgate/dachlatten/datetime/VibrationEffectExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package de.sipgate.dachlatten.datetime | ||
|
||
import android.os.Build | ||
import android.os.VibrationEffect | ||
import androidx.annotation.RequiresApi | ||
import kotlin.time.Duration | ||
|
||
@Suppress("unused") | ||
@RequiresApi(Build.VERSION_CODES.O) | ||
fun createWaveform(timings: Array<Duration>, amplitudes: IntArray, repeat: Int): VibrationEffect = | ||
VibrationEffect.createWaveform( | ||
/* timings = */ timings.map { it.inWholeMilliseconds }.toLongArray(), | ||
/* amplitudes = */ amplitudes, | ||
/* repeat = */ repeat | ||
) |
7 changes: 7 additions & 0 deletions
7
dachlatten-datetime-android/src/main/kotlin/de/sipgate/dachlatten/datetime/WakeLockExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package de.sipgate.dachlatten.datetime | ||
|
||
import android.os.PowerManager.WakeLock | ||
import kotlin.time.Duration | ||
|
||
@Suppress("unused") | ||
fun WakeLock.acquire(duration: Duration) = acquire(duration.inWholeMilliseconds) |
2 changes: 1 addition & 1 deletion
2
...ipgate/dachlatten/datetime/DateExtTest.kt → ...ipgate/dachlatten/datetime/DateExtTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters