package cn.flightfeather.thirdapp.activity; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; import com.amap.api.maps.CoordinateConverter; import com.amap.api.maps.model.LatLng; import com.ping.greendao.gen.ScenseDao; import com.ping.greendao.gen.SiteDao; import java.util.List; import cn.flightfeather.thirdapp.CommonApplication; import cn.flightfeather.thirdapp.R; import cn.flightfeather.thirdapp.bean.Scense; import cn.flightfeather.thirdapp.bean.Site; import okhttp3.ResponseBody; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; import retrofit2.http.Body; import retrofit2.http.POST; public class DebugTransSiteLatlngActivity extends AppCompatActivity { private TextView tv_main; private Button btn_scense; private Button btn_site; private ProgressBar pb_main; private CommonApplication application; private SiteDao siteDao; private ScenseDao scenseDao; private DebugService debugService; private List scenseList; private List siteList; private int position =0; private CoordinateConverter converter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_debug_trans_site_latlng); tv_main = (TextView) findViewById(R.id.tv_main); btn_scense = (Button) findViewById(R.id.btn_scense); btn_site = (Button) findViewById(R.id.btn_site); pb_main = (ProgressBar) findViewById(R.id.pb_main); application = (CommonApplication) getApplication(); siteDao = application.getDaoSession().getSiteDao(); scenseDao = application.getDaoSession().getScenseDao(); debugService = application.getRetrofit().create(DebugService.class); converter = new CoordinateConverter(this); converter.from(CoordinateConverter.CoordType.BAIDU); btn_site.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { position = 0; siteList = siteDao.loadAll(); pb_main.setMax(siteList.size()); updateOneSite(siteList.get(position)); } }); btn_scense.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { position = 0; scenseList = scenseDao.queryBuilder().where(ScenseDao.Properties.Districtname.eq("金山区")).list(); pb_main.setMax(scenseList.size()); updateOneScense(scenseList.get(position)); } }); } private void updateOneScense(Scense scense){ if (scense.getRemark()==null){ if (scense.getLongitude()!=null&&scense.getLatitude()!=null){ LatLng oldLatLng = new LatLng(scense.getLatitude(),scense.getLongitude()); converter.coord(oldLatLng); LatLng newLatlng = converter.convert(); scense.setLatitude(newLatlng.latitude); scense.setLongitude(newLatlng.longitude); } scense.setRemark("已转换为高德坐标"); } Call updateScense = debugService.updateScense(scense); updateScense.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { if (response.body()!=null){ position++; pb_main.setProgress(position); tv_main.setText(position+"/"+scenseList.size()); if (position call, Throwable t) { Toast.makeText(application, "网络链接错误", Toast.LENGTH_SHORT).show(); } }); } private void updateOneSite(Site site){ if (site.getRemark() ==null){ if (site.getSitelatitude()!=null&&site.getSitelongitude()!=null){ LatLng oldLatLng = new LatLng(site.getSitelatitude(),site.getSitelongitude()); converter.coord(oldLatLng); LatLng newLatlng = converter.convert(); site.setSitelatitude(newLatlng.latitude); site.setSitelongitude(newLatlng.longitude); } site.setRemark("已转换为高德坐标"); } Call updateSite = debugService.updateSite(site); updateSite.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { if (response.body()!=null){ position++; pb_main.setProgress(position); tv_main.setText(position+"/"+siteList.size()); if (position call, Throwable t) { Toast.makeText(application, "网络链接错误", Toast.LENGTH_SHORT).show(); } }); } interface DebugService{ @POST("scense/") Call updateScense(@Body Scense scense); @POST("site/") Call updateSite(@Body Site site); } }