Home | History | Annotate | Download | only in resources
      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 /**
     20  * UI Mode enum.
     21  * <p/>This is used in the resource folder names.
     22  */
     23 public enum UiMode implements ResourceEnum {
     24     NORMAL("", "Normal"),
     25     CAR("car", "Car Dock"),
     26     DESK("desk", "Desk Dock"),
     27     TELEVISION("television", "Television");
     28 
     29     private final String mValue;
     30     private final String mDisplayValue;
     31 
     32     private UiMode(String value, String display) {
     33         mValue = value;
     34         mDisplayValue = display;
     35     }
     36 
     37     /**
     38      * Returns the enum for matching the provided qualifier value.
     39      * @param value The qualifier value.
     40      * @return the enum for the qualifier value or null if no matching was found.
     41      */
     42     public static UiMode getEnum(String value) {
     43         for (UiMode mode : values()) {
     44             if (mode.mValue.equals(value)) {
     45                 return mode;
     46             }
     47         }
     48 
     49         return null;
     50     }
     51 
     52     public String getResourceValue() {
     53         return mValue;
     54     }
     55 
     56     public String getShortDisplayValue() {
     57         return mDisplayValue;
     58     }
     59 
     60     public String getLongDisplayValue() {
     61         return mDisplayValue;
     62     }
     63 
     64     public static int getIndex(UiMode value) {
     65         int i = 0;
     66         for (UiMode mode : values()) {
     67             if (mode == value) {
     68                 return i;
     69             }
     70 
     71             i++;
     72         }
     73 
     74         return -1;
     75     }
     76 
     77     public static UiMode getByIndex(int index) {
     78         int i = 0;
     79         for (UiMode value : values()) {
     80             if (i == index) {
     81                 return value;
     82             }
     83             i++;
     84         }
     85         return null;
     86     }
     87 
     88     public boolean isFakeValue() {
     89         return this == NORMAL; // NORMAL is not a real enum. it's used for internal state only.
     90     }
     91 
     92     public boolean isValidValueForDevice() {
     93         return this != NORMAL;
     94     }
     95 }
     96