| 1 |
/* |
| 2 |
* Copyright (C) 2010 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.resources; |
| 18 |
|
| 19 |
/** |
| 20 |
* UI Mode enum. |
| 21 |
* <p>This is used in the resource folder names. |
| 22 |
*/ |
| 23 |
public enum UiMode implements ResourceEnum { |
| 24 |
NORMAL("", "Normal", 1), |
| 25 |
CAR("car", "Car Dock", 8), |
| 26 |
DESK("desk", "Desk Dock", 8), |
| 27 |
TELEVISION("television", "Television", 13), |
| 28 |
APPLIANCE("appliance", "Appliance", 16), |
| 29 |
WATCH("watch", "Watch", 20); |
| 30 |
|
| 31 |
private final String mValue; |
| 32 |
private final String mDisplayValue; |
| 33 |
private final int mSince; |
| 34 |
|
| 35 |
UiMode(String value, String display, int since) { |
| 36 |
mValue = value; |
| 37 |
mDisplayValue = display; |
| 38 |
mSince = since; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Returns the enum for matching the provided qualifier value. |
| 43 |
* @param value The qualifier value. |
| 44 |
* @return the enum for the qualifier value or null if no matching was found. |
| 45 |
*/ |
| 46 |
public static UiMode getEnum(String value) { |
| 47 |
for (UiMode mode : values()) { |
| 48 |
if (mode.mValue.equals(value)) { |
| 49 |
return mode; |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
return null; |
| 54 |
} |
| 55 |
|
| 56 |
@Override |
| 57 |
public String getResourceValue() { |
| 58 |
return mValue; |
| 59 |
} |
| 60 |
|
| 61 |
public int since() { |
| 62 |
return mSince; |
| 63 |
} |
| 64 |
|
| 65 |
@Override |
| 66 |
public String getShortDisplayValue() { |
| 67 |
return mDisplayValue; |
| 68 |
} |
| 69 |
|
| 70 |
@Override |
| 71 |
public String getLongDisplayValue() { |
| 72 |
return mDisplayValue; |
| 73 |
} |
| 74 |
|
| 75 |
public static int getIndex(UiMode value) { |
| 76 |
return value == null ? -1 : value.ordinal(); |
| 77 |
} |
| 78 |
|
| 79 |
public static UiMode getByIndex(int index) { |
| 80 |
UiMode[] values = values(); |
| 81 |
if (index >= 0 && index < values.length) { |
| 82 |
return values[index]; |
| 83 |
} |
| 84 |
return null; |
| 85 |
} |
| 86 |
|
| 87 |
@Override |
| 88 |
public boolean isFakeValue() { |
| 89 |
return this == NORMAL; // NORMAL is not a real enum. it's used for internal state only. |
| 90 |
} |
| 91 |
|
| 92 |
@Override |
| 93 |
public boolean isValidValueForDevice() { |
| 94 |
return this != NORMAL; |
| 95 |
} |
| 96 |
} |