1 |
|
package com.dreamcatcher.bicycle.activity; |
2 |
|
|
3 |
|
import android.app.Activity; |
4 |
|
import android.content.Intent; |
5 |
|
import android.content.pm.PackageInfo; |
6 |
|
import android.net.Uri; |
7 |
|
import android.os.Bundle; |
8 |
|
import android.view.LayoutInflater; |
9 |
|
import android.view.View; |
10 |
|
import android.view.View.OnClickListener; |
11 |
|
import android.widget.ImageView; |
12 |
|
import android.widget.LinearLayout; |
13 |
|
import android.widget.LinearLayout.LayoutParams; |
14 |
|
import android.widget.TextView; |
15 |
|
import android.widget.Toast; |
16 |
|
|
17 |
|
import com.dreamcatcher.bicycle.R; |
18 |
|
import com.dreamcatcher.bicycle.core.BicycleService; |
19 |
|
import com.dreamcatcher.bicycle.interfaces.IHttpEvent; |
20 |
|
import com.dreamcatcher.bicycle.util.Constants; |
21 |
|
import com.dreamcatcher.bicycle.util.Utils; |
22 |
|
import com.dreamcatcher.bicycle.view.ActivityTitle; |
23 |
|
import com.dreamcatcher.bicycle.vo.BicycleNumberInfo; |
24 |
|
|
|
|
| 80% |
Uncovered Elements: 19 (95) |
Complexity: 28 |
Complexity Density: 0,41 |
|
25 |
|
public class BicycleMore extends Activity implements IHttpEvent{ |
26 |
|
private LayoutInflater mInflater = null; |
27 |
|
private LinearLayout mListContainer = null; |
28 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
29 |
1
|
@Override... |
30 |
|
protected void onCreate(Bundle savedInstanceState) { |
31 |
1
|
super.onCreate(savedInstanceState); |
32 |
1
|
setContentView(R.layout.bicycle_more); |
33 |
1
|
init(); |
34 |
|
} |
35 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
36 |
0
|
@Override... |
37 |
|
public void onBackPressed() { |
38 |
0
|
this.getParent().onBackPressed(); |
39 |
|
} |
40 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
|
41 |
1
|
private void init(){... |
42 |
1
|
mInflater = getLayoutInflater(); |
43 |
|
|
44 |
1
|
ActivityTitle activityTitle = (ActivityTitle) findViewById(R.id.bicycle_title); |
45 |
1
|
activityTitle.setActivityTitle(getText(R.string.title_more)); |
46 |
|
|
47 |
1
|
mListContainer = (LinearLayout) findViewById(R.id.bicycle_more_list_container); |
48 |
1
|
this.addSettingItem(); |
49 |
1
|
this.addEvent(); |
50 |
|
} |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 2 |
Complexity Density: 0,14 |
|
52 |
1
|
private void addSettingItem(){... |
53 |
6
|
for(int i = 0, n = Constants.MoreListviewItem.SETTING_ITEM_IMAGE.length; i < n; i++){ |
54 |
5
|
View view = mInflater.inflate(R.layout.setting_listview_item, mListContainer, false); |
55 |
|
|
56 |
5
|
ImageView imageView = (ImageView) view.findViewById(R.id.setting_listview_item_image); |
57 |
5
|
TextView textView = (TextView) view.findViewById(R.id.setting_listview_item_text); |
58 |
5
|
ImageView indicator = (ImageView) view.findViewById(R.id.setting_listview_item_next_indicator); |
59 |
|
|
60 |
5
|
imageView.setImageResource(Constants.MoreListviewItem.SETTING_ITEM_IMAGE[i]); |
61 |
5
|
textView.setText(Constants.MoreListviewItem.SETTING_ITEM_TEXT[i]); |
62 |
5
|
indicator.setImageResource(Constants.MoreListviewItem.SETTING_ITEM_NEXT_INDICATOR); |
63 |
|
|
64 |
5
|
view.setOnClickListener(getOnFunctionSettingItemClickListener(i)); |
65 |
|
|
66 |
5
|
view.setBackgroundResource(Constants.MoreListviewItem.BACKGROUND_IMAGE[i]); |
67 |
5
|
LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); |
68 |
5
|
params.setMargins(0, Utils.dip2px(Constants.MoreListviewItem.MARGIN_TOP_IN_DIP[i]), 0, 0); |
69 |
5
|
view.setLayoutParams(params); |
70 |
|
|
71 |
5
|
mListContainer.addView(view); |
72 |
|
} |
73 |
|
} |
|
|
| 89,5% |
Uncovered Elements: 2 (19) |
Complexity: 6 |
Complexity Density: 0,32 |
|
74 |
5
|
private OnClickListener getOnFunctionSettingItemClickListener(int index){... |
75 |
5
|
OnClickListener listener = null; |
76 |
5
|
switch (index) { |
77 |
1
|
case 0: |
78 |
1
|
case 4: |
79 |
2
|
final Intent intent = new Intent(this, Constants.MoreListviewItem.NEXT_ACTIVITY_ARRAY[index]); |
80 |
2
|
listener = new OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
2
|
public void onClick(View v) {... |
82 |
2
|
startActivity(intent); |
83 |
|
} |
84 |
|
}; |
85 |
2
|
break; |
86 |
1
|
case 1: |
87 |
1
|
listener = new OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
88 |
1
|
public void onClick(View v) { ... |
89 |
1
|
shareToFriend(); |
90 |
|
} |
91 |
|
}; |
92 |
1
|
break; |
93 |
1
|
case 2: |
94 |
1
|
listener = new OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
95 |
1
|
public void onClick(View v) {... |
96 |
1
|
checkVersion(); |
97 |
|
} |
98 |
|
}; |
99 |
1
|
break; |
100 |
1
|
case 3: |
101 |
1
|
listener = new OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
102 |
1
|
public void onClick(View v) {... |
103 |
1
|
goToMarket(); |
104 |
|
} |
105 |
|
}; |
106 |
1
|
break; |
107 |
0
|
default: |
108 |
0
|
break; |
109 |
|
} |
110 |
5
|
return listener; |
111 |
|
} |
112 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
|
113 |
1
|
private void shareToFriend(){... |
114 |
1
|
Intent intent = new Intent(Intent.ACTION_SEND); |
115 |
1
|
intent.putExtra(Intent.EXTRA_TEXT, getText(R.string.share_message)); |
116 |
1
|
intent.putExtra(Intent.EXTRA_SUBJECT, getText(R.string.share_title)); |
117 |
1
|
intent.setType("text/plain"); |
118 |
1
|
startActivity(Intent.createChooser(intent, getText(R.string.share_chooser_title))); |
119 |
|
} |
120 |
|
|
|
|
| 66,7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0,67 |
|
121 |
1
|
private void goToMarket(){... |
122 |
1
|
try { |
123 |
1
|
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.HttpUrl.APP_URI))); |
124 |
|
} catch (Exception e) { |
125 |
0
|
Toast.makeText(this, R.string.toast_msg_version_no_market, Toast.LENGTH_SHORT).show(); |
126 |
|
} |
127 |
|
} |
128 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
129 |
1
|
private void checkVersion(){... |
130 |
1
|
Toast.makeText(this, R.string.toast_msg_version_is_checking, Toast.LENGTH_SHORT).show(); |
131 |
1
|
PackageInfo packageInfo = Utils.getPackageInfo(); |
132 |
1
|
BicycleService.getInstance().getHttpService().checkNewVersion(packageInfo.versionName, packageInfo.versionCode); |
133 |
|
} |
134 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
135 |
0
|
@Override... |
136 |
|
protected void onDestroy() { |
137 |
0
|
this.removeEvent(); |
138 |
0
|
super.onDestroy(); |
139 |
|
} |
140 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
141 |
1
|
private void addEvent(){... |
142 |
1
|
BicycleService.getInstance().getHttpEventListener().addEvent(this); |
143 |
|
} |
144 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
145 |
0
|
private void removeEvent(){... |
146 |
0
|
BicycleService.getInstance().getHttpEventListener().removeEvent(this); |
147 |
|
} |
148 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
149 |
1
|
public void onAllBicyclesInfoReceived(int resultCode) {... |
150 |
|
|
151 |
|
} |
152 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
153 |
0
|
public void onSingleBicycleNumberInfoReceived(... |
154 |
|
BicycleNumberInfo bicycleNumberInfo, int resultCode) { |
155 |
|
|
156 |
|
} |
157 |
|
|
|
|
| 38,5% |
Uncovered Elements: 8 (13) |
Complexity: 4 |
Complexity Density: 0,57 |
|
158 |
1
|
public void onNewVersionCheckCompleted(boolean needUpdate, int resultCode) {... |
159 |
1
|
if(resultCode == Constants.ResultCode.NETWORK_DISCONNECT){ |
160 |
0
|
Toast.makeText(this, R.string.toast_msg_network_error, Toast.LENGTH_SHORT).show(); |
161 |
1
|
}else if(resultCode == Constants.ResultCode.SUCCESS){ |
162 |
0
|
if(needUpdate){ |
163 |
0
|
goToMarket(); |
164 |
|
}else { |
165 |
0
|
Toast.makeText(this, R.string.toast_msg_version_is_up_to_date, Toast.LENGTH_SHORT).show(); |
166 |
|
} |
167 |
|
}else { |
168 |
1
|
Toast.makeText(this, R.string.toast_msg_server_unavailable, Toast.LENGTH_SHORT).show(); |
169 |
|
} |
170 |
|
} |
171 |
|
} |