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
161   370   22   16,1
24   235   0,14   10
10     2,2  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  OutlayEditActivity       Line # 24 161 22 89,7% 0.8974359
 
No Tests
 
1    /**
2    * This Activity can be called from three different ones.
3    * Threre fore there are 2 control flags to know from whom is called.
4    * -hasChanges: Home and Detail vs. Change Autogenerated
5    * -id: Home(==0) vs Detail(>0)
6    */
7   
8    package com.loopback.androidapps.saveapp;
9   
10    import android.app.Activity;
11    import android.content.Intent;
12    import android.os.Bundle;
13    import android.text.InputType;
14    import android.util.Log;
15    import android.view.View;
16    import android.widget.ArrayAdapter;
17    import android.widget.AutoCompleteTextView;
18    import android.widget.Button;
19    import android.widget.EditText;
20    import android.widget.ImageButton;
21    import android.widget.TextView;
22    import android.widget.Toast;
23   
 
24    public class OutlayEditActivity extends Activity implements
25    View.OnClickListener {
26   
27    private ImageButton btnPhoto, btnNotes, btnFile;
28    private Button btnAccept, btnAddressChange;
29    private EditText edtCharge;
30    private AutoCompleteTextView edtItem, edtPlace;
31    private TextView txtAccount, txtAddress, txtDate;
32    private Outlay outlay;
33    private String note, date, item, place, album, addressDesc, receivedDate,
34    receivedAddressDesc;
35    public boolean isAdding, receivedHasChanges;
36    private double latitude, longitude, receivedLatitude, receivedLongitude;
37    private int charge = 0, receivedId = 0, addressId = 1;
38    public static String NOTE, ADDRESS_DESC;
39   
40    public SaveApp saveApp;
41   
42    /*------------------------------------------------------------------------------------------------
43    *--------------------------------------ONCREATE--------------------------------------------------
44    *------------------------------------------------------------------------------------------------ */
45   
 
46  9 toggle public void onCreate(Bundle savedInstanceState) {
47  9 Log.i("OEA", "Init");
48  9 super.onCreate(savedInstanceState);
49  9 setContentView(R.layout.editoutlay);
50  9 loadActivity();
51    }
52   
53    /*------------------------------------------------------------------------------------------------
54    *--------------------------------------LOAD--------------------------------------------------
55    *------------------------------------------------------------------------------------------------ */
 
56  9 toggle public void loadActivity() {
57   
58  9 Log.i("OEA", "Loading...");
59  9 saveApp = ((SaveApp) getApplicationContext());
60   
61  9 note = null;
62  9 btnPhoto = (ImageButton) findViewById(R.id.btnPhoto);
63  9 btnNotes = (ImageButton) findViewById(R.id.btnNotes);
64  9 btnFile = (ImageButton) findViewById(R.id.btnFile);
65  9 btnAccept = (Button) findViewById(R.id.btnAccept);
66  9 btnAddressChange = (Button) findViewById(R.id.btnAddressChange);
67  9 edtCharge = (EditText) findViewById(R.id.edtCharge);
68  9 edtItem = (AutoCompleteTextView) findViewById(R.id.edtItem);
69  9 edtPlace = (AutoCompleteTextView) findViewById(R.id.edtPlace);
70  9 txtAccount = (TextView) findViewById(R.id.txtAccount);
71  9 txtAddress = (TextView) findViewById(R.id.txtAddress);
72  9 txtDate = (TextView) findViewById(R.id.txtDate);
73   
74  9 edtItem.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
75  9 edtPlace.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
76   
77  9 btnPhoto.setOnClickListener(this);
78  9 btnNotes.setOnClickListener(this);
79  9 btnFile.setOnClickListener(this);
80  9 btnAccept.setOnClickListener(this);
81  9 btnAddressChange.setOnClickListener(this);
82   
83    }
84   
85    /*------------------------------------------------------------------------------------------------
86    *--------------------------------------ONRESUME--------------------------------------------------
87    *------------------------------------------------------------------------------------------------ */
88   
 
89  14 toggle public void onResume() {
90  14 super.onResume();
91  14 restoreState();
92  14 settings();
93    }
94   
 
95  14 toggle public void restoreState() {
96    // Load Autocomplete items
97  14 final String[] items;
98  14 Item itemAutoComplete = new Item();
99  14 items = itemAutoComplete.selectItems();
100  14 ArrayAdapter<String> adapterItems = new ArrayAdapter<String>(this,
101    R.layout.autocompleteitem, items);
102  14 edtItem.setAdapter(adapterItems);
103  14 edtItem.setThreshold(1);
104   
105  14 final String[] places;
106  14 Place placeAutoComplete = new Place();
107  14 places = placeAutoComplete.selectPlaces();
108  14 ArrayAdapter<String> adapterPlaces = new ArrayAdapter<String>(this,
109    R.layout.autocompleteplace, places);
110  14 edtPlace.setAdapter(adapterPlaces);
111  14 edtPlace.setThreshold(1);
112   
113  14 charge = saveApp.outlay.getCharge();
114  14 item = saveApp.outlay.getItemDesc();
115  14 place = saveApp.outlay.getPlaceDesc();
116  14 note = saveApp.outlay.getNote();
117  14 date = saveApp.outlay.getDate();
118  14 addressDesc = saveApp.outlay.getAddressDesc();
119  14 latitude = saveApp.getLatitude();
120  14 longitude = saveApp.getLongitude();
121   
122  14 edtCharge.setText(String.valueOf(charge));
123  14 edtItem.setText(item);
124  14 edtPlace.setText(place);
125  14 txtDate.setText(date);
126  14 txtAddress.setText(addressDesc);
127  14 txtAccount.setText(getString(R.string.strAccount) + ": "
128    + saveApp.getAccountDesc());
129    }
130   
131    /*------------------------------------------------------------------------------------------------
132    *--------------------------------------ONPAUSE--------------------------------------------------
133    *------------------------------------------------------------------------------------------------ */
134   
 
135  14 toggle public void onPause() {
136  14 saveState();
137  14 super.onPause();
138    }
139   
 
140  25 toggle public void saveState() {
141  25 charge = Utilities.stringToInt(edtCharge.getText().toString());
142  25 item = edtItem.getText().toString();
143  25 place = edtPlace.getText().toString();
144  25 album = "";
145  25 addressDesc = txtAddress.getText().toString();
146  25 date = txtDate.getText().toString();
147   
148  25 saveApp.outlay.setCharge(charge);
149  25 saveApp.outlay.setItemDesc(item);
150  25 saveApp.outlay.setPlaceDesc(place);
151  25 saveApp.outlay.setNote(note);
152  25 saveApp.outlay.setAlbumId(1);
153  25 saveApp.outlay.setDate(date);
154  25 saveApp.outlay.setAddressDesc(addressDesc);
155  25 saveApp.setLatitude(latitude);
156  25 saveApp.setLongitude(longitude);
157    }
158   
159    /*------------------------------------------------------------------------------------------------
160    *--------------------------------------GET DATA FROM PREVIOUS ACTIVITY---------------------------
161    *------------------------------------------------------------------------------------------------ */
 
162  14 toggle public void settings() {
163    // Initialize variables
164   
165    /*-------------------------------------- GET DATA -----------------------------*/
166   
167  14 Bundle bundle = this.getIntent().getExtras();
168  14 receivedHasChanges = bundle.getBoolean("HasChanges");
169   
170    /*--------------------------------------FROM CHANGE AUTOGENERATED-----------------------------*/
171   
172  14 if (receivedHasChanges) {
173  1 isAdding = saveApp.isAdding();
174  1 receivedId = bundle.getInt("Id");
175  1 receivedDate = bundle.getString("Date");
176  1 receivedAddressDesc = bundle.getString("AddressDesc");
177  1 receivedLatitude = bundle.getDouble("Latitude");
178  1 receivedLongitude = bundle.getDouble("Longitude");
179   
180    // Get Received Data
181  1 date = receivedDate;
182  1 addressDesc = receivedAddressDesc;
183  1 latitude = receivedLatitude;
184  1 longitude = receivedLongitude;
185   
186    // Set Received Data
187  1 txtAddress.setText((addressDesc == null) ? "No data" : addressDesc);
188  1 txtDate.setText(date);
189   
190    } else {
191    // The previous activity is Home or DetailOutlay
192  13 isAdding = saveApp.isAdding();
193  13 receivedId = bundle.getInt("Id");
194   
195    /*--------------------------------------FROM DETAIL-----------------------------------------*/
196    // if (receivedId > 0) {
197    // outlay = new Outlay(receivedId);
198    //
199    // addressDesc = outlay.getAddressDesc();
200    //
201    // edtCharge.setText(String.valueOf(outlay.getCharge()));
202    // edtItem.setText(outlay.getItemDesc());
203    // edtPlace.setText(outlay.getPlaceDesc());
204    //
205    // txtAccount.setText(getString(R.string.strAccount) + ": "
206    // + saveApp.getAccountDesc());
207    //
208    // txtAddress.setText(addressDesc);
209    // txtDate.setText(date);
210   
211    /*--------------------------------------FROM HOME-----------------------------------------*/
212    // } else {
213    // // Get Today Date
214    // saveApp.setDate(Utilities.dateGetter());
215    //
216    // // Set Global Variables
217    // date = saveApp.getDate();
218    // addressDesc = saveApp.getAddressDesc();
219    // latitude = saveApp.getLatitude();
220    // longitude = saveApp.getLongirude();
221    //
222    // // Set Activity texts
223    // txtAccount.setText(getString(R.string.strAccount) + ": "
224    // + saveApp.getAccountDesc());
225    // txtAddress.setText((addressDesc == null) ? "No data"
226    // : addressDesc);
227    // txtDate.setText(date);
228    // Log.i("OEA", "Loaded");
229    // }
230    }
231   
232    }
233   
234    /*------------------------------------------------------------------------------------------------
235    *--------------------------------------ONBACK--------------------------------------------------
236    *------------------------------------------------------------------------------------------------ */
237   
 
238  0 toggle public void onBackPressed() {
239  0 Log.i("OEA", "Back Pressed...");
240  0 if (receivedId > 0) {
241  0 Intent intent = new Intent(this.getApplicationContext(),
242    OutlaysListActivity.class);
243  0 Log.i("OEA", "Starting Activity Outlay List");
244  0 startActivity(intent);
245    } else {
246  0 Intent intent = new Intent(this.getApplicationContext(),
247    HomeActivity.class);
248  0 Log.i("OEA", "Starting Activity Outlay List");
249  0 startActivity(intent);
250    }
251    }
252   
253    /*------------------------------------------------------------------------------------------------
254    *--------------------------------------CLICKS--------------------------------------------------
255    *------------------------------------------------------------------------------------------------ */
256   
 
257  16 toggle public void onClick(View v) {
258  16 if (v == btnAccept) {
259  5 Log.i("OEA", "New/Edit Outlay");
260    // Inflate the Outlay
261  5 outlay = new Outlay();
262  5 charge = Utilities.stringToInt(edtCharge.getText().toString());
263  5 item = edtItem.getText().toString();
264  5 place = edtPlace.getText().toString();
265  5 album = "";
266    /*--------------------------------------FROM CHANGE AUTOGENERATED-----------------------------------------*/
267  5 if (receivedHasChanges) { // Update SaveApp
268  0 addressDesc = receivedAddressDesc;
269  0 date = saveApp.outlay.getDate();
270  0 saveApp.setAddressDesc(receivedAddressDesc);
271  0 saveApp.setLatitude(receivedLatitude);
272  0 saveApp.setLongitude(receivedLongitude);
273    }
274   
275    /*--------------------------------------FROM DETAIL-----------------------------------------*/
276  5 if (receivedId > 0) {
277  3 outlay.inflate(receivedId);
278  3 outlay.setCharge(charge);
279  3 outlay.setItemDesc(item);
280  3 outlay.setPlaceDesc(place);
281  3 outlay.setAddressId(addressId);
282  3 outlay.setAddressDesc(addressDesc);
283  3 outlay.setDate(date);
284  3 outlay.setNote(note);
285   
286    // TODO setAlbum()
287   
288  3 Log.i("OEA", "Updating Outlay...");
289  3 outlay.update();
290  3 saveApp.setCurrentBudget(Utilities.calculateCurrentBudget());
291  3 saveApp.setCurrentDays(Utilities.daysUntilToday(saveApp
292    .getStartDate()));
293   
294  3 Bundle bundle = new Bundle();
295  3 bundle.putInt("Id", receivedId);
296  3 Intent intent = new Intent(this.getApplicationContext(),
297    OutlayDetailActivity.class);
298  3 intent.putExtras(bundle);
299  3 Log.i("OEA", "Starting Activity Outlay Detail");
300  3 startActivity(intent);
301   
302    /*--------------------------------------FROM HOME-----------------------------------------*/
303    } else {
304  2 if (!isAdding)
305  1 charge = charge * (-1);
306   
307    // Insert
308  2 outlay.insert(saveApp.getAccountId(), charge, date, note, item,
309    place, album, addressDesc, longitude, latitude);
310   
311    // Recalculate Global Variables
312  2 saveApp.setCurrentBudget(Utilities.calculateCurrentBudget());
313  2 saveApp.setCurrentDays(Utilities.daysUntilToday(saveApp
314    .getStartDate()));
315   
316    // Jump to List Activity
317  2 Intent intent = new Intent(this.getApplicationContext(),
318    OutlaysListActivity.class);
319  2 Log.i("OEA", "Starting Activity Outlay Detail");
320  2 startActivity(intent);
321    }
322   
323    /* ******************************************************************************** */
324  11 } else if (v == btnNotes) {
325  5 saveState();
326  5 Bundle bundle = new Bundle();
327  5 bundle.putString("Note", saveApp.outlay.getNote());
328  5 Intent intent = new Intent(this.getApplicationContext(),
329    NoteActivity.class);
330  5 intent.putExtras(bundle);
331  5 startActivityForResult(intent, 0);
332   
333    /* ******************************************************************************** */
334  6 } else if (v == btnFile) {
335  1 saveState();
336  1 Toast.makeText(this,
337    "You can not link files in this version. Upgrade Now!",
338    Toast.LENGTH_SHORT).show();
339    /* ******************************************************************************** */
340  5 } else if (v == btnPhoto) {
341  1 saveState();
342    // Intent intent = new Intent(this.getApplicationContext(),
343    // PhotoActivity.class);
344    // startActivity(intent);
345  1 Toast.makeText(this,
346    "You can not save the photo in this version. Upgrade Now!",
347    Toast.LENGTH_SHORT).show();
348    /* ******************************************************************************** */
349  4 } else if (v == btnAddressChange) {
350  4 saveState();
351  4 Bundle bundle = new Bundle();
352  4 bundle.putInt("Id", receivedId);
353  4 bundle.putBoolean("HasBeenChanged", false);
354  4 Intent intent = new Intent(this.getApplicationContext(),
355    ChangeAutogeneratedActivity.class);
356  4 intent.putExtras(bundle);
357  4 startActivity(intent);
358    // startActivityForResult(intent, requestCode);
359    }
360    }
361   
 
362  5 toggle protected void onActivityResult(int requestCode, int resultCode, Intent data) {
363  5 note = data.getStringExtra("Note");
364  5 saveApp.outlay.setNote(note);
365  5 if (note != null)
366  5 Toast.makeText(this, "Note Added", Toast.LENGTH_SHORT).show();
367   
368    }
369   
370    }