|
@ -1,156 +0,0 @@
|
1
|
|
package com.wade.mobile.func;
|
2
|
|
|
3
|
|
import java.util.HashMap;
|
4
|
|
|
5
|
|
import org.json.JSONArray;
|
6
|
|
|
7
|
|
import android.content.Intent;
|
8
|
|
|
9
|
|
import com.ai.ipu.basic.string.StringUtil;
|
10
|
|
import com.ai.ipu.mobile.data.SharedPrefUtil;
|
11
|
|
import com.ai.ipu.mobile.ui.UiTool;
|
12
|
|
import com.ailk.common.data.IData;
|
13
|
|
import com.ailk.common.data.IDataset;
|
14
|
|
import com.ailk.common.data.impl.DataMap;
|
15
|
|
import com.ailk.common.data.impl.DatasetList;
|
16
|
|
import com.wade.mobile.common.map.AMapLocationInfo;
|
17
|
|
import com.wade.mobile.common.map.AMapMobilePosition;
|
18
|
|
import com.wade.mobile.common.map.activity.MarkMapActivity;
|
19
|
|
import com.wade.mobile.common.map.activity.SelectLocationActivity;
|
20
|
|
import com.wade.mobile.common.map.util.MapConstant;
|
21
|
|
import com.wade.mobile.frame.IWadeMobile;
|
22
|
|
import com.wade.mobile.frame.plugin.Plugin;
|
23
|
|
import com.wade.mobile.util.Constant;
|
24
|
|
|
25
|
|
public class MobileMap extends Plugin {
|
26
|
|
private final int SELECT_LOCATION_CODE = 100;
|
27
|
|
private final int MARK_MAP_CODE = 110;
|
28
|
|
private AMapMobilePosition mobilePosition;
|
29
|
|
private HashMap<String, Integer> iconMap;
|
30
|
|
|
31
|
|
public MobileMap(IWadeMobile wademobile) {
|
32
|
|
super(wademobile);
|
33
|
|
iconMap = new HashMap<String, Integer>();
|
34
|
|
}
|
35
|
|
|
36
|
|
public void markMap(JSONArray params)throws Exception{
|
37
|
|
String dataString = params.getString(0);
|
38
|
|
boolean isSelect = "true".equals(params.getString(1))?true:false;
|
39
|
|
boolean isJump = "true".equals(params.getString(2))?true:false;
|
40
|
|
|
41
|
|
IDataset paramDatas = null;
|
42
|
|
if(StringUtil.isDataMap(dataString)){
|
43
|
|
paramDatas = new DatasetList(new DataMap(dataString));
|
44
|
|
}else{
|
45
|
|
paramDatas = new DatasetList(dataString);
|
46
|
|
}
|
47
|
|
int id = 0;
|
48
|
|
for (int i = 0; i < paramDatas.size(); i++) {
|
49
|
|
IData data = paramDatas.getData(i);
|
50
|
|
String pngName = data.getString(MapConstant.KEY_MARK_ICON);
|
51
|
|
if (pngName != null) {
|
52
|
|
if (iconMap.containsKey(pngName)) {
|
53
|
|
id = iconMap.get(pngName);
|
54
|
|
} else {
|
55
|
|
id = UiTool.getR(Constant.DRAWABLE, pngName);
|
56
|
|
iconMap.put(pngName, id);
|
57
|
|
}
|
58
|
|
data.put(MapConstant.KEY_MARK_ICON, id);
|
59
|
|
}
|
60
|
|
}
|
61
|
|
|
62
|
|
markMap(paramDatas, isSelect, isJump);
|
63
|
|
}
|
64
|
|
|
65
|
|
public void markMap(IDataset datas, boolean isSelect, boolean isJump){
|
66
|
|
Intent intent = new Intent(context, MarkMapActivity.class);
|
67
|
|
intent.putExtra(MapConstant.MARK_DATA, datas.toString());
|
68
|
|
intent.putExtra(MapConstant.MARK_IS_SELECT, isSelect);
|
69
|
|
intent.putExtra(MapConstant.MARK_IS_JUMP, isJump);
|
70
|
|
startActivityForResult(intent, MARK_MAP_CODE);
|
71
|
|
}
|
72
|
|
|
73
|
|
/**
|
74
|
|
* 获取位置信息
|
75
|
|
*/
|
76
|
|
public void location(JSONArray params) throws Exception {
|
77
|
|
// TODO Auto-generated method stub
|
78
|
|
location();
|
79
|
|
}
|
80
|
|
|
81
|
|
public void location() throws Exception {
|
82
|
|
// TODO Auto-generated method stub
|
83
|
|
//原始的定位方法,可在高版本android系统使用,无法在android2.3上使用.
|
84
|
|
/*LocationInfo locationInfo = new MobilePosition(context).getLocation();
|
85
|
|
String result = locationInfo==null?"":locationInfo.toString();
|
86
|
|
return result;*/
|
87
|
|
mobilePosition = new AMapMobilePosition(context){
|
88
|
|
@Override
|
89
|
|
protected void locationSuccess(AMapLocationInfo locationInfo) {
|
90
|
|
callback(locationInfo.toString());
|
91
|
|
}
|
92
|
|
|
93
|
|
@Override
|
94
|
|
protected void locationFailed(String errorMsg) {
|
95
|
|
// TODO Auto-generated method stub
|
96
|
|
error(errorMsg);
|
97
|
|
}
|
98
|
|
};
|
99
|
|
mobilePosition.location();
|
100
|
|
}
|
101
|
|
|
102
|
|
protected void selectLocation(JSONArray params) throws Exception {
|
103
|
|
Intent intent = new Intent(this.context, SelectLocationActivity.class);
|
104
|
|
intent.putExtra(MapConstant.IS_LOCATION, params.getString(0));
|
105
|
|
intent.putExtra(MapConstant.INIT_LONGITUDE, params.getString(1));
|
106
|
|
intent.putExtra(MapConstant.INIT_LATITUDE, params.getString(2));
|
107
|
|
intent.putExtra(MapConstant.INIT_SCALE, params.getString(3));
|
108
|
|
startActivityForResult(intent, SELECT_LOCATION_CODE);
|
109
|
|
}
|
110
|
|
|
111
|
|
@Override
|
112
|
|
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
113
|
|
switch (requestCode) {
|
114
|
|
case SELECT_LOCATION_CODE:
|
115
|
|
if (resultCode == MapConstant.SUCCESS_CODE) {
|
116
|
|
callback(intent.getStringExtra(MapConstant.CALLBACK_RESULT));
|
117
|
|
}
|
118
|
|
break;
|
119
|
|
case MARK_MAP_CODE:
|
120
|
|
if (resultCode == MapConstant.SUCCESS_CODE) {
|
121
|
|
double lat = intent.getDoubleExtra(MapConstant.KEY_LAT, -1);
|
122
|
|
double lng = intent.getDoubleExtra(MapConstant.KEY_LNG, -1);
|
123
|
|
String title = intent.getStringExtra(MapConstant.KEY_MARK_TITLE);
|
124
|
|
String snippet = intent.getStringExtra(MapConstant.KEY_MARK_SNIPPET);
|
125
|
|
DataMap dataMap = new DataMap();
|
126
|
|
dataMap.put(MapConstant.KEY_LAT, lat);
|
127
|
|
dataMap.put(MapConstant.KEY_LNG, lng);
|
128
|
|
dataMap.put(MapConstant.KEY_MARK_TITLE, title);
|
129
|
|
dataMap.put(MapConstant.KEY_MARK_SNIPPET, snippet);
|
130
|
|
String result = dataMap.toString();
|
131
|
|
callback(result, true);
|
132
|
|
}
|
133
|
|
break;
|
134
|
|
default:
|
135
|
|
break;
|
136
|
|
}
|
137
|
|
}
|
138
|
|
|
139
|
|
@Override
|
140
|
|
public void onPause() {
|
141
|
|
// TODO Auto-generated method stub
|
142
|
|
super.onPause();
|
143
|
|
if(mobilePosition!=null){
|
144
|
|
mobilePosition.stopLocation();
|
145
|
|
}
|
146
|
|
}
|
147
|
|
|
148
|
|
@Override
|
149
|
|
public void onDestroy() {
|
150
|
|
// TODO Auto-generated method stub
|
151
|
|
super.onDestroy();
|
152
|
|
//退出应用的时候清空[设定位置]定位的坐标
|
153
|
|
SharedPrefUtil.remove(Constant.MobileCache.APP_RECORD,
|
154
|
|
new String[] { MapConstant.KEY_LAT, MapConstant.KEY_LNG });
|
155
|
|
}
|
156
|
|
}
|