fix conflict
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
package com.mogo.module.tanlu.constant
|
||||
|
||||
const val REQUESTCODE_MAINACTIVITY = 0
|
||||
const val REQUESTCODE_MEDIAACTIVITY = 1
|
||||
|
||||
//EXTRA_STATE
|
||||
const val AUTO_NAVI_START = 8 //开始导航
|
||||
const val AUTO_NAVI_END = 9 //结束导航
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.mogo.module.tanlu.constant;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-24
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class TanluConstants {
|
||||
|
||||
public static final String TAG = "/tanlu/ui";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,464 @@
|
||||
package com.mogo.module.tanlu.fragment;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.commons.mvp.IView;
|
||||
import com.mogo.commons.mvp.MvpFragment;
|
||||
import com.mogo.commons.mvp.Presenter;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.listener.IMogoMapListener;
|
||||
import com.mogo.map.location.IMogoLocationListener;
|
||||
import com.mogo.map.location.MogoLocation;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||
import com.mogo.map.marker.IMogoMarkerManager;
|
||||
import com.mogo.map.marker.MogoMarkerOptions;
|
||||
import com.mogo.map.model.MogoPoi;
|
||||
import com.mogo.map.search.geo.MogoPoiItem;
|
||||
import com.mogo.map.search.poisearch.IMogoPoiSearchListener;
|
||||
import com.mogo.map.search.poisearch.MogoPoiResult;
|
||||
import com.mogo.map.uicontroller.EnumMapUI;
|
||||
import com.mogo.module.service.entity.MarkerExploreWay;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.imageloader.IMogoImageLoaderListener;
|
||||
import com.mogo.service.imageloader.IMogoImageloader;
|
||||
import com.mogo.service.map.IMogoMapService;
|
||||
import com.mogo.service.module.IMogoModuleLifecycle;
|
||||
import com.mogo.module.tanlu.R;
|
||||
import com.mogo.module.tanlu.model.event.MarkerInfo;
|
||||
import com.mogo.module.tanlu.util.Utils;
|
||||
import com.mogo.module.tanlu.video.FullMediaActivity;
|
||||
import com.mogo.module.tanlu.video.SimpleCoverVideoPlayer;
|
||||
import com.mogo.module.tanlu.view.AutoZoomInImageView;
|
||||
import com.mogo.utils.TipToast;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.shuyu.gsyvideoplayer.builder.GSYVideoOptionBuilder;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.mogo.module.tanlu.util.StringUitlKt.formatDate;
|
||||
import static com.mogo.module.tanlu.util.Utils.handleDistance;
|
||||
import static com.mogo.module.tanlu.video.VideoInitKt.initVideo;
|
||||
|
||||
/**
|
||||
* @author lixiaopeng
|
||||
* @description 探路卡片
|
||||
* @since 2020-01-02
|
||||
*/
|
||||
public class TanluCardViewFragment extends MvpFragment<IView, Presenter<IView>>
|
||||
implements IView,
|
||||
IMogoMarkerClickListener,
|
||||
IMogoModuleLifecycle,
|
||||
IMogoMapListener,
|
||||
IMogoPoiSearchListener,
|
||||
IMogoLocationListener,
|
||||
View.OnClickListener {
|
||||
|
||||
private static final String TAG = "liyz";
|
||||
SimpleCoverVideoPlayer simpleCoverVideoPlayer;
|
||||
AutoZoomInImageView autoZoomInImageView;
|
||||
//map
|
||||
private IMogoMarker mPoiMarker;
|
||||
private IMogoMarkerManager mMarkerManager;
|
||||
private IMogoMapService mMogoMapService;
|
||||
//media
|
||||
private GSYVideoOptionBuilder gsyVideoOptionBuilder = new GSYVideoOptionBuilder();
|
||||
private String mVideoUrl = "http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8";
|
||||
private String mImageUrl = "https://oimagec4.ydstatic.com/image?id=-5397300958976572132&product=adpublish&w=520&h=347";
|
||||
private IMogoImageloader mogoImageloader;
|
||||
private TextView mPreviousTv;
|
||||
private TextView mNextTv;
|
||||
private RelativeLayout mRootLayout;
|
||||
private RelativeLayout mEmptyLayout;
|
||||
private TextView mEmptyTv;
|
||||
private TextView mAddressTv;
|
||||
private TextView mDistanceTv;
|
||||
private TextView mTimeTv;
|
||||
|
||||
private List<MarkerExploreWay> markerExploreWayList = new ArrayList<>();
|
||||
private int currentPosition = 0; //卡片媒体当前位置
|
||||
private Bitmap mMarkerIcon;
|
||||
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.tanlu_item_main_media_recycler;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initViews() {
|
||||
initVideo();
|
||||
simpleCoverVideoPlayer = findViewById(R.id.video_player_main);
|
||||
autoZoomInImageView = findViewById(R.id.tanlu_photo_imageView);
|
||||
mPreviousTv = findViewById(R.id.tv_previous_res);
|
||||
mNextTv = findViewById(R.id.tv_next_res);
|
||||
mRootLayout = findViewById(R.id.layout_data_show);
|
||||
mEmptyLayout = findViewById(R.id.layout_empty_data_show);
|
||||
mEmptyTv = findViewById(R.id.tv_main_empty);
|
||||
mAddressTv = findViewById(R.id.tv_information_media_content);
|
||||
mDistanceTv = findViewById(R.id.tv_distance_video);
|
||||
mTimeTv = findViewById(R.id.tv_information_media_time);
|
||||
|
||||
mPreviousTv.setOnClickListener(this);
|
||||
mNextTv.setOnClickListener(this);
|
||||
mEmptyTv.setOnClickListener(this);
|
||||
|
||||
simpleCoverVideoPlayer.setVisibility(View.VISIBLE);
|
||||
autoZoomInImageView.setVisibility(View.GONE);
|
||||
|
||||
//视频配置
|
||||
gsyVideoOptionBuilder.setUrl(mVideoUrl).setCacheWithPlay(false).setPlayTag(TAG)
|
||||
.build(simpleCoverVideoPlayer);
|
||||
// simpleCoverVideoPlayer.getStartButton().performClick();
|
||||
simpleCoverVideoPlayer.getStartButton().setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Logger.d(TAG, "simpleCoverVideoPlayer onClick -------> ");
|
||||
FullMediaActivity.Companion.launch(getActivity(), mVideoUrl, mImageUrl, "东城区环球贸易中心", 1300000300);
|
||||
}
|
||||
});
|
||||
|
||||
//图片配置
|
||||
mogoImageloader = (IMogoImageloader) ARouter.getInstance().build(MogoServicePaths.PATH_UTILS_IMAGE_LOADER).navigation();
|
||||
//地图marker
|
||||
mMogoMapService = (IMogoMapService) ARouter.getInstance().build(MogoServicePaths.PATH_SERVICES_MAP).navigation(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
getViewLifecycleOwner().getLifecycle().addObserver(mPresenter);
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @param view
|
||||
*/
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int id = view.getId();
|
||||
if (id == R.id.tv_previous_res) { //上一个
|
||||
//判断是图片还是视频,第一个时,上一个不可点击
|
||||
Logger.d(TAG, " tv_previous_res --1-> currentPosition =" + currentPosition + ">> size= " + markerExploreWayList.size());
|
||||
if (currentPosition < 0) {
|
||||
return;
|
||||
}
|
||||
currentPosition--;
|
||||
Logger.d(TAG, " tv_previous_res --2-> currentPosition =" + currentPosition + ">> size= " + markerExploreWayList.size());
|
||||
if (markerExploreWayList.size() > currentPosition && currentPosition >= 0) {
|
||||
handleData(markerExploreWayList.get(currentPosition));
|
||||
}
|
||||
} else if (id == R.id.tv_next_res) { //下一个
|
||||
//判断是图片还是视频,最后一个时,下一个不可点击
|
||||
Logger.d(TAG, " tv_next_res --1-> currentPosition =" + currentPosition + ">> size= " + markerExploreWayList.size());
|
||||
if (currentPosition > markerExploreWayList.size()) {
|
||||
return;
|
||||
}
|
||||
currentPosition++;
|
||||
Logger.d(TAG, " tv_next_res --2-> currentPosition =" + currentPosition + ">> size= " + markerExploreWayList.size());
|
||||
if (markerExploreWayList.size() > currentPosition) {
|
||||
handleData(markerExploreWayList.get(currentPosition));
|
||||
}
|
||||
|
||||
} else if (id == R.id.tv_main_empty) { //TODO 上报路况,逻辑
|
||||
Logger.d(TAG, "tv_main_empty click -----> ");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行图片动画
|
||||
*/
|
||||
private void handleImageAnimation() {
|
||||
autoZoomInImageView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
//放大增量是0.3,放大时间是1000毫秒,放大开始时间是600毫秒以后
|
||||
autoZoomInImageView.init()
|
||||
.startZoomInByScaleDeltaAndDuration(0.2f, 1000, 500);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* marker点击事件
|
||||
*
|
||||
* @param marker
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean onMarkerClicked(IMogoMarker marker) {
|
||||
//点击marker以后,确认他的位置?然后点击下一个操作
|
||||
MarkerExploreWay exploreWay = (MarkerExploreWay) marker.getObject();
|
||||
handleData(exploreWay);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的处理数据逻辑
|
||||
*
|
||||
* @param exploreWay
|
||||
*/
|
||||
private void handleData(MarkerExploreWay exploreWay) {
|
||||
if (exploreWay != null && exploreWay.getFileType() != null) {
|
||||
if (exploreWay.getFileType().equals("0")) { //图片
|
||||
refreshPhotoData(exploreWay);
|
||||
} else if (exploreWay.getFileType().equals("1")) { //视频
|
||||
refreshVideoData(exploreWay);
|
||||
}
|
||||
} else {
|
||||
Logger.e(TAG, "handleData exploreWay == null ");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新单个视频数据,更新位置positon
|
||||
*/
|
||||
private void refreshVideoData(MarkerExploreWay markerExploreWay) {
|
||||
if (markerExploreWay.getItems() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (markerExploreWay.getItems().size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
String videoUrl = markerExploreWay.getItems().get(0).getUrl();
|
||||
mAddressTv.setText(markerExploreWay.getAddr());
|
||||
mDistanceTv.setText(handleDistance(markerExploreWay.getDistance()));
|
||||
mTimeTv.setText(formatDate(markerExploreWay.getGenerateTime()));
|
||||
//判断是图片还是视频,第一个时,上一个不可点击
|
||||
simpleCoverVideoPlayer.setVisibility(View.VISIBLE);
|
||||
autoZoomInImageView.setVisibility(View.GONE);
|
||||
//视频配置
|
||||
gsyVideoOptionBuilder.setUrl(videoUrl).setCacheWithPlay(false).setPlayTag(TAG)
|
||||
.build(simpleCoverVideoPlayer);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新单个图片数据
|
||||
*/
|
||||
private void refreshPhotoData(MarkerExploreWay markerExploreWay) {
|
||||
if (markerExploreWay.getItems() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (markerExploreWay.getItems().size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
mAddressTv.setText(markerExploreWay.getAddr());
|
||||
mDistanceTv.setText(handleDistance(markerExploreWay.getDistance()));
|
||||
mTimeTv.setText(formatDate(markerExploreWay.getGenerateTime()));
|
||||
String thumbnailUrl = markerExploreWay.getItems().get(0).getThumbnail();
|
||||
Logger.d(TAG, "refreshPhotoData thumbnailUrl ------>" + thumbnailUrl);
|
||||
autoZoomInImageView.setVisibility(View.VISIBLE);
|
||||
simpleCoverVideoPlayer.setVisibility(View.GONE);
|
||||
mogoImageloader.downloadImage(getActivity(), thumbnailUrl, new IMogoImageLoaderListener() {
|
||||
@Override
|
||||
public void onStart() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompleted(Bitmap bitmap) {
|
||||
autoZoomInImageView.setImageBitmap(bitmap);
|
||||
//动画
|
||||
handleImageAnimation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
Logger.e(TAG, "onFailure ------>" + e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected Presenter createPresenter() {
|
||||
return new Presenter(this) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* C位事件,如何获取数据,需要有默认数据 TODO
|
||||
* 如果只有一个数据,不显示上下切换按钮,没有数据显示空页面
|
||||
*/
|
||||
@Override
|
||||
public void onPerform() {
|
||||
Logger.d(TAG, "tanlu卡片 有效 ---->");
|
||||
mMarkerManager = mMogoMapService.getMarkerManager(getActivity());
|
||||
List<IMogoMarker> markers = mMarkerManager.getMarkers("CARD_TYPE_ROAD_CODITION");
|
||||
if (markers != null && markers.size() > 0) {
|
||||
mEmptyLayout.setVisibility(View.GONE);
|
||||
mRootLayout.setVisibility(View.VISIBLE);
|
||||
Logger.d(TAG, "onPerform markers.size() =" + markers.size());
|
||||
for (int i = 0; i < markers.size(); i++) {
|
||||
markerExploreWayList.add((MarkerExploreWay) markers.get(i).getObject());
|
||||
}
|
||||
|
||||
if (markers.size() == 1) {
|
||||
mPreviousTv.setVisibility(View.GONE);
|
||||
mNextTv.setVisibility(View.GONE);
|
||||
} else {
|
||||
mPreviousTv.setVisibility(View.VISIBLE);
|
||||
mNextTv.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
//展示第一个数据
|
||||
MarkerExploreWay markerExploreWay = markerExploreWayList.get(0);
|
||||
if (markerExploreWay != null && markerExploreWay.getFileType() != null) {
|
||||
if (markerExploreWay.getFileType().equals("0")) { //图片
|
||||
refreshPhotoData(markerExploreWay);
|
||||
} else if (markerExploreWay.getFileType().equals("1")) { //视频
|
||||
refreshVideoData(markerExploreWay);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mEmptyLayout.setVisibility(View.VISIBLE);
|
||||
mRootLayout.setVisibility(View.GONE);
|
||||
mEmptyTv.setText(Html.fromHtml(getContext().getString(R.string.main_empty_content)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 离开C位事件
|
||||
*/
|
||||
@Override
|
||||
public void onDisable() {
|
||||
Logger.d(TAG, "tanlu卡片 无效 ----->");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accOn() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapLoaded() {
|
||||
Logger.d(TAG, "地图加载事件");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTouch(MotionEvent motionEvent) {
|
||||
// Logger.d( TAG, "地图触摸事件" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPOIClick(MogoPoi poi) {
|
||||
if (poi != null) {
|
||||
TipToast.shortTip(poi.getName());
|
||||
}
|
||||
TanluServiceHandler.getPoiSearch().searchPOIIdAsyn(poi.getPoiId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPoiSearched(MogoPoiResult result, int errorCode) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPoiItemSearched(MogoPoiItem item, int errorCode) {
|
||||
if (item == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(MogoLocation location) {
|
||||
// if (location.getErrCode() == 0) {
|
||||
// Logger.d(TAG, "onLocationChanged 当前位置 -->" + location.getAddress());
|
||||
// } else {
|
||||
// Logger.d(TAG, "onLocationChanged 定位失败 -->" + location.getErrInfo());
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapClick(MogoLatLng latLng) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLockMap(boolean isLock) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapModeChanged(EnumMapUI ui) {
|
||||
Logger.d(TAG, ui.name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapChanged(MogoLatLng location, float zoom, float tilt, float bearing) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
EventBus.getDefault().unregister(this);
|
||||
getViewLifecycleOwner().getLifecycle().removeObserver(mPresenter);
|
||||
TanluServiceHandler.getLocationClient().removeLocationListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 接收到对应数据打点
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onMarkerInfo(final MarkerInfo event) {
|
||||
mMarkerIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_search_poi_location);
|
||||
mogoImageloader.downloadImage(getActivity(), event.imageUrl, new IMogoImageLoaderListener() {
|
||||
@Override
|
||||
public void onStart() {
|
||||
Logger.d(TAG, "onMarkerInfo onStart ------>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompleted(Bitmap bitmap) {
|
||||
Logger.d(TAG, "onMarkerInfo onCompleted ------>");
|
||||
MogoMarkerOptions options = new MogoMarkerOptions()
|
||||
.icon(mMarkerIcon)
|
||||
.latitude(event.lat)
|
||||
.owner("tag")
|
||||
.longitude(event.lon);
|
||||
|
||||
mMogoMapService = (IMogoMapService) ARouter.getInstance().build(MogoServicePaths.PATH_SERVICES_MAP).navigation(getContext());
|
||||
mMarkerManager = mMogoMapService.getMarkerManager(getContext());
|
||||
IMogoMarker marker = mMarkerManager.addMarker("tag", options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
Logger.e(TAG, "onMarkerInfo onFailure -----E->" + e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.mogo.module.tanlu.fragment;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.map.listener.IMogoMapListener;
|
||||
import com.mogo.map.location.IMogoLocationListener;
|
||||
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||
import com.mogo.map.navi.IMogoNaviListener;
|
||||
import com.mogo.service.module.IMogoModuleLifecycle;
|
||||
import com.mogo.service.module.IMogoModuleProvider;
|
||||
import com.mogo.service.module.ModuleType;
|
||||
import com.mogo.module.tanlu.constant.TanluConstants;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-24
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
@Route( path = TanluConstants.TAG )
|
||||
public class TanluCardViewProvider implements IMogoModuleProvider {
|
||||
|
||||
private static final String TAG = "TanluCardViewProvider";
|
||||
private TanluCardViewFragment fragment;
|
||||
|
||||
@Override
|
||||
public Fragment createFragment( Context context, Bundle data ) {
|
||||
fragment = new TanluCardViewFragment();
|
||||
fragment.setArguments( data );
|
||||
Logger.i( TAG, "createFragment" );
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
TanluServiceHandler.init( context );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModuleName() {
|
||||
return "CARD_TYPE_ROAD_CODITION";
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoModuleLifecycle getCardLifecycle() {
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View createView( Context context ) {
|
||||
// don't
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoMapListener getMapListener() {
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return ModuleType.TYPE_CARD_FRAGMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoNaviListener getNaviListener() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoLocationListener getLocationListener() {
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoMarkerClickListener getMarkerClickListener() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.mogo.module.tanlu.fragment;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.map.location.IMogoLocationClient;
|
||||
import com.mogo.map.marker.IMogoMarkerManager;
|
||||
import com.mogo.map.navi.IMogoNavi;
|
||||
import com.mogo.map.search.poisearch.IMogoPoiSearch;
|
||||
import com.mogo.map.search.poisearch.query.MogoPoiSearchQuery;
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.imageloader.IMogoImageloader;
|
||||
import com.mogo.service.map.IMogoMapService;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-30
|
||||
* <p>
|
||||
* 持有服务接口实例
|
||||
*/
|
||||
public class TanluServiceHandler {
|
||||
|
||||
private static IMogoMapService mMapService;
|
||||
private static IMogoPoiSearch mPoiSearch;
|
||||
private static IMogoLocationClient mLocationClient;
|
||||
private static IMogoMarkerManager mMarkerManager;
|
||||
private static IMogoNavi mNavi;
|
||||
private static IMogoMapUIController mMapUIController;
|
||||
private static IMogoImageloader mImageloader;
|
||||
|
||||
public static void init( Context context ) {
|
||||
mMapService = ( IMogoMapService ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_MAP ).navigation( context );
|
||||
mMapService = ( IMogoMapService ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_MAP ).navigation( context );
|
||||
mImageloader = ( IMogoImageloader ) ARouter.getInstance().build( MogoServicePaths.PATH_UTILS_IMAGE_LOADER ).navigation( context );
|
||||
mPoiSearch = mMapService.getPoiSearch( context, new MogoPoiSearchQuery() );
|
||||
mLocationClient = mMapService.getLocationClient( context );
|
||||
mMarkerManager = mMapService.getMarkerManager( context );
|
||||
mNavi = mMapService.getNavi( context );
|
||||
mMapUIController = mMapService.getMapUIController();
|
||||
}
|
||||
|
||||
public static IMogoMapService getMapService() {
|
||||
return mMapService;
|
||||
}
|
||||
|
||||
public static IMogoPoiSearch getPoiSearch() {
|
||||
return mPoiSearch;
|
||||
}
|
||||
|
||||
public static IMogoLocationClient getLocationClient() {
|
||||
return mLocationClient;
|
||||
}
|
||||
|
||||
public static IMogoMarkerManager getMarkerManager() {
|
||||
return mMarkerManager;
|
||||
}
|
||||
|
||||
public static IMogoNavi getNavi() {
|
||||
return mNavi;
|
||||
}
|
||||
|
||||
public static IMogoMapUIController getMapUIController() {
|
||||
return mMapUIController;
|
||||
}
|
||||
|
||||
public static IMogoImageloader getImageloader() {
|
||||
return mImageloader;
|
||||
}
|
||||
}
|
||||
268
modules/mogo-module-tanlu/src/main/java/com/mogo/module/tanlu/map/AMapUtil.java
Executable file
268
modules/mogo-module-tanlu/src/main/java/com/mogo/module/tanlu/map/AMapUtil.java
Executable file
@@ -0,0 +1,268 @@
|
||||
package com.mogo.module.tanlu.map;
|
||||
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.widget.EditText;
|
||||
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.services.core.LatLonPoint;
|
||||
import com.amap.api.services.route.BusPath;
|
||||
import com.amap.api.services.route.BusStep;
|
||||
import com.amap.api.services.route.RouteBusLineItem;
|
||||
import com.amap.api.services.route.RouteRailwayItem;
|
||||
import com.mogo.module.tanlu.R;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class AMapUtil {
|
||||
/**
|
||||
* 判断edittext是否null
|
||||
*/
|
||||
public static String checkEditText(EditText editText) {
|
||||
if (editText != null && editText.getText() != null
|
||||
&& !(editText.getText().toString().trim().equals(""))) {
|
||||
return editText.getText().toString().trim();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static Spanned stringToSpan(String src) {
|
||||
return src == null ? null : Html.fromHtml(src.replace("\n", "<br />"));
|
||||
}
|
||||
|
||||
public static String colorFont(String src, String color) {
|
||||
StringBuffer strBuf = new StringBuffer();
|
||||
|
||||
strBuf.append("<font color=").append(color).append(">").append(src)
|
||||
.append("</font>");
|
||||
return strBuf.toString();
|
||||
}
|
||||
|
||||
public static String makeHtmlNewLine() {
|
||||
return "<br />";
|
||||
}
|
||||
|
||||
public static String makeHtmlSpace(int number) {
|
||||
final String space = " ";
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int i = 0; i < number; i++) {
|
||||
result.append(space);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static String getFriendlyLength(int lenMeter) {
|
||||
if (lenMeter > 10000) // 10 km
|
||||
{
|
||||
int dis = lenMeter / 1000;
|
||||
return dis + ChString.Kilometer;
|
||||
}
|
||||
|
||||
if (lenMeter > 1000) {
|
||||
float dis = (float) lenMeter / 1000;
|
||||
DecimalFormat fnum = new DecimalFormat("##0.0");
|
||||
String dstr = fnum.format(dis);
|
||||
return dstr + ChString.Kilometer;
|
||||
}
|
||||
|
||||
if (lenMeter > 100) {
|
||||
int dis = lenMeter / 50 * 50;
|
||||
return dis + ChString.Meter;
|
||||
}
|
||||
|
||||
int dis = lenMeter / 10 * 10;
|
||||
if (dis == 0) {
|
||||
dis = 10;
|
||||
}
|
||||
|
||||
return dis + ChString.Meter;
|
||||
}
|
||||
|
||||
public static boolean IsEmptyOrNullString(String s) {
|
||||
return (s == null) || (s.trim().length() == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把LatLng对象转化为LatLonPoint对象
|
||||
*/
|
||||
public static LatLonPoint convertToLatLonPoint(LatLng latlon) {
|
||||
return new LatLonPoint(latlon.latitude, latlon.longitude);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把LatLonPoint对象转化为LatLon对象
|
||||
*/
|
||||
public static LatLng convertToLatLng(LatLonPoint latLonPoint) {
|
||||
return new LatLng(latLonPoint.getLatitude(), latLonPoint.getLongitude());
|
||||
}
|
||||
|
||||
/**
|
||||
* 把集合体的LatLonPoint转化为集合体的LatLng
|
||||
*/
|
||||
public static ArrayList<LatLng> convertArrList(List<LatLonPoint> shapes) {
|
||||
ArrayList<LatLng> lineShapes = new ArrayList<LatLng>();
|
||||
for (LatLonPoint point : shapes) {
|
||||
LatLng latLngTemp = AMapUtil.convertToLatLng(point);
|
||||
lineShapes.add(latLngTemp);
|
||||
}
|
||||
return lineShapes;
|
||||
}
|
||||
|
||||
/**
|
||||
* long类型时间格式化
|
||||
*/
|
||||
public static String convertToTime(long time) {
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date date = new Date(time);
|
||||
return df.format(date);
|
||||
}
|
||||
|
||||
public static final String HtmlBlack = "#000000";
|
||||
public static final String HtmlGray = "#808080";
|
||||
|
||||
public static String getFriendlyTime(int second) {
|
||||
if (second > 3600) {
|
||||
int hour = second / 3600;
|
||||
int miniate = (second % 3600) / 60;
|
||||
return hour + "小时" + miniate + "分钟";
|
||||
}
|
||||
if (second >= 60) {
|
||||
int miniate = second / 60;
|
||||
return miniate + "分钟";
|
||||
}
|
||||
return second + "秒";
|
||||
}
|
||||
|
||||
//路径规划方向指示和图片对应
|
||||
public static int getDriveActionID(String actionName) {
|
||||
if (actionName == null || actionName.equals("")) {
|
||||
return R.drawable.dir3;
|
||||
}
|
||||
if ("左转".equals(actionName)) {
|
||||
return R.drawable.dir2;
|
||||
}
|
||||
if ("右转".equals(actionName)) {
|
||||
return R.drawable.dir1;
|
||||
}
|
||||
if ("向左前方行驶".equals(actionName) || "靠左".equals(actionName)) {
|
||||
return R.drawable.dir6;
|
||||
}
|
||||
if ("向右前方行驶".equals(actionName) || "靠右".equals(actionName)) {
|
||||
return R.drawable.dir5;
|
||||
}
|
||||
if ("向左后方行驶".equals(actionName) || "左转调头".equals(actionName)) {
|
||||
return R.drawable.dir7;
|
||||
}
|
||||
if ("向右后方行驶".equals(actionName)) {
|
||||
return R.drawable.dir8;
|
||||
}
|
||||
if ("直行".equals(actionName)) {
|
||||
return R.drawable.dir3;
|
||||
}
|
||||
if ("减速行驶".equals(actionName)) {
|
||||
return R.drawable.dir4;
|
||||
}
|
||||
return R.drawable.dir3;
|
||||
}
|
||||
|
||||
public static int getWalkActionID(String actionName) {
|
||||
if (actionName == null || actionName.equals("")) {
|
||||
return R.drawable.dir13;
|
||||
}
|
||||
if ("左转".equals(actionName)) {
|
||||
return R.drawable.dir2;
|
||||
}
|
||||
if ("右转".equals(actionName)) {
|
||||
return R.drawable.dir1;
|
||||
}
|
||||
if ("向左前方".equals(actionName) || "靠左".equals(actionName) || actionName.contains("向左前方")) {
|
||||
return R.drawable.dir6;
|
||||
}
|
||||
if ("向右前方".equals(actionName) || "靠右".equals(actionName) || actionName.contains("向右前方")) {
|
||||
return R.drawable.dir5;
|
||||
}
|
||||
if ("向左后方".equals(actionName) || actionName.contains("向左后方")) {
|
||||
return R.drawable.dir7;
|
||||
}
|
||||
if ("向右后方".equals(actionName) || actionName.contains("向右后方")) {
|
||||
return R.drawable.dir8;
|
||||
}
|
||||
if ("直行".equals(actionName)) {
|
||||
return R.drawable.dir3;
|
||||
}
|
||||
if ("通过人行横道".equals(actionName)) {
|
||||
return R.drawable.dir9;
|
||||
}
|
||||
if ("通过过街天桥".equals(actionName)) {
|
||||
return R.drawable.dir11;
|
||||
}
|
||||
if ("通过地下通道".equals(actionName)) {
|
||||
return R.drawable.dir10;
|
||||
}
|
||||
|
||||
return R.drawable.dir13;
|
||||
}
|
||||
|
||||
public static String getBusPathTitle(BusPath busPath) {
|
||||
if (busPath == null) {
|
||||
return String.valueOf("");
|
||||
}
|
||||
List<BusStep> busSetps = busPath.getSteps();
|
||||
if (busSetps == null) {
|
||||
return String.valueOf("");
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (BusStep busStep : busSetps) {
|
||||
StringBuffer title = new StringBuffer();
|
||||
if (busStep.getBusLines().size() > 0) {
|
||||
for (RouteBusLineItem busline : busStep.getBusLines()) {
|
||||
if (busline == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String buslineName = getSimpleBusLineName(busline.getBusLineName());
|
||||
title.append(buslineName);
|
||||
title.append(" / ");
|
||||
}
|
||||
// RouteBusLineItem busline = busStep.getBusLines().get(0);
|
||||
|
||||
sb.append(title.substring(0, title.length() - 3));
|
||||
sb.append(" > ");
|
||||
}
|
||||
if (busStep.getRailway() != null) {
|
||||
RouteRailwayItem railway = busStep.getRailway();
|
||||
sb.append(railway.getTrip() + "(" + railway.getDeparturestop().getName()
|
||||
+ " - " + railway.getArrivalstop().getName() + ")");
|
||||
sb.append(" > ");
|
||||
}
|
||||
}
|
||||
return sb.substring(0, sb.length() - 3);
|
||||
}
|
||||
|
||||
public static String getBusPathDes(BusPath busPath) {
|
||||
if (busPath == null) {
|
||||
return String.valueOf("");
|
||||
}
|
||||
long second = busPath.getDuration();
|
||||
String time = getFriendlyTime((int) second);
|
||||
float subDistance = busPath.getDistance();
|
||||
String subDis = getFriendlyLength((int) subDistance);
|
||||
float walkDistance = busPath.getWalkDistance();
|
||||
String walkDis = getFriendlyLength((int) walkDistance);
|
||||
return String.valueOf(time + " | " + subDis + " | 步行" + walkDis);
|
||||
}
|
||||
|
||||
public static String getSimpleBusLineName(String busLineName) {
|
||||
if (busLineName == null) {
|
||||
return String.valueOf("");
|
||||
}
|
||||
return busLineName.replaceAll("\\(.*?\\)", "");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.mogo.module.tanlu.map;
|
||||
|
||||
public class ChString {
|
||||
public static final String Kilometer = "\u516c\u91cc";// "公里";
|
||||
public static final String Meter = "\u7c73";// "米";
|
||||
public static final String ByFoot = "\u6b65\u884c";// "步行";
|
||||
public static final String To = "\u53bb\u5f80";// "去往";
|
||||
public static final String Station = "\u8f66\u7ad9";// "车站";
|
||||
public static final String TargetPlace = "\u76ee\u7684\u5730";// "目的地";
|
||||
public static final String StartPlace = "\u51fa\u53d1\u5730";// "出发地";
|
||||
public static final String About = "\u5927\u7ea6";// "大约";
|
||||
public static final String Direction = "\u65b9\u5411";// "方向";
|
||||
|
||||
public static final String GetOn = "\u4e0a\u8f66";// "上车";
|
||||
public static final String GetOff = "\u4e0b\u8f66";// "下车";
|
||||
public static final String Zhan = "\u7ad9";// "站";
|
||||
|
||||
public static final String cross = "\u4ea4\u53c9\u8def\u53e3"; // 交叉路口
|
||||
public static final String type = "\u7c7b\u522b"; // 类别
|
||||
public static final String address = "\u5730\u5740"; // 地址
|
||||
public static final String PrevStep = "\u4e0a\u4e00\u6b65";
|
||||
public static final String NextStep = "\u4e0b\u4e00\u6b65";
|
||||
public static final String Gong = "\u516c\u4ea4";
|
||||
public static final String ByBus = "\u4e58\u8f66";
|
||||
public static final String Arrive = "\u5230\u8FBE";// 到达
|
||||
}
|
||||
@@ -0,0 +1,384 @@
|
||||
package com.mogo.module.tanlu.map;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.amap.api.maps.model.BitmapDescriptor;
|
||||
import com.amap.api.maps.model.BitmapDescriptorFactory;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.maps.model.LatLngBounds;
|
||||
import com.amap.api.maps.model.Marker;
|
||||
import com.amap.api.maps.model.MarkerOptions;
|
||||
import com.amap.api.maps.model.PolylineOptions;
|
||||
import com.amap.api.services.core.LatLonPoint;
|
||||
import com.amap.api.services.route.DrivePath;
|
||||
import com.amap.api.services.route.DriveStep;
|
||||
import com.amap.api.services.route.TMC;
|
||||
import com.mogo.module.tanlu.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 导航路线图层类
|
||||
*/
|
||||
public class DrivingRouteOverlay extends RouteOverlay {
|
||||
private DrivePath drivePath;
|
||||
private List<LatLonPoint> throughPointList;
|
||||
private List<Marker> throughPointMarkerList = new ArrayList<Marker>();
|
||||
private boolean throughPointMarkerVisible = true;
|
||||
private List<TMC> tmcs;
|
||||
private PolylineOptions mPolylineOptions;
|
||||
private PolylineOptions mPolylineOptionscolor;
|
||||
private Context mContext;
|
||||
private boolean isColorfulline = true;
|
||||
private float mWidth = 4;
|
||||
private List<LatLng> mLatLngsOfPath;
|
||||
|
||||
public void setIsColorfulline(boolean iscolorfulline) {
|
||||
this.isColorfulline = iscolorfulline;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据给定的参数,构造一个导航路线图层类对象。
|
||||
*
|
||||
* @param amap 地图对象。
|
||||
* @param path 导航路线规划方案。
|
||||
* @param context 当前的activity对象。
|
||||
*/
|
||||
public DrivingRouteOverlay(Context context, AMap amap, DrivePath path,
|
||||
LatLonPoint start, LatLonPoint end, List<LatLonPoint> throughPointList) {
|
||||
super(context);
|
||||
mContext = context;
|
||||
mAMap = amap;
|
||||
this.drivePath = path;
|
||||
startPoint = AMapUtil.convertToLatLng(start);
|
||||
endPoint = AMapUtil.convertToLatLng(end);
|
||||
this.throughPointList = throughPointList;
|
||||
|
||||
initBitmapDescriptor();
|
||||
}
|
||||
|
||||
public float getRouteWidth() {
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置路线宽度
|
||||
*
|
||||
* @param mWidth 路线宽度,取值范围:大于0
|
||||
*/
|
||||
public void setRouteWidth(float mWidth) {
|
||||
this.mWidth = mWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加驾车路线添加到地图上显示。
|
||||
*/
|
||||
public void addToMap() {
|
||||
initPolylineOptions();
|
||||
try {
|
||||
if (mAMap == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mWidth == 0 || drivePath == null) {
|
||||
return;
|
||||
}
|
||||
mLatLngsOfPath = new ArrayList<LatLng>();
|
||||
tmcs = new ArrayList<TMC>();
|
||||
List<DriveStep> drivePaths = drivePath.getSteps();
|
||||
mPolylineOptions.add(startPoint);
|
||||
for (int i = 0; i < drivePaths.size(); i++) {
|
||||
DriveStep step = drivePaths.get(i);
|
||||
List<LatLonPoint> latlonPoints = step.getPolyline();
|
||||
List<TMC> tmclist = step.getTMCs();
|
||||
tmcs.addAll(tmclist);
|
||||
addDrivingStationMarkers(step, convertToLatLng(latlonPoints.get(0)));
|
||||
for (LatLonPoint latlonpoint : latlonPoints) {
|
||||
mPolylineOptions.add(convertToLatLng(latlonpoint));
|
||||
mLatLngsOfPath.add(convertToLatLng(latlonpoint));
|
||||
}
|
||||
}
|
||||
mPolylineOptions.add(endPoint);
|
||||
if (startMarker != null) {
|
||||
startMarker.remove();
|
||||
startMarker = null;
|
||||
}
|
||||
|
||||
if (endMarker != null) {
|
||||
endMarker.remove();
|
||||
endMarker = null;
|
||||
}
|
||||
// addStartAndEndMarker();
|
||||
// addThroughPointMarker();
|
||||
if (isColorfulline && tmcs.size() > 0) {
|
||||
colorWayUpdate(tmcs);
|
||||
showcolorPolyline();
|
||||
} else {
|
||||
showPolyline();
|
||||
}
|
||||
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化线段属性
|
||||
*/
|
||||
private void initPolylineOptions() {
|
||||
mPolylineOptions = null;
|
||||
mPolylineOptions = new PolylineOptions();
|
||||
mPolylineOptions.color(getDriveColor()).width(getRouteWidth());
|
||||
}
|
||||
|
||||
private void showPolyline() {
|
||||
addPolyLine(mPolylineOptions);
|
||||
}
|
||||
|
||||
private void showcolorPolyline() {
|
||||
addPolyLine(mPolylineOptionscolor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据不同的路段拥堵情况展示不同的颜色
|
||||
*
|
||||
* @param tmcSection
|
||||
*/
|
||||
private void colorWayUpdate(List<TMC> tmcSection) {
|
||||
if (mAMap == null) {
|
||||
return;
|
||||
}
|
||||
if (tmcSection == null || tmcSection.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
TMC segmentTrafficStatus;
|
||||
mPolylineOptionscolor = null;
|
||||
mPolylineOptionscolor = new PolylineOptions();
|
||||
mPolylineOptionscolor.width(getRouteWidth());
|
||||
List<Integer> colorList = new ArrayList<Integer>();
|
||||
List<BitmapDescriptor> bitmapDescriptors = new ArrayList<BitmapDescriptor>();
|
||||
List<LatLng> points = new ArrayList<>();
|
||||
List<Integer> texIndexList = new ArrayList<Integer>();
|
||||
// mPolylineOptionscolor.add(startPoint);
|
||||
// mPolylineOptionscolor.add(AMapUtil.convertToLatLng(tmcSection.get(0).getPolyline().get(0)));
|
||||
|
||||
points.add(startPoint);
|
||||
points.add(AMapUtil.convertToLatLng(tmcSection.get(0).getPolyline().get(0)));
|
||||
colorList.add(getDriveColor());
|
||||
bitmapDescriptors.add(defaultRoute);
|
||||
|
||||
BitmapDescriptor bitmapDescriptor = null;
|
||||
int textIndex = 0;
|
||||
texIndexList.add(textIndex);
|
||||
texIndexList.add(++textIndex);
|
||||
for (int i = 0; i < tmcSection.size(); i++) {
|
||||
segmentTrafficStatus = tmcSection.get(i);
|
||||
int color = getcolor(segmentTrafficStatus.getStatus());
|
||||
bitmapDescriptor = getTrafficBitmapDescriptor(segmentTrafficStatus.getStatus());
|
||||
List<LatLonPoint> mployline = segmentTrafficStatus.getPolyline();
|
||||
for (int j = 0; j < mployline.size(); j++) {
|
||||
// mPolylineOptionscolor.add(AMapUtil.convertToLatLng(mployline.get(j)));
|
||||
points.add(AMapUtil.convertToLatLng(mployline.get(j)));
|
||||
colorList.add(color);
|
||||
|
||||
texIndexList.add(++textIndex);
|
||||
bitmapDescriptors.add(bitmapDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
points.add(endPoint);
|
||||
colorList.add(getDriveColor());
|
||||
bitmapDescriptors.add(defaultRoute);
|
||||
texIndexList.add(++textIndex);
|
||||
mPolylineOptionscolor.addAll(points);
|
||||
mPolylineOptionscolor.colorValues(colorList);
|
||||
|
||||
// mPolylineOptionscolor.setCustomTextureIndex(texIndexList);
|
||||
// mPolylineOptionscolor.setCustomTextureList(bitmapDescriptors);
|
||||
}
|
||||
|
||||
private BitmapDescriptor defaultRoute = null;
|
||||
private BitmapDescriptor unknownTraffic = null;
|
||||
private BitmapDescriptor smoothTraffic = null;
|
||||
private BitmapDescriptor slowTraffic = null;
|
||||
private BitmapDescriptor jamTraffic = null;
|
||||
private BitmapDescriptor veryJamTraffic = null;
|
||||
|
||||
private void initBitmapDescriptor() {
|
||||
defaultRoute = BitmapDescriptorFactory.fromResource(R.drawable.amap_route_color_texture_6_arrow);
|
||||
smoothTraffic = BitmapDescriptorFactory.fromResource(R.drawable.amap_route_color_texture_4_arrow);
|
||||
unknownTraffic = BitmapDescriptorFactory.fromResource(R.drawable.amap_route_color_texture_0_arrow);
|
||||
slowTraffic = BitmapDescriptorFactory.fromResource(R.drawable.amap_route_color_texture_3_arrow);
|
||||
jamTraffic = BitmapDescriptorFactory.fromResource(R.drawable.amap_route_color_texture_2_arrow);
|
||||
veryJamTraffic = BitmapDescriptorFactory.fromResource(R.drawable.amap_route_color_texture_9_arrow);
|
||||
}
|
||||
|
||||
private BitmapDescriptor getTrafficBitmapDescriptor(String status) {
|
||||
if (status.equals("畅通")) {
|
||||
return smoothTraffic;
|
||||
} else if (status.equals("缓行")) {
|
||||
return slowTraffic;
|
||||
} else if (status.equals("拥堵")) {
|
||||
return jamTraffic;
|
||||
} else if (status.equals("严重拥堵")) {
|
||||
return veryJamTraffic;
|
||||
} else {
|
||||
return defaultRoute;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private int getcolor(String status) {
|
||||
if (status.equals("畅通")) {
|
||||
return Color.GREEN;
|
||||
} else if (status.equals("缓行")) {
|
||||
return Color.YELLOW;
|
||||
} else if (status.equals("拥堵")) {
|
||||
return Color.RED;
|
||||
} else if (status.equals("严重拥堵")) {
|
||||
return Color.parseColor("#990033");
|
||||
} else {
|
||||
return Color.GREEN;
|
||||
}
|
||||
}
|
||||
|
||||
public LatLng convertToLatLng(LatLonPoint point) {
|
||||
return new LatLng(point.getLatitude(), point.getLongitude());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param driveStep
|
||||
* @param latLng
|
||||
*/
|
||||
private void addDrivingStationMarkers(DriveStep driveStep, LatLng latLng) {
|
||||
addStationMarker(new MarkerOptions()
|
||||
.position(latLng)
|
||||
.title("\u65B9\u5411:" + driveStep.getAction()
|
||||
+ "\n\u9053\u8DEF:" + driveStep.getRoad())
|
||||
.snippet(driveStep.getInstruction()).visible(nodeIconVisible)
|
||||
.anchor(0.5f, 0.5f).icon(getDriveBitmapDescriptor()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LatLngBounds getLatLngBounds() {
|
||||
LatLngBounds.Builder b = LatLngBounds.builder();
|
||||
b.include(new LatLng(startPoint.latitude, startPoint.longitude));
|
||||
b.include(new LatLng(endPoint.latitude, endPoint.longitude));
|
||||
if (this.throughPointList != null && this.throughPointList.size() > 0) {
|
||||
for (int i = 0; i < this.throughPointList.size(); i++) {
|
||||
b.include(new LatLng(
|
||||
this.throughPointList.get(i).getLatitude(),
|
||||
this.throughPointList.get(i).getLongitude()));
|
||||
}
|
||||
}
|
||||
return b.build();
|
||||
}
|
||||
|
||||
public void setThroughPointIconVisibility(boolean visible) {
|
||||
try {
|
||||
throughPointMarkerVisible = visible;
|
||||
if (this.throughPointMarkerList != null
|
||||
&& this.throughPointMarkerList.size() > 0) {
|
||||
for (int i = 0; i < this.throughPointMarkerList.size(); i++) {
|
||||
this.throughPointMarkerList.get(i).setVisible(visible);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void addThroughPointMarker() {
|
||||
if (this.throughPointList != null && this.throughPointList.size() > 0) {
|
||||
LatLonPoint latLonPoint = null;
|
||||
for (int i = 0; i < this.throughPointList.size(); i++) {
|
||||
latLonPoint = this.throughPointList.get(i);
|
||||
if (latLonPoint != null) {
|
||||
throughPointMarkerList.add(mAMap
|
||||
.addMarker((new MarkerOptions())
|
||||
.position(
|
||||
new LatLng(latLonPoint
|
||||
.getLatitude(), latLonPoint
|
||||
.getLongitude()))
|
||||
.visible(throughPointMarkerVisible)
|
||||
.icon(getThroughPointBitDes())
|
||||
.title("\u9014\u7ECF\u70B9")));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private BitmapDescriptor getThroughPointBitDes() {
|
||||
return BitmapDescriptorFactory.fromResource(R.drawable.amap_through);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取两点间距离
|
||||
*
|
||||
* @param start
|
||||
* @param end
|
||||
* @return
|
||||
*/
|
||||
public static int calculateDistance(LatLng start, LatLng end) {
|
||||
double x1 = start.longitude;
|
||||
double y1 = start.latitude;
|
||||
double x2 = end.longitude;
|
||||
double y2 = end.latitude;
|
||||
return calculateDistance(x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
public static int calculateDistance(double x1, double y1, double x2, double y2) {
|
||||
final double NF_pi = 0.01745329251994329; // 弧度 PI/180
|
||||
x1 *= NF_pi;
|
||||
y1 *= NF_pi;
|
||||
x2 *= NF_pi;
|
||||
y2 *= NF_pi;
|
||||
double sinx1 = Math.sin(x1);
|
||||
double siny1 = Math.sin(y1);
|
||||
double cosx1 = Math.cos(x1);
|
||||
double cosy1 = Math.cos(y1);
|
||||
double sinx2 = Math.sin(x2);
|
||||
double siny2 = Math.sin(y2);
|
||||
double cosx2 = Math.cos(x2);
|
||||
double cosy2 = Math.cos(y2);
|
||||
double[] v1 = new double[3];
|
||||
v1[0] = cosy1 * cosx1 - cosy2 * cosx2;
|
||||
v1[1] = cosy1 * sinx1 - cosy2 * sinx2;
|
||||
v1[2] = siny1 - siny2;
|
||||
double dist = Math.sqrt(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]);
|
||||
|
||||
return (int) (Math.asin(dist / 2) * 12742001.5798544);
|
||||
}
|
||||
|
||||
|
||||
//获取指定两点之间固定距离点
|
||||
public static LatLng getPointForDis(LatLng sPt, LatLng ePt, double dis) {
|
||||
double lSegLength = calculateDistance(sPt, ePt);
|
||||
double preResult = dis / lSegLength;
|
||||
return new LatLng((ePt.latitude - sPt.latitude) * preResult + sPt.latitude, (ePt.longitude - sPt.longitude) * preResult + sPt.longitude);
|
||||
}
|
||||
|
||||
/**
|
||||
* 去掉DriveLineOverlay上的线段和标记。
|
||||
*/
|
||||
@Override
|
||||
public void removeFromMap() {
|
||||
try {
|
||||
super.removeFromMap();
|
||||
if (this.throughPointMarkerList != null
|
||||
&& this.throughPointMarkerList.size() > 0) {
|
||||
for (int i = 0; i < this.throughPointMarkerList.size(); i++) {
|
||||
this.throughPointMarkerList.get(i).remove();
|
||||
}
|
||||
this.throughPointMarkerList.clear();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
package com.mogo.module.tanlu.map;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.amap.api.maps.CameraUpdateFactory;
|
||||
import com.amap.api.maps.model.BitmapDescriptor;
|
||||
import com.amap.api.maps.model.BitmapDescriptorFactory;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.maps.model.LatLngBounds;
|
||||
import com.amap.api.maps.model.Marker;
|
||||
import com.amap.api.maps.model.MarkerOptions;
|
||||
import com.amap.api.maps.model.Polyline;
|
||||
import com.amap.api.maps.model.PolylineOptions;
|
||||
import com.mogo.module.tanlu.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class RouteOverlay {
|
||||
protected List<Marker> stationMarkers = new ArrayList<Marker>();
|
||||
protected List<Polyline> allPolyLines = new ArrayList<Polyline>();
|
||||
protected Marker startMarker;
|
||||
protected Marker endMarker;
|
||||
protected LatLng startPoint;
|
||||
protected LatLng endPoint;
|
||||
protected AMap mAMap;
|
||||
private Context mContext;
|
||||
private Bitmap startBit, endBit, busBit, walkBit, driveBit;
|
||||
protected boolean nodeIconVisible = true;
|
||||
|
||||
public RouteOverlay(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* 去掉BusRouteOverlay上所有的Marker。
|
||||
*
|
||||
* @since V2.1.0
|
||||
*/
|
||||
public void removeFromMap() {
|
||||
if (startMarker != null) {
|
||||
startMarker.remove();
|
||||
|
||||
}
|
||||
if (endMarker != null) {
|
||||
endMarker.remove();
|
||||
}
|
||||
for (Marker marker : stationMarkers) {
|
||||
marker.remove();
|
||||
}
|
||||
for (Polyline line : allPolyLines) {
|
||||
line.remove();
|
||||
}
|
||||
destroyBit();
|
||||
}
|
||||
|
||||
private void destroyBit() {
|
||||
if (startBit != null) {
|
||||
startBit.recycle();
|
||||
startBit = null;
|
||||
}
|
||||
if (endBit != null) {
|
||||
endBit.recycle();
|
||||
endBit = null;
|
||||
}
|
||||
if (busBit != null) {
|
||||
busBit.recycle();
|
||||
busBit = null;
|
||||
}
|
||||
if (walkBit != null) {
|
||||
walkBit.recycle();
|
||||
walkBit = null;
|
||||
}
|
||||
if (driveBit != null) {
|
||||
driveBit.recycle();
|
||||
driveBit = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 给起点Marker设置图标,并返回更换图标的图片。如不用默认图片,需要重写此方法。
|
||||
*
|
||||
* @return 更换的Marker图片。
|
||||
* @since V2.1.0
|
||||
*/
|
||||
protected BitmapDescriptor getStartBitmapDescriptor() {
|
||||
return BitmapDescriptorFactory.fromResource(R.drawable.amap_start);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给终点Marker设置图标,并返回更换图标的图片。如不用默认图片,需要重写此方法。
|
||||
*
|
||||
* @return 更换的Marker图片。
|
||||
* @since V2.1.0
|
||||
*/
|
||||
protected BitmapDescriptor getEndBitmapDescriptor() {
|
||||
return BitmapDescriptorFactory.fromResource(R.drawable.amap_end);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给公交Marker设置图标,并返回更换图标的图片。如不用默认图片,需要重写此方法。
|
||||
*
|
||||
* @return 更换的Marker图片。
|
||||
* @since V2.1.0
|
||||
*/
|
||||
protected BitmapDescriptor getBusBitmapDescriptor() {
|
||||
return BitmapDescriptorFactory.fromResource(R.drawable.amap_bus);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给步行Marker设置图标,并返回更换图标的图片。如不用默认图片,需要重写此方法。
|
||||
*
|
||||
* @return 更换的Marker图片。
|
||||
* @since V2.1.0
|
||||
*/
|
||||
protected BitmapDescriptor getWalkBitmapDescriptor() {
|
||||
return BitmapDescriptorFactory.fromResource(R.drawable.amap_man);
|
||||
}
|
||||
|
||||
protected BitmapDescriptor getDriveBitmapDescriptor() {
|
||||
return BitmapDescriptorFactory.fromResource(R.drawable.amap_car);
|
||||
}
|
||||
|
||||
protected void addStartAndEndMarker() {
|
||||
startMarker = mAMap.addMarker((new MarkerOptions())
|
||||
.position(startPoint).icon(getStartBitmapDescriptor())
|
||||
.title("\u8D77\u70B9"));
|
||||
// startMarker.showInfoWindow();
|
||||
|
||||
endMarker = mAMap.addMarker((new MarkerOptions()).position(endPoint)
|
||||
.icon(getEndBitmapDescriptor()).title("\u7EC8\u70B9"));
|
||||
// mAMap.moveCamera(CameraUpdateFactory.newLatLngZoom(startPoint,
|
||||
// getShowRouteZoom()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动镜头到当前的视角。
|
||||
*
|
||||
* @since V2.1.0
|
||||
*/
|
||||
public void zoomToSpan() {
|
||||
if (startPoint != null) {
|
||||
if (mAMap == null)
|
||||
return;
|
||||
try {
|
||||
LatLngBounds bounds = getLatLngBounds();
|
||||
mAMap.animateCamera(CameraUpdateFactory
|
||||
.newLatLngBounds(bounds, 50));
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected LatLngBounds getLatLngBounds() {
|
||||
LatLngBounds.Builder b = LatLngBounds.builder();
|
||||
b.include(new LatLng(startPoint.latitude, startPoint.longitude));
|
||||
b.include(new LatLng(endPoint.latitude, endPoint.longitude));
|
||||
for (Polyline polyline : allPolyLines) {
|
||||
for (LatLng point : polyline.getPoints()) {
|
||||
b.include(point);
|
||||
}
|
||||
}
|
||||
return b.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 路段节点图标控制显示接口。
|
||||
*
|
||||
* @param visible true为显示节点图标,false为不显示。
|
||||
* @since V2.3.1
|
||||
*/
|
||||
public void setNodeIconVisibility(boolean visible) {
|
||||
try {
|
||||
nodeIconVisible = visible;
|
||||
if (this.stationMarkers != null && this.stationMarkers.size() > 0) {
|
||||
for (int i = 0; i < this.stationMarkers.size(); i++) {
|
||||
this.stationMarkers.get(i).setVisible(visible);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected void addStationMarker(MarkerOptions options) {
|
||||
if (options == null) {
|
||||
return;
|
||||
}
|
||||
Marker marker = mAMap.addMarker(options);
|
||||
if (marker != null) {
|
||||
stationMarkers.add(marker);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void addPolyLine(PolylineOptions options) {
|
||||
if (options == null) {
|
||||
return;
|
||||
}
|
||||
Polyline polyline = mAMap.addPolyline(options);
|
||||
if (polyline != null) {
|
||||
allPolyLines.add(polyline);
|
||||
}
|
||||
}
|
||||
|
||||
protected float getRouteWidth() {
|
||||
return 18f;
|
||||
}
|
||||
|
||||
protected int getWalkColor() {
|
||||
return Color.parseColor("#6db74d");
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义路线颜色。
|
||||
* return 自定义路线颜色。
|
||||
*
|
||||
* @since V2.2.1
|
||||
*/
|
||||
protected int getBusColor() {
|
||||
return Color.parseColor("#537edc");
|
||||
}
|
||||
|
||||
protected int getDriveColor() {
|
||||
return Color.parseColor("#537edc");
|
||||
}
|
||||
|
||||
// protected int getShowRouteZoom() {
|
||||
// return 15;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.mogo.module.tanlu.model
|
||||
|
||||
class CarsLive {
|
||||
var sn: String
|
||||
var lat: Double
|
||||
var lon: Double
|
||||
var direction: Int
|
||||
var canLive: Int
|
||||
|
||||
constructor(sn: String, lat: Double, lon: Double, direction: Int, canLive: Int) {
|
||||
this.sn = sn
|
||||
this.lat = lat
|
||||
this.lon = lon
|
||||
this.direction = direction
|
||||
this.canLive = canLive
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.mogo.module.tanlu.model
|
||||
|
||||
/**
|
||||
* @description
|
||||
*
|
||||
* @author lixiaopeng
|
||||
* @since 2019-10-24
|
||||
*/
|
||||
data class Center (
|
||||
val lat: Double,//weidu
|
||||
val lon: Double
|
||||
)
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.mogo.module.tanlu.model;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.mogo.commons.data.BaseData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author lixiaopeng
|
||||
* @description 列表数据
|
||||
* @since 2020-01-05
|
||||
*/
|
||||
public class Information extends BaseData implements Parcelable {
|
||||
private int type;
|
||||
private Double lon;
|
||||
private Double lat;
|
||||
private String addr;
|
||||
private Long generateTime;
|
||||
private String cityName;
|
||||
private ArrayList<Items> items;
|
||||
private int distance;
|
||||
private String nickName;
|
||||
private String headImgUrl;
|
||||
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(this.type);
|
||||
dest.writeValue(this.lon);
|
||||
dest.writeValue(this.lat);
|
||||
dest.writeString(this.addr);
|
||||
dest.writeValue(this.generateTime);
|
||||
dest.writeString(this.cityName);
|
||||
dest.writeTypedList(this.items);
|
||||
dest.writeInt(this.distance);
|
||||
dest.writeString(this.nickName);
|
||||
dest.writeString(this.headImgUrl);
|
||||
}
|
||||
|
||||
public Information() {
|
||||
}
|
||||
|
||||
protected Information(Parcel in) {
|
||||
this.type = in.readInt();
|
||||
this.lon = (Double) in.readValue(Double.class.getClassLoader());
|
||||
this.lat = (Double) in.readValue(Double.class.getClassLoader());
|
||||
this.addr = in.readString();
|
||||
this.generateTime = (Long) in.readValue(Long.class.getClassLoader());
|
||||
this.cityName = in.readString();
|
||||
this.items = in.createTypedArrayList(Items.CREATOR);
|
||||
this.distance = in.readInt();
|
||||
this.nickName = in.readString();
|
||||
this.headImgUrl = in.readString();
|
||||
}
|
||||
|
||||
public static final Creator<Information> CREATOR = new Creator<Information>() {
|
||||
@Override
|
||||
public Information createFromParcel(Parcel source) {
|
||||
return new Information(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Information[] newArray(int size) {
|
||||
return new Information[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.mogo.module.tanlu.model
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-11-20
|
||||
*
|
||||
* 根据范围请求情报+在线车机结果
|
||||
*/
|
||||
data class InformationAndLiveCarResult(
|
||||
var onTheWayData: Result,
|
||||
var infoMationResult: Result,
|
||||
var snResult: Sns
|
||||
) {
|
||||
fun getInformation(): Result = if (onTheWayData == null
|
||||
|| onTheWayData.informations == null
|
||||
|| onTheWayData.informations.isEmpty()
|
||||
) infoMationResult else onTheWayData
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.mogo.module.tanlu.model
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
|
||||
class Items(var url: String? = null, var thumbnail: String? = null) : Parcelable {
|
||||
constructor(parcel: Parcel) : this(
|
||||
parcel.readString(),
|
||||
parcel.readString()
|
||||
) {
|
||||
}
|
||||
|
||||
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
||||
parcel.writeString(url)
|
||||
parcel.writeString(thumbnail)
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
companion object CREATOR : Parcelable.Creator<Items> {
|
||||
override fun createFromParcel(parcel: Parcel): Items {
|
||||
return Items(parcel)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<Items?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.mogo.module.tanlu.model;
|
||||
|
||||
import com.mogo.commons.data.BaseData;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lixiaopeng
|
||||
* @description 通勤族划线
|
||||
* @since 2020-01-08
|
||||
*/
|
||||
public class PathLineResult extends BaseData {
|
||||
private List<Information> informations;
|
||||
private List<Center> pointList;
|
||||
|
||||
public List<Information> getInformations() {
|
||||
return informations;
|
||||
}
|
||||
|
||||
public void setInformations(List<Information> informations) {
|
||||
this.informations = informations;
|
||||
}
|
||||
|
||||
public List<Center> getPointList() {
|
||||
return pointList;
|
||||
}
|
||||
|
||||
public void setPointList(List<Center> pointList) {
|
||||
this.pointList = pointList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.mogo.module.tanlu.model;
|
||||
|
||||
import com.mogo.commons.data.BaseData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lixiaopeng
|
||||
* @description
|
||||
* @since 2020-01-08
|
||||
*/
|
||||
public class Result extends BaseData {
|
||||
public List<Information> informations;
|
||||
|
||||
public List<Information> getInformations() {
|
||||
return informations;
|
||||
}
|
||||
|
||||
public void setInformations(List<Information> informations) {
|
||||
this.informations = informations;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.mogo.module.tanlu.model
|
||||
|
||||
|
||||
class Sns {
|
||||
|
||||
var sns: List<CarsLive>
|
||||
var localUserId: String
|
||||
|
||||
constructor(sns: List<CarsLive>, localUserId: String) {
|
||||
this.sns = sns
|
||||
this.localUserId = localUserId
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.mogo.module.tanlu.model;
|
||||
|
||||
import com.mogo.commons.data.BaseData;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lixiaopeng
|
||||
* @description 声音控制接口
|
||||
* @since 2020-01-08
|
||||
*/
|
||||
public class VoiceSearchResult extends BaseData {
|
||||
private List<Information> informations;
|
||||
private String description;
|
||||
private Sns snResult;
|
||||
|
||||
public List<Information> getInformations() {
|
||||
return informations;
|
||||
}
|
||||
|
||||
public void setInformations(List<Information> informations) {
|
||||
this.informations = informations;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Sns getSnResult() {
|
||||
return snResult;
|
||||
}
|
||||
|
||||
public void setSnResult(Sns snResult) {
|
||||
this.snResult = snResult;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.mogo.module.tanlu.model.event;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author lixiaopeng
|
||||
* @description marker数据
|
||||
* @since 2020-01-08
|
||||
*/
|
||||
public class MarkerInfo implements Serializable {
|
||||
public int type; //封路,还是上报
|
||||
public String imageUrl;
|
||||
public Long lon; //经度
|
||||
public Long lat; //纬度
|
||||
|
||||
public MarkerInfo(int type, String imageUrl, Long lon, Long lat) {
|
||||
this.type = type;
|
||||
this.imageUrl = imageUrl;
|
||||
this.lon = lon;
|
||||
this.lat = lat;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.mogo.module.tanlu.model.event;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author lixiaopeng
|
||||
* @description marker数据
|
||||
* @since 2020-01-08
|
||||
*/
|
||||
public class VoiceRoadInfo implements Serializable {
|
||||
public String keyword;
|
||||
public String city;
|
||||
|
||||
public VoiceRoadInfo(String keyword, String city) {
|
||||
this.keyword = keyword;
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.mogo.module.tanlu.model.global
|
||||
|
||||
import com.mogo.module.tanlu.model.Information
|
||||
import java.util.ArrayList
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-02
|
||||
*
|
||||
* 共享的情报列表,避免在点击大屏查看视频时intent序列化造成的开销
|
||||
*/
|
||||
object GlobalSharedInformation {
|
||||
|
||||
var informationList: ArrayList<Information>? = null
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.mogo.module.tanlu.net;
|
||||
|
||||
import com.mogo.module.tanlu.model.InformationAndLiveCarResult;
|
||||
import com.mogo.module.tanlu.model.PathLineResult;
|
||||
import com.mogo.module.tanlu.model.VoiceSearchResult;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import retrofit2.http.FieldMap;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
/**
|
||||
* @author lixiaopeng
|
||||
* @description 探路相关接口定义
|
||||
* @since 2020-01-07
|
||||
*/
|
||||
public interface TanluApiService {
|
||||
|
||||
/**
|
||||
* 探路沿途数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@FormUrlEncoded
|
||||
@POST("deva/car/path/no/getOnTheWayDataAndSn/v1")
|
||||
Observable<InformationAndLiveCarResult> requestInformationAlongTheWay(@Query("sn") String sn, @FieldMap Map<String, String> parameters);
|
||||
|
||||
/**
|
||||
* 获取上班族路线的坐标集
|
||||
*/
|
||||
@FormUrlEncoded
|
||||
@POST("yycp-travel-condition/travelDetail/info/no/commuter/v1")
|
||||
Observable<PathLineResult> getRoadLineInfo(@FieldMap Map<String, String> infoBody);
|
||||
|
||||
|
||||
/**
|
||||
* 基于地理信息词缀的空间情报检索
|
||||
*/
|
||||
@FormUrlEncoded
|
||||
@POST("deva/car/search/no/searchInforationByAddress/v1")
|
||||
Observable<VoiceSearchResult> searchOnLineInformation(@FieldMap Map<String, String> infoBody);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.mogo.module.tanlu.receiver
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import com.mogo.module.tanlu.model.event.MarkerInfo
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
/**
|
||||
* marker数据接收
|
||||
*/
|
||||
class MarkerInfoReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
if (intent.action == "com.zhidao.roadcondition.marker.info"){
|
||||
var imageUrl = intent.getStringExtra("imageUrl")
|
||||
var lat = intent.getLongExtra("lat",0)
|
||||
var lon = intent.getLongExtra("lon",0) //经度
|
||||
Log.d("MarkerInfoReceiver", "imageUrl = $imageUrl ---->lat = $lat ---->lon = $lon")
|
||||
EventBus.getDefault().post(MarkerInfo(1, imageUrl, lon, lat))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.mogo.module.tanlu.receiver
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import com.mogo.module.tanlu.model.event.VoiceRoadInfo
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
/**
|
||||
* xx堵不堵,接收关键字,应该在哪里接收关键字请求接口?
|
||||
*/
|
||||
class RoadInfoReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
if (intent.action == "com.zhidao.roadcondition.roadinfo"){
|
||||
var keyWords = intent.getStringExtra("keywords")
|
||||
var city = intent.getStringExtra("city")
|
||||
Log.d("RoadInfoReceiver", "keyWords = $keyWords ---->city = $city")
|
||||
EventBus.getDefault().post(VoiceRoadInfo(keyWords, city))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.mogo.module.tanlu.util
|
||||
|
||||
|
||||
const val SPACE_TIME = 1000
|
||||
var lastClickTime = 0L
|
||||
var viewId: Int = 0
|
||||
|
||||
fun isDoubleClick(view: Int): Boolean {
|
||||
val time = System.currentTimeMillis()
|
||||
val timeD = time - lastClickTime
|
||||
if (timeD < SPACE_TIME && viewId == view) {
|
||||
return true
|
||||
}
|
||||
lastClickTime = time
|
||||
viewId = view
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
fun isDoubleClickTime(view: Int,spaceTime:Int): Boolean {
|
||||
val time = System.currentTimeMillis()
|
||||
val timeD = time - lastClickTime
|
||||
if (timeD < spaceTime && viewId == view) {
|
||||
return true
|
||||
}
|
||||
lastClickTime = time
|
||||
viewId = view
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.mogo.module.tanlu.util
|
||||
|
||||
import android.os.Message
|
||||
import android.view.View
|
||||
import androidx.constraintlayout.widget.Group
|
||||
|
||||
class HideControl {
|
||||
|
||||
companion object {
|
||||
const val MSG_HIDE = 0x01
|
||||
}
|
||||
|
||||
private var mHideHandler: HideHandler = HideHandler()
|
||||
var view1: Group? = null
|
||||
var view2: Group? = null
|
||||
|
||||
val hideRunable = Runnable {
|
||||
mHideHandler.obtainMessage(MSG_HIDE).sendToTarget()
|
||||
}
|
||||
|
||||
private inner class HideHandler : android.os.Handler() {
|
||||
override fun handleMessage(msg: Message) {
|
||||
super.handleMessage(msg)
|
||||
when (msg.what) {
|
||||
MSG_HIDE -> {
|
||||
view1?.let {
|
||||
it.visibility = View.GONE
|
||||
}
|
||||
view2?.let {
|
||||
it.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun startHideTimer(view1: Group,view2: Group? = null) {
|
||||
this.view1 = view1
|
||||
this.view2 = view2
|
||||
mHideHandler.removeCallbacks(hideRunable)
|
||||
if (view1.visibility == View.GONE) {
|
||||
view1.visibility = View.VISIBLE
|
||||
}
|
||||
if (view2?.visibility == View.GONE) {
|
||||
view2.visibility = View.VISIBLE
|
||||
}
|
||||
mHideHandler.postDelayed(hideRunable, 3000)
|
||||
}
|
||||
|
||||
fun resetHideTimer() {
|
||||
if(view1 != null){
|
||||
view1!!.visibility = View.VISIBLE
|
||||
}
|
||||
if(view2 != null){
|
||||
view2!!.visibility = View.VISIBLE
|
||||
}
|
||||
mHideHandler.removeCallbacks(hideRunable)
|
||||
mHideHandler.postDelayed(hideRunable, 3000)
|
||||
}
|
||||
|
||||
fun endHideTime() {
|
||||
mHideHandler.removeCallbacks(hideRunable)
|
||||
if (view1 != null) {
|
||||
view1 = null
|
||||
}
|
||||
if (view2 != null) {
|
||||
view2 = null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.mogo.module.tanlu.util
|
||||
|
||||
import android.text.format.DateFormat
|
||||
import java.text.DecimalFormat
|
||||
|
||||
const val format = "yy/MM/dd kk:mm:ss"
|
||||
|
||||
fun formatDate(time: Long): String {
|
||||
return DateFormat.format(format, time).toString()
|
||||
}
|
||||
|
||||
fun convertVar(param: Any?): Any? {
|
||||
return if (param is String) {
|
||||
"\"$param\""
|
||||
} else {
|
||||
param
|
||||
}
|
||||
}
|
||||
|
||||
//处理距离,大于1000时,四舍五入保留一位小数
|
||||
fun handleDistances(distance: Int): String {
|
||||
if (distance < 1000) {
|
||||
return distance.toString() + "M"
|
||||
} else {
|
||||
var floatDistance = distance.toFloat()
|
||||
val df = DecimalFormat("0.0")
|
||||
val transformDistance = floatDistance / 1000
|
||||
return (df.format(transformDistance)).toString() + "KM"
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.mogo.module.tanlu.util;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
/**
|
||||
* @author lixiaopeng
|
||||
* @description
|
||||
* @since 2020-01-08
|
||||
*/
|
||||
public class Utils {
|
||||
|
||||
//处理距离,大于1000时,四舍五入保留一位小数
|
||||
public static String handleDistance(long distance) {
|
||||
if (distance < 1000) {
|
||||
return distance + "M";
|
||||
} else {
|
||||
DecimalFormat df = new DecimalFormat("0.0");
|
||||
double transformDistance = distance / 1000;
|
||||
return (df.format(transformDistance)) + "KM";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
package com.mogo.module.tanlu.video
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.mogo.module.tanlu.R
|
||||
import com.mogo.module.tanlu.util.HideControl
|
||||
import com.mogo.module.tanlu.util.formatDate
|
||||
import com.mogo.utils.logger.Logger
|
||||
import com.shuyu.gsyvideoplayer.GSYVideoManager
|
||||
import com.shuyu.gsyvideoplayer.builder.GSYVideoOptionBuilder
|
||||
import kotlinx.android.synthetic.main.tanlu_activity_media_full.*
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* 全屏显示适配
|
||||
*/
|
||||
|
||||
class FullMediaActivity : AppCompatActivity(), View.OnClickListener {
|
||||
companion object {
|
||||
const val TAG = "FullMediaActivity"
|
||||
|
||||
const val PARAM_VIDEO_URL = "param_video_url"
|
||||
const val PARAM_THUMB_URL = "param_thumb_url"
|
||||
const val PARAM_ADDRESS = "param_address"
|
||||
const val PARAM_TIME = "generate_time"
|
||||
|
||||
|
||||
// fun launch(context: Activity, strategyInfo: List<Informations>, position: Int) {
|
||||
// val intent = Intent(context, FullMediaActivity::class.java)
|
||||
// intent.putExtra(PARAM_MEDIA_POSITION, position)
|
||||
// // 使用全局静态对象代替,避免序列化开销
|
||||
// GlobalSharedInformation.informationList = strategyInfo as ArrayList<Informations>
|
||||
// context.startActivityForResult(intent, REQUESTCODE_MAINACTIVITY)
|
||||
// context.overridePendingTransition(0, 0)
|
||||
// }
|
||||
|
||||
fun launch(context: Activity, videoUrl: String, thumbnail: String, address: String, generateTime: Long) {
|
||||
val intent = Intent(context, FullMediaActivity::class.java)
|
||||
intent.putExtra(PARAM_VIDEO_URL, videoUrl)
|
||||
intent.putExtra(PARAM_THUMB_URL, thumbnail)
|
||||
intent.putExtra(PARAM_ADDRESS, address)
|
||||
intent.putExtra(PARAM_TIME, generateTime)
|
||||
context.startActivity(intent)
|
||||
context.overridePendingTransition(0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private var control = HideControl()
|
||||
private var gsyVideoOptionBuilder = GSYVideoOptionBuilder()
|
||||
private var videoUrl: String? = null
|
||||
private var thumbUrl: String? = null
|
||||
private var address: String? = null
|
||||
private var generateTime: Long = 0
|
||||
|
||||
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.tanlu_activity_media_full)
|
||||
handleIntent()
|
||||
setListener()
|
||||
}
|
||||
|
||||
private fun handleIntent() {
|
||||
var intent = intent
|
||||
|
||||
videoUrl = intent.getStringExtra(PARAM_VIDEO_URL)
|
||||
thumbUrl = intent.getStringExtra(PARAM_THUMB_URL)
|
||||
address = intent.getStringExtra(PARAM_ADDRESS)
|
||||
generateTime = intent.getLongExtra(PARAM_TIME, 0)
|
||||
Logger.d("liyz", "FullMediaActivityvideoUrl = $videoUrl --->thumbUrl = $thumbUrl")
|
||||
Logger.d("liyz", "FullMediaActivity address = $address --->generateTime = $generateTime")
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
updateInformation()
|
||||
GSYVideoManager.onResume()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
GSYVideoManager.onPause()
|
||||
}
|
||||
|
||||
//需要监听完成事件
|
||||
private fun setListener() {
|
||||
iv_media_back.setOnClickListener(this)
|
||||
//重置timer
|
||||
video_view.addSingleClickListener(object :
|
||||
MediaCoverVideoPlayer.SingleClickListener {
|
||||
override fun onClick() {
|
||||
control.resetHideTimer()
|
||||
}
|
||||
})
|
||||
|
||||
//视频播放完成
|
||||
video_view.onCompletionListener(object :
|
||||
MediaCoverVideoPlayer.CompletionListener {
|
||||
override fun onCompletion() {
|
||||
GSYVideoManager.releaseAllVideos()
|
||||
finish()
|
||||
}
|
||||
})
|
||||
|
||||
video_view.loadCoverImage(thumbUrl!!)
|
||||
//设置url,点击播放
|
||||
gsyVideoOptionBuilder.setUrl(videoUrl).setCacheWithPlay(true)
|
||||
.setPlayTag(TAG).build(video_view)
|
||||
video_view.startButton.performClick()
|
||||
}
|
||||
|
||||
|
||||
private fun updateInformation() {
|
||||
tv_media_title_content.text = address
|
||||
tv_media_title_time.text = formatDate(generateTime)
|
||||
}
|
||||
|
||||
|
||||
override fun onClick(view: View) {
|
||||
view?.let {
|
||||
when (view) {
|
||||
iv_media_back -> {
|
||||
handleBack()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
GSYVideoManager.releaseAllVideos()
|
||||
overridePendingTransition(0, 0)
|
||||
}
|
||||
|
||||
private fun handleBack() {
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
super.onBackPressed()
|
||||
handleBack()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
package com.mogo.module.tanlu.video
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.mogo.module.tanlu.R
|
||||
import com.shuyu.gsyvideoplayer.GSYVideoManager
|
||||
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer
|
||||
import com.shuyu.gsyvideoplayer.video.base.GSYVideoView
|
||||
import com.shuyu.gsyvideoplayer.video.base.GSYVideoViewBridge
|
||||
|
||||
|
||||
/**
|
||||
* 全屏播放
|
||||
*/
|
||||
class MediaCoverVideoPlayer : StandardGSYVideoPlayer {
|
||||
|
||||
private lateinit var coverImage: ImageView
|
||||
private lateinit var start: ImageView
|
||||
private lateinit var fullscreen: ImageView
|
||||
private lateinit var singleClickListener: SingleClickListener
|
||||
private lateinit var completionListener: CompletionListener
|
||||
|
||||
constructor(context: Context?) : super(context)
|
||||
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
|
||||
constructor(context: Context?, fullFlag: Boolean?) : super(context, fullFlag)
|
||||
|
||||
interface SingleClickListener {
|
||||
fun onClick()
|
||||
}
|
||||
|
||||
interface CompletionListener {
|
||||
fun onCompletion()
|
||||
}
|
||||
|
||||
override fun init(context: Context) {
|
||||
super.init(context)
|
||||
coverImage = findViewById(R.id.thumbImage)
|
||||
start = findViewById(R.id.start)
|
||||
fullscreen = findViewById(R.id.fullscreen)
|
||||
if (mThumbImageViewLayout != null
|
||||
&& (mCurrentState == -1 || mCurrentState == GSYVideoView.CURRENT_STATE_NORMAL || mCurrentState == GSYVideoView.CURRENT_STATE_ERROR)
|
||||
) {
|
||||
mThumbImageViewLayout.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
fun addSingleClickListener(singleClickListener: SingleClickListener) {
|
||||
this.singleClickListener = singleClickListener
|
||||
}
|
||||
|
||||
fun onCompletionListener(completionListener: CompletionListener) {
|
||||
this.completionListener = completionListener
|
||||
}
|
||||
|
||||
override fun getLayoutId(): Int {
|
||||
return R.layout.tanlu_item_video_cover_media
|
||||
}
|
||||
|
||||
override fun getGSYVideoManager(): GSYVideoViewBridge {
|
||||
GSYVideoManager.instance().initContext(context.applicationContext)
|
||||
return GSYVideoManager.instance()
|
||||
}
|
||||
|
||||
override fun setProgressAndTime(
|
||||
progress: Int,
|
||||
secProgress: Int,
|
||||
currentTime: Int,
|
||||
totalTime: Int
|
||||
) {
|
||||
super.setProgressAndTime(progress, secProgress, currentTime, totalTime)
|
||||
if (progress != 0) {
|
||||
mProgressBar.progress = progress
|
||||
}
|
||||
}
|
||||
|
||||
fun loadCoverImage(url: String) {
|
||||
Glide.with(context)
|
||||
.load(url)
|
||||
.into(coverImage)
|
||||
}
|
||||
|
||||
override fun updateStartImage() {
|
||||
when (mCurrentState) {
|
||||
GSYVideoView.CURRENT_STATE_PLAYING -> start.setImageResource(R.drawable.selector_bg_btn_pause)
|
||||
GSYVideoView.CURRENT_STATE_ERROR -> start.setImageResource(R.mipmap.main_video_refresh_btn)
|
||||
else -> start.setImageResource(R.drawable.selector_bg_btn_play)
|
||||
}
|
||||
}
|
||||
|
||||
fun setFullClickListener(listener: OnClickListener) {
|
||||
fullscreen.setOnClickListener(listener)
|
||||
}
|
||||
|
||||
override fun onClickUiToggle() {
|
||||
super.onClickUiToggle()
|
||||
singleClickListener.let {
|
||||
it.onClick()
|
||||
}
|
||||
}
|
||||
|
||||
override fun changeUiToCompleteShow() {
|
||||
super.changeUiToCompleteShow()
|
||||
setViewShowState(mBottomContainer, View.INVISIBLE)
|
||||
}
|
||||
|
||||
override fun onAutoCompletion() {
|
||||
super.onAutoCompletion()
|
||||
mProgressBar.progress = 0
|
||||
}
|
||||
|
||||
override fun showWifiDialog() {
|
||||
//直接播放,不显示WIFI对话框
|
||||
startPlayLogic()
|
||||
}
|
||||
|
||||
override fun onClick(v: View?) {
|
||||
super.onClick(v)
|
||||
v?.let {
|
||||
when (v) {
|
||||
start -> {
|
||||
|
||||
}
|
||||
else -> {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPrepared() {
|
||||
super.onPrepared()
|
||||
}
|
||||
|
||||
/**
|
||||
* 多次回调? TODO
|
||||
*/
|
||||
override fun onCompletion() {
|
||||
Log.d("liyz", "onCompletion --------->")
|
||||
// completionListener.let {
|
||||
// it.onCompletion()
|
||||
// }
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
mFullPauseBitmap?.let {
|
||||
if (!it.isRecycled) {
|
||||
it.recycle()
|
||||
}
|
||||
}
|
||||
mFullPauseBitmap = null
|
||||
Log.d("MediaCoverVideoPlayer", "recycle.")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package com.mogo.module.tanlu.video
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.Surface
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.mogo.module.tanlu.R
|
||||
import com.shuyu.gsyvideoplayer.GSYVideoManager
|
||||
import com.shuyu.gsyvideoplayer.utils.GSYVideoType
|
||||
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer
|
||||
import com.shuyu.gsyvideoplayer.video.base.GSYVideoView
|
||||
import com.shuyu.gsyvideoplayer.video.base.GSYVideoViewBridge
|
||||
|
||||
|
||||
class SimpleCoverVideoPlayer : StandardGSYVideoPlayer {
|
||||
private lateinit var coverImage: ImageView
|
||||
private lateinit var start: ImageView
|
||||
private lateinit var fullscreen: ImageView
|
||||
|
||||
constructor(context: Context?) : super(context)
|
||||
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
|
||||
constructor(context: Context?, fullFlag: Boolean?) : super(context, fullFlag)
|
||||
|
||||
override fun init(context: Context) {
|
||||
super.init(context)
|
||||
coverImage = findViewById(R.id.thumbImage)
|
||||
start = findViewById(R.id.start)
|
||||
fullscreen = findViewById(R.id.fullscreen)
|
||||
if (mThumbImageViewLayout != null
|
||||
&& (mCurrentState == -1 || mCurrentState == GSYVideoView.CURRENT_STATE_NORMAL || mCurrentState == GSYVideoView.CURRENT_STATE_ERROR)
|
||||
) {
|
||||
mThumbImageViewLayout.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
override fun getLayoutId(): Int {
|
||||
return R.layout.tanlu_item_video_cover
|
||||
}
|
||||
|
||||
override fun getGSYVideoManager(): GSYVideoViewBridge {
|
||||
GSYVideoManager.instance().initContext(context.applicationContext)
|
||||
return GSYVideoManager.instance()
|
||||
}
|
||||
|
||||
override fun setProgressAndTime(
|
||||
progress: Int,
|
||||
secProgress: Int,
|
||||
currentTime: Int,
|
||||
totalTime: Int
|
||||
) {
|
||||
super.setProgressAndTime(progress, secProgress, currentTime, totalTime)
|
||||
if (progress != 0) {
|
||||
mProgressBar.progress = progress
|
||||
}
|
||||
}
|
||||
|
||||
// fun loadCoverImage(url: String, mContext: Context) {
|
||||
// Glide.with(mContext.applicationContext)
|
||||
// .load(url)
|
||||
// .error(R.color.color_303447)
|
||||
// .into(coverImage)
|
||||
// }
|
||||
|
||||
override fun updateStartImage() {
|
||||
when (mCurrentState) {
|
||||
GSYVideoView.CURRENT_STATE_PLAYING -> start.setImageResource(R.drawable.selector_bg_btn_pause)
|
||||
GSYVideoView.CURRENT_STATE_ERROR -> start.setImageResource(R.mipmap.main_video_refresh_btn)
|
||||
else -> start.setImageResource(R.drawable.selector_bg_btn_play)
|
||||
}
|
||||
}
|
||||
|
||||
fun setFullClickListener(listener: OnClickListener) {
|
||||
fullscreen.setOnClickListener(listener)
|
||||
}
|
||||
|
||||
override fun changeUiToCompleteShow() {
|
||||
super.changeUiToCompleteShow()
|
||||
setViewShowState(mBottomContainer, View.INVISIBLE)
|
||||
}
|
||||
|
||||
override fun onAutoCompletion() {
|
||||
super.onAutoCompletion()
|
||||
mProgressBar.progress = 0
|
||||
}
|
||||
|
||||
override fun showWifiDialog() {
|
||||
//直接播放,不显示WIFI对话框
|
||||
startPlayLogic()
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
mProgressBar.progress = 0
|
||||
mFullPauseBitmap = null
|
||||
}
|
||||
|
||||
override fun onClick(v: View?) {
|
||||
super.onClick(v)
|
||||
}
|
||||
|
||||
|
||||
override fun onPrepared() {
|
||||
super.onPrepared()
|
||||
}
|
||||
|
||||
override fun onCompletion() {
|
||||
|
||||
}
|
||||
|
||||
override fun onSurfaceUpdated(surface: Surface) {
|
||||
super.onSurfaceUpdated(surface)
|
||||
if (mThumbImageViewLayout != null && mThumbImageViewLayout.visibility == View.VISIBLE) {
|
||||
mThumbImageViewLayout.visibility = View.INVISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
override fun setViewShowState(view: View?, visibility: Int) {
|
||||
if (view === mThumbImageViewLayout && visibility != View.VISIBLE) {
|
||||
return
|
||||
}
|
||||
super.setViewShowState(view, visibility)
|
||||
}
|
||||
|
||||
override fun onSurfaceAvailable(surface: Surface) {
|
||||
super.onSurfaceAvailable(surface)
|
||||
if (GSYVideoType.getRenderType() != GSYVideoType.TEXTURE) {
|
||||
if (mThumbImageViewLayout != null && mThumbImageViewLayout.visibility == View.VISIBLE) {
|
||||
mThumbImageViewLayout.visibility = View.INVISIBLE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.mogo.module.tanlu.video
|
||||
|
||||
import com.shuyu.gsyvideoplayer.GSYVideoManager
|
||||
import com.shuyu.gsyvideoplayer.cache.CacheFactory
|
||||
import com.shuyu.gsyvideoplayer.cache.ProxyCacheManager
|
||||
import com.shuyu.gsyvideoplayer.model.VideoOptionModel
|
||||
import com.shuyu.gsyvideoplayer.player.IjkPlayerManager
|
||||
import com.shuyu.gsyvideoplayer.player.PlayerFactory
|
||||
import com.shuyu.gsyvideoplayer.utils.GSYVideoType
|
||||
import tv.danmaku.ijk.media.player.IjkMediaPlayer
|
||||
|
||||
|
||||
fun initVideo() {
|
||||
PlayerFactory.setPlayManager(IjkPlayerManager::class.java)
|
||||
CacheFactory.setCacheManager(ProxyCacheManager::class.java)
|
||||
var list = mutableListOf<VideoOptionModel>()
|
||||
list.add(VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "enable-accurate-seek", 1))
|
||||
list.add(VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "videotoolbox", 0))
|
||||
GSYVideoManager.instance().optionModelList = list
|
||||
GSYVideoType.enableMediaCodec()
|
||||
GSYVideoType.enableMediaCodecTexture()
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
package com.mogo.module.tanlu.view;
|
||||
|
||||
import com.mogo.service.imageloader.MogoImageView;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Context;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
|
||||
/**
|
||||
* @author lixiaopeng
|
||||
* @description
|
||||
* @since 2020-01-06
|
||||
*/
|
||||
public class AutoZoomInImageView extends MogoImageView {
|
||||
private int mDrawableW;
|
||||
private int mDrawableH;
|
||||
private int mImageViewW;
|
||||
private int mImageViewH;
|
||||
private long mDurationMillis = 700;
|
||||
|
||||
private float[] mValues = new float[9];
|
||||
private float mScaleDelta = 0.2f;
|
||||
|
||||
private Drawable mDrawable;
|
||||
private Matrix mMatrix;
|
||||
|
||||
public AutoZoomInImageView(Context context) {
|
||||
super(context);
|
||||
this.setScaleType(ScaleType.MATRIX);
|
||||
}
|
||||
|
||||
public AutoZoomInImageView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
this.setScaleType(ScaleType.MATRIX);
|
||||
}
|
||||
|
||||
public AutoZoomInImageView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
this.setScaleType(ScaleType.MATRIX);
|
||||
}
|
||||
|
||||
public AutoZoomInImageView init() {
|
||||
initInternalValues();
|
||||
initPicturePosition();
|
||||
return this;
|
||||
}
|
||||
|
||||
public void init(Drawable drawable) {
|
||||
initInternalValues(drawable);
|
||||
initPicturePosition();
|
||||
}
|
||||
|
||||
private void initInternalValues() {
|
||||
mDrawable = getDrawable();
|
||||
|
||||
if (mDrawable == null) {
|
||||
throw new IllegalArgumentException("please set the source of AutoZoomInImageView");
|
||||
}
|
||||
|
||||
mDrawableW = mDrawable.getIntrinsicWidth();
|
||||
mDrawableH = mDrawable.getIntrinsicHeight();
|
||||
|
||||
mImageViewW = getMeasuredWidth();
|
||||
mImageViewH = getMeasuredHeight();
|
||||
|
||||
mMatrix = getImageMatrix();
|
||||
mMatrix.getValues(mValues);
|
||||
}
|
||||
|
||||
private void initInternalValues(Drawable drawable) {
|
||||
mDrawable = drawable;
|
||||
|
||||
if (mDrawable == null) {
|
||||
throw new IllegalArgumentException("please set the source of AutoZoomInImageView");
|
||||
}
|
||||
|
||||
mDrawableW = mDrawable.getIntrinsicWidth();
|
||||
mDrawableH = mDrawable.getIntrinsicHeight();
|
||||
|
||||
mImageViewW = getMeasuredWidth();
|
||||
mImageViewH = getMeasuredHeight();
|
||||
|
||||
mMatrix = getImageMatrix();
|
||||
mMatrix.getValues(mValues);
|
||||
}
|
||||
|
||||
private void initPicturePosition() {
|
||||
updateMatrixValuesOrigin(mMatrix, mValues, mDrawableW, mDrawableH, mImageViewW, mImageViewH);
|
||||
setImageMatrix(mMatrix);
|
||||
}
|
||||
|
||||
private void startZoomInByScaleDelta(final float scaleDelta, long duration) {
|
||||
|
||||
final float oriScaleX = mValues[0];
|
||||
final float oriScaleY = mValues[4];
|
||||
|
||||
ValueAnimator va = ValueAnimator.ofFloat(0, scaleDelta);
|
||||
va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator animation) {
|
||||
float value = (Float) animation.getAnimatedValue();
|
||||
if (mOnZoomListener != null)
|
||||
mOnZoomListener.onUpdate(AutoZoomInImageView.this, value / scaleDelta);
|
||||
updateMatrixValuesSpan(mValues, mDrawableW, mDrawableH, mImageViewW, mImageViewH,
|
||||
oriScaleX, oriScaleY, value);
|
||||
mMatrix.setValues(mValues);
|
||||
setImageMatrix(mMatrix);
|
||||
}
|
||||
});
|
||||
va.addListener(new Animator.AnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
if (mOnZoomListener != null) mOnZoomListener.onStart(AutoZoomInImageView.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
if (mOnZoomListener != null) mOnZoomListener.onEnd(AutoZoomInImageView.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animation) {
|
||||
}
|
||||
});
|
||||
va.setDuration(duration);
|
||||
va.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* start zooming in
|
||||
*
|
||||
* @param scaleDelta the scale that the image will add to original scale
|
||||
* @param durationMillis the duration of zoomin animation, in millisecond.
|
||||
* @param delayMillis the delayed time of starting zoomin animation, in millisecond.
|
||||
*/
|
||||
public void startZoomInByScaleDeltaAndDuration(final float scaleDelta, final long durationMillis, long delayMillis) {
|
||||
if (scaleDelta < 0) {
|
||||
throw new IllegalArgumentException("scaleDelta should be larger than 0, now scaleDelta is " + scaleDelta);
|
||||
}
|
||||
if (durationMillis < 0) {
|
||||
throw new IllegalArgumentException("durationMillis should not be less than 0, now durationMillis is " + durationMillis);
|
||||
}
|
||||
if (delayMillis < 0) {
|
||||
throw new IllegalArgumentException("delayMillis should not be less than 0, now delayMillis is " + delayMillis);
|
||||
}
|
||||
postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startZoomInByScaleDelta(scaleDelta, durationMillis);
|
||||
}
|
||||
}, delayMillis);
|
||||
}
|
||||
|
||||
/**
|
||||
* the scale that the image will add to original scale
|
||||
*
|
||||
* @param scaleDelta
|
||||
* @return
|
||||
*/
|
||||
public AutoZoomInImageView setScaleDelta(float scaleDelta) {
|
||||
mScaleDelta = scaleDelta;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* the duration of zoomin animation, in millisecond.
|
||||
*
|
||||
* @param durationMillis
|
||||
* @return
|
||||
*/
|
||||
public AutoZoomInImageView setDurationMillis(long durationMillis) {
|
||||
mDurationMillis = durationMillis;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* callback when zoomin animation finished
|
||||
*
|
||||
* @param onZoomListener
|
||||
* @return
|
||||
*/
|
||||
public AutoZoomInImageView setOnZoomListener(OnZoomListener onZoomListener) {
|
||||
mOnZoomListener = onZoomListener;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* start animation of zoomin
|
||||
*
|
||||
* @param delayMillis the delayed time of starting zoomin animation, in millisecond.
|
||||
*/
|
||||
public void start(long delayMillis) {
|
||||
postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startZoomInByScaleDelta(mScaleDelta, mDurationMillis);
|
||||
}
|
||||
}, delayMillis);
|
||||
}
|
||||
|
||||
private void updateMatrixValuesOrigin(Matrix outMatrix, float[] outValues, float drawW, float drawH, float imageW, float imageH) {
|
||||
if (outMatrix == null || outValues == null) {
|
||||
throw new IllegalArgumentException("please set the source of AutoZoomInImageView's matrix and values");
|
||||
}
|
||||
outMatrix.reset();
|
||||
if ((imageH * drawW > drawH * imageW)) {
|
||||
float scale1 = (imageH) / (drawH);
|
||||
float offset1 = (drawW * scale1 - imageW) / 2;
|
||||
outMatrix.postScale(scale1, scale1);
|
||||
outMatrix.postTranslate(-offset1, 0);
|
||||
} else {
|
||||
float scale2 = (imageW) / (drawW);
|
||||
float offset2 = (drawH * scale2 - imageH) / 2;
|
||||
outMatrix.postScale(scale2, scale2);
|
||||
outMatrix.postTranslate(0, -offset2);
|
||||
}
|
||||
outMatrix.getValues(outValues);
|
||||
}
|
||||
|
||||
private void updateMatrixValuesSpan(float[] outValues,
|
||||
float drawW, float drawH,
|
||||
float imageW, float imageH,
|
||||
float oriScaleX, float oriScaleY,
|
||||
float scaleDelta) {
|
||||
outValues[0] = oriScaleX * (1 + scaleDelta);
|
||||
outValues[4] = oriScaleY * (1 + scaleDelta);
|
||||
float offsetwidth = (drawW * outValues[0] - imageW) / 2;
|
||||
outValues[2] = -offsetwidth;
|
||||
float offsetHeight = (drawH * outValues[4] - imageH) / 2;
|
||||
outValues[5] = -offsetHeight;
|
||||
}
|
||||
|
||||
private OnZoomListener mOnZoomListener;
|
||||
|
||||
public interface OnZoomListener {
|
||||
/**
|
||||
* callback when zoom in animation is updating
|
||||
*
|
||||
* @param view AutoZoomInImageView
|
||||
* @param progress return the progress of animation, scope is [0,1]
|
||||
*/
|
||||
void onUpdate(View view, float progress);
|
||||
|
||||
void onEnd(View view);
|
||||
|
||||
void onStart(View view);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user