Skip to content

System UI control #5287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/src/main/java/one/mixin/android/extension/ContextExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,24 @@ fun supportsOreo(
}
}


inline fun supportsIceCream(code: () -> Unit) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
code()
}
}

fun supportsIceCream(
code: () -> Unit,
elseAction: (() -> Unit),
) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
code()
} else {
elseAction.invoke()
}
}

@SuppressLint("ObsoleteSdkInt")
inline fun supportsNougat(code: () -> Unit) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class AvatarActivity : BaseActivity() {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}
postponeEnterTransition()
window.statusBarColor = Color.TRANSPARENT
binding = ActivityAvatarBinding.inflate(layoutInflater)
setContentView(binding.root)
getScreenshot()?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ open class BaseActivity : AppCompatActivity() {
} else {
setTheme(getDefaultThemeId())
}
if (!skipSystemUi) {
window.navigationBarColor = colorFromAttribute(R.attr.bg_white)
}
window.navigationBarColor = colorFromAttribute(R.attr.bg_white)
}

override fun setContentView(layoutResID: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class BubbleActivity : BlazeBaseActivity() {
displayId != Display.DEFAULT_DISPLAY
}
setContentView(R.layout.activity_chat)
WindowCompat.setDecorFitsSystemWindows(window, false)
showConversation(intent)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class ConversationActivity : BlazeBaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_chat)
WindowCompat.setDecorFitsSystemWindows(window, false)
if (savedInstanceState == null) {
if (intent.getBooleanExtra(ARGS_FAST_SHOW, false)) {
replaceFragment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import android.graphics.Color
import android.graphics.Paint
import android.graphics.Path
import android.graphics.RectF
import android.graphics.drawable.ColorDrawable
import android.media.MediaScannerConnection
import android.net.Uri
import android.os.Bundle
import android.util.Base64
import android.view.View
import android.view.WindowManager
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.viewModels
import androidx.appcompat.view.ContextThemeWrapper
Expand Down Expand Up @@ -130,16 +132,20 @@ class InscriptionActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
skipSystemUi = true
super.onCreate(savedInstanceState)
SystemUIManager.lightUI(window, false)
window.setBackgroundDrawable(ColorDrawable(Color.BLACK))
binding = ActivityInscriptionBinding.inflate(layoutInflater)
setContentView(binding.root)
window.decorView.setOnApplyWindowInsetsListener { view, windowInsets ->
view.setBackgroundColor(Color.BLACK)
windowInsets
}
getSendResult =
registerForActivityResult(
InscriptionSendActivity.SendContract(),
activityResultRegistry,
::callbackSend,
)
SystemUIManager.lightUI(window, false)
window.statusBarColor = Color.TRANSPARENT
binding = ActivityInscriptionBinding.inflate(layoutInflater)
setContentView(binding.root)
val qrcode = "$INSCRIPTION$inscriptionHash".generateQRCode(dpToPx(110f), 0).first
binding.compose.setContent {
InscriptionPage(inscriptionHash, { finish() }, { inscriptionState ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ import one.mixin.android.util.SensorOrientationChangeNotifier
import one.mixin.android.util.SystemUIManager
import one.mixin.android.util.VideoPlayer
import one.mixin.android.util.reportEvent
import one.mixin.android.util.reportException
import one.mixin.android.util.rxpermission.RxPermissions
import one.mixin.android.vo.FixedMessageDataSource
import one.mixin.android.vo.MediaStatus
Expand Down Expand Up @@ -152,9 +151,16 @@ class MediaPagerActivity : BaseActivity(), DismissFrameLayout.OnDismissListener,
postponeEnterTransition()
}
super.onCreate(savedInstanceState)
colorDrawable = ColorDrawable(Color.BLACK)
window.setBackgroundDrawable(colorDrawable)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
binding = ActivityMediaPagerBinding.inflate(layoutInflater)
setContentView(binding.root)
window.decorView.setOnApplyWindowInsetsListener { view, windowInsets ->
view.setBackgroundColor(Color.BLACK)
windowInsets
}
SystemUIManager.lightUI(window, false)
window.sharedElementEnterTransition.duration = SHARED_ELEMENT_TRANSITION_DURATION
window.sharedElementExitTransition.duration = SHARED_ELEMENT_TRANSITION_DURATION

Expand All @@ -164,11 +170,6 @@ class MediaPagerActivity : BaseActivity(), DismissFrameLayout.OnDismissListener,
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
window.attributes = lp
}
SystemUIManager.fitsSystem(window)
binding.root.doOnPreDraw {
SystemUIManager.lightUI(window, false)
}
colorDrawable = ColorDrawable(Color.BLACK)
binding.viewPager.backgroundDrawable = colorDrawable
binding.viewPager.adapter = adapter
binding.viewPager.registerOnPageChangeCallback(onPageChangeCallback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,16 @@ class TranscriptMediaPagerActivity : BaseActivity(), DismissFrameLayout.OnDismis
skipSystemUi = true
postponeEnterTransition()
super.onCreate(savedInstanceState)
colorDrawable = ColorDrawable(Color.BLACK)
window.setBackgroundDrawable(colorDrawable)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
binding = ActivityMediaPagerBinding.inflate(layoutInflater)
setContentView(binding.root)
window.decorView.setOnApplyWindowInsetsListener { view, windowInsets ->
view.setBackgroundColor(Color.BLACK)
windowInsets
}
SystemUIManager.lightUI(window, false)
window.sharedElementEnterTransition.duration = SHARED_ELEMENT_TRANSITION_DURATION
window.sharedElementExitTransition.duration = SHARED_ELEMENT_TRANSITION_DURATION
supportsPie {
Expand All @@ -136,11 +143,9 @@ class TranscriptMediaPagerActivity : BaseActivity(), DismissFrameLayout.OnDismis
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
window.attributes = lp
}
SystemUIManager.fitsSystem(window)
binding.root.doOnPreDraw {
SystemUIManager.lightUI(window, false)
}
colorDrawable = ColorDrawable(Color.BLACK)
binding.viewPager.backgroundDrawable = colorDrawable
binding.viewPager.adapter = adapter
binding.viewPager.registerOnPageChangeCallback(onPageChangeCallback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ class MarketShareActivity : BaseActivity() {
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
)
window.statusBarColor = android.graphics.Color.TRANSPARENT
binding.test.round(8.dp)
binding.content.updateLayoutParams<MarginLayoutParams> {
topMargin = 20.dp
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/one/mixin/android/ui/web/WebFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import android.content.pm.ActivityInfo
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.drawable.BitmapDrawable
import android.media.MediaScannerConnection
import android.net.Uri
import android.net.http.SslError
Expand Down Expand Up @@ -1648,7 +1647,7 @@ class WebFragment : BaseFragment() {

requireActivity().window.statusBarColor = color
requireActivity().window?.let {
SystemUIManager.setAppearanceLightStatusBars(it, !dark)
SystemUIManager.lightUI(it, !dark)
}
titleColor = color
binding.titleTv.setTextColor(if (dark) Color.WHITE else Color.BLACK)
Expand Down
60 changes: 4 additions & 56 deletions app/src/main/java/one/mixin/android/util/SystemUIManager.kt
Original file line number Diff line number Diff line change
@@ -1,50 +1,20 @@
package one.mixin.android.util

import android.annotation.SuppressLint
import android.graphics.Color
import android.view.Window
import androidx.annotation.ColorInt
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import one.mixin.android.extension.supportsPie

@SuppressLint("InlinedApi")
object SystemUIManager {
fun fitsSystem(
window: Window,
@ColorInt color: Int = 0x33000000,
) {
WindowCompat.setDecorFitsSystemWindows(window, false)

window.statusBarColor = color
window.navigationBarColor = color
supportsPie {
window.navigationBarDividerColor = color
}
}

fun clearStyle(window: Window) {
WindowCompat.setDecorFitsSystemWindows(window, true)
}

fun fullScreen(window: Window) {
WindowCompat.setDecorFitsSystemWindows(window, false)

WindowCompat.getInsetsController(window, window.decorView).apply {
hide(WindowInsetsCompat.Type.systemBars())
systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
}

fun lightUI(
window: Window,
light: Boolean,
isLight: Boolean,
) {
val controller = WindowCompat.getInsetsController(window, window.decorView)
controller.apply {
isAppearanceLightStatusBars = light
isAppearanceLightNavigationBars = light
}
val windowInsetsControllerCompat = WindowInsetsControllerCompat(window, window.decorView)
windowInsetsControllerCompat.isAppearanceLightStatusBars = isLight
}

fun hideSystemUI(window: Window) {
Expand All @@ -61,26 +31,4 @@ object SystemUIManager {
show(WindowInsetsCompat.Type.systemBars())
}
}

fun setSystemUiColor(
window: Window,
color: Int,
) {
window.navigationBarColor = color
window.statusBarColor = color
}

fun hasCutOut(window: Window): Boolean {
supportsPie {
return window.decorView.rootWindowInsets?.displayCutout?.safeInsetTop != 0
}
return false
}

fun setAppearanceLightStatusBars(
window: Window,
isLight: Boolean,
) {
WindowCompat.getInsetsController(window, window.decorView).isAppearanceLightStatusBars = isLight
}
}
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_inscription.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:background="#000000">

<androidx.compose.ui.platform.ComposeView
android:id="@+id/compose"
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_media_pager.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:background="#000000">

<androidx.viewpager2.widget.ViewPager2
android:id="@+id/view_pager"
Expand Down
Loading