forked from organicmaps/organicmaps
Fixed zoom buttons visibility.
This commit is contained in:
parent
1c5d94e555
commit
184446aba4
3 changed files with 78 additions and 17 deletions
|
@ -30,6 +30,7 @@ import android.view.MotionEvent;
|
|||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.animation.AccelerateInterpolator;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
import android.widget.ImageButton;
|
||||
|
@ -174,6 +175,7 @@ public class MWMActivity extends BaseMwmFragmentActivity
|
|||
private FadeView mFadeView;
|
||||
|
||||
private ViewGroup mNavigationButtons;
|
||||
private View mToolbarSearch;
|
||||
private ImageButton mBtnZoomIn;
|
||||
private ImageButton mBtnZoomOut;
|
||||
|
||||
|
@ -655,6 +657,8 @@ public class MWMActivity extends BaseMwmFragmentActivity
|
|||
mBtnZoomOut.setOnClickListener(this);
|
||||
mBtnLocation = (ImageButton) mNavigationButtons.findViewById(R.id.btn__myposition);
|
||||
mBtnLocation.setOnClickListener(this);
|
||||
|
||||
mToolbarSearch = findViewById(R.id.toolbar_search);
|
||||
}
|
||||
|
||||
private void initPlacePage()
|
||||
|
@ -999,13 +1003,11 @@ public class MWMActivity extends BaseMwmFragmentActivity
|
|||
listenLocationStateModeUpdates();
|
||||
invalidateLocationState();
|
||||
startWatchingExternalStorage();
|
||||
|
||||
refreshZoomButtonsVisibility();
|
||||
refreshRouterIcon();
|
||||
|
||||
SearchController.getInstance().onResume();
|
||||
mPlacePage.onResume();
|
||||
mLikesManager.showLikeDialogForCurrentSession();
|
||||
refreshZoomButtonsAfterLayout();
|
||||
}
|
||||
|
||||
private void refreshRouterIcon()
|
||||
|
@ -1016,10 +1018,25 @@ public class MWMActivity extends BaseMwmFragmentActivity
|
|||
mIvStartRouting.setImageResource(R.drawable.ic_walk);
|
||||
}
|
||||
|
||||
private void refreshZoomButtonsAfterLayout()
|
||||
{
|
||||
mFadeView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
|
||||
{
|
||||
@Override
|
||||
public void onGlobalLayout()
|
||||
{
|
||||
refreshZoomButtonsVisibility();
|
||||
mFadeView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void refreshZoomButtonsVisibility()
|
||||
{
|
||||
UiUtils.showIf(MWMApplication.get().nativeGetBoolean(SettingsActivity.ZOOM_BUTTON_ENABLED, true) ||
|
||||
Framework.nativeIsRoutingActive(),
|
||||
final boolean showZoomSetting = MWMApplication.get().nativeGetBoolean(SettingsActivity.ZOOM_BUTTON_ENABLED, true) || Framework.nativeIsRoutingActive();
|
||||
UiUtils.showIf(showZoomSetting &&
|
||||
!UiUtils.areViewsIntersecting(mToolbarSearch, mBtnZoomIn) &&
|
||||
!UiUtils.areViewsIntersecting(mRlRoutingBox, mBtnZoomIn),
|
||||
mBtnZoomIn, mBtnZoomOut);
|
||||
}
|
||||
|
||||
|
@ -1308,17 +1325,20 @@ public class MWMActivity extends BaseMwmFragmentActivity
|
|||
@Override
|
||||
public void onPreviewVisibilityChanged(boolean isVisible)
|
||||
{
|
||||
if (!isVisible)
|
||||
if (isVisible)
|
||||
{
|
||||
if (previewIntersectsBottomMenu())
|
||||
mBottomButtons.setVisibility(View.GONE);
|
||||
if (previewIntersectsZoomButtons())
|
||||
UiUtils.hide(mBtnZoomIn, mBtnZoomOut);
|
||||
}
|
||||
else
|
||||
{
|
||||
Framework.deactivatePopup();
|
||||
mPlacePage.setMapObject(null);
|
||||
}
|
||||
if (previewIntersectsBottomMenu())
|
||||
mBottomButtons.setVisibility(isVisible ? View.GONE : View.VISIBLE);
|
||||
if (previewIntersectsZoomButtons())
|
||||
UiUtils.hide(mBtnZoomIn, mBtnZoomOut);
|
||||
else
|
||||
refreshZoomButtonsVisibility();
|
||||
mBottomButtons.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean previewIntersectsBottomMenu()
|
||||
|
@ -1334,11 +1354,16 @@ public class MWMActivity extends BaseMwmFragmentActivity
|
|||
@Override
|
||||
public void onPlacePageVisibilityChanged(boolean isVisible)
|
||||
{
|
||||
AlohaHelper.logClick(AlohaHelper.PP_OPEN);
|
||||
if (placePageIntersectsZoomButtons())
|
||||
UiUtils.hide(mBtnZoomIn, mBtnZoomOut);
|
||||
if (isVisible)
|
||||
{
|
||||
AlohaHelper.logClick(AlohaHelper.PP_OPEN);
|
||||
if (placePageIntersectsZoomButtons())
|
||||
UiUtils.hide(mBtnZoomIn, mBtnZoomOut);
|
||||
else
|
||||
refreshZoomButtonsVisibility();
|
||||
}
|
||||
else
|
||||
refreshZoomButtonsVisibility();
|
||||
AlohaHelper.logClick(AlohaHelper.PP_CLOSE);
|
||||
}
|
||||
|
||||
private boolean placePageIntersectsZoomButtons()
|
||||
|
@ -1644,7 +1669,6 @@ public class MWMActivity extends BaseMwmFragmentActivity
|
|||
@Override
|
||||
public void run()
|
||||
{
|
||||
refreshZoomButtonsVisibility();
|
||||
if (resultCode == RoutingResultCodes.NO_ERROR)
|
||||
{
|
||||
mRlTurnByTurnBox.setVisibility(View.GONE);
|
||||
|
@ -1716,6 +1740,8 @@ public class MWMActivity extends BaseMwmFragmentActivity
|
|||
}
|
||||
builder.create().show();
|
||||
}
|
||||
|
||||
refreshZoomButtonsVisibility();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.content.res.Resources;
|
|||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
|
@ -323,6 +324,39 @@ public final class UiUtils
|
|||
return MWMApplication.get().getResources().getBoolean(R.bool.isBigTablet);
|
||||
}
|
||||
|
||||
/**
|
||||
* View's default getHitRect() had a bug and would not apply transforms properly.
|
||||
* More details : http://stackoverflow.com/questions/17750116/strange-view-gethitrect-behaviour
|
||||
* @param v view
|
||||
* @param rect rect
|
||||
*/
|
||||
public static void getHitRect(View v, Rect rect)
|
||||
{
|
||||
rect.left = (int) com.nineoldandroids.view.ViewHelper.getX(v);
|
||||
rect.top = (int) com.nineoldandroids.view.ViewHelper.getY(v);
|
||||
rect.right = rect.left + v.getWidth();
|
||||
rect.bottom = rect.top + v.getHeight();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests, whether views intercects each other in parent coordinates.
|
||||
* @param firstView base view
|
||||
* @param secondView covering view
|
||||
* @return intersects or not
|
||||
*/
|
||||
public static boolean areViewsIntersecting(View firstView, View secondView)
|
||||
{
|
||||
if (firstView.getVisibility() == View.GONE)
|
||||
return false;
|
||||
|
||||
final Rect baseRect = new Rect();
|
||||
final Rect testRect = new Rect();
|
||||
UiUtils.getHitRect(firstView, baseRect);
|
||||
UiUtils.getHitRect(secondView, testRect);
|
||||
|
||||
return baseRect.intersect(testRect);
|
||||
}
|
||||
|
||||
// utility class
|
||||
private UiUtils()
|
||||
{}
|
||||
|
|
|
@ -41,6 +41,7 @@ public class AlohaHelper
|
|||
public static final String MENU_SHARE = "share@";
|
||||
// place page
|
||||
public static final String PP_OPEN = "ppOpen";
|
||||
public static final String PP_CLOSE = "ppClose";
|
||||
public static final String PP_SHARE = "ppShare";
|
||||
public static final String PP_BOOKMARK = "ppBookmark";
|
||||
public static final String PP_ROUTE = "ppRoute";
|
||||
|
|
Loading…
Add table
Reference in a new issue