Merge remote-tracking branch 'origin/dev_merge_shunyi_vr_map' into dev_merge_shunyi_vr_map

This commit is contained in:
wangcongtao
2020-12-15 19:45:40 +08:00
3 changed files with 89 additions and 11 deletions

View File

@@ -3,14 +3,13 @@ package com.mogo.module.small.map;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.RotateAnimation;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import androidx.annotation.Nullable;
import com.mogo.module.common.view.RoundLayout;
import com.mogo.module.small.map.animation.DirectionRotateAnimation;
/**
* 小地图的方向View
@@ -21,6 +20,8 @@ import com.mogo.module.common.view.RoundLayout;
public class SmallMapDirectionView extends RoundLayout {
private ImageView mIvMapBorder;
private DirectionRotateAnimation mRotateAnimation;
private int lastAngle = 0;
public SmallMapDirectionView(Context context) {
this(context, null);
@@ -38,6 +39,7 @@ public class SmallMapDirectionView extends RoundLayout {
private void initView(Context context) {
LayoutInflater.from(context).inflate(R.layout.module_small_map_view, this);
mIvMapBorder = findViewById(R.id.ivMapBorder);
mRotateAnimation = new DirectionRotateAnimation(context, null);
}
@@ -47,18 +49,25 @@ public class SmallMapDirectionView extends RoundLayout {
* @param angle 角度 0 - 359度旋转,相对于自身中心位置
*/
public void changeAngle(int angle) {
Animation mRotateAnimation = new RotateAnimation(
0, angle,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
int tempAngle = angle;
if (angle <= 180) {
tempAngle = angle;
} else {
tempAngle = -(360 - tempAngle);
}
mRotateAnimation.setFromDegrees(lastAngle);
mRotateAnimation.setToDegrees(tempAngle);
//设置线性插值,可以解决旋转一圈后卡顿问题
mRotateAnimation.setInterpolator(new DecelerateInterpolator());
mRotateAnimation.setInterpolator(new LinearInterpolator());
//设置旋转一圈时间
mRotateAnimation.setDuration(1000);
mRotateAnimation.setDuration(300);
//控件动画结束时是否保持动画最后的状态
mRotateAnimation.setFillAfter(true);
mIvMapBorder.startAnimation(mRotateAnimation);
// 刷新最后一次角度
lastAngle = tempAngle;
}
}

View File

@@ -15,6 +15,8 @@ import com.mogo.module.common.machinevision.IMachineVisionInterface;
import com.mogo.module.common.wm.WindowManagerView;
import com.mogo.utils.logger.Logger;
import java.util.Random;
/**
* @author donghongyu
* @date 12/10/20 1:35 PM
@@ -90,7 +92,8 @@ public class SmallMapService extends Service {
mSmallMapDirectionView.postDelayed(new Runnable() {
@Override
public void run() {
mSmallMapDirectionView.changeAngle(-60);
Random random = new Random();
mSmallMapDirectionView.changeAngle(random.nextInt(360));
}
}, 1000);

View File

@@ -0,0 +1,66 @@
package com.mogo.module.small.map.animation;
import android.content.Context;
import android.util.AttributeSet;
import android.view.animation.Animation;
import android.view.animation.Transformation;
/**
* 方向罗盘旋转动画
* @author donghongyu
* @date 12/14/20 7:46 PM
*/
public class DirectionRotateAnimation extends Animation {
private float mFromDegrees;
private float mToDegrees;
private int mPivotXType = Animation.RELATIVE_TO_SELF;
private int mPivotYType = Animation.RELATIVE_TO_SELF;
private float mPivotXValue = 0.5f;
private float mPivotYValue = 0.5f;
private float mPivotX;
private float mPivotY;
public DirectionRotateAnimation(Context context, AttributeSet attrs) {
super(context, attrs);
initializePivotPoint();
}
public void setFromDegrees(float fromDegrees) {
mFromDegrees = fromDegrees;
}
public void setToDegrees(float toDegrees) {
mToDegrees = toDegrees;
}
private void initializePivotPoint() {
if (mPivotXType == ABSOLUTE) {
mPivotX = mPivotXValue;
}
if (mPivotYType == ABSOLUTE) {
mPivotY = mPivotYValue;
}
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
float degrees = mFromDegrees + ((mToDegrees - mFromDegrees) * interpolatedTime);
float scale = getScaleFactor();
if (mPivotX == 0.0f && mPivotY == 0.0f) {
t.getMatrix().setRotate(degrees);
} else {
t.getMatrix().setRotate(degrees, mPivotX * scale, mPivotY * scale);
}
}
@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
mPivotX = resolveSize(mPivotXType, mPivotXValue, width, parentWidth);
mPivotY = resolveSize(mPivotYType, mPivotYValue, height, parentHeight);
}
}