2 * Copyright (C) 2009 The Android Open Source Project
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
8 * http://www.eclipse.org/org/documents/epl-v10.php
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.
17 package com.android.ide.eclipse.adt.internal.resources.configurations;
19 import com.android.ide.eclipse.adt.internal.editors.IconFactory;
20 import com.android.sdklib.AndroidVersion;
21 import com.android.sdklib.IAndroidTarget;
23 import org.eclipse.swt.graphics.Image;
25 public class ScreenRatioQualifier extends ResourceQualifier {
27 public static final String NAME = "Screen Ratio";
29 private ScreenRatio mValue = null;
32 * Screen Orientation enum.
34 public static enum ScreenRatio {
35 NOTLONG("notlong", "Not Long"), //$NON-NLS-1$
36 LONG("long", "Long"); //$NON-NLS-1$
38 private String mValue;
39 private String mDisplayValue;
41 private ScreenRatio(String value, String displayValue) {
43 mDisplayValue = displayValue;
47 * Returns the enum for matching the provided qualifier value.
48 * @param value The qualifier value.
49 * @return the enum for the qualifier value or null if no matching was found.
51 public static ScreenRatio getEnum(String value) {
52 for (ScreenRatio orient : values()) {
53 if (orient.mValue.equals(value)) {
61 public String getValue() {
65 public String getDisplayValue() {
69 public static int getIndex(ScreenRatio orientation) {
71 for (ScreenRatio orient : values()) {
72 if (orient == orientation) {
82 public static ScreenRatio getByIndex(int index) {
84 for (ScreenRatio orient : values()) {
95 public ScreenRatioQualifier() {
98 public ScreenRatioQualifier(ScreenRatio value) {
102 public ScreenRatio getValue() {
107 public String getName() {
112 public String getShortName() {
117 public Image getIcon() {
118 return IconFactory.getInstance().getIcon("ratio"); //$NON-NLS-1$
122 public boolean isValid() {
123 return mValue != null;
127 public boolean checkAndSet(String value, FolderConfiguration config) {
128 ScreenRatio size = ScreenRatio.getEnum(value);
130 ScreenRatioQualifier qualifier = new ScreenRatioQualifier(size);
131 config.setScreenRatioQualifier(qualifier);
139 public boolean equals(Object qualifier) {
140 if (qualifier instanceof ScreenRatioQualifier) {
141 return mValue == ((ScreenRatioQualifier)qualifier).mValue;
148 public int hashCode() {
149 if (mValue != null) {
150 return mValue.hashCode();
157 * Returns the string used to represent this qualifier in the folder name.
160 public String getFolderSegment(IAndroidTarget target) {
161 if (mValue != null) {
162 if (target == null) {
163 // Default behavior (when target==null) is qualifier is supported
164 return mValue.getValue();
167 AndroidVersion version = target.getVersion();
168 if (version.getApiLevel() >= 4 ||
169 (version.getApiLevel() == 3 && "Donut".equals(version.getCodename()))) {
170 return mValue.getValue();
174 return ""; //$NON-NLS-1$
178 public String getStringValue() {
179 if (mValue != null) {
180 return mValue.getDisplayValue();
183 return ""; //$NON-NLS-1$