1 package sk.baka.ambient;
2
3 import java.util.EnumMap;
4 import java.util.Map;
5
6 import sk.baka.ambient.commons.Interval;
7
8 /***
9 * Ambient - A music player for the Android platform
10 Copyright (C) 2007 Martin Vysny
11
12 This program is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26 /***
27 * Zoom categories. Generally, low integer values means smaller image.
28 *
29 * @author Martin Vysny
30 */
31 public enum ZoomEnum {
32 /***
33 * The menu/sub-menu buttons.
34 */
35 Buttons(new Interval(0, 2)),
36 /***
37 * Zoom of the list view items.
38 */
39 ListViewItems(new Interval(0, 3));
40 /***
41 * Allowed levels.
42 */
43 public final Interval levels;
44
45 private ZoomEnum(final Interval levels) {
46 this.levels = levels;
47 }
48
49 /***
50 * Returns a map of levels having minimal levels.
51 *
52 * @return map with all zoom constants.
53 */
54 public static EnumMap<ZoomEnum, Integer> getMinLevels() {
55 final EnumMap<ZoomEnum, Integer> result = new EnumMap<ZoomEnum, Integer>(
56 ZoomEnum.class);
57 for (final ZoomEnum z : values()) {
58 result.put(z, z.levels.start);
59 }
60 return result;
61 }
62
63 /***
64 * Returns zoom level for this category.
65 *
66 * @param map
67 * the category map to query.
68 * @return zoom level or minimum level if not yet specified.
69 */
70 public int getLevel(final Map<ZoomEnum, Integer> map) {
71 if (map == null) {
72 return levels.start;
73 }
74 final Integer result = map.get(this);
75 return result == null ? levels.start : result;
76 }
77
78 /***
79 * Returns zoom level for this category.
80 *
81 * @param map
82 * the category map to modify.
83 * @param level
84 * the level
85 */
86 public void setLevel(final Map<ZoomEnum, Integer> map,
87 final int level) {
88 if (!levels.contains(level)) {
89 throw new IllegalArgumentException("invalid level " + level);
90 }
91 map.put(this, level);
92 }
93 }