android: Use Material 3 components
parent
18f4ef436d
commit
5840d60724
@ -0,0 +1,18 @@
|
||||
package org.yuzu.yuzu_emu.utils
|
||||
|
||||
import android.content.Context
|
||||
|
||||
object InsetsHelper {
|
||||
const val THREE_BUTTON_NAVIGATION = 0
|
||||
const val TWO_BUTTON_NAVIGATION = 1
|
||||
const val GESTURE_NAVIGATION = 2
|
||||
|
||||
fun getSystemGestureType(context: Context): Int {
|
||||
val resources = context.resources
|
||||
val resourceId =
|
||||
resources.getIdentifier("config_navBarInteractionMode", "integer", "android")
|
||||
return if (resourceId != 0) {
|
||||
resources.getInteger(resourceId)
|
||||
} else 0
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.yuzu.yuzu_emu.utils
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Color
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.WindowCompat
|
||||
import com.google.android.material.color.MaterialColors
|
||||
import org.yuzu.yuzu_emu.R
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
object ThemeHelper {
|
||||
private const val NAV_BAR_ALPHA = 0.9f
|
||||
|
||||
@JvmStatic
|
||||
fun setTheme(activity: AppCompatActivity) {
|
||||
val windowController = WindowCompat.getInsetsController(
|
||||
activity.window,
|
||||
activity.window.decorView
|
||||
)
|
||||
val isLightMode =
|
||||
(activity.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO
|
||||
windowController.isAppearanceLightStatusBars = isLightMode
|
||||
windowController.isAppearanceLightNavigationBars = isLightMode
|
||||
|
||||
activity.window.statusBarColor = ContextCompat.getColor(activity, android.R.color.transparent)
|
||||
|
||||
val navigationBarColor =
|
||||
MaterialColors.getColor(activity.window.decorView, R.attr.colorSurface)
|
||||
setNavigationBarColor(activity, navigationBarColor)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setNavigationBarColor(activity: Activity, @ColorInt color: Int) {
|
||||
val gestureType = InsetsHelper.getSystemGestureType(activity.applicationContext)
|
||||
val orientation = activity.resources.configuration.orientation
|
||||
|
||||
if ((gestureType == InsetsHelper.THREE_BUTTON_NAVIGATION ||
|
||||
gestureType == InsetsHelper.TWO_BUTTON_NAVIGATION) &&
|
||||
orientation == Configuration.ORIENTATION_LANDSCAPE
|
||||
) {
|
||||
activity.window.navigationBarColor = color
|
||||
} else if (gestureType == InsetsHelper.THREE_BUTTON_NAVIGATION ||
|
||||
gestureType == InsetsHelper.TWO_BUTTON_NAVIGATION
|
||||
) {
|
||||
activity.window.navigationBarColor = getColorWithOpacity(color, NAV_BAR_ALPHA)
|
||||
} else {
|
||||
activity.window.navigationBarColor = ContextCompat.getColor(
|
||||
activity.applicationContext,
|
||||
android.R.color.transparent
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
private fun getColorWithOpacity(@ColorInt color: Int, alphaFactor: Float): Int {
|
||||
return Color.argb(
|
||||
(alphaFactor * Color.alpha(color)).roundToInt(), Color.red(color),
|
||||
Color.green(color), Color.blue(color)
|
||||
)
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<size
|
||||
android:width="1dp"
|
||||
android:height="1dp" />
|
||||
|
||||
<solid android:color="@color/gamelist_divider" />
|
||||
|
||||
</shape>
|
@ -1,5 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
android:id="@+id/coordinator_main"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/frame_content" />
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/appbar_settings"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar_settings"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize" />
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/frame_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="5dp"
|
||||
android:paddingLeft="20dp"
|
||||
android:paddingRight="20dp"
|
||||
android:paddingBottom="0dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/checkBox"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/do_not_show_this_again" />
|
||||
</LinearLayout>
|
@ -1,26 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ProgressBar
|
||||
<com.google.android.material.progressindicator.LinearProgressIndicator
|
||||
android:id="@+id/progress_bar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/spacing_large"
|
||||
android:layout_marginRight="@dimen/spacing_large"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_below="@+id/progress_text"
|
||||
android:layout_alignParentStart="true"/>
|
||||
android:layout_margin="24dp"
|
||||
app:trackCornerRadius="4dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/progress_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/spacing_large"
|
||||
android:layout_marginRight="@dimen/spacing_large"
|
||||
android:gravity="right"
|
||||
android:text="1/100" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
Loading…
Reference in New Issue