aboutsummaryrefslogtreecommitdiff
path: root/TestMediaApp/src/com/android/car/media/testmediaapp/prefs/TmaEnumPrefs.java
blob: 1ee7d73962c8ce6b9b24b42b3d228e3ffcb7e3fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.car.media.testmediaapp.prefs;

/** Various enums saved in the prefs. */
public class TmaEnumPrefs {

    /** Interface for all enums that can be saved in the preferences. */
    public interface EnumPrefValue {
        /** Title for UI display. */
        String getTitle();

        /** Stable id for persisting the value. */
        String getId();
    }

    public enum TmaAccountType implements EnumPrefValue {
        FREE("Free", "free"),
        PAID("Paid", "paid"),
        NONE("None", "none");

        private final PrefValueImpl mPrefValue;

        TmaAccountType(String displayTitle, String id) {
            mPrefValue = new PrefValueImpl(displayTitle, id);
        }

        @Override
        public String getTitle() {
            return mPrefValue.getTitle();
        }

        @Override
        public String getId() {
            return mPrefValue.getId();
        }
    }

    /** For simulating various reply speeds. */
    public enum TmaReplyDelay implements EnumPrefValue {
        NONE("None", "none", 0),
        SHORT("Short", "short", 50),
        SHORT_PLUS("Short+", "short+", 150),
        MEDIUM("Medium", "medium", 500),
        MEDIUM_PLUS("Medium+", "medium+", 2000),
        LONG("Long", "long", 5000),
        EXTRA_LONG("Extra-Long", "extra-long", 10000);

        private final PrefValueImpl mPrefValue;
        public final int mReplyDelayMs;

        TmaReplyDelay(String displayTitle, String id, int delayMs) {
            mPrefValue = new PrefValueImpl(displayTitle + "(" + delayMs + ")", id);
            mReplyDelayMs = delayMs;
        }

        @Override
        public String getTitle() {
            return mPrefValue.getTitle();
        }

        @Override
        public String getId() {
            return mPrefValue.getId();
        }
    }


    public enum TmaBrowseNodeType implements EnumPrefValue {
        NODE_CHILDREN("Only browse-able content", "nodes"),
        NULL("Null (error)", "null"),
        EMPTY("Empty", "empty"),
        QUEUE_ONLY("Queue only", "queue-only"),
        SINGLE_TAB("Single browse-able tab", "single-tab"),
        LEAF_CHILDREN("Only playable content (basic working and error cases)", "leaves"),
        MIXED_CHILDREN("Mixed content (apps are not supposed to do that)", "mixed"),
        UNTAGGED("Untagged media items (not playable or browsable)", "untagged");

        private final PrefValueImpl mPrefValue;

        TmaBrowseNodeType(String displayTitle, String id) {
            mPrefValue = new PrefValueImpl(displayTitle, id);
        }

        @Override
        public String getTitle() {
            return mPrefValue.getTitle();
        }

        @Override
        public String getId() {
            return mPrefValue.getId();
        }
    }

    /* To simulate the events order after login. Media apps should update playback state first, then
     * load the browse tree. But sometims some apps (e.g., GPB) don't follow this order strictly. */
    public enum TmaLoginEventOrder implements EnumPrefValue {
        PLAYBACK_STATE_UPDATE_FIRST("Update playback state first", "state-first"),
        BROWSE_TREE_LOAD_FRIST("Load browse tree first", "tree-first");

        private final PrefValueImpl mPrefValue;

        TmaLoginEventOrder(String displayTitle, String id) {
            mPrefValue = new PrefValueImpl(displayTitle, id);
        }

        @Override
        public String getTitle() {
            return mPrefValue.getTitle();
        }

        @Override
        public String getId() {
            return mPrefValue.getId();
        }
    }

    private static class PrefValueImpl implements EnumPrefValue {

        private final String mDisplayTitle;
        private final String mId;

        /** If the app had to be localized, a resource id should be used for the title. */
        PrefValueImpl(String displayTitle, String id) {
            mDisplayTitle = displayTitle;
            mId = id;
        }

        @Override
        public String getTitle() {
            return mDisplayTitle;
        }

        @Override
        public String getId() {
            return mId;
        }
    }
}