-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
11 changed files
with
294 additions
and
68 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Binary file not shown.
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
40 changes: 40 additions & 0 deletions
40
app/src/main/java/com/sqz/writingboard/KeyboardListening.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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.sqz.writingboard | ||
|
||
import android.content.Context | ||
import android.graphics.Rect | ||
import android.view.ViewTreeObserver | ||
import android.view.inputmethod.InputMethodManager | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.DisposableEffect | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.platform.LocalView | ||
|
||
@Composable | ||
fun KeyboardVisibilityObserver( | ||
onKeyboardVisibilityChanged: (Boolean) -> Unit | ||
) { | ||
val context = LocalContext.current | ||
val rootView = LocalView.current | ||
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager | ||
|
||
DisposableEffect(rootView, imm) { | ||
val listener = ViewTreeObserver.OnGlobalLayoutListener { | ||
val rect = Rect() | ||
rootView.getWindowVisibleDisplayFrame(rect) | ||
val screenHeight = rootView.height | ||
|
||
// Calculate the remaining visible height of the layout. If it's less than half of the screen height, consider the keyboard visible. | ||
val keypadHeight = screenHeight - rect.bottom | ||
val isKeyboardVisible = keypadHeight > screenHeight * 0.15 | ||
|
||
onKeyboardVisibilityChanged(isKeyboardVisible) | ||
} | ||
|
||
rootView.viewTreeObserver.addOnGlobalLayoutListener(listener) | ||
|
||
// Remove the listener when the DisposableEffect is disposed. | ||
onDispose { | ||
rootView.viewTreeObserver.removeOnGlobalLayoutListener(listener) | ||
} | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
app/src/main/java/com/sqz/writingboard/ui/WritingBoardInitScreen.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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.sqz.writingboard.ui | ||
|
||
import android.util.Log | ||
import androidx.compose.foundation.background | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.tooling.preview.Preview | ||
|
||
@Composable | ||
fun WritingBoardNone(modifier: Modifier = Modifier) { | ||
Surface( | ||
modifier = modifier | ||
.background( | ||
MaterialTheme.colorScheme.surfaceVariant | ||
) | ||
) { Log.i("WritingBoardTag", "NoneScreen has open") } | ||
} | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
fun WritingBoardScreenPreview() { | ||
WritingBoardNone() | ||
} |
Oops, something went wrong.