-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.java
More file actions
101 lines (78 loc) · 3.09 KB
/
util.java
File metadata and controls
101 lines (78 loc) · 3.09 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package br.com.hangar55.archery2go.helper;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* Created by calencastro on 24/07/2017.
*/
public final class util {
public util() {
}
public static String fromUnixtoFormatedString(long unixEpoch) {
String data = "";
data = new SimpleDateFormat("dd/MM/yyyy").format(new java.util.Date(unixEpoch));
return data;
}
public static long fromFormatedStringtoUnix(String date) {
return fromFormatedStringtoUnix(date, "00:00");
}
public static long fromFormatedStringtoUnix(String date, String time) {
long unixEpoch = 0;
String str = date + " " + time;
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm");
Date typeDate = null;
try {
typeDate = df.parse(str);
} catch (ParseException e) {
e.printStackTrace();
}
unixEpoch = typeDate.getTime();
return unixEpoch;
}
public static long currentEpoch() {
Long currentEpoch = System.currentTimeMillis();
return currentEpoch;
}
public static String getTodayDate() {
final Calendar c = Calendar.getInstance();
int month = c.get(Calendar.MONTH) + 1;
int day = c.get(Calendar.DAY_OF_MONTH);
String textMonth;
String textDay;
if (month < 10) {
textMonth = "0" + month;
} else {
textMonth = String.valueOf(month);
}
if (day < 10) {
textDay = "0" + day;
} else {
textDay = String.valueOf(day);
}
return textDay + "/" + textMonth + "/" + c.get(Calendar.YEAR);
}
public static void setCurrentTreino(Context context, int id) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("currentTreino", String.valueOf(id));
editor.commit();
}
public static int getCurrentTreino(Context context) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
return Integer.valueOf(sharedPreferences.getString("currentTreino", "-1"));
}
public static void setLastRound(Context context, int id) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("pref_last_round_id", String.valueOf(id));
editor.commit();
}
public static int getLastRound(Context context) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
return Integer.valueOf(sharedPreferences.getString("pref_last_round_id", "-1"));
}
}