From a1fcc330533f3d7611f091b1da08c02188dc032f Mon Sep 17 00:00:00 2001 From: kichikuou Date: Mon, 3 Jan 2022 17:36:08 +0900 Subject: [PATCH] Android: Stop using deprecated ListActivity --- .../kichikuou/system3/LauncherActivity.kt | 21 ++++++++++++------- android/app/src/main/res/layout/launcher.xml | 9 ++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 android/app/src/main/res/layout/launcher.xml diff --git a/android/app/src/main/java/io/github/kichikuou/system3/LauncherActivity.kt b/android/app/src/main/java/io/github/kichikuou/system3/LauncherActivity.kt index fddf9ae..2e12edd 100644 --- a/android/app/src/main/java/io/github/kichikuou/system3/LauncherActivity.kt +++ b/android/app/src/main/java/io/github/kichikuou/system3/LauncherActivity.kt @@ -23,8 +23,6 @@ import android.os.Bundle import android.util.Log import android.view.Menu import android.view.MenuItem -import android.view.View -import android.widget.AdapterView import android.widget.ArrayAdapter import android.widget.ListView import android.widget.Toast @@ -35,12 +33,13 @@ private const val INSTALL_REQUEST = 1 private const val SAVEDATA_EXPORT_REQUEST = 2 private const val SAVEDATA_IMPORT_REQUEST = 3 -class LauncherActivity : ListActivity(), AdapterView.OnItemLongClickListener, LauncherObserver { +class LauncherActivity : Activity(), LauncherObserver { private lateinit var launcher: Launcher private var progressDialog: ProgressDialogFragment? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + setContentView(R.layout.launcher) launcher = Launcher.getInstance(filesDir) launcher.observer = this @@ -49,7 +48,13 @@ class LauncherActivity : ListActivity(), AdapterView.OnItemLongClickListener, La } onGameListChange() - listView.onItemLongClickListener = this + val listView = findViewById(R.id.list) + listView.setOnItemClickListener { _, _, position, _ -> + onListItemClick(position) + } + listView.setOnItemLongClickListener { _, _, position, _ -> + onItemLongClick(position) + } } override fun onDestroy() { @@ -57,8 +62,7 @@ class LauncherActivity : ListActivity(), AdapterView.OnItemLongClickListener, La super.onDestroy() } - override fun onListItemClick(l: ListView?, v: View?, position: Int, id: Long) { - super.onListItemClick(l, v, position, id) + private fun onListItemClick(position: Int) { if (position < launcher.games.size) { startGame(launcher.games[position].path) } else { @@ -68,7 +72,7 @@ class LauncherActivity : ListActivity(), AdapterView.OnItemLongClickListener, La } } - override fun onItemLongClick(a: AdapterView<*>?, v: View?, position: Int, id: Long): Boolean { + private fun onItemLongClick(position: Int): Boolean { if (position < launcher.games.size) { AlertDialog.Builder(this).setTitle(R.string.uninstall_dialog_title) .setMessage(getString(R.string.uninstall_dialog_message, launcher.games[position].title)) @@ -137,7 +141,8 @@ class LauncherActivity : ListActivity(), AdapterView.OnItemLongClickListener, La override fun onGameListChange() { val items = launcher.titles.toMutableList() items.add(getString(R.string.install_from_zip)) - listAdapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, items) + val listView = findViewById(R.id.list) + listView.adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, items) } override fun onInstallProgress(path: String) { diff --git a/android/app/src/main/res/layout/launcher.xml b/android/app/src/main/res/layout/launcher.xml new file mode 100644 index 0000000..18ef6a0 --- /dev/null +++ b/android/app/src/main/res/layout/launcher.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file