• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php
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.ide.eclipse.adt.internal.resources.manager;
18 
19 import com.android.ide.eclipse.adt.internal.resources.configurations.FolderConfiguration;
20 import com.android.sdklib.SdkConstants;
21 
22 /**
23  * Enum representing a type of resource folder.
24  */
25 public enum ResourceFolderType {
26     ANIM(SdkConstants.FD_ANIM),
27     COLOR(SdkConstants.FD_COLOR),
28     DRAWABLE(SdkConstants.FD_DRAWABLE),
29     LAYOUT(SdkConstants.FD_LAYOUT),
30     MENU(SdkConstants.FD_MENU),
31     RAW(SdkConstants.FD_RAW),
32     VALUES(SdkConstants.FD_VALUES),
33     XML(SdkConstants.FD_XML);
34 
35     private final String mName;
36 
ResourceFolderType(String name)37     ResourceFolderType(String name) {
38         mName = name;
39     }
40 
getName()41     public String getName() {
42         return mName;
43     }
44 
45     /**
46      * Returns the enum by name.
47      * @param name The enum string value.
48      * @return the enum or null if not found.
49      */
getTypeByName(String name)50     public static ResourceFolderType getTypeByName(String name) {
51         for (ResourceFolderType rType : values()) {
52             if (rType.mName.equals(name)) {
53                 return rType;
54             }
55         }
56         return null;
57     }
58 
59     /**
60      * Returns the {@link ResourceFolderType} from the folder name
61      * @param folderName The name of the folder. This must be a valid folder name in the format
62      * <code>resType[-resqualifiers[-resqualifiers[...]]</code>
63      * @return the <code>ResourceFolderType</code> representing the type of the folder, or
64      * <code>null</code> if no matching type was found.
65      */
getFolderType(String folderName)66     public static ResourceFolderType getFolderType(String folderName) {
67         // split the name of the folder in segments.
68         String[] folderSegments = folderName.split(FolderConfiguration.QUALIFIER_SEP);
69 
70         // get the enum for the resource type.
71         return getTypeByName(folderSegments[0]);
72     }
73 }
74