package com.jiuqi.njt.ui.xxcj;
import java.util.ArrayList;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewStub;
import android.view.View.OnClickListener;
import android.widget.TableLayout;
import com.amap.api.search.core.LatLonPoint;
import com.jiuqi.mobile.nigo.comeclose.bean.NiGoBean;
import com.jiuqi.mobile.nigo.comeclose.bean.app.collect.DealerServiceBean;
import com.jiuqi.mobile.nigo.comeclose.bean.app.collect.DrivingSchoolServiceBean;
import com.jiuqi.mobile.nigo.comeclose.bean.app.collect.GasStationServiceBean;
import com.jiuqi.mobile.nigo.comeclose.bean.app.collect.RepairServiceBean;
import com.jiuqi.mobile.nigo.comeclose.bean.app.collect.ServiceCollectBean;
import com.jiuqi.mobile.nigo.comeclose.bean.app.coop.CooperBean;
import com.jiuqi.mobile.nigo.comeclose.bean.app.news.TaskNews;
import com.jiuqi.njt.R;
import com.jiuqi.njt.data.MyApp;
import com.jiuqi.njt.ui.PoiLocateActivity;
import com.jiuqi.njt.ui.xxcj.XxcjTask.DataType;
import com.jiuqi.njt.util.Constants;
import com.jiuqi.njt.util.GpsService;
import com.jiuqi.njt.util.TitleBarUtil;
import com.jiuqi.njt.util.UIUtil;
import com.jqyd.android.module.lbs.util.CheckState_interface;
/**
* 信息采集数据展示、修改页面
* @author Administrator
*
*/
@SuppressWarnings("unused")
public class XxcxDetail extends Activity implements OnClickListener {
private TableLayout table;
private MyApp application;
private double lon = 0.0;
private double lat = 0.0;
private NiGoBean bean;
private LatLonPoint startPoint, endPoint;
private String flag;
private String tel;
private String name;
private ArrayList<String[]> rlist;
private Dialog dialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
doinit();
}
private void doinit() {
// TODO Auto-generated method stub
initParam();
initWidgets();
initListeners();
inItUI();
}
private void initWidgets() {
// TODO Auto-generated method stub
setContentView(R.layout.xxcx_detail);
ViewStub rlTitleBar = (ViewStub) findViewById(R.id.titleBarStub);
TitleBarUtil.createTitleBar(this, rlTitleBar, "详细信息",
new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
}, "地图标记", new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(XxcxDetail.this,
PoiLocateActivity.class);
startActivityForResult(intent,
Constants.REQUEST_MAP_LOCATE_CODE);
}
});
table = (TableLayout) findViewById(R.id.tbLayout);
}
private void inItUI() {
// TODO Auto-generated method stub
if (null != rlist) {
UIUtil.generateTableRows(XxcxDetail.this, table, rlist);
}
}
private void initListeners() {
// TODO Auto-generated method stub
}
private void initParam() {
application = (MyApp) getApplicationContext();
bean = (NiGoBean) getIntent().getSerializableExtra("bean");
flag = getIntent().getStringExtra("flag");
if (null == bean) {
UIUtil.showMsg(XxcxDetail.this, "无信息展示");
} else {
rlist = new ArrayList<String[]>();
try {
if (bean instanceof TaskNews) {
tel = ((TaskNews) bean).getContactMobileNumber();
// startPoint = new LatLonPoint(mylat, mylon);
endPoint = new LatLonPoint(((TaskNews) bean).getLatitude(),
((TaskNews) bean).getLongitude());
}
} catch (Exception e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
if ("service".equals(flag)) {
// 显示地图导航和拨打电话的按钮
// startPoint = new LatLonPoint(mylat, mylon);
try {
endPoint = new LatLonPoint(
((ServiceCollectBean) bean).getLatitude(),
((ServiceCollectBean) bean).getLongitude());
name = strFormat(((ServiceCollectBean) bean)
.getResponsiblePersonName());
tel = strFormat(((ServiceCollectBean) bean)
.getResponsiblePersonmobileNumber());
if (!TextUtils.isEmpty(((ServiceCollectBean) bean)
.getName())) {
rlist.add(new String[] { "单位名称:",
((ServiceCollectBean) bean).getName() });
}
if (!TextUtils.isEmpty(name)) {
rlist.add(new String[] { "联系人:", name });
}
if (!TextUtils.isEmpty(tel)) {
rlist.add(new String[] { "联系电话:", tel });
}
if (((ServiceCollectBean) bean).getAdminAreaCode() != null
&& !TextUtils.isEmpty(((ServiceCollectBean) bean)
.getAdminAreaCode().getFullName())) {
rlist.add(new String[] {
"联系地址:",
((ServiceCollectBean) bean).getAdminAreaCode()
.getFullName() });
// 新增地图标记
rlist.add(new String[] { "经度:",
((ServiceCollectBean) bean).getLongitude() + "" });
rlist.add(new String[] { "纬度:",
((ServiceCollectBean) bean).getLatitude() + "" });
}
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// //////////////////////// 维修站 //////////////////////////
if (bean instanceof RepairServiceBean) {
try {
if (!TextUtils.isEmpty(((RepairServiceBean) bean)
.getType().getName())) {
rlist.add(new String[] {
"维修站类型:",
((RepairServiceBean) bean).getType()
.getName() });
}
if (!TextUtils.isEmpty(((RepairServiceBean) bean)
.getGrade().getName())) {
rlist.add(new String[] {
"维修站资质:",
((RepairServiceBean) bean).getGrade()
.getName() });
}
if (!TextUtils.isEmpty(((RepairServiceBean) bean)
.getMemo())) {
rlist.add(new String[] { "简介:",
((RepairServiceBean) bean).getMemo() });
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// /////////////////////// 加油站 //////////////////////////////
if (bean instanceof GasStationServiceBean) {
try {
if (!TextUtils.isEmpty(((GasStationServiceBean) bean)
.getMemo())) {
rlist.add(new String[] { "简介:",
((GasStationServiceBean) bean).getMemo() });
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// ///////////////////////// 经销商 ////////////////////////////
if (bean instanceof DealerServiceBean) {
try {
if (!TextUtils.isEmpty(((DealerServiceBean) bean)
.getCategory().getName())) {
rlist.add(new String[] {
"经销商类型:",
((DealerServiceBean) bean).getCategory()
.getName() });
}
if (!TextUtils.isEmpty(((DealerServiceBean) bean)
.getMemo())) {
rlist.add(new String[] { "简介:",
((DealerServiceBean) bean).getMemo() });
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// /////////////////////////// 农机驾校 //////////////////////////
if (bean instanceof DrivingSchoolServiceBean) {
if (!TextUtils.isEmpty(((DrivingSchoolServiceBean) bean)
.getMemo())) {
rlist.add(new String[] { "简介:",
((DrivingSchoolServiceBean) bean).getMemo() });
}
}
} else if ("cooper".equals(flag)) { // 合作社
// 显示地图导航和拨打电话的按钮
// startPoint = new LatLonPoint(mylat, mylon);
try {
endPoint = new LatLonPoint(
((CooperBean) bean).getLatitude(),
((CooperBean) bean).getLongitude());
name = strFormat(((CooperBean) bean).getChargePerson());
tel = strFormat(((CooperBean) bean).getTelephone());
if (!TextUtils.isEmpty(((CooperBean) bean).getCoopName())) {
rlist.add(new String[] { "单位名称:",
((CooperBean) bean).getCoopName() });
}
if (!TextUtils.isEmpty(((CooperBean) bean)
.getCoopProperty().getName())) {
rlist.add(new String[] { "合作社类型:",
((CooperBean) bean).getCoopProperty().getName() });
}
if (!TextUtils.isEmpty(name)) {
rlist.add(new String[] { "联系人:", name });
}
if (!TextUtils.isEmpty(tel)) {
rlist.add(new String[] { "联系电话:", tel });
}
if (((CooperBean) bean).getAdminAreaCode() != null
&& !TextUtils.isEmpty(((CooperBean) bean)
.getAdminAreaCode().getFullName())) {
rlist.add(new String[] {
"联系地址:",
((CooperBean) bean).getAdminAreaCode()
.getFullName() });
}
if (!TextUtils.isEmpty(((CooperBean) bean)
.getIntroduction())) {
rlist.add(new String[] { "简介:",
((CooperBean) bean).getIntroduction() });
}
if (!TextUtils.isEmpty(((CooperBean) bean).getLongitude()
+ "")) {
rlist.add(new String[] { "经度:",
((CooperBean) bean).getLongitude() + "" });
}
if (!TextUtils.isEmpty(((CooperBean) bean).getLatitude()
+ "")) {
rlist.add(new String[] { "纬度:",
((CooperBean) bean).getLatitude() + "" });
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
// 数据为空时,显示空串
private String strFormat(String str) {
if (str == null) {
str = "";
}
return str;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == Constants.REQUEST_MAP_LOCATE_CODE) {
if (resultCode == RESULT_OK) {
lon = data.getDoubleExtra("longitude", 0);
lat = data.getDoubleExtra("latitude", 0);
Log.v(Constants.TAG, "longitude: " + lon + " latitude: " + lat);
int length = rlist.size();
rlist.remove(length - 1);
rlist.remove(length - 2);
rlist.add(new String[] { "经度:", lon + "" });
rlist.add(new String[] { "纬度:", lat + "" });
table.removeAllViews();
UIUtil.generateTableRows(XxcxDetail.this, table, rlist);
}
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.upload:
if (lon != 0 && lat != 0)
{
// new UpLoadTask().execute(lon, lat);
new XxcjTask(XxcxDetail.this, DataType.modifyData, bean, flag, lon, lat).execute();
}
else
{
if (startGps(XxcxDetail.this))
{
// new WzcxTask(XxcxDetail.this).execute();
new GetLocationByGPSTask(XxcxDetail.this, DataType.modifyData, bean, flag).execute();
}
}
break;
default:
break;
}
}
/**
* 检测并启动Gps搜星
*/
public static boolean startGps(final Context contex) {
int gps_flag = new CheckState_interface(contex).checkGpState();
if (gps_flag == 1) {// GPS设备已打开
// TODO 搜索位置
Intent stateService = new Intent(contex, GpsService.class);
contex.startService(stateService);
return true;
} else {// GPS设备未打开
UIUtil.alert(contex, "GPS模块不可用,请打开GPS功能!",
new DialogInterface.OnClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
contex.startActivity(intent);
}
});
return false;
}
}
@Override
protected void onResume() {
super.onResume();
}
}