-
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
9 changed files
with
109 additions
and
20 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
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
72 changes: 72 additions & 0 deletions
72
android/app/src/main/java/org/wheelmap/pwawrapper/EdgeToEdgeHandler.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,72 @@ | ||
package org.wheelmap.pwawrapper | ||
|
||
import android.graphics.Color | ||
import android.os.Build | ||
import android.view.View | ||
import android.widget.RelativeLayout | ||
import androidx.annotation.RequiresApi | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.content.ContextCompat | ||
import androidx.core.view.ViewCompat | ||
|
||
class EdgeToEdgeHandler(private val activity: AppCompatActivity) { | ||
|
||
@RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM) // Android 15 | ||
fun adjustLayout(){ | ||
val rootView = activity.findViewById<RelativeLayout>(R.id.coordinatorLayout) | ||
|
||
ViewCompat.setOnApplyWindowInsetsListener(rootView) { _, windowInsets -> | ||
// Handle Status Bar Background | ||
val statusBarHeight = windowInsets.stableInsetTop | ||
if (statusBarHeight > 0) { | ||
val statusBarBackgroundView = View(activity).apply { | ||
setBackgroundColor(ContextCompat.getColor(activity, R.color.primary)) | ||
} | ||
rootView.addView( | ||
statusBarBackgroundView, | ||
RelativeLayout.LayoutParams( | ||
RelativeLayout.LayoutParams.MATCH_PARENT, | ||
statusBarHeight | ||
).apply { | ||
addRule(RelativeLayout.ALIGN_PARENT_TOP) | ||
} | ||
) | ||
} | ||
|
||
// Handle Bottom Bar Background | ||
val bottomBarHeight = windowInsets.stableInsetBottom | ||
if (bottomBarHeight > 0) { | ||
val bottomBarBackgroundView = View(activity).apply { | ||
setBackgroundColor(Color.BLACK) | ||
} | ||
rootView.addView( | ||
bottomBarBackgroundView, | ||
RelativeLayout.LayoutParams( | ||
RelativeLayout.LayoutParams.MATCH_PARENT, | ||
bottomBarHeight | ||
).apply { | ||
addRule(RelativeLayout.ALIGN_PARENT_BOTTOM) | ||
} | ||
) | ||
} | ||
windowInsets | ||
} | ||
|
||
applyMarginsToView(R.id.offlineContainer) | ||
applyMarginsToView(R.id.loadingContainer) | ||
applyMarginsToView(R.id.webView) | ||
applyMarginsToView(R.id.progressBarBottom) | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM) | ||
fun applyMarginsToView(viewId: Int) { | ||
val view = activity.findViewById<View>(viewId) | ||
|
||
ViewCompat.setOnApplyWindowInsetsListener(view) { v, windowInsets -> | ||
val layoutParams = view.layoutParams as RelativeLayout.LayoutParams | ||
layoutParams.setMargins(0, windowInsets.stableInsetTop, 0, windowInsets.stableInsetBottom) | ||
view.layoutParams = layoutParams | ||
windowInsets | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<resources> | ||
<style name="AppTheme.NoActionBar.OptOut" parent="AppTheme.NoActionBar"> | ||
<item name="android:windowOptOutEdgeToEdgeEnforcement">true</item> | ||
</style> | ||
</resources> |
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