Clover Coverage Report - Main Coverage Report
Coverage timestamp: ven dic 19 2014 16:47:52 EST
../../../../img/srcFileCovDistChart7.png 35% of files have more coverage
87   212   32   5,8
28   167   0,37   15
15     2,13  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  MapSettingActivity       Line # 22 87 32 61,5% 0.61538464
 
No Tests
 
1    package com.dreamcatcher.bicycle.activity;
2   
3    import android.app.Activity;
4    import android.os.Bundle;
5    import android.view.View;
6    import android.view.View.OnClickListener;
7    import android.widget.ImageView;
8    import android.widget.RelativeLayout;
9    import android.widget.TextView;
10    import android.widget.Toast;
11   
12    import com.baidu.mapapi.BMapManager;
13    import com.baidu.mapapi.MKOLUpdateElement;
14    import com.baidu.mapapi.MKOfflineMap;
15    import com.baidu.mapapi.MKOfflineMapListener;
16    import com.dreamcatcher.bicycle.BicycleApp;
17    import com.dreamcatcher.bicycle.R;
18    import com.dreamcatcher.bicycle.util.Constants;
19    import com.dreamcatcher.bicycle.util.Utils;
20    import com.dreamcatcher.bicycle.view.ActivityTitle;
21   
 
22    public class MapSettingActivity extends Activity implements MKOfflineMapListener{
23    private ImageView mAutoLocateImage = null;
24    private ImageView mShowFavoriteImage = null;
25    private TextView mOfflineMapPercentage = null;
26   
27    private BMapManager mMapManger = null;
28    private MKOfflineMap mOfflineMap = null;
29    private int mCityId = -1;
30   
 
31  2 toggle @Override
32    protected void onCreate(Bundle savedInstanceState) {
33    // TODO Auto-generated method stub
34  2 super.onCreate(savedInstanceState);
35  2 setContentView(R.layout.map_setting);
36  2 init();
37    }
38   
 
39  2 toggle private void init(){
40  2 mMapManger = BicycleApp.getInstance().getMapManager();
41  2 if(mMapManger == null){
42  0 BicycleApp.getInstance().initBaiduMap();
43    }
44  2 mMapManger.start();
45   
46  2 ActivityTitle activityTitle = (ActivityTitle) findViewById(R.id.bicycle_title);
47  2 activityTitle.setActivityTitle(R.string.title_map_setting);
48   
49  2 mOfflineMapPercentage = (TextView) findViewById(R.id.map_setting_download_offline_map_percentage);
50  2 int offlinePercentage = Utils.getIntDataFromLocal(Constants.LocalStoreTag.OFFLINE_MAP_PERCENTAGE, 0);
51  2 if(offlinePercentage > 0){
52  0 showOfflineMapPercentage(offlinePercentage);
53    }
54   
55  2 RelativeLayout autoLocateLine = (RelativeLayout) findViewById(R.id.map_setting_auto_locate);
56  2 mAutoLocateImage = (ImageView) findViewById(R.id.map_setting_auto_locate_image);
57   
58  2 boolean autoLocate = Utils.getBooleanDataFromLocal(Constants.LocalStoreTag.AUTO_LOCATE_ON_STARTUP, false);
59  2 mAutoLocateImage.setSelected(autoLocate);
60   
61  2 autoLocateLine.setOnClickListener(new OnClickListener() {
 
62  2 toggle public void onClick(View v) {
63  2 onAutoLocateLineClicked();
64    }
65    });
66   
67  2 RelativeLayout downloadOfflineMap = (RelativeLayout) findViewById(R.id.map_setting_download_offline_map);
68  2 downloadOfflineMap.setOnClickListener(new OnClickListener() {
 
69  1 toggle public void onClick(View v) {
70  1 downloadOfflineMap();
71    }
72    });
73   
74  2 RelativeLayout showNearSpot = (RelativeLayout) findViewById(R.id.map_setting_show_nearest_spots);
75   
76    // int showNearestSpot = Utils.getIntDataFromLocal(Constants.LocalStoreTag.SHOW_NEAREST_SPOTS, -1);
77   
78   
79  2 showNearSpot.setOnClickListener(new OnClickListener() {
 
80  0 toggle public void onClick(View v) {
81  0 onShowNearSpotsClicked();
82    }
83    });
84   
85  2 RelativeLayout showFavorites = (RelativeLayout) findViewById(R.id.map_setting_show_favorites);
86  2 mShowFavoriteImage = (ImageView) findViewById(R.id.map_setting_show_favorites_image);
87   
88  2 boolean showFavorite = Utils.getBooleanDataFromLocal(Constants.LocalStoreTag.SHOW_FAVORITE_SPOTS, false);
89  2 mShowFavoriteImage.setSelected(showFavorite);
90   
91  2 showFavorites.setOnClickListener(new OnClickListener() {
 
92  3 toggle public void onClick(View v) {
93  3 onShowFavoritesClicked();
94    }
95    });
96    }
97   
 
98  2 toggle @Override
99    protected void onResume() {
100  2 super.onResume();
101  2 if(mMapManger != null){
102  2 mMapManger.start();
103    }
104    }
105   
 
106  2 toggle @Override
107    protected void onPause() {
108  2 if(mMapManger != null){
109  2 mMapManger.stop();
110    }
111  2 super.onPause();
112    }
113   
 
114  0 toggle private void showOfflineMapPercentage(int percentage){
115  0 if(percentage == 0){
116  0 return;
117    }
118  0 mOfflineMapPercentage.setText(String.format(getText(R.string.map_setting_download_offline_map_percentage).toString(), percentage));
119    }
120   
 
121  2 toggle private void onAutoLocateLineClicked(){
122  2 boolean selected = mAutoLocateImage.isSelected();
123  2 mAutoLocateImage.setSelected(!selected);
124  2 Utils.storeBooleanDataToLocal(Constants.LocalStoreTag.AUTO_LOCATE_ON_STARTUP, !selected);
125    }
126   
127    /**
128    * download offline map
129    */
 
130  1 toggle private void downloadOfflineMap(){
131  1 mOfflineMap = new MKOfflineMap();
132  1 mOfflineMap.init(mMapManger, this);
133   
134  1 int networkInfo = Utils.getNetworkInfo();
135    //network unavailable
136  1 if(networkInfo == Constants.NetworkInfo.DISCONNECT){
137  0 Toast.makeText(this, R.string.toast_msg_network_error, Toast.LENGTH_SHORT).show();
138  0 return;
139    }
140    //not wifi
141  1 if(networkInfo != Constants.NetworkInfo.WIFI){
142  0 Toast.makeText(this, R.string.map_setting_download_offline_map_network_not_wifi_msg, Toast.LENGTH_SHORT).show();
143  0 return;
144    }
145   
146  1 mCityId = Constants.CitySetting.CITY_MAP_ID[getCityIndex()];
147   
148  1 MKOLUpdateElement mapInfo = mOfflineMap.getUpdateInfo(mCityId);
149   
150  1 String startMsg = "";
151   
152  1 if(mapInfo != null){
153  0 if(mapInfo.ratio == 100){
154  0 Toast.makeText(this, getText(R.string.map_setting_map_already_complete), Toast.LENGTH_LONG).show();
155  0 return;
156  0 }else if(mapInfo.ratio != 0){
157  0 startMsg = getText(R.string.map_setting_download_offline_map_already_downloaded).toString();
158    }else {
159  0 startMsg = getText(R.string.map_setting_download_offline_map_started).toString();
160    }
161    }
162   
163  1 if(mOfflineMap.start(mCityId)){
164  0 Toast.makeText(this, startMsg, Toast.LENGTH_LONG).show();
165    }else {
166  1 Toast.makeText(this, getText(R.string.map_setting_download_offline_map_start_failed), Toast.LENGTH_SHORT).show();
167    }
168    }
169   
 
170  1 toggle private int getCityIndex(){
171  1 String currentCityTag = Utils.getStringDataFromLocal(Constants.LocalStoreTag.CITY_NAME);
172  1 int index = -1;
173  4 for(int i = 0, n = Constants.CitySetting.CITY_TAG.length; i < n; i++){
174  4 if (currentCityTag.equalsIgnoreCase(Constants.CitySetting.CITY_TAG[i])){
175  1 index = i;
176  1 break;
177    }
178    }
179  1 return index;
180    }
181   
 
182  0 toggle private void onShowNearSpotsClicked(){
183   
184    }
185   
186   
 
187  3 toggle private void onShowFavoritesClicked(){
188  3 boolean selected = mShowFavoriteImage.isSelected();
189  3 mShowFavoriteImage.setSelected(!selected);
190  3 Utils.storeBooleanDataToLocal(Constants.LocalStoreTag.SHOW_FAVORITE_SPOTS, !selected);
191    }
192   
 
193  0 toggle public void onGetOfflineMapState(int type, int state) {
194  0 switch (type) {
195  0 case MKOfflineMap.TYPE_DOWNLOAD_UPDATE:
196  0 MKOLUpdateElement update = mOfflineMap.getUpdateInfo(state);
197  0 if (update.ratio == 100) {
198  0 Toast.makeText(BicycleApp.getInstance(),getText(R.string.map_setting_download_offline_map_complete), Toast.LENGTH_SHORT).show();
199    }else {
200  0 showOfflineMapPercentage(update.ratio);
201  0 Utils.storeIntDataToLocal(Constants.LocalStoreTag.OFFLINE_MAP_PERCENTAGE, update.ratio);
202    }
203   
204  0 break;
205  0 case MKOfflineMap.TYPE_NEW_OFFLINE:
206  0 break;
207  0 case MKOfflineMap.TYPE_VER_UPDATE:
208  0 break;
209    }
210   
211    }
212    }