New file |
| | |
| | | <svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#1890FF"><rect fill="none" height="24" width="24"/><path d="M12,2L12,2C8.13,2,5,5.13,5,9c0,1.74,0.5,3.37,1.41,4.84c0.95,1.54,2.2,2.86,3.16,4.4c0.47,0.75,0.81,1.45,1.17,2.26 C11,21.05,11.21,22,12,22h0c0.79,0,1-0.95,1.25-1.5c0.37-0.81,0.7-1.51,1.17-2.26c0.96-1.53,2.21-2.85,3.16-4.4 C18.5,12.37,19,10.74,19,9C19,5.13,15.87,2,12,2z M12,11.75c-1.38,0-2.5-1.12-2.5-2.5s1.12-2.5,2.5-2.5s2.5,1.12,2.5,2.5 S13.38,11.75,12,11.75z"/></svg> |
| | |
| | | const locationIMGPath = 'img/location.png'; |
| | | const markerBalckPath = 'img/marker_black.svg'; |
| | | const markerRedPath = 'img/marker_red.svg'; |
| | | |
| | | const markerBluePath = 'img/marker_blue.svg'; |
| | | let map; |
| | | let lastMarker = null; |
| | | let lastClickedMarker = null; |
| | | let isShowWaterIntakeDetail = false; |
| | | let zoom=12; |
| | | let zoom = 12; |
| | | |
| | | |
| | | document.addEventListener('DOMContentLoaded', function () { |
| | |
| | | mountMethodToWindow(); |
| | | |
| | | }); |
| | | window.onload = function() { |
| | | //加载坐标点 |
| | | window.onload = function () { |
| | | //加载坐标点 |
| | | window.Android.loadMarker(); |
| | | }; |
| | | // 初始化地图 |
| | |
| | | |
| | | for (let i = 0; i < data_info.length; i++) { |
| | | let icon = new T.Icon({ |
| | | iconUrl: markerBalckPath, |
| | | iconUrl: markerBluePath, |
| | | iconSize: new T.Point(27, 27), |
| | | iconAnchor: new T.Point(10, 25) |
| | | }); |
| | |
| | | |
| | | // 手机获取到定位后显示定位 |
| | | function locationOverLay(lng, lag) { |
| | | console.log("function》》》》》locationOverLay"); |
| | | map.centerAndZoom(new T.LngLat(lng, lag), 18); |
| | | |
| | | let icon = new T.Icon({ |
| | |
| | | map.addOverLay(marker); |
| | | } |
| | | |
| | | |
| | | //设置地图中心点 |
| | | function setCenterAndZoom(lng, lat) { |
| | | console.log("function》》》》》setCenterAndZoom>>>>lng:" + lng + ",lat:" + lat); |
| | | map.centerAndZoom(new T.LngLat(lng, lat), zoom); |
| | | } |
| | | |
| | | |
| | | // 将方法挂载到 window 上 |
| | | function mountMethodToWindow() { |
| | | window.locationOverLay = locationOverLay; |
| | | window.showToast = showToast; |
| | | window.addMarker = addMarker; |
| | | window.setCenterAndZoom = setCenterAndZoom; |
| | | } |
| | | |
| | | // 调用原生安卓方法显示取水口详情 |
| | |
| | | |
| | | // 调用原生安卓方法隐藏取水口详情 |
| | | function closeWaterIntakeDetail(data) { |
| | | if (lastClickedMarker!== null) { |
| | | if (lastClickedMarker !== null) { |
| | | // 如果有点击取水口则将取水口恢复成黑色 |
| | | // 上次点击的标注改为黑色 |
| | | var defaulticon = new T.Icon({ |
| | | iconUrl: markerBalckPath, |
| | | iconSize: new T.Point(27, 27), |
| | | iconAnchor: new T.Point(10, 25) |
| | | iconUrl: markerBluePath, |
| | | iconSize: new T.Point(27, 27), |
| | | iconAnchor: new T.Point(10, 25) |
| | | }); |
| | | lastClickedMarker.setIcon(defaulticon); |
| | | } |
| | | if (isShowWaterIntakeDetail) { |
| | | } |
| | | if (isShowWaterIntakeDetail) { |
| | | // 假如显示了取水口详情则隐藏取水口详情 |
| | | isShowWaterIntakeDetail = false; |
| | | window.Android.closeWaterIntakeView(); |
| | | } else { |
| | | } else { |
| | | // 假如没有显示取水口则添加点击的坐标 |
| | | getLngLat(data.lnglat); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 点击标注的事件 |
| | |
| | | |
| | | // 修改点击标注的图标 |
| | | function chageMarkerIcon(data) { |
| | | // 点击的标注改为红色 |
| | | var currentMarker = data.target; |
| | | // 点击后图标 |
| | | var clickedIcon = new T.Icon({ |
| | | iconUrl: markerRedPath, |
| | | iconSize: new T.Point(27, 27), |
| | | iconAnchor: new T.Point(10, 25) |
| | | }); |
| | | // 设置当前点击的 marker 为点击后图标 |
| | | currentMarker.setIcon(clickedIcon); |
| | | // 判断点击的不是同一个坐标 |
| | | if (lastClickedMarker!== null) { |
| | | if (!isEqualsLngLat(data.target.getLngLat(), lastClickedMarker.getLngLat())) { |
| | | var defaulticon = new T.Icon({ |
| | | iconUrl: markerBalckPath, |
| | | iconSize: new T.Point(27, 27), |
| | | iconAnchor: new T.Point(10, 25) |
| | | }); |
| | | lastClickedMarker.setIcon(defaulticon); |
| | | } |
| | | } |
| | | lastClickedMarker = data.target; |
| | | // 点击的标注改为红色 |
| | | var currentMarker = data.target; |
| | | // 点击后图标 |
| | | var clickedIcon = new T.Icon({ |
| | | iconUrl: markerRedPath, |
| | | iconSize: new T.Point(27, 27), |
| | | iconAnchor: new T.Point(10, 25) |
| | | }); |
| | | // 设置当前点击的 marker 为点击后图标 |
| | | currentMarker.setIcon(clickedIcon); |
| | | // 判断点击的不是同一个坐标 |
| | | if (lastClickedMarker !== null) { |
| | | if (!isEqualsLngLat(data.target.getLngLat(), lastClickedMarker.getLngLat())) { |
| | | var defaulticon = new T.Icon({ |
| | | iconUrl: markerBluePath, |
| | | iconSize: new T.Point(27, 27), |
| | | iconAnchor: new T.Point(10, 25) |
| | | }); |
| | | lastClickedMarker.setIcon(defaulticon); |
| | | } |
| | | } |
| | | lastClickedMarker = data.target; |
| | | } |
| | | //调安卓原生 |
| | | function showToast() { |
| | |
| | | console.log("function》》》》》addMarker"); |
| | | var array = JSON.parse(jsonData); |
| | | var icon = new T.Icon({ |
| | | iconUrl: markerBalckPath, |
| | | iconUrl: markerBluePath, |
| | | iconSize: new T.Point(27, 27), |
| | | iconAnchor: new T.Point(10, 25) |
| | | }); |
| | |
| | | addMarkerListener(data) |
| | | }); |
| | | map.addOverLay(marker); // 将标注添加到地图中 |
| | | let label = new T.Label({ |
| | | text: element[2], |
| | | position: marker.getLngLat(), |
| | | offset: new T.Point(-35, 8), // 设置标注文字的位置 |
| | | opacity: 1, // 设置文本的显示不透明度(范围0-1) |
| | | }); |
| | | label.setBorderLine(0); // 设置文本的边框线宽 |
| | | label.setBackgroundColor("transparent"); // 设置文本的背景色(透明色) |
| | | label.setFontColor("#0000FF"); |
| | | label.setFontSize(10); |
| | | map.addOverLay(label); |
| | | }); |
| | | return "addMarker加载成功" |
| | | } |
| | |
| | | import com.dayu.pipirrapp.utils.CommonData; |
| | | import com.dayu.pipirrapp.utils.SharedPreferencesHelper; |
| | | import com.dayu.pipirrapp.utils.ToastUtil; |
| | | import com.dayu.pipirrapp.view.TagDialog; |
| | | import com.tencent.bugly.crashreport.CrashReport; |
| | | |
| | | import java.util.HashMap; |
| | |
| | | |
| | | |
| | | private void initData() { |
| | | |
| | | |
| | | } |
| | | |
New file |
| | |
| | | package com.dayu.pipirrapp.bean.db; |
| | | |
| | | import androidx.room.Entity; |
| | | import androidx.room.PrimaryKey; |
| | | |
| | | /** |
| | | * author: zuo |
| | | * Date: 2024-09-20 |
| | | * Time: 14:56 |
| | | * 备注: |
| | | */ |
| | | @Entity |
| | | public class MarkerBean { |
| | | @PrimaryKey(autoGenerate = true) |
| | | public long id; |
| | | |
| | | String blockId; |
| | | String deleted;//逻辑删除标识 |
| | | String divideId;//string |
| | | String lat;//经度 |
| | | String lng;//纬度 |
| | | String name;//取水口名称 |
| | | String operateDt;//操作时间 |
| | | String operator;//操作人编号 |
| | | String remarks;//备注 |
| | | String townId;//所在镇编号 |
| | | String villageId;//所在村编号 |
| | | String countyId;//所在县编号 |
| | | |
| | | public String getBlockId() { |
| | | return blockId; |
| | | } |
| | | |
| | | public void setBlockId(String blockId) { |
| | | this.blockId = blockId; |
| | | } |
| | | |
| | | public String getDeleted() { |
| | | return deleted; |
| | | } |
| | | |
| | | public void setDeleted(String deleted) { |
| | | this.deleted = deleted; |
| | | } |
| | | |
| | | public String getDivideId() { |
| | | return divideId; |
| | | } |
| | | |
| | | public void setDivideId(String divideId) { |
| | | this.divideId = divideId; |
| | | } |
| | | |
| | | |
| | | public String getLat() { |
| | | return lat; |
| | | } |
| | | |
| | | public void setLat(String lat) { |
| | | this.lat = lat; |
| | | } |
| | | |
| | | public String getLng() { |
| | | return lng; |
| | | } |
| | | |
| | | public void setLng(String lng) { |
| | | this.lng = lng; |
| | | } |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | public String getOperateDt() { |
| | | return operateDt; |
| | | } |
| | | |
| | | public void setOperateDt(String operateDt) { |
| | | this.operateDt = operateDt; |
| | | } |
| | | |
| | | public String getOperator() { |
| | | return operator; |
| | | } |
| | | |
| | | public void setOperator(String operator) { |
| | | this.operator = operator; |
| | | } |
| | | |
| | | public String getRemarks() { |
| | | return remarks; |
| | | } |
| | | |
| | | public void setRemarks(String remarks) { |
| | | this.remarks = remarks; |
| | | } |
| | | |
| | | public String getTownId() { |
| | | return townId; |
| | | } |
| | | |
| | | public void setTownId(String townId) { |
| | | this.townId = townId; |
| | | } |
| | | |
| | | public String getVillageId() { |
| | | return villageId; |
| | | } |
| | | |
| | | public void setVillageId(String villageId) { |
| | | this.villageId = villageId; |
| | | } |
| | | |
| | | public String getCountyId() { |
| | | return countyId; |
| | | } |
| | | |
| | | public void setCountyId(String countyId) { |
| | | this.countyId = countyId; |
| | | } |
| | | } |
New file |
| | |
| | | package com.dayu.pipirrapp.bean.net; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * author; zuo |
| | | * Date; 2024-09-20 |
| | | * Time; 14;12 |
| | | * 备注: |
| | | */ |
| | | public class MarkerResult extends BaseResult { |
| | | int itemTotal; |
| | | int pageCurr; |
| | | int pageSize; |
| | | int pageTotal; |
| | | List<Obj> obj; |
| | | |
| | | public int getItemTotal() { |
| | | return itemTotal; |
| | | } |
| | | |
| | | public void setItemTotal(int itemTotal) { |
| | | this.itemTotal = itemTotal; |
| | | } |
| | | |
| | | public int getPageCurr() { |
| | | return pageCurr; |
| | | } |
| | | |
| | | public void setPageCurr(int pageCurr) { |
| | | this.pageCurr = pageCurr; |
| | | } |
| | | |
| | | public int getPageSize() { |
| | | return pageSize; |
| | | } |
| | | |
| | | public void setPageSize(int pageSize) { |
| | | this.pageSize = pageSize; |
| | | } |
| | | |
| | | public int getPageTotal() { |
| | | return pageTotal; |
| | | } |
| | | |
| | | public void setPageTotal(int pageTotal) { |
| | | this.pageTotal = pageTotal; |
| | | } |
| | | |
| | | public List<Obj> getObj() { |
| | | return obj; |
| | | } |
| | | |
| | | public void setObj(List<Obj> obj) { |
| | | this.obj = obj; |
| | | } |
| | | |
| | | public class Obj { |
| | | String blockId; |
| | | |
| | | String deleted;//逻辑删除标识 |
| | | String divideId;//string |
| | | |
| | | String id; |
| | | String lat;//经度 |
| | | String lng;//纬度 |
| | | |
| | | String name;//取水口名称 |
| | | |
| | | String operateDt;//操作时间 |
| | | String operator;//操作人编号 |
| | | String remarks;//备注 |
| | | String townId;//所在镇编号 |
| | | String villageId;//所在村编号 |
| | | String countyId;//所在县编号 |
| | | |
| | | public String getBlockId() { |
| | | return blockId; |
| | | } |
| | | |
| | | public void setBlockId(String blockId) { |
| | | this.blockId = blockId; |
| | | } |
| | | |
| | | public String getDeleted() { |
| | | return deleted; |
| | | } |
| | | |
| | | public void setDeleted(String deleted) { |
| | | this.deleted = deleted; |
| | | } |
| | | |
| | | public String getDivideId() { |
| | | return divideId; |
| | | } |
| | | |
| | | public void setDivideId(String divideId) { |
| | | this.divideId = divideId; |
| | | } |
| | | |
| | | public String getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(String id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getLat() { |
| | | return lat; |
| | | } |
| | | |
| | | public void setLat(String lat) { |
| | | this.lat = lat; |
| | | } |
| | | |
| | | public String getLng() { |
| | | return lng; |
| | | } |
| | | |
| | | public void setLng(String lng) { |
| | | this.lng = lng; |
| | | } |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | public String getOperateDt() { |
| | | return operateDt; |
| | | } |
| | | |
| | | public void setOperateDt(String operateDt) { |
| | | this.operateDt = operateDt; |
| | | } |
| | | |
| | | public String getOperator() { |
| | | return operator; |
| | | } |
| | | |
| | | public void setOperator(String operator) { |
| | | this.operator = operator; |
| | | } |
| | | |
| | | public String getRemarks() { |
| | | return remarks; |
| | | } |
| | | |
| | | public void setRemarks(String remarks) { |
| | | this.remarks = remarks; |
| | | } |
| | | |
| | | public String getTownId() { |
| | | return townId; |
| | | } |
| | | |
| | | public void setTownId(String townId) { |
| | | this.townId = townId; |
| | | } |
| | | |
| | | public String getVillageId() { |
| | | return villageId; |
| | | } |
| | | |
| | | public void setVillageId(String villageId) { |
| | | this.villageId = villageId; |
| | | } |
| | | |
| | | public String getCountyId() { |
| | | return countyId; |
| | | } |
| | | |
| | | public void setCountyId(String countyId) { |
| | | this.countyId = countyId; |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.annotation.Nullable; |
| | | |
| | | import com.dayu.pipirrapp.MyApplication; |
| | | import com.dayu.pipirrapp.bean.db.CenterPointBean; |
| | | import com.dayu.pipirrapp.bean.net.CenterPointResult; |
| | | import com.dayu.pipirrapp.bean.net.MarkerResult; |
| | | import com.dayu.pipirrapp.dao.DaoSingleton; |
| | | import com.dayu.pipirrapp.databinding.FragmentMapBinding; |
| | | import com.dayu.pipirrapp.js.MyWebViewInterface; |
| | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileNotFoundException; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.Random; |
| | | |
| | | /** |
| | |
| | | |
| | | WebView mWebView; |
| | | CenterPointBean centerPointBean; |
| | | String jsonData; |
| | | |
| | | @Override |
| | | public void onAttach(@NonNull Context context) { |
| | |
| | | mWebView.loadUrl("file:///android_asset/index.html"); |
| | | getCenterPoint(); |
| | | initView(); |
| | | initData(); |
| | | getMarkerData(); |
| | | //开启定位 |
| | | // Intent location = new Intent(this.getActivity(), MyLocationService.class); |
| | | // location.putExtra("isSingle", false); |
| | |
| | | } |
| | | |
| | | private void initData() { |
| | | centerPointBean = DaoSingleton.getInstance(MapFragment.this.getContext()).centerPointDao().findFirst(); |
| | | if (centerPointBean!=null){ |
| | | jumpCenterPoint(); |
| | | } |
| | | |
| | | /** |
| | | * 跳转地图中心点 |
| | | */ |
| | | public void jumpCenterPoint() { |
| | | |
| | | centerPointBean = DaoSingleton.getInstance(MapFragment.this.getContext()).centerPointDao().findFirst(); |
| | | if (centerPointBean != null) { |
| | | Log.d(TAG, "jumpCenterPoint>>>>>>>>>>>>>>>>>>>" + centerPointBean.getLng() + "\",\"" + centerPointBean.getLat()); |
| | | mWebView.evaluateJavascript("javascript:setCenterAndZoom(\"" + centerPointBean.getLng() + "\",\"" + centerPointBean.getLat() + "\")", value -> { |
| | | }); |
| | | } |
| | | } |
| | | |
| | | public void setMapMarker(){ |
| | | Log.i("mWebView", "addMarker????????????" + jsonData); |
| | | mWebView.evaluateJavascript("javascript:addMarker(\"" + jsonData + "\")", new ValueCallback<String>() { |
| | | @Override |
| | | public void onReceiveValue(String value) { |
| | | Log.i("mWebView", "addMarker!!!!!!!!!" + value); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | |
| | | private void getMarkerData() { |
| | | ApiManager.getInstance().requestGet(this.getContext(), Constants.BASE_URL + ":8085/project/intake/all", MarkerResult.class, null, new SubscriberListener<BaseResponse<MarkerResult>>() { |
| | | @Override |
| | | public void onNext(BaseResponse<MarkerResult> t) { |
| | | if (t.isSuccess()) { |
| | | if (t.isSuccess()) { |
| | | if (t.getContent().getObj() != null && !t.getContent().getObj().isEmpty()) { |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | stringBuilder.append("["); |
| | | for (int i = 0; i < t.getContent().getObj().size(); i++) { |
| | | stringBuilder.append("["); |
| | | stringBuilder.append(t.getContent().getObj().get(i).getLng()); |
| | | stringBuilder.append(","); |
| | | stringBuilder.append(t.getContent().getObj().get(i).getLat()); |
| | | stringBuilder.append(",\"" + t.getContent().getObj().get(i).getName() + "\"]"); |
| | | if (i != t.getContent().getObj().size() - 1) { |
| | | stringBuilder.append(","); |
| | | } |
| | | } |
| | | stringBuilder.append("]"); |
| | | jsonData = stringBuilder.toString().replace("\\", "\\\\").replace("\"", "\\\""); |
| | | |
| | | } |
| | | } |
| | | } else { |
| | | ToastUtil.showToast(MapFragment.this.getContext(), t.getMsg()); |
| | | } |
| | | } |
| | | |
| | | }); |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | stringBuilder.append("[116.417854,39.921988,\"235取水口\"]]"); |
| | | String jsonData = stringBuilder.toString().replace("\\", "\\\\").replace("\"", "\\\""); |
| | | // String jsonData = "[[116.417854,39.921988,\"235取水口\"],[116.406605,39.921585,\"237取水口\"],[116.412222,39.912345,\"236取水口\"]]"; |
| | | Log.i("mWebView", "addMarker????????????" + jsonData); |
| | | mWebView.evaluateJavascript("javascript:addMarker(\"" + jsonData + "\")", new ValueCallback<String>() { |
| | | @Override |
| | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void onResume() { |
| | |
| | | * 获取地图中心点 |
| | | */ |
| | | private void getCenterPoint() { |
| | | Map<String, Object> data = new HashMap<>(); |
| | | data.put("token", MyApplication.myApplication.token); |
| | | |
| | | ApiManager.getInstance().requestGet(this.getContext(), Constants.SUCCESS + "8080/base/dict_item/map_center", CenterPointResult.class, data, new SubscriberListener<BaseResponse<CenterPointResult>>() { |
| | | ApiManager.getInstance().requestGet(this.getContext(), Constants.BASE_URL + ":8080/base/dict_item/map_center", CenterPointResult.class, null, new SubscriberListener<BaseResponse<CenterPointResult>>() { |
| | | @Override |
| | | public void onNext(BaseResponse<CenterPointResult> t) { |
| | | if (t.isSuccess()) { |
| | |
| | | } |
| | | centerPointBean.setLat(t.getContent().getLat()); |
| | | centerPointBean.setLng(t.getContent().getLng()); |
| | | DaoSingleton.getInstance(MapFragment.this.getContext()).centerPointDao().update(centerPointBean); |
| | | DaoSingleton.getInstance(MapFragment.this.getContext()).centerPointDao().insert(centerPointBean); |
| | | jumpCenterPoint(); |
| | | } else { |
| | | ToastUtil.showToast(MapFragment.this.getContext(), t.getMsg()); |
| | | } |
| | |
| | | |
| | | /** |
| | | * 显示取水口详情 |
| | | * |
| | | * @param data |
| | | */ |
| | | @JavascriptInterface |
| | |
| | | |
| | | /** |
| | | * 隐藏取水口详情 |
| | | * |
| | | */ |
| | | @JavascriptInterface |
| | | public void closeWaterIntakeView() { |
| | |
| | | } |
| | | |
| | | @JavascriptInterface |
| | | public void loadMarker(){ |
| | | public void loadMarker() { |
| | | if (myContext instanceof MapFragment) { |
| | | new Handler(Looper.getMainLooper()).post(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | // 在主线程上执行UI操作 |
| | | // 更新或操作UI元素的代码 |
| | | myContext.addMarker(); |
| | | // myContext.addMarker(); |
| | | myContext.jumpCenterPoint(); |
| | | myContext.setMapMarker(); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | package com.dayu.pipirrapp.net; |
| | | |
| | | import android.content.Context; |
| | | import android.net.ConnectivityManager; |
| | | import android.net.NetworkCapabilities; |
| | | import android.net.NetworkInfo; |
| | | import android.os.Build; |
| | | import android.util.Log; |
| | | |
| | | import com.dayu.pipirrapp.MyApplication; |
| | | import com.dayu.pipirrapp.bean.net.CodeResult; |
| | | import com.dayu.pipirrapp.bean.net.WeatherResponse; |
| | | import com.dayu.pipirrapp.net.subscribers.BaseProgressSubscriber; |
| | |
| | | |
| | | if (isGet) { |
| | | if (params == null) { |
| | | observable = apiService.requestGet(path); |
| | | observable = apiService.requestGet(path, MyApplication.myApplication.token); |
| | | } else { |
| | | |
| | | observable = apiService.requestGet(path, params); |
| | | observable = apiService.requestGet(path, params, MyApplication.myApplication.token); |
| | | } |
| | | } else { |
| | | observable = apiService.requestPost(path, params); |
| | |
| | | |
| | | /** |
| | | * 获取验证码 |
| | | * |
| | | * @param params |
| | | * @param listener |
| | | * @param <T> |
| | | */ |
| | | public <T> void getCode( Map<String, Object> params, CodeListener listener) { |
| | | Observable observable; |
| | | observable = apiService.getCode(params); |
| | | observable.subscribeOn(Schedulers.io()) |
| | | .unsubscribeOn(Schedulers.newThread()) |
| | | .observeOn(AndroidSchedulers.mainThread()) |
| | | .subscribe(responseBody -> { |
| | | listener.onNext((CodeResult) responseBody); |
| | | }, throwable -> { |
| | | listener.error((Throwable) throwable); |
| | | }); |
| | | public <T> void getCode(Map<String, Object> params, CodeListener listener) { |
| | | if (isNetworkAvailable(MyApplication.myApplication)) { |
| | | Observable observable; |
| | | observable = apiService.getCode(params); |
| | | observable.subscribeOn(Schedulers.io()) |
| | | .unsubscribeOn(Schedulers.newThread()) |
| | | .observeOn(AndroidSchedulers.mainThread()) |
| | | .subscribe(responseBody -> { |
| | | listener.onNext((CodeResult) responseBody); |
| | | }, throwable -> { |
| | | listener.error((Throwable) throwable); |
| | | }); |
| | | } else { |
| | | listener.onNext(null); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 判断当前是否有网络 |
| | | * |
| | | * @param context |
| | | * @return |
| | | */ |
| | | public boolean isNetworkAvailable(Context context) { |
| | | ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); |
| | | |
| | | if (connectivityManager != null) { |
| | | // 对于 Android 版本大于等于 Android Q (API level 29) |
| | | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { |
| | | NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(connectivityManager.getActiveNetwork()); |
| | | if (capabilities != null) { |
| | | // 检查网络是否有传输能力(包括 Wi-Fi 和移动数据) |
| | | if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) || capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) { |
| | | return true; |
| | | } |
| | | } |
| | | } else { |
| | | // 对于 Android Q 以下版本 |
| | | NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); |
| | | if (activeNetworkInfo != null && activeNetworkInfo.isConnected()) { |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return false; // 无网络连接 |
| | | } |
| | | |
| | | } |
| | |
| | | import retrofit2.Call; |
| | | import retrofit2.http.Body; |
| | | import retrofit2.http.GET; |
| | | import retrofit2.http.Header; |
| | | import retrofit2.http.Multipart; |
| | | import retrofit2.http.POST; |
| | | import retrofit2.http.Part; |
| | | import retrofit2.http.PartMap; |
| | | import retrofit2.http.Path; |
| | | import retrofit2.http.QueryMap; |
| | | import retrofit2.http.Streaming; |
| | | import retrofit2.http.Url; |
| | |
| | | @POST() |
| | | Observable<BaseResponse> requestPost(@Url String url, @Body Map<String, Object> params); |
| | | |
| | | @GET("{url}") |
| | | Observable<BaseResponse> requestGet(@Path("url") String url, @QueryMap Map<String, Object> params); |
| | | @GET() |
| | | Observable<BaseResponse> requestGet(@Url String url, @QueryMap Map<String, Object> params,@Header("token") String token); |
| | | |
| | | @GET("{url}") |
| | | Observable<BaseResponse> requestGet(@Path("url") String url); |
| | | @GET() |
| | | Observable<BaseResponse> requestGet(@Url String url); |
| | | |
| | | @GET() |
| | | Observable<BaseResponse> requestGet(@Url String url, @Header("token") String token); |
| | | |
| | | @Streaming |
| | | @GET() |
| | |
| | | builder.addHeader("os", "app"); |
| | | builder.addHeader("Authorization", SharedPreferencesHelper.getInstance(MyApplication.myApplication).get("token", "")); |
| | | } |
| | | builder.addHeader("tag", CommonData.Tag); |
| | | builder.addHeader("tag", MyApplication.myApplication.myTag); |
| | | return builder.build(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | public static String androidKey = "4dace6fd6dad43a9bc08d1ed94ec28d8"; |
| | | |
| | | //缓存 |
| | | |
| | | public static String Tag = "ym"; |
| | | public final static String Token = "Token"; |
| | | public final static String isShowCode="isShowCode"; |
| | | |
| | |
| | | import android.widget.TextView; |
| | | |
| | | |
| | | import com.dayu.pipirrapp.MyApplication; |
| | | import com.dayu.pipirrapp.R; |
| | | import com.dayu.pipirrapp.bean.db.TagBean; |
| | | import com.dayu.pipirrapp.dao.DaoSingleton; |
| | |
| | | // 当选中的RadioButton发生变化时调用 |
| | | if (checkedId == R.id.testLibrary) { |
| | | type = CommonData.TestTag; |
| | | tagBean.setTag("ym"); |
| | | tagBean.setTag("test"); |
| | | data = "确认选择测试版本吗?"; |
| | | } else if (checkedId == R.id.yuanmouLibrary) {// 处理选中Option 2的逻辑 |
| | | type = CommonData.YuanMouTag; |
| | |
| | | confirmDialog = new ConfirmDialog(mContext, data, new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | MyApplication.myApplication.myTag = tagBean.getTag(); |
| | | tagDao.insert(tagBean); |
| | | mLibraryBack.listener(type); |
| | | TagDialog.this.dismiss(); |