Skip to content

Instantly share code, notes, and snippets.

View husaynhakeem's full-sized avatar

Husayn Hakeem husaynhakeem

View GitHub Profile
// Create a listener with a callback invoked when a gesture event has occurred
val listener = object : ScaleGestureDetector.SimpleOnScaleGestureListener() {
override fun onScale(detector: ScaleGestureDetector): Boolean {
// Get the current camera zoom ratio
val currentZoomRatio: Float = cameraInfo.zoomRatio.value ?: 1F
// Get by how much the scale has changed due to the user's pinch gesture
val delta = detector.scaleFactor
// Update the camera's zoom ratio
// Listen to pinch gestures
val listener = object : ScaleGestureDetector.SimpleOnScaleGestureListener() {
override fun onScale(detector: ScaleGestureDetector): Boolean {
// Get the camera's current zoom ratio
val currentZoomRatio = cameraInfo.zoomState.value?.zoomRatio ?: 0F
// Get the pinch gesture's scaling factor
val delta = detector.scaleFactor
// Update the camera's zoom ratio. This is an asynchronous operation that returns
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:window="http://schemas.android.com/apk/res-auto">
<SplitPairRule
window:splitRatio="0.4">
<SplitPairFilter
window:primaryActivityName=".list.ListActivity"
window:secondaryActivityName=".details.DetailsActivity" />
</SplitPairRule>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:window="http://schemas.android.com/apk/res-auto">
<!-- Other rules -->
<SplitPlaceholderRule
window:placeholderActivityName=".details.DetailsPlaceholderActivity"
window:splitRatio="0.4">
<ActivityFilter window:activityName=".list.ListActivity" />
</SplitPlaceholderRule>
</resources>
<resources xmlns:window="http://schemas.android.com/apk/res-auto">
<SplitPairRule
<!-- split rule config option -->
>
<SplitPairFilter
window:primaryActivityName=".list.ListActivity"
window:secondaryActivityName=".details.DetailsActivity" />
<SplitPairFilter
window:primaryActivityName=".details.DetailsActivity"
window:secondaryActivityName=".share.ShareActivity" />
<resources xmlns:window="http://schemas.android.com/apk/res-auto">
<SplitPairRule
window:finishPrimaryWithSecondary="true"
window:finishSecondaryWithPrimary="true"
window:splitRatio="0.4">
<SplitPairFilter
window:primaryActivityName=".list.ListActivity"
window:secondaryActivityName=".details.DetailsActivity" />
</SplitPairRule>
</resources>
class ListActivity : AppCompatActivity() {
private val splitListener = Consumer<List<SplitInfo>> { splitInfoList ->
// React to a split change
}
override fun onStart() {
super.onStart()
SplitController
.getInstance()
val splitController = SplitController.getInstance()
if (!splitController.isSplitSupported()) {
// Split is not supported on this device
}
dependencies {
// Other app dependencies
implementation "androidx.window:window:1.0.0"
}
class ActivityEmbeddingSampleApplication : Application() {
override fun onCreate() {
super.onCreate()
SplitController.initialize(this, R.xml.split_configuration)
}
}