package com.jiuqi.njt.ui; import java.util.ArrayList; import java.util.List; import android.annotation.SuppressLint; import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.text.TextUtils; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.LinearLayout; import android.widget.TableLayout; import com.amap.api.search.core.LatLonPoint; import com.jiuqi.mobile.nigo.comeclose.bean.app.collect.ServiceCollectBean; import com.jiuqi.mobile.nigo.comeclose.bean.app.file.CollectionBean; import com.jiuqi.mobile.nigo.comeclose.bean.app.gps.UserPositionBean; import com.jiuqi.mobile.nigo.comeclose.bean.base.KindsOfCarBean; import com.jiuqi.mobile.nigo.comeclose.bean.base.RoleCode; import com.jiuqi.mobile.nigo.comeclose.bean.master.DriverBean; import com.jiuqi.mobile.nigo.comeclose.manager.master.IDriverManager; import com.jiuqi.mobile.nigo.comeclose.utils.PositionUtils; import com.jiuqi.mobile.nigo.comeclose.ws.client.ClientContext; import com.jiuqi.njt.R; import com.jiuqi.njt.data.MyApp; import com.jiuqi.njt.data.OptsharepreInterface; import com.jiuqi.njt.management.FregmentFileRepair; import com.jiuqi.njt.management.task.QueryFavorOrNotTask; import com.jiuqi.njt.model.ModuleType; import com.jiuqi.njt.model.TableRawItem; import com.jiuqi.njt.util.Constants; import com.jiuqi.njt.util.ReturnObject; import com.jiuqi.njt.util.TableRawUtils; import com.jiuqi.njt.util.TitleBarUtil; import com.jiuqi.njt.util.UIUtil; import com.jiuqi.njt.widget.ProgressDialogStyle; import com.jqyd.android.module.lbs.LocationClient; import com.jqyd.android.module.lbs.Interface.ILocationListener; import com.jqyd.android.module.lbs.bean.LocationInfo; /**============================================================ * 版权: 久其软件 版权所有 (c) * 包: * 修改记录: * 日期 作者 内容 * ============================================================= * 2013-6-13 liyue * ============================================================*/ /** * <p> * 地图POI点 卡片界面 * </p> * * <p> * Copyright: 版权所有 (c)<br> * Company: 久其 * </p> * * @author liyue * @version 2013-6-13 */ @SuppressLint("NewApi") public class PoiDetailActivity extends Activity implements OnClickListener { private UserPositionBean obj; private View btnNav; private View btnPhoneCall; private TableLayout table; private OptsharepreInterface sharePre; private MyApp myApp; private ArrayList<String[]> rowlist; public static List<TableRawItem> rlistWithDraw; private View optlayout; private View btnSubmit; private String collectionGuid; // 收藏GUID private int typeOfCollection = 6;// 收藏种类,1.维修点 2.机手 3.合作社 4.加油站 5.经销商 6.服务网点 private LinearLayout tbLayoutNew; private RoleCode showRoleCode; /** * 开始定位 */ private final int ROUTE_START_SEARCH = 2000; /** * 定位结束 */ private final int ROUTE_SEARCH_RESULT = 2002; /** * 搜索路线失败 */ private final int ROUTE_SEARCH_ERROR = 2004; private Dialog pd; private Context context = this; private LatLonPoint startPoint = null, endPoint; String usertypeName = ""; private CollectionBean collectionBean; public boolean favorOrNot = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); initWidgets(); myApp = (MyApp) getApplication(); obj = (UserPositionBean) getIntent().getSerializableExtra("obj"); sharePre = new OptsharepreInterface(this); showRoleCode = (RoleCode) getIntent().getSerializableExtra( Constants.PARAM_NAME); if (null == showRoleCode) { usertypeName = "名称"; } else { if (showRoleCode.getName() == "未知角色") { usertypeName = "银行"; } else { usertypeName = showRoleCode.getName(); } if (null != obj) { collectionGuid = obj.getGuid(); switch (showRoleCode) { case Driver: typeOfCollection = 2; collectionGuid = obj.getGuid(); break; case Cooper: typeOfCollection = 3; break; case Gastation: typeOfCollection = 4; break; case Repair: typeOfCollection = 1; break; case Dealer: typeOfCollection = 5; break; case UnknowRole:// 银行 typeOfCollection = 7; break; default: break; } } } routeHandler.sendEmptyMessage(ROUTE_START_SEARCH); } private void doinit() { initParam(); initListeners(); initUI(); // 判断收藏与否的接口 } private void initParam() { rowlist = new ArrayList<String[]>(); rlistWithDraw = new ArrayList<TableRawItem>(); if (!TextUtils.isEmpty(obj.getUserName())) { rowlist.add(new String[] { usertypeName + ":", obj.getUserName() }); CollectionBean collectionBean = new CollectionBean(); collectionBean.setGuid(); collectionBean.setCreateDate(); collectionBean.setAddPersonGuid(sharePre.getPres("guid")); collectionBean.setTypeOfCollection(typeOfCollection); collectionBean.setCollectionGuid(collectionGuid); ServiceCollectBean serviceCollectBean = new ServiceCollectBean(); serviceCollectBean.setGuid(obj.getGuid()); collectionBean.setCollection(serviceCollectBean); if (usertypeName.equals("银行")) { rlistWithDraw.add(TableRawUtils.newTableRawItemWithOutDraw(usertypeName + ":",obj.getUserName())); }else { rlistWithDraw.add(TableRawUtils.newTableRawItemWithAddFavorDraw( PoiDetailActivity.this, usertypeName + ":", obj.getUserName(), favorOrNot, collectionBean)); } } if (!TextUtils.isEmpty(obj.getSim())) { rowlist.add(new String[] { "手机号:", obj.getSim() }); rlistWithDraw.add(TableRawUtils.newTableRawItemWithPhoneDraw( PoiDetailActivity.this, "手机号:", obj.getSim())); } if (obj.getLatitude() != 0 && obj.getLongitude() != 0) { double latitude = UIUtil.tryToDouble(sharePre .getPres(Constants.PREFERENCE_KEY_LATITUDE)); double longitude = UIUtil.tryToDouble(sharePre .getPres(Constants.PREFERENCE_KEY_LONGITUDE)); double pointSpace = PositionUtils.pointSpace(obj.getLongitude(), obj.getLatitude(), longitude, latitude); // rowlist.add(new String[] { // "距离:",UIUtil.getFriendlyDistance(pointSpace * 1000) }); if (obj.getLatitude() == 0 || obj.getLatitude() == 0) { // UIUtil.showMsg(this, "该地点位置信息有问题,无法导航"); } else { rlistWithDraw.add(TableRawUtils.newTableRawItemWithMapDraw( PoiDetailActivity.this, "距离:", UIUtil .getFriendlyDistance(pointSpace * 1000), new LatLonPoint(latitude, longitude), new LatLonPoint( obj.getLatitude(), obj.getLongitude()))); } } if (null != showRoleCode && showRoleCode == RoleCode.Driver) { doqueryRelativeInfo(); } else { if (!TextUtils.isEmpty(obj.getContent())) { rowlist.add(new String[] { "定位详情:", obj.getContent() }); if (obj.getLatitude() == 0 || obj.getLatitude() == 0) { // UIUtil.showMsg(this, "该地点位置信息有问题,无法导航"); } else { double longitude = UIUtil.tryToDouble(sharePre .getPres(Constants.PREFERENCE_KEY_LONGITUDE)); double latitude = UIUtil.tryToDouble(sharePre .getPres(Constants.PREFERENCE_KEY_LATITUDE)); rlistWithDraw.add(TableRawUtils.newTableRawItemWithMapDraw( PoiDetailActivity.this, "定位详情:", obj.getContent(), new LatLonPoint(latitude, longitude), new LatLonPoint(obj.getLatitude(), obj .getLongitude()))); } } UIUtil.ctreatTableRowsWithDraw(PoiDetailActivity.this, tbLayoutNew, rlistWithDraw); } // } } private void doqueryRelativeInfo() { // 查询相关信息 new MyTask().execute(obj.getSim()); } private class MyTask extends AsyncTask<String, Void, ReturnObject> { Dialog pd = null; private DriverBean bean; @Override protected void onPreExecute() { if (PoiDetailActivity.this != null && !PoiDetailActivity.this.isFinishing()) { pd = ProgressDialogStyle.createLoadingDialog( PoiDetailActivity.this, null); pd.show(); } } @Override protected ReturnObject doInBackground(String... params) { ReturnObject ro = new ReturnObject(); try { ClientContext cc = myApp.getClientContext(); if (null == cc) { cc = ClientContext.getClientContext(Constants.SERVER_URL, Constants.ANONYMOUS, Constants.ANONYMOUS); myApp.setClientContext(cc); } IDriverManager manager = cc.getManager(IDriverManager.class); bean = manager.getDriverByMobileNumber1(params[0]); // bean 可能==null ,因为有垃圾数据 if (null != bean) { KindsOfCarBean carBean = bean.getCarType(); String bigMachineCategories = carBean.getBigClassName(); String smallMachineCategories = carBean.getSmallClassName(); String machineItems = carBean.getItemName(); if (null == bigMachineCategories || bigMachineCategories.equals("")) { bigMachineCategories = "无"; smallMachineCategories = "无"; machineItems = "无"; } if (null == bigMachineCategories || smallMachineCategories.equals("")) { smallMachineCategories = "无"; machineItems = "无"; } if (null == bigMachineCategories || machineItems.equals("")) { machineItems = "无"; } String[][] res = new String[][] { new String[] { "农机大类:", bigMachineCategories }, new String[] { "农机小类:", smallMachineCategories }, new String[] { "农机品目:", machineItems } }; // rowlist.add(new String[] {"大类", bigMachineCategories}); // rowlist.add(new String[] {"小类", smallMachineCategories}); // rowlist.add(new String[] {"品目", machineItems}); ro.data = res; ro.isSuccess = true; } } catch (Exception e) { e.printStackTrace(); // Log.v(Constants.TAG, e.getMessage()); ro.isSuccess = false; ro.exception = e; } return ro; } @Override protected void onPostExecute(ReturnObject result) { try { if (result.isSuccess && null != result.data) { String[][] res = (String[][]) result.data; // for (String[] s : res) { // rowlist.add(s); // rlistWithDraw.add(TableRawUtils // .newTableRawItemWithOutDraw(s[0], s[1])); // } if (!TextUtils.isEmpty(obj.getContent())) { rowlist.add(new String[] { "定位详情:", obj.getContent() }); if (obj.getLatitude() == 0 || obj.getLatitude() == 0) { // UIUtil.showMsg(PoiDetailActivity.this, // "该地点位置信息有问题,无法导航"); } else { double longitude = UIUtil .tryToDouble(sharePre .getPres(Constants.PREFERENCE_KEY_LONGITUDE)); double latitude = UIUtil .tryToDouble(sharePre .getPres(Constants.PREFERENCE_KEY_LATITUDE)); rlistWithDraw.add(TableRawUtils .newTableRawItemWithMapDraw( PoiDetailActivity.this, "定位详情:", obj.getContent(), new LatLonPoint( latitude, longitude), new LatLonPoint(obj.getLatitude(), obj.getLongitude()))); } } } if (null != pd) { pd.dismiss(); } UIUtil.ctreatTableRowsWithDraw(PoiDetailActivity.this, tbLayoutNew, rlistWithDraw); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } private void initWidgets() { setContentView(R.layout.poi_detail); View rlTitleBar = findViewById(R.id.titleBarStub); TitleBarUtil.createTitleBar(this, rlTitleBar, "详细信息", new OnClickListener() { @Override public void onClick(View v) { PoiDetailActivity.this.finish(); } }, "首页", new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.setClass(PoiDetailActivity.this, NjtMainActivity.class); startActivity(intent); PoiDetailActivity.this.finish(); } }); table = (TableLayout) findViewById(R.id.tbLayout); tbLayoutNew = (LinearLayout) findViewById(R.id.tbLayoutNew); btnNav = findViewById(R.id.btnNav); btnPhoneCall = findViewById(R.id.btnPhoneCall); optlayout = findViewById(R.id.optlayout); btnSubmit = findViewById(R.id.btnSubmit); } private Handler routeHandler = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case ROUTE_SEARCH_ERROR: myremoveDialog(pd); UIUtil.showMsg(PoiDetailActivity.this, "导航失败,请确认您的网络后重新请求"); break; case ROUTE_START_SEARCH: pd = myshowDialog(1); setUpBaiduLocation(); break; case ROUTE_SEARCH_RESULT: myremoveDialog(pd); toQuery(); break; default: break; } } }; private void setUpBaiduLocation() { /** * 接收百度定位类传来的参数 */ LocationClient client = new LocationClient(context); client.request(new ILocationListener() { @Override public void onReceiveLocInfo(int locType, LocationInfo loc) { startPoint = new LatLonPoint(loc.getLat(), loc.getLon()); sharePre.putPres(Constants.PREFERENCE_KEY_LATITUDE, String.valueOf(startPoint.getLatitude())); sharePre.putPres(Constants.PREFERENCE_KEY_LONGITUDE, String.valueOf(startPoint.getLongitude())); Log.wtf("longitude - PoiDetailActivity", sharePre.getPres(Constants.PREFERENCE_KEY_LONGITUDE) + ""); Log.wtf("latitude - PoiDetailActivity", sharePre.getPres(Constants.PREFERENCE_KEY_LATITUDE) + ""); routeHandler.sendEmptyMessage(ROUTE_SEARCH_RESULT); } }); } private Dialog myshowDialog(int i) { if (i == 1) { pd = ProgressDialogStyle.createLoadingDialog( PoiDetailActivity.this, "正在定位..."); pd.show(); } else if (i == 2) { pd = ProgressDialogStyle.createLoadingDialog( PoiDetailActivity.this, "正在获取路线..."); pd.show(); } return pd; } private void myremoveDialog(Dialog pd) { if (pd != null) { pd.dismiss(); } } private void initListeners() { btnNav.setOnClickListener(this); btnPhoneCall.setOnClickListener(this); btnSubmit.setOnClickListener(this); } private void initUI() { if (null == obj) { int PADDING = UIUtil.dip2px(this, this.getResources().getDimension(R.dimen.padding)); int MARGINMORE = UIUtil.dip2px(this, this.getResources() .getDimension(R.dimen.marginMore)); UIUtil.appendNewRow(this, table, "", "无信息可显示", PADDING, MARGINMORE, getResources().getDrawable(R.drawable.round_all)); btnNav.setVisibility(View.GONE); btnPhoneCall.setVisibility(View.GONE); } if (null != showRoleCode && showRoleCode == RoleCode.Repair) { if (myApp.getIsLogin()) { btnSubmit.setVisibility(View.VISIBLE); } } optlayout.setVisibility(View.GONE); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.btnNav: toMap(); break; case R.id.btnPhoneCall: UIUtil.tryToDial(this, obj.getSim()); break; case R.id.btnSubmit: Intent intent = new Intent(); intent.setClass(PoiDetailActivity.this, FregmentFileRepair.class); intent.putExtra("moduleType", ModuleType.wxgl); intent.putExtra("UserPositionBean", obj); startActivity(intent); break; default: break; } } private void toMap() { if (obj.getLatitude() == 0 || obj.getLatitude() == 0) { UIUtil.showMsg(this, "该地点位置信息有问题,无法导航"); } else { double longitude = UIUtil.tryToDouble(sharePre .getPres(Constants.PREFERENCE_KEY_LONGITUDE)); double latitude = UIUtil.tryToDouble(sharePre .getPres(Constants.PREFERENCE_KEY_LATITUDE)); UIUtil.requestNav(this, new LatLonPoint(latitude, longitude), new LatLonPoint(obj.getLatitude(), obj.getLongitude())); } } public void toQuery() { Log.wtf("collectionGuid", collectionGuid); Log.wtf("sharePre.getPres", sharePre.getPres("guid")); new QueryFavorOrNotTask(PoiDetailActivity.this, new GetData(), collectionGuid, sharePre.getPres("guid")).execute(); } private class GetData implements WhenTaskFinish { public void taskFinished(CollectionBean result) { if (result != null) { favorOrNot = true; } doinit(); } } }