1 |
|
package com.loopback.androidapps.saveapp; |
2 |
|
|
3 |
|
import android.app.Activity; |
4 |
|
import android.app.DatePickerDialog; |
5 |
|
import android.app.Dialog; |
6 |
|
import android.app.TimePickerDialog; |
7 |
|
import android.content.Intent; |
8 |
|
import android.os.Bundle; |
9 |
|
import android.util.Log; |
10 |
|
import android.view.View; |
11 |
|
import android.widget.AdapterView; |
12 |
|
import android.widget.Button; |
13 |
|
import android.widget.DatePicker; |
14 |
|
import android.widget.TextView; |
15 |
|
import android.widget.TimePicker; |
16 |
|
|
|
|
| 74,6% |
Uncovered Elements: 44 (173) |
Complexity: 21 |
Complexity Density: 0,14 |
|
17 |
|
public class ChangeAutogeneratedActivity extends Activity implements |
18 |
|
AdapterView.OnItemSelectedListener, View.OnClickListener { |
19 |
|
|
20 |
|
private String dateSelected, timeSelected, dateInput, timeInput, |
21 |
|
dateTimeInput, addressSelected; |
22 |
|
|
23 |
|
private TextView txtAccount, txtDate, txtTime, txtLatitude, txtLongitude, |
24 |
|
txtChangeAddress; |
25 |
|
private Button btnChangeDate, btnChangeTime, btnChangeAddress, btnDiscard, |
26 |
|
btnSave; |
27 |
|
private double latitudeSelected, longitudeSelected; |
28 |
|
private AddressX address; |
29 |
|
private Integer receivedId, addressId; |
30 |
|
static final int DATE_DIALOG_ID = 0, TIME_DIALOG_ID = 1; |
31 |
|
private boolean hasBeenChanged; |
32 |
|
private SaveApp saveApp; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
38 |
7
|
public void onCreate(Bundle savedInstanceState) {... |
39 |
7
|
Log.i("CHA", "Init."); |
40 |
7
|
super.onCreate(savedInstanceState); |
41 |
7
|
setContentView(R.layout.changedateaddress); |
42 |
|
|
43 |
7
|
loadActivity(); |
44 |
|
} |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 1 |
Complexity Density: 0,05 |
|
50 |
7
|
public void loadActivity() {... |
51 |
7
|
saveApp = ((SaveApp) getApplicationContext()); |
52 |
|
|
53 |
7
|
Log.i("CHA", "Loading..."); |
54 |
|
|
55 |
7
|
txtAccount = (TextView) findViewById(R.id.txtAccount); |
56 |
7
|
txtDate = (TextView) findViewById(R.id.txtDate); |
57 |
7
|
txtTime = (TextView) findViewById(R.id.txtTime); |
58 |
7
|
txtLatitude = (TextView) findViewById(R.id.txtLatitude); |
59 |
7
|
txtLongitude = (TextView) findViewById(R.id.txtLongitude); |
60 |
7
|
btnChangeDate = (Button) findViewById(R.id.btnChangeDate); |
61 |
7
|
btnChangeTime = (Button) findViewById(R.id.btnChangeTime); |
62 |
7
|
btnChangeAddress = (Button) findViewById(R.id.btnChangeAddress); |
63 |
7
|
btnDiscard = (Button) findViewById(R.id.btnDiscard); |
64 |
7
|
btnSave = (Button) findViewById(R.id.btnSave); |
65 |
7
|
txtChangeAddress = (TextView) findViewById(R.id.txtChangeAddress); |
66 |
|
|
67 |
7
|
btnChangeDate.setOnClickListener(this); |
68 |
7
|
btnChangeTime.setOnClickListener(this); |
69 |
7
|
btnChangeAddress.setOnClickListener(this); |
70 |
7
|
btnSave.setOnClickListener(this); |
71 |
7
|
btnDiscard.setOnClickListener(this); |
72 |
|
|
73 |
7
|
Log.i("CHA", "Loading..."); |
74 |
|
|
75 |
|
} |
76 |
|
|
|
|
| 44,7% |
Uncovered Elements: 26 (47) |
Complexity: 3 |
Complexity Density: 0,07 |
|
77 |
7
|
public void onResume() {... |
78 |
7
|
super.onResume(); |
79 |
7
|
Bundle bundle = this.getIntent().getExtras(); |
80 |
|
|
81 |
7
|
receivedId = bundle.getInt("Id"); |
82 |
|
|
83 |
7
|
hasBeenChanged = bundle.getBoolean("HasBeenChanged"); |
84 |
7
|
if (hasBeenChanged) { |
85 |
0
|
addressSelected = bundle.getString("AddressDesc"); |
86 |
0
|
latitudeSelected = bundle.getDouble("Latitude"); |
87 |
0
|
longitudeSelected = bundle.getDouble("Longitude"); |
88 |
0
|
txtChangeAddress.setText(addressSelected); |
89 |
0
|
saveApp.outlay.setAddressDesc(addressSelected); |
90 |
0
|
saveApp.setLatitude(latitudeSelected); |
91 |
0
|
saveApp.setLongitude(longitudeSelected); |
92 |
0
|
txtChangeAddress.setText(addressSelected); |
93 |
0
|
txtLatitude.setText(String.valueOf(latitudeSelected)); |
94 |
0
|
txtLongitude.setText(String.valueOf(longitudeSelected)); |
95 |
0
|
txtDate.setText((Utilities.printDate(saveApp.outlay.getDate()) |
96 |
|
.subSequence(0, 10))); |
97 |
0
|
txtTime.setText(saveApp.outlay.getDate().subSequence(11, 16)); |
98 |
|
|
99 |
|
} else { |
100 |
|
|
101 |
|
|
102 |
7
|
if (receivedId > 0) { |
103 |
0
|
Outlay outlay = new Outlay(receivedId); |
104 |
0
|
saveApp.setDate(outlay.getDate()); |
105 |
0
|
txtDate.setText((Utilities.printDate(outlay.getDate()) |
106 |
|
.subSequence(0, 10))); |
107 |
0
|
txtTime.setText((outlay.getDate()).subSequence(11, 16)); |
108 |
0
|
txtChangeAddress.setText(outlay.getAddressDesc()); |
109 |
0
|
address = new AddressX(outlay.getAddressId()); |
110 |
0
|
txtLatitude.setText(String.valueOf(address.getLatitude())); |
111 |
0
|
txtLongitude.setText(String.valueOf(address.getLongitude())); |
112 |
|
|
113 |
0
|
addressSelected = outlay.getAddressDesc(); |
114 |
0
|
dateTimeInput = outlay.getDate(); |
115 |
0
|
latitudeSelected = address.getLatitude(); |
116 |
0
|
longitudeSelected = address.getLongitude(); |
117 |
|
|
118 |
|
|
119 |
|
} else { |
120 |
7
|
txtDate.setText((Utilities.printDate(Utilities.dateGetter()) |
121 |
|
.subSequence(0, 10))); |
122 |
7
|
txtTime.setText((Utilities.dateGetter()).subSequence(11, 16)); |
123 |
7
|
txtChangeAddress.setText(saveApp.getAddressDesc()); |
124 |
7
|
txtLatitude.setText(String.valueOf(saveApp.getLatitude())); |
125 |
7
|
txtLongitude.setText(String.valueOf(saveApp.getLongitude())); |
126 |
|
|
127 |
7
|
addressSelected = saveApp.getAddressDesc(); |
128 |
7
|
dateTimeInput = saveApp.getDate(); |
129 |
7
|
latitudeSelected = saveApp.getLatitude(); |
130 |
7
|
longitudeSelected = saveApp.getLongitude(); |
131 |
|
} |
132 |
7
|
dateInput = (String) txtDate.getText(); |
133 |
7
|
timeInput = (String) txtTime.getText(); |
134 |
|
|
135 |
7
|
txtAccount.setText(getString(R.string.strAccount) + ": " |
136 |
|
+ saveApp.getAccountDesc()); |
137 |
|
|
138 |
7
|
Log.i("CHA", "Loaded"); |
139 |
|
} |
140 |
|
|
141 |
|
} |
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
|
147 |
0
|
public void onBackPressed() {... |
148 |
0
|
Log.i("CHA", "Back Cklicked"); |
149 |
0
|
Bundle bundle = new Bundle(); |
150 |
0
|
bundle.putBoolean("IsAdding", saveApp.isAdding()); |
151 |
0
|
Intent intent = new Intent(this.getApplicationContext(), |
152 |
|
OutlayEditActivity.class); |
153 |
0
|
intent.putExtras(bundle); |
154 |
0
|
startActivity(intent); |
155 |
|
} |
156 |
|
|
|
|
| 96,7% |
Uncovered Elements: 2 (60) |
Complexity: 7 |
Complexity Density: 0,15 |
|
157 |
11
|
public void onClick(View v) {... |
158 |
11
|
Log.i("CHA", "Clicked"); |
159 |
|
|
160 |
11
|
if (v == btnChangeDate) { |
161 |
2
|
dateInput = (String) txtDate.getText(); |
162 |
2
|
showDialog(DATE_DIALOG_ID); |
163 |
|
|
164 |
|
|
165 |
9
|
} else if (v == btnChangeTime) { |
166 |
2
|
timeInput = (String) txtTime.getText(); |
167 |
2
|
showDialog(TIME_DIALOG_ID); |
168 |
|
|
169 |
|
|
170 |
7
|
} else if (v == btnChangeAddress) { |
171 |
3
|
dateInput = (String) txtDate.getText(); |
172 |
3
|
timeInput = (String) txtTime.getText(); |
173 |
3
|
dateTimeInput = (dateInput + " " + timeInput); |
174 |
3
|
saveApp.setDate(dateTimeInput); |
175 |
3
|
Bundle bundle = new Bundle(); |
176 |
3
|
bundle.putInt("Id", receivedId); |
177 |
3
|
Intent intent = new Intent(this.getApplicationContext(), |
178 |
|
MapAddressSelectionActivity.class); |
179 |
3
|
intent.putExtras(bundle); |
180 |
3
|
startActivity(intent); |
181 |
|
|
182 |
|
|
183 |
4
|
} else if (v == btnSave) { |
184 |
1
|
dateInput = (String) txtDate.getText(); |
185 |
1
|
timeInput = (String) txtTime.getText(); |
186 |
1
|
dateTimeInput = (dateInput + " " + timeInput); |
187 |
1
|
saveApp.outlay.setDate(dateTimeInput); |
188 |
1
|
saveApp.outlay.setAddressDesc(addressSelected); |
189 |
1
|
AddressX address = new AddressX(); |
190 |
1
|
addressId = address.insertOrGetId(addressSelected); |
191 |
1
|
address.inflate(addressId); |
192 |
1
|
if (address.getLatitude() == 0) { |
193 |
1
|
address.setLatitude(Double.valueOf(latitudeSelected)); |
194 |
1
|
address.setLongitude(Double.valueOf(longitudeSelected)); |
195 |
1
|
address.update(); |
196 |
|
} |
197 |
|
|
198 |
1
|
Bundle bundle = new Bundle(); |
199 |
1
|
bundle.putBoolean("HasChanges", true); |
200 |
1
|
bundle.putInt("Id", receivedId); |
201 |
1
|
bundle.putString("Date", dateTimeInput); |
202 |
1
|
bundle.putInt("AddressId", addressId); |
203 |
1
|
bundle.putString("AddressDesc", addressSelected); |
204 |
1
|
bundle.putDouble("Latitude", latitudeSelected); |
205 |
1
|
bundle.putDouble("Longitude", longitudeSelected); |
206 |
|
|
207 |
1
|
Intent intent = new Intent(this.getApplicationContext(), |
208 |
|
OutlayEditActivity.class); |
209 |
1
|
intent.putExtras(bundle); |
210 |
1
|
startActivity(intent); |
211 |
|
|
212 |
|
|
213 |
3
|
} else if (v == btnDiscard) { |
214 |
3
|
Bundle bundle = new Bundle(); |
215 |
3
|
bundle.putBoolean("HasChanges", false); |
216 |
3
|
bundle.putInt("Id", receivedId); |
217 |
3
|
Intent intent = new Intent(this.getApplicationContext(), |
218 |
|
OutlayEditActivity.class); |
219 |
3
|
intent.putExtras(bundle); |
220 |
3
|
startActivity(intent); |
221 |
|
} |
222 |
|
} |
223 |
|
|
224 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
225 |
0
|
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,... |
226 |
|
long arg3) { |
227 |
|
|
228 |
|
|
229 |
|
} |
230 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
231 |
0
|
public void onNothingSelected(AdapterView<?> arg0) {... |
232 |
|
|
233 |
|
|
234 |
|
} |
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
public DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() { |
242 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
243 |
4
|
public void onDateSet(DatePicker view, int year, int monthOfYear,... |
244 |
|
int dayOfMonth) { |
245 |
4
|
Log.i("CHA", "Date Picker"); |
246 |
4
|
dateSelected = Utilities.formatDate(year, monthOfYear, dayOfMonth, |
247 |
|
0, 0); |
248 |
4
|
txtDate.setText(Utilities.printDate(dateSelected) |
249 |
|
.subSequence(0, 10)); |
250 |
|
} |
251 |
|
}; |
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
private TimePickerDialog.OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() { |
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
257 |
4
|
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {... |
258 |
4
|
Log.i("CHA", "Time Picker"); |
259 |
4
|
timeSelected = String.format("%02d", hourOfDay) + ':' |
260 |
|
+ String.format("%02d", minute); |
261 |
4
|
txtTime.setText(timeSelected); |
262 |
|
} |
263 |
|
}; |
264 |
|
|
265 |
|
|
266 |
|
|
267 |
|
|
|
|
| 66,7% |
Uncovered Elements: 7 (21) |
Complexity: 4 |
Complexity Density: 0,21 |
|
268 |
4
|
protected Dialog onCreateDialog(int id) {... |
269 |
4
|
Log.i("CHA", "Dialog"); |
270 |
4
|
int year, month, day, hour, minute; |
271 |
4
|
if (dateInput.substring(0, 1).equals("N")) { |
272 |
0
|
year = 2012; |
273 |
0
|
month = 0; |
274 |
0
|
day = 1; |
275 |
0
|
hour = 0; |
276 |
0
|
minute = 0; |
277 |
|
} else { |
278 |
4
|
year = Integer.valueOf(Utilities.getDateUnit(dateInput, 'y')); |
279 |
4
|
month = Integer.valueOf(Utilities.getDateUnit(dateInput, 'M')) - 1; |
280 |
4
|
day = Integer.valueOf(Utilities.getDateUnit(dateInput, 'd')); |
281 |
4
|
hour = Integer.valueOf((String) timeInput.subSequence(0, 2)); |
282 |
4
|
minute = Integer.valueOf((String) timeInput.subSequence(3, 5)); |
283 |
|
} |
284 |
4
|
switch (id) { |
285 |
2
|
case DATE_DIALOG_ID: |
286 |
2
|
return new DatePickerDialog(this, mDateSetListener, year, month, |
287 |
|
day); |
288 |
|
|
289 |
2
|
case TIME_DIALOG_ID: |
290 |
2
|
return new TimePickerDialog(this, mTimeSetListener, hour, minute, |
291 |
|
false); |
292 |
|
} |
293 |
0
|
return null; |
294 |
|
} |
295 |
|
|
296 |
|
} |