Debian Codegraph @

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

raw
1 /*
2 * Copyright (C) 2012 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 * Layout Direction enum.
21 */
22 public enum LayoutDirection implements ResourceEnum {
23 LTR("ldltr", "LTR", "Left To Right"), //$NON-NLS-1$
24 RTL("ldrtl", "RTL", "Right To Left"); //$NON-NLS-1$
25
26 private final String mValue;
27 private final String mShortDisplayValue;
28 private final String mLongDisplayValue;
29
30 LayoutDirection(String value, String shortDisplayValue, String longDisplayValue) {
31 mValue = value;
32 mShortDisplayValue = shortDisplayValue;
33 mLongDisplayValue = longDisplayValue;
34 }
35
36 /**
37 * Returns the enum for matching the provided qualifier value.
38 * @param value The qualifier value.
39 * @return the enum for the qualifier value or null if no matching was found.
40 */
41 public static LayoutDirection getEnum(String value) {
42 for (LayoutDirection orient : values()) {
43 if (orient.mValue.equals(value)) {
44 return orient;
45 }
46 }
47
48 return null;
49 }
50
51 @Override
52 public String getResourceValue() {
53 return mValue;
54 }
55
56 @Override
57 public String getShortDisplayValue() {
58 return mShortDisplayValue;
59 }
60
61 @Override
62 public String getLongDisplayValue() {
63 return mLongDisplayValue;
64 }
65
66 public static int getIndex(LayoutDirection orientation) {
67 return orientation == null ? -1 : orientation.ordinal();
68 }
69
70 public static LayoutDirection getByIndex(int index) {
71 LayoutDirection[] values = values();
72 if (index >= 0 && index < values.length) {
73 return values[index];
74 }
75 return null;
76 }
77
78 @Override
79 public boolean isFakeValue() {
80 return false;
81 }
82
83 @Override
84 public boolean isValidValueForDevice() {
85 return true;
86 }
87 }