FilmstripItemAttributes.java revision b6a8810b7a5ac0df1e19efd26628c01bcb32b97b
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
17package com.android.camera.data;
18
19import java.util.EnumSet;
20
21/**
22 * Represents an immutable set of item attributes
23 */
24public class FilmstripItemAttributes {
25    public enum Attributes {
26        HAS_DETAILED_CAPTURE_INFO,
27        CAN_SHARE,
28        CAN_EDIT,
29        CAN_DELETE,
30        CAN_PLAY,
31        CAN_OPEN_VIEWER,
32        CAN_SWIPE_AWAY,
33        CAN_ZOOM_IN_PLACE,
34        IS_RENDERING,
35        IS_IMAGE,
36        IS_VIDEO,
37        IS_STICKY,
38    }
39
40    private final EnumSet<Attributes> mAttributes;
41
42    public static final FilmstripItemAttributes DEFAULT =
43          new Builder().build();
44
45    private FilmstripItemAttributes(EnumSet<Attributes> attributes) {
46       mAttributes = attributes;
47    }
48
49    public boolean hasDetailedCaptureInfo() {
50        return mAttributes.contains(Attributes.HAS_DETAILED_CAPTURE_INFO);
51    }
52
53    // TODO: Replace this with a command.
54    public boolean canShare() {
55        return mAttributes.contains(Attributes.CAN_SHARE);
56    }
57
58    // TODO: Replace this with a command.
59    public boolean canEdit() {
60        return mAttributes.contains(Attributes.CAN_EDIT);
61    }
62
63    // TODO: Replace this with a command.
64    public boolean canDelete() {
65        return mAttributes.contains(Attributes.CAN_DELETE);
66    }
67
68    public boolean canSwipeAway() {
69        return mAttributes.contains(Attributes.CAN_SWIPE_AWAY);
70    }
71
72    public boolean canZoomInPlace() {
73        return mAttributes.contains(Attributes.CAN_ZOOM_IN_PLACE);
74    }
75
76    public boolean isRendering() {
77        return mAttributes.contains(Attributes.IS_RENDERING);
78    }
79
80    // TODO: Consider replacing video / image with an enum.
81    public boolean isImage() {
82        return mAttributes.contains(Attributes.IS_IMAGE);
83    }
84
85    public boolean isVideo() {
86        return mAttributes.contains(Attributes.IS_VIDEO);
87    }
88
89    public boolean isSticky() {
90        return mAttributes.contains(Attributes.IS_STICKY);
91    }
92
93    /**
94     * Builder for {@code FilmstripItemAttributes}.
95     */
96    public static class Builder {
97        EnumSet<Attributes> mAttributes = EnumSet.noneOf(Attributes.class);
98        public Builder with(Attributes attribute) {
99            mAttributes.add(attribute);
100            return this;
101        }
102
103        public FilmstripItemAttributes build() {
104            return new FilmstripItemAttributes(EnumSet.copyOf(mAttributes));
105        }
106    }
107}