Pārlūkot izejas kodu

Fix some login issue.
Fix X509TrustManager issue.

Ray Zhang 9 gadi atpakaļ
vecāks
revīzija
71cec02a8f

+ 302 - 170
Apex/src/com/usai/apex/BaiduMapFragment.java

@@ -11,17 +11,36 @@ import java.util.HashMap;
 import org.json.JSONException;
 import org.json.JSONObject;
 
+//import baidumapsdk.demo.R;
+
+
+
+
+
 import com.baidu.mapapi.BMapManager;
-import com.baidu.mapapi.MKGeneralListener;
-import com.baidu.mapapi.map.ItemizedOverlay;
-import com.baidu.mapapi.map.MKEvent;
-import com.baidu.mapapi.map.MapController;
+import com.baidu.mapapi.SDKInitializer;
+import com.baidu.mapapi.map.BaiduMap.OnMapClickListener;
+import com.baidu.mapapi.map.BitmapDescriptor;
+import com.baidu.mapapi.map.BitmapDescriptorFactory;
+import com.baidu.mapapi.map.InfoWindow;
+import com.baidu.mapapi.map.MapPoi;
+import com.baidu.mapapi.map.MapStatusUpdate;
+import com.baidu.mapapi.map.MapStatusUpdateFactory;
+//import com.baidu.mapapi.MKGeneralListener;
+//import com.baidu.mapapi.map.ItemizedOverlay;
+//import com.baidu.mapapi.map.MKEvent;
+//import com.baidu.mapapi.map.MapController;
 import com.baidu.mapapi.map.MapView;
-import com.baidu.mapapi.map.OverlayItem;
-import com.baidu.mapapi.map.PopupClickListener;
-import com.baidu.mapapi.map.PopupOverlay;
+import com.baidu.mapapi.map.Marker;
+import com.baidu.mapapi.map.MarkerOptions;
+//import com.baidu.mapapi.map.OverlayItem;
+//import com.baidu.mapapi.map.PopupClickListener;
+//import com.baidu.mapapi.map.PopupOverlay;
 import com.baidu.mapapi.map.SupportMapFragment;
-import com.baidu.platform.comapi.basestruct.GeoPoint;
+import com.baidu.mapapi.map.BaiduMap.OnMarkerClickListener;
+import com.baidu.mapapi.map.InfoWindow.OnInfoWindowClickListener;
+import com.baidu.mapapi.model.LatLng;
+//import com.baidu.platform.comapi.basestruct.GeoPoint;
 import com.usai.util.Network;
 
 import android.content.Context;
@@ -37,6 +56,8 @@ import android.view.Gravity;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.View.OnClickListener;
+import android.widget.Button;
 import android.widget.TextView;
 import android.widget.Toast;
 
@@ -45,59 +66,43 @@ public class BaiduMapFragment extends Fragment
 	private SearchTask				m_task				= null;
 	String							fragment_content	= null;
 	private MapView					mMapView			= null;
-	private MyOverlay				mOverlay			= null;
+	// private MyOverlay mOverlay = null;
 	// private OverlayItem mCurItem = null;
 	// private Button button = null;
-	private ArrayList<OverlayItem>	mItems				= null;
-	private PopupOverlay			pop					= null;
+	// private ArrayList<OverlayItem> mItems = null;
+	// private PopupOverlay pop = null;
 	SupportMapFragment				fragment;
 	BMapManager						mBMapManager		= null;
 	public static boolean			m_bKeyRight			= true;
 	HashMap<String, LocationDetail>	marker_detail		= new HashMap<String, LocationDetail>();
-	OverlayItem						m_curitem			= null;
-
-	public class MyOverlay extends ItemizedOverlay
-	{
-
-		public MyOverlay(Drawable defaultMarker, MapView mapView)
-		{
-			super(defaultMarker, mapView);
-		}
-
-		@Override
-		public boolean onTap(int index)
-		{
-			Log.d("baidumap...................", "ontap");
-			View viewCache = getActivity().getLayoutInflater().inflate(
-					R.layout.marker_view, null);
-
-			TextView tv_title = (TextView) viewCache
-					.findViewById(R.id.tv_title);
-			TextView tv_info = (TextView) viewCache.findViewById(R.id.tv_info);
 
-			OverlayItem item = getItem(index);
-
-			tv_title.setText(item.getTitle());
-			tv_info.setText(item.getSnippet());
-			m_curitem = item;
-			pop.showPopup(viewCache, item.getPoint(), 32);
-			return true;
-		}
-
-		@Override
-		public boolean onTap(GeoPoint pt, MapView mMapView)
-		{
-			Log.d("baidu map demo ", "hide pop");
-			if (pop != null)
-			{
-
-				pop.hidePop();
-				// mMapView.removeView(button);
-			}
-			return false;
-		}
-
-	}
+	// OverlayItem m_curitem = null;
+	/*
+	 * public class MyOverlay extends ItemizedOverlay {
+	 * 
+	 * public MyOverlay(Drawable defaultMarker, MapView mapView) {
+	 * super(defaultMarker, mapView); }
+	 * 
+	 * @Override public boolean onTap(int index) {
+	 * Log.d("baidumap...................", "ontap"); View viewCache =
+	 * getActivity().getLayoutInflater().inflate( R.layout.marker_view, null);
+	 * 
+	 * TextView tv_title = (TextView) viewCache .findViewById(R.id.tv_title);
+	 * TextView tv_info = (TextView) viewCache.findViewById(R.id.tv_info);
+	 * 
+	 * OverlayItem item = getItem(index);
+	 * 
+	 * tv_title.setText(item.getTitle()); tv_info.setText(item.getSnippet());
+	 * m_curitem = item; pop.showPopup(viewCache, item.getPoint(), 32); return
+	 * true; }
+	 * 
+	 * @Override public boolean onTap(GeoPoint pt, MapView mMapView) {
+	 * Log.d("baidu map demo ", "hide pop"); if (pop != null) {
+	 * 
+	 * pop.hidePop(); // mMapView.removeView(button); } return false; }
+	 * 
+	 * }
+	 */
 
 	void AddMarker()
 	{
@@ -118,8 +123,10 @@ public class BaiduMapFragment extends Fragment
 			int count = jsobj.getInt("total");
 
 			JSONObject objrecords = jsobj.getJSONObject("records");
-			mOverlay = new MyOverlay(getResources().getDrawable(
-					R.drawable.ic_marker), mMapView);
+			// mOverlay = new MyOverlay(getResources().getDrawable(
+			// R.drawable.ic_marker), mMapView);
+			BitmapDescriptor icon = BitmapDescriptorFactory
+					.fromResource(R.drawable.ic_marker);
 			for (int i = 0; i < count; i++)
 			{
 				// offset++;
@@ -140,57 +147,74 @@ public class BaiduMapFragment extends Fragment
 						telephone, fax, contact, email);
 				marker_detail.put(company, detail);
 
-				/**
-				 * 准备overlay 数据
-				 */
-				GeoPoint p1 = new GeoPoint(
-						(int) (Double.parseDouble(latitude) * 1E6),
-						(int) (Double.parseDouble(longitude) * 1E6));
-				OverlayItem item1 = new OverlayItem(p1, company, city + "\n"
-						+ area);
-
-				/**
-				 * 将item 添加到overlay中 注意: 同一个itme只能add一次
-				 */
-				mOverlay.addItem(item1);
+				Bundle extrainfo = new Bundle();
+				extrainfo.putString("company", company);
+				extrainfo.putSerializable("detail", detail);
+				extrainfo.putSerializable("city", city);
+				extrainfo.putSerializable("area", area);
+				// // 准备overlay 数据
+				//
+				// GeoPoint p1 = new GeoPoint(
+				// (int) (Double.parseDouble(latitude) * 1E6),
+				// (int) (Double.parseDouble(longitude) * 1E6));
+				// OverlayItem item1 = new OverlayItem(p1, company, city + "\n"
+				// + area);
+				//
+				// //
+				// // * 将item 添加到overlay中 注意: 同一个itme只能add一次
+				// //
+				// mOverlay.addItem(item1);
+				LatLng llA = new LatLng(Double.parseDouble(latitude),
+						Double.parseDouble(longitude));
+
+				MarkerOptions markeroption = new MarkerOptions().position(llA)
+						.icon(icon).zIndex(9).title(company)
+						.extraInfo(extrainfo).draggable(true);
+
+				// if (animationBox.isChecked()) {
+				// //掉下动画
+				// ooA.animateType(MarkerAnimateType.drop);
+				// }
+				Marker mMarkerA = (Marker) (mMapView.getMap()
+						.addOverlay(markeroption));
 
 			}
-			/**
-			 * 保存所有item,以便overlay在reset后重新添加
-			 */
-			mItems = new ArrayList<OverlayItem>();
-			mItems.addAll(mOverlay.getAllItem());
-			/**
-			 * 将overlay 添加至MapView中
-			 */
-			mMapView.getOverlays().add(mOverlay);
-			/**
-			 * 刷新地图
-			 */
-			mMapView.refresh();
-			PopupClickListener popListener = new PopupClickListener()
-			{
-				@Override
-				public void onClickedPopup(int index)
-				{
-					Log.d("baidu map.......", "popup on click");
-					pop.hidePop();
-
-					mMapView.refresh();
-					Intent intent = new Intent();
-					intent.setClass(getActivity(), LocationDetailActivity.class);
-
-					String markertext = m_curitem.getTitle();
-
-					intent.putExtra("detail", marker_detail.get(markertext));
-					// // intent.putExtra("password", password);
-					// intent.putExtra("function_name", function_name);
-					// intent.putExtra("behavior", Network.BEHAVIOR_SEARCH);
-					startActivity(intent);
-
-				}
-			};
-			pop = new PopupOverlay(mMapView, popListener);
+			//
+			// * 保存所有item,以便overlay在reset后重新添加
+			//
+			// mItems = new ArrayList<OverlayItem>();
+			// mItems.addAll(mOverlay.getAllItem());
+			// //
+			// // * 将overlay 添加至MapView中
+			// //
+			// mMapView.getOverlays().add(mOverlay);
+			// //
+			// // * 刷新地图
+			// //
+			// mMapView.refresh();
+			// PopupClickListener popListener = new PopupClickListener()
+			// {
+			// @Override
+			// public void onClickedPopup(int index)
+			// {
+			// Log.d("baidu map.......", "popup on click");
+			// pop.hidePop();
+			//
+			// mMapView.refresh();
+			// Intent intent = new Intent();
+			// intent.setClass(getActivity(), LocationDetailActivity.class);
+			//
+			// String markertext = m_curitem.getTitle();
+			//
+			// intent.putExtra("detail", marker_detail.get(markertext));
+			// // // intent.putExtra("password", password);
+			// // intent.putExtra("function_name", function_name);
+			// // intent.putExtra("behavior", Network.BEHAVIOR_SEARCH);
+			// startActivity(intent);
+			//
+			// }
+			// };
+			// pop = new PopupOverlay(mMapView, popListener);
 		}
 		catch (JSONException e)
 		{
@@ -335,6 +359,131 @@ public class BaiduMapFragment extends Fragment
 			if (success)
 			{
 				AddMarker();
+
+				mMapView.getMap().setOnMapClickListener( new OnMapClickListener()
+				{
+					
+					@Override
+					public boolean onMapPoiClick(MapPoi arg0)
+					{
+						mMapView.getMap().hideInfoWindow();
+						return false;
+					}
+					
+					@Override
+					public void onMapClick(LatLng arg0)
+					{
+						mMapView.getMap().hideInfoWindow();
+						
+					}
+				});
+				mMapView.getMap().setOnMarkerClickListener(
+						new OnMarkerClickListener()
+						{
+							public boolean onMarkerClick(final Marker marker)
+							{
+								// Button button = new
+								// Button(getActivity().getApplicationContext());
+								// button.setBackgroundResource(R.drawable.popup);
+
+								View viewCache = getActivity()
+										.getLayoutInflater().inflate(
+												R.layout.marker_view, null);
+
+								TextView tv_title = (TextView) viewCache
+										.findViewById(R.id.tv_title);
+								TextView tv_info = (TextView) viewCache
+										.findViewById(R.id.tv_info);
+
+								final String title = marker.getTitle();
+
+								Bundle bundle = marker.getExtraInfo();
+
+								final LocationDetail detail = (LocationDetail) bundle
+										.getSerializable("detail");
+								String city = bundle.getString("city");
+								String area = bundle.getString("area");
+								// OverlayItem item = getItem(index);
+
+								// marker.get
+
+								tv_title.setText(title);
+								tv_info.setText(city + "\n" + area);
+								// m_curitem = item;
+								// pop.showPopup(viewCache, item.getPoint(),
+								// 32);
+								OnInfoWindowClickListener listener = null;
+								if (true)
+								{
+									// button.setText("更改位置");
+									listener = new OnInfoWindowClickListener()
+									{
+										public void onInfoWindowClick()
+										{
+
+											mMapView.getMap().hideInfoWindow();
+
+											Log.d("baidu map.......",
+													"popup on click");
+											
+
+//											mMapView.refresh();
+											Intent intent = new Intent();
+											intent.setClass(
+													getActivity(),
+													LocationDetailActivity.class);
+
+											String markertext = title;
+
+											intent.putExtra("detail",
+													detail);
+											// // intent.putExtra("password",
+											// password);
+											// intent.putExtra("function_name",
+											// function_name);
+											// intent.putExtra("behavior",
+											// Network.BEHAVIOR_SEARCH);
+											startActivity(intent);
+										}
+									};
+									LatLng ll = marker.getPosition();
+									InfoWindow mInfoWindow = new InfoWindow(
+											BitmapDescriptorFactory
+													.fromView(viewCache), ll,
+											-100, listener);
+									mMapView.getMap().showInfoWindow(
+											mInfoWindow);
+								}
+								// else if (marker == mMarkerB) {
+								// button.setText("更改图标");
+								// button.setOnClickListener(new
+								// OnClickListener() {
+								// public void onClick(View v) {
+								// marker.setIcon(bd);
+								// mBaiduMap.hideInfoWindow();
+								// }
+								// });
+								// LatLng ll = marker.getPosition();
+								// mInfoWindow = new InfoWindow(button, ll,
+								// -47);
+								// mBaiduMap.showInfoWindow(mInfoWindow);
+								// } else if (marker == mMarkerC) {
+								// button.setText("删除");
+								// button.setOnClickListener(new
+								// OnClickListener() {
+								// public void onClick(View v) {
+								// marker.remove();
+								// mBaiduMap.hideInfoWindow();
+								// }
+								// });
+								// LatLng ll = marker.getPosition();
+								// mInfoWindow = new InfoWindow(button, ll,
+								// -47);
+								// mBaiduMap.showInfoWindow(mInfoWindow);
+								// }
+								return true;
+							}
+						});
 				//
 				// if (bfinish)
 				// {
@@ -373,69 +522,42 @@ public class BaiduMapFragment extends Fragment
 
 	public void initEngineManager(Context context)
 	{
-		String strKey = ApexTrackingApplication.get_instance().getString(
-				R.string.baidu_key);
-		if (mBMapManager == null)
-		{
-			mBMapManager = new BMapManager(context);
-		}
 
-		if (!mBMapManager.init(strKey, new MyGeneralListener()))
-		{
-			// Toast.makeText(getActivity().getApplicationContext(),
-			// "BMapManager  初始化错误!", Toast.LENGTH_LONG).show();
-		}
-	}
-
-	// 常用事件监听,用来处理通常的网络错误,授权验证错误等
-	static class MyGeneralListener implements MKGeneralListener
-	{
-
-		@Override
-		public void onGetNetworkState(int iError)
-		{
-			if (iError == MKEvent.ERROR_NETWORK_CONNECT)
-			{
-				// Toast.makeText(
-				// ApexTrackingApplication.get_instance()
-				// .getApplicationContext(), "您的网络出错啦!",
-				// Toast.LENGTH_LONG).show();
-			}
-			else if (iError == MKEvent.ERROR_NETWORK_DATA)
-			{
-				// Toast.makeText(
-				// ApexTrackingApplication.get_instance()
-				// .getApplicationContext(), "输入正确的检索条件!",
-				// Toast.LENGTH_LONG).show();
-			}
-			// ...
-		}
-
-		@Override
-		public void onGetPermissionState(int iError)
-		{
-			// 非零值表示key验证未通过
-			if (iError != 0)
-			{
-				// 授权Key错误:
-				// Toast.makeText(
-				// ApexTrackingApplication.get_instance()
-				// .getApplicationContext(),
-				// "请在 DemoApplication.java文件输入正确的授权Key,并检查您的网络连接是否正常!error: "
-				// + iError, Toast.LENGTH_LONG).show();
-				m_bKeyRight = false;
-			}
-			else
-			{
-				m_bKeyRight = true;
-				// Toast.makeText(
-				// ApexTrackingApplication.get_instance()
-				// .getApplicationContext(), "key认证成功",
-				// Toast.LENGTH_LONG).show();
-			}
-		}
+		SDKInitializer.initialize(ApexTrackingApplication.get_instance());
+		// String strKey = ApexTrackingApplication.get_instance().getString(
+		// R.string.baidu_key);
+		// if (mBMapManager == null)
+		// {
+		// mBMapManager = new BMapManager(context);
+		// }
+		//
+		// if (!mBMapManager.init(strKey, new MyGeneralListener()))
+		// {
+		// // Toast.makeText(getActivity().getApplicationContext(),
+		// // "BMapManager  初始化错误!", Toast.LENGTH_LONG).show();
+		// }
 	}
 
+	/*
+	 * // 常用事件监听,用来处理通常的网络错误,授权验证错误等 static class MyGeneralListener implements
+	 * MKGeneralListener {
+	 * 
+	 * @Override public void onGetNetworkState(int iError) { if (iError ==
+	 * MKEvent.ERROR_NETWORK_CONNECT) { // Toast.makeText( //
+	 * ApexTrackingApplication.get_instance() // .getApplicationContext(),
+	 * "您的网络出错啦!", // Toast.LENGTH_LONG).show(); } else if (iError ==
+	 * MKEvent.ERROR_NETWORK_DATA) { // Toast.makeText( //
+	 * ApexTrackingApplication.get_instance() // .getApplicationContext(),
+	 * "输入正确的检索条件!", // Toast.LENGTH_LONG).show(); } // ... }
+	 * 
+	 * @Override public void onGetPermissionState(int iError) { // 非零值表示key验证未通过
+	 * if (iError != 0) { // 授权Key错误: // Toast.makeText( //
+	 * ApexTrackingApplication.get_instance() // .getApplicationContext(), //
+	 * "请在 DemoApplication.java文件输入正确的授权Key,并检查您的网络连接是否正常!error: " // + iError,
+	 * Toast.LENGTH_LONG).show(); m_bKeyRight = false; } else { m_bKeyRight =
+	 * true; // Toast.makeText( // ApexTrackingApplication.get_instance() //
+	 * .getApplicationContext(), "key认证成功", // Toast.LENGTH_LONG).show(); } } }
+	 */
 	@Override
 	public void onActivityCreated(Bundle savedInstanceState)
 	{
@@ -463,6 +585,8 @@ public class BaiduMapFragment extends Fragment
 	{
 		// TODO Auto-generated method stub
 		// return super.onCreateView(inflater, container, savedInstanceState);
+				
+
 		requestloactions();
 		return inflater.inflate(R.layout.fragment_service_location, container,
 				false);
@@ -474,11 +598,19 @@ public class BaiduMapFragment extends Fragment
 		super.onResume();
 
 		Log.d("onResume", "get map from fragment");
-
-		MapController controller = fragment.getMapView().getController();
-		controller.setCenter(new GeoPoint((int) (29.945 * 1E6),
-				(int) (106.404 * 1E6)));
-		controller.setZoom(5);
+		LatLng center = new LatLng(29.945,104.7);
+		MapStatusUpdate msu = MapStatusUpdateFactory.newLatLngZoom(center,4.8f);//MapStatusUpdateFactory.zoomTo(4.5f);
+		
+		
+		fragment.getMapView().getMap().setMapStatus(msu);
+		
+//		float zoomLevel = Float.parseFloat(t.getText().toString());
+//		MapStatusUpdate u = MapStatusUpdateFactory.zoomTo(zoomLevel);
+//		mBaiduMap.animateMapStatus(u);
+//		 MapController controller = fragment.getMapView().getController();
+//		 controller.setCenter(new GeoPoint((int) ( * 1E6),
+//		 (int)  * 1E6)));
+//		 controller.setZoom(5);
 	}
 
 }

+ 3 - 3
Apex/src/com/usai/apex/InnerMapActivity.java

@@ -1,8 +1,8 @@
 package com.usai.apex;
 
 import com.baidu.mapapi.BMapManager;
-import com.baidu.mapapi.MKGeneralListener;
-import com.baidu.mapapi.map.MKEvent;
+//import com.baidu.mapapi.MKGeneralListener;
+//import com.baidu.mapapi.map.MKEvent;
 import com.baidu.mapapi.map.SupportMapFragment;
 
 import android.content.pm.PackageInfo;
@@ -126,7 +126,7 @@ public class InnerMapActivity extends FragmentActivity
 
 
 		Fragment slFragment = null;
-		if (m_bhasgoogleframework)
+		if (m_bhasgoogleframework )
 		{
 			setContentView(R.layout.activity_inner_map);
 			slFragment = new ServiceLocationFragment();