1 |
|
package com.dreamcatcher.bicycle.activity; |
2 |
|
|
3 |
|
import android.app.AlertDialog; |
4 |
|
import android.app.TabActivity; |
5 |
|
import android.content.DialogInterface; |
6 |
|
import android.content.Intent; |
7 |
|
import android.os.Bundle; |
8 |
|
import android.view.LayoutInflater; |
9 |
|
import android.view.View; |
10 |
|
import android.widget.ImageView; |
11 |
|
import android.widget.TabHost; |
12 |
|
import android.widget.TabHost.TabSpec; |
13 |
|
import android.widget.TextView; |
14 |
|
import android.widget.Toast; |
15 |
|
|
16 |
|
import com.dreamcatcher.bicycle.R; |
17 |
|
import com.dreamcatcher.bicycle.core.BicycleService; |
18 |
|
import com.dreamcatcher.bicycle.interfaces.IAdEvent; |
19 |
|
import com.dreamcatcher.bicycle.interfaces.ISettingEvent; |
20 |
|
import com.dreamcatcher.bicycle.util.Constants; |
21 |
|
import com.dreamcatcher.bicycle.util.GlobalSetting; |
22 |
|
import com.dreamcatcher.bicycle.util.Utils; |
23 |
|
import com.dreamcatcher.bicycle.vo.CitySetting; |
24 |
|
import com.kuguo.ad.PushAdsManager; |
25 |
|
import com.uucun.adsdk.UUAppConnect; |
26 |
|
|
|
|
| 60,9% |
Uncovered Elements: 50 (128) |
Complexity: 36 |
Complexity Density: 0,47 |
|
27 |
|
public class Main extends TabActivity implements ISettingEvent, IAdEvent{ |
28 |
|
private TabHost mTabHost; |
29 |
|
private LayoutInflater mLayoutInflater; |
30 |
|
private long mCurrentTime = 0; |
31 |
|
private static final int SPLASH_SCREEN_CODE = 1; |
32 |
|
private static final int SELECT_CITY_CODE = 1; |
33 |
|
|
34 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
35 |
1
|
@Override... |
36 |
|
public void onCreate(Bundle savedInstanceState) { |
37 |
1
|
super.onCreate(savedInstanceState); |
38 |
1
|
startActivityForResult(new Intent(this, SplashScreen.class), SPLASH_SCREEN_CODE); |
39 |
|
} |
40 |
|
|
|
|
| 52,4% |
Uncovered Elements: 10 (21) |
Complexity: 6 |
Complexity Density: 0,55 |
|
41 |
2
|
@Override... |
42 |
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
43 |
2
|
if(requestCode == SPLASH_SCREEN_CODE){ |
44 |
2
|
if(resultCode == RESULT_OK){ |
45 |
2
|
boolean loadCompleted = data.getBooleanExtra("load_completed", false); |
46 |
2
|
if(loadCompleted){ |
47 |
1
|
setContentView(R.layout.main); |
48 |
1
|
this.init(); |
49 |
|
}else { |
50 |
1
|
startActivityForResult(new Intent(this, SelectCityActivity.class), SELECT_CITY_CODE); |
51 |
|
} |
52 |
|
} |
53 |
0
|
}else if(requestCode == SELECT_CITY_CODE) { |
54 |
0
|
if(requestCode == RESULT_OK){ |
55 |
0
|
setContentView(R.layout.main); |
56 |
0
|
this.init(); |
57 |
|
} |
58 |
|
} |
59 |
|
} |
60 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
61 |
0
|
@Override... |
62 |
|
protected void onDestroy() { |
63 |
0
|
this.removeEvent(); |
64 |
0
|
UUAppConnect.getInstance(this).exitSdk(); |
65 |
0
|
super.onDestroy(); |
66 |
|
} |
67 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0,5 |
|
68 |
0
|
@Override... |
69 |
|
public void onBackPressed() { |
70 |
0
|
if(System.currentTimeMillis() - mCurrentTime < 2000){ |
71 |
0
|
Utils.exitApplication(); |
72 |
|
}else { |
73 |
0
|
try { |
74 |
0
|
Toast.makeText(this, getText(R.string.exit_app_inform_msg), Toast.LENGTH_SHORT).show(); |
75 |
0
|
mCurrentTime = System.currentTimeMillis(); |
76 |
|
} catch (Exception e) { |
77 |
0
|
e.printStackTrace(); |
78 |
|
} |
79 |
|
} |
80 |
|
} |
81 |
|
|
|
|
| 83,3% |
Uncovered Elements: 4 (24) |
Complexity: 4 |
Complexity Density: 0,22 |
|
82 |
1
|
private void init(){... |
83 |
1
|
this.addEvent(); |
84 |
|
|
85 |
1
|
mTabHost = getTabHost(); |
86 |
1
|
mLayoutInflater = LayoutInflater.from(this); |
87 |
|
|
88 |
1
|
CitySetting citySetting = GlobalSetting.getInstance().getCitySetting(); |
89 |
1
|
if(citySetting == null){ |
90 |
0
|
return; |
91 |
|
} |
92 |
1
|
int[] tabs = citySetting.getTabs(); |
93 |
1
|
int childrenCount = Constants.TabSetting.IMAGE_ARRAY.length; |
94 |
|
|
95 |
5
|
for(int i = 0; i < childrenCount; i++){ |
96 |
4
|
TabSpec tabSpec = mTabHost.newTabSpec(getString(Constants.TabSetting.TEXT_ARRAY[i])).setIndicator(getTabItemView(i)).setContent(getTabItemIntent(i)); |
97 |
|
|
98 |
4
|
mTabHost.addTab(tabSpec); |
99 |
4
|
mTabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.selector_tab_background); |
100 |
4
|
if(!inArray(i, tabs)){ |
101 |
0
|
mTabHost.getTabWidget().getChildAt(i).setVisibility(View.GONE); |
102 |
|
} |
103 |
|
} |
104 |
|
|
105 |
1
|
UUAppConnect.getInstance(this).initSdk(); |
106 |
|
|
107 |
|
|
108 |
1
|
BicycleService.getInstance().getAdService().getPoints(); |
109 |
|
|
110 |
|
|
111 |
1
|
PushAdsManager paManager = PushAdsManager.getInstance(); |
112 |
1
|
paManager.receivePushMessage(this, true); |
113 |
|
} |
114 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
115 |
1
|
private void addEvent(){... |
116 |
1
|
BicycleService.getInstance().getSettingEventListener().addEvent(this); |
117 |
1
|
BicycleService.getInstance().getAdEventListener().addEvent(this); |
118 |
|
} |
119 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
120 |
0
|
private void removeEvent(){... |
121 |
0
|
BicycleService.getInstance().getSettingEventListener().removeEvent(this); |
122 |
0
|
BicycleService.getInstance().getAdEventListener().removeEvent(this); |
123 |
|
} |
124 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 3 |
Complexity Density: 0,5 |
|
125 |
6
|
private boolean inArray(int data, int[] array){... |
126 |
6
|
boolean result = false; |
127 |
12
|
for(int i = 0; i < array.length; i++){ |
128 |
12
|
if(data == array[i]){ |
129 |
6
|
result = true; |
130 |
6
|
break; |
131 |
|
} |
132 |
|
} |
133 |
6
|
return result; |
134 |
|
} |
135 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
136 |
0
|
@Override... |
137 |
|
protected void onNewIntent(Intent intent) { |
138 |
0
|
processIntent(intent); |
139 |
0
|
super.onNewIntent(intent); |
140 |
|
} |
141 |
|
|
142 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
143 |
0
|
private void processIntent(Intent intent){... |
144 |
0
|
boolean isFromReminderNotificaiton = intent.getBooleanExtra(Constants.IntentExtraTag.MAIN_REMINDER_FROM_NOTIFICATION, false); |
145 |
0
|
if(isFromReminderNotificaiton){ |
146 |
0
|
new AlertDialog.Builder(this) |
147 |
|
.setTitle(R.string.return_bicycle_reminder_cancel_dialog_title) |
148 |
|
.setMessage(R.string.return_bicycle_reminder_cancel_dialog_msg) |
149 |
|
.setPositiveButton(R.string.return_bicycle_reminder_cancel_dialog_btn, new DialogInterface.OnClickListener() { |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
150 |
0
|
public void onClick(DialogInterface dialog, int which) {... |
151 |
0
|
closeReturnBicycleReminder(); |
152 |
|
} |
153 |
|
}).show(); |
154 |
|
} |
155 |
|
} |
156 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
157 |
0
|
private void closeReturnBicycleReminder(){... |
158 |
0
|
Utils.stopReminder(); |
159 |
|
} |
160 |
|
|
|
|
| 73,3% |
Uncovered Elements: 4 (15) |
Complexity: 4 |
Complexity Density: 0,44 |
|
161 |
2
|
private void reloadUI(){... |
162 |
2
|
CitySetting citySetting = GlobalSetting.getInstance().getCitySetting(); |
163 |
2
|
if(citySetting == null){ |
164 |
0
|
return; |
165 |
|
} |
166 |
2
|
int[] tabs = citySetting.getTabs(); |
167 |
2
|
int tabCount = mTabHost.getChildCount(); |
168 |
4
|
for(int i = 0; i < tabCount; i++){ |
169 |
2
|
if(inArray(i, tabs)){ |
170 |
2
|
mTabHost.getTabWidget().getChildAt(i).setVisibility(View.VISIBLE); |
171 |
|
}else { |
172 |
0
|
mTabHost.getTabWidget().getChildAt(i).setVisibility(View.VISIBLE); |
173 |
|
} |
174 |
|
} |
175 |
|
} |
176 |
|
|
|
|
| 88,9% |
Uncovered Elements: 1 (9) |
Complexity: 2 |
Complexity Density: 0,29 |
|
177 |
4
|
private View getTabItemView(int index){... |
178 |
4
|
View view = mLayoutInflater.inflate(R.layout.tab_item_view, null); |
179 |
4
|
ImageView tabImage = (ImageView) view.findViewById(R.id.tab_item_image); |
180 |
4
|
if(tabImage != null){ |
181 |
4
|
tabImage.setImageResource(Constants.TabSetting.IMAGE_ARRAY[index]); |
182 |
|
} |
183 |
|
|
184 |
4
|
TextView textView = (TextView) view.findViewById(R.id.tab_item_text); |
185 |
4
|
textView.setText(Constants.TabSetting.TEXT_ARRAY[index]); |
186 |
|
|
187 |
4
|
return view; |
188 |
|
} |
189 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
190 |
4
|
private Intent getTabItemIntent(int index){... |
191 |
4
|
Intent intent = new Intent(this, Constants.TabSetting.CONTENT_ARRAY[index]); |
192 |
4
|
return intent; |
193 |
|
} |
194 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
195 |
2
|
public void onCitySettingChanged(int resultCode) {... |
196 |
2
|
reloadUI(); |
197 |
|
} |
198 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
199 |
8
|
public void onFavoriteIdsChanged() {... |
200 |
|
|
201 |
|
} |
202 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
203 |
1
|
@Override... |
204 |
|
public void onPointsUpdated(String currencyName, int totalPoint) { |
205 |
1
|
GlobalSetting.getInstance().getAdsetting().setPointTotal(totalPoint); |
206 |
|
} |
207 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
208 |
0
|
@Override... |
209 |
|
public void onPointsUpdateFailed(String error) { |
210 |
|
|
211 |
|
} |
212 |
|
|
213 |
|
} |