Update the orientation of the NavScreen on orientationChange.
Before, it was destroying all the UI objects and recreating them,
no matter if the tab switcher was visible or not. The new behavior
matches the old one visually, but happens in a fraction of the
time.
Also, this updates a bit the visibility of properties in the class.
This class should require more cleanup in the future.
Change-Id: I4e5be461aa954faf8fc6b8d50fa8dd865a72e564
diff --git a/src/com/android/browser/NavTabScroller.java b/src/com/android/browser/NavTabScroller.java
index 39c73ac..220f44c 100644
--- a/src/com/android/browser/NavTabScroller.java
+++ b/src/com/android/browser/NavTabScroller.java
@@ -30,6 +30,7 @@
import android.view.ViewGroup;
import android.view.animation.DecelerateInterpolator;
import android.widget.BaseAdapter;
+import android.widget.FrameLayout;
import android.widget.LinearLayout;
import com.android.browser.view.ScrollerView;
@@ -126,6 +127,17 @@
new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
}
super.setOrientation(orientation);
+
+ // update the layout parameters of existing views (to not destroy/recreate all)
+ final int childCount = mContentView.getChildCount();
+ for (int i = 0; i < childCount; i++) {
+ final View view = mContentView.getChildAt(i);
+ final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
+ lp.gravity = (mHorizontal ? Gravity.CENTER_VERTICAL : Gravity.CENTER_HORIZONTAL);
+ view.setLayoutParams(lp);
+ if (mGapPosition > INVALID_POSITION)
+ adjustViewGap(view, i);
+ }
}
@Override
@@ -190,6 +202,10 @@
handleDataChanged(INVALID_POSITION);
}
+ void setScrollOnNextLayout() {
+ mNeedsScroll = true;
+ }
+
void handleDataChanged(int newscroll) {
int scroll = getScrollValue();
if (mGapAnimator != null) {
@@ -381,8 +397,10 @@
|| (mGap > 0 && pos < mGapPosition)) {
if (mHorizontal) {
view.setTranslationX(mGap);
+ view.setTranslationY(0);
} else {
view.setTranslationY(mGap);
+ view.setTranslationX(0);
}
}
}