Debian Codegraph @

layoutlib-api/src/main/java/com/android/resources/ScreenSize.java

raw
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 import com.android.annotations.Nullable;
20
21 /**
22 * Screen size enum.
23 * <p>This is used in the manifest in the uses-configuration node and in the resource folder names.
24 */
25 public enum ScreenSize implements ResourceEnum {
26 SMALL("small", "Small", "Small Screen"), //$NON-NLS-1$
27 NORMAL("normal", "Normal", "Normal Screen"), //$NON-NLS-1$
28 LARGE("large", "Large", "Large Screen"), //$NON-NLS-1$
29 XLARGE("xlarge", "X-Large", "Extra Large Screen"); //$NON-NLS-1$
30
31 private final String mValue;
32 private final String mShortDisplayValue;
33 private final String mLongDisplayValue;
34
35 ScreenSize(String value, String shortDisplayValue, String longDisplayValue) {
36 mValue = value;
37 mShortDisplayValue = shortDisplayValue;
38 mLongDisplayValue = longDisplayValue;
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 ScreenSize getEnum(String value) {
47 for (ScreenSize orient : values()) {
48 if (orient.mValue.equals(value)) {
49 return orient;
50 }
51 }
52
53 return null;
54 }
55
56 @Override
57 public String getResourceValue() {
58 return mValue;
59 }
60
61 @Override
62 public String getShortDisplayValue() {
63 return mShortDisplayValue;
64 }
65
66 @Override
67 public String getLongDisplayValue() {
68 return mLongDisplayValue;
69 }
70
71 public static int getIndex(@Nullable ScreenSize value) {
72 return value == null ? -1 : value.ordinal();
73 }
74
75 public static ScreenSize getByIndex(int index) {
76 ScreenSize[] values = values();
77 if (index >= 0 && index < values.length) {
78 return values[index];
79 }
80 return null;
81 }
82
83 @Override
84 public boolean isFakeValue() {
85 return false;
86 }
87
88 @Override
89 public boolean isValidValueForDevice() {
90 return true;
91 }
92
93 }