summaryrefslogtreecommitdiff
path: root/client/Piztor
diff options
context:
space:
mode:
authorsjtufs <[email protected]>2013-08-30 10:41:03 +0800
committersjtufs <[email protected]>2013-08-30 10:41:03 +0800
commit711354d20f1b233a48c59c52bcf38242ef78dd5f (patch)
tree230505ba7b60a2b08f2bded917e04aad277b0da3 /client/Piztor
parentcc2b1778d19e6b6457c023284f86a0efcdb8e039 (diff)
offline map support but needs to be copied manually.
fix bug duel to api update
Diffstat (limited to 'client/Piztor')
-rw-r--r--client/Piztor/src/com/macaroon/piztor/AlertMaker.java1
-rw-r--r--client/Piztor/src/com/macaroon/piztor/AppMgr.java2
-rw-r--r--client/Piztor/src/com/macaroon/piztor/CopyMap.java50
-rw-r--r--client/Piztor/src/com/macaroon/piztor/InitAct.java9
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Main.java8
-rw-r--r--client/Piztor/src/com/macaroon/piztor/MapMaker.java55
-rw-r--r--client/Piztor/src/com/macaroon/piztor/Settings.java1
7 files changed, 113 insertions, 13 deletions
diff --git a/client/Piztor/src/com/macaroon/piztor/AlertMaker.java b/client/Piztor/src/com/macaroon/piztor/AlertMaker.java
index 63382bb..839813a 100644
--- a/client/Piztor/src/com/macaroon/piztor/AlertMaker.java
+++ b/client/Piztor/src/com/macaroon/piztor/AlertMaker.java
@@ -124,6 +124,7 @@ public class AlertMaker {
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
+ closeBoard(context);
}
});
quitDialog.show();
diff --git a/client/Piztor/src/com/macaroon/piztor/AppMgr.java b/client/Piztor/src/com/macaroon/piztor/AppMgr.java
index 790fe4d..e322745 100644
--- a/client/Piztor/src/com/macaroon/piztor/AppMgr.java
+++ b/client/Piztor/src/com/macaroon/piztor/AppMgr.java
@@ -15,7 +15,7 @@ import com.baidu.mapapi.MKGeneralListener;
@SuppressLint("UseSparseArrays")
public class AppMgr {
- private static final String strKey = "8a0ae50048d103b2b8b12b7066f4ea7d";
+ static final String strKey = "8a0ae50048d103b2b8b12b7066f4ea7d";
static BMapManager mBMapManager = null;
// Status
diff --git a/client/Piztor/src/com/macaroon/piztor/CopyMap.java b/client/Piztor/src/com/macaroon/piztor/CopyMap.java
new file mode 100644
index 0000000..6d49767
--- /dev/null
+++ b/client/Piztor/src/com/macaroon/piztor/CopyMap.java
@@ -0,0 +1,50 @@
+package com.macaroon.piztor;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import android.content.Context;
+
+public class CopyMap {
+ /**
+ *
+ * @param myContext
+ * @param ASSETS_NAME 要复制的文件名
+ * @param savePath 要保存的路径
+ * @param saveName 复制后的文件名
+ * testCopy(Context context)是一个测试例子。
+ */
+
+ public static void copy(Context myContext, String ASSETS_NAME,
+ String savePath, String saveName) {
+ String filename = savePath + "/" + saveName;
+
+ File dir = new File(savePath);
+ // 如果目录不中存在,创建这个目录
+ if (!dir.exists())
+ dir.mkdir();
+ try {
+ if (!(new File(filename)).exists()) {
+ InputStream is = myContext.getResources().getAssets()
+ .open(ASSETS_NAME);
+ System.out.println(ASSETS_NAME);
+ FileOutputStream fos = new FileOutputStream(filename);
+ byte[] buffer = new byte[7168];
+ int count = 0;
+ while ((count = is.read(buffer)) > 0) {
+ fos.write(buffer, 0, count);
+ }
+ fos.close();
+ is.close();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ public void testCopy(Context context) {
+ String path=context.getFilesDir().getAbsolutePath();
+ String name="test";
+ CopyMap.copy(context, name, path, name);
+ }
+}
+
diff --git a/client/Piztor/src/com/macaroon/piztor/InitAct.java b/client/Piztor/src/com/macaroon/piztor/InitAct.java
index 8145935..272afe7 100644
--- a/client/Piztor/src/com/macaroon/piztor/InitAct.java
+++ b/client/Piztor/src/com/macaroon/piztor/InitAct.java
@@ -2,16 +2,23 @@ package com.macaroon.piztor;
import android.os.Bundle;
import android.view.Menu;
+import android.content.Context;
public class InitAct extends PiztorAct {
+ private CopyMap copyMap;
+ private String assetDir;
+ private String dir;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
id = "initAct";
super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_init);
+ copyMap = new CopyMap();
+ copyMap.testCopy(InitAct.this);
AppMgr.init(getApplicationContext());
AppMgr.transam.setTimeOutTime(5000);
- setContentView(R.layout.activity_init);
}
@Override
diff --git a/client/Piztor/src/com/macaroon/piztor/Main.java b/client/Piztor/src/com/macaroon/piztor/Main.java
index 3e8a939..1e46003 100644
--- a/client/Piztor/src/com/macaroon/piztor/Main.java
+++ b/client/Piztor/src/com/macaroon/piztor/Main.java
@@ -224,7 +224,12 @@ public class Main extends PiztorAct {
cnt = 0;
}
}
- mapMaker.UpdateLocationOverlay(locData, false);
+ boolean hasAnimation = false;
+ if (isFirstLocation) {
+ hasAnimation = true;
+ isFirstLocation = false;
+ }
+ mapMaker.UpdateLocationOverlay(locData, hasAnimation);
}
@Override
@@ -334,6 +339,7 @@ public class Main extends PiztorAct {
mapMaker.InitMap();
InitTouchListenr();
mLocClient = new LocationClient(this);
+ mLocClient.setAK(AppMgr.strKey);
locData = new LocationData();
mLocClient.registerLocationListener(myListener);
LocationClientOption option = new LocationClientOption();
diff --git a/client/Piztor/src/com/macaroon/piztor/MapMaker.java b/client/Piztor/src/com/macaroon/piztor/MapMaker.java
index 05cf0b9..bf34d7d 100644
--- a/client/Piztor/src/com/macaroon/piztor/MapMaker.java
+++ b/client/Piztor/src/com/macaroon/piztor/MapMaker.java
@@ -50,9 +50,13 @@ import com.baidu.mapapi.map.MapController;
import com.baidu.mapapi.map.MapPoi;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MyLocationOverlay;
+import com.baidu.mapapi.map.MKOLSearchRecord;
+import com.baidu.mapapi.map.MKOLUpdateElement;
import com.baidu.mapapi.map.OverlayItem;
import com.baidu.mapapi.map.PopupClickListener;
import com.baidu.mapapi.map.PopupOverlay;
+import com.baidu.mapapi.map.MKOfflineMap;
+import com.baidu.mapapi.map.MKOfflineMapListener;
import com.baidu.mapapi.search.MKPoiInfo;
import com.baidu.mapapi.search.MKPoiResult;
import com.baidu.platform.comapi.basestruct.GeoPoint;
@@ -62,7 +66,8 @@ public class MapMaker extends Activity {
// MapView controlling component
private MapView mMapView = null;
MapController mMapController = null;
-
+ MKOfflineMap mOffline = null;
+
// Default center
private final static GeoPoint sjtuCenter = new GeoPoint((int)(31.032247 * 1E6), (int)(121.445937 * 1E6));
@@ -72,6 +77,8 @@ public class MapMaker extends Activity {
private LocationOverlay mLocationOverlay;
private ArrayList<OverlayItem> mItems = null;
private MapInfo preMapInfo = null;
+ private MapInfo nowMapInfo = null;
+
// marker layer
private MyOverlay markerOverlay;
@@ -163,6 +170,40 @@ public class MapMaker extends Activity {
}
/**
+ * Initialize offline map
+ */
+ public void InitOfflineMap() {
+
+ mOffline = new MKOfflineMap();
+ mOffline.init(mMapController, new MKOfflineMapListener() {
+
+ @Override
+ public void onGetOfflineMapState(int type, int state) {
+ switch (type) {
+ case MKOfflineMap.TYPE_DOWNLOAD_UPDATE:
+ MKOLUpdateElement update = mOffline.getUpdateInfo(state);
+ break;
+ case MKOfflineMap.TYPE_NEW_OFFLINE:
+ Log.d("offline", String.format("add offline map %d", state));
+ break;
+ case MKOfflineMap.TYPE_VER_UPDATE:
+ Log.d("offline", String.format("new offline map version"));
+ break;
+ }
+ }
+ });
+ int num = mOffline.scan();
+ String msg = "";
+ if (num == 0) {
+ //msg = "No offline map found. It may have been loaded already or misplaced.";
+ } else {
+ msg = String.format("Loaded %d offline maps.", num);
+ }
+ Log.d("offline", "inited");
+ Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
+ }
+
+ /**
* Initialize location layer
*/
public void InitLocationOverlay() {
@@ -234,6 +275,7 @@ public class MapMaker extends Activity {
InitLocationOverlay();
InitMyOverLay();
InitPopup();
+ InitOfflineMap();
//InitTouchListenr();
}
@@ -263,9 +305,7 @@ public class MapMaker extends Activity {
mOverlay = new MyOverlay(context.getResources().getDrawable(R.drawable.circle_red), mMapView);
GeoPoint p;
Vector<UserInfo> allUsers = mapInfo.getVector();
- boolean flag = false;
if (nowMarker != null) {
- Log.d("marker", "now marker is not null");
mOverlay.addItem(nowMarker);
}
for (int i =1; i < allUsers.size(); i++) {
@@ -276,12 +316,7 @@ public class MapMaker extends Activity {
curItem = new OverlayItem(p, "USERNAME HERE!!!!!", "");
//TODO
////////////////////////////////////////////////////////////
- if (flag == false){
- flag = true;
- curItem.setMarker(context.getResources().getDrawable(R.drawable.circle_green));
- } else {
- curItem.setMarker(context.getResources().getDrawable(R.drawable.circle_red));
- }
+ curItem.setMarker(context.getResources().getDrawable(R.drawable.circle_red));
mOverlay.addItem(curItem);
}
mItems = new ArrayList<OverlayItem>();
@@ -296,6 +331,8 @@ public class MapMaker extends Activity {
}
}
+
+
/**
* Update marker
*/
diff --git a/client/Piztor/src/com/macaroon/piztor/Settings.java b/client/Piztor/src/com/macaroon/piztor/Settings.java
index e930bf2..c0ca901 100644
--- a/client/Piztor/src/com/macaroon/piztor/Settings.java
+++ b/client/Piztor/src/com/macaroon/piztor/Settings.java
@@ -109,7 +109,6 @@ public class Settings extends PiztorAct {
// TODO Auto-generated method stub
}
-
}
@Override