-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainActivity.kt
55 lines (49 loc) · 2.04 KB
/
MainActivity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.gfk.s2s.demo
import android.annotation.SuppressLint
import android.app.PictureInPictureParams
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.multidex.MultiDex
import com.gfk.s2s.demo.s2s.R
class MainActivity : AppCompatActivity() {
var usePictureInPictureByHomeButtonPress = true
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
MultiDex.install(this)
val actionBar = findViewById<Toolbar>(R.id.toolBar)
setSupportActionBar(actionBar)
}
override fun onUserLeaveHint() {
super.onUserLeaveHint()
if (usePictureInPictureByHomeButtonPress) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N
&& packageManager?.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE) == true) {
enterPictureInPictureMode()
} else if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O
&& packageManager?.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE) == true) {
enterPictureInPictureMode(PictureInPictureParams.Builder().build())
}
}
}
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
if (newConfig.orientation != Configuration.ORIENTATION_PORTRAIT) {
supportActionBar?.hide()
} else {
supportActionBar?.show()
}
}
@SuppressLint("MissingSuperCall")
override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean, newConfig: Configuration) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
if (isInPictureInPictureMode) {
supportActionBar?.hide()
} else {
supportActionBar?.show()
}
}
}