Skip to content
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

Splash screen fixed on Android Lollipop #60

Merged
merged 1 commit into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,27 @@ public class ScannerActivity extends AppCompatActivity implements DevicesAdapter

@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
// The splash screen compat library does not work for pre-Lollipop devices
// so for them the theme needs to be set back to AppTheme.
// The AppTheme.SplashScreen theme will only be used to display the loading image.
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
setTheme(R.style.AppTheme);
}
// Set the proper theme for the Activity. This could have been set in "v23/styles..xml"
// as "postSplashScreenTheme", but as this app works on pre-API-23 devices, it needs to be
// set for them as well, and that code would not apply in suce case.
// As "postSplashScreenTheme" is optional, and setting the theme can be done using
// setTheme, this is preferred in our case, as this also work for older platforms.
setTheme(R.style.AppTheme);

super.onCreate(savedInstanceState);

// Set up the splash screen.
// The app is using SplashScreen compat library, which is supported on Android 5+.
// On Android 12+ the splash screen will be animated, while on 5-11 will present a still
// The app is using SplashScreen compat library, which is supported on Android 5+, but the
// icon is only supported on API 23+.
//
// See: https://android.googlesource.com/platform/frameworks/support/+/androidx-main/core/core-splashscreen/src/main/java/androidx/core/splashscreen/package-info.java
//
// On Android 12+ the splash screen will be animated, while on 6 - 11 will present a still
// image. See more: https://developer.android.com/guide/topics/ui/splash-screen/
//
// As nRF Blinky supports Android 4.3+, on older platforms a 9-patch image is presented
// without the use of SplashScreen compat library.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
final SplashScreen splashScreen = SplashScreen.installSplashScreen(this);

// Animated Vector Drawable is only supported on API 31+.
Expand Down
53 changes: 0 additions & 53 deletions app/src/main/res/values-v21/styles.xml

This file was deleted.

26 changes: 26 additions & 0 deletions app/src/main/res/values-v23/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,32 @@
-->

<resources>

<!-- Configuration for compat splashscreen, from androidx.core.core-splashscreen. -->
<style name="AppTheme.SplashScreenBase" parent="Theme.SplashScreen">
<!--
Set the splash screen background.
The window background will be white in light mode, and black in dark mode.
-->
<!--<item name="windowSplashScreenBackground">@color/nordicBlue</item>-->

<!--
Use windowSplashScreenAnimatedIcon to add either a drawable or an
animated drawable. One of these is required.
-->
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_splash_screen</item>
<!-- Required for animated icons-->
<item name="windowSplashScreenAnimationDuration">900</item>

<!--
Set the theme of the Activity that directly follows your splash screen.
This is no longer required since alpha02:
https://developer.android.com/jetpack/androidx/releases/core#core-splashscreen-1.0.0-alpha02

<item name="postSplashScreenTheme">@style/AppTheme</item>
-->
</style>

<style name="AppTheme.SplashScreen" parent="AppTheme.SplashScreenBase">
<!-- Using translucent status bar. -->
<item name="android:windowTranslucentStatus">true</item>
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@

<!--
Splash screen configuration.
On API 18-20 the splash screen is using a normal activity, which displays windowBackground.
On API 18-22 the splash screen is using a normal activity, which displays windowBackground.

Above API 21 it is using androidx.core.core-splashscreen implementation and the theme is
overwritten in styles-v21.
From API 23 it is using androidx.core.core-splashscreen implementation and the theme is
overwritten in styles-v23.
As of version alpha02 of this library, the splash screen icon is supported on API 23+.
-->
<style name="AppTheme.SplashScreenBase">
<!-- Draw splash screen an window background. -->
Expand Down