• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 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.media.testmediaapp.prefs;
18 
19 /** Various enums saved in the prefs. */
20 public class TmaEnumPrefs {
21 
22     /** Interface for all enums that can be saved in the preferences. */
23     public interface EnumPrefValue {
24         /** Title for UI display. */
getTitle()25         String getTitle();
26 
27         /** Stable id for persisting the value. */
getId()28         String getId();
29     }
30 
31     public enum TmaAccountType implements EnumPrefValue {
32         NONE("None", "none"),
33         FREE("Free", "free"),
34         PAID("Paid", "paid");
35 
36         private final PrefValueImpl mPrefValue;
37 
TmaAccountType(String displayTitle, String id)38         TmaAccountType(String displayTitle, String id) {
39             mPrefValue = new PrefValueImpl(displayTitle, id);
40         }
41 
42         @Override
getTitle()43         public String getTitle() {
44             return mPrefValue.getTitle();
45         }
46 
47         @Override
getId()48         public String getId() {
49             return mPrefValue.getId();
50         }
51     }
52 
53     /** For simulating various reply speeds. */
54     public enum TmaNodeReplyDelay implements EnumPrefValue {
55         NONE("None", "none", 0),
56         SHORT("Short", "short", 50),
57         MEDIUM("Medium", "medium", 500),
58         LONG("Long", "long", 5000),
59         EXTRA_LONG("Extra-Long", "extra-long", 10000);
60 
61         private final PrefValueImpl mPrefValue;
62         public final int mReplyDelayMs;
63 
TmaNodeReplyDelay(String displayTitle, String id, int delayMs)64         TmaNodeReplyDelay(String displayTitle, String id, int delayMs) {
65             mPrefValue = new PrefValueImpl(displayTitle + "(" + delayMs + ")", id);
66             mReplyDelayMs = delayMs;
67         }
68 
69         @Override
getTitle()70         public String getTitle() {
71             return mPrefValue.getTitle();
72         }
73 
74         @Override
getId()75         public String getId() {
76             return mPrefValue.getId();
77         }
78     }
79 
80 
81     public enum TmaBrowseNodeType implements EnumPrefValue {
82         NULL("Null (error)", "null"),
83         EMPTY("Empty", "empty"),
84         NODE_CHILDREN("Only browse-able content", "nodes"),
85         LEAF_CHILDREN("Only playable content (basic working and error cases)", "leaves"),
86         MIXED_CHILDREN("Mixed content (apps are not supposed to do that)", "mixed");
87 
88         private final PrefValueImpl mPrefValue;
89 
TmaBrowseNodeType(String displayTitle, String id)90         TmaBrowseNodeType(String displayTitle, String id) {
91             mPrefValue = new PrefValueImpl(displayTitle, id);
92         }
93 
94         @Override
getTitle()95         public String getTitle() {
96             return mPrefValue.getTitle();
97         }
98 
99         @Override
getId()100         public String getId() {
101             return mPrefValue.getId();
102         }
103     }
104 
105     private static class PrefValueImpl implements EnumPrefValue {
106 
107         private final String mDisplayTitle;
108         private final String mId;
109 
110         /** If the app had to be localized, a resource id should be used for the title. */
PrefValueImpl(String displayTitle, String id)111         PrefValueImpl(String displayTitle, String id) {
112             mDisplayTitle = displayTitle;
113             mId = id;
114         }
115 
116         @Override
getTitle()117         public String getTitle() {
118             return mDisplayTitle;
119         }
120 
121         @Override
getId()122         public String getId() {
123             return mId;
124         }
125     }
126 }
127