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