This commit is contained in:
lixiaopeng
2020-08-12 17:32:10 +08:00
parent 3e28bee7e3
commit 8046dfe511
11 changed files with 201 additions and 42 deletions

View File

@@ -23,7 +23,7 @@ import java.util.List;
* @description 周边
* @since 2020/7/29
*/
public class SurroundingEventAdapter extends RecyclerView.Adapter<SurroundingEventViewHolder> {
public class V2XSurroundingAdapter extends RecyclerView.Adapter<V2XSurroundingViewHolder> {
private List<SurroundingConstruction> mPoiInfosList;
private Context mContext;
private ImageView mBgImageView;
@@ -34,7 +34,7 @@ public class SurroundingEventAdapter extends RecyclerView.Adapter<SurroundingEve
private SurroundingItemClickListener mClickListener;
public SurroundingEventAdapter(Context context, List<SurroundingConstruction> poiInfosList, SurroundingItemClickListener clickListener) {
public V2XSurroundingAdapter(Context context, List<SurroundingConstruction> poiInfosList, SurroundingItemClickListener clickListener) {
mContext = context;
mPoiInfosList = poiInfosList;
mClickListener = clickListener;
@@ -47,14 +47,14 @@ public class SurroundingEventAdapter extends RecyclerView.Adapter<SurroundingEve
@NonNull
@Override
public SurroundingEventViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
public V2XSurroundingViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View inflate = LayoutInflater.from(parent.getContext())
.inflate(R.layout.module_fragment_surrounding_event_item, parent, false);
return new SurroundingEventViewHolder(inflate);
return new V2XSurroundingViewHolder(inflate);
}
@Override
public void onBindViewHolder(@NonNull SurroundingEventViewHolder holder, final int position) {
public void onBindViewHolder(@NonNull V2XSurroundingViewHolder holder, final int position) {
final SurroundingConstruction surroundingConstruction = mPoiInfosList.get(position);
if (surroundingConstruction == null) {
return;
@@ -84,11 +84,29 @@ public class SurroundingEventAdapter extends RecyclerView.Adapter<SurroundingEve
.load(getTypeRes(surroundingConstruction.getPoiType()))
.into(mBgImageView);
// CornerTransform transformation = new CornerTransform(mContext, dip2px(mContext, 15));
// //只是绘制左上角和右上角圆角
// transformation.setExceptCorner(true, true, false, false);
//
// Glide.with(mContext).
// load(getTypeRes(surroundingConstruction.getPoiType()))
// .asBitmap()
// .skipMemoryCache(true)
// .diskCacheStrategy(DiskCacheStrategy.NONE)
// .transform(transformation)
// .into(mBgImageView);
//
Glide.with(mContext)
.load(getTypeSmallRes(surroundingConstruction.getPoiType()))
.into(mTypeImageView);
}
public static int dip2px(Context context, float dpValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}
@Override
public int getItemCount() {
return mPoiInfosList == null ? 0 : mPoiInfosList.size();

View File

@@ -10,9 +10,9 @@ import androidx.recyclerview.widget.RecyclerView;
* @description
* @since 2020/7/29
*/
public class SurroundingEventViewHolder extends RecyclerView.ViewHolder{
public class V2XSurroundingViewHolder extends RecyclerView.ViewHolder{
public SurroundingEventViewHolder(@NonNull View itemView) {
public V2XSurroundingViewHolder(@NonNull View itemView) {
super(itemView);
}

View File

@@ -22,18 +22,16 @@ import androidx.recyclerview.widget.RecyclerView;
import com.alibaba.android.arouter.launcher.ARouter;
import com.mogo.commons.mvp.MvpFragment;
import com.mogo.commons.voice.AIAssist;
import com.mogo.map.MogoLatLng;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.anim.OnMarkerAnimationListener;
import com.mogo.module.common.entity.MarkerExploreWay;
import com.mogo.module.common.entity.MarkerLocation;
import com.mogo.module.common.entity.MarkerPoiTypeEnum;
import com.mogo.module.common.entity.MarkerShowEntity;
import com.mogo.module.service.ServiceConst;
import com.mogo.module.v2x.R;
import com.mogo.module.v2x.V2XServiceManager;
import com.mogo.module.v2x.adapter.SurroundingEventAdapter;
import com.mogo.module.v2x.adapter.V2XSurroundingAdapter;
import com.mogo.module.v2x.entity.panel.SurroundingConstruction;
import com.mogo.module.v2x.listener.SurroundingItemClickListener;
import com.mogo.module.v2x.presenter.SurroundingEventPresenter;
@@ -41,7 +39,6 @@ import com.mogo.module.v2x.view.SurroundingEventView;
import com.mogo.module.v2x.view.SurroundingMarginDecoration;
import com.mogo.service.IMogoServiceApis;
import com.mogo.service.MogoServicePaths;
import com.mogo.utils.TipToast;
import com.mogo.utils.WorkThreadHandler;
import com.mogo.utils.logger.Logger;
@@ -66,7 +63,7 @@ public class V2XSurroundingFragment extends MvpFragment<SurroundingEventView, Su
private TextView mTopFreshTv;
private TextView mShareTv;
private TextView mFreshTv;
private SurroundingEventAdapter mAdapter;
private V2XSurroundingAdapter mAdapter;
private SurroundingEventPresenter surroundingEventPresenter;
private List<SurroundingConstruction> poiInfosList = new ArrayList<>();
private IMogoServiceApis mApis;
@@ -93,11 +90,11 @@ public class V2XSurroundingFragment extends MvpFragment<SurroundingEventView, Su
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setOverScrollMode(OVER_SCROLL_NEVER);
GridLayoutManager layoutManage = new GridLayoutManager(getContext(), 2);
int spacingInPixels = getResources().getDimensionPixelSize(R.dimen.module_v2x_surrounding_item_size);
int spacingInPixels = getContext().getResources().getDimensionPixelSize(R.dimen.module_v2x_surrounding_item_size);
mRecyclerView.addItemDecoration(new SurroundingMarginDecoration(spacingInPixels));
mRecyclerView.setLayoutManager(layoutManage);
mAdapter = new SurroundingEventAdapter(getActivity(), poiInfosList, this);
mAdapter = new V2XSurroundingAdapter(getActivity(), poiInfosList, this);
mRecyclerView.setAdapter(mAdapter);
initData();
@@ -212,7 +209,7 @@ public class V2XSurroundingFragment extends MvpFragment<SurroundingEventView, Su
V2XServiceManager.getMarkerManager().removeMarkers(ServiceConst.CARD_TYPE_ROAD_CONDITION);
try {
//处理 marker的显示 TODO 是否需要showbound
//处理 marker的显示
List<MarkerExploreWay> exploreWayList = construction.getConstrutList();
Logger.d(TAG, "onItemClickListener exploreWayList.size() = " + exploreWayList.size());
if (exploreWayList != null && exploreWayList.size() > 0) {
@@ -261,7 +258,6 @@ public class V2XSurroundingFragment extends MvpFragment<SurroundingEventView, Su
}
}
/**
* 自适应显示
*
@@ -270,10 +266,10 @@ public class V2XSurroundingFragment extends MvpFragment<SurroundingEventView, Su
private void showBonndsRoadtion(List<MarkerExploreWay> exploreWayList) {
Logger.e(TAG, "showBonndsRoadtion exploreWayList.size() = " + exploreWayList.size());
Rect rect = new Rect(
(int) getContext().getResources().getDimension(R.dimen.tanlu_module_map_left),
(int) getContext().getResources().getDimension(R.dimen.tanlu_module_map_top),
(int) getContext().getResources().getDimension(R.dimen.tanlu_module_map_right),
(int) getContext().getResources().getDimension(R.dimen.tanlu_module_map_bottom));
(int) getContext().getResources().getDimension(R.dimen.module_v2x_map_left),
(int) getContext().getResources().getDimension(R.dimen.module_v2x_map_top),
(int) getContext().getResources().getDimension(R.dimen.module_v2x_map_right),
(int) getContext().getResources().getDimension(R.dimen.module_v2x_map_bottom));
moveNotFresh();
//第一个参数:调用者,第二个参数:当前自车的位置,第三个参数:需要显示在范围内的点(不包含自车的位置)

View File

@@ -63,7 +63,7 @@ public class SurroundingEventPresenter extends Presenter<SurroundingEventView> {
}
Center center = new Center(location.getLatitude(), location.getLongitude());
String[] poiTypes = {"10002", "10003", "10006", "10007", "10008", "10010", "10011", "10013", "10015"};
SurroundingRequest request = new SurroundingRequest(center, poiTypes, 5000, 15);
SurroundingRequest request = new SurroundingRequest(center, poiTypes, 5, 15);
eventApiService.getSurroundingEventList(Utils.getSn(), convert(GsonUtil.jsonFromObject(request)))
.subscribeOn(Schedulers.io())
@@ -87,6 +87,7 @@ public class SurroundingEventPresenter extends Presenter<SurroundingEventView> {
@Override
public void onError(String message, int code) {
super.onError(message, code);
mView.showSurroudingData(null);
Logger.e("SurroundingFragment", "onError message = " + message + " >>> code = " + code);
}
});

View File

@@ -0,0 +1,139 @@
package com.mogo.module.v2x.utils;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
import androidx.annotation.NonNull;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import com.bumptech.glide.util.Util;
import java.security.MessageDigest;
/**
* @author lixiaopeng
* @description
* @since 2020/8/12
*/
public class CornerTransform implements Transformation<Bitmap> {
private BitmapPool mBitmapPool;
private float radius;
private boolean exceptLeftTop, exceptRightTop, exceptLeftBottom, exceptRightBotoom;
/**
* 除了那几个角不需要圆角的
*
* @param leftTop
* @param rightTop
* @param leftBottom
* @param rightBottom
*/
public void setExceptCorner(boolean leftTop, boolean rightTop, boolean leftBottom, boolean rightBottom) {
this.exceptLeftTop = leftTop;
this.exceptRightTop = rightTop;
this.exceptLeftBottom = leftBottom;
this.exceptRightBotoom = rightBottom;
}
public CornerTransform(Context context, float radius) {
this.mBitmapPool = Glide.get(context).getBitmapPool();
this.radius = radius;
}
@NonNull
@Override
public Resource<Bitmap> transform(@NonNull Context context, @NonNull Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int finalWidth, finalHeight;
float ratio; //输出目标的宽高或高宽比例
if (outWidth > outHeight) { //输出宽度>输出高度,求高宽比
ratio = (float) outHeight / (float) outWidth;
finalWidth = source.getWidth();
finalHeight = (int) ((float) source.getWidth() * ratio); //固定原图宽度,求最终高度
if (finalHeight > source.getHeight()) { //求出的最终高度>原图高度,求宽高比
ratio = (float) outWidth / (float) outHeight;
finalHeight = source.getHeight();
finalWidth = (int) ((float) source.getHeight() * ratio);//固定原图高度,求最终宽度
}
} else if (outWidth < outHeight) { //输出宽度 < 输出高度,求宽高比
ratio = (float) outWidth / (float) outHeight;
finalHeight = source.getHeight();
finalWidth = (int) ((float) source.getHeight() * ratio);//固定原图高度,求最终宽度
if (finalWidth > source.getWidth()) { //求出的最终宽度 > 原图宽度,求高宽比
ratio = (float) outHeight / (float) outWidth;
finalWidth = source.getWidth();
finalHeight = (int) ((float) source.getWidth() * ratio);
}
} else { //输出宽度=输出高度
finalHeight = source.getHeight();
finalWidth = finalHeight;
}
//修正圆角
this.radius *= (float) finalHeight / (float) outHeight;
Bitmap outBitmap = this.mBitmapPool.get(finalWidth, finalHeight, Bitmap.Config.ARGB_8888);
if (outBitmap == null) {
outBitmap = Bitmap.createBitmap(finalWidth, finalHeight, Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(outBitmap);
Paint paint = new Paint();
//关联画笔绘制的原图bitmap
BitmapShader shader = new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
//计算中心位置,进行偏移
int width = (source.getWidth() - finalWidth) / 2;
int height = (source.getHeight() - finalHeight) / 2;
if (width != 0 || height != 0) {
Matrix matrix = new Matrix();
matrix.setTranslate((float) (-width), (float) (-height));
shader.setLocalMatrix(matrix);
}
paint.setShader(shader);
paint.setAntiAlias(true);
RectF rectF = new RectF(0.0F, 0.0F, (float) canvas.getWidth(), (float) canvas.getHeight());
canvas.drawRoundRect(rectF, this.radius, this.radius, paint); //先绘制圆角矩形
if (exceptLeftTop) { //左上角不为圆角
canvas.drawRect(0, 0, radius, radius, paint);
}
if (exceptRightTop) {//右上角不为圆角
canvas.drawRect(canvas.getWidth() - radius, 0, canvas.getWidth(), radius, paint);
}
if (exceptLeftBottom) {//左下角不为圆角
canvas.drawRect(0, canvas.getHeight() - radius, radius, canvas.getHeight(), paint);
}
if (exceptRightBotoom) {//右下角不为圆角
canvas.drawRect(canvas.getWidth() - radius, canvas.getHeight() - radius, canvas.getWidth(), canvas.getHeight(), paint);
}
return BitmapResource.obtain(outBitmap, this.mBitmapPool);
}
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
}
public String getId() {
return this.getClass().getName();
}
public int hashCode() {
//避免Transformation重复设置,导致图片闪烁,同一个圆角值的Transformation视为同一个对象
return Util.hashCode(getId().hashCode(), Util.hashCode(this.radius));
}
}

View File

@@ -20,13 +20,12 @@ public class SurroundingMarginDecoration extends RecyclerView.ItemDecoration {
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
outRect.bottom = margin;
outRect.right = 0;
//由于每行都只有2个所以第一个都是2的倍数把左边距设为0
if (parent.getChildLayoutPosition(view) % 2 == 0) {
outRect.left = 0;
outRect.right = margin;
} else {
outRect.left = margin;
outRect.right = 0;
}
}

View File

@@ -2,22 +2,21 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androud="http://schemas.android.com/apk/res-auto"
android:id="@+id/clPanelContainer"
android:layout_width="642px"
android:layout_height="532px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_v2x_event_surrounding_item">
<!--顶部layout-->
<RelativeLayout
android:id="@+id/layout_top"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_height="35px"
android:visibility="visible">
<TextView
android:id="@+id/tv_brief"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="20px"
android:textSize="18px"
android:textColor="@color/white" />
@@ -43,6 +42,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10px"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
android:layout_marginBottom="20px"
android:layout_below="@+id/layout_top">

View File

@@ -1,26 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:layout_width="291px"
android:layout_width="wrap_content"
android:layout_height="173px">
<ImageView
android:id="@+id/iv_event_bg"
android:scaleType="center"
android:layout_width="280px"
android:layout_width="match_parent"
android:layout_height="130px" />
<RelativeLayout
android:layout_below="@+id/iv_event_bg"
android:background="@drawable/bg_v2x_event_surrounding_item_bottom"
android:layout_width="280px"
android:layout_width="match_parent"
android:layout_height="43px">
<ImageView
android:id="@+id/iv_event_type"
android:layout_width="22px"
android:layout_height="16px"
android:layout_width="26px"
android:layout_height="26px"
android:layout_marginLeft="10px"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/icon_default_black_logo" />
@@ -40,7 +41,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="30px"
android:layout_marginRight="12px"
android:layout_centerVertical="true"
android:textSize="16px"
android:textColor="@color/transparent_white_30"

View File

@@ -23,11 +23,11 @@
<dimen name="module_v2x_event_distance_title">40px</dimen>
<dimen name="module_v2x_history_event_icon_size">80px</dimen>
<dimen name="module_v2x_surrounding_item_bottom_size">6px</dimen>
<dimen name="tanlu_module_map_left">550px</dimen>
<dimen name="tanlu_module_map_top">200px</dimen>
<dimen name="tanlu_module_map_right">200px</dimen>
<dimen name="tanlu_module_map_bottom">100px</dimen>
<dimen name="module_v2x_surrounding_item_bottom_size">6px</dimen>
<dimen name="module_v2x_map_left">550px</dimen>
<dimen name="module_v2x_map_top">200px</dimen>
<dimen name="module_v2x_map_right">200px</dimen>
<dimen name="module_v2x_map_bottom">100px</dimen>
</resources>

View File

@@ -24,11 +24,13 @@
<dimen name="module_v2x_event_distance_title">22px</dimen>
<dimen name="module_v2x_history_event_icon_size">40px</dimen>
<dimen name="module_v2x_surrounding_item_bottom_size">6px</dimen>
<dimen name="module_v2x_surrounding_item_size">16px</dimen>
<dimen name="tanlu_module_map_left">550px</dimen>
<dimen name="tanlu_module_map_top">200px</dimen>
<dimen name="tanlu_module_map_right">200px</dimen>
<dimen name="tanlu_module_map_bottom">100px</dimen>
<dimen name="module_v2x_map_left">550px</dimen>
<dimen name="module_v2x_map_top">200px</dimen>
<dimen name="module_v2x_map_right">200px</dimen>
<dimen name="module_v2x_map_bottom">100px</dimen>
</resources>

View File

@@ -6,5 +6,7 @@
<string name="v2x_report_pop_submit_txt">已提交</string>
<string name="v2x_report_pop_thank_txt">感谢已送达</string>
<string name="v2x_surrounding_top_brief">周围5公里共 %d 条交通信息</string>
<string name="v2x_surrounding_go_to_share">分享</string>
<string name="v2x_surrounding_refresh">刷新</string>
</resources>