mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-02 00:58:19 +08:00
84 lines
2.9 KiB
Kotlin
84 lines
2.9 KiB
Kotlin
package com.example.piliplus
|
|
|
|
import android.content.Intent
|
|
import android.content.pm.PackageManager
|
|
import android.content.res.Configuration
|
|
import android.os.Build
|
|
import android.os.Bundle
|
|
import android.view.WindowManager.LayoutParams
|
|
import com.ryanheise.audioservice.AudioServiceActivity
|
|
import io.flutter.SystemChrome
|
|
import io.flutter.embedding.engine.FlutterEngine
|
|
import io.flutter.plugin.common.MethodChannel
|
|
|
|
class MainActivity : AudioServiceActivity() {
|
|
// TODO: remove
|
|
private lateinit var methodChannel: MethodChannel
|
|
|
|
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
|
super.configureFlutterEngine(flutterEngine)
|
|
|
|
methodChannel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "PiliPlus")
|
|
methodChannel.setMethodCallHandler { call, result ->
|
|
when (call.method) {
|
|
"SystemChrome.setEnabledSystemUIMode" -> {
|
|
SystemChrome.onMethodCall(
|
|
this, "SystemChrome.setEnabledSystemUIMode", call.argument("arguments")
|
|
)
|
|
}
|
|
|
|
"SystemChrome.setEnabledSystemUIOverlays" -> {
|
|
SystemChrome.onMethodCall(
|
|
this, "SystemChrome.setEnabledSystemUIOverlays", call.argument("arguments")
|
|
)
|
|
}
|
|
|
|
else -> result.notImplemented()
|
|
}
|
|
}
|
|
}
|
|
|
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
|
super.onConfigurationChanged(newConfig)
|
|
if (AndroidHelper.isFoldable) {
|
|
AndroidHelper.ToDart.onConfigurationChanged?.run()
|
|
}
|
|
}
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
window.attributes.layoutInDisplayCutoutMode =
|
|
LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
|
}
|
|
|
|
AndroidHelper.isPipAvailable =
|
|
packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
try {
|
|
AndroidHelper.isFoldable =
|
|
packageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_HINGE_ANGLE)
|
|
} catch (_: Exception) {
|
|
}
|
|
}
|
|
}
|
|
|
|
override fun onDestroy() {
|
|
stopService(Intent(this, com.ryanheise.audioservice.AudioService::class.java))
|
|
super.onDestroy()
|
|
}
|
|
|
|
override fun onUserLeaveHint() {
|
|
super.onUserLeaveHint()
|
|
AndroidHelper.ToDart.onUserLeaveHint?.run()
|
|
}
|
|
|
|
override fun onPictureInPictureModeChanged(
|
|
isInPictureInPictureMode: Boolean, newConfig: Configuration?
|
|
) {
|
|
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
|
|
AndroidHelper.isPipMode = isInPictureInPictureMode
|
|
}
|
|
}
|