1/*
2 * Copyright (C) 2017 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
17package com.android.settings.testutils.shadow;
18
19import android.content.Context;
20
21import com.android.settingslib.datetime.ZoneGetter;
22
23import org.robolectric.annotation.Implementation;
24import org.robolectric.annotation.Implements;
25
26import java.util.ArrayList;
27import java.util.HashMap;
28import java.util.List;
29import java.util.Map;
30import java.util.TimeZone;
31
32@Implements(ZoneGetter.class)
33public class ShadowZoneGetter {
34
35    @Implementation
36    public static List<Map<String, Object>> getZonesList(Context context) {
37        List<Map<String, Object>> zones = new ArrayList<>();
38        zones.add(createDisplayEntry(TimeZone.getDefault(), "gmt-1:00", "FakePlace", 10000));
39        return zones;
40    }
41
42    private static Map<String, Object> createDisplayEntry(
43            TimeZone tz, CharSequence gmtOffsetText, CharSequence displayName, int offsetMillis) {
44        Map<String, Object> map = new HashMap<>();
45        map.put(ZoneGetter.KEY_ID, tz.getID());
46        map.put(ZoneGetter.KEY_DISPLAYNAME, displayName.toString());
47        map.put(ZoneGetter.KEY_DISPLAY_LABEL, displayName);
48        map.put(ZoneGetter.KEY_GMT, gmtOffsetText.toString());
49        map.put(ZoneGetter.KEY_OFFSET_LABEL, gmtOffsetText);
50        map.put(ZoneGetter.KEY_OFFSET, offsetMillis);
51        return map;
52    }
53}
54