1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.sweetiepiggy.raspberrybusmalaysia; |
21 |
|
|
22 |
|
import android.app.Activity; |
23 |
|
import android.database.Cursor; |
24 |
|
import android.os.Bundle; |
25 |
|
import android.view.ViewGroup.LayoutParams; |
26 |
|
import android.widget.RatingBar; |
27 |
|
import android.widget.TableLayout; |
28 |
|
import android.widget.TableRow; |
29 |
|
import android.widget.TextView; |
30 |
|
|
|
|
| 92% |
Uncovered Elements: 9 (113) |
Complexity: 25 |
Complexity Density: 0,37 |
|
31 |
|
public class CompanyResultActivity extends Activity |
32 |
|
{ |
33 |
|
private DbAdapter mDbHelper; |
34 |
|
private boolean m_is_operator = false; |
35 |
|
|
36 |
|
|
|
|
| 89,7% |
Uncovered Elements: 8 (78) |
Complexity: 19 |
Complexity Density: 0,45 |
|
37 |
3
|
@Override... |
38 |
|
public void onCreate(Bundle savedInstanceState) |
39 |
|
{ |
40 |
3
|
super.onCreate(savedInstanceState); |
41 |
3
|
setContentView(R.layout.company_result); |
42 |
|
|
43 |
3
|
Bundle b = getIntent().getExtras(); |
44 |
3
|
m_is_operator = (b == null) ? false : b.getBoolean("is_operator"); |
45 |
3
|
String company = (b == null) ? "<NULL>" : b.getString("company"); |
46 |
3
|
String company_display = company.length() == 0 ? getResources().getString(R.string.unknown) : company; |
47 |
3
|
((TextView) findViewById(R.id.title)).setText(company_display); |
48 |
|
|
49 |
|
|
50 |
3
|
TextView avg_delay_label = (TextView) findViewById(R.id.avg_delay_label); |
51 |
3
|
String avg_delay_str = avg_delay_label.getText().toString(); |
52 |
3
|
avg_delay_label.setText(avg_delay_str.replace('\n', ' ')); |
53 |
|
|
54 |
3
|
mDbHelper = new DbAdapter(); |
55 |
3
|
mDbHelper.open(this); |
56 |
|
|
57 |
3
|
float rating = m_is_operator ? |
58 |
|
mDbHelper.getOperatorRating(company) : |
59 |
|
mDbHelper.getAgentRating(company); |
60 |
3
|
((RatingBar) findViewById(R.id.rating_bar)).setRating(rating); |
61 |
3
|
float comfort = m_is_operator ? |
62 |
|
mDbHelper.getOperatorComfort(company) : |
63 |
|
mDbHelper.getAgentComfort(company); |
64 |
3
|
((RatingBar) findViewById(R.id.comfort_bar)).setRating(comfort); |
65 |
3
|
float safety = m_is_operator ? |
66 |
|
mDbHelper.getOperatorSafety(company) : |
67 |
|
mDbHelper.getAgentSafety(company); |
68 |
3
|
((RatingBar) findViewById(R.id.safety_bar)).setRating(safety); |
69 |
|
|
70 |
3
|
Cursor c_comp = m_is_operator ? |
71 |
|
mDbHelper.fetch_avg_operator_delay(company) : |
72 |
|
mDbHelper.fetch_avg_agent_delay(company); |
73 |
3
|
startManagingCursor(c_comp); |
74 |
3
|
if (c_comp.moveToFirst()) do { |
75 |
3
|
String avg_delay = format_time_min(c_comp.getInt(c_comp.getColumnIndex(DbAdapter.AVG_DELAY))); |
76 |
3
|
((TextView) findViewById(R.id.total_avg_delay)).setText(avg_delay); |
77 |
3
|
} while (c_comp.moveToNext()); |
78 |
|
|
79 |
3
|
Cursor c_from = m_is_operator ? |
80 |
|
mDbHelper.fetch_operator_from_cities(company) : |
81 |
|
mDbHelper.fetch_agent_from_cities(company); |
82 |
3
|
startManagingCursor(c_from); |
83 |
3
|
if (c_from.moveToFirst()) do { |
84 |
8
|
String from_city = c_from.getString(c_from.getColumnIndex(DbAdapter.KEY_FROM_CITY)); |
85 |
|
|
86 |
8
|
Cursor c_to = m_is_operator ? |
87 |
|
mDbHelper.fetch_operator_to_cities(from_city, company) : |
88 |
|
mDbHelper.fetch_agent_to_cities(from_city, company); |
89 |
8
|
startManagingCursor(c_to); |
90 |
8
|
if (c_to.moveToFirst()) do { |
91 |
9
|
String to_city = c_to.getString(c_to.getColumnIndex(DbAdapter.KEY_TO_CITY)); |
92 |
|
|
93 |
9
|
print_route_row(company, from_city, to_city); |
94 |
9
|
} while (c_to.moveToNext()); |
95 |
8
|
} while (c_from.moveToNext()); |
96 |
|
|
97 |
3
|
Cursor c_revw = m_is_operator ? |
98 |
|
mDbHelper.fetchOperatorReviews(company) : |
99 |
|
mDbHelper.fetchAgentReviews(company); |
100 |
3
|
startManagingCursor(c_revw); |
101 |
3
|
if (c_revw.moveToFirst()) do { |
102 |
15
|
String review = c_revw.getString(c_revw.getColumnIndex(DbAdapter.KEY_COMMENT)); |
103 |
15
|
print_review_row(review); |
104 |
15
|
print_review_row(""); |
105 |
15
|
} while (c_revw.moveToNext()); |
106 |
|
} |
107 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
108 |
3
|
@Override... |
109 |
|
protected void onDestroy() { |
110 |
3
|
if (mDbHelper != null) { |
111 |
3
|
mDbHelper.close(); |
112 |
|
} |
113 |
3
|
super.onDestroy(); |
114 |
|
} |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0,11 |
|
116 |
9
|
private void print_route_row(String company, String from_city,... |
117 |
|
String to_city) |
118 |
|
{ |
119 |
9
|
TextView from_view = new TextView(getApplicationContext()); |
120 |
9
|
TextView to_view = new TextView(getApplicationContext()); |
121 |
|
|
122 |
9
|
from_view.setText(from_city); |
123 |
9
|
to_view.setText(to_city); |
124 |
|
|
125 |
9
|
TableRow tr = new TableRow(getApplicationContext()); |
126 |
9
|
tr.addView(from_view); |
127 |
9
|
tr.addView(to_view); |
128 |
|
|
129 |
9
|
TableLayout results_layout = (TableLayout) findViewById(R.id.results_layout); |
130 |
9
|
results_layout.addView(tr); |
131 |
|
} |
132 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0,12 |
|
133 |
30
|
private void print_review_row(String review)... |
134 |
|
{ |
135 |
30
|
TextView review_view = new TextView(getApplicationContext()); |
136 |
30
|
LayoutParams params = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f); |
137 |
30
|
review_view.setLayoutParams(params); |
138 |
|
|
139 |
30
|
review_view.setText(review); |
140 |
|
|
141 |
30
|
TableRow tr = new TableRow(getApplicationContext()); |
142 |
30
|
tr.addView(review_view); |
143 |
|
|
144 |
30
|
TableLayout review_layout = (TableLayout) findViewById(R.id.review_layout); |
145 |
30
|
review_layout.addView(tr); |
146 |
|
} |
147 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0,33 |
|
148 |
3
|
private String format_time_min(int time)... |
149 |
|
{ |
150 |
3
|
String negative = ""; |
151 |
3
|
if (time < 0) { |
152 |
1
|
negative = "-"; |
153 |
1
|
time *= -1; |
154 |
|
} |
155 |
|
|
156 |
3
|
int min = time / 60; |
157 |
3
|
return String.format("%s%d%s", negative, min, getResources().getString(R.string.minute_abbr)); |
158 |
|
} |
159 |
|
} |
160 |
|
|