-
Notifications
You must be signed in to change notification settings - Fork 15
/
BillTools.java
executable file
·100 lines (81 loc) · 3.08 KB
/
BillTools.java
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
/*
* Copyright (C) 2021 dreamn(dream@dreamn.cn)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package cn.dreamn.qianji_auto.bills;
import android.content.Context;
import cn.dreamn.qianji_auto.R;
public class BillTools {
public static String getMoney(String s) {
return getDoubleValue(s);
}
private static String getDoubleValue(String str) {
double d = 0;
if (str != null && str.length() != 0) {
str = str.replace(",", "").replace("¥", "");
StringBuilder bf = new StringBuilder();
char[] chars = str.toCharArray();
for (char c : chars) {
if (c >= '0' && c <= '9') {
bf.append(c);
} else if (c == '.') {
if (bf.indexOf(".") != -1) {
break;
} else {
bf.append(c);
}
} else {
if (bf.length() != 0) {
break;
}
}
}
try {
d = Double.parseDouble(bf.toString());
} catch (Exception ignored) {
}
}
return String.valueOf(d);
}
public static int getColor(Context context, BillInfo billInfo) {
if (billInfo.getType().equals(BillInfo.TYPE_INCOME)) {
return context.getColor(R.color.float_3);
} else if (billInfo.getType().equals(BillInfo.TYPE_PAY)) {
return context.getColor(R.color.float_4);
} else if (billInfo.getType().equals(BillInfo.TYPE_TRANSFER_ACCOUNTS)) {
return context.getColor(R.color.float_2);
} else {
return context.getColor(R.color.float_1);
}
}
public static String getCustomBill(BillInfo billInfo) {
if (billInfo.getType().equals(BillInfo.TYPE_INCOME)) {
return "+ ¥" + billInfo.getMoney();
} else if (billInfo.getType().equals(BillInfo.TYPE_PAY)) {
return "- ¥" + billInfo.getMoney();
} else if (billInfo.getType().equals(BillInfo.TYPE_TRANSFER_ACCOUNTS)) {
return "-> ¥" + billInfo.getMoney();
} else {
return "- ¥" + billInfo.getMoney();
}
}
public static boolean isMoney(String money) {
return money.matches("^-?([1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*|0?\\.0+|0)$") || money.matches("^(-?[1-9]\\d*)|0$");
}
public static boolean hasMoney(String input) {
return true;
// return input.matches(".*[0-9]+(?:,[0-9]{3})*(\\.[0-9]{2})?.*");
}
}