Skip to content

Commit

Permalink
Improve Landscape Mode for Android Tablets (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobkoerber authored Jul 29, 2024
1 parent 1ee9744 commit 62f574a
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions android/app/src/main/kotlin/de/tum/in/tumcampus/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@ import io.flutter.embedding.android.FlutterActivity
class MainActivity : FlutterActivity() {
@SuppressLint("SourceLockedOrientationActivity")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

requestedOrientation = if (isTablet(this)) {
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
} else {
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
if (isPhone(this)) {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}

super.onCreate(savedInstanceState)
}
}

fun isTablet(context: Context): Boolean {
fun isPhone(context: Context): Boolean {
val resources = context.resources
val configuration = resources.configuration
val screenWidthDp = configuration.screenWidthDp
return screenWidthDp >= resources.getDimension(R.dimen.min_tablet_width_dp)
return screenWidthDp <= resources.getDimension(R.dimen.min_tablet_width_dp)
}

0 comments on commit 62f574a

Please sign in to comment.