Android: Allow timeout to fade out splash screen

Change-Id: I7b24f4d402da7f74b4c983467008ff4c19fc3b1b
Task-number: QTBUG-59200
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
This commit is contained in:
Mathias Hasselmann 2017-02-28 10:48:44 +01:00
parent 8d0b46c3ae
commit 0d34f0c9df
4 changed files with 37 additions and 8 deletions

View File

@ -62,6 +62,9 @@ import android.util.Base64;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
import android.view.KeyCharacterMap; import android.view.KeyCharacterMap;
@ -1016,11 +1019,37 @@ public class QtActivityDelegate
} }
public void hideSplashScreen() public void hideSplashScreen()
{
hideSplashScreen(0);
}
public void hideSplashScreen(final int duration)
{ {
if (m_splashScreen == null) if (m_splashScreen == null)
return; return;
m_layout.removeView(m_splashScreen);
m_splashScreen = null; if (duration <= 0) {
m_layout.removeView(m_splashScreen);
m_splashScreen = null;
return;
}
final Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setInterpolator(new AccelerateInterpolator());
fadeOut.setDuration(duration);
fadeOut.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) { hideSplashScreen(0); }
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationStart(Animation animation) {}
});
m_splashScreen.startAnimation(fadeOut);
} }

View File

@ -764,13 +764,13 @@ public class QtNative
}); });
} }
private static void hideSplashScreen() private static void hideSplashScreen(final int duration)
{ {
runAction(new Runnable() { runAction(new Runnable() {
@Override @Override
public void run() { public void run() {
if (m_activityDelegate != null) if (m_activityDelegate != null)
m_activityDelegate.hideSplashScreen(); m_activityDelegate.hideSplashScreen(duration);
} }
}); });
} }

View File

@ -406,7 +406,7 @@ jint QtAndroidPrivate::initJNI(JavaVM *vm, JNIEnv *env)
g_runPendingCppRunnablesMethodID = env->GetStaticMethodID(jQtNative, g_runPendingCppRunnablesMethodID = env->GetStaticMethodID(jQtNative,
"runPendingCppRunnablesOnAndroidThread", "runPendingCppRunnablesOnAndroidThread",
"()V"); "()V");
g_hideSplashScreenMethodID = env->GetStaticMethodID(jQtNative, "hideSplashScreen", "()V"); g_hideSplashScreenMethodID = env->GetStaticMethodID(jQtNative, "hideSplashScreen", "(I)V");
g_jNativeClass = static_cast<jclass>(env->NewGlobalRef(jQtNative)); g_jNativeClass = static_cast<jclass>(env->NewGlobalRef(jQtNative));
env->DeleteLocalRef(jQtNative); env->DeleteLocalRef(jQtNative);
@ -566,9 +566,9 @@ void QtAndroidPrivate::unregisterKeyEventListener(QtAndroidPrivate::KeyEventList
g_keyEventListeners()->listeners.removeOne(listener); g_keyEventListeners()->listeners.removeOne(listener);
} }
void QtAndroidPrivate::hideSplashScreen(JNIEnv *env) void QtAndroidPrivate::hideSplashScreen(JNIEnv *env, int duration)
{ {
env->CallStaticVoidMethod(g_jNativeClass, g_hideSplashScreenMethodID); env->CallStaticVoidMethod(g_jNativeClass, g_hideSplashScreenMethodID, duration);
} }
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -140,7 +140,7 @@ namespace QtAndroidPrivate
Q_CORE_EXPORT void registerKeyEventListener(KeyEventListener *listener); Q_CORE_EXPORT void registerKeyEventListener(KeyEventListener *listener);
Q_CORE_EXPORT void unregisterKeyEventListener(KeyEventListener *listener); Q_CORE_EXPORT void unregisterKeyEventListener(KeyEventListener *listener);
Q_CORE_EXPORT void hideSplashScreen(JNIEnv *env); Q_CORE_EXPORT void hideSplashScreen(JNIEnv *env, int duration = 0);
} }
QT_END_NAMESPACE QT_END_NAMESPACE