1 /*
2  * Copyright (C) 2019 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 com.android.car.settings.units;
18 
19 import android.car.VehicleUnit;
20 
21 import com.android.car.settings.R;
22 
23 import java.util.HashMap;
24 
25 /**
26  * Contains {@link Unit} instances for all units defined in {@link VehicleUnit}. This mapping is
27  * safe because OEMs cannot define their own VehicleUnit.
28  */
29 public final class UnitsMap {
30     protected static final Unit METER_PER_SEC = new Unit(VehicleUnit.METER_PER_SEC,
31             R.string.units_unit_abbreviation_meter_per_sec, R.string.units_unit_name_meter_per_sec);
32     protected static final Unit RPM = new Unit(VehicleUnit.RPM,
33             R.string.units_unit_abbreviation_rpm, R.string.units_unit_name_rpm);
34     protected static final Unit HERTZ = new Unit(VehicleUnit.HERTZ,
35             R.string.units_unit_abbreviation_hertz, R.string.units_unit_name_hertz);
36     protected static final Unit PERCENTILE = new Unit(VehicleUnit.PERCENTILE,
37             R.string.units_unit_abbreviation_percentile, R.string.units_unit_name_percentile);
38     protected static final Unit MILLIMETER = new Unit(VehicleUnit.MILLIMETER,
39             R.string.units_unit_abbreviation_millimeter, R.string.units_unit_name_millimeter);
40     protected static final Unit METER = new Unit(VehicleUnit.METER,
41             R.string.units_unit_abbreviation_meter, R.string.units_unit_name_meter);
42     protected static final Unit KILOMETER = new Unit(VehicleUnit.KILOMETER,
43             R.string.units_unit_abbreviation_kilometer, R.string.units_unit_name_kilometer);
44     protected static final Unit MILE = new Unit(VehicleUnit.MILE,
45             R.string.units_unit_abbreviation_mile, R.string.units_unit_name_mile);
46     protected static final Unit CELSIUS = new Unit(VehicleUnit.CELSIUS,
47             R.string.units_unit_abbreviation_celsius, R.string.units_unit_name_celsius);
48     protected static final Unit FAHRENHEIT = new Unit(VehicleUnit.FAHRENHEIT,
49             R.string.units_unit_abbreviation_fahrenheit, R.string.units_unit_name_fahrenheit);
50     protected static final Unit KELVIN = new Unit(VehicleUnit.KELVIN,
51             R.string.units_unit_abbreviation_kelvin, R.string.units_unit_name_kelvin);
52     protected static final Unit MILLILITER = new Unit(VehicleUnit.MILLILITER,
53             R.string.units_unit_abbreviation_milliliter, R.string.units_unit_name_milliliter);
54     protected static final Unit LITER = new Unit(VehicleUnit.LITER,
55             R.string.units_unit_abbreviation_liter, R.string.units_unit_name_liter);
56     protected static final Unit US_GALLON = new Unit(VehicleUnit.US_GALLON,
57             R.string.units_unit_abbreviation_us_gallon, R.string.units_unit_name_us_gallon);
58     protected static final Unit IMPERIAL_GALLON = new Unit(VehicleUnit.IMPERIAL_GALLON,
59             R.string.units_unit_abbreviation_imperial_gallon,
60             R.string.units_unit_name_imperial_gallon);
61     protected static final Unit NANO_SECS = new Unit(VehicleUnit.NANO_SECS,
62             R.string.units_unit_abbreviation_nano_secs, R.string.units_unit_name_nano_secs);
63     protected static final Unit SECS = new Unit(VehicleUnit.SECS,
64             R.string.units_unit_abbreviation_secs, R.string.units_unit_name_secs);
65     protected static final Unit YEAR = new Unit(VehicleUnit.YEAR,
66             R.string.units_unit_abbreviation_year, R.string.units_unit_name_year);
67     protected static final Unit KILOPASCAL = new Unit(VehicleUnit.KILOPASCAL,
68             R.string.units_unit_abbreviation_kilopascal, R.string.units_unit_name_kilopascal);
69     protected static final Unit WATT_HOUR = new Unit(VehicleUnit.WATT_HOUR,
70             R.string.units_unit_abbreviation_watt_hour, R.string.units_unit_name_watt_hour);
71     protected static final Unit MILLIAMPERE = new Unit(VehicleUnit.MILLIAMPERE,
72             R.string.units_unit_abbreviation_milliampere, R.string.units_unit_name_milliampere);
73     protected static final Unit MILLIVOLT = new Unit(VehicleUnit.MILLIVOLT,
74             R.string.units_unit_abbreviation_millivolt, R.string.units_unit_name_millivolt);
75     protected static final Unit MILLIWATTS = new Unit(VehicleUnit.MILLIWATTS,
76             R.string.units_unit_abbreviation_milliwatts, R.string.units_unit_name_milliwatts);
77     protected static final Unit AMPERE_HOURS = new Unit(VehicleUnit.AMPERE_HOURS,
78             R.string.units_unit_abbreviation_ampere_hour, R.string.units_unit_name_ampere_hour);
79     protected static final Unit KILOWATT_HOUR = new Unit(VehicleUnit.KILOWATT_HOUR,
80             R.string.units_unit_abbreviation_kilowatt_hour, R.string.units_unit_name_kilowatt_hour);
81     protected static final Unit PSI = new Unit(VehicleUnit.PSI,
82             R.string.units_unit_abbreviation_psi, R.string.units_unit_name_psi);
83     protected static final Unit BAR = new Unit(VehicleUnit.BAR,
84             R.string.units_unit_abbreviation_bar, R.string.units_unit_name_bar);
85     protected static final Unit DEGREES = new Unit(VehicleUnit.DEGREES,
86             R.string.units_unit_abbreviation_degrees, R.string.units_unit_name_degrees);
87     protected static final Unit MILES_PER_HOUR = new Unit(VehicleUnit.MILES_PER_HOUR,
88             R.string.units_unit_abbreviation_miles_per_hour,
89             R.string.units_unit_name_miles_per_hour);
90     protected static final Unit KILOMETERS_PER_HOUR = new Unit(VehicleUnit.KILOMETERS_PER_HOUR,
91             R.string.units_unit_abbreviation_kilometers_per_hour,
92             R.string.units_unit_name_kilometers_per_hour);
93 
94     public static final HashMap<Integer, Unit> MAP = createMap();
95 
createMap()96     private static HashMap<Integer, Unit> createMap() {
97         HashMap<Integer, Unit> map = new HashMap();
98         map.put(VehicleUnit.METER_PER_SEC, METER_PER_SEC);
99         map.put(VehicleUnit.RPM, RPM);
100         map.put(VehicleUnit.HERTZ, HERTZ);
101         map.put(VehicleUnit.PERCENTILE, PERCENTILE);
102         map.put(VehicleUnit.MILLIMETER, MILLIMETER);
103         map.put(VehicleUnit.METER, METER);
104         map.put(VehicleUnit.KILOMETER, KILOMETER);
105         map.put(VehicleUnit.MILE, MILE);
106         map.put(VehicleUnit.CELSIUS, CELSIUS);
107         map.put(VehicleUnit.FAHRENHEIT, FAHRENHEIT);
108         map.put(VehicleUnit.KELVIN, KELVIN);
109         map.put(VehicleUnit.MILLILITER, MILLILITER);
110         map.put(VehicleUnit.LITER, LITER);
111         map.put(VehicleUnit.US_GALLON, US_GALLON);
112         map.put(VehicleUnit.IMPERIAL_GALLON, IMPERIAL_GALLON);
113         map.put(VehicleUnit.NANO_SECS, NANO_SECS);
114         map.put(VehicleUnit.SECS, SECS);
115         map.put(VehicleUnit.YEAR, YEAR);
116         map.put(VehicleUnit.KILOPASCAL, KILOPASCAL);
117         map.put(VehicleUnit.WATT_HOUR, WATT_HOUR);
118         map.put(VehicleUnit.MILLIAMPERE, MILLIAMPERE);
119         map.put(VehicleUnit.MILLIVOLT, MILLIVOLT);
120         map.put(VehicleUnit.MILLIWATTS, MILLIWATTS);
121         map.put(VehicleUnit.AMPERE_HOURS, AMPERE_HOURS);
122         map.put(VehicleUnit.KILOWATT_HOUR, KILOWATT_HOUR);
123         map.put(VehicleUnit.PSI, PSI);
124         map.put(VehicleUnit.BAR, BAR);
125         map.put(VehicleUnit.DEGREES, DEGREES);
126         map.put(VehicleUnit.MILES_PER_HOUR, MILES_PER_HOUR);
127         map.put(VehicleUnit.KILOMETERS_PER_HOUR, KILOMETERS_PER_HOUR);
128 
129         return map;
130     }
131 
UnitsMap()132     private UnitsMap() {
133     }
134 }
135