1 /* 2 * Copyright (C) 2014 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 #ifndef __AAPT_CONFIG_H 18 #define __AAPT_CONFIG_H 19 20 #include <set> 21 #include <utils/String8.h> 22 23 #include "ConfigDescription.h" 24 25 /** 26 * Utility methods for dealing with configurations. 27 */ 28 namespace AaptConfig { 29 30 /** 31 * Parse a string of the form 'fr-sw600dp-land' and fill in the 32 * given ResTable_config with resulting configuration parameters. 33 * 34 * The resulting configuration has the appropriate sdkVersion defined 35 * for backwards compatibility. 36 */ 37 bool parse(const android::String8& str, ConfigDescription* out = NULL); 38 39 /** 40 * Parse a comma separated list of configuration strings. Duplicate configurations 41 * will be removed. 42 * 43 * Example input: "fr,de-land,fr-sw600dp-land" 44 */ 45 bool parseCommaSeparatedList(const android::String8& str, std::set<ConfigDescription>* outSet); 46 47 /** 48 * If the configuration uses an axis that was added after 49 * the original Android release, make sure the SDK version 50 * is set accordingly. 51 */ 52 void applyVersionForCompatibility(ConfigDescription* config); 53 54 // Individual axis 55 bool parseMcc(const char* str, android::ResTable_config* out = NULL); 56 bool parseMnc(const char* str, android::ResTable_config* out = NULL); 57 bool parseLayoutDirection(const char* str, android::ResTable_config* out = NULL); 58 bool parseSmallestScreenWidthDp(const char* str, android::ResTable_config* out = NULL); 59 bool parseScreenWidthDp(const char* str, android::ResTable_config* out = NULL); 60 bool parseScreenHeightDp(const char* str, android::ResTable_config* out = NULL); 61 bool parseScreenLayoutSize(const char* str, android::ResTable_config* out = NULL); 62 bool parseScreenLayoutLong(const char* str, android::ResTable_config* out = NULL); 63 bool parseScreenRound(const char* name, android::ResTable_config* out = NULL); 64 bool parseOrientation(const char* str, android::ResTable_config* out = NULL); 65 bool parseUiModeType(const char* str, android::ResTable_config* out = NULL); 66 bool parseUiModeNight(const char* str, android::ResTable_config* out = NULL); 67 bool parseDensity(const char* str, android::ResTable_config* out = NULL); 68 bool parseTouchscreen(const char* str, android::ResTable_config* out = NULL); 69 bool parseKeysHidden(const char* str, android::ResTable_config* out = NULL); 70 bool parseKeyboard(const char* str, android::ResTable_config* out = NULL); 71 bool parseNavHidden(const char* str, android::ResTable_config* out = NULL); 72 bool parseNavigation(const char* str, android::ResTable_config* out = NULL); 73 bool parseScreenSize(const char* str, android::ResTable_config* out = NULL); 74 bool parseVersion(const char* str, android::ResTable_config* out = NULL); 75 76 android::String8 getVersion(const android::ResTable_config& config); 77 78 /** 79 * Returns true if the two configurations only differ by the specified axis. 80 * The axis mask is a bitmask of CONFIG_* constants. 81 */ 82 bool isSameExcept(const android::ResTable_config& a, const android::ResTable_config& b, int configMask); 83 84 /** 85 * Returns true if the configuration only has the density specified. In the case 86 * of 'anydpi', the version is ignored. 87 */ 88 bool isDensityOnly(const android::ResTable_config& config); 89 90 } // namespace AaptConfig 91 92 #endif // __AAPT_CONFIG_H 93