yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

android: Use edge to edge

This commit is contained in:
Charles Lombardo 2023-03-13 23:47:39 -04:00 committed by bunnei
parent 5840d60724
commit f40059e4ba
9 changed files with 110 additions and 21 deletions

View File

@ -8,20 +8,24 @@ import android.content.Intent
import android.content.IntentFilter
import android.os.Bundle
import android.view.Menu
import android.view.View
import android.widget.FrameLayout
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.progressindicator.LinearProgressIndicator
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
import org.yuzu.yuzu_emu.utils.ThemeHelper
import org.yuzu.yuzu_emu.utils.*
class SettingsActivity : AppCompatActivity(), SettingsActivityView {
private val presenter = SettingsActivityPresenter(this)
@ -32,6 +36,9 @@ class SettingsActivity : AppCompatActivity(), SettingsActivityView {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
WindowCompat.setDecorFitsSystemWindows(window, false)
val launcher = intent
val gameID = launcher.getStringExtra(ARG_GAME_ID)
val menuTag = launcher.getStringExtra(ARG_MENU_TAG)
@ -40,6 +47,8 @@ class SettingsActivity : AppCompatActivity(), SettingsActivityView {
// Show "Back" button in the action bar for navigation
setSupportActionBar(findViewById(R.id.toolbar_settings))
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
setInsets()
}
override fun onSupportNavigateUp(): Boolean {
@ -185,6 +194,17 @@ class SettingsActivity : AppCompatActivity(), SettingsActivityView {
private val fragment: SettingsFragment?
get() = supportFragmentManager.findFragmentByTag(FRAGMENT_TAG) as SettingsFragment?
private fun setInsets() {
val appBar = findViewById<AppBarLayout>(R.id.appbar_settings)
val frame = findViewById<FrameLayout>(R.id.frame_content)
ViewCompat.setOnApplyWindowInsetsListener(frame) { view: View, windowInsets: WindowInsetsCompat ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
view.updatePadding(left = insets.left, right = insets.right)
InsetsHelper.insetAppBar(insets, appBar)
windowInsets
}
}
companion object {
private const val ARG_MENU_TAG = "menu_tag"
private const val ARG_GAME_ID = "game_id"

View File

@ -8,6 +8,9 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.LinearLayoutManager
@ -25,6 +28,8 @@ class SettingsFragment : Fragment(), SettingsFragmentView {
private var activityView: SettingsActivityView? = null
private var adapter: SettingsAdapter? = null
private lateinit var recyclerView: RecyclerView
override fun onAttach(context: Context) {
super.onAttach(context)
activityView = context as SettingsActivityView
@ -50,7 +55,7 @@ class SettingsFragment : Fragment(), SettingsFragmentView {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
val manager = LinearLayoutManager(activity)
val recyclerView = view.findViewById<RecyclerView>(R.id.list_settings)
recyclerView = view.findViewById(R.id.list_settings)
recyclerView.adapter = adapter
recyclerView.layoutManager = manager
val dividerDecoration = MaterialDividerItemDecoration(requireContext(), LinearLayoutManager.VERTICAL)
@ -58,6 +63,8 @@ class SettingsFragment : Fragment(), SettingsFragmentView {
recyclerView.addItemDecoration(dividerDecoration)
val activity = activity as SettingsActivityView?
presenter.onViewCreated(activity!!.settings)
setInsets()
}
override fun onDetach() {
@ -106,6 +113,14 @@ class SettingsFragment : Fragment(), SettingsFragmentView {
activityView!!.onSettingChanged()
}
private fun setInsets() {
ViewCompat.setOnApplyWindowInsetsListener(recyclerView) { view: View, windowInsets: WindowInsetsCompat ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
view.updatePadding(bottom = insets.bottom)
windowInsets
}
}
companion object {
private const val ARGUMENT_MENU_TAG = "menu_tag"
private const val ARGUMENT_GAME_ID = "game_id"

View File

@ -9,9 +9,17 @@ import android.net.Uri
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.FrameLayout
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.color.MaterialColors
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import org.yuzu.yuzu_emu.NativeLibrary
import org.yuzu.yuzu_emu.R
@ -31,6 +39,9 @@ class MainActivity : AppCompatActivity(), MainView {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
WindowCompat.setDecorFitsSystemWindows(window, false)
findViews()
setSupportActionBar(toolbar)
presenter.onCreate()
@ -50,6 +61,8 @@ class MainActivity : AppCompatActivity(), MainView {
// Dismiss previous notifications (should not happen unless a crash occurred)
EmulationActivity.tryDismissRunningNotification(this)
setInsets()
}
override fun onSaveInstanceState(outState: Bundle) {
@ -230,4 +243,15 @@ class MainActivity : AppCompatActivity(), MainView {
EmulationActivity.tryDismissRunningNotification(this)
super.onDestroy()
}
private fun setInsets() {
val appBar = findViewById<AppBarLayout>(R.id.appbar_main)
val frame = findViewById<FrameLayout>(R.id.games_platform_frame)
ViewCompat.setOnApplyWindowInsetsListener(frame) { view: View, windowInsets: WindowInsetsCompat ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
view.updatePadding(left = insets.left, right = insets.right)
InsetsHelper.insetAppBar(insets, appBar)
windowInsets
}
}
}

View File

@ -10,6 +10,9 @@ import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver.OnGlobalLayoutListener
import android.widget.TextView
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
@ -17,6 +20,7 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import org.yuzu.yuzu_emu.R
import org.yuzu.yuzu_emu.YuzuApplication
import org.yuzu.yuzu_emu.adapters.GameAdapter
import org.yuzu.yuzu_emu.utils.InsetsHelper
class PlatformGamesFragment : Fragment(), PlatformGamesView {
private val presenter = PlatformGamesPresenter(this)
@ -65,6 +69,8 @@ class PlatformGamesFragment : Fragment(), PlatformGamesView {
refresh()
pullToRefresh.isRefreshing = false
}
setInsets()
}
override fun refresh() {
@ -91,6 +97,14 @@ class PlatformGamesFragment : Fragment(), PlatformGamesView {
textView = root.findViewById(R.id.gamelist_empty_text)
}
private fun setInsets() {
ViewCompat.setOnApplyWindowInsetsListener(recyclerView) { view: View, windowInsets: WindowInsetsCompat ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
view.updatePadding(bottom = insets.bottom)
windowInsets
}
}
companion object {
const val TAG = "PlatformGamesFragment"
}

View File

@ -1,12 +1,22 @@
package org.yuzu.yuzu_emu.utils
import android.content.Context
import android.view.ViewGroup.MarginLayoutParams
import androidx.core.graphics.Insets
import com.google.android.material.appbar.AppBarLayout
object InsetsHelper {
const val THREE_BUTTON_NAVIGATION = 0
const val TWO_BUTTON_NAVIGATION = 1
const val GESTURE_NAVIGATION = 2
fun insetAppBar(insets: Insets, appBarLayout: AppBarLayout) {
val mlpAppBar = appBarLayout.layoutParams as MarginLayoutParams
mlpAppBar.leftMargin = insets.left
mlpAppBar.rightMargin = insets.right
appBarLayout.layoutParams = mlpAppBar
}
fun getSystemGestureType(context: Context): Int {
val resources = context.resources
val resourceId =

View File

@ -9,6 +9,7 @@
android:id="@+id/appbar_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:liftOnScrollTargetViewId="@id/grid_games">
<androidx.appcompat.widget.Toolbar

View File

@ -9,7 +9,8 @@
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar_settings"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_settings"

View File

@ -1,13 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
@ -17,18 +18,20 @@
android:id="@+id/gamelist_empty_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/empty_gamelist"
android:visibility="gone"
android:textSize="18sp"
android:gravity="center" />
android:visibility="gone" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/grid_games"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
tools:listitem="@layout/card_game" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/grid_games"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
tools:listitem="@layout/card_game" />
</RelativeLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</FrameLayout>

View File

@ -8,6 +8,7 @@
android:id="@+id/list_settings"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorSurface" />
android:background="?attr/colorSurface"
android:clipToPadding="false" />
</org.yuzu.yuzu_emu.features.settings.ui.SettingsFrameLayout>