• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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.ide.common.resources.configuration;
18 
19 import com.android.resources.KeyboardState;
20 import com.android.resources.ResourceEnum;
21 
22 /**
23  * Resource Qualifier for keyboard state.
24  */
25 public final class KeyboardStateQualifier extends EnumBasedResourceQualifier {
26 
27     public static final String NAME = "Keyboard State";
28 
29     private KeyboardState mValue = null;
30 
KeyboardStateQualifier()31     public KeyboardStateQualifier() {
32         // pass
33     }
34 
KeyboardStateQualifier(KeyboardState value)35     public KeyboardStateQualifier(KeyboardState value) {
36         mValue = value;
37     }
38 
getValue()39     public KeyboardState getValue() {
40         return mValue;
41     }
42 
43     @Override
getEnumValue()44     ResourceEnum getEnumValue() {
45         return mValue;
46     }
47 
48     @Override
getName()49     public String getName() {
50         return NAME;
51     }
52 
53     @Override
getShortName()54     public String getShortName() {
55         return "Keyboard";
56     }
57 
58     @Override
since()59     public int since() {
60         return 1;
61     }
62 
63     @Override
checkAndSet(String value, FolderConfiguration config)64     public boolean checkAndSet(String value, FolderConfiguration config) {
65         KeyboardState orientation = KeyboardState.getEnum(value);
66         if (orientation != null) {
67             KeyboardStateQualifier qualifier = new KeyboardStateQualifier();
68             qualifier.mValue = orientation;
69             config.setKeyboardStateQualifier(qualifier);
70             return true;
71         }
72 
73         return false;
74     }
75 
76     @Override
isMatchFor(ResourceQualifier qualifier)77     public boolean isMatchFor(ResourceQualifier qualifier) {
78         if (qualifier instanceof KeyboardStateQualifier) {
79             KeyboardStateQualifier referenceQualifier = (KeyboardStateQualifier)qualifier;
80 
81             // special case where EXPOSED can be used for SOFT
82             if (referenceQualifier.mValue == KeyboardState.SOFT &&
83                     mValue == KeyboardState.EXPOSED) {
84                 return true;
85             }
86 
87             return referenceQualifier.mValue == mValue;
88         }
89 
90         return false;
91     }
92 
93     @Override
isBetterMatchThan(ResourceQualifier compareTo, ResourceQualifier reference)94     public boolean isBetterMatchThan(ResourceQualifier compareTo, ResourceQualifier reference) {
95         if (compareTo == null) {
96             return true;
97         }
98 
99         KeyboardStateQualifier compareQualifier = (KeyboardStateQualifier)compareTo;
100         KeyboardStateQualifier referenceQualifier = (KeyboardStateQualifier)reference;
101 
102         if (referenceQualifier.mValue == KeyboardState.SOFT) { // only case where there could be a
103                                                                // better qualifier
104             // only return true if it's a better value.
105             if (compareQualifier.mValue == KeyboardState.EXPOSED && mValue == KeyboardState.SOFT) {
106                 return true;
107             }
108         }
109 
110         return false;
111     }
112 }
113