Clover Coverage Report - RaspberryBusMalaysiaActivity Coverage Report
Coverage timestamp: mar dic 23 2014 15:39:35 EST
../../../img/srcFileCovDistChart10.png 0% of files have more coverage
68   160   25   13,6
40   115   0,37   5
5     5  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  CompanyResultActivity       Line # 31 68 25 92% 0.920354
 
No Tests
 
1    /*
2    Copyright (C) 2012,2013 Sweetie Piggy Apps <sweetiepiggyapps@gmail.com>
3   
4    This file is part of Raspberry Bus Malaysia.
5   
6    Raspberry Bus Malaysia is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10   
11    Raspberry Bus Malaysia is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14    GNU General Public License for more details.
15   
16    You should have received a copy of the GNU General Public License
17    along with Raspberry Bus Malaysia; if not, see <http://www.gnu.org/licenses/>.
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   
 
31    public class CompanyResultActivity extends Activity
32    {
33    private DbAdapter mDbHelper;
34    private boolean m_is_operator = false;
35   
36    /** Called when the activity is first created. */
 
37  3 toggle @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    /* remove newline for delay label */
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   
 
108  3 toggle @Override
109    protected void onDestroy() {
110  3 if (mDbHelper != null) {
111  3 mDbHelper.close();
112    }
113  3 super.onDestroy();
114    }
115   
 
116  9 toggle 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   
 
133  30 toggle 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   
 
148  3 toggle 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