Skip to content

Commit 9921d9b

Browse files
deepanshu-The Android Automerger
authored andcommitted
Layoutlib: Add DateIntervalFormat_Delegate required by CalendarView
Change-Id: Ica79267a4eb231db833cb0232cfacf419fe73de3
1 parent c0ba613 commit 9921d9b

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (C) 2013 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package libcore.icu;
18+
19+
import java.text.FieldPosition;
20+
21+
import com.android.ide.common.rendering.api.LayoutLog;
22+
import com.android.layoutlib.bridge.Bridge;
23+
import com.android.layoutlib.bridge.impl.DelegateManager;
24+
import com.ibm.icu.text.DateIntervalFormat;
25+
import com.ibm.icu.util.DateInterval;
26+
import com.ibm.icu.util.TimeZone;
27+
import com.ibm.icu.util.ULocale;
28+
29+
public class DateIntervalFormat_Delegate {
30+
31+
// ---- delegate manager ----
32+
private static final DelegateManager<DateIntervalFormat_Delegate> sManager =
33+
new DelegateManager<DateIntervalFormat_Delegate>(DateIntervalFormat_Delegate.class);
34+
35+
// ---- delegate data ----
36+
private DateIntervalFormat mFormat;
37+
38+
39+
// ---- native methods ----
40+
41+
/*package*/static String formatDateInterval(long address, long fromDate, long toDate) {
42+
DateIntervalFormat_Delegate delegate = sManager.getDelegate((int)address);
43+
if (delegate == null) {
44+
Bridge.getLog().error(LayoutLog.TAG_BROKEN,
45+
"Unable for find native DateIntervalFormat", null);
46+
return null;
47+
}
48+
DateInterval interval = new DateInterval(fromDate, toDate);
49+
StringBuffer sb = new StringBuffer();
50+
FieldPosition pos = new FieldPosition(0);
51+
delegate.mFormat.format(interval, sb, pos);
52+
return sb.toString();
53+
}
54+
55+
/*package*/ static long createDateIntervalFormat(String skeleton, String localeName,
56+
String tzName) {
57+
TimeZone prevDefaultTz = TimeZone.getDefault();
58+
TimeZone.setDefault(TimeZone.getTimeZone(tzName));
59+
DateIntervalFormat_Delegate newDelegate = new DateIntervalFormat_Delegate();
60+
newDelegate.mFormat =
61+
DateIntervalFormat.getInstance(skeleton, new ULocale(localeName));
62+
TimeZone.setDefault(prevDefaultTz);
63+
return sManager.addNewDelegate(newDelegate);
64+
}
65+
66+
/*package*/ static void destroyDateIntervalFormat(long address) {
67+
sManager.removeJavaReferenceFor((int)address);
68+
}
69+
70+
}

tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ public String[] getJavaPkgClasses() {
187187
"android.text.AndroidBidi",
188188
"android.util.FloatMath",
189189
"android.view.Display",
190+
"libcore.icu.DateIntervalFormat",
190191
"libcore.icu.ICU",
191192
};
192193

0 commit comments

Comments
 (0)