Skip to content

Commit 62f574a

Browse files
authored
Improve Landscape Mode for Android Tablets (#263)
1 parent 1ee9744 commit 62f574a

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

android/app/src/main/kotlin/de/tum/in/tumcampus/MainActivity.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,17 @@ import io.flutter.embedding.android.FlutterActivity
1010
class MainActivity : FlutterActivity() {
1111
@SuppressLint("SourceLockedOrientationActivity")
1212
override fun onCreate(savedInstanceState: Bundle?) {
13-
super.onCreate(savedInstanceState)
14-
15-
requestedOrientation = if (isTablet(this)) {
16-
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
17-
} else {
18-
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
13+
if (isPhone(this)) {
14+
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
1915
}
16+
17+
super.onCreate(savedInstanceState)
2018
}
2119
}
2220

23-
fun isTablet(context: Context): Boolean {
21+
fun isPhone(context: Context): Boolean {
2422
val resources = context.resources
2523
val configuration = resources.configuration
2624
val screenWidthDp = configuration.screenWidthDp
27-
return screenWidthDp >= resources.getDimension(R.dimen.min_tablet_width_dp)
25+
return screenWidthDp <= resources.getDimension(R.dimen.min_tablet_width_dp)
2826
}

0 commit comments

Comments
 (0)