Skip to content

Commit

Permalink
Migrate Haptic and AudioManager Utilities to :ceres:core:foundation
Browse files Browse the repository at this point in the history
- Migrated the Haptic and AudioManager utilities from the `dev.teogor.ceres.ui.foundation` package to the `dev.teogor.ceres.core.foundation` package.
- Updated the usage of these utilities throughout the codebase to use the new methods provided by the `ceres:core:foundation` module.
  • Loading branch information
teogor committed Oct 1, 2023
1 parent b814a98 commit b104f01
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 189 deletions.
19 changes: 0 additions & 19 deletions ui/foundation/api/foundation.api
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
public final class dev/teogor/ceres/ui/foundation/HapticEffect : java/lang/Enum {
public static final field DEFAULT_AMPLITUDE Ldev/teogor/ceres/ui/foundation/HapticEffect;
public static final field EFFECT_CLICK Ldev/teogor/ceres/ui/foundation/HapticEffect;
public static final field EFFECT_DOUBLE_CLICK Ldev/teogor/ceres/ui/foundation/HapticEffect;
public static final field EFFECT_HEAVY_CLICK Ldev/teogor/ceres/ui/foundation/HapticEffect;
public static final field EFFECT_TICK Ldev/teogor/ceres/ui/foundation/HapticEffect;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public final fun getValue ()I
public static fun valueOf (Ljava/lang/String;)Ldev/teogor/ceres/ui/foundation/HapticEffect;
public static fun values ()[Ldev/teogor/ceres/ui/foundation/HapticEffect;
}

public final class dev/teogor/ceres/ui/foundation/ModifierExtensionsKt {
public static final fun clickable-GK2WfCU (Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/interaction/MutableInteractionSource;Landroidx/compose/foundation/Indication;ZLjava/lang/String;Landroidx/compose/ui/semantics/Role;ILkotlin/jvm/functions/Function0;)Landroidx/compose/ui/Modifier;
public static synthetic fun clickable-GK2WfCU$default (Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/interaction/MutableInteractionSource;Landroidx/compose/foundation/Indication;ZLjava/lang/String;Landroidx/compose/ui/semantics/Role;ILkotlin/jvm/functions/Function0;ILjava/lang/Object;)Landroidx/compose/ui/Modifier;
Expand All @@ -32,13 +20,6 @@ public final class dev/teogor/ceres/ui/foundation/TouchFeedbackKt {
public static synthetic fun withTouchFeedback$default (Lkotlin/jvm/functions/Function0;Landroid/content/Context;IILjava/lang/Object;)Lkotlin/jvm/functions/Function0;
}

public final class dev/teogor/ceres/ui/foundation/VibratorKt {
public static final fun getSystemService (Landroid/content/Context;Ljava/lang/Class;)Ljava/lang/Object;
public static final fun getVibrator (Landroid/content/Context;)Landroid/os/Vibrator;
public static final fun vibrate (Landroid/content/Context;JLdev/teogor/ceres/ui/foundation/HapticEffect;)V
public static synthetic fun vibrate$default (Landroid/content/Context;JLdev/teogor/ceres/ui/foundation/HapticEffect;ILjava/lang/Object;)V
}

public final class dev/teogor/ceres/ui/foundation/config/FeedbackConfig {
public static final field $stable I
public static final field INSTANCE Ldev/teogor/ceres/ui/foundation/config/FeedbackConfig;
Expand Down
1 change: 1 addition & 0 deletions ui/foundation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ android {

dependencies {
api(project(":core:startup"))
api(project(":core:foundation"))

api(libs.androidx.compose.foundation)
api(libs.androidx.compose.material)
Expand Down
4 changes: 1 addition & 3 deletions ui/foundation/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.VIBRATE" />
</manifest>
<manifest/>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package dev.teogor.ceres.ui.foundation

import android.content.Context
import android.media.AudioManager
import androidx.compose.foundation.Indication
import androidx.compose.foundation.LocalIndication
Expand All @@ -33,6 +32,9 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.debugInspectorInfo
import androidx.compose.ui.platform.inspectable
import androidx.compose.ui.semantics.Role
import dev.teogor.ceres.core.foundation.HapticEffect
import dev.teogor.ceres.core.foundation.audioManagerUtils
import dev.teogor.ceres.core.foundation.vibratorUtils
import dev.teogor.ceres.ui.foundation.config.FeedbackConfig

fun Modifier.clickable(
Expand All @@ -51,12 +53,11 @@ fun Modifier.clickable(
onClick()

if (!FeedbackConfig.disableAudioFeedback) {
(context.getSystemService(Context.AUDIO_SERVICE) as AudioManager)
.playSoundEffect(effectType)
context.audioManagerUtils().playSoundEffect(effectType)
}

if (!FeedbackConfig.disableVibrationFeedback) {
context.vibrate(
context.vibratorUtils().vibrate(
milliseconds = FeedbackConfig.vibrationFeedbackIntensity,
effect = HapticEffect.DEFAULT_AMPLITUDE,
)
Expand Down Expand Up @@ -85,12 +86,11 @@ fun Modifier.clickable(
onClick()

if (!FeedbackConfig.disableAudioFeedback) {
(context.getSystemService(Context.AUDIO_SERVICE) as AudioManager)
.playSoundEffect(effectType)
context.audioManagerUtils().playSoundEffect(effectType)
}

if (!FeedbackConfig.disableVibrationFeedback) {
context.vibrate(
context.vibratorUtils().vibrate(
milliseconds = FeedbackConfig.vibrationFeedbackIntensity,
effect = HapticEffect.DEFAULT_AMPLITUDE,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ package dev.teogor.ceres.ui.foundation

import android.content.Context
import android.media.AudioManager
import dev.teogor.ceres.core.foundation.HapticEffect
import dev.teogor.ceres.core.foundation.audioManagerUtils
import dev.teogor.ceres.core.foundation.vibratorUtils
import dev.teogor.ceres.core.startup.ApplicationContextProvider
import dev.teogor.ceres.ui.foundation.config.FeedbackConfig

Expand All @@ -26,12 +29,11 @@ fun (() -> Unit).withTouchFeedback(
effectType: Int = AudioManager.FX_KEY_CLICK,
): () -> Unit = {
if (!FeedbackConfig.disableAudioFeedback) {
(context.getSystemService(Context.AUDIO_SERVICE) as AudioManager)
.playSoundEffect(effectType)
context.audioManagerUtils().playSoundEffect(effectType)
}

if (!FeedbackConfig.disableVibrationFeedback) {
context.vibrate(
context.vibratorUtils().vibrate(
milliseconds = FeedbackConfig.vibrationFeedbackIntensity,
effect = HapticEffect.DEFAULT_AMPLITUDE,
)
Expand All @@ -45,12 +47,11 @@ fun applyTouchFeedback(
effectType: Int = AudioManager.FX_KEY_CLICK,
) {
if (!FeedbackConfig.disableAudioFeedback) {
(context.getSystemService(Context.AUDIO_SERVICE) as AudioManager)
.playSoundEffect(effectType)
context.audioManagerUtils().playSoundEffect(effectType)
}

if (!FeedbackConfig.disableVibrationFeedback) {
context.vibrate(
context.vibratorUtils().vibrate(
milliseconds = FeedbackConfig.vibrationFeedbackIntensity,
effect = HapticEffect.DEFAULT_AMPLITUDE,
)
Expand Down

This file was deleted.

0 comments on commit b104f01

Please sign in to comment.