1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
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 |
|
|
|
|
| 89,7% |
Uncovered Elements: 20 (195) |
Complexity: 22 |
Complexity Density: 0,14 |
|
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 |
|
|
44 |
|
|
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
46 |
9
|
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 |
|
|
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 1 |
Complexity Density: 0,05 |
|
56 |
9
|
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 |
|
|
87 |
|
|
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
89 |
14
|
public void onResume() {... |
90 |
14
|
super.onResume(); |
91 |
14
|
restoreState(); |
92 |
14
|
settings(); |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 1 |
Complexity Density: 0,04 |
|
95 |
14
|
public void restoreState() {... |
96 |
|
|
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 |
|
|
133 |
|
|
134 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
135 |
14
|
public void onPause() {... |
136 |
14
|
saveState(); |
137 |
14
|
super.onPause(); |
138 |
|
} |
139 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0,07 |
|
140 |
25
|
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 |
|
|
161 |
|
|
|
|
| 95,2% |
Uncovered Elements: 1 (21) |
Complexity: 3 |
Complexity Density: 0,18 |
|
162 |
14
|
public void settings() {... |
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
14
|
Bundle bundle = this.getIntent().getExtras(); |
168 |
14
|
receivedHasChanges = bundle.getBoolean("HasChanges"); |
169 |
|
|
170 |
|
|
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 |
|
|
181 |
1
|
date = receivedDate; |
182 |
1
|
addressDesc = receivedAddressDesc; |
183 |
1
|
latitude = receivedLatitude; |
184 |
1
|
longitude = receivedLongitude; |
185 |
|
|
186 |
|
|
187 |
1
|
txtAddress.setText((addressDesc == null) ? "No data" : addressDesc); |
188 |
1
|
txtDate.setText(date); |
189 |
|
|
190 |
|
} else { |
191 |
|
|
192 |
13
|
isAdding = saveApp.isAdding(); |
193 |
13
|
receivedId = bundle.getInt("Id"); |
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
} |
231 |
|
|
232 |
|
} |
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0,25 |
|
238 |
0
|
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 |
|
|
255 |
|
|
256 |
|
|
|
|
| 90,9% |
Uncovered Elements: 7 (77) |
Complexity: 9 |
Complexity Density: 0,15 |
|
257 |
16
|
public void onClick(View v) {... |
258 |
16
|
if (v == btnAccept) { |
259 |
5
|
Log.i("OEA", "New/Edit Outlay"); |
260 |
|
|
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 |
|
|
267 |
5
|
if (receivedHasChanges) { |
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 |
|
|
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 |
|
|
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 |
|
|
303 |
|
} else { |
304 |
2
|
if (!isAdding) |
305 |
1
|
charge = charge * (-1); |
306 |
|
|
307 |
|
|
308 |
2
|
outlay.insert(saveApp.getAccountId(), charge, date, note, item, |
309 |
|
place, album, addressDesc, longitude, latitude); |
310 |
|
|
311 |
|
|
312 |
2
|
saveApp.setCurrentBudget(Utilities.calculateCurrentBudget()); |
313 |
2
|
saveApp.setCurrentDays(Utilities.daysUntilToday(saveApp |
314 |
|
.getStartDate())); |
315 |
|
|
316 |
|
|
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 |
|
|
343 |
|
|
344 |
|
|
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 |
|
|
359 |
|
} |
360 |
|
} |
361 |
|
|
|
|
| 83,3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
362 |
5
|
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 |
|
} |