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.sdklib.resources; 18 19 20 /** 21 * Density enum. 22 * <p/>This is used in the manifest in the uses-configuration node and in the resource folder names 23 * as well as other places needing to know the density values. 24 */ 25 public enum Density implements ResourceEnum { 26 HIGH("hdpi", "High Density", 240), //$NON-NLS-1$ 27 MEDIUM("mdpi", "Medium Density", 160), //$NON-NLS-1$ 28 LOW("ldpi", "Low Density", 120), //$NON-NLS-1$ 29 NODPI("nodpi", "No Density", 0); //$NON-NLS-1$ 30 31 public final static int DEFAULT_DENSITY = 160; 32 33 private final String mValue; 34 private final String mDisplayValue; 35 private final int mDensity; 36 Density(String value, String displayValue, int density)37 private Density(String value, String displayValue, int density) { 38 mValue = value; 39 mDisplayValue = displayValue; 40 mDensity = density; 41 } 42 43 /** 44 * Returns the enum matching the provided qualifier value. 45 * @param value The qualifier value. 46 * @return the enum for the qualifier value or null if no match was found. 47 */ getEnum(String value)48 public static Density getEnum(String value) { 49 for (Density orient : values()) { 50 if (orient.mValue.equals(value)) { 51 return orient; 52 } 53 } 54 55 return null; 56 } 57 58 /** 59 * Returns the enum matching the given density value 60 * @param value The density value. 61 * @return the enum for the density value or null if no match was found. 62 */ getEnum(int value)63 public static Density getEnum(int value) { 64 for (Density d : values()) { 65 if (d.mDensity == value) { 66 return d; 67 } 68 } 69 70 return null; 71 } 72 getResourceValue()73 public String getResourceValue() { 74 return mValue; 75 } 76 getDpiValue()77 public int getDpiValue() { 78 return mDensity; 79 } 80 getLegacyValue()81 public String getLegacyValue() { 82 if (this != NODPI) { 83 return String.format("%1$ddpi", getDpiValue()); 84 } 85 86 return ""; 87 } 88 getShortDisplayValue()89 public String getShortDisplayValue() { 90 return mDisplayValue; 91 } 92 getLongDisplayValue()93 public String getLongDisplayValue() { 94 return mDisplayValue; 95 } 96 getIndex(Density value)97 public static int getIndex(Density value) { 98 int i = 0; 99 for (Density input : values()) { 100 if (value == input) { 101 return i; 102 } 103 104 i++; 105 } 106 107 return -1; 108 } 109 getByIndex(int index)110 public static Density getByIndex(int index) { 111 int i = 0; 112 for (Density value : values()) { 113 if (i == index) { 114 return value; 115 } 116 i++; 117 } 118 return null; 119 } 120 isFakeValue()121 public boolean isFakeValue() { 122 return false; 123 } 124 isValidValueForDevice()125 public boolean isValidValueForDevice() { 126 return this != NODPI; // nodpi is not a valid config for devices. 127 } 128 } 129