1 |
|
package com.loopback.androidapps.saveapp; |
2 |
|
|
3 |
|
import java.util.ArrayList; |
4 |
|
import java.util.List; |
5 |
|
|
6 |
|
import android.app.Activity; |
7 |
|
import android.app.DatePickerDialog; |
8 |
|
import android.app.Dialog; |
9 |
|
import android.content.Intent; |
10 |
|
import android.os.Bundle; |
11 |
|
import android.text.InputType; |
12 |
|
import android.util.Log; |
13 |
|
import android.view.View; |
14 |
|
import android.widget.AdapterView; |
15 |
|
import android.widget.AdapterView.OnItemSelectedListener; |
16 |
|
import android.widget.ArrayAdapter; |
17 |
|
import android.widget.Button; |
18 |
|
import android.widget.DatePicker; |
19 |
|
import android.widget.EditText; |
20 |
|
import android.widget.Spinner; |
21 |
|
import android.widget.TextView; |
22 |
|
|
|
|
| 90,7% |
Uncovered Elements: 12 (129) |
Complexity: 20 |
Complexity Density: 0,2 |
|
23 |
|
public class AccountEditActivity extends Activity implements |
24 |
|
AdapterView.OnItemSelectedListener, View.OnClickListener { |
25 |
|
|
26 |
|
private String date_selected, dateInput; |
27 |
|
|
28 |
|
private TextView txtStartDateValue, txtEndDateValue; |
29 |
|
private int periodId; |
30 |
|
private EditText edtNameValue, edtBudgetValue; |
31 |
|
private Button btnChangeStartDate, btnChangeEndDate, btnAcceppt, |
32 |
|
btnDiscard; |
33 |
|
private Spinner spnPeriod, spnCurrency; |
34 |
|
public boolean isEuropeanCalendar = true; |
35 |
|
public Account account; |
36 |
|
public Currency currency; |
37 |
|
private List<String> currencies = new ArrayList<String>(); |
38 |
|
private List<String> periods = new ArrayList<String>(); |
39 |
|
static final int DATE_DIALOG_ID = 0, DATE_DIALOG_ID2 = 1; |
40 |
|
private boolean startDateSelected = false; |
41 |
|
|
42 |
|
public SaveApp saveApp; |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
48 |
2
|
public void onCreate(Bundle savedInstanceState) {... |
49 |
2
|
Log.i("OEA", "Init"); |
50 |
2
|
super.onCreate(savedInstanceState); |
51 |
2
|
setContentView(R.layout.accountedit); |
52 |
2
|
loadActivity(); |
53 |
|
} |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (41) |
Complexity: 1 |
Complexity Density: 0,02 |
|
59 |
2
|
public void loadActivity() {... |
60 |
|
|
61 |
2
|
Log.i("AE", "Loading..."); |
62 |
2
|
saveApp = ((SaveApp) getApplicationContext()); |
63 |
|
|
64 |
2
|
edtNameValue = (EditText) findViewById(R.id.edtNameValue); |
65 |
2
|
edtBudgetValue = (EditText) findViewById(R.id.edtBudgetValue); |
66 |
2
|
spnPeriod = (Spinner) findViewById(R.id.spnPeriod); |
67 |
2
|
txtStartDateValue = (TextView) findViewById(R.id.txtStartDateValue); |
68 |
2
|
txtEndDateValue = (TextView) findViewById(R.id.txtEndDateValue); |
69 |
2
|
btnChangeStartDate = (Button) findViewById(R.id.btnChangeStartDate); |
70 |
2
|
btnChangeEndDate = (Button) findViewById(R.id.btnChangeEndDate); |
71 |
2
|
spnCurrency = (Spinner) findViewById(R.id.spnCurrency); |
72 |
2
|
btnAcceppt = (Button) findViewById(R.id.btnAccept); |
73 |
2
|
btnDiscard = (Button) findViewById(R.id.btnDiscard); |
74 |
|
|
75 |
2
|
btnChangeStartDate.setOnClickListener(this); |
76 |
2
|
btnChangeEndDate.setOnClickListener(this); |
77 |
2
|
btnAcceppt.setOnClickListener(this); |
78 |
2
|
btnDiscard.setOnClickListener(this); |
79 |
|
|
80 |
2
|
account = new Account(saveApp.getAccountId()); |
81 |
|
|
82 |
2
|
Log.i("AD", "Loading..."); |
83 |
2
|
edtNameValue.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS); |
84 |
2
|
edtNameValue.setText(account.getDescription()); |
85 |
2
|
edtBudgetValue.setText(String.valueOf(account.getBudget())); |
86 |
2
|
txtStartDateValue.setText(account.getStartDate().subSequence(0, 10)); |
87 |
2
|
txtEndDateValue.setText(account.getEndDate()); |
88 |
|
|
89 |
|
|
90 |
2
|
periods.add("None"); |
91 |
2
|
periods.add("Week"); |
92 |
2
|
periods.add("Month"); |
93 |
2
|
periods.add("Year"); |
94 |
2
|
getPeriod(account.getPeriod()); |
95 |
2
|
spnPeriod.setOnItemSelectedListener((OnItemSelectedListener) this); |
96 |
2
|
ArrayAdapter<String> adapterPeriod = new ArrayAdapter<String>(this, |
97 |
|
android.R.layout.simple_expandable_list_item_1, periods); |
98 |
2
|
adapterPeriod |
99 |
|
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
100 |
2
|
spnPeriod.setAdapter(adapterPeriod); |
101 |
2
|
spnPeriod.setSelection(periodId); |
102 |
|
|
103 |
|
|
104 |
2
|
currency = new Currency(); |
105 |
2
|
currencies = currency.selectCurrencies(); |
106 |
2
|
spnCurrency.setOnItemSelectedListener((OnItemSelectedListener) this); |
107 |
2
|
ArrayAdapter<String> adapterCurrency = new ArrayAdapter<String>(this, |
108 |
|
android.R.layout.simple_expandable_list_item_1, currencies); |
109 |
2
|
adapterCurrency |
110 |
|
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
111 |
2
|
spnCurrency.setAdapter(adapterCurrency); |
112 |
2
|
spnCurrency.setSelection(saveApp.getCurrencyId() - 1); |
113 |
|
|
114 |
2
|
Log.i("AE", "Loaded"); |
115 |
|
|
116 |
|
} |
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
122 |
0
|
public void onBackPressed() {... |
123 |
0
|
Intent intent = new Intent(this.getApplicationContext(), |
124 |
|
AccountDetailActivity.class); |
125 |
0
|
startActivity(intent); |
126 |
|
} |
127 |
|
|
|
|
| 97,2% |
Uncovered Elements: 1 (36) |
Complexity: 5 |
Complexity Density: 0,18 |
|
128 |
4
|
public void onClick(View v) {... |
129 |
|
|
130 |
4
|
if (v == btnAcceppt) { |
131 |
1
|
Log.i("AE", "Edit Account"); |
132 |
1
|
Log.i("AE", "Updating..."); |
133 |
|
|
134 |
1
|
account.setDescription(String.valueOf(edtNameValue.getText())); |
135 |
1
|
account.setCurrencyId(spnCurrency.getSelectedItemPosition() + 1); |
136 |
1
|
account.setPeriod((String) spnPeriod.getSelectedItem()); |
137 |
1
|
account.setStartDate((String) txtStartDateValue.getText()); |
138 |
1
|
account.setEndDate((String) txtEndDateValue.getText()); |
139 |
1
|
account.setBudget(Integer.valueOf(String.valueOf(edtBudgetValue |
140 |
|
.getText()))); |
141 |
1
|
account.update(); |
142 |
1
|
saveApp.setAccountDesc(account.getDescription().toString()); |
143 |
1
|
saveApp.setCurrencyId(account.getCurrencyId()); |
144 |
1
|
currency.inflate(saveApp.getCurrencyId()); |
145 |
1
|
saveApp.setCurrencySymbol(currency.getSymbol().toString()); |
146 |
|
|
147 |
1
|
Log.i("AE", "Updated."); |
148 |
1
|
Intent intent = new Intent(this.getApplicationContext(), |
149 |
|
AccountDetailActivity.class); |
150 |
1
|
startActivity(intent); |
151 |
|
|
152 |
3
|
} else if (v == btnDiscard) { |
153 |
1
|
Intent intent = new Intent(this.getApplicationContext(), |
154 |
|
AccountDetailActivity.class); |
155 |
1
|
startActivity(intent); |
156 |
|
|
157 |
2
|
} else if (v == btnChangeStartDate) { |
158 |
1
|
dateInput = account.getStartDate(); |
159 |
1
|
showDialog(DATE_DIALOG_ID); |
160 |
1
|
startDateSelected = true; |
161 |
|
|
162 |
1
|
} else if (v == btnChangeEndDate) { |
163 |
1
|
dateInput = account.getEndDate(); |
164 |
1
|
showDialog(DATE_DIALOG_ID2); |
165 |
1
|
startDateSelected = false; |
166 |
|
|
167 |
|
} |
168 |
|
} |
169 |
|
|
170 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
171 |
9
|
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,... |
172 |
|
long arg3) { |
173 |
|
|
174 |
|
|
175 |
|
} |
176 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
177 |
0
|
public void onNothingSelected(AdapterView<?> arg0) {... |
178 |
|
|
179 |
|
|
180 |
|
} |
181 |
|
|
182 |
|
|
|
|
| 53,8% |
Uncovered Elements: 6 (13) |
Complexity: 4 |
Complexity Density: 0,57 |
|
183 |
2
|
public void getPeriod(String period) {... |
184 |
2
|
if (period.equals("Week")) |
185 |
1
|
periodId = 1; |
186 |
1
|
else if (period.equals("Month")) |
187 |
1
|
periodId = 2; |
188 |
0
|
else if (period.equals("Year")) |
189 |
0
|
periodId = 3; |
190 |
|
else |
191 |
0
|
periodId = 0; |
192 |
|
} |
193 |
|
|
194 |
|
|
195 |
|
public DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() { |
196 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0,33 |
|
197 |
4
|
public void onDateSet(DatePicker view, int year, int monthOfYear,... |
198 |
|
int dayOfMonth) { |
199 |
4
|
date_selected = Utilities.formatDate(year, monthOfYear, dayOfMonth, |
200 |
|
0, 0); |
201 |
4
|
if (startDateSelected) { |
202 |
2
|
account.setStartDate(date_selected); |
203 |
2
|
txtStartDateValue.setText(Utilities.printDate( |
204 |
|
account.getStartDate()).subSequence(0, 10)); |
205 |
|
} else { |
206 |
2
|
account.setEndDate(date_selected); |
207 |
2
|
txtEndDateValue.setText(Utilities.printDate( |
208 |
|
account.getEndDate()).subSequence(0, 10)); |
209 |
|
} |
210 |
|
} |
211 |
|
}; |
212 |
|
|
|
|
| 93,8% |
Uncovered Elements: 1 (16) |
Complexity: 4 |
Complexity Density: 0,29 |
|
213 |
2
|
protected Dialog onCreateDialog(int id) {... |
214 |
2
|
int year, month, day; |
215 |
2
|
if (dateInput.substring(0, 1).equals("N")) { |
216 |
1
|
year = 2012; |
217 |
1
|
month = 0; |
218 |
1
|
day = 1; |
219 |
|
} else { |
220 |
1
|
year = Integer.valueOf(Utilities.getDateUnit(dateInput, 'y')); |
221 |
1
|
month = Integer.valueOf(Utilities.getDateUnit(dateInput, 'M')) - 1; |
222 |
1
|
day = Integer.valueOf(Utilities.getDateUnit(dateInput, 'd')); |
223 |
|
} |
224 |
2
|
switch (id) { |
225 |
1
|
case DATE_DIALOG_ID: |
226 |
1
|
return new DatePickerDialog(this, mDateSetListener, year, month, |
227 |
|
day); |
228 |
|
|
229 |
1
|
case DATE_DIALOG_ID2: |
230 |
1
|
return new DatePickerDialog(this, mDateSetListener, year, month, |
231 |
|
day); |
232 |
|
} |
233 |
0
|
return null; |
234 |
|
|
235 |
|
} |
236 |
|
} |