Skip to content

Instantly share code, notes, and snippets.

View halilozercan's full-sized avatar
🏛️
Learning

Halil Ozercan halilozercan

🏛️
Learning
View GitHub Profile
@halilozercan
halilozercan / jacoco.gradle
Created November 21, 2018 06:29 — forked from almozavr/jacoco.gradle
Gradle Jacoco config for Android (3.x plugin) with kotlin and custom excludes support
apply plugin: "jacoco"
jacoco {
toolVersion = deps.test.jacocoVersion
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
}
@halilozercan
halilozercan / BuilderPattern.kt
Last active January 23, 2019 07:44
Builder pattern in Kotlin
abstract class BaseBuilder<T> {
abstract fun buildInternal(): T
}
fun <T, R: BaseBuilder<T>> R.build(block: R.() -> Unit): T {
block.invoke(this)
return this.buildInternal()
}
<activity android:name="VideoActivity"
android:supportsPictureInPicture="true"
android:configChanges=
"screenSize|smallestScreenSize|screenLayout|orientation"
...
activity?.enterPictureInPictureMode()
override fun onUserLeaveHint() {
if (iWantToBeInPipModeNow()) {
enterPictureInPictureMode()
}
}
<activity android:name="VideoActivity"
android:supportsPictureInPicture=“true"
android:autoRemoveFromRecents=“true”
android:configChanges=
"screenSize|smallestScreenSize|screenLayout|orientation"
...
private fun startPictureInPicture(): Boolean {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && shouldStart) {
enterPictureInPictureMode(
PictureInPictureParams.Builder()
.setAspectRatio(…) // This has lower and upper limitations
.build()
)
return true
}
return false
override fun onPictureInPictureModeChanged(
isInPictureInPictureMode: Boolean,
newConfig: Configuration
) {
if (isInPictureInPictureMode) {
// entered PiP
} else {
// keep track of background in onStart and onStop
if (inBackground) {
// User highly probably finished the activity in PiP.
typealias OnAudioDeviceChanged = (
selectedAudioDevice: AudioGenie.AudioDevice?,
availableAudioDevices: Set<AudioGenie.AudioDevice>
) -> Unit
val newAudioDevices: MutableSet<AudioDevice> = HashSet()
if (bluetoothManager.state == State.SCO_CONNECTED || bluetoothManager.state == State.SCO_CONNECTING || bluetoothManager.state == State.HEADSET_AVAILABLE
) {
newAudioDevices.add(AudioDevice.BLUETOOTH)
}
private inner class BluetoothServiceListener : BluetoothProfile.ServiceListener {
// Called to notify the client when the proxy object has been connected to the service.
// Once we have the profile proxy object, we can use it to monitor the state of the
// connection and perform other operations that are relevant to the headset profile.
override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) {
if (profile != BluetoothProfile.HEADSET || bluetoothState == State.UNINITIALIZED) {
return
}
// Android only supports one connected Bluetooth Headset at a time.
bluetoothHeadset = proxy as BluetoothHeadset