Skip to content

Commit

Permalink
feat: re-add AutoHideSplashScreen and SplashScreenDelay preference su…
Browse files Browse the repository at this point in the history
…pport
  • Loading branch information
erisu committed Jun 21, 2022
1 parent 113d3af commit 95737bd
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions templates/project/Activity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ Licensed to the Apache Software Foundation (ASF) under one
package __ID__;

import android.os.Bundle;
import android.os.Handler;
import android.util.Log;

import org.apache.cordova.*;
import androidx.core.splashscreen.SplashScreen;

public class __ACTIVITY__ extends CordovaActivity
{
private boolean splashScreenKeepOnScreen = true;

@Override
public void onCreate(Bundle savedInstanceState)
{
Expand All @@ -33,6 +38,9 @@ public void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

// Setup the splash screen delay based on preference settings
setupSplashScreenDelay(splashScreen);

// enable Cordova apps to be started in the background
Bundle extras = getIntent().getExtras();
if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
Expand All @@ -42,4 +50,22 @@ public void onCreate(Bundle savedInstanceState)
// Set by <content src="index.html" /> in config.xml
loadUrl(launchUrl);
}

private void setupSplashScreenDelay(SplashScreen splashScreen) {
boolean splashScreenAutoHide = preferences.getBoolean("AutoHideSplashScreen", true);
int splashScreenDelay = preferences.getInteger("SplashScreenDelay", 3000);

Log.d("CdvSplashScreen", "Auto Hide: " + splashScreenAutoHide);

if (splashScreenAutoHide) {
Log.d("CdvSplashScreen", "Delay: " + splashScreenDelay + "ms");

splashScreen.setKeepOnScreenCondition(() -> splashScreenKeepOnScreen);
Handler splashScreenDelayHandler = new Handler();
splashScreenDelayHandler.postDelayed(
() -> splashScreenKeepOnScreen = false,
splashScreenDelay
);
}
}
}

0 comments on commit 95737bd

Please sign in to comment.