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 TmaReplyDelay implements EnumPrefValue { 55 NONE("None", "none", 0), 56 SHORT("Short", "short", 50), 57 SHORT_PLUS("Short+", "short+", 150), 58 MEDIUM("Medium", "medium", 500), 59 MEDIUM_PLUS("Medium+", "medium+", 2000), 60 LONG("Long", "long", 5000), 61 EXTRA_LONG("Extra-Long", "extra-long", 10000); 62 63 private final PrefValueImpl mPrefValue; 64 public final int mReplyDelayMs; 65 TmaReplyDelay(String displayTitle, String id, int delayMs)66 TmaReplyDelay(String displayTitle, String id, int delayMs) { 67 mPrefValue = new PrefValueImpl(displayTitle + "(" + delayMs + ")", id); 68 mReplyDelayMs = delayMs; 69 } 70 71 @Override getTitle()72 public String getTitle() { 73 return mPrefValue.getTitle(); 74 } 75 76 @Override getId()77 public String getId() { 78 return mPrefValue.getId(); 79 } 80 } 81 82 83 public enum TmaBrowseNodeType implements EnumPrefValue { 84 NULL("Null (error)", "null"), 85 EMPTY("Empty", "empty"), 86 QUEUE_ONLY("Queue only", "queue-only"), 87 SINGLE_TAB("Single browse-able tab", "single-tab"), 88 NODE_CHILDREN("Only browse-able content", "nodes"), 89 LEAF_CHILDREN("Only playable content (basic working and error cases)", "leaves"), 90 MIXED_CHILDREN("Mixed content (apps are not supposed to do that)", "mixed"), 91 UNTAGGED("Untagged media items (not playable or browsable)", "untagged"); 92 93 private final PrefValueImpl mPrefValue; 94 TmaBrowseNodeType(String displayTitle, String id)95 TmaBrowseNodeType(String displayTitle, String id) { 96 mPrefValue = new PrefValueImpl(displayTitle, id); 97 } 98 99 @Override getTitle()100 public String getTitle() { 101 return mPrefValue.getTitle(); 102 } 103 104 @Override getId()105 public String getId() { 106 return mPrefValue.getId(); 107 } 108 } 109 110 /* To simulate the events order after login. Media apps should update playback state first, then 111 * load the browse tree. But sometims some apps (e.g., GPB) don't follow this order strictly. */ 112 public enum TmaLoginEventOrder implements EnumPrefValue { 113 PLAYBACK_STATE_UPDATE_FIRST("Update playback state first", "state-first"), 114 BROWSE_TREE_LOAD_FRIST("Load browse tree first", "tree-first"); 115 116 private final PrefValueImpl mPrefValue; 117 TmaLoginEventOrder(String displayTitle, String id)118 TmaLoginEventOrder(String displayTitle, String id) { 119 mPrefValue = new PrefValueImpl(displayTitle, id); 120 } 121 122 @Override getTitle()123 public String getTitle() { 124 return mPrefValue.getTitle(); 125 } 126 127 @Override getId()128 public String getId() { 129 return mPrefValue.getId(); 130 } 131 } 132 133 private static class PrefValueImpl implements EnumPrefValue { 134 135 private final String mDisplayTitle; 136 private final String mId; 137 138 /** If the app had to be localized, a resource id should be used for the title. */ PrefValueImpl(String displayTitle, String id)139 PrefValueImpl(String displayTitle, String id) { 140 mDisplayTitle = displayTitle; 141 mId = id; 142 } 143 144 @Override getTitle()145 public String getTitle() { 146 return mDisplayTitle; 147 } 148 149 @Override getId()150 public String getId() { 151 return mId; 152 } 153 } 154 } 155