• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
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
7  *
8  *      http://www.eclipse.org/org/documents/epl-v10.php
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.ide.eclipse.adt.internal.resources.configurations;
18 
19 import com.android.ide.eclipse.adt.internal.editors.IconFactory;
20 import com.android.sdklib.IAndroidTarget;
21 
22 import org.eclipse.swt.graphics.Image;
23 
24 
25 
26 
27 /**
28  * Resource Qualifier for Text Input Method.
29  */
30 public final class TextInputMethodQualifier extends ResourceQualifier {
31 
32     public static final String NAME = "Text Input Method";
33 
34     private TextInputMethod mValue;
35 
36     /**
37      * Screen Orientation enum.
38      */
39     public static enum TextInputMethod {
40         NOKEY("nokeys", "No Keys"), //$NON-NLS-1$
41         QWERTY("qwerty", "Qwerty"), //$NON-NLS-1$
42         TWELVEKEYS("12key", "12 Key"); //$NON-NLS-1$
43 
44         private String mValue;
45         private String mDisplayValue;
46 
TextInputMethod(String value, String displayValue)47         private TextInputMethod(String value, String displayValue) {
48             mValue = value;
49             mDisplayValue = displayValue;
50         }
51 
52         /**
53          * Returns the enum for matching the provided qualifier value.
54          * @param value The qualifier value.
55          * @return the enum for the qualifier value or null if no matching was found.
56          */
getEnum(String value)57         public static TextInputMethod getEnum(String value) {
58             for (TextInputMethod orient : values()) {
59                 if (orient.mValue.equals(value)) {
60                     return orient;
61                 }
62             }
63 
64             return null;
65         }
66 
getValue()67         public String getValue() {
68             return mValue;
69         }
70 
getDisplayValue()71         public String getDisplayValue() {
72             return mDisplayValue;
73         }
74 
getIndex(TextInputMethod value)75         public static int getIndex(TextInputMethod value) {
76             int i = 0;
77             for (TextInputMethod input : values()) {
78                 if (value == input) {
79                     return i;
80                 }
81 
82                 i++;
83             }
84 
85             return -1;
86         }
87 
getByIndex(int index)88         public static TextInputMethod getByIndex(int index) {
89             int i = 0;
90             for (TextInputMethod value : values()) {
91                 if (i == index) {
92                     return value;
93                 }
94                 i++;
95             }
96             return null;
97         }
98     }
99 
TextInputMethodQualifier()100     public TextInputMethodQualifier() {
101         // pass
102     }
103 
TextInputMethodQualifier(TextInputMethod value)104     public TextInputMethodQualifier(TextInputMethod value) {
105         mValue = value;
106     }
107 
getValue()108     public TextInputMethod getValue() {
109         return mValue;
110     }
111 
112     @Override
getName()113     public String getName() {
114         return NAME;
115     }
116 
117     @Override
getShortName()118     public String getShortName() {
119         return "Text Input";
120     }
121 
122     @Override
getIcon()123     public Image getIcon() {
124         return IconFactory.getInstance().getIcon("text_input"); //$NON-NLS-1$
125     }
126 
127     @Override
isValid()128     public boolean isValid() {
129         return mValue != null;
130     }
131 
132     @Override
checkAndSet(String value, FolderConfiguration config)133     public boolean checkAndSet(String value, FolderConfiguration config) {
134         TextInputMethod method = TextInputMethod.getEnum(value);
135         if (method != null) {
136             TextInputMethodQualifier qualifier = new TextInputMethodQualifier();
137             qualifier.mValue = method;
138             config.setTextInputMethodQualifier(qualifier);
139             return true;
140         }
141 
142         return false;
143     }
144 
145     @Override
equals(Object qualifier)146     public boolean equals(Object qualifier) {
147         if (qualifier instanceof TextInputMethodQualifier) {
148             return mValue == ((TextInputMethodQualifier)qualifier).mValue;
149         }
150 
151         return false;
152     }
153 
154     @Override
hashCode()155     public int hashCode() {
156         if (mValue != null) {
157             return mValue.hashCode();
158         }
159 
160         return 0;
161     }
162 
163     /**
164      * Returns the string used to represent this qualifier in the folder name.
165      */
166     @Override
getFolderSegment(IAndroidTarget target)167     public String getFolderSegment(IAndroidTarget target) {
168         if (mValue != null) {
169             return mValue.getValue();
170         }
171 
172         return ""; //$NON-NLS-1$
173     }
174 
175     @Override
getStringValue()176     public String getStringValue() {
177         if (mValue != null) {
178             return mValue.getDisplayValue();
179         }
180 
181         return ""; //$NON-NLS-1$
182     }
183 }
184