Hide compass after 5 sec

This commit is contained in:
Alexey Kulish 2016-10-17 18:11:58 +03:00
parent 1f82fcb4ff
commit ae79b37de1

View file

@ -13,6 +13,9 @@ import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPropertyAnimatorCompat;
import android.support.v4.view.ViewPropertyAnimatorListener;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
@ -134,6 +137,7 @@ public class MapControlsLayer extends OsmandMapLayer {
View compassView = compassHud.iv; View compassView = compassHud.iv;
ViewGroup parent = (ViewGroup) compassView.getParent(); ViewGroup parent = (ViewGroup) compassView.getParent();
if (parent != null) { if (parent != null) {
compassHud.cancelHideAnimation();
compassHud.compassOutside = true; compassHud.compassOutside = true;
forceShowCompass = true; forceShowCompass = true;
parent.removeView(compassView); parent.removeView(compassView);
@ -642,7 +646,7 @@ public class MapControlsLayer extends OsmandMapLayer {
mapZoomIn.updateVisibility(!dialogOpened); mapZoomIn.updateVisibility(!dialogOpened);
mapZoomOut.updateVisibility(!dialogOpened); mapZoomOut.updateVisibility(!dialogOpened);
compassHud.updateVisibility(!dialogOpened); compassHud.updateVisibility(!dialogOpened && shouldShowCompass());
layersHud.updateVisibility(!dialogOpened); layersHud.updateVisibility(!dialogOpened);
quickSearchHud.updateVisibility(!dialogOpened); quickSearchHud.updateVisibility(!dialogOpened);
@ -673,9 +677,7 @@ public class MapControlsLayer extends OsmandMapLayer {
public void updateCompass(boolean isNight) { public void updateCompass(boolean isNight) {
float mapRotate = mapActivity.getMapView().getRotate(); float mapRotate = mapActivity.getMapView().getRotate();
boolean showCompass = forceShowCompass || mapRotate != 0 boolean showCompass = shouldShowCompass();
|| settings.ROTATE_MAP.get() != OsmandSettings.ROTATE_MAP_NONE
|| mapActivity.getMapLayers().getMapInfoLayer().getMapInfoControls().isVisible("compass");
if (mapRotate != cachedRotate) { if (mapRotate != cachedRotate) {
cachedRotate = mapRotate; cachedRotate = mapRotate;
// Apply animation to image view // Apply animation to image view
@ -697,6 +699,13 @@ public class MapControlsLayer extends OsmandMapLayer {
} }
} }
private boolean shouldShowCompass() {
float mapRotate = mapActivity.getMapView().getRotate();
return forceShowCompass || mapRotate != 0
|| settings.ROTATE_MAP.get() != OsmandSettings.ROTATE_MAP_NONE
|| mapActivity.getMapLayers().getMapInfoLayer().getMapInfoControls().isVisible("compass");
}
public CompassDrawable getCompassDrawable(Drawable originalDrawable) { public CompassDrawable getCompassDrawable(Drawable originalDrawable) {
return new CompassDrawable(originalDrawable); return new CompassDrawable(originalDrawable);
} }
@ -827,11 +836,11 @@ public class MapControlsLayer extends OsmandMapLayer {
int resClrLight = R.color.icon_color; int resClrLight = R.color.icon_color;
int resClrDark = 0; int resClrDark = 0;
boolean nightMode = false; boolean nightMode = false;
boolean f = true; boolean f = true;
boolean compass; boolean compass;
boolean compassOutside; boolean compassOutside;
ViewPropertyAnimatorCompat hideAnimator;
public MapHudButton setRoundTransparent() { public MapHudButton setRoundTransparent() {
setBg(R.drawable.btn_circle_trans, R.drawable.btn_circle_night); setBg(R.drawable.btn_circle_trans, R.drawable.btn_circle_night);
@ -849,15 +858,61 @@ public class MapControlsLayer extends OsmandMapLayer {
return this; return this;
} }
public void hideDelayed(long msec) {
if (!compassOutside && (iv.getVisibility() == View.VISIBLE)) {
if (hideAnimator != null) {
hideAnimator.cancel();
}
hideAnimator = ViewCompat.animate(iv).alpha(0f).setDuration(250).setStartDelay(msec).setListener(new ViewPropertyAnimatorListener() {
@Override
public void onAnimationStart(View view) {
}
@Override
public void onAnimationEnd(View view) {
iv.setVisibility(View.GONE);
ViewCompat.setAlpha(iv, 1f);
hideAnimator = null;
}
@Override
public void onAnimationCancel(View view) {
iv.setVisibility(View.GONE);
ViewCompat.setAlpha(iv, 1f);
hideAnimator = null;
}
});
hideAnimator.start();
}
}
public void cancelHideAnimation() {
if (hideAnimator != null) {
hideAnimator.cancel();
}
}
public boolean updateVisibility(boolean visible) { public boolean updateVisibility(boolean visible) {
if (!compassOutside && visible != (iv.getVisibility() == View.VISIBLE)) { if (!compassOutside && visible != (iv.getVisibility() == View.VISIBLE)) {
if (visible) { if (visible) {
if (hideAnimator != null) {
hideAnimator.cancel();
}
iv.setVisibility(View.VISIBLE); iv.setVisibility(View.VISIBLE);
} else { iv.invalidate();
iv.setVisibility(View.GONE); } else if (hideAnimator == null) {
if (compass) {
hideDelayed(5000);
} else {
iv.setVisibility(View.GONE);
iv.invalidate();
}
} }
iv.invalidate();
return true; return true;
} else if (visible && hideAnimator != null) {
hideAnimator.cancel();
iv.setVisibility(View.VISIBLE);
iv.invalidate();
} }
return false; return false;
} }