blob: 5001a05975c6601b48012eb71f80e85d2df74d5d (
plain)
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
|
package net.miz_hi.smileessence.util;
import android.net.Uri;
import com.twitter.Extractor;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
public class StringUtils
{
public static String parseUrlToFileName(String string)
{
return Uri.parse(string).getLastPathSegment();
}
public static String dateToString(Date date)
{
Calendar cal = Calendar.getInstance();
Calendar calToday = Calendar.getInstance();
cal.setTime(date);
int y = cal.get(Calendar.YEAR);
int m = cal.get(Calendar.MONTH);
int d = cal.get(Calendar.DATE);
int h = cal.get(Calendar.HOUR_OF_DAY);
int min = cal.get(Calendar.MINUTE);
int s = cal.get(Calendar.SECOND);
StringBuilder builder = new StringBuilder();
if (cal.get(Calendar.YEAR) != calToday.get(Calendar.YEAR))
{
builder.append(y).append("/");
}
if (cal.get(Calendar.DAY_OF_YEAR) != calToday.get(Calendar.DAY_OF_YEAR))
{
builder.append(String.format("%02d", m + 1)).append("/").append(String.format("%02d", d)).append(" ");
}
builder.append(String.format("%02d", h)).append(":").append(String.format("%02d", min)).append(":").append(String.format("%02d", s));
return builder.toString();
}
public static int countTweetCharacters(String text)
{
int count = text.length();
Extractor extractor = new Extractor();
List<String> urls = extractor.extractURLs(text);
for (String url : urls)
{
count -= (url.length() - 22);
if (url.startsWith("https://"))
{
count += 1;
}
}
return count;
}
}
|