Clover Coverage Report - Main Coverage Report
Coverage timestamp: ven dic 19 2014 16:47:52 EST
../../../../img/srcFileCovDistChart4.png 74% of files have more coverage
338   852   118   5,73
104   683   0,35   14,75
59     2  
4    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  BicycleMap       Line # 69 270 87 43,3% 0.4329114
  BicycleMap.ItemizedBicycleOverlay       Line # 549 22 10 32,4% 0.32352942
  BicycleMap.MySearchListener       Line # 643 39 18 0% 0.0
  BicycleMap.MyPoiOverlay       Line # 727 7 3 0% 0.0
 
No Tests
 
1    package com.dreamcatcher.bicycle.activity;
2   
3    import java.util.ArrayList;
4    import java.util.List;
5   
6    import net.youmi.android.AdManager;
7    import net.youmi.android.AdView;
8    import android.app.Activity;
9    import android.content.Context;
10    import android.graphics.Point;
11    import android.graphics.drawable.Drawable;
12    import android.location.Location;
13    import android.os.Bundle;
14    import android.view.View;
15    import android.view.View.OnClickListener;
16    import android.view.ViewGroup.LayoutParams;
17    import android.view.animation.Animation;
18    import android.view.animation.AnimationUtils;
19    import android.view.inputmethod.InputMethodManager;
20    import android.widget.Button;
21    import android.widget.EditText;
22    import android.widget.ImageButton;
23    import android.widget.LinearLayout;
24    import android.widget.RelativeLayout;
25    import android.widget.TextView;
26    import android.widget.Toast;
27   
28    import com.baidu.mapapi.BMapManager;
29    import com.baidu.mapapi.GeoPoint;
30    import com.baidu.mapapi.ItemizedOverlay;
31    import com.baidu.mapapi.LocationListener;
32    import com.baidu.mapapi.MKAddrInfo;
33    import com.baidu.mapapi.MKDrivingRouteResult;
34    import com.baidu.mapapi.MKLocationManager;
35    import com.baidu.mapapi.MKPlanNode;
36    import com.baidu.mapapi.MKPoiInfo;
37    import com.baidu.mapapi.MKPoiResult;
38    import com.baidu.mapapi.MKSearch;
39    import com.baidu.mapapi.MKSearchListener;
40    import com.baidu.mapapi.MKTransitRouteResult;
41    import com.baidu.mapapi.MKWalkingRouteResult;
42    import com.baidu.mapapi.MapActivity;
43    import com.baidu.mapapi.MapController;
44    import com.baidu.mapapi.MapView;
45    import com.baidu.mapapi.MyLocationOverlay;
46    import com.baidu.mapapi.Overlay;
47    import com.baidu.mapapi.OverlayItem;
48    import com.baidu.mapapi.PoiOverlay;
49    import com.baidu.mapapi.RouteOverlay;
50    import com.dreamcatcher.bicycle.BicycleApp;
51    import com.dreamcatcher.bicycle.R;
52    import com.dreamcatcher.bicycle.core.BicycleService;
53    import com.dreamcatcher.bicycle.dataset.BicycleDataset;
54    import com.dreamcatcher.bicycle.interfaces.IAdEvent;
55    import com.dreamcatcher.bicycle.interfaces.IHttpEvent;
56    import com.dreamcatcher.bicycle.interfaces.IHttpService;
57    import com.dreamcatcher.bicycle.interfaces.ISettingEvent;
58    import com.dreamcatcher.bicycle.util.Constants;
59    import com.dreamcatcher.bicycle.util.GlobalSetting;
60    import com.dreamcatcher.bicycle.util.Utils;
61    import com.dreamcatcher.bicycle.view.ActivityTitle;
62    import com.dreamcatcher.bicycle.view.ActivityTitle.IActivityTitleLeftImageClickEvent;
63    import com.dreamcatcher.bicycle.view.ActivityTitle.IActivityTitleRightImageClickEvent;
64    import com.dreamcatcher.bicycle.vo.Adsetting;
65    import com.dreamcatcher.bicycle.vo.BicycleNumberInfo;
66    import com.dreamcatcher.bicycle.vo.BicycleStationInfo;
67    import com.dreamcatcher.bicycle.vo.CitySetting;
68   
 
69    public class BicycleMap extends MapActivity implements IHttpEvent, ISettingEvent, IAdEvent{
70    private BMapManager mBMapManager = null;
71    private MKLocationManager mLocationManager = null;
72    private LocationListener mLocationListener = null;
73    private MapView mMapView = null;
74    private List<Overlay> mMapOverLayList = null;
75    private View mBicyclePopView = null;
76    private MapController mMapController = null;
77    private BicycleDataset mDataset = null;
78    private final static int RAT = 1000000;
79    private TextView mBicyclePopName = null;
80    private TextView mBicyclePopAvailBicycles = null;
81    private TextView mBicyclePopAvailParks = null;
82    private TextView mBicyclePopAddress = null;
83    private Button mBicyclePopBtnTo = null;
84    private TextView mBicyclePopAvailBicycleLabel = null;
85    private TextView mBicyclePopAvailParkLabel = null;
86    private Drawable mMarker = null;
87    private AdView mAdLine = null;
88    private ItemizedBicycleOverlay mMarkersOverlay = null;
89    private int mMarkerWidth = 0;
90    private int mMarkerHeight = 0;
91    private Drawable mFavoriteMarker = null;
92    private ItemizedBicycleOverlay mFavoriteMarkersOverlay = null;
93    private MyLocationOverlay mMyLocationOverlay = null;
94    private boolean mMyLocationAdded = false;
95    private boolean mMyLocationAnimationEnabled = false;
96    private CitySetting mCitySetting = null;
97    private IHttpService mHttpService = null;
98    private OverlayItem mSelectedBicycleItem = null;
99    private long mCurrentTime = 0;
100    private int mSelectedId = -1;
101    private boolean mAutoLocate = false;
102    private LinearLayout mProgressbarLine = null;
103    private boolean mNeedUpdateMyGeo = false;
104    private GeoPoint mMyPoint = null;
105    private MKSearch mMkSearch = null;
106    private RouteOverlay mRouteOverlay = null;
107    private PoiOverlay mPoiOverlay = null;
108    private ArrayList<MKPoiInfo> mPoiInfos = null;
109    private RelativeLayout mSearchBar = null;
110    private boolean mSearchBarShown = false;
111    private EditText mSearchInput = null;
112    private String mCityName = "";
113    private boolean mNeedUpdateCity = false;
114    private View mPoiPopview = null;
115    private TextView mPoiPopName = null;
116    private TextView mPoiPopAddress = null;
117    private Button mPoiPopBtn = null;
118    private OverlayItem mSelectedPoiItem = null;
119   
 
120  1 toggle @Override
121    protected void onCreate(Bundle savedInstanceState) {
122    // TODO Auto-generated method stub
123  1 super.onCreate(savedInstanceState);
124  1 setContentView(R.layout.bicycle_map);
125   
126  1 init();
127    }
128   
 
129  1 toggle private void init(){
130  1 this.addEvent();
131   
132  1 mCitySetting = GlobalSetting.getInstance().getCitySetting();
133  1 mHttpService = BicycleService.getInstance().getHttpService();
134  1 mHttpService.getAllBicyclesInfo();
135   
136  1 mBMapManager = BicycleApp.getInstance().getMapManager();
137  1 if(mBMapManager == null){
138  0 BicycleApp.getInstance().initBaiduMap();
139    }
140  1 mBMapManager.start();
141  1 super.initMapActivity(mBMapManager);
142    //init search
143  1 mMkSearch = new MKSearch();
144  1 mMkSearch.init(mBMapManager, new MySearchListener());
145   
146  1 mDataset = BicycleDataset.getInstance();
147   
148  1 mProgressbarLine = (LinearLayout) findViewById(R.id.bicycle_map_progress_line);
149   
150  1 ActivityTitle activityTitle = (ActivityTitle) findViewById(R.id.bicycle_title);
151  1 activityTitle.setActivityTitle(getText(R.string.title_map));
152   
153  1 activityTitle.setRightImage(R.drawable.ic_titlebar_locate, new IActivityTitleRightImageClickEvent() {
 
154  0 toggle @Override
155    public void onRightImageClicked() {
156  0 BicycleMap.this.toggleMyLocation();
157    }
158    }, true);
159   
160  1 activityTitle.setLeftImage(R.drawable.ic_titlebar_search, new IActivityTitleLeftImageClickEvent() {
 
161  0 toggle @Override
162    public void onLeftImageClicked() {
163  0 BicycleMap.this.toggleSearchBar();
164    }
165    }, false);
166   
167  1 mSearchBar = (RelativeLayout) findViewById(R.id.bicycle_map_search_bar);
168  1 mSearchInput = (EditText) findViewById(R.id.bicycle_map_search_input);
169   
170  1 ImageButton searchBtn = (ImageButton) findViewById(R.id.bicycle_map_search_btn);
171  1 ImageButton hideBtn = (ImageButton) findViewById(R.id.bicycle_map_search_btn_hide);
172   
173  1 searchBtn.setOnClickListener(new OnClickListener() {
 
174  0 toggle @Override
175    public void onClick(View v) {
176  0 searchPoi();
177    }
178    });
179   
180  1 hideBtn.setOnClickListener(new OnClickListener() {
 
181  0 toggle @Override
182    public void onClick(View v) {
183  0 hideSearchBar();
184    }
185    });
186   
187  1 mMapView = (MapView) findViewById(R.id.bicycle_mapview);
188  1 mMapView.setEnabled(true);
189  1 mMapView.setClickable(true);
190  1 mMapView.setBuiltInZoomControls(true);
191   
192  1 mMapController = mMapView.getController();
193  1 mMapController.setZoom(mCitySetting.getDefaultZoom());
194   
195  1 setMapSenter();
196   
197  1 mBicyclePopView = getLayoutInflater().inflate(R.layout.map_pop, null);
198  1 mBicyclePopName = (TextView) mBicyclePopView.findViewById(R.id.map_pop_name);
199  1 mBicyclePopAvailBicycles = (TextView) mBicyclePopView.findViewById(R.id.map_pop_available_bicycles);
200  1 mBicyclePopAvailParks = (TextView) mBicyclePopView.findViewById(R.id.map_pop_available_parks);
201  1 mBicyclePopAddress = (TextView) mBicyclePopView.findViewById(R.id.map_pop_address);
202  1 mBicyclePopBtnTo = (Button) mBicyclePopView.findViewById(R.id.map_pop_btn_to);
203  1 mBicyclePopAvailBicycleLabel = (TextView) mBicyclePopView.findViewById(R.id.map_pop_available_bicycles_label);
204  1 mBicyclePopAvailParkLabel = (TextView) mBicyclePopView.findViewById(R.id.map_pop_available_parks_label);
205   
206  1 mBicyclePopBtnTo.setOnClickListener(new OnClickListener() {
 
207  0 toggle @Override
208    public void onClick(View v) {
209  0 onMapPopBtnToClicked();
210    }
211    });
212   
213  1 mMapView.addView(mBicyclePopView, new MapView.LayoutParams(
214    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, null,
215    MapView.LayoutParams.BOTTOM));
216  1 mBicyclePopView.setVisibility(View.GONE);
217   
218  1 mPoiPopview = getLayoutInflater().inflate(R.layout.poi_bubble, null);
219  1 mPoiPopName = (TextView) mPoiPopview.findViewById(R.id.poi_bubble_name);
220  1 mPoiPopAddress = (TextView) mPoiPopview.findViewById(R.id.poi_bubble_address);
221  1 mPoiPopBtn = (Button) mPoiPopview.findViewById(R.id.poi_bubble_btn_to);
222   
223  1 mPoiPopBtn.setOnClickListener(new OnClickListener() {
 
224  0 toggle @Override
225    public void onClick(View v) {
226  0 searchPoiRouter();
227    }
228    });
229   
230  1 mMapView.addView(mPoiPopview, new MapView.LayoutParams(
231    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, null,
232    MapView.LayoutParams.BOTTOM));
233  1 mPoiPopview.setVisibility(View.GONE);
234   
235  1 mMapOverLayList = mMapView.getOverlays();
236   
237    //init markers
238  1 mMarker = getResources().getDrawable(R.drawable.ic_marker);
239  1 mMarkerHeight = mMarker.getIntrinsicHeight();
240  1 mMarkerWidth = mMarker.getIntrinsicWidth();
241  1 mMarker.setBounds(0, 0, mMarkerWidth, mMarkerHeight);
242   
243  1 mMarkersOverlay = new ItemizedBicycleOverlay(mMarker, this);
244   
245  1 mFavoriteMarker = getResources().getDrawable(R.drawable.ic_marker_favorite);
246  1 mFavoriteMarker.setBounds(0, 0, mMarkerWidth, mMarkerHeight);
247   
248  1 mFavoriteMarkersOverlay = new ItemizedBicycleOverlay(mFavoriteMarker, this);
249   
250    //add all bicycle marks
251  1 addAllBicycleMarkers();
252   
253  1 mAutoLocate = Utils.getBooleanDataFromLocal(Constants.LocalStoreTag.AUTO_LOCATE_ON_STARTUP, false);
254   
255    //add my location if auto locate set
256  1 if(mAutoLocate){
257  0 addMyLocation();
258  0 enalbeMyLocationAnimation();
259    }
260    //check whether need show ad
261  1 checkAd(true);
262    }
263   
 
264  2 toggle private void checkAd(boolean create){
265  2 Adsetting adsetting = GlobalSetting.getInstance().getAdsetting();
266  2 long nextShowAdTime = adsetting.getNextShowAdTime();
267   
268  2 if(System.currentTimeMillis() > nextShowAdTime){
269  2 if(create){
270  1 mAdLine = (AdView)findViewById(R.id.AdLinearLayout);
271  1 AdManager.init(this, "1eee45f1c2e37b1b", "92537a922838d9e8", 30, false);
272    }
273    }else {
274  0 if(mAdLine != null){
275  0 mAdLine.setVisibility(View.GONE);
276    }
277    }
278    }
279   
 
280  0 toggle private void toggleSearchBar(){
281  0 if(mSearchBarShown){
282  0 hideSearchBar();
283    }else {
284  0 Animation animation = AnimationUtils.loadAnimation(this, R.anim.slide_down);
285  0 mSearchBar.setVisibility(View.VISIBLE);
286  0 mSearchBar.startAnimation(animation);
287  0 mSearchBarShown = true;
288    }
289    }
290   
 
291  3 toggle private void setMapSenter(){
292  3 GeoPoint centerPoint = new GeoPoint(
293    (int) ((mCitySetting.getDefaultLatitude() + mCitySetting.getOffsetLatitude()) * RAT),
294    (int) ((mCitySetting.getDefaultLongitude() + mCitySetting.getOffsetLongitude()) * RAT));
295   
296  3 mMapController.setCenter(centerPoint);
297    }
298   
 
299  1 toggle private void addEvent(){
300  1 BicycleService.getInstance().getHttpEventListener().addEvent(this);
301  1 BicycleService.getInstance().getSettingEventListener().addEvent(this);
302  1 BicycleService.getInstance().getAdEventListener().addEvent(this);
303    }
304   
 
305  0 toggle private void removeEvent(){
306  0 BicycleService.getInstance().getHttpEventListener().removeEvent(this);
307  0 BicycleService.getInstance().getSettingEventListener().removeEvent(this);
308  0 BicycleService.getInstance().getAdEventListener().removeEvent(this);
309    }
310   
 
311  0 toggle private void onMapPopBtnToClicked(){
312  0 Toast.makeText(this, R.string.toast_msg_searching_router, Toast.LENGTH_SHORT).show();
313   
314  0 GeoPoint geoPoint = this.mSelectedBicycleItem.getPoint();
315  0 if(mMyPoint == null){
316  0 mNeedUpdateMyGeo = true;
317  0 getMyLocation();
318    }else {
319  0 MKPlanNode start = new MKPlanNode();
320  0 start.pt = mMyPoint;
321  0 MKPlanNode end = new MKPlanNode();
322  0 end.pt = geoPoint;
323   
324  0 mMkSearch.walkingSearch(null, start, null, end);
325  0 mNeedUpdateMyGeo = false;
326    }
327    }
328   
329    //search poi
 
330  0 toggle private void searchPoi(){
331  0 String searchKey = mSearchInput.getText().toString();
332  0 if("".equals(searchKey.trim())){
333  0 return;
334    }
335   
336  0 if(mPoiOverlay != null){
337  0 mMapOverLayList.remove(mPoiOverlay);
338  0 mMapView.invalidate();
339    }
340   
341  0 if("".equals(mCityName)){
342  0 mNeedUpdateCity = true;
343  0 getMyLocation();
344    }else {
345  0 mProgressbarLine.setVisibility(View.VISIBLE);
346    // mMkSearch.poiSearchInCity(mCityName, searchKey);
347    //search 50km
348  0 mMkSearch.poiSearchNearBy(searchKey, mMyPoint, 50000);
349  0 mNeedUpdateCity = false;
350    }
351    }
352   
 
353  0 toggle private void hideSearchBar(){
354  0 Animation animation = AnimationUtils.loadAnimation(BicycleMap.this, R.anim.slide_up);
355  0 mSearchBar.startAnimation(animation);
356  0 mSearchBar.setVisibility(View.GONE);
357  0 mSearchBarShown = false;
358    }
359   
 
360  0 toggle private void getMyLocation(){
361  0 if (!mMyLocationAdded) {
362  0 addMyLocation();
363    }
364    }
365   
 
366  0 toggle private void toggleMyLocation(){
367  0 if(!mMyLocationAdded){
368  0 addMyLocation();
369    }
370  0 if(mMyLocationAnimationEnabled){
371  0 disableMyLocationAnimation();
372    }else {
373  0 enalbeMyLocationAnimation();
374    }
375    }
376   
 
377  0 toggle private void enalbeMyLocationAnimation(){
378  0 mMyLocationAnimationEnabled = true;
379  0 if(mMyPoint != null){
380  0 mMapController.animateTo(mMyPoint);
381    }
382    }
383   
 
384  0 toggle private void disableMyLocationAnimation(){
385  0 mMyLocationAnimationEnabled = false;
386    }
387   
 
388  0 toggle private void addMyLocation(){
389    //Add my location
390  0 mLocationManager = mBMapManager.getLocationManager();
391   
392  0 mLocationManager.enableProvider(MKLocationManager.MK_NETWORK_PROVIDER);
393  0 mLocationManager.enableProvider(MKLocationManager.MK_GPS_PROVIDER);
394   
395  0 mMyLocationOverlay = new MyLocationOverlay(this, mMapView);
396   
397  0 mLocationListener = new LocationListener() {
 
398  0 toggle public void onLocationChanged(Location location) {
399  0 mMyPoint = new GeoPoint((int)(location.getLatitude() * RAT), (int)(location.getLongitude() * RAT));
400  0 if(mMyLocationAnimationEnabled){
401  0 mMapController.animateTo(mMyPoint);
402    }
403   
404  0 if(mNeedUpdateMyGeo){
405  0 onMapPopBtnToClicked();
406    }
407  0 if("".equals(mCityName)){
408  0 mMkSearch.reverseGeocode(mMyPoint);
409    }
410    }
411    };
412   
413  0 mMapView.getOverlays().add(mMyLocationOverlay);
414   
415  0 mMyLocationOverlay.enableCompass();
416  0 mMyLocationOverlay.enableMyLocation();
417   
418  0 mBMapManager.stop();
419  0 mLocationManager.requestLocationUpdates(mLocationListener);
420  0 mBMapManager.start();
421   
422  0 mMyLocationAdded = true;
423    }
424   
425   
426    /**
427    * add all the bicycle marks in map
428    * @param overlayList
429    */
 
430  11 toggle private void addAllBicycleMarkers(){
431  11 ArrayList<BicycleStationInfo> bicycleInfos = mDataset.getBicycleStationInfos();
432  11 String[] favoriteIds = getFavoriteIds();
433  11 if(mMarkersOverlay != null){
434  11 mMarkersOverlay.clearAllOverlayItem();
435    }
436  11 if(mFavoriteMarkersOverlay != null){
437  11 mFavoriteMarkersOverlay.clearAllOverlayItem();
438    }
439   
440   
441  741 for(int i = 0, count = bicycleInfos.size(); i < count; i++){
442  730 BicycleStationInfo bicycleInfo = bicycleInfos.get(i);
443  730 GeoPoint point = new GeoPoint((int)((mCitySetting.getOffsetLatitude() + bicycleInfo.getLatitude()) * RAT), (int)((mCitySetting.getOffsetLongitude() + bicycleInfo.getLongitude()) * RAT));
444  730 OverlayItem overlayItem = new OverlayItem(point, String.valueOf(bicycleInfo.getId()), bicycleInfo.getName());
445  730 int bicycleId = bicycleInfo.getId();
446  730 if(favoriteIds!= null && isInArray(bicycleId, favoriteIds)){
447  21 mFavoriteMarkersOverlay.addOverlayItem(overlayItem);
448    }else {
449  709 mMarkersOverlay.addOverlayItem(overlayItem);
450    }
451    }
452  11 if(mMarkersOverlay.size() > 0){
453  11 mMapOverLayList.add(mMarkersOverlay);
454    }
455   
456  11 if(mFavoriteMarkersOverlay.size() > 0){
457  8 mMapOverLayList.add(mFavoriteMarkersOverlay);
458    }
459    }
460   
 
461  11 toggle private String[] getFavoriteIds(){
462  11 String favoriteIds = Utils.getStringDataFromLocal(Constants.LocalStoreTag.FAVORITE_IDS);
463  11 if(favoriteIds == null || favoriteIds.equals("")){
464  3 return null;
465    }
466  8 String[] favoriteIdArray = favoriteIds.split("\\|");
467  8 return favoriteIdArray;
468   
469    }
470   
 
471  544 toggle private boolean isInArray(int index, String[] idArray){
472  544 boolean result = false;
473  544 for(String id : idArray){
474  1404 if(Integer.parseInt(id) == index){
475  21 result = true;
476  21 break;
477    }
478    }
479  544 return result;
480    }
481   
 
482  8 toggle private void removeAllBicyleMarkers(){
483  8 if(mMarkersOverlay.size() >= 0){
484  8 mMapOverLayList.remove(mMarkersOverlay);
485    }
486   
487  8 if(mFavoriteMarkersOverlay.size() >= 0){
488  8 mMapOverLayList.remove(mFavoriteMarkersOverlay);
489    }
490    }
491   
 
492  2 toggle private void reLoadUI(){
493    //set map center
494  2 mCitySetting = GlobalSetting.getInstance().getCitySetting();
495  2 mBicyclePopView.setVisibility(View.GONE);
496   
497  2 mMapOverLayList.clear();
498  2 setMapSenter();
499   
500    //add all overlay
501  2 addAllBicycleMarkers();
502  2 mMapView.invalidate();
503    }
504   
 
505  0 toggle @Override
506    public void onBackPressed() {
507  0 this.getParent().onBackPressed();
508    }
509   
 
510  0 toggle @Override
511    protected void onDestroy() {
512  0 if(mBMapManager != null){
513  0 if(mLocationManager != null){
514  0 mLocationManager.removeUpdates(mLocationListener);
515    }
516    }
517   
518  0 this.removeEvent();
519  0 super.onDestroy();
520    }
521   
 
522  1 toggle @Override
523    protected void onPause() {
524  1 if (mBMapManager != null) {
525  1 if (mLocationManager != null) {
526  0 mLocationManager.removeUpdates(mLocationListener);
527    }
528  1 mBMapManager.stop();
529    }
530  1 super.onPause();
531    }
532   
 
533  1 toggle @Override
534    protected void onResume() {
535  1 if (mBMapManager != null) {
536  1 if (mLocationManager != null && mMyLocationAdded) {
537  0 mLocationManager.requestLocationUpdates(mLocationListener);
538    }
539  1 mBMapManager.start();
540    }
541  1 super.onResume();
542    }
543   
 
544  0 toggle @Override
545    protected boolean isRouteDisplayed() {
546  0 return false;
547    }
548   
 
549    private class ItemizedBicycleOverlay extends ItemizedOverlay<OverlayItem>{
550    private ArrayList<OverlayItem> mOverlayItems = new ArrayList<OverlayItem>();
551   
 
552  0 toggle public ItemizedBicycleOverlay(Drawable defaultMarker) {
553  0 super(boundCenterBottom(defaultMarker));
554    }
555   
 
556  2 toggle public ItemizedBicycleOverlay(Drawable marker, Context context){
557  2 super(boundCenterBottom(marker));
558    }
559   
 
560  23295 toggle @Override
561    protected OverlayItem createItem(int i) {
562  23295 return mOverlayItems.get(i);
563    }
564   
 
565  0 toggle @Override
566    protected boolean onTap(int index) {
567  0 OverlayItem overlayItem = mOverlayItems.get(index);
568  0 mSelectedBicycleItem = overlayItem;
569  0 setFocus(overlayItem);
570   
571  0 int bicycleId = Integer.parseInt(overlayItem.getTitle());
572   
573  0 if(System.currentTimeMillis() - mCurrentTime > 2000){
574  0 mCurrentTime = System.currentTimeMillis();
575  0 mSelectedId = bicycleId;
576   
577    //show bicycle info first
578  0 BicycleStationInfo bicycleStationInfo = mDataset.getBicycleInfo(mSelectedId);
579  0 showBicyclePopContent(bicycleStationInfo);
580   
581    //if need refresh single bicycle info, get from server
582  0 if(mCitySetting.isRefreshSingle()){
583  0 mProgressbarLine.setVisibility(View.VISIBLE);
584  0 mHttpService.getSingleBicycleInfo(bicycleId);
585    }
586    }
587  0 return true;
588    }
589   
 
590  0 toggle @Override
591    public boolean onTap(GeoPoint point, MapView mapView) {
592  0 mBicyclePopView.setVisibility(View.GONE);
593  0 return super.onTap(point, mapView);
594    }
595   
 
596  768 toggle @Override
597    public int size() {
598  768 return mOverlayItems.size();
599    }
600   
 
601  730 toggle public void addOverlayItem(OverlayItem overlayItem){
602  730 mOverlayItems.add(overlayItem);
603  730 this.populate();
604    }
605   
 
606  22 toggle public void clearAllOverlayItem(){
607  22 mOverlayItems.clear();
608    }
609    }
610   
 
611  0 toggle private void showBicyclePopContent(BicycleStationInfo bicycleStationInfo){
612  0 if(bicycleStationInfo == null){
613  0 return;
614    }
615  0 mBicyclePopName.setText(bicycleStationInfo.getName());
616  0 mBicyclePopAddress.setText(bicycleStationInfo.getAddress());
617   
618  0 if(mCitySetting.isShowBicycleNumber()){
619  0 mBicyclePopAvailBicycles.setText(String.valueOf(bicycleStationInfo.getAvailable()));
620  0 mBicyclePopAvailParks.setText(String.valueOf(bicycleStationInfo.getCapacity() - bicycleStationInfo.getAvailable()));
621  0 mBicyclePopAvailBicycleLabel.setVisibility(View.VISIBLE);
622  0 mBicyclePopAvailBicycles.setVisibility(View.VISIBLE);
623  0 mBicyclePopAvailParkLabel.setVisibility(View.VISIBLE);
624  0 mBicyclePopAvailParks.setVisibility(View.VISIBLE);
625    }else{
626  0 mBicyclePopAvailBicycleLabel.setVisibility(View.GONE);
627  0 mBicyclePopAvailBicycles.setVisibility(View.GONE);
628  0 mBicyclePopAvailParkLabel.setVisibility(View.GONE);
629  0 mBicyclePopAvailParks.setVisibility(View.GONE);
630    }
631   
632  0 GeoPoint geoPoint = this.mSelectedBicycleItem.getPoint();
633  0 Point point = mMapView.getProjection().toPixels(geoPoint, null);
634  0 int posX = point.x - mMarkerWidth,
635    poxY = point.y - mMarkerHeight;
636  0 GeoPoint toShowPoint = mMapView.getProjection().fromPixels(posX, poxY);
637   
638  0 mMapView.updateViewLayout(mBicyclePopView, new MapView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
639    toShowPoint, MapView.LayoutParams.BOTTOM));
640  0 mBicyclePopView.setVisibility(View.VISIBLE);
641    }
642   
 
643    private class MySearchListener implements MKSearchListener{
644   
 
645  0 toggle @Override
646    public void onGetAddrResult(MKAddrInfo result, int error) {
647  0 if(error != 0 || result == null){
648  0 return;
649    }
650  0 if(result.poiList != null && result.poiList.size() > 0){
651  0 MKPoiInfo poiInfo = result.poiList.get(0);
652  0 mCityName = poiInfo.city;
653  0 if(mNeedUpdateCity){
654  0 searchPoi();
655    }
656    }
657    }
658   
 
659  0 toggle @Override
660    public void onGetDrivingRouteResult(MKDrivingRouteResult result, int error) {
661    // TODO Auto-generated method stub
662   
663    }
664   
 
665  0 toggle @Override
666    public void onGetPoiResult(MKPoiResult result, int type, int error) {
667  0 mProgressbarLine.setVisibility(View.GONE);
668   
669  0 if(error != 0 || result == null){
670  0 Toast.makeText(BicycleMap.this, R.string.toast_msg_no_poi_result, Toast.LENGTH_SHORT).show();
671  0 return;
672    }
673   
674  0 if(mPoiOverlay != null){
675  0 mMapOverLayList.remove(mPoiOverlay);
676    }
677  0 if(mRouteOverlay != null){
678  0 mMapOverLayList.remove(mRouteOverlay);
679    }
680   
681  0 mMapView.invalidate();
682   
683  0 if(result.getCurrentNumPois() > 0){
684  0 mPoiOverlay = new MyPoiOverlay(BicycleMap.this, mMapView);
685  0 mPoiInfos = result.getAllPoi();
686  0 mPoiOverlay.setData(mPoiInfos);
687   
688  0 mMapOverLayList.add(mPoiOverlay);
689  0 mMapView.invalidate();
690  0 mMapController.animateTo(result.getPoi(0).pt);
691  0 hideSearchBar();
692  0 hideKeyBoard();
693    }else {
694  0 hideKeyBoard();
695  0 Toast.makeText(BicycleMap.this, R.string.toast_msg_no_poi_result, Toast.LENGTH_SHORT).show();
696    }
697    }
698   
 
699  0 toggle @Override
700    public void onGetTransitRouteResult(MKTransitRouteResult result, int error) {
701    // TODO Auto-generated method stub
702   
703    }
704   
 
705  0 toggle @Override
706    public void onGetWalkingRouteResult(MKWalkingRouteResult result, int error) {
707  0 mProgressbarLine.setVisibility(View.GONE);
708   
709  0 if(error != 0 || result == null){
710  0 Toast.makeText(BicycleMap.this, R.string.toast_msg_warking_router_search_failed, Toast.LENGTH_SHORT).show();
711  0 return;
712    }
713   
714  0 if(mRouteOverlay != null){
715  0 mMapOverLayList.remove(mRouteOverlay);
716    }
717   
718  0 mRouteOverlay = new RouteOverlay(BicycleMap.this, mMapView);
719  0 mRouteOverlay.setData(result.getPlan(0).getRoute(0));
720  0 mMapOverLayList.add(mRouteOverlay);
721  0 mMapView.invalidate();
722  0 mBicyclePopView.setVisibility(View.GONE);
723  0 mPoiPopview.setVisibility(View.GONE);
724    }
725    }
726   
 
727    private class MyPoiOverlay extends PoiOverlay{
 
728  0 toggle public MyPoiOverlay(Activity avtivity, MapView mapView) {
729  0 super(avtivity, mapView);
730    }
731   
 
732  0 toggle @Override
733    public boolean onTap(GeoPoint point, MapView mapView) {
734  0 mPoiPopview.setVisibility(View.GONE);
735  0 return super.onTap(point, mapView);
736    }
737   
 
738  0 toggle @Override
739    protected boolean onTap(int index) {
740  0 mSelectedPoiItem = getItem(index);
741  0 int height = mSelectedPoiItem.getMarker(index).getIntrinsicWidth();
742  0 showPoiPopContent(index, height);
743  0 return true;
744    }
745    }
746   
 
747  0 toggle private void showPoiPopContent(int index, int height){
748  0 MKPoiInfo poiInfo = mPoiInfos.get(index);
749  0 if(poiInfo == null){
750  0 return;
751    }
752   
753  0 String name = poiInfo.name;
754  0 String address = poiInfo.address;
755  0 mPoiPopName.setText(name);
756  0 mPoiPopAddress.setText(address);
757   
758  0 GeoPoint geoPoint = poiInfo.pt;
759  0 Point point = mMapView.getProjection().toPixels(geoPoint, null);
760  0 int posX = point.x,
761    poxY = point.y - height;
762  0 GeoPoint toShowPoint = mMapView.getProjection().fromPixels(posX, poxY);
763   
764  0 mMapView.updateViewLayout(mPoiPopview, new MapView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
765    toShowPoint, MapView.LayoutParams.BOTTOM));
766   
767  0 mPoiPopview.setVisibility(View.VISIBLE);
768    }
769   
 
770  0 toggle private void searchPoiRouter(){
771  0 if(mSelectedPoiItem == null){
772  0 return;
773    }
774   
775  0 GeoPoint geoPoint = mSelectedPoiItem.getPoint();
776   
777  0 MKPlanNode start = new MKPlanNode();
778  0 start.pt = mMyPoint;
779  0 MKPlanNode end = new MKPlanNode();
780  0 end.pt = geoPoint;
781   
782  0 Toast.makeText(this, R.string.toast_msg_searching_router, Toast.LENGTH_SHORT).show();
783   
784  0 mMkSearch.walkingSearch(null, start, null, end);
785    }
786   
 
787  0 toggle private void hideKeyBoard(){
788  0 ((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(getCurrentFocus()
789    .getWindowToken(), 0);
790    }
791   
792    /**
793    * on All bicycles info received
794    */
 
795  3 toggle public void onAllBicyclesInfoReceived(int resultCode) {
796  3 if(resultCode == Constants.ResultCode.NETWORK_DISCONNECT){
797  0 Toast.makeText(this, R.string.toast_msg_network_error, Toast.LENGTH_SHORT);
798    }
799    }
800   
801    /**
802    * on single bicycle info received
803    */
 
804  0 toggle public void onSingleBicycleNumberInfoReceived(
805    BicycleNumberInfo bicycleNumberInfo, int resultCode) {
806  0 mProgressbarLine.setVisibility(View.GONE);
807  0 if(resultCode == Constants.ResultCode.SUCCESS){
808  0 int id = bicycleNumberInfo.getId();
809  0 BicycleStationInfo bicycleStationInfo = mDataset.getBicycleInfo(id);
810    //update bicycle number
811  0 bicycleStationInfo.setCapacity(bicycleNumberInfo.getCapacity());
812  0 bicycleStationInfo.setAvailable(bicycleNumberInfo.getAvailable());
813   
814  0 showBicyclePopContent(bicycleStationInfo);
815  0 mDataset.updateBicycleInfo(mSelectedId, bicycleStationInfo);
816  0 }else if(resultCode == Constants.ResultCode.NETWORK_DISCONNECT){
817  0 Toast.makeText(this, R.string.toast_msg_network_error, Toast.LENGTH_SHORT).show();
818    }else {
819  0 Toast.makeText(this, R.string.toast_msg_server_unavailable, Toast.LENGTH_SHORT).show();
820    }
821    }
822   
 
823  1 toggle public void onNewVersionCheckCompleted(boolean needUpdate, int resultCode) {
824   
825    }
826   
827    /**
828    * when city setting changed, reload UI
829    */
 
830  2 toggle public void onCitySettingChanged(int resultCode) {
831  2 if(resultCode == Constants.ResultCode.SUCCESS){
832  2 reLoadUI();
833    }
834    }
835   
 
836  8 toggle public void onFavoriteIdsChanged() {
837  8 removeAllBicyleMarkers();
838  8 addAllBicycleMarkers();
839  8 mMapView.invalidate();
840    }
841   
 
842  1 toggle @Override
843    public void onPointsUpdated(String currencyName, int totalPoint) {
844    //check whether need to show ad
845  1 checkAd(false);
846    }
847   
 
848  0 toggle @Override
849    public void onPointsUpdateFailed(String error) {
850   
851    }
852    }