-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Shock@5678
committed
Aug 15, 2024
1 parent
ae0b936
commit 09e3724
Showing
30 changed files
with
133 additions
and
1,260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 12 additions & 42 deletions
54
android/app/src/main/kotlin/com/example/beacon/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,21 @@ | ||
package com.example.beacon | ||
|
||
import android.app.PictureInPictureParams | ||
import android.os.Build | ||
import android.util.Rational | ||
import android.content.res.Configuration | ||
import androidx.annotation.NonNull | ||
import cl.puntito.simple_pip_mode.PipCallbackHelper | ||
import io.flutter.embedding.android.FlutterActivity | ||
import io.flutter.embedding.engine.FlutterEngine | ||
import io.flutter.plugin.common.MethodChannel | ||
|
||
class MainActivity : FlutterActivity() { | ||
private val CHANNEL = "com.example.beacon/pip" | ||
private var shouldEnterPipMode = false | ||
private var callbackHelper = PipCallbackHelper() | ||
|
||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) { | ||
super.configureFlutterEngine(flutterEngine) | ||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result -> | ||
when (call.method) { | ||
"switchPIPMode"->{ | ||
shouldEnterPipMode = true | ||
result.success(null) | ||
} | ||
"enablePIPMode" -> { | ||
shouldEnterPipMode = true | ||
result.success(null) | ||
} | ||
"disablePIPMode" -> { | ||
shouldEnterPipMode = false | ||
result.success(null) | ||
} | ||
else -> result.notImplemented() | ||
} | ||
} | ||
} | ||
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { | ||
super.configureFlutterEngine(flutterEngine) | ||
callbackHelper.configureFlutterEngine(flutterEngine) | ||
} | ||
|
||
override fun onUserLeaveHint() { | ||
super.onUserLeaveHint() | ||
if (shouldEnterPipMode) { | ||
enterPIPMode() | ||
} | ||
} | ||
|
||
private fun enterPIPMode() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
val aspectRatio = Rational(16, 9) | ||
val pipParams = PictureInPictureParams.Builder() | ||
.setAspectRatio(aspectRatio) | ||
.build() | ||
enterPictureInPictureMode(pipParams) | ||
} | ||
} | ||
override fun onPictureInPictureModeChanged(active: Boolean, newConfig: Configuration?) { | ||
super.onPictureInPictureModeChanged(active, newConfig) | ||
callbackHelper.onPictureInPictureModeChanged(active) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.