Repository navigation
Expand file tree
/
Copy pathUtil.java
More file actions
61 lines (51 loc) · 2.33 KB
/
Copy pathUtil.java
File metadata and controls
61 lines (51 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.pedrocarrillo.expensetracker.utils;
import android.preference.PreferenceManager;
import android.widget.EditText;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.pedrocarrillo.expensetracker.ExpenseTrackerApp;
import com.pedrocarrillo.expensetracker.R;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
/**
* Created by Pedro on 15/9/2015.
*/
public class Util {
public static String formatDateToString(Date date, String pattern) {
DateFormat formatter = new SimpleDateFormat(pattern);
return formatter.format(date);
}
public static boolean isEmptyField(EditText et) {
return (et.getText() == null || et.getText().toString().isEmpty());
}
public static List<Integer> getListColors() {
ArrayList<Integer> colors = new ArrayList<>();
for (int c : ColorTemplate.LIBERTY_COLORS)
colors.add(c);
for (int c : ColorTemplate.VORDIPLOM_COLORS)
colors.add(c);
for (int c : ColorTemplate.JOYFUL_COLORS)
colors.add(c);
for (int c : ColorTemplate.COLORFUL_COLORS)
colors.add(c);
for (int c : ColorTemplate.PASTEL_COLORS)
colors.add(c);
colors.add(ColorTemplate.getHoloBlue());
return colors;
}
public static String getFormattedCurrency(float number) {
String countryCode = PreferenceManager.getDefaultSharedPreferences(ExpenseTrackerApp.getContext()).getString(ExpenseTrackerApp.getContext().getString(R.string.pref_country_key), ExpenseTrackerApp.getContext().getString(R.string.default_country));
Locale locale = new Locale("EN", countryCode);
NumberFormat numberFormat = NumberFormat.getCurrencyInstance(locale);
String formattedNumber = numberFormat.format(number);
String symbol = numberFormat.getCurrency().getSymbol(locale);
return formattedNumber.replace(symbol, symbol+" ");
}
public static String getCurrentDateFormat() {
return PreferenceManager.getDefaultSharedPreferences(ExpenseTrackerApp.getContext()).getString(ExpenseTrackerApp.getContext().getString(R.string.date_format_key), ExpenseTrackerApp.getContext().getString(R.string.default_date_format));
}
}