|
|
@@ -1,4 +1,4 @@
|
|
|
-package com.silence.commonframe.activity;
|
|
|
+package com.silence.commonframe.activity.site.activity;
|
|
|
|
|
|
import android.Manifest;
|
|
|
import android.app.AlertDialog;
|
|
|
@@ -7,20 +7,17 @@ import android.content.Intent;
|
|
|
import android.content.pm.PackageManager;
|
|
|
import android.graphics.BitmapFactory;
|
|
|
import android.graphics.Color;
|
|
|
+import android.location.Geocoder;
|
|
|
import android.net.Uri;
|
|
|
-import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
import android.provider.Settings;
|
|
|
import android.support.v4.app.ActivityCompat;
|
|
|
import android.support.v4.content.ContextCompat;
|
|
|
-import android.support.v7.app.AppCompatActivity;
|
|
|
import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
|
import android.view.View;
|
|
|
-import android.view.Window;
|
|
|
import android.view.WindowManager;
|
|
|
import android.widget.EditText;
|
|
|
-import android.widget.ImageView;
|
|
|
import android.widget.ScrollView;
|
|
|
import android.widget.TextView;
|
|
|
import android.widget.Toast;
|
|
|
@@ -30,15 +27,19 @@ import com.amap.api.location.AMapLocationClient;
|
|
|
import com.amap.api.location.AMapLocationClientOption;
|
|
|
import com.amap.api.location.AMapLocationListener;
|
|
|
import com.amap.api.maps.AMap;
|
|
|
+import com.amap.api.maps.CameraUpdate;
|
|
|
import com.amap.api.maps.CameraUpdateFactory;
|
|
|
+import com.amap.api.maps.CoordinateConverter;
|
|
|
import com.amap.api.maps.LocationSource;
|
|
|
import com.amap.api.maps.MapView;
|
|
|
import com.amap.api.maps.model.BitmapDescriptorFactory;
|
|
|
+import com.amap.api.maps.model.CameraPosition;
|
|
|
import com.amap.api.maps.model.Circle;
|
|
|
import com.amap.api.maps.model.CircleOptions;
|
|
|
import com.amap.api.maps.model.LatLng;
|
|
|
import com.amap.api.maps.model.Marker;
|
|
|
import com.amap.api.maps.model.MarkerOptions;
|
|
|
+import com.amap.api.maps.model.Poi;
|
|
|
import com.lzy.okgo.OkGo;
|
|
|
import com.lzy.okgo.cache.CacheMode;
|
|
|
import com.lzy.okgo.callback.StringCallback;
|
|
|
@@ -47,9 +48,11 @@ import com.silence.commonframe.ApiService;
|
|
|
import com.silence.commonframe.Dialog.CDialog;
|
|
|
import com.silence.commonframe.R;
|
|
|
import com.silence.commonframe.activity.mine.activity.AddlinkmanActivity;
|
|
|
+import com.silence.commonframe.activity.site.Interface.AddSiteListener;
|
|
|
+import com.silence.commonframe.activity.site.presenter.AddSitePresenter;
|
|
|
+import com.silence.commonframe.base.basemvp.BaseActivity;
|
|
|
import com.silence.commonframe.bean.IsDeviceChange;
|
|
|
import com.silence.commonframe.common.constant.BaseConstants;
|
|
|
-import com.silence.commonframe.utils.AtyContainer;
|
|
|
import com.silence.commonframe.utils.Data;
|
|
|
import com.silence.commonframe.utils.LoginIn;
|
|
|
import com.silence.commonframe.utils.SensorEventHelper;
|
|
|
@@ -62,19 +65,12 @@ import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
|
|
|
-
|
|
|
import butterknife.BindView;
|
|
|
-import butterknife.ButterKnife;
|
|
|
import okhttp3.Call;
|
|
|
import okhttp3.Response;
|
|
|
|
|
|
@SuppressWarnings("ALL")
|
|
|
-public class AddSiteActivity extends AppCompatActivity implements LocationSource,
|
|
|
- AMapLocationListener {
|
|
|
- @BindView(R.id.imageView3)
|
|
|
- ImageView imageView3;
|
|
|
- @BindView(R.id.textView_comfirm)
|
|
|
- TextView textViewComfirm;
|
|
|
+public class AddSiteActivity extends BaseActivity implements LocationSource, AMapLocationListener, AddSiteListener.View {
|
|
|
// @BindView(R.id.map)
|
|
|
// MapView map;
|
|
|
@BindView(R.id.edit_site)
|
|
|
@@ -115,6 +111,7 @@ public class AddSiteActivity extends AppCompatActivity implements LocationSource
|
|
|
private String place1 = "";
|
|
|
private String Latitude = "";
|
|
|
private String Longitude = "";
|
|
|
+ private String regionCode = "";
|
|
|
|
|
|
private AMapLocationClient locationClientSingle = null;
|
|
|
private String data1;
|
|
|
@@ -134,19 +131,38 @@ public class AddSiteActivity extends AppCompatActivity implements LocationSource
|
|
|
|
|
|
private boolean isNeedCheck = true;
|
|
|
|
|
|
+ AddSitePresenter presenter;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getLayoutId() {
|
|
|
+ return R.layout.activity_add_site;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initPresenter() {
|
|
|
+ presenter = new AddSitePresenter(this,this);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
- protected void onCreate(Bundle savedInstanceState) {
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
- setContentView(R.layout.activity_add_site);
|
|
|
- ButterKnife.bind(this);
|
|
|
- AtyContainer.getInstance().addActivity(this);
|
|
|
+ public void initView() {
|
|
|
+ clickTitle(this,"添加场所",getResources().getString(R.string.confirm),true)
|
|
|
+ .setRightClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (TextUtils.isEmpty(editSite.getText().toString().trim())) {
|
|
|
+ Toast.makeText(AddSiteActivity.this, "场所名称不能为空", Toast.LENGTH_SHORT).show();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ presenter.addSite();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ setResult(2);
|
|
|
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);//防止输入被挡
|
|
|
mapView = (MapView) findViewById(R.id.map);
|
|
|
- mapView.onCreate(savedInstanceState);// 此方法必须重写
|
|
|
+ mapView.onCreate(getSavedInstanceState());// 此方法必须重写
|
|
|
mapContainer.setScrollView(scrollView);
|
|
|
init();
|
|
|
startSingleLocation();
|
|
|
- initWindows();
|
|
|
tvPeople.setText(Hawk.get(BaseConstants.USER_NAME)+"");
|
|
|
tvPhoto.setText(Hawk.get(BaseConstants.PHONE)+"");
|
|
|
|
|
|
@@ -154,19 +170,6 @@ public class AddSiteActivity extends AppCompatActivity implements LocationSource
|
|
|
// editSite.setText(place);
|
|
|
}
|
|
|
|
|
|
- private void initWindows() {
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
- Window window = getWindow();
|
|
|
- window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
|
|
|
- | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
|
|
|
- window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
|
|
- | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
|
|
- window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
|
|
- window.setStatusBarColor(Color.TRANSPARENT);
|
|
|
- window.setNavigationBarColor(Color.BLACK);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private void init() {
|
|
|
if (aMap == null) {
|
|
|
aMap = mapView.getMap();
|
|
|
@@ -255,8 +258,6 @@ public class AddSiteActivity extends AppCompatActivity implements LocationSource
|
|
|
*/
|
|
|
private void showMissingPermissionDialog() {
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
-// builder.setTitle(R.string.notifyTitle);
|
|
|
-// builder.setMessage(R.string.notifyMsg);
|
|
|
// 拒绝, 退出应用
|
|
|
builder.setNegativeButton("退出",
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
@@ -361,32 +362,42 @@ public class AddSiteActivity extends AppCompatActivity implements LocationSource
|
|
|
// } else {
|
|
|
// sb.append(Utils.getLocationStr(location));
|
|
|
// }
|
|
|
-
|
|
|
- if (null == location) {
|
|
|
- Toast.makeText(AddSiteActivity.this, "定位失败!", Toast.LENGTH_SHORT).show();
|
|
|
- } else {
|
|
|
- place = location.getAddress();
|
|
|
- place1 = location.getDistrict();
|
|
|
- Latitude = String.valueOf(location.getLatitude());
|
|
|
- Longitude = String.valueOf(location.getLongitude());
|
|
|
- runOnUiThread(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- // editSite.setText(place);
|
|
|
- textViewSite1.setText(place1);
|
|
|
- editDetailedsite.setText(place);
|
|
|
- }
|
|
|
- });
|
|
|
+ if (null != location) {
|
|
|
+ if (location.getErrorCode() == 0){
|
|
|
+// LatLng latLng = new LatLng(location.getLatitude(),location.getLongitude());
|
|
|
+// if (mLocMarker == null){
|
|
|
+// addCircle(latLng, location.getAccuracy());//添加定位精度圆
|
|
|
+// addMarker(latLng);
|
|
|
+// mSensorHelper.setCurrentMarker(mLocMarker);//定位图标旋转
|
|
|
+//// mLocMarker = aMap.addMarker(new MarkerOptions().position(latLng).draggable(true).setFlat(true));
|
|
|
+// mLocMarker.showInfoWindow();
|
|
|
+// mLocMarker.setPositionByPixels(mapView.getWidth() / 2,mapView.getHeight() / 2);
|
|
|
+// }else {
|
|
|
+// mCircle.setCenter(latLng);
|
|
|
+// mCircle.setRadius(location.getAccuracy());
|
|
|
+// mLocMarker.setPosition(latLng);
|
|
|
+// }
|
|
|
+// aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng,18));//参数:1.经纬度 2.缩放级别
|
|
|
+//
|
|
|
+// LatLng latLngPoint = mLocMarker.getOptions().getPosition();
|
|
|
+
|
|
|
+ place = location.getAddress();
|
|
|
+ place1 = location.getDistrict();
|
|
|
+ Latitude = String.valueOf(location.getLatitude());
|
|
|
+ Longitude = String.valueOf(location.getLongitude());
|
|
|
+ regionCode = location.getAdCode();
|
|
|
+
|
|
|
+ textViewSite1.setText(place1);
|
|
|
+ editDetailedsite.setText(place);
|
|
|
+ }else {
|
|
|
+ Toast.makeText(AddSiteActivity.this, "定位失败!", Toast.LENGTH_SHORT).show();
|
|
|
+ mLocationErrText.setText(location.describeContents());//textViewSite1
|
|
|
+ }
|
|
|
}
|
|
|
- mLocationErrText.setText(location.describeContents());//textViewSite1
|
|
|
- // textViewSite1.setText(location.describeContents());
|
|
|
+
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-// public void click(View view) {
|
|
|
-// startSingleLocation();
|
|
|
-// }
|
|
|
-
|
|
|
/**
|
|
|
* 方法必须重写
|
|
|
*/
|
|
|
@@ -427,12 +438,12 @@ public class AddSiteActivity extends AppCompatActivity implements LocationSource
|
|
|
addCircle(location, amapLocation.getAccuracy());//添加定位精度圆
|
|
|
addMarker(location);//添加定位图标
|
|
|
mSensorHelper.setCurrentMarker(mLocMarker);//定位图标旋转
|
|
|
- aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(location, 18));
|
|
|
+ aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(location,18));//参数:1.经纬度 2.缩放级别
|
|
|
} else {
|
|
|
mCircle.setCenter(location);
|
|
|
mCircle.setRadius(amapLocation.getAccuracy());
|
|
|
mLocMarker.setPosition(location);
|
|
|
- aMap.moveCamera(CameraUpdateFactory.changeLatLng(location));
|
|
|
+ aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(location,18));//参数:1.经纬度 2.缩放级别
|
|
|
}
|
|
|
} else {
|
|
|
String errText = "定位失败," + amapLocation.getErrorCode() + ": " + amapLocation.getErrorInfo();
|
|
|
@@ -499,23 +510,10 @@ public class AddSiteActivity extends AppCompatActivity implements LocationSource
|
|
|
options.anchor(0.5f, 0.5f);
|
|
|
options.position(latlng);
|
|
|
mLocMarker = aMap.addMarker(options);
|
|
|
- mLocMarker.setTitle(LOCATION_MARKER_FLAG);
|
|
|
- }
|
|
|
-
|
|
|
- public void click(View view) {
|
|
|
- setResult(2);
|
|
|
- finish();
|
|
|
- }
|
|
|
-
|
|
|
- public void click1(View view) {
|
|
|
- getdata();
|
|
|
}
|
|
|
|
|
|
- private void getdata1() {
|
|
|
+ private void showLinkManDialog() {
|
|
|
CDialog.Builder builder = new CDialog.Builder(this);
|
|
|
- // AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getContext(), R.style.dialog));
|
|
|
- //builder.setIcon(R.drawable.ic_launcher);
|
|
|
-// builder.setTitle("你确定要退出系统吗?");
|
|
|
|
|
|
builder.setCancelable(false);
|
|
|
builder.setTitle("提示");
|
|
|
@@ -540,94 +538,52 @@ public class AddSiteActivity extends AppCompatActivity implements LocationSource
|
|
|
builder.show();
|
|
|
}
|
|
|
|
|
|
- private void getdata() {
|
|
|
-//editSite
|
|
|
- if (TextUtils.isEmpty(editSite.getText().toString().trim())) {
|
|
|
- Toast.makeText(this, "场所名称不能为空", Toast.LENGTH_SHORT).show();
|
|
|
- return;
|
|
|
- }
|
|
|
- HashMap<String, String> params = new HashMap<>();
|
|
|
- params.put("deployment", editSite.getText().toString().trim());//场所名称
|
|
|
-// params.put("userid", Data.getUserid());
|
|
|
- params.put("regionName", textViewSite1.getText().toString());//区域名称
|
|
|
- params.put("location", editDetailedsite.getText().toString());// 详细地址
|
|
|
- params.put("longtitude", Longitude);
|
|
|
- params.put("regionCode", "123456");
|
|
|
- params.put("latitude", Latitude);
|
|
|
-
|
|
|
-// params.put("phone", "13333311338");
|
|
|
- JSONObject jsonObject = new JSONObject(params);
|
|
|
- String s = Data.getToken();
|
|
|
- Log.v("Tag", s);
|
|
|
- String str = jsonObject.toString();
|
|
|
- OkGo.post(ApiService.httpUrl1 + Data.getConfigUrl() + "/addSite")
|
|
|
- .tag(this)
|
|
|
- .cacheKey("cachePostRegister11")
|
|
|
- .cacheMode(CacheMode.DEFAULT)
|
|
|
- .upJson(jsonObject.toString())
|
|
|
-
|
|
|
- .headers("token", Data.getToken())
|
|
|
-// .params("format", "json")
|
|
|
-// .params("albumId", "Lqfme5hSolM")
|
|
|
-// .params("pageNo", "1")
|
|
|
-// .params("pageSize", "2")
|
|
|
- .execute(new StringCallback() {
|
|
|
- @Override
|
|
|
- public void onSuccess(String s, Call call, Response response) {
|
|
|
- // mTextView2.setText(s);
|
|
|
- // System.out.println("sss"+response);
|
|
|
+ @Override
|
|
|
+ public String getDeployment() {
|
|
|
+ //场所名称
|
|
|
+ return editSite.getText().toString().trim();
|
|
|
+ }
|
|
|
|
|
|
-// SiteInfo siteInfo = new Gson().fromJson(s, SiteInfo.class);
|
|
|
-// if(siteInfo.getMessage().equals("ok")) {
|
|
|
-// Toast.makeText(AddSiteActivity.this,"场所添加成功"+s,Toast.LENGTH_SHORT).show();
|
|
|
-//
|
|
|
-// }else {
|
|
|
-// Toast.makeText(AddSiteActivity.this,"场所添加没有成功!"+s,Toast.LENGTH_SHORT).show();
|
|
|
-// }
|
|
|
-
|
|
|
- JSONObject jsonObject = null;
|
|
|
- try {
|
|
|
- jsonObject = new JSONObject(s);
|
|
|
- String message = jsonObject.get("msg").toString();
|
|
|
- String code = jsonObject.get("code").toString();
|
|
|
- String data = jsonObject.get("data").toString();
|
|
|
- if (message.equalsIgnoreCase("success")) {
|
|
|
- data1 = data;
|
|
|
-
|
|
|
- HashMap<String, String> hashMap2 = new HashMap<>();
|
|
|
- hashMap2.put("RegionName", textViewSite1.getText().toString());
|
|
|
- hashMap2.put("Location", editDetailedsite.getText().toString());
|
|
|
- hashMap2.put("id", data1);
|
|
|
- Data.getListmap().add(0, hashMap2);
|
|
|
-
|
|
|
- Toast.makeText(AddSiteActivity.this, "添加成功!", Toast.LENGTH_SHORT).show();
|
|
|
- List<String> listdata = Data.getList();
|
|
|
- listdata.add(0, editSite.getText().toString()); //3行可简化为 Data.getList().add(0,editSite.getText().toString());
|
|
|
- Data.setList(listdata);
|
|
|
- IsDeviceChange.setChangeSize(true); //判断设备界面title列表要不要刷新
|
|
|
- Data.setLinkmanname(data1);
|
|
|
- getdata1();
|
|
|
- // return;
|
|
|
- } else {
|
|
|
- LoginIn.tokenOut(message, AddSiteActivity.this);
|
|
|
- Toast.makeText(AddSiteActivity.this, "" + message, Toast.LENGTH_SHORT).show();
|
|
|
- }
|
|
|
- } catch (JSONException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- // Toast.makeText(AddSiteActivity.this,"dd"+s,Toast.LENGTH_SHORT).show();
|
|
|
- // Toast.makeText(AddSiteActivity.this,"场所添加成功!"+s,Toast.LENGTH_SHORT).show();
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public String getRegionName() {
|
|
|
+ //区域名字
|
|
|
+ return textViewSite1.getText().toString();
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public void onError(Call call, Response response, Exception e) {
|
|
|
- super.onError(call, response, e);
|
|
|
- // mTextView2.setText(e.getMessage());
|
|
|
- // Toast.makeText(getContext(),"NOsuccess "+e,Toast.LENGTH_SHORT).show();
|
|
|
- System.out.println("sss" + e);
|
|
|
- }
|
|
|
- });
|
|
|
- // getdata1();
|
|
|
+ @Override
|
|
|
+ public String getLocation() {
|
|
|
+ //详细地址
|
|
|
+ return editDetailedsite.getText().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getLongtitude() {
|
|
|
+ //经度
|
|
|
+ return Longitude;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getRegionCode() {
|
|
|
+ return regionCode;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getLatitude() {
|
|
|
+ //纬度
|
|
|
+ return Latitude;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSuccess(String data) {
|
|
|
+ data1 = data;
|
|
|
+ Toast.makeText(AddSiteActivity.this, "添加成功!", Toast.LENGTH_SHORT).show();
|
|
|
+ IsDeviceChange.setChangeSize(true); //判断设备界面title列表要不要刷新
|
|
|
+ Data.setLinkmanname(data1);
|
|
|
+ showLinkManDialog();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFile(String msg) {
|
|
|
+ Toast.makeText(this,""+msg,Toast.LENGTH_SHORT).show();
|
|
|
}
|
|
|
}
|