make Trackbook work better with different status bar heights (e.g. on phones with camera cutouts.)

This commit is contained in:
y20k 2020-10-05 14:00:44 +02:00
parent acfb902a39
commit 7805f6aaeb
No known key found for this signature in database
GPG key ID: 824D4259F41FAFF6
9 changed files with 38 additions and 23 deletions

View file

@ -4,13 +4,13 @@ apply plugin: 'kotlin-android-extensions'
apply plugin: 'androidx.navigation.safeargs.kotlin' apply plugin: 'androidx.navigation.safeargs.kotlin'
android { android {
compileSdkVersion 29 compileSdkVersion 30
buildToolsVersion "29.0.3" buildToolsVersion "29.0.3"
defaultConfig { defaultConfig {
applicationId 'org.y20k.trackbook' applicationId 'org.y20k.trackbook'
minSdkVersion 25 minSdkVersion 25
targetSdkVersion 29 targetSdkVersion 30
versionCode 43 versionCode 43
versionName '2.0.6' versionName '2.0.6'
resConfigs "en", "da", "de", "fr", "hr", "id", "it", "ja", "nb-rNO", "nl", "pt-rBR", "sv", "zh-rCN" resConfigs "en", "da", "de", "fr", "hr", "id", "it", "ja", "nb-rNO", "nl", "pt-rBR", "sv", "zh-rCN"
@ -59,7 +59,7 @@ dependencies {
// AndroidX // AndroidX
implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'androidx.core:core-ktx:1.3.1' implementation 'androidx.core:core-ktx:1.3.2'
implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version" implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
implementation "androidx.navigation:navigation-ui-ktx:$navigation_version" implementation "androidx.navigation:navigation-ui-ktx:$navigation_version"
implementation 'androidx.preference:preference-ktx:1.1.1' implementation 'androidx.preference:preference-ktx:1.1.1'

View file

@ -75,7 +75,8 @@ class MapFragment : Fragment(), YesNoDialog.YesNoDialogListener, MapOverlayHelpe
/* Overrides onStop from Fragment */ /* Overrides onStop from Fragment */
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
// initialize layout // initialize layout
layout = MapFragmentLayoutHolder(activity as Context, this as MapOverlayHelper.MarkerListener, inflater, container, currentBestLocation, trackingState) val statusBarHeight: Int = UiHelper.getStatusBarHeight(activity as Context)
layout = MapFragmentLayoutHolder(activity as Context, this as MapOverlayHelper.MarkerListener, inflater, container, statusBarHeight, currentBestLocation, trackingState)
// set up buttons // set up buttons
layout.currentLocationButton.setOnClickListener { layout.currentLocationButton.setOnClickListener {

View file

@ -30,10 +30,7 @@ import android.widget.Toast
import androidx.preference.* import androidx.preference.*
import kotlinx.coroutines.* import kotlinx.coroutines.*
import org.y20k.trackbook.core.Tracklist import org.y20k.trackbook.core.Tracklist
import org.y20k.trackbook.helpers.AppThemeHelper import org.y20k.trackbook.helpers.*
import org.y20k.trackbook.helpers.FileHelper
import org.y20k.trackbook.helpers.LengthUnitHelper
import org.y20k.trackbook.helpers.LogHelper
/* /*
@ -51,7 +48,7 @@ class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogList
// set the background color // set the background color
view.setBackgroundColor(resources.getColor(R.color.app_window_background, null)) view.setBackgroundColor(resources.getColor(R.color.app_window_background, null))
// add padding - necessary because translucent status bar is used // add padding - necessary because translucent status bar is used
val topPadding = this.resources.displayMetrics.density * 24 // 24 dp * display density val topPadding = UiHelper.getStatusBarHeight(activity as Context)
view.setPadding(0, topPadding.toInt(), 0, 0) view.setPadding(0, topPadding.toInt(), 0, 0)
} }

View file

@ -39,10 +39,7 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.y20k.trackbook.core.Track import org.y20k.trackbook.core.Track
import org.y20k.trackbook.dialogs.RenameTrackDialog import org.y20k.trackbook.dialogs.RenameTrackDialog
import org.y20k.trackbook.helpers.FileHelper import org.y20k.trackbook.helpers.*
import org.y20k.trackbook.helpers.LogHelper
import org.y20k.trackbook.helpers.MapOverlayHelper
import org.y20k.trackbook.helpers.TrackHelper
import org.y20k.trackbook.ui.TrackFragmentLayoutHolder import org.y20k.trackbook.ui.TrackFragmentLayoutHolder
@ -73,7 +70,8 @@ class TrackFragment : Fragment(), RenameTrackDialog.RenameTrackListener, YesNoDi
/* Overrides onCreateView from Fragment */ /* Overrides onCreateView from Fragment */
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
// initialize layout // initialize layout
layout = TrackFragmentLayoutHolder(activity as Context, this as MapOverlayHelper.MarkerListener, inflater, container, track) val statusBarHeight: Int = UiHelper.getStatusBarHeight(activity as Context)
layout = TrackFragmentLayoutHolder(activity as Context, this as MapOverlayHelper.MarkerListener, inflater, statusBarHeight, container, track)
// set up share button // set up share button
layout.shareButton.setOnClickListener { layout.shareButton.setOnClickListener {

View file

@ -67,6 +67,10 @@ class TracklistFragment : Fragment(), TracklistAdapter.TracklistAdapterListener,
trackElementList = rootView.findViewById(R.id.track_element_list) trackElementList = rootView.findViewById(R.id.track_element_list)
tracklistOnboarding = rootView.findViewById(R.id.track_list_onboarding) tracklistOnboarding = rootView.findViewById(R.id.track_list_onboarding)
// add padding - necessary because translucent status bar is used
val topPadding = UiHelper.getStatusBarHeight(activity as Context)
trackElementList.setPadding(0, topPadding.toInt(), 0, 0)
// set up recycler view // set up recycler view
trackElementList.layoutManager = CustomLinearLayoutManager(activity as Context) trackElementList.layoutManager = CustomLinearLayoutManager(activity as Context)
trackElementList.itemAnimator = DefaultItemAnimator() trackElementList.itemAnimator = DefaultItemAnimator()

View file

@ -65,6 +65,24 @@ object UiHelper {
} }
/* Get the height of the system's top status bar */
fun getStatusBarHeight(context: Context): Int {
var result: Int = 0
val resourceId: Int = context.resources.getIdentifier("status_bar_height", "dimen", "android")
if (resourceId > 0) {
result = context.resources.getDimensionPixelSize(resourceId)
}
return result
}
/* Get scaling factor from display density */
fun getDensityScalingFactor(context: Context): Float {
return context.resources.displayMetrics.density
}
/* /*
* Inner class: Callback that detects a left swipe * Inner class: Callback that detects a left swipe
* Credit: https://github.com/kitek/android-rv-swipe-delete/blob/master/app/src/main/java/pl/kitek/rvswipetodelete/SwipeToDeleteCallback.kt * Credit: https://github.com/kitek/android-rv-swipe-delete/blob/master/app/src/main/java/pl/kitek/rvswipetodelete/SwipeToDeleteCallback.kt

View file

@ -42,16 +42,13 @@ import org.osmdroid.views.overlay.compass.InternalCompassOrientationProvider
import org.y20k.trackbook.Keys import org.y20k.trackbook.Keys
import org.y20k.trackbook.R import org.y20k.trackbook.R
import org.y20k.trackbook.core.Track import org.y20k.trackbook.core.Track
import org.y20k.trackbook.helpers.AppThemeHelper import org.y20k.trackbook.helpers.*
import org.y20k.trackbook.helpers.LogHelper
import org.y20k.trackbook.helpers.MapOverlayHelper
import org.y20k.trackbook.helpers.PreferencesHelper
/* /*
* MapFragmentLayoutHolder class * MapFragmentLayoutHolder class
*/ */
data class MapFragmentLayoutHolder(private var context: Context, private var markerListener: MapOverlayHelper.MarkerListener, private var inflater: LayoutInflater, private var container: ViewGroup?, private val startLocation: Location, private val trackingState: Int) { data class MapFragmentLayoutHolder(private var context: Context, private var markerListener: MapOverlayHelper.MarkerListener, private var inflater: LayoutInflater, private var container: ViewGroup?, private var statusBarHeight: Int ,private val startLocation: Location, private val trackingState: Int) {
/* Define log tag */ /* Define log tag */
private val TAG: String = LogHelper.makeLogTag(MapFragmentLayoutHolder::class.java) private val TAG: String = LogHelper.makeLogTag(MapFragmentLayoutHolder::class.java)
@ -104,7 +101,7 @@ data class MapFragmentLayoutHolder(private var context: Context, private var mar
// add compass to map // add compass to map
val compassOverlay = CompassOverlay(context, InternalCompassOrientationProvider(context), mapView) val compassOverlay = CompassOverlay(context, InternalCompassOrientationProvider(context), mapView)
compassOverlay.enableCompass() compassOverlay.enableCompass()
compassOverlay.setCompassCenter(36f, 60f) compassOverlay.setCompassCenter(36f, 36f + (statusBarHeight / UiHelper.getDensityScalingFactor(context)))
mapView.overlays.add(compassOverlay) mapView.overlays.add(compassOverlay)

View file

@ -53,7 +53,7 @@ import kotlin.math.roundToInt
/* /*
* TrackFragmentLayoutHolder class * TrackFragmentLayoutHolder class
*/ */
data class TrackFragmentLayoutHolder(private var context: Context, private var markerListener: MapOverlayHelper.MarkerListener, private var inflater: LayoutInflater, private var container: ViewGroup?, var track: Track): MapListener { data class TrackFragmentLayoutHolder(private var context: Context, private var markerListener: MapOverlayHelper.MarkerListener, private var inflater: LayoutInflater, private var statusBarHeight: Int, private var container: ViewGroup?, var track: Track): MapListener {
/* Define log tag */ /* Define log tag */
private val TAG: String = LogHelper.makeLogTag(TrackFragmentLayoutHolder::class.java) private val TAG: String = LogHelper.makeLogTag(TrackFragmentLayoutHolder::class.java)
@ -140,7 +140,7 @@ data class TrackFragmentLayoutHolder(private var context: Context, private var m
// add compass to map // add compass to map
val compassOverlay = CompassOverlay(context, InternalCompassOrientationProvider(context), mapView) val compassOverlay = CompassOverlay(context, InternalCompassOrientationProvider(context), mapView)
compassOverlay.enableCompass() compassOverlay.enableCompass()
compassOverlay.setCompassCenter(36f, 60f) compassOverlay.setCompassCenter(36f, 36f + (statusBarHeight / UiHelper.getDensityScalingFactor(context)))
mapView.overlays.add(compassOverlay) mapView.overlays.add(compassOverlay)
// create map overlay // create map overlay

View file

@ -12,7 +12,7 @@
android:id="@+id/track_element_list" android:id="@+id/track_element_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_marginTop="28dp" android:layout_marginTop="4dp"
android:layout_marginBottom="4dp" android:layout_marginBottom="4dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"