Skip to content

Commit

Permalink
Splash screen moved to Scanner Activity, where it's supposed to be
Browse files Browse the repository at this point in the history
  • Loading branch information
philips77 committed Nov 4, 2021
1 parent 384d38c commit 54bc7d6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 95 deletions.
15 changes: 10 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@
tools:ignore="GoogleAppIndexingWarning">

<activity
android:name=".SplashScreenActivity"
android:name=".ScannerActivity"
android:theme="@style/AppTheme.SplashScreen"
android:noHistory="true"
android:launchMode="singleTop"
android:exported="true">
<intent-filter>
Expand All @@ -101,8 +100,14 @@
</intent-filter>
</activity>

<activity
android:name=".ScannerActivity"
<!--
This activity alias is used to allow opening nRF Blinky from nRF Toolbox.
This is not required if this feature is not desired.
nRF Toolbox is displaying a different name and an icon, which are taken from this alias.
-->
<activity-alias
android:name="SplashScreenActivity"
android:targetActivity=".ScannerActivity"
android:icon="@drawable/ic_blinky_feature"
android:label="@string/feature_name"
android:launchMode="singleTop"
Expand All @@ -111,7 +116,7 @@
<action android:name="android.intent.action.MAIN"/>
<category android:name="no.nordicsemi.android.nrftoolbox.LAUNCHER"/>
</intent-filter>
</activity>
</activity-alias>

<activity
android:name=".BlinkyActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.view.Menu;
Expand All @@ -40,6 +41,7 @@
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.splashscreen.SplashScreen;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
Expand All @@ -53,12 +55,44 @@
import no.nordicsemi.android.blinky.viewmodels.ScannerViewModel;

public class ScannerActivity extends AppCompatActivity implements DevicesAdapter.OnItemClickListener {
// This flag is false when the app is first started (cold start).
// In this case, the animation will be fully shown (1 sec).
// Subsequent launches will display it only briefly.
// It is only used on API 31+
public static boolean coldStart = true;

private ScannerViewModel scannerViewModel;
private ActivityScannerBinding binding;

@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
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
// 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) {
final SplashScreen splashScreen = SplashScreen.installSplashScreen(this);

// Animated Vector Drawable is only supported on API 31+.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (coldStart) {
coldStart = false;
// Keep the splash screen on-screen for longer periods.
// Handle the splash screen transition.
final long then = System.currentTimeMillis();
splashScreen.setKeepVisibleCondition(() -> {
final long now = System.currentTimeMillis();
return now < then + 900;
});
}
}
}

binding = ActivityScannerBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

Expand Down

This file was deleted.

0 comments on commit 54bc7d6

Please sign in to comment.