diff options
author | Charles Lombardo <clombardo169@gmail.com> | 2023-03-08 03:13:50 +0100 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2023-06-03 09:05:37 +0200 |
commit | b10e13c090419fe2236cf02494d4c015dad07d87 (patch) | |
tree | 7161e1fd40f87a2fb963c2bdf844e8671ba7a2b5 /src | |
parent | android: Convert SubmenuViewHolder to Kotlin (diff) | |
download | yuzu-b10e13c090419fe2236cf02494d4c015dad07d87.tar yuzu-b10e13c090419fe2236cf02494d4c015dad07d87.tar.gz yuzu-b10e13c090419fe2236cf02494d4c015dad07d87.tar.bz2 yuzu-b10e13c090419fe2236cf02494d4c015dad07d87.tar.lz yuzu-b10e13c090419fe2236cf02494d4c015dad07d87.tar.xz yuzu-b10e13c090419fe2236cf02494d4c015dad07d87.tar.zst yuzu-b10e13c090419fe2236cf02494d4c015dad07d87.zip |
Diffstat (limited to 'src')
2 files changed, 186 insertions, 209 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivity.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivity.java deleted file mode 100644 index 0a1323a1f..000000000 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivity.java +++ /dev/null @@ -1,209 +0,0 @@ -package org.yuzu.yuzu_emu.features.settings.ui; - -import android.app.ProgressDialog; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.os.Bundle; -import android.provider.Settings; -import android.view.Menu; -import android.view.MenuInflater; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.fragment.app.FragmentTransaction; -import androidx.localbroadcastmanager.content.LocalBroadcastManager; - -import org.yuzu.yuzu_emu.NativeLibrary; -import org.yuzu.yuzu_emu.R; -import org.yuzu.yuzu_emu.utils.DirectoryInitialization; -import org.yuzu.yuzu_emu.utils.DirectoryStateReceiver; -import org.yuzu.yuzu_emu.utils.EmulationMenuSettings; - -public final class SettingsActivity extends AppCompatActivity implements SettingsActivityView { - private static final String ARG_MENU_TAG = "menu_tag"; - private static final String ARG_GAME_ID = "game_id"; - private static final String FRAGMENT_TAG = "settings"; - private SettingsActivityPresenter mPresenter = new SettingsActivityPresenter(this); - - private ProgressDialog dialog; - - public static void launch(Context context, String menuTag, String gameId) { - Intent settings = new Intent(context, SettingsActivity.class); - settings.putExtra(ARG_MENU_TAG, menuTag); - settings.putExtra(ARG_GAME_ID, gameId); - context.startActivity(settings); - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setContentView(R.layout.activity_settings); - - Intent launcher = getIntent(); - String gameID = launcher.getStringExtra(ARG_GAME_ID); - String menuTag = launcher.getStringExtra(ARG_MENU_TAG); - - mPresenter.onCreate(savedInstanceState, menuTag, gameID); - - // Show "Back" button in the action bar for navigation - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - } - - @Override - public boolean onSupportNavigateUp() { - onBackPressed(); - - return true; - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.menu_settings, menu); - - return true; - } - - @Override - protected void onSaveInstanceState(@NonNull Bundle outState) { - // Critical: If super method is not called, rotations will be busted. - super.onSaveInstanceState(outState); - mPresenter.saveState(outState); - } - - @Override - protected void onStart() { - super.onStart(); - mPresenter.onStart(); - } - - /** - * If this is called, the user has left the settings screen (potentially through the - * home button) and will expect their changes to be persisted. So we kick off an - * IntentService which will do so on a background thread. - */ - @Override - protected void onStop() { - super.onStop(); - - mPresenter.onStop(isFinishing()); - - // Update framebuffer layout when closing the settings - NativeLibrary.NotifyOrientationChange(EmulationMenuSettings.getLandscapeScreenLayout(), - getWindowManager().getDefaultDisplay().getRotation()); - } - - @Override - public void showSettingsFragment(String menuTag, boolean addToStack, String gameID) { - if (!addToStack && getFragment() != null) { - return; - } - - FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); - - if (addToStack) { - if (areSystemAnimationsEnabled()) { - transaction.setCustomAnimations( - R.animator.settings_enter, - R.animator.settings_exit, - R.animator.settings_pop_enter, - R.animator.setttings_pop_exit); - } - - transaction.addToBackStack(null); - } - transaction.replace(R.id.frame_content, SettingsFragment.newInstance(menuTag, gameID), FRAGMENT_TAG); - - transaction.commit(); - } - - private boolean areSystemAnimationsEnabled() { - float duration = Settings.Global.getFloat( - getContentResolver(), - Settings.Global.ANIMATOR_DURATION_SCALE, 1); - float transition = Settings.Global.getFloat( - getContentResolver(), - Settings.Global.TRANSITION_ANIMATION_SCALE, 1); - return duration != 0 && transition != 0; - } - - @Override - public void startDirectoryInitializationService(DirectoryStateReceiver receiver, IntentFilter filter) { - LocalBroadcastManager.getInstance(this).registerReceiver( - receiver, - filter); - DirectoryInitialization.start(this); - } - - @Override - public void stopListeningToDirectoryInitializationService(DirectoryStateReceiver receiver) { - LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver); - } - - @Override - public void showLoading() { - if (dialog == null) { - dialog = new ProgressDialog(this); - dialog.setMessage(getString(R.string.load_settings)); - dialog.setIndeterminate(true); - } - - dialog.show(); - } - - @Override - public void hideLoading() { - dialog.dismiss(); - } - - @Override - public void showExternalStorageNotMountedHint() { - Toast.makeText(this, R.string.external_storage_not_mounted, Toast.LENGTH_SHORT) - .show(); - } - - @Override - public org.yuzu.yuzu_emu.features.settings.model.Settings getSettings() { - return mPresenter.getSettings(); - } - - @Override - public void setSettings(org.yuzu.yuzu_emu.features.settings.model.Settings settings) { - mPresenter.setSettings(settings); - } - - @Override - public void onSettingsFileLoaded(org.yuzu.yuzu_emu.features.settings.model.Settings settings) { - SettingsFragmentView fragment = getFragment(); - - if (fragment != null) { - fragment.onSettingsFileLoaded(settings); - } - } - - @Override - public void onSettingsFileNotFound() { - SettingsFragmentView fragment = getFragment(); - - if (fragment != null) { - fragment.loadDefaultSettings(); - } - } - - @Override - public void showToastMessage(String message, boolean is_long) { - Toast.makeText(this, message, is_long ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT).show(); - } - - @Override - public void onSettingChanged() { - mPresenter.onSettingChanged(); - } - - private SettingsFragment getFragment() { - return (SettingsFragment) getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG); - } -} diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivity.kt new file mode 100644 index 000000000..ed26ec52f --- /dev/null +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivity.kt @@ -0,0 +1,186 @@ +package org.yuzu.yuzu_emu.features.settings.ui + +import android.app.ProgressDialog +import android.content.Context +import android.content.Intent +import android.content.IntentFilter +import android.os.Bundle +import android.view.Menu +import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity +import androidx.localbroadcastmanager.content.LocalBroadcastManager +import org.yuzu.yuzu_emu.NativeLibrary +import org.yuzu.yuzu_emu.R +import org.yuzu.yuzu_emu.features.settings.model.Settings +import org.yuzu.yuzu_emu.features.settings.ui.SettingsFragment.Companion.newInstance +import org.yuzu.yuzu_emu.utils.DirectoryInitialization +import org.yuzu.yuzu_emu.utils.DirectoryStateReceiver +import org.yuzu.yuzu_emu.utils.EmulationMenuSettings + +class SettingsActivity : AppCompatActivity(), SettingsActivityView { + private val presenter = SettingsActivityPresenter(this) + private var dialog: ProgressDialog? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_settings) + val launcher = intent + val gameID = launcher.getStringExtra(ARG_GAME_ID) + val menuTag = launcher.getStringExtra(ARG_MENU_TAG) + presenter.onCreate(savedInstanceState, menuTag!!, gameID!!) + + // Show "Back" button in the action bar for navigation + supportActionBar!!.setDisplayHomeAsUpEnabled(true) + } + + override fun onSupportNavigateUp(): Boolean { + onBackPressed() + return true + } + + override fun onCreateOptionsMenu(menu: Menu): Boolean { + val inflater = menuInflater + inflater.inflate(R.menu.menu_settings, menu) + return true + } + + override fun onSaveInstanceState(outState: Bundle) { + // Critical: If super method is not called, rotations will be busted. + super.onSaveInstanceState(outState) + presenter.saveState(outState) + } + + override fun onStart() { + super.onStart() + presenter.onStart() + } + + /** + * If this is called, the user has left the settings screen (potentially through the + * home button) and will expect their changes to be persisted. So we kick off an + * IntentService which will do so on a background thread. + */ + override fun onStop() { + super.onStop() + presenter.onStop(isFinishing) + + // Update framebuffer layout when closing the settings + NativeLibrary.NotifyOrientationChange( + EmulationMenuSettings.landscapeScreenLayout, + windowManager.defaultDisplay.rotation + ) + } + + override fun showSettingsFragment(menuTag: String, addToStack: Boolean, gameId: String) { + if (!addToStack && fragment != null) { + return + } + val transaction = supportFragmentManager.beginTransaction() + if (addToStack) { + if (areSystemAnimationsEnabled()) { + transaction.setCustomAnimations( + R.animator.settings_enter, + R.animator.settings_exit, + R.animator.settings_pop_enter, + R.animator.setttings_pop_exit + ) + } + transaction.addToBackStack(null) + } + transaction.replace(R.id.frame_content, newInstance(menuTag, gameId), FRAGMENT_TAG) + transaction.commit() + } + + private fun areSystemAnimationsEnabled(): Boolean { + val duration = android.provider.Settings.Global.getFloat( + contentResolver, + android.provider.Settings.Global.ANIMATOR_DURATION_SCALE, 1f + ) + val transition = android.provider.Settings.Global.getFloat( + contentResolver, + android.provider.Settings.Global.TRANSITION_ANIMATION_SCALE, 1f + ) + return duration != 0f && transition != 0f + } + + override fun startDirectoryInitializationService( + receiver: DirectoryStateReceiver?, + filter: IntentFilter + ) { + LocalBroadcastManager.getInstance(this).registerReceiver( + receiver!!, + filter + ) + DirectoryInitialization.start(this) + } + + override fun stopListeningToDirectoryInitializationService(receiver: DirectoryStateReceiver) { + LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver) + } + + override fun showLoading() { + if (dialog == null) { + dialog = ProgressDialog(this) + dialog!!.setMessage(getString(R.string.load_settings)) + dialog!!.isIndeterminate = true + } + dialog!!.show() + } + + override fun hideLoading() { + dialog!!.dismiss() + } + + override fun showExternalStorageNotMountedHint() { + Toast.makeText( + this, + R.string.external_storage_not_mounted, + Toast.LENGTH_SHORT + ).show() + } + + override var settings: Settings? + get() = presenter.settings + set(settings) { + presenter.settings = settings + } + + override fun onSettingsFileLoaded(settings: Settings?) { + val fragment: SettingsFragmentView? = fragment + fragment?.onSettingsFileLoaded(settings) + } + + override fun onSettingsFileNotFound() { + val fragment: SettingsFragmentView? = fragment + fragment?.loadDefaultSettings() + } + + override fun showToastMessage(message: String, is_long: Boolean) { + Toast.makeText( + this, + message, + if (is_long) Toast.LENGTH_LONG else Toast.LENGTH_SHORT + ).show() + } + + override fun onSettingChanged() { + presenter.onSettingChanged() + } + + private val fragment: SettingsFragment? + get() = supportFragmentManager.findFragmentByTag(FRAGMENT_TAG) as SettingsFragment? + + companion object { + private const val ARG_MENU_TAG = "menu_tag" + private const val ARG_GAME_ID = "game_id" + private const val FRAGMENT_TAG = "settings" + + @JvmStatic + fun launch(context: Context, menuTag: String?, gameId: String?) { + val settings = Intent(context, SettingsActivity::class.java) + settings.putExtra(ARG_MENU_TAG, menuTag) + settings.putExtra(ARG_GAME_ID, gameId) + context.startActivity(settings) + } + } +} |