mirror of
https://github.com/kichikuou/system3-sdl2.git
synced 2026-09-30 02:48:10 +03:00
Android: Add system menu
The system menu opens with 3-finger touch. Currently, it can only exit the game.
This commit is contained in:
@@ -22,6 +22,10 @@ import android.media.MediaPlayer
|
||||
import android.os.Bundle
|
||||
import android.text.InputType
|
||||
import android.util.Log
|
||||
import android.view.ContextMenu
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.EditText
|
||||
import org.libsdl.app.SDLActivity
|
||||
import java.io.File
|
||||
@@ -44,6 +48,7 @@ class GameActivity : SDLActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
gameRoot = File(intent.getStringExtra(EXTRA_GAME_ROOT))
|
||||
cdda = CddaPlayer(File(gameRoot, Launcher.PLAYLIST_FILE))
|
||||
registerForContextMenu(mLayout)
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
@@ -97,6 +102,34 @@ class GameActivity : SDLActivity() {
|
||||
.show()
|
||||
}
|
||||
|
||||
private var menuShown = false
|
||||
private fun openMenu() {
|
||||
if (menuShown)
|
||||
return
|
||||
openContextMenu(mLayout)
|
||||
menuShown = true
|
||||
}
|
||||
|
||||
override fun onCreateContextMenu(menu: ContextMenu?, v: View?, menuInfo: ContextMenu.ContextMenuInfo?) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo)
|
||||
menuInflater.inflate(R.menu.game_menu, menu)
|
||||
}
|
||||
|
||||
override fun onContextItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.quit_game -> {
|
||||
finish()
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onContextMenuClosed(menu: Menu?) {
|
||||
super.onContextMenuClosed(menu)
|
||||
menuShown = false
|
||||
}
|
||||
|
||||
// The functions below are called in the SDL thread by JNI.
|
||||
@Suppress("unused") fun cddaStart(track: Int, loop: Boolean) = cdda.start(track, loop)
|
||||
@Suppress("unused") fun cddaStop() = cdda.stop()
|
||||
@@ -118,6 +151,10 @@ class GameActivity : SDLActivity() {
|
||||
}
|
||||
return result[0]
|
||||
}
|
||||
|
||||
@Suppress("unused") fun popupMenu() {
|
||||
runOnUiThread { openMenu() }
|
||||
}
|
||||
}
|
||||
|
||||
private class CddaPlayer(private val playlistPath: File) {
|
||||
|
||||
Reference in New Issue
Block a user