AaptConfig.h revision de7de47fef1dcaa26d553665d89e4d3792325c3f
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 */
28namespace 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 */
37bool 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 */
45bool 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 */
52void applyVersionForCompatibility(ConfigDescription* config);
53
54// Individual axis
55bool parseMcc(const char* str, android::ResTable_config* out = NULL);
56bool parseMnc(const char* str, android::ResTable_config* out = NULL);
57bool parseLayoutDirection(const char* str, android::ResTable_config* out = NULL);
58bool parseSmallestScreenWidthDp(const char* str, android::ResTable_config* out = NULL);
59bool parseScreenWidthDp(const char* str, android::ResTable_config* out = NULL);
60bool parseScreenHeightDp(const char* str, android::ResTable_config* out = NULL);
61bool parseScreenLayoutSize(const char* str, android::ResTable_config* out = NULL);
62bool parseScreenLayoutLong(const char* str, android::ResTable_config* out = NULL);
63bool parseOrientation(const char* str, android::ResTable_config* out = NULL);
64bool parseUiModeType(const char* str, android::ResTable_config* out = NULL);
65bool parseUiModeNight(const char* str, android::ResTable_config* out = NULL);
66bool parseDensity(const char* str, android::ResTable_config* out = NULL);
67bool parseTouchscreen(const char* str, android::ResTable_config* out = NULL);
68bool parseKeysHidden(const char* str, android::ResTable_config* out = NULL);
69bool parseKeyboard(const char* str, android::ResTable_config* out = NULL);
70bool parseNavHidden(const char* str, android::ResTable_config* out = NULL);
71bool parseNavigation(const char* str, android::ResTable_config* out = NULL);
72bool parseScreenSize(const char* str, android::ResTable_config* out = NULL);
73bool parseVersion(const char* str, android::ResTable_config* out = NULL);
74
75android::String8 getVersion(const android::ResTable_config& config);
76
77/**
78 * Returns true if the two configurations only differ by the specified axis.
79 * The axis mask is a bitmask of CONFIG_* constants.
80 */
81bool isSameExcept(const android::ResTable_config& a, const android::ResTable_config& b, int configMask);
82
83/**
84 * Returns true if the configuration only has the density specified. In the case
85 * of 'anydpi', the version is ignored.
86 */
87bool isDensityOnly(const android::ResTable_config& config);
88
89} // namespace AaptConfig
90
91#endif // __AAPT_CONFIG_H
92