This commit is contained in:
zhongchao
2022-11-10 16:54:26 +08:00
parent 5322d03ec1
commit 2156d2cd18
148 changed files with 147 additions and 19811 deletions

View File

@@ -1,19 +0,0 @@
package com.mogo.module.common;
/**
* @author congtaowang
* @since 2020-03-13
* <p>
* 各个卡片模块类型
*/
public class ModuleNames {
/**
* 卡片 探路数据
*/
public static final String CARD_TYPE_ROAD_CONDITION = "CARD_TYPE_ROAD_CONDITION";
/**
* 卡片 用户数据
*/
public static final String CARD_TYPE_USER_DATA = "CARD_TYPE_USER_DATA";
}

View File

@@ -1,63 +0,0 @@
package com.mogo.module.common;
/**
* @author congtaowang
* @since 2019-12-31
* <p>
* 模块描述信息
*/
public class MogoModule {
/**
* 模块加载路径
*/
private String mPath;
/**
* 模块名称
*/
private String mName;
/**
* 广播接收者
*/
private String mBroadcastAction;
/**
* @param path 模块加载路径
* @param name 模块名称
*/
public MogoModule( String path, String name ) {
this.mPath = path;
this.mName = name;
}
public String getPath() {
return mPath;
}
public MogoModule setPath( String path ) {
this.mPath = path;
return this;
}
public String getName() {
return mName;
}
public MogoModule setName( String name ) {
this.mName = name;
return this;
}
public String getBroadcastAction() {
return mBroadcastAction;
}
public MogoModule setBroadcastAction( String broadcastAction ) {
this.mBroadcastAction = broadcastAction;
return this;
}
}

View File

@@ -1,88 +0,0 @@
package com.mogo.module.common;
import android.text.TextUtils;
import java.util.ArrayList;
import java.util.List;
/**
* @author congtaowang
* @since 2019-12-23
* <p>
* 模块路由路径
*/
public class MogoModulePaths {
private static final List<MogoModule> mMogoModules = new ArrayList<>();
// 不需要启动APP也能运行的模块
private static final List<MogoModule> mMogoBaseModules = new ArrayList<>();
private static final List<MogoModule> mModuleFunctions = new ArrayList<>();
private static final List<MogoModule> mModuleFunctionServers = new ArrayList<>();
/**
* 添加卡片模块
*
* @param module
*/
public static void addModule(MogoModule module) {
if (module == null || TextUtils.isEmpty(module.getPath().replace(" ", ""))) {
throw new IllegalArgumentException("module path can't be empty or null or blank");
}
mMogoModules.add(module);
}
/**
* 添加模块功能
*
* @param module 功能模块
*/
public static void addModuleFunction(MogoModule module) {
if (module == null || TextUtils.isEmpty(module.getPath().replace(" ", ""))) {
throw new IllegalArgumentException("module path can't be empty or null or blank");
}
mModuleFunctions.add(module);
}
/**
* 添加 功能服务, 不带UI Fragment的
*
* @param module 功能模块
*/
public static void addModuleFunctionServer(MogoModule module) {
if (module == null || TextUtils.isEmpty(module.getPath().replace(" ", ""))) {
throw new IllegalArgumentException("module path can't be empty or null or blank");
}
mModuleFunctionServers.add(module);
}
/**
* 添加基础模块
*
* @param module
*/
public static void addBaseModule(MogoModule module) {
if (module == null || TextUtils.isEmpty(module.getPath().replace(" ", ""))) {
throw new IllegalArgumentException("module path can't be empty or null or blank");
}
mMogoBaseModules.add(module);
}
public static List<MogoModule> getModules() {
return mMogoModules;
}
public static List<MogoModule> getBaseModules() {
return mMogoBaseModules;
}
public static List<MogoModule> getModuleFunctions() {
return mModuleFunctions;
}
public static List<MogoModule> getModuleFunctionServers() {
return mModuleFunctionServers;
}
}

View File

@@ -1,30 +0,0 @@
package com.mogo.module.common.entity;
import com.mogo.eagle.core.data.BaseData;
import java.util.List;
@SuppressWarnings("unused")
public class MarkerCardResult extends BaseData {
private List<String> dataType; // 要查询的类型
private long messageTime;
public List<String> getDataType() {
return dataType;
}
public void setDataType(List<String> dataType) {
this.dataType = dataType;
}
public long getMessageTime() {
return messageTime;
}
public void setMessageTime(long messageTime) {
this.messageTime = messageTime;
}
}

View File

@@ -1,54 +0,0 @@
package com.mogo.module.common.entity;
import com.mogo.eagle.core.data.BaseData;
import java.io.Serializable;
@SuppressWarnings("unused")
public class MarkerResponse extends BaseData implements Serializable {
// private int code;
// private String msg;
private MarkerCardResult result;
private String sign;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public MarkerCardResult getResult() {
return result;
}
public void setResult(MarkerCardResult result) {
this.result = result;
}
public String getSign() {
return sign;
}
public void setSign(String sign) {
this.sign = sign;
}
@Override
public String toString() {
return "MarkerResponse{" + "result=" + result + ", sign='" + sign + '\'' + ", code=" + code + ", msg='" + msg + '\'' + '}';
}
}

View File

@@ -1,125 +0,0 @@
package com.mogo.module.common.utils;
import android.text.TextUtils;
import com.mogo.commons.debug.DebugConfig;
import java.lang.reflect.Method;
/**
* @author congtaowang
* @since 2020-03-26
* <p>
* 车机类型
*/
public class CarSeries {
private static boolean invokeFlag = false;
private static boolean isF8xxSeries = false;
public static boolean isF8xxSeries() {
if ( invokeFlag ) {
return isF8xxSeries;
}
isF8xxSeries = DebugConfig.getProductFlavor().startsWith( "f" );
invokeFlag = true;
return isF8xxSeries;
}
@Deprecated
public static final int CAR_SERIES_C80X = 10;
@Deprecated
public static final int CAR_SERIES_D80X = 20;
@Deprecated
public static final int CAR_SERIES_D81X = 21;
@Deprecated
public static final int CAR_SERIES_D82X = 22;
@Deprecated
public static final int CAR_SERIES_D84X = 23;
@Deprecated
public static final int CAR_SERIES_F80X = 30;
@Deprecated
public static final int CAR_SERIES_G80X = 40;
@Deprecated
public static final int CAR_SERIES_E84X = 50;
@Deprecated
public static final int CAR_SERIES_E84XCD = 51;
@Deprecated
public static final int CAR_SERIES_E85X = 50;
@Deprecated
public static final int CAR_SERIES_E85XCD = 51;
@Deprecated
public static final int CAR_SERIES_E85XJD = 51;
@Deprecated
public static int CAR_SERIES = 0;
/**
* Deprecated.
* Use {@link DebugConfig#getProductFlavor()} instead.
*
* @return
*/
@Deprecated
public static int getSeries() {
if ( CAR_SERIES != 0 ) {
return CAR_SERIES;
}
synchronized ( CarSeries.class ) {
if ( CAR_SERIES != 0 ) {
return CAR_SERIES;
}
String device = get( "ro.fota.device" );
if ( TextUtils.isEmpty( device ) ) {
return CAR_SERIES_F80X;
}
if ( "FG166".equals( device ) ) {
CAR_SERIES = CAR_SERIES_C80X;
} else if ( "D801-802".equals( device ) ) {
CAR_SERIES = CAR_SERIES_D80X;
} else if ( "D801B-802B".equals( device ) ) {
// 2+16G
CAR_SERIES = CAR_SERIES_D80X;
} else if ( "D811-812".equals( device ) ) {
CAR_SERIES = CAR_SERIES_D81X;
} else if ( "D821-822".equals( device ) ) {
CAR_SERIES = CAR_SERIES_D82X;
} else if ( "D841-842".equals( device ) ) {
CAR_SERIES = CAR_SERIES_D84X;
} else if ( "G801-802".equals( device ) ) {
CAR_SERIES = CAR_SERIES_G80X;
} else if ( "F801-802".equals( device ) ) {
CAR_SERIES = CAR_SERIES_F80X;
} else if ( "E841-842".equals( device ) ) {
CAR_SERIES = CAR_SERIES_E84X;
} else if ( "E84XCD".equals( device ) ) {
CAR_SERIES = CAR_SERIES_E84XCD;
} else if ( "E851-852".equals( device ) ) {
CAR_SERIES = CAR_SERIES_E85X;
} else if ( "E85XCD".equals( device ) ) {
CAR_SERIES = CAR_SERIES_E85XCD;
} else if ( "E85XJD".equals( device ) ) {
CAR_SERIES = CAR_SERIES_E85XJD;
} else if ( device.startsWith( "E85" ) ) {
CAR_SERIES = CAR_SERIES_E85XJD;
} else {
CAR_SERIES = CAR_SERIES_F80X;
}
return CAR_SERIES;
}
}
@Deprecated
private static String get( String key ) {
String value = "";
try {
Class< ? > c = Class.forName( "android.os.SystemProperties" );
Method get = c.getMethod( "get", new Class[]{String.class, String.class} );
value = ( String ) get.invoke( c, new Object[]{key, "unknown"} );
} catch ( Exception e ) {
value = "";
}
return value;
}
}

View File

@@ -1,156 +0,0 @@
package com.mogo.module.common.utils;
import static java.lang.Math.PI;
import android.util.Pair;
/**
* author : donghongyu
* e-mail : 1358506549@qq.com
* date : 2020/4/14 1:02 PM
* desc : 计算车辆驾驶方向的工具类
* version: 1.0
*/
public class DrivingDirectionUtils {
public static long getDegreeOfCar2Poi2(double x1, double y1, double x2, double y2, double x1_angle) {
Pair<Double, Double> newPoint = calculateNewPoint(x1, y1, x1_angle, 10);
if (newPoint != null) {
double angle = getAngle(x1, y1, newPoint.first, newPoint.second, x2, y2);
return Math.round(angle + 0.5);
}
return 0;
}
public static double distance(double x1, double y1, double x2, double y2) {
return Math.sqrt(Math.pow(x1 - x2, 2.0) + Math.pow(y1 - y2, 2.0));
}
public static double getAngle(double sx, double sy, double x1, double y1, double x2, double y2) {
x1 = x1 - sx;
y1 = y1 - sy;
x2 = x2 - sx;
y2 = y2 - sy;
double product = x1 * x2 + y1 * y2;
double radians = Math.acos(product / (Math.sqrt(Math.pow(x1, 2.0) + Math.pow(y1, 2.0)) * Math.sqrt(Math.pow(x2, 2.0) + Math.pow(y2, 2.0))));
return Math.toDegrees(radians);
}
public static Pair<Double, Double> calculateNewPoint(double x, double y, double angle, double distance) {
if (distance == 0) {
return null;
}
double radian = Math.toRadians(angle);
double radianCandle = Math.toRadians(90.0 - angle);
double nX = x + distance * Math.sin(radian) / 100000.0;
double nY = y + distance * Math.sin(radianCandle) / 100000.0;
return Pair.create(nX, nY);
}
/**
* 计算车辆行驶方向 与 poi点到车辆的连线 间的夹角
*
* @param carLon 车辆位置 lon
* @param carLat 车辆位置 lat
* @param poiLon poi 位置 lon
* @param poiLat poi 位置 lat
* @param carAngle 车辆行驶方向
* @return
*/
public static int getDegreeOfCar2Poi(double carLon, double carLat, double poiLon, double poiLat, int carAngle) {
int poiAngle = 0;
// 以子午线作为y轴 计算两点的余切 再将余切值转化为角度
double _angle = Math.atan2(Math.abs(carLon - poiLon), Math.abs(carLat - poiLat)) * (180 / PI);
if (poiLon > carLon) {
// poi 在 车辆位置的第1象限
if (poiLat > carLat) {
poiAngle = (int) _angle;
}
// poi 在 车辆位置的第2象限
else {
poiAngle = 180 - (int) _angle;
}
} else {
// poi 在 车辆位置的第3象限
if (poiLat < carLat) {
poiAngle = (int) _angle + 180;
}
// poi 在 车辆位置的第4象限
else {
poiAngle = 360 - (int) _angle;
}
}
return calculationAngle(poiAngle, carAngle);
}
/**
* 计算两个行驶方向间的夹角 计算结果小于180度
*
* @param angle0
* @param angle1
* @return
*/
public static int calculationAngle(int angle0, int angle1) {
// 获取两方向间夹角
int angle = Math.abs(angle0 - angle1);
if (angle > 180) {
int minAngle = Math.min(angle0, angle1);
int maxAngle = Math.max(angle0, angle1);
return 180 - Math.abs(minAngle + 180 - maxAngle);
} else {
return angle;
}
}
/**
* 计算车辆行驶方向角度,起点&终点经纬度
*
* @param carLat 车辆位置 lat
* @param carLon 车辆位置 lon
* @param poiLat poi 位置 lat
* @param poiLon poi 位置 lon
*/
public static int getCarAngle(double carLat, double carLon, double poiLat, double poiLon) {
int poiAngle = 0;
// 以子午线作为y轴 计算两点的余切 再将余切值转化为角度
double _angle = Math.atan2(Math.abs(carLon - poiLon), Math.abs(carLat - poiLat)) * (180 / PI);
if (poiLon > carLon) {
// poi 在 车辆位置的第1象限
if (poiLat > carLat) {
poiAngle = (int) _angle;
}
// poi 在 车辆位置的第2象限
else {
poiAngle = 180 - (int) _angle;
}
} else {
// poi 在 车辆位置的第3象限
if (poiLat < carLat) {
poiAngle = (int) _angle + 180;
}
// poi 在 车辆位置的第4象限
else {
poiAngle = 360 - (int) _angle;
}
}
if (poiAngle >= 355) {
poiAngle = 0;
}
return poiAngle;
}
/**
* 计算连两个角度差值
*
* @param angle1 角度1
* @param angle2 角度2
* @return 差值
*/
public static double getAngleDiff(double angle1, double angle2) {
// 两个角度差值较小
return 180 - Math.abs(Math.abs(angle1 - angle2) - 180);
}
}

View File

@@ -1,53 +0,0 @@
package com.mogo.module.common.utils;
import com.mogo.eagle.core.data.map.MogoLatLng;
/**
* @author liujing
* @description 描述
* @since: 2021/4/13
*/
public class Trigonometric {
private final static double radius_b = 6378137;//大半径
private final static double radius_s = 6356725;//小半径
private static double mRadLo;
private static double mRadLa;
private static double Ec;
private static double Ed;
/**
* 计算两点间的角度
*/
public static double getAngle(double lon1, double lat1, double lon2,
double lat2) {
double fLat = Math.PI * (lat1) / 180.0;
double fLng = Math.PI * (lon1) / 180.0;
double tLat = Math.PI * (lat2) / 180.0;
double tLng = Math.PI * (lon2) / 180.0;
double degree = (Math.atan2(Math.sin(tLng - fLng) * Math.cos(tLat), Math.cos(fLat) * Math.sin(tLat) -
Math.sin(fLat) * Math.cos(tLat) * Math.cos(tLng - fLng))) * 180.0 / Math.PI;
if (degree >= 0) {
return degree;
} else {
return 360 + degree;
}
}
/**
* 根据角度获取指定距离点的经纬度
*/
public static MogoLatLng getNewLocation(double lon, double lat, double distance, double angle) {
mRadLo = lon * Math.PI / 180.;
mRadLa = lat * Math.PI / 180.;
Ec = radius_s + (radius_b - radius_s) * (90. - lat) / 90;
Ed = Ec * Math.cos(mRadLa);
double dx = distance * Math.sin(Math.toRadians(angle));
double dy = distance * Math.cos(Math.toRadians(angle));
double lon_new = (dx / Ed + mRadLo) * 180. / Math.PI;
double lat_new = (dy / Ec + mRadLa) * 180. / Math.PI;
return new MogoLatLng(lat_new, lon_new);
}
}

View File

@@ -1,310 +0,0 @@
package com.mogo.module.common.view;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import com.mogo.module.common.R;
import java.math.BigDecimal;
public class CustomRatingBar extends LinearLayout {
private Context mContext;
/*
是否可点击
* */
private boolean mClickable;
/*
* 单元总数(心形/星星)
* */
private int elementCount;
/*
* 单元点击事件
* */
private OnRatingChangeListener mOnRatingBarChangeListener;
/*
* 每个单元的大小
* */
private float elementWidth;
private float elementHeight;
public float getElementWidth() {
return elementWidth;
}
public void setElementWidth(float elementWidth) {
this.elementWidth = elementWidth;
}
public float getElementHeight() {
return elementHeight;
}
public void setElementHeight(float elementHeight) {
this.elementHeight = elementHeight;
}
/*
* 每个单元间的距离
* */
private float elementPadding;
/*
*单元的显示数量,支持小数点
* */
private float elementStep;
/*
* 空白的默认单元图片
* */
private Drawable elementEmptyDrawable;
/*
* 选中后的单元图片
* */
private Drawable elementFillDrawable;
/*
* 半颗单元图片
* */
private Drawable elementHarfDrawable;
/*
* 每次点击单元所增加的量是半个还是整个
* */
private StepSize stepSize;
/*
*添加资源(空白心是白色还是灰色自定义属性)
* */
private boolean otherHeartImg;
@Override
public boolean isClickable() {
return mClickable;
}
@Override
public void setClickable(boolean clickable) {
mClickable = clickable;
}
public int getElementCount() {
return elementCount;
}
public void setElementCount(int elementCount) {
this.elementCount = elementCount;
}
public OnRatingChangeListener getOnRatingBarChangeListener() {
return mOnRatingBarChangeListener;
}
public void setOnRatingChangeListener(OnRatingChangeListener onRatingBarChangeListener) {
mOnRatingBarChangeListener = onRatingBarChangeListener;
}
public float getElementPadding() {
return elementPadding;
}
public void setElementPadding(float elementPadding) {
this.elementPadding = elementPadding;
}
public float getElementStep() {
return elementStep;
}
public void setElementStep(float elementStep) {
this.elementStep = elementStep;
}
public Drawable getElementEmptyDrawable() {
return elementEmptyDrawable;
}
public void setElementEmptyDrawable(Drawable elementEmptyDrawable) {
this.elementEmptyDrawable = elementEmptyDrawable;
}
public Drawable getElementFillDrawable() {
return elementFillDrawable;
}
public void setElementFillDrawable(Drawable elementFillDrawable) {
this.elementFillDrawable = elementFillDrawable;
}
public Drawable getElementHarfDrawable() {
return elementHarfDrawable;
}
public void setElementHarfDrawable(Drawable elementHarfDrawable) {
this.elementHarfDrawable = elementHarfDrawable;
}
public void setStepSize(StepSize stepSize) {
this.stepSize = stepSize;
}
public CustomRatingBar(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
mContext = context;
setOrientation(LinearLayout.HORIZONTAL);
TypedArray mTypedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomRatingBar);
elementWidth = mTypedArray.getDimension(R.styleable.CustomRatingBar_elenmentWidth,
context.getResources().getDimension(R.dimen.heart_ratingbar_width));
elementHeight = mTypedArray.getDimension(R.styleable.CustomRatingBar_elenmentHeight,
context.getResources().getDimension(R.dimen.heart_ratingbar_height));
elementPadding = mTypedArray.getDimension(R.styleable.CustomRatingBar_elenmentPadding,
context.getResources().getDimension(R.dimen.ratingbar_padding));
/*
* 白天模式下 热心指数(白色)和个人中心(灰色)使用不同的资源
* 默认灰色
* */
otherHeartImg = mTypedArray.getBoolean(R.styleable.CustomRatingBar_OtherHeartImg, true);
elementStep = mTypedArray.getFloat(R.styleable.CustomRatingBar_elenmentStep, 1.0f);
stepSize = StepSize.fromStep(mTypedArray.getInt(R.styleable.CustomRatingBar_stepSize, 1));
elementCount = mTypedArray.getInteger(R.styleable.CustomRatingBar_elenmentCount, 5);
stepSize = StepSize.Half;
Drawable drawable_empty_default = ContextCompat.getDrawable(context,
otherHeartImg == false ? R.drawable.icon_heart_unchoose : R.drawable.icon_heart_unchoose_other);
Drawable drawable_half_default = ContextCompat.getDrawable(context,
otherHeartImg == false ? R.drawable.icon_heart_second : R.drawable.icon_heart_second_other);
Drawable drawable_fill_default = ContextCompat.getDrawable(context, R.drawable.icon_heart_choose);
Drawable drawable_empty = mTypedArray.getDrawable(R.styleable.CustomRatingBar_elenmentEmpty);
Drawable drawable_half = mTypedArray.getDrawable(R.styleable.CustomRatingBar_elenmentHarf);
Drawable drawable_fill = mTypedArray.getDrawable(R.styleable.CustomRatingBar_elenmentFill);
elementEmptyDrawable = drawable_empty != null ? drawable_empty : drawable_empty_default;
elementFillDrawable = drawable_half != null ? drawable_half : drawable_fill_default;
elementHarfDrawable = drawable_fill != null ? drawable_fill : drawable_half_default;
mClickable = mTypedArray.getBoolean(R.styleable.CustomRatingBar_clickable, false);
mTypedArray.recycle();
for (int i = 0; i < elementCount; ++i) {
final ImageView imageView = getElenmentImageView();
imageView.setImageDrawable(elementEmptyDrawable);
imageView.setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
if (mClickable) {
//浮点数的整数部分
int fint = (int) elementStep;
BigDecimal b1 = new BigDecimal(Float.toString(elementStep));
BigDecimal b2 = new BigDecimal(Integer.toString(fint));
//浮点数的小数部分
float fPoint = b1.subtract(b2).floatValue();
if (fPoint == 0) {
fint -= 1;
}
if (indexOfChild(v) > fint) {
setRating(indexOfChild(v) + 1);
} else if (indexOfChild(v) == fint) {
if (stepSize == StepSize.Full) {//如果是满星 就不考虑半颗星了
return;
}
//点击之后默认每次先增加一颗星,再次点击变为半颗星
if (imageView.getDrawable().getCurrent().getConstantState().
equals(elementHarfDrawable.getConstantState())) {
setRating(indexOfChild(v) + 1);
} else {
setRating(indexOfChild(v) + 0.5f);
}
} else {
setRating(indexOfChild(v) + 1f);
}
}
}
}
);
addView(imageView);
}
setRating(elementStep);
}
private ImageView getElenmentImageView() {
ImageView imageView = new ImageView(getContext());
LayoutParams layout = new LayoutParams(
Math.round(mContext.getResources().getDimension(R.dimen.heart_ratingbar_width)),
Math.round(mContext.getResources().getDimension(R.dimen.heart_ratingbar_width)));//设置每个单元格在线性布局的大小
layout.setMargins(0, 0, Math.round(elementPadding), 0);//设置每颗星星在线性布局的间距
imageView.setLayoutParams(layout);
imageView.setAdjustViewBounds(true);
imageView.setImageDrawable(elementEmptyDrawable);
imageView.setMinimumWidth((int) elementWidth);
imageView.setMaxWidth((int) elementWidth);
imageView.setMinimumHeight((int) elementHeight);
imageView.setMaxHeight((int) elementHeight);
return imageView;
}
public void setRating(float rating) {
if (rating > elementCount)
rating = elementCount;
if (mOnRatingBarChangeListener != null) {
mOnRatingBarChangeListener.onRatingChange(rating);
}
this.elementStep = rating;
//浮点数的整数部分
int fint = (int) rating;
BigDecimal b1 = new BigDecimal(Float.toString(rating));
BigDecimal b2 = new BigDecimal(Integer.toString(fint));
//浮点数的小数部分
float fPoint = b1.subtract(b2).floatValue();
//设置选中的单元
for (int i = 0; i < fint; ++i) {
((ImageView) getChildAt(i)).setImageDrawable(elementFillDrawable);
}
//设置没有选中的单元
for (int i = fint; i < elementCount; i++) {
((ImageView) getChildAt(i)).setImageDrawable(elementEmptyDrawable);
}
//小数点默认增加半个
if (fPoint > 0) {
((ImageView) getChildAt(fint)).setImageDrawable(elementHarfDrawable);
}
}
public interface OnRatingChangeListener {
void onRatingChange(float ratingCount);
}
/**
* 每次增加的方式整颗还是半颗,枚举类型
* 类似于View.GONE
*/
public enum StepSize {
Half(0), Full(1);
int step;
StepSize(int step) {
this.step = step;
}
public static StepSize fromStep(int step) {
for (StepSize f : values()) {
if (f.step == step) {
return f;
}
}
throw new IllegalArgumentException();
}
}
}

View File

@@ -1,55 +0,0 @@
package com.mogo.module.common.view;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.util.AttributeSet;
import androidx.appcompat.widget.AppCompatImageView;
/**
* @author donghongyu
* @date 2019-08-22
*/
public class ImageViewClipBounds extends AppCompatImageView {
Rect mClipBounds = null;
public ImageViewClipBounds(Context context) {
this(context, null);
}
public ImageViewClipBounds(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public ImageViewClipBounds(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onDraw(Canvas canvas) {
if (mClipBounds != null) {
// clip bounds ignore scroll
canvas.clipRect(mClipBounds);
}
super.onDraw(canvas);
}
public void setClip(Rect clipBounds) {
if (clipBounds == mClipBounds || (clipBounds != null && clipBounds.equals(mClipBounds))) {
return;
}
if (clipBounds != null) {
if (mClipBounds == null) {
mClipBounds = new Rect(clipBounds);
} else {
mClipBounds.set(clipBounds);
}
} else {
mClipBounds = null;
}
invalidate();
}
}

View File

@@ -1,39 +0,0 @@
package com.mogo.module.common.view;
import android.view.View;
public
/**
* @author congtaowang
* @since 2020/9/25
*
* 防止短时间内多次点击
*/
abstract class OnPreventFastClickListener implements View.OnClickListener {
public static final long INTERVAL = 1_000L;
private long mInterval;
private long mLastClickTime = 0L;
public OnPreventFastClickListener() {
this( INTERVAL );
}
public OnPreventFastClickListener( long interval ) {
if ( interval < 0L ) {
interval = INTERVAL;
}
this.mInterval = interval;
}
@Override
public final void onClick( View v ) {
if ( System.currentTimeMillis() - mLastClickTime > mInterval ) {
onClickImpl( v );
mLastClickTime = System.currentTimeMillis();
}
}
public abstract void onClickImpl( View v );
}

View File

@@ -1,25 +0,0 @@
package com.mogo.module.common.view;
import android.graphics.Rect;
import android.view.View;
import androidx.recyclerview.widget.RecyclerView;
/**
* 这是LinearLayoutManager设置Item间距的的一个辅助类
*
* @author donghongyu
*/
public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
private int space;
public SpacesItemDecoration(int space) {
this.space = space;
}
@Override
public void getItemOffsets(Rect outRect, View view,
RecyclerView parent, RecyclerView.State state) {
outRect.bottom = space;
}
}

View File

@@ -1,58 +0,0 @@
package com.mogo.module.common.wm;
import android.app.Dialog;
import android.view.View;
import android.view.ViewGroup;
import com.mogo.module.common.dialog.BaseFloatDialog;
/**
* 采用Dialog实现接口
*/
class DialogImpl implements IWindowManagerView {
private Dialog dialog;
private View contentView;
@Override
public void init(WindowManagerView.WMViewParams params) {
dialog = new BaseFloatDialog(params.mContext);
contentView = params.mContentView;
dialog.setContentView(contentView);
}
@Override
public boolean isShowing() {
return dialog.isShowing();
}
@Override
public void handleTouchEvent(OnViewClickListener listener) {
// do nothings.
}
@Override
public void show() {
dialog.show();
}
@Override
public void update(WindowManagerView.WMViewParams params) {
}
@Override
public void update() {
}
@Override
public void hide() {
/*
* 取得view的父组件然后移除view
*/
if (contentView != null) {
((ViewGroup) contentView.getParent()).removeView(contentView);
}
dialog.dismiss();
}
}

View File

@@ -1,49 +0,0 @@
package com.mogo.module.common.wm;
import android.view.View;
public interface IWindowManagerView {
/**
* 初始化
*
* @param params contentView包装类
*/
void init( WindowManagerView.WMViewParams params );
/**
* 是否显示
*
* @return true - 显示中
*/
boolean isShowing();
/**
* 支持手势拖动,该操作只支持触发点击操作
*/
void handleTouchEvent(OnViewClickListener listener);
/**
* 显示
*/
void show();
/**
* 更新界面位置或大小
* @param params 具体参数
*/
void update(WindowManagerView.WMViewParams params);
/**
* 刷新
*/
void update();
/**
* 隐藏
*/
void hide();
public interface OnViewClickListener {
void onClick( View view, float xPos, float yPos );
}
}

View File

@@ -1,118 +0,0 @@
package com.mogo.module.common.wm;
import android.content.Context;
import android.graphics.PixelFormat;
import android.os.Build;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
/**
* 采用windowManager实现接口
*/
class WindowManagerImpl implements IWindowManagerView {
private WindowManager mWindowManager;
private WindowManager.LayoutParams mLayoutParams;
private WindowManagerView.WMViewParams mParams;
private boolean isShowing;
private View rootView;
private float mLastX, mLastY;
private int mOldOffsetX, mOldOffsetY;
@Override
public void init( WindowManagerView.WMViewParams params ) {
mParams = params;
mWindowManager = ( WindowManager ) mParams.mContext.getApplicationContext().getSystemService( Context.WINDOW_SERVICE );
generateLayoutParams();
}
private void generateLayoutParams(){
mLayoutParams = new WindowManager.LayoutParams();
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ) {
mLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
} else {
mLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
}
mLayoutParams.format = PixelFormat.TRANSLUCENT;
mLayoutParams.gravity = mParams.mGravity;
mLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
mLayoutParams.width = mParams.mWidth;
mLayoutParams.height = mParams.mHeight;
mOldOffsetX = mLayoutParams.x = mParams.mX;
mOldOffsetY = mLayoutParams.y = mParams.mY;
mLayoutParams.dimAmount = 0.5f;
}
@Override
public boolean isShowing() {
return isShowing;
}
@Override
public void handleTouchEvent(OnViewClickListener listener) {
mParams.mContentView.setOnTouchListener( ( v, event ) -> {
final int action = event.getAction();
float x = event.getX();
float y = event.getY();
if ( action == MotionEvent.ACTION_DOWN ) {
mLastX = x;
mLastY = y;
} else if ( action == MotionEvent.ACTION_MOVE ) {
mLayoutParams.x += ( int ) ( x - mLastX ) / 3; // 减小偏移量,防止过度抖动
mLayoutParams.y += ( int ) ( y - mLastY ) / 3; // 减小偏移量,防止过度抖动
mWindowManager.updateViewLayout( mParams.mContentView, mLayoutParams );
} else if ( action == MotionEvent.ACTION_UP ) {
int newOffsetX = mLayoutParams.x;
int newOffsetY = mLayoutParams.y;
// 只要按钮一动位置不是很大,就认为是点击事件
if ( Math.abs( mOldOffsetX - newOffsetX ) <= 20
&& Math.abs( mOldOffsetY - newOffsetY ) <= 20 ) {
if ( listener != null ) {
listener.onClick( mParams.mContentView, x, y );
}
return false;
}
mOldOffsetX = newOffsetX;
mOldOffsetY = newOffsetY;
}
return true;
} );
}
@Override
public void show() {
if ( !isShowing ) {
isShowing = true;
rootView = mParams.mContentView;
mWindowManager.addView( mParams.mContentView, mLayoutParams );
}
}
@Override
public void update(WindowManagerView.WMViewParams params) {
if (isShowing) {
mParams = params;
generateLayoutParams();
mWindowManager.updateViewLayout(rootView,mLayoutParams);
}
}
@Override
public void update() {
if ( isShowing ) {
mWindowManager.updateViewLayout(rootView,mLayoutParams);
}
}
@Override
public void hide() {
if ( isShowing && mParams != null ) {
mWindowManager.removeView( mParams.mContentView );
isShowing = false;
}
}
}

View File

@@ -1,136 +0,0 @@
package com.mogo.module.common.wm;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import androidx.annotation.IdRes;
import androidx.annotation.LayoutRes;
/**
* @author congtaowang
* @since 2020-05-21
* <p>
* 往 window manager 添加view
*/
public class WindowManagerView {
private WMViewParams mParams;
private IWindowManagerView mManagerView;
private WindowManagerView( WMViewParams params, IWindowManagerView view ) {
this.mParams = params;
mManagerView = view;
view.init( params );
}
public boolean isShowing() {
return mManagerView.isShowing();
}
public < T extends View > T findViewById( @IdRes int id ) {
return mParams.mContentView.findViewById( id );
}
public void attachTouchEvent( IWindowManagerView.OnViewClickListener listener ) {
mManagerView.handleTouchEvent(listener);
}
public void show() {
mManagerView.show();
}
public void dismiss() {
mManagerView.hide();
}
public static class Builder {
private WMViewParams mParams = null;
public Builder( Context context ) {
mParams = new WMViewParams();
mParams.mContext = context;
}
public Builder contentView( View contentView ) {
mParams.mContentView = contentView;
return this;
}
public Builder contentView( @LayoutRes int contentViewId ) {
mParams.mContentView = LayoutInflater.from( mParams.mContext ).inflate( contentViewId, null );
return this;
}
public Builder size( int width, int height ) {
mParams.mWidth = width;
mParams.mHeight = height;
return this;
}
public Builder position( int x, int y ) {
mParams.mX = x;
mParams.mY = y;
return this;
}
public Builder gravity( int gravity ) {
mParams.mGravity = gravity;
return this;
}
/**
* 默认dialog实现
*
* @return
*/
public WindowManagerView build() {
return showInDialog();
}
public WindowManagerView showInDialog() {
if ( mParams.mContentView == null ) {
throw new NullPointerException( "WMViewParams#mContentView must not be null." );
}
return new WindowManagerView( mParams, new DialogImpl() );
}
public WindowManagerView showInWindowManager() {
if ( mParams.mContentView == null ) {
throw new NullPointerException( "WMViewParams#mContentView must not be null." );
}
return new WindowManagerView( mParams, new WindowManagerImpl() );
}
}
public static class WMViewParams {
public View mContentView;
public Context mContext;
public int mWidth;
public int mHeight;
public int mX;
public int mY;
public int mGravity;
}
public void exchangeSizeAndPosition(int width, int height, int x, int y) {
if (isShowing()) {
mParams.mX = x;
mParams.mY = y;
mParams.mWidth = width;
mParams.mHeight = height;
mManagerView.update(mParams);
}
}
public void update(){
if ( mManagerView != null) {
mManagerView.update();
}
}
}