Skip to content

Commit

Permalink
feat: Android 优化全屏显示
Browse files Browse the repository at this point in the history
  • Loading branch information
PeanutMelonSeedBigAlmond committed Feb 7, 2024
1 parent bbaee6e commit 60a4a9f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
40 changes: 37 additions & 3 deletions android/app/src/main/kotlin/com/lifegpc/ehf/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ package com.lifegpc.ehf
import android.app.Activity
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.util.Log
import android.view.WindowInsets
import android.view.WindowInsetsController
import android.view.WindowManager
import com.lifegpc.ehf.annotation.ChannelMethod
import com.lifegpc.ehf.eventbus.SAFAuthEvent
import com.lifegpc.ehf.platform.ClipboardPlugin
import com.lifegpc.ehf.platform.MethodChannelUtils
import com.lifegpc.ehf.platform.SAFPlugin
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.engine.FlutterEngine
import org.greenrobot.eventbus.EventBus

class MainActivity : FlutterActivity() {
class MainActivity : FlutterFragmentActivity() {

override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
Expand Down Expand Up @@ -56,6 +58,15 @@ class MainActivity : FlutterActivity() {
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val lp=window.attributes
lp.layoutInDisplayCutoutMode=WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
window.attributes=lp
}
}

@ChannelMethod(methodName = "enableProtect")
@Suppress("unused")
private fun enableFlagSecure() {
Expand All @@ -68,6 +79,29 @@ class MainActivity : FlutterActivity() {
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}

@ChannelMethod(methodName = "setFullscreenMode")
@Suppress("unused")
private fun setFullscreenMode(value: Boolean) {
// api 23
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val windowController = window.insetsController
if (value) {
windowController?.hide(WindowInsets.Type.statusBars())
windowController?.systemBarsBehavior =
WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
} else {
windowController?.show(WindowInsets.Type.statusBars())
}
} else {
@Suppress("DEPRECATION")
if (value){
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
}else{
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
}
}
}

@ChannelMethod(methodName = "deviceName")
@Suppress("unused")
private fun getDeviceName(): String {
Expand Down
10 changes: 10 additions & 0 deletions lib/platform/display.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,14 @@ class Display {
return false;
}
}

Future<bool> setFullscreenMode(bool fullscreenMode) async{
try{
await platform.invokeMethod<void>("setScreenMode",fullscreenMode);
return true;
}catch(e){
_log.warning("Failed to set screen mode",e);
return false;
}
}
}

0 comments on commit 60a4a9f

Please sign in to comment.