From 8582a0f9902ea06be59e363eb23a0c7f312f9c5b Mon Sep 17 00:00:00 2001 From: Dzmitry Yarmolenka Date: Tue, 10 Aug 2021 17:58:40 +0200 Subject: [PATCH] [android] Fixes invisible button in navigation panel issue on api 23. Signed-off-by: Dzmitry Yarmolenka --- .../maps/widget/RotateDrawable.java | 63 ------------------- .../mapswithme/maps/widget/menu/NavMenu.java | 42 ++++--------- 2 files changed, 13 insertions(+), 92 deletions(-) delete mode 100644 android/src/com/mapswithme/maps/widget/RotateDrawable.java diff --git a/android/src/com/mapswithme/maps/widget/RotateDrawable.java b/android/src/com/mapswithme/maps/widget/RotateDrawable.java deleted file mode 100644 index 6075fad2ce..0000000000 --- a/android/src/com/mapswithme/maps/widget/RotateDrawable.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.mapswithme.maps.widget; - -import android.graphics.Canvas; -import android.graphics.ColorFilter; -import android.graphics.Rect; -import android.graphics.drawable.Drawable; - -import androidx.annotation.NonNull; - -public class RotateDrawable extends Drawable -{ - private final Drawable mBaseDrawable; - private float mAngle; - - public RotateDrawable(Drawable drawable) - { - super(); - mBaseDrawable = drawable; - } - - @Override - public void setAlpha(int alpha) - { - mBaseDrawable.setAlpha(alpha); - } - - @Override - public void setColorFilter(ColorFilter cf) - { - mBaseDrawable.setColorFilter(cf); - } - - @Override - public int getOpacity() - { - return mBaseDrawable.getOpacity(); - } - - @Override - protected void onBoundsChange(Rect bounds) - { - super.onBoundsChange(bounds); - mBaseDrawable.setBounds(0, 0, mBaseDrawable.getIntrinsicWidth(), - mBaseDrawable.getIntrinsicHeight()); - } - - @Override - public void draw(@NonNull Canvas canvas) - { - canvas.save(); - canvas.rotate(mAngle, getBounds().width() * 0.5f, getBounds().height() * 0.5f); - canvas.translate((getBounds().width() - mBaseDrawable.getIntrinsicWidth()) * 0.5f, - (getBounds().height() - mBaseDrawable.getIntrinsicHeight()) * 0.5f); - mBaseDrawable.draw(canvas); - canvas.restore(); - } - - public void setAngle(float angle) - { - mAngle = angle; - invalidateSelf(); - } -} diff --git a/android/src/com/mapswithme/maps/widget/menu/NavMenu.java b/android/src/com/mapswithme/maps/widget/menu/NavMenu.java index 489cc37ecb..56c7fa2eb7 100644 --- a/android/src/com/mapswithme/maps/widget/menu/NavMenu.java +++ b/android/src/com/mapswithme/maps/widget/menu/NavMenu.java @@ -11,12 +11,10 @@ import androidx.annotation.IntegerRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.mapswithme.maps.Framework; import com.mapswithme.maps.MwmApplication; import com.mapswithme.maps.R; import com.mapswithme.maps.maplayer.traffic.TrafficManager; import com.mapswithme.maps.sound.TtsPlayer; -import com.mapswithme.maps.widget.RotateDrawable; import com.mapswithme.util.Graphics; import com.mapswithme.util.UiUtils; @@ -24,12 +22,13 @@ public class NavMenu extends BaseMenu { @IntegerRes private final int mAnimationDuration; - private final RotateDrawable mToggleImage; @NonNull private final ImageView mTts; @NonNull private final ImageView mTraffic; + ImageView mToggle; + final View mContentFrame; int mContentHeight; @@ -83,9 +82,8 @@ public class NavMenu extends BaseMenu mAnimationDuration = MwmApplication.from(frame.getContext()) .getResources().getInteger(R.integer.anim_menu); mContentFrame = mFrame.findViewById(R.id.content_frame); - mToggleImage = new RotateDrawable(Graphics.tint(mFrame.getContext(), R.drawable.ic_menu_close, R.attr.iconTintLight)); - ImageView toggle = mLineFrame.findViewById(R.id.toggle); - toggle.setImageDrawable(mToggleImage); + mToggle = mLineFrame.findViewById(R.id.toggle); + mToggle.setImageDrawable(Graphics.tint(mFrame.getContext(), R.drawable.ic_menu_close, R.attr.iconTintLight)); setToggleState(false, false); @@ -207,27 +205,22 @@ public class NavMenu extends BaseMenu if (mLayoutMeasured) return; - UiUtils.measureView(mContentFrame, new UiUtils.OnViewMeasuredListener() + UiUtils.measureView(mContentFrame, (width, height) -> { - @Override - public void onViewMeasured(int width, int height) + if (height != 0) { - if (height != 0) - { - mContentHeight = height; - mLayoutMeasured = true; + mContentHeight = height; + mLayoutMeasured = true; - UiUtils.hide(mContentFrame); - } - afterLayoutMeasured(procAfterMeasurement); + UiUtils.hide(mContentFrame); } + afterLayoutMeasured(procAfterMeasurement); }); } public void refresh() { refreshTts(); -// refreshTraffic(); } public void refreshTts() @@ -251,20 +244,14 @@ public class NavMenu extends BaseMenu final float to = open ? -90.0f : 90.0f; if (!animate) { - mToggleImage.setAngle(to); + mToggle.setRotation(to); + mToggle.invalidate(); return; } final float from = -to; ValueAnimator animator = ValueAnimator.ofFloat(from, to); - animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() - { - @Override - public void onAnimationUpdate(ValueAnimator animation) - { - mToggleImage.setAngle((float) animation.getAnimatedValue()); - } - }); + animator.addUpdateListener(animation -> mToggle.setRotation((float) animation.getAnimatedValue())); animator.setDuration(mAnimationDuration); animator.start(); @@ -284,9 +271,6 @@ public class NavMenu extends BaseMenu { super.show(show); measureContent(null); - @Framework.RouterType - int routerType = Framework.nativeGetRouter(); UiUtils.showIf(show, mTts); -// UiUtils.showIf(show && routerType == Framework.ROUTER_TYPE_VEHICLE, mTraffic); } }