Clover Coverage Report - SaveApp Coverage Report
Coverage timestamp: mar dic 23 2014 15:53:11 EST
../../../../img/srcFileCovDistChart9.png 12% of files have more coverage
164   336   29   12,62
26   249   0,18   13
13     2,23  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  HomeActivity       Line # 28 164 29 85,2% 0.8522167
 
No Tests
 
1    package com.loopback.androidapps.saveapp;
2   
3    import java.util.List;
4    import java.util.Locale;
5   
6    import android.app.Activity;
7    import android.app.AlertDialog;
8    import android.content.Context;
9    import android.content.DialogInterface;
10    import android.content.Intent;
11    import android.content.SharedPreferences;
12    import android.graphics.PixelFormat;
13    import android.location.Address;
14    import android.location.Geocoder;
15    import android.location.Location;
16    import android.location.LocationManager;
17    import android.os.Bundle;
18    import android.util.Log;
19    import android.view.Menu;
20    import android.view.MenuInflater;
21    import android.view.MenuItem;
22    import android.view.View;
23    import android.view.WindowManager;
24    import android.widget.ImageButton;
25    import android.widget.TextView;
26    import android.widget.Toast;
27   
 
28    public class HomeActivity extends Activity implements View.OnClickListener {
29   
30    private double[] currentLocation;
31    private TextView txtAccountSelection, txtBudget, txtNumberOfDays;
32    private ImageButton btnAccountSelection, btnAdd, btnTake, btnPlot, btnAll,
33    btnMap, btnAccountEdit;
34   
35    public SaveApp saveApp;
36   
37    /*------------------------------------------------------------------------------------------------
38    *-------------------------------------ON CREATE--------------------------------------------------
39    *------------------------------------------------------------------------------------------------ */
40   
 
41  6 toggle public void onCreate(Bundle savedInstanceState) {
42  6 super.onCreate(savedInstanceState);
43  6 getWindow().setFormat(PixelFormat.RGBA_8888);
44  6 getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);
45   
46  6 setContentView(R.layout.main);
47   
48  6 loadActivity();
49    }
50   
51    /*------------------------------------------------------------------------------------------------
52    *-------------------------------------LOAD ACTIVITY--------------------------------------------------
53    *------------------------------------------------------------------------------------------------ */
54   
 
55  6 toggle public void loadActivity() {
56   
57  6 Log.i("HA", "Init App...");
58    // Application Context
59  6 saveApp = ((SaveApp) getApplicationContext());
60   
61    // DataBase
62  6 Log.i("HA", "Init DB...");
63  6 saveApp.setDbManager(new DBManager(getBaseContext()));
64  6 Log.i("HA", "DB Created.");
65   
66    // Layout
67  6 btnAccountSelection = (ImageButton) findViewById(R.id.btnAccountSelection);
68  6 txtAccountSelection = (TextView) findViewById(R.id.txtAccountSelection);
69  6 btnAdd = (ImageButton) findViewById(R.id.btnAdd);
70  6 btnTake = (ImageButton) findViewById(R.id.btnTake);
71  6 btnAll = (ImageButton) findViewById(R.id.btnAll);
72  6 btnMap = (ImageButton) findViewById(R.id.btnMap);
73  6 btnPlot = (ImageButton) findViewById(R.id.btnPlot);
74  6 btnAccountEdit = (ImageButton) findViewById(R.id.btnAccountEdit);
75  6 txtBudget = (TextView) findViewById(R.id.txtBudget);
76  6 txtNumberOfDays = (TextView) findViewById(R.id.txtNumberOfDays);
77   
78  6 btnAdd.setOnClickListener(this);
79  6 btnTake.setOnClickListener(this);
80  6 btnAll.setOnClickListener(this);
81  6 btnMap.setOnClickListener(this);
82  6 btnPlot.setOnClickListener(this);
83  6 btnAccountEdit.setOnClickListener(this);
84  6 btnAccountSelection.setOnClickListener(this);
85   
86    }
87   
88    /*------------------------------------------------------------------------------------------------
89    *------------------------------------- ACTIVITY LIFE CICLE--------------------------------------------------
90    *------------------------------------------------------------------------------------------------ */
91    // RESUME
 
92  7 toggle public void onResume() {
93  7 super.onResume();
94  7 getAddress();
95  7 setAccount(saveApp.getAccountId());
96  7 setPreview();
97    }
98   
99    // STOP
 
100  7 toggle protected void onStop() {
101  7 super.onStop();
102   
103  7 SharedPreferences settings = getSharedPreferences(
104    getString(R.string.prefs_name), 0);
105  7 SharedPreferences.Editor editor = settings.edit();
106   
107  7 editor.putInt("Account", saveApp.getAccountId());
108  7 editor.commit();
109    }
110   
111    /*------------------------------------------------------------------------------------------------
112    *--------------------------------------CLICKS--------------------------------------------------
113    *------------------------------------------------------------------------------------------------ */
 
114  0 toggle public void onBackPressed() {
115  0 Log.i("HA", "Finishing SaveApp");
116  0 HomeActivity.this.finish();
117    }
118   
 
119  7 toggle public void onClick(View v) {
120    // Add
121  7 if (v == btnAdd) {
122  1 Log.i("HA", "Button Add Clicked");
123  1 saveApp.setAdding(true);
124  1 saveApp.setDate(Utilities.dateGetter());
125   
126  1 saveApp.outlay.setCharge(0);
127  1 saveApp.outlay.setItemDesc("");
128  1 saveApp.outlay.setPlaceDesc("");
129  1 saveApp.outlay.setNote("");
130  1 saveApp.outlay.setDate(saveApp.getDate());
131  1 saveApp.outlay.setAddressDesc(saveApp.getAddressDesc());
132   
133  1 Bundle bundle = new Bundle();
134  1 bundle.putInt("Id", 0);
135  1 bundle.putBoolean("HasChanges", false);// If comes from
136    // ChangeAutogenerated
137   
138  1 Intent intent = new Intent(this.getApplicationContext(),
139    OutlayEditActivity.class);
140  1 intent.putExtras(bundle);
141  1 startActivity(intent);
142    }
143  7 if (v == btnTake) {
144  1 Log.i("HA", "Button Take Clicked");
145  1 saveApp.setAdding(false);
146  1 saveApp.setDate(Utilities.dateGetter());
147   
148  1 saveApp.outlay.setCharge(0);
149  1 saveApp.outlay.setItemDesc("");
150  1 saveApp.outlay.setPlaceDesc("");
151  1 saveApp.outlay.setNote("");
152  1 saveApp.outlay.setDate(saveApp.getDate());
153  1 saveApp.outlay.setAddressDesc(saveApp.getAddressDesc());
154   
155  1 Bundle bundle = new Bundle();
156  1 bundle.putInt("Id", 0);
157  1 bundle.putBoolean("HasChanges", false);// If comes from
158    // ChangeAutogenerated
159   
160  1 Intent intent = new Intent(this.getApplicationContext(),
161    OutlayEditActivity.class);
162  1 intent.putExtras(bundle);
163  1 startActivity(intent);
164    }
165   
166    // Plots
167  6 else if (v == btnPlot) {
168  0 Log.i("HA", "Button Plot Clicked");
169  0 Intent intent = new Intent(this.getApplicationContext(),
170    PlotActivity.class);
171  0 startActivity(intent);
172    }
173   
174    // All
175  6 else if (v == btnAll) {
176    // ProgressDialog.show(HomeActivity.this, "",
177    // " Loading. Please wait ... ", true);
178  2 Log.i("HA", "Button All Clicked");
179  2 Intent intent = new Intent(this.getApplicationContext(),
180    OutlaysListActivity.class);
181  2 startActivity(intent);
182    }
183   
184    // Map
185  4 else if (v == btnMap) {
186  1 Log.i("HA", "Button Map Clicked");
187  1 Intent intent = new Intent(this.getApplicationContext(),
188    MapAccountActivity.class);
189  1 startActivity(intent);
190    }
191    // Account edition
192  3 else if (v == btnAccountEdit) {
193  1 Log.i("HA", "Button Account Clicked");
194  1 Toast.makeText(this,
195    "More than one account is not allowed in this version",
196    Toast.LENGTH_LONG).show();
197  1 Intent intent = new Intent(this.getApplicationContext(),
198    AccountDetailActivity.class);
199  1 startActivity(intent);
200    // Account Selection
201  2 } else if (v == btnAccountSelection) {
202   
203  1 final CharSequence[] accounts;
204  1 Account account = new Account();
205  1 accounts = account.selectAccounts();
206  1 AlertDialog.Builder builder = new AlertDialog.Builder(this);
207  1 builder.setTitle("Chooese Account");
208  1 builder.setItems(accounts, new DialogInterface.OnClickListener() {
 
209  1 toggle public void onClick(DialogInterface dialog, int _item) {
210  1 saveApp.setAccountId(_item + 1);
211  1 setAccount(saveApp.getAccountId());
212  1 setPreview();
213  1 txtAccountSelection.setText(getString(R.string.strAccount)
214    + ": " + accounts[_item]);
215    }
216    });
217  1 AlertDialog dropdown = builder.create();
218  1 dropdown.show();
219    }
220    }
221   
222    /*------------------------------------------------------------------------------------------------
223    *--------------------------------------SET ACCOUNT--------------------------------------------------
224    *------------------------------------------------------------------------------------------------ */
225   
 
226  8 toggle public void setAccount(int id) {
227  8 Log.i("HA", "Set Account...");
228  8 saveApp.setAccountId(id);
229  8 Account account = new Account();
230  8 account.inflate(saveApp.getAccountId());
231  8 saveApp.setAccountDesc(account.getDescription());
232  8 saveApp.setCurrencyId(account.getCurrencyId());
233  8 Currency currency = new Currency();
234  8 currency.inflate(saveApp.getCurrencyId());
235  8 saveApp.setCurrencySymbol(currency.getSymbol());
236  8 txtAccountSelection.setText(getString(R.string.strAccountSelection)
237    + ": " + saveApp.getAccountDesc());
238    }
239   
240    /*------------------------------------------------------------------------------------------------
241    *--------------------------------------SET PREVIEW BUDGET + DAYS---------------------------------
242    *------------------------------------------------------------------------------------------------ */
243   
 
244  8 toggle public void setPreview() {
245  8 Log.i("HA", "Set Preview...");
246   
247    // Actual Budget
248  8 Account account = new Account();
249  8 account.inflate(saveApp.getAccountId());
250  8 saveApp.setBudget(account.getBudget());
251  8 saveApp.setStartDate(account.getStartDate());
252  8 saveApp.setCurrentBudget(Utilities.calculateCurrentBudget());
253  8 txtBudget.setText(saveApp.getCurrentBudget() + saveApp.getCurrencySymbol());
254   
255    // Number of days
256  8 String date = account.getStartDate();
257  8 saveApp.setCurrentDays(Utilities.daysUntilToday(date));
258  8 txtNumberOfDays.setText(String.valueOf(saveApp.getCurrentDays()));
259    }
260   
261    /*------------------------------------------------------------------------------------------------
262    *--------------------------------------LOCATION--------------------------------------------------
263    *------------------------------------------------------------------------------------------------ */
 
264  7 toggle private double[] getLocation() {
265  7 Log.i("HA", "Get Localization");
266  7 LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
267  7 List<String> providers = lm.getProviders(true);
268   
269  7 Location l = null;
270   
271  7 for (int i = providers.size() - 1; i >= 0; i--) {
272  7 l = lm.getLastKnownLocation(providers.get(i));
273  7 if (l != null) {
274  7 Log.i("OEA", "MAP");
275  7 break;
276    }
277    }
278   
279  7 double[] gps = new double[2];
280  7 if (l != null) {
281  7 gps[0] = l.getLatitude();
282  7 gps[1] = l.getLongitude();
283    }
284  7 if (gps[0] == 0.0 || gps[1] == 0.0) {
285  0 gps[0] = 40.416700;
286  0 gps[1] = -3.703900;
287    }
288  7 saveApp.setLatitude(gps[0]);
289  7 saveApp.setLongitude(gps[1]);
290  7 return gps;
291    }
292   
 
293  7 toggle public void getAddress() {
294  7 Log.i("HA", "Get Address");
295  7 currentLocation = getLocation();
296  7 Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());
297  7 List<Address> addresses;
298  7 try {
299  7 addresses = geoCoder.getFromLocation(currentLocation[0],
300    currentLocation[1], 1);
301  7 String addresDesc = "";
302  7 if (addresses.size() > 0)
303  21 for (int i = 0; i < addresses.get(0).getMaxAddressLineIndex(); i++)
304  14 addresDesc += addresses.get(0).getAddressLine(i) + "\n";
305  7 saveApp.setAddressDesc(addresDesc);
306    } catch (Exception ex) {
307    }
308    }
309    /*------------------------------------------------------------------------------------------------
310    *--------------------------------------MENU------------------------------------------------------
311    *------------------------------------------------------------------------------------------------ */
312   
 
313  0 toggle public boolean onCreateOptionsMenu(Menu menu) {
314  0 Log.i("ODA", "Menu Inflating...");
315  0 MenuInflater inflater = getMenuInflater();
316  0 inflater.inflate(R.menu.menuhome, menu);
317  0 Log.i("ODA", "Menu Inflated");
318  0 return true;
319    }
320   
 
321  0 toggle @Override
322    public boolean onOptionsItemSelected(MenuItem item) {
323  0 Log.i("ODA", "Menu...");
324  0 switch (item.getItemId()) {
325  0 case R.id.mnuAbout:
326  0 Log.i("ODA", "Menu Info");
327  0 Intent intentEdit = new Intent(this.getApplicationContext(),
328    AboutActivity.class);
329  0 startActivity(intentEdit);
330  0 return true;
331  0 default:
332  0 return super.onOptionsItemSelected(item);
333    }
334    }
335   
336    }