1 |
|
package com.dreamcatcher.bicycle.activity; |
2 |
|
|
3 |
|
import android.app.Activity; |
4 |
|
import android.app.ProgressDialog; |
5 |
|
import android.os.Bundle; |
6 |
|
import android.view.View; |
7 |
|
import android.view.View.OnClickListener; |
8 |
|
import android.widget.Button; |
9 |
|
import android.widget.ListView; |
10 |
|
import android.widget.Toast; |
11 |
|
|
12 |
|
import com.dreamcatcher.bicycle.R; |
13 |
|
import com.dreamcatcher.bicycle.adapter.CityListAdapter; |
14 |
|
import com.dreamcatcher.bicycle.adapter.CityListAdapter.ICityListEvent; |
15 |
|
import com.dreamcatcher.bicycle.core.BicycleService; |
16 |
|
import com.dreamcatcher.bicycle.interfaces.ISettingEvent; |
17 |
|
import com.dreamcatcher.bicycle.interfaces.ISettingService; |
18 |
|
import com.dreamcatcher.bicycle.util.Constants; |
19 |
|
import com.dreamcatcher.bicycle.util.Utils; |
20 |
|
import com.dreamcatcher.bicycle.view.ActivityTitle; |
21 |
|
|
|
|
| 86,4% |
Uncovered Elements: 8 (59) |
Complexity: 16 |
Complexity Density: 0,42 |
|
22 |
|
public class ChangeCityActivity extends Activity implements ISettingEvent{ |
23 |
|
private int mSelectedCityIndex = -1; |
24 |
|
private ISettingService mSettingService = null; |
25 |
|
private ProgressDialog mProgressDialog = null; |
26 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
27 |
3
|
@Override... |
28 |
|
protected void onCreate(Bundle savedInstanceState) { |
29 |
3
|
super.onCreate(savedInstanceState); |
30 |
3
|
setContentView(R.layout.change_city); |
31 |
3
|
this.init(); |
32 |
|
} |
33 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0,1 |
|
34 |
3
|
private void init(){ ... |
35 |
3
|
mSettingService = BicycleService.getInstance().getSettingService(); |
36 |
3
|
this.addEvent(); |
37 |
|
|
38 |
3
|
ActivityTitle activityTitle = (ActivityTitle) findViewById(R.id.bicycle_title); |
39 |
3
|
activityTitle.setActivityTitle(R.string.title_change_city); |
40 |
|
|
41 |
3
|
ListView listView = (ListView) findViewById(R.id.change_city_list); |
42 |
|
|
43 |
3
|
ICityListEvent citySelectEvent = new ICityListEvent() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
44 |
2
|
public void onCityItemClicked(int index) {... |
45 |
2
|
mSelectedCityIndex = index; |
46 |
|
} |
47 |
|
}; |
48 |
|
|
49 |
3
|
CityListAdapter adapter = new CityListAdapter(citySelectEvent, getCurrentCityIndex()); |
50 |
|
|
51 |
3
|
listView.setAdapter(adapter); |
52 |
|
|
53 |
3
|
Button reloadBtn = (Button) findViewById(R.id.change_city_reload_btn); |
54 |
3
|
reloadBtn.setOnClickListener(new OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
55 |
2
|
public void onClick(View v) {... |
56 |
2
|
onReloadtBtnClicked(); |
57 |
|
} |
58 |
|
}); |
59 |
|
} |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
61 |
3
|
@Override... |
62 |
|
protected void onDestroy() { |
63 |
3
|
this.removeEvent(); |
64 |
3
|
super.onDestroy(); |
65 |
|
} |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
3
|
private void addEvent(){... |
68 |
3
|
BicycleService.getInstance().getSettingEventListener().addEvent(this); |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
3
|
private void removeEvent(){... |
72 |
3
|
BicycleService.getInstance().getSettingEventListener().removeEvent(this); |
73 |
|
} |
74 |
|
|
|
|
| 77,8% |
Uncovered Elements: 2 (9) |
Complexity: 3 |
Complexity Density: 0,6 |
|
75 |
3
|
private int getCurrentCityIndex(){... |
76 |
3
|
String currentCity = Utils.getStringDataFromLocal(Constants.LocalStoreTag.CITY_NAME); |
77 |
13
|
for(int i = 0, n = Constants.CitySetting.CITY_TAG.length; i < n; i++){ |
78 |
13
|
if(currentCity.equalsIgnoreCase(Constants.CitySetting.CITY_TAG[i])){ |
79 |
3
|
return i; |
80 |
|
} |
81 |
|
} |
82 |
0
|
return -1; |
83 |
|
} |
84 |
|
|
|
|
| 80% |
Uncovered Elements: 2 (10) |
Complexity: 2 |
Complexity Density: 0,25 |
|
85 |
2
|
private void onReloadtBtnClicked(){... |
86 |
2
|
String currentCity = Utils.getStringDataFromLocal(Constants.LocalStoreTag.CITY_NAME); |
87 |
2
|
String selectedCity = Constants.CitySetting.CITY_TAG[mSelectedCityIndex]; |
88 |
2
|
if(currentCity.equalsIgnoreCase(selectedCity)){ |
89 |
0
|
Toast.makeText(this, R.string.change_city_same_city_toast_msg, Toast.LENGTH_SHORT).show(); |
90 |
|
}else { |
91 |
2
|
mProgressDialog = new ProgressDialog(this); |
92 |
2
|
mProgressDialog.setMessage(getText(R.string.change_city_progress_dialog_msg)); |
93 |
2
|
mProgressDialog.show(); |
94 |
2
|
mSettingService.changeCitySetting(selectedCity); |
95 |
|
} |
96 |
|
} |
97 |
|
|
|
|
| 70% |
Uncovered Elements: 3 (10) |
Complexity: 3 |
Complexity Density: 0,5 |
|
98 |
2
|
public void onCitySettingChanged(int resultCode) {... |
99 |
2
|
if(mProgressDialog != null){ |
100 |
2
|
mProgressDialog.dismiss(); |
101 |
|
} |
102 |
2
|
if(resultCode == Constants.ResultCode.CHANGE_CITY_FAILED){ |
103 |
0
|
Toast.makeText(ChangeCityActivity.this, getText(R.string.change_city_reload_failed_msg), Toast.LENGTH_SHORT).show(); |
104 |
|
}else { |
105 |
2
|
Toast.makeText(ChangeCityActivity.this, getText(R.string.change_city_reload_success_msg), Toast.LENGTH_SHORT).show(); |
106 |
2
|
super.onBackPressed(); |
107 |
|
} |
108 |
|
} |
109 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
110 |
0
|
public void onFavoriteIdsChanged() {... |
111 |
|
|
112 |
|
} |
113 |
|
|
114 |
|
} |