1 |
|
package com.dreamcatcher.bicycle.activity; |
2 |
|
|
3 |
|
import java.util.Timer; |
4 |
|
import java.util.TimerTask; |
5 |
|
|
6 |
|
import android.app.Activity; |
7 |
|
import android.app.AlertDialog; |
8 |
|
import android.content.DialogInterface; |
9 |
|
import android.content.Intent; |
10 |
|
import android.os.Bundle; |
11 |
|
import android.os.Handler; |
12 |
|
import android.os.Message; |
13 |
|
import android.view.LayoutInflater; |
14 |
|
import android.view.View; |
15 |
|
import android.view.View.OnClickListener; |
16 |
|
import android.widget.ImageView; |
17 |
|
import android.widget.LinearLayout; |
18 |
|
import android.widget.LinearLayout.LayoutParams; |
19 |
|
import android.widget.RelativeLayout; |
20 |
|
import android.widget.SeekBar; |
21 |
|
import android.widget.SeekBar.OnSeekBarChangeListener; |
22 |
|
import android.widget.TextView; |
23 |
|
import android.widget.Toast; |
24 |
|
|
25 |
|
import com.dreamcatcher.bicycle.R; |
26 |
|
import com.dreamcatcher.bicycle.core.BicycleService; |
27 |
|
import com.dreamcatcher.bicycle.interfaces.IAdEvent; |
28 |
|
import com.dreamcatcher.bicycle.util.Constants; |
29 |
|
import com.dreamcatcher.bicycle.util.GlobalSetting; |
30 |
|
import com.dreamcatcher.bicycle.util.ReminderNotification; |
31 |
|
import com.dreamcatcher.bicycle.util.Utils; |
32 |
|
import com.dreamcatcher.bicycle.view.ActivityTitle; |
33 |
|
import com.dreamcatcher.bicycle.vo.Adsetting; |
34 |
|
import com.uucun.adsdk.UUAppConnect; |
35 |
|
|
|
|
| 70,9% |
Uncovered Elements: 55 (189) |
Complexity: 51 |
Complexity Density: 0,38 |
|
36 |
|
public class BicycleSetting extends Activity implements IAdEvent{ |
37 |
|
private LayoutInflater mInflater = null; |
38 |
|
private LinearLayout mListContainer = null; |
39 |
|
private Timer mTimer = null; |
40 |
|
private TimerTask mTimerTask = null; |
41 |
|
private static long mReminderTimeValue = 0; |
42 |
|
private Handler mHandler = null; |
43 |
|
private final static int SPEND_SUCCESS = 0; |
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
45 |
1
|
@Override... |
46 |
|
protected void onCreate(Bundle savedInstanceState) { |
47 |
1
|
super.onCreate(savedInstanceState); |
48 |
1
|
setContentView(R.layout.bicycle_setting); |
49 |
1
|
init(); |
50 |
|
} |
51 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
52 |
0
|
@Override... |
53 |
|
public void onBackPressed() { |
54 |
0
|
this.getParent().onBackPressed(); |
55 |
|
} |
56 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
57 |
0
|
@Override... |
58 |
|
protected void onDestroy() { |
59 |
0
|
this.removeEvent(); |
60 |
0
|
super.onDestroy(); |
61 |
|
} |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
63 |
1
|
private void addEvent(){... |
64 |
1
|
BicycleService.getInstance().getAdEventListener().addEvent(this); |
65 |
|
} |
66 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
0
|
private void removeEvent(){... |
68 |
0
|
BicycleService.getInstance().getAdEventListener().removeEvent(this); |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0,14 |
|
71 |
1
|
private void init(){... |
72 |
1
|
this.addEvent(); |
73 |
|
|
74 |
1
|
mHandler = new Handler(){ |
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
75 |
0
|
@Override... |
76 |
|
public void handleMessage(Message msg) { |
77 |
0
|
if(msg.what == SPEND_SUCCESS){ |
78 |
0
|
Toast.makeText(BicycleSetting.this, R.string.toast_msg_ad_remove_success, Toast.LENGTH_SHORT).show(); |
79 |
|
} |
80 |
|
} |
81 |
|
}; |
82 |
|
|
83 |
1
|
mInflater = getLayoutInflater(); |
84 |
|
|
85 |
1
|
ActivityTitle activityTitle = (ActivityTitle) findViewById(R.id.bicycle_title); |
86 |
1
|
activityTitle.setActivityTitle(getText(R.string.title_setting)); |
87 |
|
|
88 |
1
|
mListContainer = (LinearLayout) findViewById(R.id.bicycle_setting_list_container); |
89 |
1
|
this.addSettingItem(); |
90 |
|
|
91 |
|
} |
92 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 2 |
Complexity Density: 0,14 |
|
93 |
1
|
private void addSettingItem(){... |
94 |
6
|
for(int i = 0, n = Constants.SettingListViewItem.SETTING_ITEM_IMAGE.length; i < n; i++){ |
95 |
5
|
View view = mInflater.inflate(R.layout.setting_listview_item, mListContainer, false); |
96 |
|
|
97 |
5
|
ImageView imageView = (ImageView) view.findViewById(R.id.setting_listview_item_image); |
98 |
5
|
TextView textView = (TextView) view.findViewById(R.id.setting_listview_item_text); |
99 |
5
|
ImageView indicator = (ImageView) view.findViewById(R.id.setting_listview_item_next_indicator); |
100 |
|
|
101 |
5
|
imageView.setImageResource(Constants.SettingListViewItem.SETTING_ITEM_IMAGE[i]); |
102 |
5
|
textView.setText(Constants.SettingListViewItem.SETTING_ITEM_TEXT[i]); |
103 |
5
|
indicator.setImageResource(Constants.SettingListViewItem.SETTING_ITEM_NEXT_INDICATOR); |
104 |
|
|
105 |
5
|
view.setOnClickListener(getOnFunctionSettingItemClickListener(i)); |
106 |
|
|
107 |
5
|
view.setBackgroundResource(Constants.SettingListViewItem.BACKGROUND_IMAGE[i]); |
108 |
5
|
LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); |
109 |
5
|
params.setMargins(0, Utils.dip2px(Constants.SettingListViewItem.MARGIN_TOP_IN_DIP[i]), 0, 0); |
110 |
5
|
view.setLayoutParams(params); |
111 |
|
|
112 |
5
|
mListContainer.addView(view); |
113 |
|
} |
114 |
|
} |
115 |
|
|
|
|
| 88,2% |
Uncovered Elements: 2 (17) |
Complexity: 6 |
Complexity Density: 0,35 |
|
116 |
5
|
private OnClickListener getOnFunctionSettingItemClickListener(int index){... |
117 |
5
|
OnClickListener listener = null; |
118 |
5
|
switch (index) { |
119 |
1
|
case 0: |
120 |
1
|
case 1: |
121 |
1
|
case 2: |
122 |
3
|
final Intent intent = new Intent(this, Constants.SettingListViewItem.NEXT_ACTIVITY_ARRAY[index]); |
123 |
3
|
listener = new OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
124 |
6
|
public void onClick(View v) {... |
125 |
6
|
startActivity(intent); |
126 |
|
} |
127 |
|
}; |
128 |
3
|
break; |
129 |
1
|
case 4: |
130 |
1
|
listener = new OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
131 |
2
|
public void onClick(View v) { ... |
132 |
2
|
showAdOffers(); |
133 |
|
} |
134 |
|
}; |
135 |
1
|
break; |
136 |
1
|
case 3: |
137 |
1
|
listener = new OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
138 |
3
|
public void onClick(View v) {... |
139 |
3
|
reminder(); |
140 |
|
} |
141 |
|
}; |
142 |
1
|
break; |
143 |
0
|
default: |
144 |
0
|
break; |
145 |
|
} |
146 |
5
|
return listener; |
147 |
|
} |
148 |
|
|
|
|
| 50% |
Uncovered Elements: 7 (14) |
Complexity: 4 |
Complexity Density: 0,4 |
|
149 |
2
|
private void showAdOffers(){... |
150 |
2
|
Adsetting adsetting = GlobalSetting.getInstance().getAdsetting(); |
151 |
2
|
int currentPoint = adsetting.getPointTotal(); |
152 |
2
|
long nextShowAdTime = adsetting.getNextShowAdTime(); |
153 |
|
|
154 |
2
|
if(System.currentTimeMillis() > nextShowAdTime && currentPoint < Constants.AdSetting.REMOVE_AD_MIN_POINT ){ |
155 |
2
|
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
156 |
2
|
builder.setMessage(String.format(getText(R.string.dialog_remove_ad_msg_not_enough).toString(), currentPoint)) |
157 |
|
.setPositiveButton(R.string.dialog_remove_ad_btn_earn_points, new DialogInterface.OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
158 |
1
|
@Override... |
159 |
|
public void onClick(DialogInterface dialog, int which) { |
160 |
1
|
UUAppConnect.getInstance(BicycleSetting.this).showOffers(); |
161 |
1
|
dialog.dismiss(); |
162 |
|
} |
163 |
|
}) |
164 |
|
.setNegativeButton(R.string.btn_cancel, new DialogInterface.OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
165 |
1
|
@Override... |
166 |
|
public void onClick(DialogInterface dialog, int which) { |
167 |
1
|
dialog.dismiss(); |
168 |
|
} |
169 |
|
}) |
170 |
|
.show(); |
171 |
|
|
172 |
0
|
} else if(System.currentTimeMillis() > nextShowAdTime){ |
173 |
0
|
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
174 |
0
|
builder.setMessage(String.format(getText(R.string.dialog_remove_ad_msg_enough).toString(), currentPoint)) |
175 |
|
.setPositiveButton(R.string.dialog_remove_ad_btn_remove_ad, new DialogInterface.OnClickListener() { |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
176 |
0
|
@Override... |
177 |
|
public void onClick(DialogInterface dialog, int which) { |
178 |
0
|
removeAd(); |
179 |
0
|
dialog.dismiss(); |
180 |
|
} |
181 |
|
}) |
182 |
|
.setNeutralButton(R.string.dialog_remove_ad_btn_earn_points, new DialogInterface.OnClickListener() { |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
183 |
0
|
@Override... |
184 |
|
public void onClick(DialogInterface dialog, int which) { |
185 |
0
|
UUAppConnect.getInstance(BicycleSetting.this).showOffers(); |
186 |
0
|
dialog.dismiss(); |
187 |
|
} |
188 |
|
}) |
189 |
|
.setNegativeButton(R.string.btn_cancel, new DialogInterface.OnClickListener() { |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
190 |
0
|
@Override... |
191 |
|
public void onClick(DialogInterface dialog, int which) { |
192 |
0
|
dialog.dismiss(); |
193 |
|
} |
194 |
|
}) |
195 |
|
.show(); |
196 |
|
} else { |
197 |
0
|
UUAppConnect.getInstance(BicycleSetting.this).showOffers(); |
198 |
|
} |
199 |
|
} |
200 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
201 |
0
|
private void removeAd(){... |
202 |
|
|
203 |
0
|
long currentTime = System.currentTimeMillis(); |
204 |
0
|
long nextShowAdTime = currentTime + Constants.AdSetting.MONTH_TIME; |
205 |
0
|
setNextShowAdTime(nextShowAdTime); |
206 |
0
|
BicycleService.getInstance().getAdService().spendPoints(Constants.AdSetting.REMOVE_AD_MIN_POINT); |
207 |
|
} |
208 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 2 |
Complexity Density: 0,1 |
|
209 |
3
|
private void reminder(){ ... |
210 |
3
|
View layout = mInflater.inflate(R.layout.return_bicycle_reminder, null, false); |
211 |
3
|
final TextView timeValueText = (TextView) layout.findViewById(R.id.return_bicycle_reminder_time_value); |
212 |
3
|
SeekBar seekBar = (SeekBar) layout.findViewById(R.id.return_bicycle_reminder_seekbar); |
213 |
3
|
RelativeLayout soundLine = (RelativeLayout) layout.findViewById(R.id.return_bicycle_reminder_sound_line); |
214 |
3
|
RelativeLayout vibrateLine = (RelativeLayout) layout.findViewById(R.id.return_bicycle_reminder_vibrate_line); |
215 |
3
|
RelativeLayout soundAndVibrateLine = (RelativeLayout) layout.findViewById(R.id.return_bicycle_reminder_sound_and_vibrate_line); |
216 |
3
|
final ImageView soundImage = (ImageView) layout.findViewById(R.id.return_bicycle_reminder_sound_image); |
217 |
3
|
final ImageView vibrateImage = (ImageView) layout.findViewById(R.id.return_bicycle_reminder_vibrate_image); |
218 |
3
|
final ImageView soundAndVibrateImage = (ImageView) layout.findViewById(R.id.return_bicycle_reminder_sound_and_vibrate_image); |
219 |
3
|
soundImage.setSelected(true); |
220 |
|
|
221 |
3
|
if(mReminderTimeValue != 0){ |
222 |
2
|
int timeValue = Math.round((mReminderTimeValue - System.currentTimeMillis())/(1000 * 60)); |
223 |
2
|
timeValueText.setText(String.valueOf(timeValue)); |
224 |
|
} |
225 |
|
|
226 |
3
|
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
227 |
2
|
public void onStopTrackingTouch(SeekBar seekBar) {... |
228 |
|
|
229 |
|
} |
230 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
231 |
2
|
public void onStartTrackingTouch(SeekBar seekBar) {... |
232 |
|
|
233 |
|
} |
234 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
235 |
20
|
public void onProgressChanged(SeekBar seekBar, int progress,... |
236 |
|
boolean fromUser) { |
237 |
20
|
timeValueText.setText(String.valueOf(progress)); |
238 |
|
} |
239 |
|
}); |
240 |
|
|
241 |
3
|
soundLine.setOnClickListener(new OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
242 |
2
|
public void onClick(View v) {... |
243 |
2
|
soundImage.setSelected(true); |
244 |
2
|
vibrateImage.setSelected(false); |
245 |
2
|
soundAndVibrateImage.setSelected(false); |
246 |
|
} |
247 |
|
}); |
248 |
|
|
249 |
3
|
vibrateLine.setOnClickListener(new OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
250 |
3
|
public void onClick(View v) {... |
251 |
3
|
soundImage.setSelected(false); |
252 |
3
|
vibrateImage.setSelected(true); |
253 |
3
|
soundAndVibrateImage.setSelected(false); |
254 |
|
} |
255 |
|
}); |
256 |
|
|
257 |
3
|
soundAndVibrateLine.setOnClickListener(new OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
258 |
2
|
public void onClick(View v) {... |
259 |
2
|
soundImage.setSelected(false); |
260 |
2
|
vibrateImage.setSelected(false); |
261 |
2
|
soundAndVibrateImage.setSelected(true); |
262 |
|
} |
263 |
|
}); |
264 |
|
|
265 |
3
|
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
266 |
3
|
builder.setTitle(R.string.return_bicycle_reminder_dialog_title) |
267 |
|
.setView(layout) |
268 |
|
.setNegativeButton(R.string.return_bicycle_reminder_dialog_negative_btn,new DialogInterface.OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
269 |
1
|
public void onClick(DialogInterface dialog, int which) {... |
270 |
1
|
cancelReminder(); |
271 |
1
|
dialog.dismiss(); |
272 |
|
} |
273 |
|
}) |
274 |
|
.setPositiveButton(R.string.return_bicycle_reminder_dialog_positive_btn, new DialogInterface.OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
|
275 |
2
|
public void onClick(DialogInterface dialog, int which) {... |
276 |
2
|
int timeValue = Integer.parseInt(timeValueText.getText().toString()); |
277 |
2
|
boolean soundSelected = soundImage.isSelected(); |
278 |
2
|
boolean vibrateSelected = vibrateImage.isSelected(); |
279 |
2
|
boolean soundAndVibrateSelected = soundAndVibrateImage.isSelected(); |
280 |
2
|
startReminder(timeValue, soundSelected, vibrateSelected, soundAndVibrateSelected); |
281 |
2
|
dialog.dismiss(); |
282 |
|
} |
283 |
|
}); |
284 |
|
|
285 |
3
|
builder.show(); |
286 |
|
} |
287 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 3 |
Complexity Density: 0,38 |
|
288 |
2
|
private void startReminder(int timeValue, boolean soundSelected, boolean vibrateSelected, boolean soundAndVibrateSelected){... |
289 |
2
|
if(mTimer == null){ |
290 |
1
|
mTimer = new Timer(); |
291 |
|
} |
292 |
2
|
if(mTimerTask != null){ |
293 |
1
|
mTimerTask.cancel(); |
294 |
|
} |
295 |
2
|
mTimerTask = getTimerTask(soundSelected, vibrateSelected, soundAndVibrateSelected); |
296 |
2
|
long delay = 1000 * 60 * timeValue; |
297 |
|
|
298 |
2
|
mTimer.schedule(mTimerTask, delay); |
299 |
2
|
mReminderTimeValue = System.currentTimeMillis() + delay; |
300 |
|
} |
301 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
302 |
2
|
private TimerTask getTimerTask(final boolean soundSelected, final boolean vibrateSelected, final boolean soundAndVibrateSelected){... |
303 |
2
|
return new TimerTask() { |
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0,43 |
|
304 |
0
|
@Override... |
305 |
|
public void run() { |
306 |
0
|
if(soundAndVibrateSelected){ |
307 |
0
|
Utils.reminderReturnBicycle(); |
308 |
0
|
Utils.vibrate(); |
309 |
0
|
}else if(soundSelected){ |
310 |
0
|
Utils.reminderReturnBicycle(); |
311 |
|
}else { |
312 |
0
|
Utils.vibrate(); |
313 |
|
} |
314 |
0
|
ReminderNotification.startNotification(); |
315 |
|
} |
316 |
|
}; |
317 |
|
} |
318 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
319 |
1
|
private void cancelReminder(){... |
320 |
1
|
if(mTimer != null){ |
321 |
1
|
mTimer.cancel(); |
322 |
|
} |
323 |
|
} |
324 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
325 |
0
|
private void setNextShowAdTime(long nextShowAdTime){... |
326 |
0
|
Utils.storeLongDataToLocal(Constants.LocalStoreTag.NEXT_AD_SHOWN_TIME, nextShowAdTime); |
327 |
0
|
GlobalSetting.getInstance().getAdsetting().setNextShowAdTime(nextShowAdTime); |
328 |
|
} |
329 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
330 |
0
|
@Override... |
331 |
|
public void onPointsUpdated(String currencyName, int totalPoint) { |
332 |
|
|
333 |
0
|
GlobalSetting.getInstance().getAdsetting().setPointTotal(totalPoint); |
334 |
|
|
335 |
0
|
mHandler.sendEmptyMessage(SPEND_SUCCESS); |
336 |
|
} |
337 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
338 |
0
|
@Override... |
339 |
|
public void onPointsUpdateFailed(String error) { |
340 |
|
|
341 |
0
|
setNextShowAdTime(0); |
342 |
|
} |
343 |
|
} |