From a2765eef60e57ac4db6fdb573c51b683801f23af Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Sun, 14 May 2023 17:26:39 -0700 Subject: [PATCH] Add touch sound api --- app/src/main/java/gallery/memories/MainActivity.kt | 2 +- app/src/main/java/gallery/memories/NativeX.kt | 8 ++++++++ app/src/main/res/layout/activity_main.xml | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/gallery/memories/MainActivity.kt b/app/src/main/java/gallery/memories/MainActivity.kt index 75f9b3ac..51fee267 100644 --- a/app/src/main/java/gallery/memories/MainActivity.kt +++ b/app/src/main/java/gallery/memories/MainActivity.kt @@ -17,7 +17,7 @@ import androidx.media3.exoplayer.hls.HlsMediaSource import gallery.memories.databinding.ActivityMainBinding @UnstableApi class MainActivity : AppCompatActivity() { - private val binding by lazy(LazyThreadSafetyMode.NONE) { + val binding by lazy(LazyThreadSafetyMode.NONE) { ActivityMainBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/gallery/memories/NativeX.kt b/app/src/main/java/gallery/memories/NativeX.kt index 430282d5..b8f8ad7a 100644 --- a/app/src/main/java/gallery/memories/NativeX.kt +++ b/app/src/main/java/gallery/memories/NativeX.kt @@ -5,6 +5,7 @@ import android.graphics.Color import android.net.Uri import android.os.Build import android.util.Log +import android.view.SoundEffectConstants import android.view.View import android.view.WindowInsetsController import android.webkit.JavascriptInterface @@ -104,6 +105,13 @@ import java.net.URLDecoder mDlService!!.queue(url, filename) } + @JavascriptInterface + fun playTouchSound() { + mActivity.runOnUiThread { + mActivity.binding.webview.playSoundEffect(SoundEffectConstants.CLICK) + } + } + @JavascriptInterface fun playVideoLocal(fileId: String?) { if (fileId == null) return; diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 4a29b5ec..a63f210f 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -17,6 +17,7 @@ android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="match_parent" + android:soundEffectsEnabled="true" /> \ No newline at end of file