-
Notifications
You must be signed in to change notification settings - Fork 386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android 15 support #2624
base: dev
Are you sure you want to change the base?
Android 15 support #2624
Conversation
brandonpage
commented
Sep 28, 2024
- Bumped compileSdk and targetSdk of sample apps to 35 and Gradle to 8.6.1 to match.
- Fixed an issue related to new intent rules in Android 15 that broke IDP initiated IDP flow.
- Enabled Edge to Edge UI for ScreenLockActivity and fixed the status bar icon color in dark mode.
- Conditionally (if app targets API 35+) enabled Edge to Edge for all other screens. Fixed layouts taking the entire screen and showing behind status and navigation bars. Fixed status and navigation bar colors for all screens.
…ar colors. Fix Android 15 IDP issue.
// TODO: Remove this in 13.0 after rewriting screens in compose. | ||
internal fun AppCompatActivity.fixEdgeToEdge(view: View) { | ||
if (application.applicationInfo.targetSdkVersion > UPSIDE_DOWN_CAKE) { | ||
enableEdgeToEdge() | ||
ViewCompat.setOnApplyWindowInsetsListener(view) { listenerView, windowInsets -> | ||
val insets = windowInsets.getInsets( | ||
WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout() | ||
) | ||
|
||
// Fix screens being drawn behind status and navigation bars | ||
listenerView.updatePadding(insets.left, insets.top, insets.right, insets.bottom) | ||
|
||
// Fix transparent status bar not matching action bar | ||
val background = ResourcesCompat.getDrawable(resources, sf__fix_status_bar, null) | ||
val statusBarFiller = (background as LayerDrawable).findDrawableByLayerId(sf__status_bar_background) | ||
statusBarFiller.setBounds(0, 0, insets.right, insets.bottom) | ||
view.setBackgroundResource(sf__fix_status_bar) | ||
|
||
WindowInsetsCompat.CONSUMED | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where all of UX magic happens 🪄 ✨
<?xml version="1.0" encoding="utf-8"?> | ||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:id="@+id/sf__status_bar_background" android:height="100dp" > | ||
<shape android:shape="rectangle"> | ||
<size android:height="100dp" android:width="100dp"/> | ||
<solid android:color="@color/sf__primary_color"/> | ||
</shape> | ||
</item> | ||
|
||
<item android:id="@+id/sf__nav_bar_background" android:height="100dp"> | ||
<shape android:shape="rectangle"> | ||
<size android:height="100dp" android:width="100dp"/> | ||
<solid android:color="@android:color/transparent"/> | ||
</shape> | ||
</item> | ||
</layer-list> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is sort of a hack to fill in the status and navigation bars with the appropriate color since they are now forced transparent and completely unsettable in Edge to Edge. Note that I am changing the height of the top rectangle to match the device status bar height in code!
@@ -214,6 +213,7 @@ internal class IDPManager( | |||
addCategory(Intent.CATEGORY_DEFAULT) | |||
} | |||
startActivity(activeFlow.context, launchIntent) | |||
activeFlow.authCodeActivity?.finish() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The IDP fix.
listenerView.updatePadding(insets.left, insets.top, insets.right, insets.bottom) | ||
|
||
// Fix transparent status bar not matching action bar | ||
val background = ResourcesCompat.getDrawable(resources, sf__fix_status_bar, null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a chance background could be null? Should we check for null? E.g. if they subclass our activity and use a different layout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"background" is the new sf__fix_status_bar.xml drawable added in this PR. I set it as the background of the activity later with view.setBackgroundResource(sf__fix_status_bar)
.
The drawable is split in half, the top being sf__primary_color
and the bottom is transparent. I am getting a reference to it here so I can set the height of the top to the height of the status bar. This mimics the old look.
|
||
// TODO: Remove this in 13.0 after rewriting screens in compose. | ||
internal fun AppCompatActivity.fixEdgeToEdge(view: View) { | ||
if (application.applicationInfo.targetSdkVersion > UPSIDE_DOWN_CAKE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should actually check this and SDK_INT
so we don't do anything special on pre-Android 15 devices.
val background = ResourcesCompat.getDrawable(resources, sf__fix_status_bar, null) | ||
val statusBarFiller = (background as LayerDrawable).findDrawableByLayerId(sf__status_bar_background) | ||
statusBarFiller.setBounds(0, 0, insets.right, insets.bottom) | ||
view.setBackgroundResource(sf__fix_status_bar) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think setBackgroundResource
does a getDrawable
followed by setBackground
so we could just do:
view.setBackground(background)
Also we might only want to set the background once:
if (view.background != background) {
view.setBackground(background)
}