https://github.com/WhiteDog-Apps/FoldableActivity_Android
Android library that simplifies the logic necessary to detect state changes in foldable devices
https://github.com/WhiteDog-Apps/FoldableActivity_Android
android android-library flip fold foldable kotlin
Last synced: about 2 months ago
JSON representation
Android library that simplifies the logic necessary to detect state changes in foldable devices
- Host: GitHub
- URL: https://github.com/WhiteDog-Apps/FoldableActivity_Android
- Owner: WhiteDog-Apps
- Created: 2021-06-10T21:46:27.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-09-22T11:40:15.000Z (over 1 year ago)
- Last Synced: 2024-11-07T13:37:08.306Z (7 months ago)
- Topics: android, android-library, flip, fold, foldable, kotlin
- Language: Kotlin
- Homepage:
- Size: 185 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-list - WhiteDog-Apps/FoldableActivity_Android - Android library that simplifies the logic necessary to detect state changes in foldable devices (Kotlin)
README
[](https://jitpack.io/#WhiteDog-Apps/FoldableActivity_Android)
# FoldableActivity
Android library that simplifies the logic necessary to detect state changes in foldable devices,## Setup
#### 1. Add the JitPack repository to your "settings.gradle" file if you didn't add before.
```gradle
pluginManagement {
...
}
dependencyResolutionManagement {
...
repositories {
...
maven { url 'https://jitpack.io' }
}
}
...
```#### 2. Add the dependency
```gradle
dependencies {
implementation 'com.github.WhiteDog-Apps:FoldableActivity_Android:1.0.4'
}
```## Usage
#### 1. Make your activity inherit from FoldableActivity
```kotlin
class MainActivity: FoldableActivity() {
...
}
```#### 2. Implements members
```kotlin
override fun getRootView(): View {
// Return the view where you will control the fold
}override fun onFoldablePostureChanged(foldPosture: FoldPosture, foldPositionFromEnd: Int) {
// Update UI
}
```## Example
```kotlin
// 1. Make your activity inherit from FoldableActivity
class MainActivity: FoldableActivity() {override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}// 2. Implements members
override fun getRootView(): View {
return findViewById(R.id.motion_layout_guides_root)
}override fun onFoldablePostureChanged(foldPosture: FoldPosture, foldPositionFromEnd: Int) {
when(foldPosture) {
FoldPosture.TABLE_TOP -> {
ConstraintLayout.getSharedValues().fireNewValue(R.id.rg_motion_layout_guides_tabletop, foldPositionFromEnd)
ConstraintLayout.getSharedValues().fireNewValue(R.id.rg_motion_layout_guides_book, 0)
}
FoldPosture.BOOK -> {
ConstraintLayout.getSharedValues().fireNewValue(R.id.rg_motion_layout_guides_tabletop, 0)
ConstraintLayout.getSharedValues().fireNewValue(R.id.rg_motion_layout_guides_book, foldPositionFromEnd)
}
else -> {
ConstraintLayout.getSharedValues().fireNewValue(R.id.rg_motion_layout_guides_tabletop, 0)
ConstraintLayout.getSharedValues().fireNewValue(R.id.rg_motion_layout_guides_book, 0)
}
}
}
}
```