diff --git a/app/build.gradle b/app/build.gradle index 6c7ed46..554a859 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -52,7 +52,6 @@ dependencies { implementation 'androidx.navigation:navigation-ui:2.1.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation files('libs\\jts-1.13.jar') - implementation files('libs\\jts-1.13.jar') testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' diff --git a/app/src/main/java/com/navinfo/outdoor/adapter/FilterAdapter.java b/app/src/main/java/com/navinfo/outdoor/adapter/FilterAdapter.java index 40adbfd..2748f84 100644 --- a/app/src/main/java/com/navinfo/outdoor/adapter/FilterAdapter.java +++ b/app/src/main/java/com/navinfo/outdoor/adapter/FilterAdapter.java @@ -12,6 +12,9 @@ import androidx.recyclerview.widget.RecyclerView; import com.navinfo.outdoor.R; import com.navinfo.outdoor.room.PoiEntity; +import java.math.RoundingMode; +import java.text.DecimalFormat; +import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; @@ -20,7 +23,7 @@ import java.util.List; */ public class FilterAdapter extends RecyclerView.Adapter { private Context context; - private List allPoi=new ArrayList<>(); + private List allPoi = new ArrayList<>(); public FilterAdapter(Context context) { this.context = context; @@ -42,32 +45,60 @@ public class FilterAdapter extends RecyclerView.Adapter infoPhoto = new ArrayList<>(); String name = editNameContent.getText().toString().trim();//名称 - if (name != null || !name.equals("")) { + if (name != null && !name.equals("")) { poiEntity.setName(name); } String site = editSiteContent.getText().toString().trim(); - if (site != null || !site.equals("")) { + if (site != null && !site.equals("")) { poiEntity.setAddress(site); } if (latLng != null) { @@ -640,30 +642,30 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. poiEntity.setY(String.valueOf(latLng.latitude)); } String describe = editDescribe.getText().toString().trim(); - if (describe != null || !describe.equals("")) { + if (describe != null && !describe.equals("")) { poiEntity.setDescribe(describe); } if (phoneData.size() > 0) { poiEntity.setTelPhone(phoneData.get(0)); } String tagPanorama = (String) ivPanorama.getTag(); - if (tagPanorama != null) { + if (tagPanorama != null&&!tagPanorama.equals("")) { infoPhoto.add(new Info(tagPanorama)); } String tagName = (String) ivName.getTag(); - if (tagName != null) { + if (tagName != null&&!tagName.equals("")) { infoPhoto.add(new Info(tagName)); } String tagInternal = (String) ivInternal.getTag(); - if (tagInternal != null) { + if (tagInternal != null&&!tagInternal.equals("")) { infoPhoto.add(new Info(tagInternal)); } String tagElse = (String) ivElse.getTag(); - if (tagElse != null) { + if (tagElse != null&&!tagElse.equals("")) { infoPhoto.add(new Info(tagElse)); } String tagScutcheon = (String) ivScutcheon.getTag(); - if (tagScutcheon != null) { + if (tagScutcheon != null&&!tagScutcheon.equals("")) { infoPhoto.add(new Info(tagScutcheon)); } poiEntity.setPhotoInfo(infoPhoto); @@ -674,7 +676,8 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. String format = formatter.format(calendar.getTime()); poiEntity.setCreateTime(format); poiEntity.setType(2); - poiEntity.setTaskStatus(0); + poiEntity.setTaskStatus(1); + poiEntity.setIsLocalData(1); new Thread(new Runnable() { @Override public void run() { @@ -713,11 +716,11 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. PoiEntity poiEntity = new PoiEntity(); List infoPhoto = new ArrayList<>(); String name = editNameContent.getText().toString().trim();//名称 - if (name != null || !name.equals("")) { + if (name != null && !name.equals("")) { poiEntity.setName(name); } String site = editSiteContent.getText().toString().trim(); - if (site != null || !site.equals("")) { + if (site != null && !site.equals("")) { poiEntity.setAddress(site); } if (latLng != null) { @@ -725,30 +728,30 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. poiEntity.setY(String.valueOf(latLng.latitude)); } String describe = editDescribe.getText().toString().trim(); - if (describe != null || !describe.equals("")) { + if (describe != null && !describe.equals("")) { poiEntity.setDescribe(describe); } if (phoneData.size() > 0) { poiEntity.setTelPhone(phoneData.get(0)); } String tagPanorama = (String) ivPanorama.getTag(); - if (tagPanorama != null) { + if (tagPanorama != null&&!tagPanorama.equals("")) { infoPhoto.add(new Info(tagPanorama)); } String tagName = (String) ivName.getTag(); - if (tagName != null) { + if (tagName != null&&!tagName.equals("")) { infoPhoto.add(new Info(tagName)); } String tagInternal = (String) ivInternal.getTag(); - if (tagInternal != null) { + if (tagInternal != null&&!tagInternal.equals("")) { infoPhoto.add(new Info(tagInternal)); } String tagElse = (String) ivElse.getTag(); - if (tagElse != null) { + if (tagElse != null&&!tagElse.equals("")) { infoPhoto.add(new Info(tagElse)); } String tagScutcheon = (String) ivScutcheon.getTag(); - if (tagScutcheon != null) { + if (tagScutcheon != null&&!tagScutcheon.equals("")) { infoPhoto.add(new Info(tagScutcheon)); } poiEntity.setPhotoInfo(infoPhoto); @@ -759,7 +762,8 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. String format = formatter.format(calendar.getTime()); poiEntity.setCreateTime(format); poiEntity.setType(2); - poiEntity.setTaskStatus(0); + poiEntity.setTaskStatus(1); + poiEntity.setIsLocalData(1); new Thread(new Runnable() { @Override public void run() { diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/FilterFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/FilterFragment.java index db36fa0..6b4cb9f 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/FilterFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/FilterFragment.java @@ -20,10 +20,18 @@ import com.navinfo.outdoor.R; import com.navinfo.outdoor.adapter.FilterAdapter; import com.navinfo.outdoor.api.Constant; import com.navinfo.outdoor.base.BaseDrawerFragment; +import com.navinfo.outdoor.bean.JobSearchBean; import com.navinfo.outdoor.room.PoiDao; import com.navinfo.outdoor.room.PoiDatabase; import com.navinfo.outdoor.room.PoiEntity; +import com.navinfo.outdoor.util.GeometryTools; +import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +import com.vividsolutions.jts.geom.Geometry; + import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; + +import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -78,7 +86,14 @@ public class FilterFragment extends BaseDrawerFragment implements View.OnClickLi }); } } + @Override + public void onStart() { + super.onStart(); + if (!EventBus.getDefault().isRegistered(this)) {//加上判断 + EventBus.getDefault().register(this); + } + } @Override public void onResume() { super.onResume(); @@ -159,15 +174,77 @@ public class FilterFragment extends BaseDrawerFragment implements View.OnClickLi }); filterAdapter.setItemCLick(new FilterAdapter.ItemCLick() { @Override - public void item(PoiEntity poiEntity) { - Message obtain = Message.obtain(); - obtain.what = Constant.FILTER_LIST_ITEM; - obtain.obj = poiEntity; - EventBus.getDefault().post(obtain); + public void item(PoiEntity poiEntity,boolean aBoolean) { + if (aBoolean){ + Message obtain = Message.obtain(); + obtain.what = Constant.GATHER_GET; + obtain.obj = poiEntity; + EventBus.getDefault().post(obtain); + }else { + Message obtain = Message.obtain(); + obtain.what = Constant.FILTER_LIST_ITEM; + obtain.obj = poiEntity; + EventBus.getDefault().post(obtain); + } + } }); } + @Subscribe + public void onEvent(Message data) { + if (data.what == Constant.JOB_SEARCH_WORD) { + /* + * id : 0 + * name : + * address : http://10.130.23.166:8080/cbt/img/blue.png + * telephone : 11 + * geo : 标题11 + * price : 通过 + * type : + * dist : + **/ + new Thread(new Runnable() { + @Override + public void run() { + List allPoi = poiDao.getAllPoi(); + + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + Log.d("TAG", "run: " + allPoi.toString()); + poiEntities.clear(); + JobSearchBean jobSearchBean = (JobSearchBean) data.obj; + List list = jobSearchBean.getBody().getList(); + for (int i = 0; i < list.size(); i++) { + PoiEntity poiEntity = new PoiEntity(); + poiEntity.setTaskId(list.get(i).getId()); + poiEntity.setName(list.get(i).getName()); + poiEntity.setAddress(list.get(i).getAddress()); + poiEntity.setTelPhone(list.get(i).getTelephone()+""); + poiEntity.setPrecision(list.get(i).getPrice()); + poiEntity.setDist(list.get(i).getDist()); + poiEntity.setType(Integer.valueOf(list.get(i).getType())); + String geo = list.get(i).getGeo(); + Geometry geometry = GeometryTools.createGeometry(geo); + if ( geometry.getGeometryType().equals("Point")){//点 + LatLng latLng = GeometryTools.createLatLng(geo); + poiEntity.setX(latLng.longitude+""); + poiEntity.setY(latLng.altitude+""); + }else if ( geometry.getGeometryType().equals("LineString")){//线 + }else if ( geometry.getGeometryType().equals("Polygon")) {//面 + + } + poiEntities.add(poiEntity); + } + poiEntities.addAll(allPoi); + filterAdapter.setAllPoi(poiEntities); + } + }); + } + }).start(); + } + } @Override @@ -186,6 +263,29 @@ public class FilterFragment extends BaseDrawerFragment implements View.OnClickLi public void run() { Log.d("TAG", "run: " + allPoi.toString()); poiEntities.clear(); + JobSearchBean jobSearchBean = (JobSearchBean) getArguments().getSerializable("body"); + List list = jobSearchBean.getBody().getList(); + for (int i = 0; i < list.size(); i++) { + PoiEntity poiEntity = new PoiEntity(); + poiEntity.setTaskId(list.get(i).getId()); + poiEntity.setName(list.get(i).getName()); + poiEntity.setAddress(list.get(i).getAddress()); + poiEntity.setTelPhone(list.get(i).getTelephone()+""); + poiEntity.setPrecision(list.get(i).getPrice()); + poiEntity.setDist(list.get(i).getDist()); + poiEntity.setType(Integer.valueOf(list.get(i).getType())); + String geo = list.get(i).getGeo(); + Geometry geometry = GeometryTools.createGeometry(geo); + if ( geometry.getGeometryType().equals("Point")){//点 + LatLng latLng = GeometryTools.createLatLng(geo); + poiEntity.setX(latLng.longitude+""); + poiEntity.setY(latLng.altitude+""); + }else if ( geometry.getGeometryType().equals("LineString")){//线 + }else if ( geometry.getGeometryType().equals("Polygon")) {//面 + + } + poiEntities.add(poiEntity); + } poiEntities.addAll(allPoi); filterAdapter.setAllPoi(poiEntities); } @@ -240,4 +340,11 @@ public class FilterFragment extends BaseDrawerFragment implements View.OnClickLi }); } } + @Override + public void onDestroy() { + if (EventBus.getDefault().isRegistered(this))//加上判断 + EventBus.getDefault().unregister(this); + super.onDestroy(); + } + } diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/GatherGetFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/GatherGetFragment.java index d778477..6175b12 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/GatherGetFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/GatherGetFragment.java @@ -23,7 +23,7 @@ import org.greenrobot.eventbus.Subscribe; public class GatherGetFragment extends BaseFragment implements View.OnClickListener { private Button btnBank; - private TextView tvTitle, tvMoney, tvTime, tvLength, tvDistance, tvDescribe; + private TextView tvTitle, tvMoney, tvTime, tvDistance, tvDescribe; private PoiEntity poiEntity; public static GatherGetFragment newInstance(Bundle bundle) { @@ -72,9 +72,8 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe tvTitle.setText(poiEntity.getName()); tvMoney.setText("3.5元"); tvTime.setText("到期时间:" + poiEntity.getCreateTime()); - tvLength.setText("长度:" + poiEntity.getDetail()); tvDescribe.setText("任务描述:" + poiEntity.getDescribe()); - tvDistance.setText("距离:" + poiEntity.getX()); + tvDistance.setText("距离:" + poiEntity.getDist()); } } @@ -89,7 +88,6 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe tvTitle = findViewById(R.id.tv_title); tvMoney = findViewById(R.id.tv_money); tvTime = findViewById(R.id.tv_time); - tvLength = findViewById(R.id.tv_length); tvDistance = findViewById(R.id.tv_distance); tvDescribe = findViewById(R.id.tv_describe); btnBank = findViewById(R.id.btn_bank); @@ -99,15 +97,12 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe if (arguments!=null) { poiEntity = (PoiEntity) arguments.getSerializable("poiEntity"); tvTitle.setText(poiEntity.getName()); - tvMoney.setText("3.5元"); + tvMoney.setText("¥"+poiEntity.getPrecision()); tvTime.setText("到期时间:" + poiEntity.getCreateTime()); - tvLength.setText("长度:" + poiEntity.getDetail()); tvDescribe.setText("任务描述:" + poiEntity.getDescribe()); - tvDistance.setText("距离:" ); + tvDistance.setText("距离:"+format5(Double.valueOf(poiEntity.getDist())/1000)+"km"); } - - } @Override @@ -126,7 +121,10 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe } } + public static String format5(double value) { + return String.format("%.2f", value).toString(); + } @Override public void onDestroy() { if (EventBus.getDefault().isRegistered(this))//加上判断 diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/OtherFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/OtherFragment.java index ec5a6ba..d041c1f 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/OtherFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/OtherFragment.java @@ -210,7 +210,7 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis showPoiEntity = (PoiEntity) getArguments().getSerializable("poiEntity"); if (showPoiEntity != null) { String name = showPoiEntity.getName();//名称 - if (name != null) { + if (name != null&&!name.equals("")) { editTaskName.setText(name + ""); } String x = showPoiEntity.getX(); @@ -221,7 +221,7 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis latLng.setLatitude(Double.parseDouble(y)); } String describe = showPoiEntity.getDescribe();//任务描述 - if (describe != null) { + if (describe != null &&!describe.equals("")) { editOtherDescribe.setText(describe); } if (showPoiEntity.getPhotoInfo() != null) { @@ -307,8 +307,9 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis calendar.setTimeInMillis(System.currentTimeMillis()); String format = formatter.format(calendar.getTime()); poiEntity.setCreateTime(format); - poiEntity.setType(3); - poiEntity.setTaskStatus(0); + poiEntity.setType(5); + poiEntity.setTaskStatus(1); + poiEntity.setIsLocalData(1); new Thread(new Runnable() { @Override public void run() { @@ -353,7 +354,7 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis PoiEntity poiEntity = new PoiEntity(); ArrayList arrayList = new ArrayList<>(); String name = editTaskName.getText().toString().trim();//名称 - if (name != null || !name.equals("")) { + if (name != null && !name.equals("")) { poiEntity.setName(name); } @@ -362,15 +363,15 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis poiEntity.setY(String.valueOf(latLng.latitude)); } String describe = editOtherDescribe.getText().toString().trim(); - if (describe != null || !describe.equals("")) { + if (describe != null && !describe.equals("")) { poiEntity.setDescribe(describe); } String tagPicture = (String) ivPicture.getTag(); - if (tagPicture != null) { + if (tagPicture != null &&!tagPicture.equals("")) { arrayList.add(new Info(tagPicture)); } String tagPictures = (String) ivPictures.getTag(); - if (tagPictures != null) { + if (tagPictures != null&&!tagPictures.equals("")) { arrayList.add(new Info(tagPictures)); } poiEntity.setPhotoInfo(arrayList); @@ -379,8 +380,9 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis calendar.setTimeInMillis(System.currentTimeMillis()); String format = formatter.format(calendar.getTime()); poiEntity.setCreateTime(format); - poiEntity.setType(3); - poiEntity.setTaskStatus(0); + poiEntity.setType(5); + poiEntity.setTaskStatus(1); + poiEntity.setIsLocalData(1); String newPoiEntity = new Gson().toJson(poiEntity); //以键值对的形式添加新值。 edit.putString("poiEntity", newPoiEntity); diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/PoiFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/PoiFragment.java index 4926728..823a343 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/PoiFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/PoiFragment.java @@ -223,11 +223,11 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe showPoiEntity = (PoiEntity) getArguments().getSerializable("poiEntity"); if (showPoiEntity != null) { String name = showPoiEntity.getName();//名称 - if (name != null) { + if (name != null && !name.equals("")) { editNameContent.setText(name + ""); } String address = showPoiEntity.getAddress();//地址 - if (address != null) { + if (address != null && !address.equals("")) { editSiteContent.setText(address); } String x = showPoiEntity.getX(); @@ -238,11 +238,11 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe latLng.setLongitude(Double.parseDouble(x)); } String describe = showPoiEntity.getDescribe();//任务描述 - if (describe != null) { + if (describe != null&&!describe.equals("")) { editDescribe.setText(describe); } String telPhone = showPoiEntity.getTelPhone(); - if (telPhone != null) { + if (telPhone != null&&!telPhone.equals("")) { phoneData.add(showPoiEntity.getTelPhone()); poiBeans.add(new PoiBean("电话*", telPhone, R.drawable.icon_add_bg)); poiRecycleAdapter.setList(poiBeans); @@ -390,8 +390,9 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe calendar.setTimeInMillis(System.currentTimeMillis()); String format = formatter.format(calendar.getTime()); poiEntity.setCreateTime(format); - poiEntity.setType(0); - poiEntity.setTaskStatus(0); + poiEntity.setType(1); + poiEntity.setTaskStatus(1); + poiEntity.setIsLocalData(1); new Thread(new Runnable() { @Override public void run() { @@ -470,11 +471,11 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe PoiEntity poiEntity = new PoiEntity(); ArrayList infoPhoto = new ArrayList<>(); String name = editNameContent.getText().toString().trim();//名称 - if (name != null || !name.equals("")) { + if (name != null && !name.equals("")) { poiEntity.setName(name); } String site = editSiteContent.getText().toString().trim(); - if (site != null || !site.equals("")) { + if (site != null && !site.equals("")) { poiEntity.setAddress(site); } if (latLng != null) { @@ -482,30 +483,30 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe poiEntity.setY(String.valueOf(latLng.latitude)); } String describe = editDescribe.getText().toString().trim(); - if (describe!= null || !describe.equals("")) { + if (describe!= null && !describe.equals("")) { poiEntity.setDescribe(describe); } if (phoneData.size() > 0) { poiEntity.setTelPhone(phoneData.get(0)); } String tagPanorama = (String) ivPanorama.getTag(); - if (tagPanorama!=null) { + if (tagPanorama!=null&&!tagPanorama.equals("")) { infoPhoto.add(new Info(tagPanorama)); } String tagName = (String) ivName.getTag(); - if (tagName!= null) { + if (tagName!= null&&!tagName.equals("")) { infoPhoto.add(new Info(tagName)); } String tagInternal = (String) ivInternal.getTag(); - if (tagInternal!= null) { + if (tagInternal!= null&&!tagInternal.equals("")) { infoPhoto.add(new Info(tagInternal)); } String tagElse = (String) ivElse.getTag(); - if (tagElse!=null) { + if (tagElse!=null&&!tagElse.equals("")) { infoPhoto.add(new Info(tagElse)); } String tagCard = (String) ivCard.getTag(); - if (tagCard != null) { + if (tagCard != null&&!tagCard.equals("")) { infoPhoto.add(new Info(tagCard)); } poiEntity.setPhotoInfo(infoPhoto); @@ -514,8 +515,9 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe calendar.setTimeInMillis(System.currentTimeMillis()); String format = formatter.format(calendar.getTime()); poiEntity.setCreateTime(format); - poiEntity.setType(0); - poiEntity.setTaskStatus(0); + poiEntity.setType(1); + poiEntity.setTaskStatus(1); + poiEntity.setIsLocalData(1); String newPoiEntity = new Gson().toJson(poiEntity); //以键值对的形式添加新值。 edit.putString("poiEntity", newPoiEntity); diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/PoiVideoFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/PoiVideoFragment.java index 6108c74..bc52a62 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/PoiVideoFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/PoiVideoFragment.java @@ -134,17 +134,17 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick showPoiEntity = (PoiEntity) getArguments().getSerializable("poiEntity"); if (showPoiEntity != null) { String name = showPoiEntity.getName();//名称 - if (name != null || !name.equals("")) { + if (name != null && !name.equals("")) { etRoadName.setText(name + ""); } String extend = showPoiEntity.getExtend(); - if (extend!=null||!extend.equals("")){ + if (extend!=null&&!extend.equals("")){ RoadExtend roadExtend = new Gson().fromJson(extend, RoadExtend.class); int type= roadExtend.getType(); showPictureType(type); } String describe = showPoiEntity.getDescribe();//任务描述 - if (describe != null || !describe.equals("")) { + if (describe != null && !describe.equals("")) { etDesc.setText(describe); } } @@ -225,6 +225,9 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick calendar.setTimeInMillis(System.currentTimeMillis()); String format = formatter.format(calendar.getTime()); poiEntity.setCreateTime(format); + poiEntity.setType(3); + poiEntity.setTaskStatus(1); + poiEntity.setIsLocalData(1); new Thread(new Runnable() { @Override public void run() { @@ -278,7 +281,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick PoiEntity poiEntity = new PoiEntity(); String roadName = etRoadName.getText().toString().trim(); - if (roadName != null || !roadName.equals("")) { + if (roadName != null && !roadName.equals("")) { poiEntity.setName(roadName); } RoadExtend roadExtend = new RoadExtend(); @@ -290,7 +293,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick poiEntity.setExtend(roadExtendJson); } String desc = etDesc.getText().toString().trim(); - if (desc != null || !desc.equals("")) { + if (desc != null && !desc.equals("")) { poiEntity.setDescribe(desc); } DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @@ -298,7 +301,9 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick calendar.setTimeInMillis(System.currentTimeMillis()); String format = formatter.format(calendar.getTime()); poiEntity.setCreateTime(format); - poiEntity.setType(4); + poiEntity.setType(3); + poiEntity.setTaskStatus(1); + poiEntity.setIsLocalData(1); String newPoiEntity = new Gson().toJson(poiEntity); //以键值对的形式添加新值。 edit.putString("poiEntity", newPoiEntity); diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/RoadFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/RoadFragment.java index b277059..a2ea7aa 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/RoadFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/RoadFragment.java @@ -139,17 +139,17 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList showPoiEntity = (PoiEntity) getArguments().getSerializable("poiEntity"); if (showPoiEntity != null) { String name = showPoiEntity.getName();//名称 - if (name != null || !name.equals("")) { + if (name != null && !name.equals("")) { etRoadName.setText(name + ""); } String extend = showPoiEntity.getExtend(); - if (extend!=null||!extend.equals("")){ + if (extend!=null&& !extend.equals("")){ RoadExtend roadExtend = new Gson().fromJson(extend, RoadExtend.class); int type= roadExtend.getType(); showPictureType(type); } String describe = showPoiEntity.getDescribe();//任务描述 - if (describe != null || !describe.equals("")) { + if (describe != null && !describe.equals("")) { etDesc.setText(describe); } } @@ -231,7 +231,9 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList calendar.setTimeInMillis(System.currentTimeMillis()); String format = formatter.format(calendar.getTime()); poiEntity.setCreateTime(format); - poiEntity.setType(1); + poiEntity.setType(4); + poiEntity.setTaskStatus(1); + poiEntity.setIsLocalData(1); new Thread(new Runnable() { @Override public void run() { @@ -286,7 +288,7 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList PoiEntity poiEntity = new PoiEntity(); String roadName = etRoadName.getText().toString().trim(); - if (roadName != null || !roadName.equals("")) { + if (roadName != null && !roadName.equals("")) { poiEntity.setName(roadName); } RoadExtend roadExtend = new RoadExtend(); @@ -298,7 +300,7 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList poiEntity.setExtend(roadExtendJson); } String desc = etDesc.getText().toString().trim(); - if (desc != null || !desc.equals("")) { + if (desc != null && !desc.equals("")) { poiEntity.setDescribe(desc); } DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @@ -306,7 +308,9 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList calendar.setTimeInMillis(System.currentTimeMillis()); String format = formatter.format(calendar.getTime()); poiEntity.setCreateTime(format); - poiEntity.setType(1); + poiEntity.setType(4); + poiEntity.setTaskStatus(1); + poiEntity.setIsLocalData(1); String newPoiEntity = new Gson().toJson(poiEntity); //以键值对的形式添加新值。 edit.putString("poiEntity", newPoiEntity); diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/TreasureFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/TreasureFragment.java index f038da3..1d1289e 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/TreasureFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/TreasureFragment.java @@ -89,6 +89,8 @@ import org.greenrobot.eventbus.Subscribe; import java.util.ArrayList; import java.util.List; +import okhttp3.OkHttpClient; + /** * 寻宝的Fragment * 2021-5-25 @@ -120,6 +122,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen private ChargingPileEntity chargingPileEntity; private String userEncode; private String centerEncode; + private JobSearchBean body; public static TreasureFragment newInstance(Bundle bundle) { TreasureFragment fragment = new TreasureFragment(); @@ -181,6 +184,8 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen tencentMap.setMapStyle(2); //启用3d视图 tencentMap.setBuilding3dEffectEnable(true); + + tencentMap.setOnCameraChangeListener(cameraChangeListener); //获取地图UI 设置对象 UiSettings uiSettings = tencentMap.getUiSettings(); //设置logo的大小 @@ -191,21 +196,41 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen initSharePre(); //数据库 initThread(); - - } + private TencentMap.OnCameraChangeListener cameraChangeListener = new TencentMap.OnCameraChangeListener() { + @Override + public void onCameraChange(CameraPosition cameraPosition) { // 地图移动中 + + } + + @Override + public void onCameraChangeFinished(CameraPosition cameraPosition) { // 地图移动结束 + if (Constant.currentLocation != null) { + initList(Constant.currentLocation); + } + } + }; + private void initList(TencentLocation tencentLocation) { //获取中心点位置 LatLng mapCenterPoint = getMapCenterPoint(); ArrayList removables = new ArrayList<>(); + if (removables.size() != 0) { + for (int i = 0; i < removables.size(); i++) { + removables.get(i).remove(); + } + removables.clear(); + } if (mapCenterPoint != null) { centerEncode = Geohash.getInstance().encode(mapCenterPoint.latitude, mapCenterPoint.longitude); } - userEncode = Geohash.getInstance().encode(tencentLocation.getLatitude(),tencentLocation.getLongitude()); + userEncode = Geohash.getInstance().encode(tencentLocation.getLatitude(), tencentLocation.getLongitude()); long date = System.currentTimeMillis(); +// showLoadingDialog(); + OkGo.getInstance().cancelTag(this); // 请求方式和请求url OkGo.get(HttpInterface.TASK_LIST) .tag(this) @@ -215,66 +240,100 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen .params("date", date) .params("pageSize", Constant.NUMBER) .params("pageNum", "1") +// .client(new OkHttpClient()) .execute(new DialogCallback(JobSearchBean.class) { @Override public void onSuccess(Response response) { + dismissLoadingDialog(); + body = response.body(); Log.d("TAG", "onSuccess: " + response.body().toString() + "sssssssssssss"); - if (removables.size() > 0) { + if (removables.size() != 0) { for (int i = 0; i < removables.size(); i++) { removables.get(i).remove(); } removables.clear(); - } - List list = response.body().getBody().getList(); - for (int i = 0; i < list.size(); i++) { - String geo = list.get(i).getGeo(); - Log.d("TAG", "onSuccess: " + geo); - Geometry geometry = GeometryTools.createGeometry(geo); - if ( geometry.getGeometryType().equals("Point")){//点 - LatLng latLng = GeometryTools.createLatLng(geo); - BitmapDescriptor custom = BitmapDescriptorFactory.fromResource(R.drawable.marker_road); - Marker marker = tencentMap.addMarker(new MarkerOptions(latLng)); - marker.setClickable(true); - removables.add(marker); + } else { + List list = response.body().getBody().getList(); + for (int i = 0; i < list.size(); i++) { + String geo = list.get(i).getGeo(); + Log.d("TAG", "onSuccess: " + geo); + Geometry geometry = GeometryTools.createGeometry(geo); + if (geometry.getGeometryType().equals("Point")) {//点 + LatLng latLng = GeometryTools.createLatLng(geo); + switch (Integer.valueOf(list.get(i).getType())) { + case 1://poi + Marker poiMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(Constant.POI_ICON).alpha(0.5f) + .flat(true) + .clockwise(false)); + removables.add(poiMarker); - }else if ( geometry.getGeometryType().equals("LineString")){//线 - List latLineString= GeometryTools.getLatLngs(geo); - // 构造 PolylineOpitons - PolylineOptions polylineOptions = new PolylineOptions() - .addAll(latLineString) - // 折线设置圆形线头 - .lineCap(true) - // 折线的颜色为绿色 - .color(0xff00ff00) - // 折线宽度为5像素 - .width(5) - // 还可以添加描边颜色 - .borderColor(0xffff0000) - // 描边颜色的宽度,线宽还是 25 像素,不过填充的部分宽度为 `width` - 2 * `borderWidth` - .borderWidth(1); - // 绘制折线 - Polyline polyline = tencentMap.addPolyline(polylineOptions); - removables.add(polyline); - }else if ( geometry.getGeometryType().equals("Polygon")){//面 - List latPolygon = GeometryTools.getLatLngs(geo); - Polygon polygon = tencentMap.addPolygon(new PolygonOptions(). - //连接封闭图形的点 - addAll(latPolygon). - //填充颜色为红色 - fillColor(Color.parseColor("#97E0E7EC")). - //边线颜色为黑色 - strokeColor(0xff000000). - //边线宽度15像素 - strokeWidth(5)); - removables.add(polygon); + break; + case 2://充电站 + Marker stationMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(Constant.STATION_ICON).alpha(0.7f) + .flat(true) + .clockwise(false)); + removables.add(stationMarker); + break; + case 3://poi录像 + break; + case 4://道路录像 + Marker roadMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(Constant.ROAD_ICON).alpha(0.7f) + .flat(true) + .clockwise(false)); + removables.add(roadMarker); + break; + case 5://其他 + break; + case 6://面状任务 + Marker planarMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(Constant.PLANAR_TASK_ICON).alpha(0.7f) + .flat(true) + .clockwise(false)); + removables.add(planarMarker); + break; + } + } else if (geometry.getGeometryType().equals("LineString")) {//线 + List latLineString = GeometryTools.getLatLngs(geo); + // 构造 PolylineOpitons + PolylineOptions polylineOptions = new PolylineOptions() + .addAll(latLineString) + // 折线设置圆形线头 + .lineCap(true) + // 折线的颜色为绿色 + .color(0xff00ff00) + // 折线宽度为5像素 + .width(5) + // 还可以添加描边颜色 + .borderColor(0xffff0000) + // 描边颜色的宽度,线宽还是 25 像素,不过填充的部分宽度为 `width` - 2 * `borderWidth` + .borderWidth(1); + // 绘制折线 + Polyline polyline = tencentMap.addPolyline(polylineOptions); + removables.add(polyline); + } else if (geometry.getGeometryType().equals("Polygon")) {//面 + List latPolygon = GeometryTools.getLatLngs(geo); + Polygon polygon = tencentMap.addPolygon(new PolygonOptions(). + //连接封闭图形的点 + addAll(latPolygon). + //填充颜色为红色 + fillColor(Color.parseColor("#97E0E7EC")). + //边线颜色为黑色 + strokeColor(0xff000000). + //边线宽度15像素 + strokeWidth(5)); + removables.add(polygon); + } } - } + Message obtain = Message.obtain(); + obtain.what = Constant.JOB_SEARCH_WORD; + obtain.obj = body; + EventBus.getDefault().post(obtain); } @Override public void onError(Response response) { super.onError(response); + dismissLoadingDialog(); Log.d("TAG", "onError: " + response.message()); } }); @@ -421,8 +480,10 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen public void onEvent(Message data) { if (data.what == Constant.FILTER_LIST_ITEM) { // 点击筛选的item PoiEntity poiEntity = (PoiEntity) data.obj; - LatLng position = new LatLng(Double.valueOf(poiEntity.getY()), Double.valueOf(poiEntity.getX())); - tencentMap.addMarker(new MarkerOptions(position)); + if (poiEntity.getX() != null && poiEntity.getY() != null) { + LatLng position = new LatLng(Double.valueOf(poiEntity.getY()), Double.valueOf(poiEntity.getX())); + tencentMap.addMarker(new MarkerOptions(position)); + } sliding_layout.setPanelHeight(0); sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.HIDDEN); frameLayout.setVisibility(View.VISIBLE); @@ -437,26 +498,30 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen Bundle bundle = new Bundle(); bundle.putBoolean("isSliding", false); // 通知抽屉不收回 bundle.putSerializable("poiEntity", poiEntity); - frameLayout.setVisibility(View.GONE); - fragmentTransaction.remove(gatherGetFragment); switch (poiEntity.getType()) { - case 0: + case 1: PoiFragment poiFragment = PoiFragment.newInstance(bundle); showSlidingFragment(poiFragment); break; - case 1: - RoadFragment roadFragment = RoadFragment.newInstance(bundle); - showSlidingFragment(roadFragment); - break; case 2: ChargingStationFragment chargingStationFragment = ChargingStationFragment.newInstance(bundle); showSlidingFragment(chargingStationFragment); break; case 3: + PoiVideoFragment poiVideoFragment = PoiVideoFragment.newInstance(bundle); + showSlidingFragment(poiVideoFragment); + break; + case 4: + RoadFragment roadFragment = RoadFragment.newInstance(bundle); + showSlidingFragment(roadFragment); + break; + case 5: OtherFragment otherFragment = OtherFragment.newInstance(bundle); showSlidingFragment(otherFragment); break; } + frameLayout.setVisibility(View.GONE); + fragmentTransaction.remove(gatherGetFragment); } else if (data.what == Constant.FILTER_LIST) { // 筛选列表所有数据地图显示 List poiEntities = (List) data.obj; initFilterMarker(poiEntities); @@ -493,6 +558,8 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED); } else { setMainButtonVisiable(View.VISIBLE); + frameLayout.setVisibility(View.GONE); + fragmentTransaction.remove(gatherGetFragment); } } else if (data.what == Constant.CHARGING_STATION) {//充电站的充电桩 Bundle bundle = new Bundle(); @@ -731,13 +798,19 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen }).setTitle(title); break; case R.id.iv_filter: - FilterFragment filterFragment = FilterFragment.newInstance(new Bundle()); + Bundle bundle = new Bundle(); + if (body != null) { + bundle.putSerializable("body", body); + } + FilterFragment filterFragment = FilterFragment.newInstance(bundle); showSlidingFragment(filterFragment); break; case R.id.iv_message: + Intent messageIntent = new Intent(getContext(), FragmentManagement.class); messageIntent.putExtra("tag", 35); startActivity(messageIntent); + break; } } @@ -879,9 +952,6 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen location.setAccuracy(tencentLocation.getAccuracy()); locationChangedListener.onLocationChanged(location); locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER); - if (Constant.currentLocation == null) { - initList(tencentLocation); - } Constant.currentLocation = tencentLocation; Constant.markerCurrentLocation = tencentLocation; Constant.markerLatitude = tencentLocation.getLatitude(); diff --git a/app/src/main/java/com/navinfo/outdoor/room/PoiEntity.java b/app/src/main/java/com/navinfo/outdoor/room/PoiEntity.java index 585b369..7ead847 100644 --- a/app/src/main/java/com/navinfo/outdoor/room/PoiEntity.java +++ b/app/src/main/java/com/navinfo/outdoor/room/PoiEntity.java @@ -26,7 +26,7 @@ public class PoiEntity implements Serializable { private String address;//地址 private String telPhone;//电话 private String memo;//备注 - private double precision;//金额 + private String precision;//金额 private String photo;//照片信息 private String extend;//添加字段 private boolean checked; @@ -54,9 +54,27 @@ public class PoiEntity implements Serializable { private String x;//经度 private String y;//纬度 private String detail;//深度信息 - private int taskStatus;//任务状态 0.待提交,1.已提交,2 已领取 - private int type;//0.poi,1.道路,2.充电站,3.其他 ,4,poi录像 - private int station_type;//0.全部,1.poi,2.道路,3.充电站,4.其他 + private String dist;//距离用户位置 + private int taskStatus;//任务状态 1.待提交,2.已提交,3已领取 + private int type;//1 "POI"2 "充电站"3 "POI录像"4 "道路录像"5 "其他"6 "面状任务" + private int station_type;//1 "POI"2 "充电站"3 "POI录像"4 "道路录像"5 "其他"6 "面状任务" + private int isLocalData;//是否是本地数据 0,服务 1,本地 + + public int getIsLocalData() { + return isLocalData; + } + + public void setIsLocalData(int isLocalData) { + this.isLocalData = isLocalData; + } + + public String getDist() { + return dist; + } + + public void setDist(String dist) { + this.dist = dist; + } public int getStation_type() { return station_type; @@ -162,11 +180,11 @@ public class PoiEntity implements Serializable { this.memo = memo; } - public double getPrecision() { + public String getPrecision() { return precision; } - public void setPrecision(double precision) { + public void setPrecision(String precision) { this.precision = precision; } diff --git a/app/src/main/res/drawable/planar_task_icon.jpg b/app/src/main/res/drawable/planar_task_icon.jpg new file mode 100644 index 0000000..e5e5900 Binary files /dev/null and b/app/src/main/res/drawable/planar_task_icon.jpg differ diff --git a/app/src/main/res/drawable/poi_icons.png b/app/src/main/res/drawable/poi_icons.png new file mode 100644 index 0000000..5650df1 Binary files /dev/null and b/app/src/main/res/drawable/poi_icons.png differ diff --git a/app/src/main/res/drawable/road_icon.png b/app/src/main/res/drawable/road_icon.png new file mode 100644 index 0000000..059c295 Binary files /dev/null and b/app/src/main/res/drawable/road_icon.png differ diff --git a/app/src/main/res/drawable/station_icon.jpg b/app/src/main/res/drawable/station_icon.jpg new file mode 100644 index 0000000..659125c Binary files /dev/null and b/app/src/main/res/drawable/station_icon.jpg differ diff --git a/app/src/main/res/layout/fragment_gather_get.xml b/app/src/main/res/layout/fragment_gather_get.xml index bde6e3a..58347fa 100644 --- a/app/src/main/res/layout/fragment_gather_get.xml +++ b/app/src/main/res/layout/fragment_gather_get.xml @@ -41,29 +41,26 @@ app:layout_constraintStart_toStartOf="@+id/tv_title" app:layout_constraintTop_toBottomOf="@+id/tv_title" /> - - + app:layout_constraintTop_toTopOf="@+id/tv_describe" /> + app:layout_constraintTop_toTopOf="@+id/tv_time" /> -