From 90808ead98edbab33a6bcc724d123864842a5ed3 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 22 May 2014 14:10:53 +0200 Subject: Android: Fix flashing on startup/shutdown There were several issues on startup of the application which were caused by the fact that we would get the wrong available screen geometry on startup, set this as the initial surface size and then expose native windows with this size. This would cause first a flicker of white on the early expose and the window contents to jump around as the window was resized to the actual available space on screen. The fix for this is to postpone the first expose until we have actually got a proper screen size from the main layout. We use width,height = 0 as an indicator that the available geometry is not yet known, and we skip posting any expose events before this is set by the layout. In addition, since we removed the surface before we shut down the application, it was by a white rectangle before the shutdown transition happens, and this white rectangle will be animated instead of application contents. To rectify this, we make sure the last surface in the stack remains in the layout until it is either replaced by a different surface or until the application has shut down. This way, the shutdown animation will work on this surface instead. [ChangeLog][Android] Fixed regression where there would be flickering on startup and shutdown of the application. Task-number: QTBUG-38960 Change-Id: Ia1579ca8c522d8beeab066f78070ad49009d0238 Reviewed-by: Paul Olav Tvete --- .../qtproject/qt5/android/QtActivityDelegate.java | 33 ++++++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'src/android/jar') diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java index 554c54d4a0..c39bd1a749 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java @@ -118,6 +118,7 @@ public class QtActivityDelegate private InputMethodManager m_imm = null; private boolean m_quitApp = true; private Process m_debuggerProcess = null; // debugger process + private View m_dummyView = null; private boolean m_keyboardIsVisible = false; public boolean m_backKeyPressedSent = false; @@ -667,7 +668,7 @@ public class QtActivityDelegate DisplayMetrics metrics = new DisplayMetrics(); m_activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); QtNative.setApplicationDisplayMetrics(metrics.widthPixels, metrics.heightPixels, - metrics.widthPixels, metrics.heightPixels, + 0, 0, metrics.xdpi, metrics.ydpi, metrics.scaledDensity); } m_layout = new QtLayout(m_activity); @@ -677,6 +678,10 @@ public class QtActivityDelegate m_nativeViews = new HashMap(); m_activity.registerForContextMenu(m_layout); + m_activity.setContentView(m_layout, + new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT)); + int orientation = m_activity.getResources().getConfiguration().orientation; int rotation = m_activity.getWindowManager().getDefaultDisplay().getRotation(); boolean rot90 = (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270); @@ -1001,6 +1006,11 @@ public class QtActivityDelegate } public void insertNativeView(int id, View view, int x, int y, int w, int h) { + if (m_dummyView != null) { + m_layout.removeView(m_dummyView); + m_dummyView = null; + } + if (m_nativeViews.containsKey(id)) m_layout.removeView(m_nativeViews.remove(id)); @@ -1026,9 +1036,10 @@ public class QtActivityDelegate m_activity.getWindow().setBackgroundDrawable(m_activity.getResources().getDrawable(attr.resourceId)); } - m_activity.setContentView(m_layout, - new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT)); + if (m_dummyView != null) { + m_layout.removeView(m_dummyView); + m_dummyView = null; + } } if (m_surfaces.containsKey(id)) @@ -1065,12 +1076,22 @@ public class QtActivityDelegate } public void destroySurface(int id) { + View view = null; + if (m_surfaces.containsKey(id)) { - m_layout.removeView(m_surfaces.remove(id)); + view = m_surfaces.remove(id); } else if (m_nativeViews.containsKey(id)) { - m_layout.removeView(m_nativeViews.remove(id)); + view = m_nativeViews.remove(id); } else { Log.e(QtNative.QtTAG, "Surface " + id +" not found!"); } + + // Keep last frame in stack until it is replaced to get correct + // shutdown transition + if (m_surfaces.size() == 0 && m_nativeViews.size() == 0) { + m_dummyView = view; + } else if (view != null) { + m_layout.removeView(view); + } } } -- cgit v1.2.3