blob: 74cf80e1f4f2d82043098a41c6a9b6545010f9ab [file] [log] [blame]
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -07001/*
2 * Copyright (C) 2010 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#define LOG_TAG "Configuration"
18#include <utils/Log.h>
19
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080020#include <androidfw/AssetManager.h>
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070021
22#include <android_runtime/android_content_res_Configuration.h>
23
24using namespace android;
25
26AConfiguration* AConfiguration_new() {
27 AConfiguration* config = new AConfiguration;
28 memset(config, 0, sizeof(AConfiguration));
29 return config;
30}
31
32void AConfiguration_delete(AConfiguration* config) {
33 delete config;
34}
35
36void AConfiguration_fromAssetManager(AConfiguration* out, AAssetManager* am) {
37 ((AssetManager*)am)->getConfiguration(out);
38}
39
40void AConfiguration_copy(AConfiguration* dest, AConfiguration* src) {
41 *dest = *src;
42}
43
44int32_t AConfiguration_getMcc(AConfiguration* config) {
45 return config->mcc;
46}
47
48int32_t AConfiguration_getMnc(AConfiguration* config) {
49 return config->mnc;
50}
51
52void AConfiguration_getLanguage(AConfiguration* config, char* outLanguage) {
53 outLanguage[0] = config->language[0];
54 outLanguage[1] = config->language[1];
55}
56
57void AConfiguration_getCountry(AConfiguration* config, char* outCountry) {
58 outCountry[0] = config->country[0];
59 outCountry[1] = config->country[1];
60}
61
62int32_t AConfiguration_getOrientation(AConfiguration* config) {
63 return config->orientation;
64}
65
66int32_t AConfiguration_getTouchscreen(AConfiguration* config) {
67 return config->touchscreen;
68}
69
70int32_t AConfiguration_getDensity(AConfiguration* config) {
71 return config->density;
72}
73
74int32_t AConfiguration_getKeyboard(AConfiguration* config) {
75 return config->keyboard;
76}
77
78int32_t AConfiguration_getNavigation(AConfiguration* config) {
79 return config->navigation;
80}
81
82int32_t AConfiguration_getKeysHidden(AConfiguration* config) {
83 return config->inputFlags&ResTable_config::MASK_KEYSHIDDEN;
84}
85
86int32_t AConfiguration_getNavHidden(AConfiguration* config) {
87 return (config->inputFlags&ResTable_config::MASK_NAVHIDDEN)
88 >> ResTable_config::SHIFT_NAVHIDDEN;
89}
90
91int32_t AConfiguration_getSdkVersion(AConfiguration* config) {
92 return config->sdkVersion;
93}
94
95int32_t AConfiguration_getScreenSize(AConfiguration* config) {
96 return config->screenLayout&ResTable_config::MASK_SCREENSIZE;
97}
98
99int32_t AConfiguration_getScreenLong(AConfiguration* config) {
100 return (config->screenLayout&ResTable_config::MASK_SCREENLONG)
101 >> ResTable_config::SHIFT_SCREENLONG;
102}
103
104int32_t AConfiguration_getUiModeType(AConfiguration* config) {
105 return config->uiMode&ResTable_config::MASK_UI_MODE_TYPE;
106}
107
108int32_t AConfiguration_getUiModeNight(AConfiguration* config) {
109 return (config->uiMode&ResTable_config::MASK_UI_MODE_NIGHT)
110 >> ResTable_config::SHIFT_UI_MODE_NIGHT;
111
112}
113
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700114int32_t AConfiguration_getScreenWidthDp(AConfiguration* config) {
115 return config->screenWidthDp;
116}
117
118int32_t AConfiguration_getScreenHeightDp(AConfiguration* config) {
119 return config->screenHeightDp;
120}
121
122int32_t AConfiguration_getSmallestScreenWidthDp(AConfiguration* config) {
123 return config->smallestScreenWidthDp;
124}
125
Fabrice Di Meglio5f797992012-06-15 20:16:41 -0700126int32_t AConfiguration_getLayoutDirection(AConfiguration* config) {
127 return (config->screenLayout&ResTable_config::MASK_LAYOUTDIR)
128 >> ResTable_config::SHIFT_LAYOUTDIR;
129}
130
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700131// ----------------------------------------------------------------------
132
133void AConfiguration_setMcc(AConfiguration* config, int32_t mcc) {
134 config->mcc = mcc;
135}
136
137void AConfiguration_setMnc(AConfiguration* config, int32_t mnc) {
138 config->mnc = mnc;
139}
140
141void AConfiguration_setLanguage(AConfiguration* config, const char* language) {
142 config->language[0] = language[0];
143 config->language[1] = language[1];
144}
145
146void AConfiguration_setCountry(AConfiguration* config, const char* country) {
147 config->country[0] = country[0];
148 config->country[1] = country[1];
149}
150
151void AConfiguration_setOrientation(AConfiguration* config, int32_t orientation) {
152 config->orientation = orientation;
153}
154
155void AConfiguration_setTouchscreen(AConfiguration* config, int32_t touchscreen) {
156 config->touchscreen = touchscreen;
157}
158
159void AConfiguration_setDensity(AConfiguration* config, int32_t density) {
160 config->density = density;
161}
162
163void AConfiguration_setKeyboard(AConfiguration* config, int32_t keyboard) {
164 config->keyboard = keyboard;
165}
166
167void AConfiguration_setNavigation(AConfiguration* config, int32_t navigation) {
168 config->navigation = navigation;
169}
170
171void AConfiguration_setKeysHidden(AConfiguration* config, int32_t keysHidden) {
172 config->inputFlags = (config->inputFlags&~ResTable_config::MASK_KEYSHIDDEN)
173 | (keysHidden&ResTable_config::MASK_KEYSHIDDEN);
174}
175
176void AConfiguration_setNavHidden(AConfiguration* config, int32_t navHidden) {
177 config->inputFlags = (config->inputFlags&~ResTable_config::MASK_NAVHIDDEN)
178 | ((navHidden<<ResTable_config::SHIFT_NAVHIDDEN)&ResTable_config::MASK_NAVHIDDEN);
179}
180
181void AConfiguration_setSdkVersion(AConfiguration* config, int32_t sdkVersion) {
182 config->sdkVersion = sdkVersion;
183}
184
185void AConfiguration_setScreenSize(AConfiguration* config, int32_t screenSize) {
186 config->screenLayout = (config->screenLayout&~ResTable_config::MASK_SCREENSIZE)
187 | (screenSize&ResTable_config::MASK_SCREENSIZE);
188}
189
190void AConfiguration_setScreenLong(AConfiguration* config, int32_t screenLong) {
191 config->screenLayout = (config->screenLayout&~ResTable_config::MASK_SCREENLONG)
192 | ((screenLong<<ResTable_config::SHIFT_SCREENLONG)&ResTable_config::MASK_SCREENLONG);
193}
194
195void AConfiguration_setUiModeType(AConfiguration* config, int32_t uiModeType) {
196 config->uiMode = (config->uiMode&~ResTable_config::MASK_UI_MODE_TYPE)
197 | (uiModeType&ResTable_config::MASK_UI_MODE_TYPE);
198}
199
200void AConfiguration_setUiModeNight(AConfiguration* config, int32_t uiModeNight) {
201 config->uiMode = (config->uiMode&~ResTable_config::MASK_UI_MODE_NIGHT)
202 | ((uiModeNight<<ResTable_config::SHIFT_UI_MODE_NIGHT)&ResTable_config::MASK_UI_MODE_NIGHT);
203
204}
205
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700206void AConfiguration_setScreenWidthDp(AConfiguration* config, int32_t value) {
207 config->screenWidthDp = value;
208}
209
210void AConfiguration_setScreenHeightDp(AConfiguration* config, int32_t value) {
211 config->screenHeightDp = value;
212}
213
214void AConfiguration_setSmallestScreenWidthDp(AConfiguration* config, int32_t value) {
215 config->smallestScreenWidthDp = value;
216}
217
Fabrice Di Meglio5f797992012-06-15 20:16:41 -0700218void AConfiguration_setLayoutDirection(AConfiguration* config, int32_t value) {
219 config->screenLayout = (config->screenLayout&~ResTable_config::MASK_LAYOUTDIR)
220 | ((value<<ResTable_config::SHIFT_LAYOUTDIR)&ResTable_config::MASK_LAYOUTDIR);
221}
222
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700223// ----------------------------------------------------------------------
224
225int32_t AConfiguration_diff(AConfiguration* config1, AConfiguration* config2) {
226 return (config1->diff(*config2));
227}
228
229int32_t AConfiguration_match(AConfiguration* base, AConfiguration* requested) {
230 return base->match(*requested);
231}
232
233int32_t AConfiguration_isBetterThan(AConfiguration* base, AConfiguration* test,
234 AConfiguration* requested) {
235 return base->isBetterThan(*test, requested);
236}