blob: 941e260fbe1fd95ccc9d4ea7cc0dd886d3ed87da (
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
|
package org.robolectric.shadows;
import static android.os.Build.VERSION_CODES.KITKAT_WATCH;
import static android.os.Build.VERSION_CODES.LOLLIPOP;
import static android.os.Build.VERSION_CODES.N;
import android.icu.util.ULocale;
import java.util.Locale;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
@Implements(value = libcore.icu.ICU.class, isInAndroidSdk = false)
public class ShadowICU {
@Implementation
public static String addLikelySubtags(String languageTag) {
if (RuntimeEnvironment.getApiLevel() >= N) {
return ULocale.addLikelySubtags(ULocale.forLanguageTag(languageTag)).toLanguageTag();
} else {
// Return what is essentially the given locale, normalized by passing through the Locale
// factory method.
Locale locale = Locale.forLanguageTag(languageTag);
// To support testing with the ar-XB pseudo locale add "Arab" as the script for "ar" language,
// this is used by the Configuration to set the layout direction.
if (locale.getScript().isEmpty()
&& locale.getLanguage().equals(new Locale("ar").getLanguage())) {
locale = new Locale.Builder().setLanguageTag(languageTag).setScript("Arab").build();
}
return locale.toLanguageTag();
}
}
@Implementation(minSdk = LOLLIPOP)
public static String getBestDateTimePattern(String skeleton, Locale locale) {
switch (skeleton) {
case "jmm":
return getjmmPattern(locale);
case "yMMMd": // This is from {@code DatePickerDefaults.YearAbbrMonthDaySkeleton}
return "MMM d, y";
case "yMMMMEEEEd": // This is from {@code DatePickerDefaults.YearMonthWeekdayDaySkeleton}
return "EEEE, MMMM d, y";
case "yMMMM": // This is from {@code DatePickerDefaults.YearMonthSkeleton}
return "MMMM y";
default:
return skeleton;
}
}
@Implementation(maxSdk = KITKAT_WATCH)
public static String getBestDateTimePattern(String skeleton, String locale) {
return skeleton;
}
private static String getjmmPattern(Locale locale) {
if (locale.equals(new Locale("pt", "BR")) || locale.equals(Locale.UK)) {
return "H:mm";
}
return "h:mm a";
}
}
|