diff --git a/android/src/com/mapswithme/maps/dialog/RoutingErrorDialogFragment.java b/android/src/com/mapswithme/maps/dialog/RoutingErrorDialogFragment.java index d8cf512fc9..f8d411cd63 100644 --- a/android/src/com/mapswithme/maps/dialog/RoutingErrorDialogFragment.java +++ b/android/src/com/mapswithme/maps/dialog/RoutingErrorDialogFragment.java @@ -147,10 +147,8 @@ public class RoutingErrorDialogFragment extends BaseMwmDialogFragment listView.setAdapter(buildAdapter()); listView.setChildDivider(new ColorDrawable(getResources().getColor(android.R.color.transparent))); - ViewTreeObserver observer = listView.getViewTreeObserver(); - observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() + UiUtils.waitLayout(listView, new ViewTreeObserver.OnGlobalLayoutListener() { - @SuppressWarnings("deprecation") @Override public void onGlobalLayout() { @@ -161,12 +159,6 @@ public class RoutingErrorDialogFragment extends BaseMwmDialogFragment listView.setIndicatorBounds(width - indicatorWidth, width); else listView.setIndicatorBoundsRelative(width - indicatorWidth, width); - - final ViewTreeObserver treeObserver = listView.getViewTreeObserver(); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) - treeObserver.removeGlobalOnLayoutListener(this); - else - treeObserver.removeOnGlobalLayoutListener(this); } }); diff --git a/android/src/com/mapswithme/maps/widget/menu/MainMenu.java b/android/src/com/mapswithme/maps/widget/menu/MainMenu.java index 9eac2d6196..73d3f9e8a0 100644 --- a/android/src/com/mapswithme/maps/widget/menu/MainMenu.java +++ b/android/src/com/mapswithme/maps/widget/menu/MainMenu.java @@ -281,7 +281,8 @@ public class MainMenu if (mLayoutCorrected) return; - mContentFrame.post(new Runnable() { + mContentFrame.post(new Runnable() + { @Override public void run() { @@ -390,6 +391,12 @@ public class MainMenu UiUtils.showIf(navigation, mNavigationFrame, mItemViews.get(Item.SEARCH), mItemViews.get(Item.BOOKMARKS)); + if (mLayoutCorrected) + { + mContentFrame.measure(ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT); + mContentHeight = mContentFrame.getMeasuredHeight(); + } } public boolean isOpen() diff --git a/android/src/com/mapswithme/util/UiUtils.java b/android/src/com/mapswithme/util/UiUtils.java index c12ed36f2c..8c86f91cc5 100644 --- a/android/src/com/mapswithme/util/UiUtils.java +++ b/android/src/com/mapswithme/util/UiUtils.java @@ -16,12 +16,14 @@ import android.os.Build; import android.provider.Settings; import android.support.annotation.DimenRes; import android.support.annotation.IdRes; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v7.app.AlertDialog; import android.support.v7.widget.Toolbar; import android.text.TextUtils; import android.view.Surface; import android.view.View; +import android.view.ViewTreeObserver; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.AnimationUtils; @@ -37,6 +39,57 @@ public final class UiUtils private static float sScreenDensity; + public static class SimpleAnimationListener implements AnimationListener + { + @Override + public void onAnimationStart(Animation animation) + {} + + @Override + public void onAnimationEnd(Animation animation) + {} + + @Override + public void onAnimationRepeat(Animation animation) + {} + } + + + public static class SimpleNineoldAnimationListener implements Animator.AnimatorListener + { + @Override + public void onAnimationStart(Animator animation) {} + + @Override + public void onAnimationEnd(Animator animation) {} + + @Override + public void onAnimationCancel(Animator animation) {} + + @Override + public void onAnimationRepeat(Animator animation) {} + } + + + public static void waitLayout(View view, @NonNull final ViewTreeObserver.OnGlobalLayoutListener callback) + { + final ViewTreeObserver observer = view.getViewTreeObserver(); + observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() + { + @SuppressWarnings("deprecation") + @Override + public void onGlobalLayout() + { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) + observer.removeGlobalOnLayoutListener(this); + else + observer.removeOnGlobalLayoutListener(this); + + callback.onGlobalLayout(); + } + }); + } + public static void hide(View view) { view.setVisibility(View.GONE); @@ -142,36 +195,6 @@ public final class UiUtils return new BitmapDrawable(res, bmp); } - public static class SimpleAnimationListener implements AnimationListener - { - @Override - public void onAnimationStart(Animation animation) - {} - - @Override - public void onAnimationEnd(Animation animation) - {} - - @Override - public void onAnimationRepeat(Animation animation) - {} - } - - public static class SimpleNineoldAnimationListener implements Animator.AnimatorListener - { - @Override - public void onAnimationStart(Animator animation) {} - - @Override - public void onAnimationEnd(Animator animation) {} - - @Override - public void onAnimationCancel(Animator animation) {} - - @Override - public void onAnimationRepeat(Animator animation) {} - } - public static TextView setTextAndShow(TextView tv, CharSequence text) { checkNotNull(tv);