Repository URL to install this package:
package com.vipera.splashscreen;
import com.vipera.de.utility.logging.impl.DELoggerFactory;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPreferences;
import org.slf4j.Logger;
/**
* Created by enrico on 24/02/17.
*/
public class DESplashScreenManager {
private static final Logger LOGGER= DELoggerFactory.getLogger(DESplashScreenManager.class);
private static final String AUTO_HIDE_PREF_TAG="desplash.autoHide";
private static final String ENABLED_PREF_TAG="desplash.enabled";
private static DESplashScreenManager instance;
private final CordovaPreferences preferences;
private DESplashScreenProvider splashScreenProvider;
private DESplashScreen splashScreen;
private DESplashScreenManager(CordovaInterface cordova, CordovaPreferences preferences) {
this.preferences=preferences;
this.splashScreenProvider=new DefaultSplashScreenProvider(cordova,preferences);
}
public void init(){
LOGGER.debug("init");
if(isEnabled()){
getSplashScreen().show();
}
}
/**
*
* @param cordova
* @param preferences
* @return
*/
public static DESplashScreenManager getInstance(CordovaInterface cordova, CordovaPreferences preferences) {
if(instance==null){
instance=new DESplashScreenManager(cordova,preferences);
}
return instance;
}
/**
* Get the current splashScreen provider
* @return
*/
public DESplashScreenProvider getSplashScreenProvider() {
return splashScreenProvider;
}
/**
* Set the current splashScreen provider
* @param splashScreenProvider
*/
public void setSplashScreenProvider(DESplashScreenProvider splashScreenProvider) {
LOGGER.debug("DESplashScreenProvider class: {}",splashScreenProvider.getClass());
this.splashScreenProvider = splashScreenProvider;
}
public DESplashScreen getSplashScreen() {
if(splashScreen == null){
splashScreen = splashScreenProvider.provideSplashScreen();
}
return splashScreen;
}
public void show(){
getSplashScreen().show();
}
public void hide(){
getSplashScreen().hide();
}
public void destroy(){
getSplashScreen().destroy();
this.splashScreenProvider.dispose();
instance=null;
}
public boolean isEnabled(){
return preferences.getBoolean(ENABLED_PREF_TAG,true);
}
public boolean isAutoHide(){
return preferences.getBoolean(AUTO_HIDE_PREF_TAG,true);
}
public void autoHide(){
LOGGER.debug("Evaluate autoHide");
if(isEnabled() && isAutoHide()){
LOGGER.debug("AutoHide required");
getSplashScreen().hide();
//getSplashScreen().destroy();
}
}
}