diff options
author | Christian Strømme <christian.stromme@theqtcompany.com> | 2015-05-29 17:23:37 +0200 |
---|---|---|
committer | Christian Stromme <christian.stromme@theqtcompany.com> | 2015-10-19 11:47:38 +0000 |
commit | 1811e31cdbce08ce59eb673fa64a43192006afd9 (patch) | |
tree | 0441fc2cec21aec389c7629c6aa33c83abe5a38a /src/android | |
parent | 5afc431323454225363dae30e67a1cb909086bf9 (diff) |
Android: Improve the way we update layout params for native views.
Removing and adding a view each time the layout parameters changes is
triggering unnecessary layout updates. The affect of this is not very
visible since there are few views in the layout, but the procedure is
never the less wasteful.
Change-Id: I2540ab519b12c6d3e10457e2e518b439118b966d
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
Diffstat (limited to 'src/android')
-rw-r--r-- | src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java | 9 | ||||
-rw-r--r-- | src/android/jar/src/org/qtproject/qt5/android/QtLayout.java | 30 |
2 files changed, 33 insertions, 6 deletions
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 ba3ecfecd6..b7190fd4de 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java @@ -312,8 +312,7 @@ public class QtActivityDelegate m_editText.setImeOptions(imeOptions); m_editText.setInputType(inputType); - m_layout.removeView(m_editText); - m_layout.addView(m_editText, new QtLayout.LayoutParams(width, height, x, y)); + m_layout.setLayoutParams(m_editText, new QtLayout.LayoutParams(width, height, x, y), false); m_editText.requestFocus(); m_editText.postDelayed(new Runnable() { @Override @@ -1091,12 +1090,10 @@ public class QtActivityDelegate if (Build.VERSION.SDK_INT < 11 || w <= 0 || h <= 0) { m_activity.openContextMenu(m_layout); } else if (Build.VERSION.SDK_INT < 14) { - m_layout.removeView(m_editText); - m_layout.addView(m_editText, new QtLayout.LayoutParams(w, h, x, y)); + m_layout.setLayoutParams(m_editText, new QtLayout.LayoutParams(w, h, x, y), false); QtPopupMenu.getInstance().showMenu(m_editText); } else { - m_layout.removeView(m_editText); - m_layout.addView(m_editText, new QtLayout.LayoutParams(w, h, x, y)); + m_layout.setLayoutParams(m_editText, new QtLayout.LayoutParams(w, h, x, y), false); QtPopupMenu14.getInstance().showMenu(m_editText); } } diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtLayout.java b/src/android/jar/src/org/qtproject/qt5/android/QtLayout.java index 4d7ca47dde..408636dcf3 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtLayout.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtLayout.java @@ -216,4 +216,34 @@ public class QtLayout extends ViewGroup invalidate(); attachViewToParent(view, index, view.getLayoutParams()); } + + /** + * set the layout params on a child view. + * + * Note: This function adds the child view if it's not in the + * layout already. + */ + public void setLayoutParams(final View childView, + final ViewGroup.LayoutParams params, + final boolean forceRedraw) + { + // Invalid view + if (childView == null) + return; + + // Invalid params + if (!checkLayoutParams(params)) + return; + + // View is already in the layout and can therefore be updated + final boolean canUpdate = (this == childView.getParent()); + + if (canUpdate) { + childView.setLayoutParams(params); + if (forceRedraw) + invalidate(); + } else { + addView(childView, params); + } + } } |