• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 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.AndroidConstants;
20 
21 /**
22  * Enum representing a type of resource folder.
23  */
24 public enum ResourceFolderType {
25     ANIM(AndroidConstants.FD_RES_ANIM),
26     ANIMATOR(AndroidConstants.FD_RES_ANIMATOR),
27     COLOR(AndroidConstants.FD_RES_COLOR),
28     DRAWABLE(AndroidConstants.FD_RES_DRAWABLE),
29     INTERPOLATOR(AndroidConstants.FD_RES_INTERPOLATOR),
30     LAYOUT(AndroidConstants.FD_RES_LAYOUT),
31     MENU(AndroidConstants.FD_RES_MENU),
32     MIPMAP(AndroidConstants.FD_RES_MIPMAP),
33     RAW(AndroidConstants.FD_RES_RAW),
34     VALUES(AndroidConstants.FD_RES_VALUES),
35     XML(AndroidConstants.FD_RES_XML);
36 
37     private final String mName;
38 
ResourceFolderType(String name)39     ResourceFolderType(String name) {
40         mName = name;
41     }
42 
43     /**
44      * Returns the folder name for this resource folder type.
45      */
getName()46     public String getName() {
47         return mName;
48     }
49 
50     /**
51      * Returns the enum by name.
52      * @param name The enum string value.
53      * @return the enum or null if not found.
54      */
getTypeByName(String name)55     public static ResourceFolderType getTypeByName(String name) {
56         for (ResourceFolderType rType : values()) {
57             if (rType.mName.equals(name)) {
58                 return rType;
59             }
60         }
61         return null;
62     }
63 
64     /**
65      * Returns the {@link ResourceFolderType} from the folder name
66      * @param folderName The name of the folder. This must be a valid folder name in the format
67      * <code>resType[-resqualifiers[-resqualifiers[...]]</code>
68      * @return the <code>ResourceFolderType</code> representing the type of the folder, or
69      * <code>null</code> if no matching type was found.
70      */
getFolderType(String folderName)71     public static ResourceFolderType getFolderType(String folderName) {
72         // split the name of the folder in segments.
73         String[] folderSegments = folderName.split(AndroidConstants.RES_QUALIFIER_SEP);
74 
75         // get the enum for the resource type.
76         return getTypeByName(folderSegments[0]);
77     }
78 }
79