1 |
|
package com.loopback.androidapps.saveapp; |
2 |
|
|
3 |
|
import java.text.ParseException; |
4 |
|
import java.text.SimpleDateFormat; |
5 |
|
import java.util.ArrayList; |
6 |
|
import java.util.Calendar; |
7 |
|
import java.util.Date; |
8 |
|
|
9 |
|
import android.app.AlertDialog; |
10 |
|
import android.content.DialogInterface; |
11 |
|
import android.database.Cursor; |
12 |
|
import android.util.Log; |
13 |
|
import android.view.Display; |
14 |
|
|
|
|
| 30,6% |
Uncovered Elements: 129 (186) |
Complexity: 54 |
Complexity Density: 0,36 |
|
15 |
|
public class Utilities { |
16 |
|
public static SaveApp saveApp; |
17 |
|
|
18 |
|
|
|
|
| 60% |
Uncovered Elements: 4 (10) |
Complexity: 3 |
Complexity Density: 0,5 |
|
19 |
253
|
public static int stringToInt(String string) {... |
20 |
253
|
Log.i("UT", "String = " + string + "."); |
21 |
253
|
if (string == null) |
22 |
0
|
return 0; |
23 |
253
|
else if (string.compareTo("") == 0) |
24 |
0
|
return 0; |
25 |
|
else |
26 |
253
|
return Integer.valueOf(string); |
27 |
|
} |
28 |
|
|
29 |
|
|
|
|
| 55,6% |
Uncovered Elements: 4 (9) |
Complexity: 3 |
Complexity Density: 0,6 |
|
30 |
74
|
public static double stringToDouble(String string) {... |
31 |
74
|
if (string == null) |
32 |
0
|
return 0; |
33 |
74
|
else if (string.compareTo("") == 0) |
34 |
0
|
return 0; |
35 |
|
else |
36 |
74
|
return Double.valueOf(string); |
37 |
|
} |
38 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 3 |
Complexity Density: 0,25 |
|
39 |
0
|
public ArrayList<Outlay> readOutlay(Cursor cursor) {... |
40 |
0
|
ArrayList<Outlay> outlayList = new ArrayList<Outlay>(); |
41 |
0
|
int i = 0; |
42 |
0
|
Log.i("UT", "Read Cursor"); |
43 |
0
|
if (cursor.moveToFirst()) |
44 |
0
|
do { |
45 |
0
|
Outlay outlay = new Outlay(); |
46 |
0
|
outlay.setId(cursor.getInt(cursor |
47 |
|
.getColumnIndexOrThrow(DBManager.KEY_ID))); |
48 |
0
|
outlay.setCharge(cursor.getInt(cursor |
49 |
|
.getColumnIndexOrThrow(DBManager.OUTLAY_COLUMN_CHARGE))); |
50 |
0
|
outlay.setDate(cursor.getString(cursor |
51 |
|
.getColumnIndexOrThrow(DBManager.OUTLAY_COLUMN_DATE))); |
52 |
0
|
outlayList.add(outlay); |
53 |
0
|
i++; |
54 |
0
|
} while (cursor.moveToNext()); |
55 |
0
|
return outlayList; |
56 |
|
} |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
61 |
17
|
public static String dateGetter() {... |
62 |
17
|
String pattern = "MM/dd/yyyy HH:mm"; |
63 |
17
|
SimpleDateFormat dateFormat = new SimpleDateFormat(pattern); |
64 |
17
|
Date date = new Date(); |
65 |
17
|
return dateFormat.format(date); |
66 |
|
} |
67 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0,25 |
|
68 |
0
|
public static Date datePutter(String _date) {... |
69 |
0
|
String pattern = "MM/dd/yyyy HH:mm"; |
70 |
0
|
SimpleDateFormat dateFormat = new SimpleDateFormat(pattern); |
71 |
0
|
Date date = new Date(); |
72 |
0
|
try { |
73 |
0
|
date = dateFormat.parse(_date); |
74 |
|
} catch (ParseException e) { |
75 |
0
|
Log.i("UT", "Date Format Error"); |
76 |
0
|
e.printStackTrace(); |
77 |
|
} |
78 |
|
|
79 |
0
|
return date; |
80 |
|
|
81 |
|
} |
82 |
|
|
83 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0,75 |
|
84 |
0
|
public static int getLayout(Display display, int orientationPortrait,... |
85 |
|
int orientationLandScape) { |
86 |
0
|
int orientation = display.getOrientation(); |
87 |
0
|
if (orientation == 1 || orientation == 3) |
88 |
0
|
return orientationLandScape; |
89 |
|
else |
90 |
0
|
return orientationPortrait; |
91 |
|
} |
92 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 6 |
Complexity Density: 0,32 |
|
93 |
0
|
public static int getDateUnit(Date date, char unit) {... |
94 |
0
|
String pattern = null; |
95 |
0
|
switch (unit) { |
96 |
0
|
case 'y': |
97 |
0
|
pattern = "yyyy"; |
98 |
0
|
break; |
99 |
0
|
case 'M': |
100 |
0
|
pattern = "MM"; |
101 |
0
|
break; |
102 |
0
|
case 'd': |
103 |
0
|
pattern = "dd"; |
104 |
0
|
break; |
105 |
0
|
case 'H': |
106 |
0
|
pattern = "HH"; |
107 |
0
|
break; |
108 |
0
|
case 'm': |
109 |
0
|
pattern = "mm"; |
110 |
0
|
break; |
111 |
|
} |
112 |
0
|
SimpleDateFormat simpleDateformat = new SimpleDateFormat(pattern); |
113 |
0
|
return Integer.valueOf(simpleDateformat.format(date)); |
114 |
|
} |
115 |
|
|
|
|
| 66,7% |
Uncovered Elements: 6 (18) |
Complexity: 6 |
Complexity Density: 0,33 |
|
116 |
54
|
public static String getDateUnit(String date, char unit) {... |
117 |
54
|
String result = null; |
118 |
54
|
switch (unit) { |
119 |
18
|
case 'y': |
120 |
18
|
result = date.substring(6, 10); |
121 |
18
|
break; |
122 |
18
|
case 'M': |
123 |
18
|
result = date.substring(0, 2); |
124 |
18
|
break; |
125 |
18
|
case 'd': |
126 |
18
|
result = date.substring(3, 5); |
127 |
18
|
break; |
128 |
0
|
case 'H': |
129 |
0
|
result = date.substring(11, 13); |
130 |
0
|
break; |
131 |
0
|
case 'm': |
132 |
0
|
result = date.substring(13, 15); |
133 |
0
|
break; |
134 |
|
} |
135 |
54
|
return result; |
136 |
|
} |
137 |
|
|
|
|
| 53,8% |
Uncovered Elements: 6 (13) |
Complexity: 5 |
Complexity Density: 0,71 |
|
138 |
66
|
public static String printDate(String date) {... |
139 |
66
|
if (date.substring(0, 1).equals("N") || date.substring(0, 1).equals("")) |
140 |
0
|
return date; |
141 |
66
|
else if (date.length() == 0) |
142 |
0
|
return date; |
143 |
66
|
else if (saveApp.isEuropean()) { |
144 |
0
|
return date.substring(3, 5) + "/" + date.substring(0, 2) |
145 |
|
+ date.substring(6, 10) + "/ " + date.substring(11, 13) |
146 |
|
+ ":" + date.substring(13, 15); |
147 |
|
} else |
148 |
66
|
return date; |
149 |
|
} |
150 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
|
151 |
8
|
public static String formatDate(int _year, int _month, int _day, int _hour,... |
152 |
|
int _minute) { |
153 |
8
|
String year = String.valueOf(_year); |
154 |
8
|
String month = String.format("%02d", _month + 1); |
155 |
8
|
String day = String.format("%02d", _day); |
156 |
8
|
String hour = String.format("%02d", _hour); |
157 |
8
|
String minute = String.format("%02d", _minute); |
158 |
|
|
159 |
8
|
return month + "/" + day + "/" + year + " " + hour + ":" + minute; |
160 |
|
} |
161 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
162 |
13
|
public static int calculateCurrentBudget() {... |
163 |
13
|
Outlay outlay = new Outlay(); |
164 |
13
|
return saveApp.getBudget() + outlay.sum(saveApp.getAccountId()); |
165 |
|
} |
166 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0,14 |
|
167 |
13
|
public static int daysUntilToday(String date) {... |
168 |
13
|
Calendar todayCal = Calendar.getInstance(); |
169 |
13
|
Calendar dateCal = Calendar.getInstance(); |
170 |
13
|
dateCal.set(Integer.valueOf(getDateUnit(date, 'y')), |
171 |
|
Integer.valueOf(Utilities.getDateUnit(date, 'M')) - 1, |
172 |
|
Integer.valueOf(Utilities.getDateUnit(date, 'd'))); |
173 |
13
|
long milis1 = todayCal.getTimeInMillis(); |
174 |
13
|
long milis2 = dateCal.getTimeInMillis(); |
175 |
13
|
long diff = milis1 - milis2; |
176 |
13
|
return (int) (diff / (24 * 60 * 60 * 1000)); |
177 |
|
} |
178 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
179 |
0
|
public static double dateToMiliseconds(String date) {... |
180 |
0
|
Calendar dateCal = Calendar.getInstance(); |
181 |
0
|
dateCal.set(Integer.valueOf(getDateUnit(date, 'y')), |
182 |
|
Integer.valueOf(Utilities.getDateUnit(date, 'M')) - 1, |
183 |
|
Integer.valueOf(Utilities.getDateUnit(date, 'd'))); |
184 |
0
|
return dateCal.getTimeInMillis(); |
185 |
|
} |
186 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
|
187 |
0
|
public static void showAccounts(AlertDialog.Builder builder) {... |
188 |
0
|
final CharSequence[] accounts; |
189 |
0
|
Account account = new Account(); |
190 |
0
|
accounts = account.selectAccounts(); |
191 |
0
|
builder.setTitle("Chooese Account"); |
192 |
0
|
builder.setItems(accounts, new DialogInterface.OnClickListener() { |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
193 |
0
|
public void onClick(DialogInterface dialog, int _item) {... |
194 |
0
|
saveApp.setAccountId(_item + 1); |
195 |
|
|
196 |
|
} |
197 |
|
}); |
198 |
|
} |
199 |
|
|
|
|
| 0% |
Uncovered Elements: 43 (43) |
Complexity: 16 |
Complexity Density: 0,39 |
|
200 |
0
|
public static int numberOfDaysPerMonth(int month, int year) {... |
201 |
0
|
int returnValue = 30; |
202 |
0
|
switch (month) { |
203 |
0
|
case 1: |
204 |
0
|
returnValue = 31; |
205 |
0
|
break; |
206 |
0
|
case 2: |
207 |
0
|
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) |
208 |
0
|
returnValue = 29; |
209 |
|
else |
210 |
0
|
returnValue = 28; |
211 |
0
|
break; |
212 |
0
|
case 3: |
213 |
0
|
returnValue = 30; |
214 |
0
|
break; |
215 |
0
|
case 4: |
216 |
0
|
returnValue = 31; |
217 |
0
|
break; |
218 |
0
|
case 5: |
219 |
0
|
returnValue = 30; |
220 |
0
|
break; |
221 |
0
|
case 6: |
222 |
0
|
returnValue = 31; |
223 |
0
|
break; |
224 |
0
|
case 7: |
225 |
0
|
returnValue = 30; |
226 |
0
|
break; |
227 |
0
|
case 8: |
228 |
0
|
returnValue = 31; |
229 |
0
|
break; |
230 |
0
|
case 9: |
231 |
0
|
returnValue = 30; |
232 |
0
|
break; |
233 |
0
|
case 10: |
234 |
0
|
returnValue = 31; |
235 |
0
|
break; |
236 |
0
|
case 11: |
237 |
0
|
returnValue = 30; |
238 |
0
|
break; |
239 |
0
|
case 12: |
240 |
0
|
returnValue = 31; |
241 |
0
|
break; |
242 |
|
|
243 |
|
} |
244 |
0
|
return returnValue; |
245 |
|
|
246 |
|
} |
247 |
|
} |