Kenny Root | 15a4d2f | 2010-03-11 18:20:12 -0800 | [diff] [blame] | 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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | package android.content.res; |
| 18 | |
Dianne Hackborn | 337e01a | 2018-02-27 17:16:37 -0800 | [diff] [blame] | 19 | import static android.content.ConfigurationProto.COLOR_MODE; |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 20 | import static android.content.ConfigurationProto.DENSITY_DPI; |
| 21 | import static android.content.ConfigurationProto.FONT_SCALE; |
Dianne Hackborn | bf5ba6b | 2018-02-20 10:31:02 -0800 | [diff] [blame] | 22 | import static android.content.ConfigurationProto.HARD_KEYBOARD_HIDDEN; |
Dianne Hackborn | 337e01a | 2018-02-27 17:16:37 -0800 | [diff] [blame] | 23 | import static android.content.ConfigurationProto.KEYBOARD; |
Dianne Hackborn | bf5ba6b | 2018-02-20 10:31:02 -0800 | [diff] [blame] | 24 | import static android.content.ConfigurationProto.KEYBOARD_HIDDEN; |
| 25 | import static android.content.ConfigurationProto.LOCALES; |
Varun Shah | bd0ce4d | 2019-09-10 15:51:37 -0400 | [diff] [blame] | 26 | import static android.content.ConfigurationProto.LOCALE_LIST; |
Dianne Hackborn | bf5ba6b | 2018-02-20 10:31:02 -0800 | [diff] [blame] | 27 | import static android.content.ConfigurationProto.MCC; |
| 28 | import static android.content.ConfigurationProto.MNC; |
| 29 | import static android.content.ConfigurationProto.NAVIGATION; |
| 30 | import static android.content.ConfigurationProto.NAVIGATION_HIDDEN; |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 31 | import static android.content.ConfigurationProto.ORIENTATION; |
| 32 | import static android.content.ConfigurationProto.SCREEN_HEIGHT_DP; |
| 33 | import static android.content.ConfigurationProto.SCREEN_LAYOUT; |
| 34 | import static android.content.ConfigurationProto.SCREEN_WIDTH_DP; |
| 35 | import static android.content.ConfigurationProto.SMALLEST_SCREEN_WIDTH_DP; |
Dianne Hackborn | bf5ba6b | 2018-02-20 10:31:02 -0800 | [diff] [blame] | 36 | import static android.content.ConfigurationProto.TOUCHSCREEN; |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 37 | import static android.content.ConfigurationProto.UI_MODE; |
| 38 | import static android.content.ConfigurationProto.WINDOW_CONFIGURATION; |
Dianne Hackborn | bf5ba6b | 2018-02-20 10:31:02 -0800 | [diff] [blame] | 39 | import static android.content.ResourcesConfigurationProto.CONFIGURATION; |
| 40 | import static android.content.ResourcesConfigurationProto.SCREEN_HEIGHT_PX; |
| 41 | import static android.content.ResourcesConfigurationProto.SCREEN_WIDTH_PX; |
| 42 | import static android.content.ResourcesConfigurationProto.SDK_VERSION; |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 43 | |
Alan Viverette | ac85f90 | 2016-03-11 15:15:51 -0500 | [diff] [blame] | 44 | import android.annotation.IntDef; |
| 45 | import android.annotation.NonNull; |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 46 | import android.annotation.Nullable; |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 47 | import android.annotation.TestApi; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 48 | import android.annotation.UnsupportedAppUsage; |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 49 | import android.app.WindowConfiguration; |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 50 | import android.content.LocaleProto; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import android.content.pm.ActivityInfo; |
Alan Viverette | ac85f90 | 2016-03-11 15:15:51 -0500 | [diff] [blame] | 52 | import android.content.pm.ActivityInfo.Config; |
Adam Lesinski | 2c749d2 | 2014-06-04 13:00:29 -0700 | [diff] [blame] | 53 | import android.os.Build; |
Yohei Yukawa | 23cbe85 | 2016-05-17 16:42:58 -0700 | [diff] [blame] | 54 | import android.os.LocaleList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.os.Parcel; |
| 56 | import android.os.Parcelable; |
Fabrice Di Meglio | d3d9f3f | 2012-09-18 12:55:32 -0700 | [diff] [blame] | 57 | import android.text.TextUtils; |
Dianne Hackborn | bf5ba6b | 2018-02-20 10:31:02 -0800 | [diff] [blame] | 58 | import android.util.DisplayMetrics; |
Varun Shah | 95fabaf | 2019-05-01 12:45:37 -0700 | [diff] [blame] | 59 | import android.util.Slog; |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 60 | import android.util.proto.ProtoInputStream; |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 61 | import android.util.proto.ProtoOutputStream; |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 62 | import android.util.proto.WireTypeMismatchException; |
Fabrice Di Meglio | 3fb824b | 2012-02-28 17:58:31 -0800 | [diff] [blame] | 63 | import android.view.View; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | |
Romain Guy | e89d0bb | 2017-06-20 12:23:42 -0700 | [diff] [blame] | 65 | import com.android.internal.util.XmlUtils; |
| 66 | |
| 67 | import org.xmlpull.v1.XmlPullParser; |
| 68 | import org.xmlpull.v1.XmlPullParserException; |
Romain Guy | e89d0bb | 2017-06-20 12:23:42 -0700 | [diff] [blame] | 69 | |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 70 | import java.io.IOException; |
Alan Viverette | ac85f90 | 2016-03-11 15:15:51 -0500 | [diff] [blame] | 71 | import java.lang.annotation.Retention; |
| 72 | import java.lang.annotation.RetentionPolicy; |
Adam Lesinski | 2c749d2 | 2014-06-04 13:00:29 -0700 | [diff] [blame] | 73 | import java.util.ArrayList; |
Varun Shah | 95fabaf | 2019-05-01 12:45:37 -0700 | [diff] [blame] | 74 | import java.util.IllformedLocaleException; |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 75 | import java.util.List; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | import java.util.Locale; |
| 77 | |
| 78 | /** |
| 79 | * This class describes all device configuration information that can |
| 80 | * impact the resources the application retrieves. This includes both |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 81 | * user-specified configuration options (locale list and scaling) as well |
Scott Main | 63848e3 | 2011-04-20 22:20:46 -0700 | [diff] [blame] | 82 | * as device configurations (such as input modes, screen size and screen orientation). |
| 83 | * <p>You can acquire this object from {@link Resources}, using {@link |
| 84 | * Resources#getConfiguration}. Thus, from an activity, you can get it by chaining the request |
| 85 | * with {@link android.app.Activity#getResources}:</p> |
| 86 | * <pre>Configuration config = getResources().getConfiguration();</pre> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | */ |
| 88 | public final class Configuration implements Parcelable, Comparable<Configuration> { |
Dianne Hackborn | 756220b | 2012-08-14 16:45:30 -0700 | [diff] [blame] | 89 | /** @hide */ |
| 90 | public static final Configuration EMPTY = new Configuration(); |
| 91 | |
Varun Shah | 95fabaf | 2019-05-01 12:45:37 -0700 | [diff] [blame] | 92 | private static final String TAG = "Configuration"; |
| 93 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | /** |
| 95 | * Current user preference for the scaling factor for fonts, relative |
| 96 | * to the base density scaling. |
| 97 | */ |
| 98 | public float fontScale; |
| 99 | |
| 100 | /** |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 101 | * IMSI MCC (Mobile Country Code), corresponding to |
| 102 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#MccQualifier">mcc</a> |
| 103 | * resource qualifier. 0 if undefined. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | */ |
| 105 | public int mcc; |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 106 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | /** |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 108 | * IMSI MNC (Mobile Network Code), corresponding to |
| 109 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#MccQualifier">mnc</a> |
Mattias Petersson | 1d766b5 | 2011-10-07 09:33:52 +0200 | [diff] [blame] | 110 | * resource qualifier. 0 if undefined. Note that the actual MNC may be 0; in order to check |
| 111 | * for this use the {@link #MNC_ZERO} symbol. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | */ |
| 113 | public int mnc; |
Mattias Petersson | 1d766b5 | 2011-10-07 09:33:52 +0200 | [diff] [blame] | 114 | |
| 115 | /** |
| 116 | * Constant used to to represent MNC (Mobile Network Code) zero. |
| 117 | * 0 cannot be used, since it is used to represent an undefined MNC. |
| 118 | */ |
| 119 | public static final int MNC_ZERO = 0xffff; |
| 120 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | /** |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 122 | * Current user preference for the locale, corresponding to |
| 123 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#LocaleQualifier">locale</a> |
| 124 | * resource qualifier. |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 125 | * |
| 126 | * @deprecated Do not set or read this directly. Use {@link #getLocales()} and |
Raph Levien | b163870 | 2016-04-27 11:02:12 -0700 | [diff] [blame] | 127 | * {@link #setLocales(LocaleList)}. If only the primary locale is needed, |
| 128 | * <code>getLocales().get(0)</code> is now the preferred accessor. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | */ |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 130 | @Deprecated public Locale locale; |
| 131 | |
| 132 | private LocaleList mLocaleList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | |
| 134 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 135 | * Locale should persist on setting. This is hidden because it is really |
| 136 | * questionable whether this is the right way to expose the functionality. |
| 137 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 139 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | public boolean userSetLocale; |
| 141 | |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 142 | |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 143 | /** Constant for {@link #colorMode}: bits that encode whether the screen is wide gamut. */ |
| 144 | public static final int COLOR_MODE_WIDE_COLOR_GAMUT_MASK = 0x3; |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 145 | /** |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 146 | * Constant for {@link #colorMode}: a {@link #COLOR_MODE_WIDE_COLOR_GAMUT_MASK} value |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 147 | * indicating that it is unknown whether or not the screen is wide gamut. |
| 148 | */ |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 149 | public static final int COLOR_MODE_WIDE_COLOR_GAMUT_UNDEFINED = 0x0; |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 150 | /** |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 151 | * Constant for {@link #colorMode}: a {@link #COLOR_MODE_WIDE_COLOR_GAMUT_MASK} value |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 152 | * indicating that the screen is not wide gamut. |
| 153 | * <p>Corresponds to the <code>-nowidecg</code> resource qualifier.</p> |
| 154 | */ |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 155 | public static final int COLOR_MODE_WIDE_COLOR_GAMUT_NO = 0x1; |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 156 | /** |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 157 | * Constant for {@link #colorMode}: a {@link #COLOR_MODE_WIDE_COLOR_GAMUT_MASK} value |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 158 | * indicating that the screen is wide gamut. |
| 159 | * <p>Corresponds to the <code>-widecg</code> resource qualifier.</p> |
| 160 | */ |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 161 | public static final int COLOR_MODE_WIDE_COLOR_GAMUT_YES = 0x2; |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 162 | |
Romain Guy | b3f6926 | 2017-04-13 20:06:41 -0700 | [diff] [blame] | 163 | /** Constant for {@link #colorMode}: bits that encode the dynamic range of the screen. */ |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 164 | public static final int COLOR_MODE_HDR_MASK = 0xc; |
| 165 | /** Constant for {@link #colorMode}: bits shift to get the screen dynamic range. */ |
| 166 | public static final int COLOR_MODE_HDR_SHIFT = 2; |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 167 | /** |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 168 | * Constant for {@link #colorMode}: a {@link #COLOR_MODE_HDR_MASK} value |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 169 | * indicating that it is unknown whether or not the screen is HDR. |
| 170 | */ |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 171 | public static final int COLOR_MODE_HDR_UNDEFINED = 0x0; |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 172 | /** |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 173 | * Constant for {@link #colorMode}: a {@link #COLOR_MODE_HDR_MASK} value |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 174 | * indicating that the screen is not HDR (low/standard dynamic range). |
| 175 | * <p>Corresponds to the <code>-lowdr</code> resource qualifier.</p> |
| 176 | */ |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 177 | public static final int COLOR_MODE_HDR_NO = 0x1 << COLOR_MODE_HDR_SHIFT; |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 178 | /** |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 179 | * Constant for {@link #colorMode}: a {@link #COLOR_MODE_HDR_MASK} value |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 180 | * indicating that the screen is HDR (dynamic range). |
| 181 | * <p>Corresponds to the <code>-highdr</code> resource qualifier.</p> |
| 182 | */ |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 183 | public static final int COLOR_MODE_HDR_YES = 0x2 << COLOR_MODE_HDR_SHIFT; |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 184 | |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 185 | /** Constant for {@link #colorMode}: a value indicating that the color mode is undefined */ |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 186 | @SuppressWarnings("PointlessBitwiseExpression") |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 187 | public static final int COLOR_MODE_UNDEFINED = COLOR_MODE_WIDE_COLOR_GAMUT_UNDEFINED | |
| 188 | COLOR_MODE_HDR_UNDEFINED; |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 189 | |
| 190 | /** |
Romain Guy | b3f6926 | 2017-04-13 20:06:41 -0700 | [diff] [blame] | 191 | * Bit mask of color capabilities of the screen. Currently there are two fields: |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 192 | * <p>The {@link #COLOR_MODE_WIDE_COLOR_GAMUT_MASK} bits define the color gamut of |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 193 | * the screen. They may be one of |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 194 | * {@link #COLOR_MODE_WIDE_COLOR_GAMUT_NO} or {@link #COLOR_MODE_WIDE_COLOR_GAMUT_YES}.</p> |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 195 | * |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 196 | * <p>The {@link #COLOR_MODE_HDR_MASK} defines the dynamic range of the screen. They may be |
| 197 | * one of {@link #COLOR_MODE_HDR_NO} or {@link #COLOR_MODE_HDR_YES}.</p> |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 198 | * |
| 199 | * <p>See <a href="{@docRoot}guide/practices/screens_support.html">Supporting |
| 200 | * Multiple Screens</a> for more information.</p> |
| 201 | */ |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 202 | public int colorMode; |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 203 | |
Dianne Hackborn | 2f98f26 | 2011-03-28 18:28:35 -0700 | [diff] [blame] | 204 | /** Constant for {@link #screenLayout}: bits that encode the size. */ |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 205 | public static final int SCREENLAYOUT_SIZE_MASK = 0x0f; |
Dianne Hackborn | 2f98f26 | 2011-03-28 18:28:35 -0700 | [diff] [blame] | 206 | /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK} |
| 207 | * value indicating that no size has been set. */ |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 208 | public static final int SCREENLAYOUT_SIZE_UNDEFINED = 0x00; |
Dianne Hackborn | 2f98f26 | 2011-03-28 18:28:35 -0700 | [diff] [blame] | 209 | /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK} |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 210 | * value indicating the screen is at least approximately 320x426 dp units, |
| 211 | * corresponds to the |
| 212 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenSizeQualifier">small</a> |
| 213 | * resource qualifier. |
Dianne Hackborn | 2f98f26 | 2011-03-28 18:28:35 -0700 | [diff] [blame] | 214 | * See <a href="{@docRoot}guide/practices/screens_support.html">Supporting |
| 215 | * Multiple Screens</a> for more information. */ |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 216 | public static final int SCREENLAYOUT_SIZE_SMALL = 0x01; |
Dianne Hackborn | 2f98f26 | 2011-03-28 18:28:35 -0700 | [diff] [blame] | 217 | /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK} |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 218 | * value indicating the screen is at least approximately 320x470 dp units, |
| 219 | * corresponds to the |
| 220 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenSizeQualifier">normal</a> |
| 221 | * resource qualifier. |
Dianne Hackborn | 2f98f26 | 2011-03-28 18:28:35 -0700 | [diff] [blame] | 222 | * See <a href="{@docRoot}guide/practices/screens_support.html">Supporting |
| 223 | * Multiple Screens</a> for more information. */ |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 224 | public static final int SCREENLAYOUT_SIZE_NORMAL = 0x02; |
Dianne Hackborn | 2f98f26 | 2011-03-28 18:28:35 -0700 | [diff] [blame] | 225 | /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK} |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 226 | * value indicating the screen is at least approximately 480x640 dp units, |
| 227 | * corresponds to the |
| 228 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenSizeQualifier">large</a> |
| 229 | * resource qualifier. |
Dianne Hackborn | 2f98f26 | 2011-03-28 18:28:35 -0700 | [diff] [blame] | 230 | * See <a href="{@docRoot}guide/practices/screens_support.html">Supporting |
| 231 | * Multiple Screens</a> for more information. */ |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 232 | public static final int SCREENLAYOUT_SIZE_LARGE = 0x03; |
Dianne Hackborn | 2f98f26 | 2011-03-28 18:28:35 -0700 | [diff] [blame] | 233 | /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK} |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 234 | * value indicating the screen is at least approximately 720x960 dp units, |
| 235 | * corresponds to the |
| 236 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenSizeQualifier">xlarge</a> |
| 237 | * resource qualifier. |
Dianne Hackborn | 2f98f26 | 2011-03-28 18:28:35 -0700 | [diff] [blame] | 238 | * See <a href="{@docRoot}guide/practices/screens_support.html">Supporting |
| 239 | * Multiple Screens</a> for more information.*/ |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 240 | public static final int SCREENLAYOUT_SIZE_XLARGE = 0x04; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 241 | |
| 242 | /** Constant for {@link #screenLayout}: bits that encode the aspect ratio. */ |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 243 | public static final int SCREENLAYOUT_LONG_MASK = 0x30; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 244 | /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LONG_MASK} |
| 245 | * value indicating that no size has been set. */ |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 246 | public static final int SCREENLAYOUT_LONG_UNDEFINED = 0x00; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 247 | /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LONG_MASK} |
| 248 | * value that corresponds to the |
| 249 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenAspectQualifier">notlong</a> |
| 250 | * resource qualifier. */ |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 251 | public static final int SCREENLAYOUT_LONG_NO = 0x10; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 252 | /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LONG_MASK} |
| 253 | * value that corresponds to the |
| 254 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenAspectQualifier">long</a> |
| 255 | * resource qualifier. */ |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 256 | public static final int SCREENLAYOUT_LONG_YES = 0x20; |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 257 | |
| 258 | /** Constant for {@link #screenLayout}: bits that encode the layout direction. */ |
| 259 | public static final int SCREENLAYOUT_LAYOUTDIR_MASK = 0xC0; |
| 260 | /** Constant for {@link #screenLayout}: bits shift to get the layout direction. */ |
| 261 | public static final int SCREENLAYOUT_LAYOUTDIR_SHIFT = 6; |
| 262 | /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LAYOUTDIR_MASK} |
| 263 | * value indicating that no layout dir has been set. */ |
| 264 | public static final int SCREENLAYOUT_LAYOUTDIR_UNDEFINED = 0x00; |
| 265 | /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LAYOUTDIR_MASK} |
| 266 | * value indicating that a layout dir has been set to LTR. */ |
| 267 | public static final int SCREENLAYOUT_LAYOUTDIR_LTR = 0x01 << SCREENLAYOUT_LAYOUTDIR_SHIFT; |
| 268 | /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LAYOUTDIR_MASK} |
| 269 | * value indicating that a layout dir has been set to RTL. */ |
| 270 | public static final int SCREENLAYOUT_LAYOUTDIR_RTL = 0x02 << SCREENLAYOUT_LAYOUTDIR_SHIFT; |
| 271 | |
Adam Powell | 49e7ff9 | 2015-05-14 16:18:53 -0700 | [diff] [blame] | 272 | /** Constant for {@link #screenLayout}: bits that encode roundness of the screen. */ |
| 273 | public static final int SCREENLAYOUT_ROUND_MASK = 0x300; |
| 274 | /** @hide Constant for {@link #screenLayout}: bit shift to get to screen roundness bits */ |
| 275 | public static final int SCREENLAYOUT_ROUND_SHIFT = 8; |
| 276 | /** |
| 277 | * Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_ROUND_MASK} value indicating |
| 278 | * that it is unknown whether or not the screen has a round shape. |
| 279 | */ |
| 280 | public static final int SCREENLAYOUT_ROUND_UNDEFINED = 0x00; |
| 281 | /** |
| 282 | * Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_ROUND_MASK} value indicating |
| 283 | * that the screen does not have a rounded shape. |
| 284 | */ |
| 285 | public static final int SCREENLAYOUT_ROUND_NO = 0x1 << SCREENLAYOUT_ROUND_SHIFT; |
| 286 | /** |
| 287 | * Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_ROUND_MASK} value indicating |
| 288 | * that the screen has a rounded shape. Corners may not be visible to the user; |
| 289 | * developers should pay special attention to the {@link android.view.WindowInsets} delivered |
| 290 | * to views for more information about ensuring content is not obscured. |
| 291 | * |
| 292 | * <p>Corresponds to the <code>-round</code> resource qualifier.</p> |
| 293 | */ |
| 294 | public static final int SCREENLAYOUT_ROUND_YES = 0x2 << SCREENLAYOUT_ROUND_SHIFT; |
| 295 | |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 296 | /** Constant for {@link #screenLayout}: a value indicating that screenLayout is undefined */ |
| 297 | public static final int SCREENLAYOUT_UNDEFINED = SCREENLAYOUT_SIZE_UNDEFINED | |
Adam Powell | 49e7ff9 | 2015-05-14 16:18:53 -0700 | [diff] [blame] | 298 | SCREENLAYOUT_LONG_UNDEFINED | SCREENLAYOUT_LAYOUTDIR_UNDEFINED | |
| 299 | SCREENLAYOUT_ROUND_UNDEFINED; |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 300 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 301 | /** |
| 302 | * Special flag we generate to indicate that the screen layout requires |
| 303 | * us to use a compatibility mode for apps that are not modern layout |
| 304 | * aware. |
| 305 | * @hide |
| 306 | */ |
| 307 | public static final int SCREENLAYOUT_COMPAT_NEEDED = 0x10000000; |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 308 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 309 | /** |
Andrii Kulian | f12fce1 | 2016-05-27 17:30:16 -0700 | [diff] [blame] | 310 | * Bit mask of overall layout of the screen. Currently there are four |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 311 | * fields: |
| 312 | * <p>The {@link #SCREENLAYOUT_SIZE_MASK} bits define the overall size |
| 313 | * of the screen. They may be one of |
| 314 | * {@link #SCREENLAYOUT_SIZE_SMALL}, {@link #SCREENLAYOUT_SIZE_NORMAL}, |
Adam Powell | 49e7ff9 | 2015-05-14 16:18:53 -0700 | [diff] [blame] | 315 | * {@link #SCREENLAYOUT_SIZE_LARGE}, or {@link #SCREENLAYOUT_SIZE_XLARGE}.</p> |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 316 | * |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 317 | * <p>The {@link #SCREENLAYOUT_LONG_MASK} defines whether the screen |
| 318 | * is wider/taller than normal. They may be one of |
Adam Powell | 49e7ff9 | 2015-05-14 16:18:53 -0700 | [diff] [blame] | 319 | * {@link #SCREENLAYOUT_LONG_NO} or {@link #SCREENLAYOUT_LONG_YES}.</p> |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 320 | * |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 321 | * <p>The {@link #SCREENLAYOUT_LAYOUTDIR_MASK} defines whether the screen layout |
| 322 | * is either LTR or RTL. They may be one of |
Adam Powell | 49e7ff9 | 2015-05-14 16:18:53 -0700 | [diff] [blame] | 323 | * {@link #SCREENLAYOUT_LAYOUTDIR_LTR} or {@link #SCREENLAYOUT_LAYOUTDIR_RTL}.</p> |
| 324 | * |
| 325 | * <p>The {@link #SCREENLAYOUT_ROUND_MASK} defines whether the screen has a rounded |
| 326 | * shape. They may be one of {@link #SCREENLAYOUT_ROUND_NO} or {@link #SCREENLAYOUT_ROUND_YES}. |
| 327 | * </p> |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 328 | * |
Dianne Hackborn | 2f98f26 | 2011-03-28 18:28:35 -0700 | [diff] [blame] | 329 | * <p>See <a href="{@docRoot}guide/practices/screens_support.html">Supporting |
Adam Powell | 49e7ff9 | 2015-05-14 16:18:53 -0700 | [diff] [blame] | 330 | * Multiple Screens</a> for more information.</p> |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 331 | */ |
| 332 | public int screenLayout; |
Dianne Hackborn | fe37f8f | 2012-09-30 12:24:33 -0700 | [diff] [blame] | 333 | |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 334 | /** |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 335 | * Configuration relating to the windowing state of the object associated with this |
| 336 | * Configuration. Contents of this field are not intended to affect resources, but need to be |
| 337 | * communicated and propagated at the same time as the rest of Configuration. |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 338 | * @hide |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 339 | */ |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 340 | @TestApi |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 341 | public final WindowConfiguration windowConfiguration = new WindowConfiguration(); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 342 | |
Dianne Hackborn | fe37f8f | 2012-09-30 12:24:33 -0700 | [diff] [blame] | 343 | /** @hide */ |
| 344 | static public int resetScreenLayout(int curLayout) { |
| 345 | return (curLayout&~(SCREENLAYOUT_LONG_MASK | SCREENLAYOUT_SIZE_MASK |
| 346 | | SCREENLAYOUT_COMPAT_NEEDED)) |
| 347 | | (SCREENLAYOUT_LONG_YES | SCREENLAYOUT_SIZE_XLARGE); |
| 348 | } |
| 349 | |
| 350 | /** @hide */ |
| 351 | static public int reduceScreenLayout(int curLayout, int longSizeDp, int shortSizeDp) { |
| 352 | int screenLayoutSize; |
| 353 | boolean screenLayoutLong; |
| 354 | boolean screenLayoutCompatNeeded; |
| 355 | |
| 356 | // These semi-magic numbers define our compatibility modes for |
| 357 | // applications with different screens. These are guarantees to |
| 358 | // app developers about the space they can expect for a particular |
| 359 | // configuration. DO NOT CHANGE! |
| 360 | if (longSizeDp < 470) { |
| 361 | // This is shorter than an HVGA normal density screen (which |
| 362 | // is 480 pixels on its long side). |
| 363 | screenLayoutSize = SCREENLAYOUT_SIZE_SMALL; |
| 364 | screenLayoutLong = false; |
| 365 | screenLayoutCompatNeeded = false; |
| 366 | } else { |
| 367 | // What size is this screen screen? |
| 368 | if (longSizeDp >= 960 && shortSizeDp >= 720) { |
| 369 | // 1.5xVGA or larger screens at medium density are the point |
| 370 | // at which we consider it to be an extra large screen. |
| 371 | screenLayoutSize = SCREENLAYOUT_SIZE_XLARGE; |
| 372 | } else if (longSizeDp >= 640 && shortSizeDp >= 480) { |
| 373 | // VGA or larger screens at medium density are the point |
| 374 | // at which we consider it to be a large screen. |
| 375 | screenLayoutSize = SCREENLAYOUT_SIZE_LARGE; |
| 376 | } else { |
| 377 | screenLayoutSize = SCREENLAYOUT_SIZE_NORMAL; |
| 378 | } |
| 379 | |
| 380 | // If this screen is wider than normal HVGA, or taller |
| 381 | // than FWVGA, then for old apps we want to run in size |
| 382 | // compatibility mode. |
| 383 | if (shortSizeDp > 321 || longSizeDp > 570) { |
| 384 | screenLayoutCompatNeeded = true; |
| 385 | } else { |
| 386 | screenLayoutCompatNeeded = false; |
| 387 | } |
| 388 | |
| 389 | // Is this a long screen? |
| 390 | if (((longSizeDp*3)/5) >= (shortSizeDp-1)) { |
| 391 | // Anything wider than WVGA (5:3) is considering to be long. |
| 392 | screenLayoutLong = true; |
| 393 | } else { |
| 394 | screenLayoutLong = false; |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | // Now reduce the last screenLayout to not be better than what we |
| 399 | // have found. |
| 400 | if (!screenLayoutLong) { |
| 401 | curLayout = (curLayout&~SCREENLAYOUT_LONG_MASK) | SCREENLAYOUT_LONG_NO; |
| 402 | } |
| 403 | if (screenLayoutCompatNeeded) { |
| 404 | curLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 405 | } |
| 406 | int curSize = curLayout&SCREENLAYOUT_SIZE_MASK; |
| 407 | if (screenLayoutSize < curSize) { |
| 408 | curLayout = (curLayout&~SCREENLAYOUT_SIZE_MASK) | screenLayoutSize; |
| 409 | } |
| 410 | return curLayout; |
| 411 | } |
| 412 | |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 413 | /** @hide */ |
| 414 | public static String configurationDiffToString(int diff) { |
| 415 | ArrayList<String> list = new ArrayList<>(); |
| 416 | if ((diff & ActivityInfo.CONFIG_MCC) != 0) { |
| 417 | list.add("CONFIG_MCC"); |
| 418 | } |
| 419 | if ((diff & ActivityInfo.CONFIG_MNC) != 0) { |
| 420 | list.add("CONFIG_MNC"); |
| 421 | } |
| 422 | if ((diff & ActivityInfo.CONFIG_LOCALE) != 0) { |
| 423 | list.add("CONFIG_LOCALE"); |
| 424 | } |
| 425 | if ((diff & ActivityInfo.CONFIG_TOUCHSCREEN) != 0) { |
| 426 | list.add("CONFIG_TOUCHSCREEN"); |
| 427 | } |
| 428 | if ((diff & ActivityInfo.CONFIG_KEYBOARD) != 0) { |
| 429 | list.add("CONFIG_KEYBOARD"); |
| 430 | } |
| 431 | if ((diff & ActivityInfo.CONFIG_KEYBOARD_HIDDEN) != 0) { |
| 432 | list.add("CONFIG_KEYBOARD_HIDDEN"); |
| 433 | } |
| 434 | if ((diff & ActivityInfo.CONFIG_NAVIGATION) != 0) { |
| 435 | list.add("CONFIG_NAVIGATION"); |
| 436 | } |
| 437 | if ((diff & ActivityInfo.CONFIG_ORIENTATION) != 0) { |
| 438 | list.add("CONFIG_ORIENTATION"); |
| 439 | } |
| 440 | if ((diff & ActivityInfo.CONFIG_SCREEN_LAYOUT) != 0) { |
| 441 | list.add("CONFIG_SCREEN_LAYOUT"); |
| 442 | } |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 443 | if ((diff & ActivityInfo.CONFIG_COLOR_MODE) != 0) { |
| 444 | list.add("CONFIG_COLOR_MODE"); |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 445 | } |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 446 | if ((diff & ActivityInfo.CONFIG_UI_MODE) != 0) { |
| 447 | list.add("CONFIG_UI_MODE"); |
| 448 | } |
| 449 | if ((diff & ActivityInfo.CONFIG_SCREEN_SIZE) != 0) { |
| 450 | list.add("CONFIG_SCREEN_SIZE"); |
| 451 | } |
| 452 | if ((diff & ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE) != 0) { |
| 453 | list.add("CONFIG_SMALLEST_SCREEN_SIZE"); |
| 454 | } |
| 455 | if ((diff & ActivityInfo.CONFIG_LAYOUT_DIRECTION) != 0) { |
| 456 | list.add("CONFIG_LAYOUT_DIRECTION"); |
| 457 | } |
| 458 | if ((diff & ActivityInfo.CONFIG_FONT_SCALE) != 0) { |
| 459 | list.add("CONFIG_FONT_SCALE"); |
| 460 | } |
Mårten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 461 | if ((diff & ActivityInfo.CONFIG_ASSETS_PATHS) != 0) { |
| 462 | list.add("CONFIG_ASSETS_PATHS"); |
| 463 | } |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 464 | StringBuilder builder = new StringBuilder("{"); |
| 465 | for (int i = 0, n = list.size(); i < n; i++) { |
| 466 | builder.append(list.get(i)); |
| 467 | if (i != n - 1) { |
| 468 | builder.append(", "); |
| 469 | } |
| 470 | } |
| 471 | builder.append("}"); |
| 472 | return builder.toString(); |
| 473 | } |
| 474 | |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 475 | /** |
| 476 | * Check if the Configuration's current {@link #screenLayout} is at |
| 477 | * least the given size. |
| 478 | * |
| 479 | * @param size The desired size, either {@link #SCREENLAYOUT_SIZE_SMALL}, |
| 480 | * {@link #SCREENLAYOUT_SIZE_NORMAL}, {@link #SCREENLAYOUT_SIZE_LARGE}, or |
| 481 | * {@link #SCREENLAYOUT_SIZE_XLARGE}. |
| 482 | * @return Returns true if the current screen layout size is at least |
| 483 | * the given size. |
| 484 | */ |
| 485 | public boolean isLayoutSizeAtLeast(int size) { |
| 486 | int cur = screenLayout&SCREENLAYOUT_SIZE_MASK; |
| 487 | if (cur == SCREENLAYOUT_SIZE_UNDEFINED) return false; |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 488 | return cur >= size; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 489 | } |
| 490 | |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 491 | /** Constant for {@link #touchscreen}: a value indicating that no value has been set. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 492 | public static final int TOUCHSCREEN_UNDEFINED = 0; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 493 | /** Constant for {@link #touchscreen}, value corresponding to the |
| 494 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#TouchscreenQualifier">notouch</a> |
| 495 | * resource qualifier. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | public static final int TOUCHSCREEN_NOTOUCH = 1; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 497 | /** @deprecated Not currently supported or used. */ |
| 498 | @Deprecated public static final int TOUCHSCREEN_STYLUS = 2; |
| 499 | /** Constant for {@link #touchscreen}, value corresponding to the |
| 500 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#TouchscreenQualifier">finger</a> |
| 501 | * resource qualifier. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 502 | public static final int TOUCHSCREEN_FINGER = 3; |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 503 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 504 | /** |
| 505 | * The kind of touch screen attached to the device. |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 506 | * One of: {@link #TOUCHSCREEN_NOTOUCH}, {@link #TOUCHSCREEN_FINGER}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | */ |
| 508 | public int touchscreen; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 509 | |
| 510 | /** Constant for {@link #keyboard}: a value indicating that no value has been set. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 511 | public static final int KEYBOARD_UNDEFINED = 0; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 512 | /** Constant for {@link #keyboard}, value corresponding to the |
| 513 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ImeQualifier">nokeys</a> |
| 514 | * resource qualifier. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | public static final int KEYBOARD_NOKEYS = 1; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 516 | /** Constant for {@link #keyboard}, value corresponding to the |
| 517 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ImeQualifier">qwerty</a> |
| 518 | * resource qualifier. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 519 | public static final int KEYBOARD_QWERTY = 2; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 520 | /** Constant for {@link #keyboard}, value corresponding to the |
| 521 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ImeQualifier">12key</a> |
| 522 | * resource qualifier. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 523 | public static final int KEYBOARD_12KEY = 3; |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 524 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 525 | /** |
| 526 | * The kind of keyboard attached to the device. |
Kenny Root | 507f8ed | 2009-06-09 11:21:11 -0500 | [diff] [blame] | 527 | * One of: {@link #KEYBOARD_NOKEYS}, {@link #KEYBOARD_QWERTY}, |
| 528 | * {@link #KEYBOARD_12KEY}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 529 | */ |
| 530 | public int keyboard; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 531 | |
| 532 | /** Constant for {@link #keyboardHidden}: a value indicating that no value has been set. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 533 | public static final int KEYBOARDHIDDEN_UNDEFINED = 0; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 534 | /** Constant for {@link #keyboardHidden}, value corresponding to the |
| 535 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#KeyboardAvailQualifier">keysexposed</a> |
| 536 | * resource qualifier. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | public static final int KEYBOARDHIDDEN_NO = 1; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 538 | /** Constant for {@link #keyboardHidden}, value corresponding to the |
| 539 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#KeyboardAvailQualifier">keyshidden</a> |
| 540 | * resource qualifier. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 541 | public static final int KEYBOARDHIDDEN_YES = 2; |
| 542 | /** Constant matching actual resource implementation. {@hide} */ |
| 543 | public static final int KEYBOARDHIDDEN_SOFT = 3; |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 544 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 545 | /** |
| 546 | * A flag indicating whether any keyboard is available. Unlike |
| 547 | * {@link #hardKeyboardHidden}, this also takes into account a soft |
| 548 | * keyboard, so if the hard keyboard is hidden but there is soft |
| 549 | * keyboard available, it will be set to NO. Value is one of: |
| 550 | * {@link #KEYBOARDHIDDEN_NO}, {@link #KEYBOARDHIDDEN_YES}. |
| 551 | */ |
| 552 | public int keyboardHidden; |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 553 | |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 554 | /** Constant for {@link #hardKeyboardHidden}: a value indicating that no value has been set. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 555 | public static final int HARDKEYBOARDHIDDEN_UNDEFINED = 0; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 556 | /** Constant for {@link #hardKeyboardHidden}, value corresponding to the |
| 557 | * physical keyboard being exposed. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | public static final int HARDKEYBOARDHIDDEN_NO = 1; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 559 | /** Constant for {@link #hardKeyboardHidden}, value corresponding to the |
| 560 | * physical keyboard being hidden. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | public static final int HARDKEYBOARDHIDDEN_YES = 2; |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 562 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | /** |
| 564 | * A flag indicating whether the hard keyboard has been hidden. This will |
| 565 | * be set on a device with a mechanism to hide the keyboard from the |
| 566 | * user, when that mechanism is closed. One of: |
| 567 | * {@link #HARDKEYBOARDHIDDEN_NO}, {@link #HARDKEYBOARDHIDDEN_YES}. |
| 568 | */ |
| 569 | public int hardKeyboardHidden; |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 570 | |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 571 | /** Constant for {@link #navigation}: a value indicating that no value has been set. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 572 | public static final int NAVIGATION_UNDEFINED = 0; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 573 | /** Constant for {@link #navigation}, value corresponding to the |
| 574 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavigationQualifier">nonav</a> |
| 575 | * resource qualifier. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 576 | public static final int NAVIGATION_NONAV = 1; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 577 | /** Constant for {@link #navigation}, value corresponding to the |
| 578 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavigationQualifier">dpad</a> |
| 579 | * resource qualifier. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 580 | public static final int NAVIGATION_DPAD = 2; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 581 | /** Constant for {@link #navigation}, value corresponding to the |
| 582 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavigationQualifier">trackball</a> |
| 583 | * resource qualifier. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 584 | public static final int NAVIGATION_TRACKBALL = 3; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 585 | /** Constant for {@link #navigation}, value corresponding to the |
| 586 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavigationQualifier">wheel</a> |
| 587 | * resource qualifier. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 588 | public static final int NAVIGATION_WHEEL = 4; |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 589 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 590 | /** |
| 591 | * The kind of navigation method available on the device. |
Kenny Root | 507f8ed | 2009-06-09 11:21:11 -0500 | [diff] [blame] | 592 | * One of: {@link #NAVIGATION_NONAV}, {@link #NAVIGATION_DPAD}, |
| 593 | * {@link #NAVIGATION_TRACKBALL}, {@link #NAVIGATION_WHEEL}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | */ |
| 595 | public int navigation; |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 596 | |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 597 | /** Constant for {@link #navigationHidden}: a value indicating that no value has been set. */ |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 598 | public static final int NAVIGATIONHIDDEN_UNDEFINED = 0; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 599 | /** Constant for {@link #navigationHidden}, value corresponding to the |
| 600 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavAvailQualifier">navexposed</a> |
| 601 | * resource qualifier. */ |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 602 | public static final int NAVIGATIONHIDDEN_NO = 1; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 603 | /** Constant for {@link #navigationHidden}, value corresponding to the |
| 604 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavAvailQualifier">navhidden</a> |
| 605 | * resource qualifier. */ |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 606 | public static final int NAVIGATIONHIDDEN_YES = 2; |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 607 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 608 | /** |
| 609 | * A flag indicating whether any 5-way or DPAD navigation available. |
| 610 | * This will be set on a device with a mechanism to hide the navigation |
| 611 | * controls from the user, when that mechanism is closed. One of: |
| 612 | * {@link #NAVIGATIONHIDDEN_NO}, {@link #NAVIGATIONHIDDEN_YES}. |
| 613 | */ |
| 614 | public int navigationHidden; |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 615 | |
Vadim Caen | 600e490 | 2019-10-17 13:02:24 +0200 | [diff] [blame] | 616 | /** @hide **/ |
| 617 | @IntDef(prefix = {"ORIENTATION_"}, value = { |
| 618 | ORIENTATION_UNDEFINED, |
| 619 | ORIENTATION_PORTRAIT, |
| 620 | ORIENTATION_LANDSCAPE, |
| 621 | ORIENTATION_SQUARE |
| 622 | }) |
| 623 | public @interface Orientation { |
| 624 | } |
| 625 | |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 626 | /** Constant for {@link #orientation}: a value indicating that no value has been set. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 627 | public static final int ORIENTATION_UNDEFINED = 0; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 628 | /** Constant for {@link #orientation}, value corresponding to the |
| 629 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#OrientationQualifier">port</a> |
| 630 | * resource qualifier. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 631 | public static final int ORIENTATION_PORTRAIT = 1; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 632 | /** Constant for {@link #orientation}, value corresponding to the |
| 633 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#OrientationQualifier">land</a> |
| 634 | * resource qualifier. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 635 | public static final int ORIENTATION_LANDSCAPE = 2; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 636 | /** @deprecated Not currently supported or used. */ |
| 637 | @Deprecated public static final int ORIENTATION_SQUARE = 3; |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 638 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 639 | /** |
| 640 | * Overall orientation of the screen. May be one of |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 641 | * {@link #ORIENTATION_LANDSCAPE}, {@link #ORIENTATION_PORTRAIT}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 642 | */ |
Vadim Caen | 600e490 | 2019-10-17 13:02:24 +0200 | [diff] [blame] | 643 | @Orientation |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 644 | public int orientation; |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 645 | |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 646 | /** Constant for {@link #uiMode}: bits that encode the mode type. */ |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 647 | public static final int UI_MODE_TYPE_MASK = 0x0f; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 648 | /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK} |
| 649 | * value indicating that no mode type has been set. */ |
Dianne Hackborn | ef05e07 | 2010-03-01 17:43:39 -0800 | [diff] [blame] | 650 | public static final int UI_MODE_TYPE_UNDEFINED = 0x00; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 651 | /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK} |
| 652 | * value that corresponds to |
| 653 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">no |
| 654 | * UI mode</a> resource qualifier specified. */ |
Dianne Hackborn | ef05e07 | 2010-03-01 17:43:39 -0800 | [diff] [blame] | 655 | public static final int UI_MODE_TYPE_NORMAL = 0x01; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 656 | /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK} |
| 657 | * value that corresponds to the |
| 658 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">desk</a> |
| 659 | * resource qualifier. */ |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 660 | public static final int UI_MODE_TYPE_DESK = 0x02; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 661 | /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK} |
| 662 | * value that corresponds to the |
| 663 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">car</a> |
| 664 | * resource qualifier. */ |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 665 | public static final int UI_MODE_TYPE_CAR = 0x03; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 666 | /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK} |
| 667 | * value that corresponds to the |
| 668 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">television</a> |
| 669 | * resource qualifier. */ |
Dianne Hackborn | e360bb6 | 2011-05-20 16:11:04 -0700 | [diff] [blame] | 670 | public static final int UI_MODE_TYPE_TELEVISION = 0x04; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 671 | /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK} |
| 672 | * value that corresponds to the |
| 673 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">appliance</a> |
| 674 | * resource qualifier. */ |
Joe Onorato | 44fcb83 | 2011-12-14 20:59:30 -0800 | [diff] [blame] | 675 | public static final int UI_MODE_TYPE_APPLIANCE = 0x05; |
John Spurlock | 6c19129 | 2014-04-03 16:37:27 -0400 | [diff] [blame] | 676 | /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK} |
| 677 | * value that corresponds to the |
| 678 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">watch</a> |
| 679 | * resource qualifier. */ |
| 680 | public static final int UI_MODE_TYPE_WATCH = 0x06; |
Zak Cohen | 1a6acdb | 2016-12-12 15:21:21 -0800 | [diff] [blame] | 681 | /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK} |
| 682 | * value that corresponds to the |
| 683 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">vrheadset</a> |
| 684 | * resource qualifier. */ |
| 685 | public static final int UI_MODE_TYPE_VR_HEADSET = 0x07; |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 686 | |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 687 | /** Constant for {@link #uiMode}: bits that encode the night mode. */ |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 688 | public static final int UI_MODE_NIGHT_MASK = 0x30; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 689 | /** Constant for {@link #uiMode}: a {@link #UI_MODE_NIGHT_MASK} |
| 690 | * value indicating that no mode type has been set. */ |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 691 | public static final int UI_MODE_NIGHT_UNDEFINED = 0x00; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 692 | /** Constant for {@link #uiMode}: a {@link #UI_MODE_NIGHT_MASK} |
| 693 | * value that corresponds to the |
| 694 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NightQualifier">notnight</a> |
| 695 | * resource qualifier. */ |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 696 | public static final int UI_MODE_NIGHT_NO = 0x10; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 697 | /** Constant for {@link #uiMode}: a {@link #UI_MODE_NIGHT_MASK} |
| 698 | * value that corresponds to the |
| 699 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NightQualifier">night</a> |
| 700 | * resource qualifier. */ |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 701 | public static final int UI_MODE_NIGHT_YES = 0x20; |
| 702 | |
| 703 | /** |
| 704 | * Bit mask of the ui mode. Currently there are two fields: |
| 705 | * <p>The {@link #UI_MODE_TYPE_MASK} bits define the overall ui mode of the |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 706 | * device. They may be one of {@link #UI_MODE_TYPE_UNDEFINED}, |
| 707 | * {@link #UI_MODE_TYPE_NORMAL}, {@link #UI_MODE_TYPE_DESK}, |
John Spurlock | 6c19129 | 2014-04-03 16:37:27 -0400 | [diff] [blame] | 708 | * {@link #UI_MODE_TYPE_CAR}, {@link #UI_MODE_TYPE_TELEVISION}, |
Zak Cohen | 1a6acdb | 2016-12-12 15:21:21 -0800 | [diff] [blame] | 709 | * {@link #UI_MODE_TYPE_APPLIANCE}, {@link #UI_MODE_TYPE_WATCH}, |
| 710 | * or {@link #UI_MODE_TYPE_VR_HEADSET}. |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 711 | * |
| 712 | * <p>The {@link #UI_MODE_NIGHT_MASK} defines whether the screen |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 713 | * is in a special mode. They may be one of {@link #UI_MODE_NIGHT_UNDEFINED}, |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 714 | * {@link #UI_MODE_NIGHT_NO} or {@link #UI_MODE_NIGHT_YES}. |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 715 | */ |
| 716 | public int uiMode; |
| 717 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 718 | /** |
| 719 | * Default value for {@link #screenWidthDp} indicating that no width |
| 720 | * has been specified. |
| 721 | */ |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 722 | public static final int SCREEN_WIDTH_DP_UNDEFINED = 0; |
| 723 | |
| 724 | /** |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 725 | * The current width of the available screen space, in dp units, |
| 726 | * corresponding to |
| 727 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenWidthQualifier">screen |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 728 | * width</a> resource qualifier. Set to |
| 729 | * {@link #SCREEN_WIDTH_DP_UNDEFINED} if no width is specified. |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 730 | */ |
| 731 | public int screenWidthDp; |
| 732 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 733 | /** |
| 734 | * Default value for {@link #screenHeightDp} indicating that no width |
| 735 | * has been specified. |
| 736 | */ |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 737 | public static final int SCREEN_HEIGHT_DP_UNDEFINED = 0; |
| 738 | |
| 739 | /** |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 740 | * The current height of the available screen space, in dp units, |
| 741 | * corresponding to |
| 742 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenHeightQualifier">screen |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 743 | * height</a> resource qualifier. Set to |
| 744 | * {@link #SCREEN_HEIGHT_DP_UNDEFINED} if no height is specified. |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 745 | */ |
| 746 | public int screenHeightDp; |
| 747 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 748 | /** |
| 749 | * Default value for {@link #smallestScreenWidthDp} indicating that no width |
| 750 | * has been specified. |
| 751 | */ |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 752 | public static final int SMALLEST_SCREEN_WIDTH_DP_UNDEFINED = 0; |
| 753 | |
| 754 | /** |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 755 | * The smallest screen size an application will see in normal operation, |
| 756 | * corresponding to |
| 757 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#SmallestScreenWidthQualifier">smallest |
| 758 | * screen width</a> resource qualifier. |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 759 | * This is the smallest value of both screenWidthDp and screenHeightDp |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 760 | * in both portrait and landscape. Set to |
| 761 | * {@link #SMALLEST_SCREEN_WIDTH_DP_UNDEFINED} if no width is specified. |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 762 | */ |
| 763 | public int smallestScreenWidthDp; |
| 764 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 765 | /** |
| 766 | * Default value for {@link #densityDpi} indicating that no width |
| 767 | * has been specified. |
| 768 | */ |
| 769 | public static final int DENSITY_DPI_UNDEFINED = 0; |
| 770 | |
| 771 | /** |
Adam Lesinski | 31245b4 | 2014-08-22 19:10:56 -0700 | [diff] [blame] | 772 | * Value for {@link #densityDpi} for resources that scale to any density (vector drawables). |
| 773 | * {@hide} |
| 774 | */ |
| 775 | public static final int DENSITY_DPI_ANY = 0xfffe; |
| 776 | |
| 777 | /** |
| 778 | * Value for {@link #densityDpi} for resources that are not meant to be scaled. |
| 779 | * {@hide} |
| 780 | */ |
| 781 | public static final int DENSITY_DPI_NONE = 0xffff; |
| 782 | |
| 783 | /** |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 784 | * The target screen density being rendered to, |
| 785 | * corresponding to |
| 786 | * <a href="{@docRoot}guide/topics/resources/providing-resources.html#DensityQualifier">density</a> |
| 787 | * resource qualifier. Set to |
| 788 | * {@link #DENSITY_DPI_UNDEFINED} if no density is specified. |
| 789 | */ |
| 790 | public int densityDpi; |
| 791 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 792 | /** @hide Hack to get this information from WM to app running in compat mode. */ |
| 793 | public int compatScreenWidthDp; |
| 794 | /** @hide Hack to get this information from WM to app running in compat mode. */ |
| 795 | public int compatScreenHeightDp; |
| 796 | /** @hide Hack to get this information from WM to app running in compat mode. */ |
| 797 | public int compatSmallestScreenWidthDp; |
| 798 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 799 | /** |
Mårten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 800 | * An undefined assetsSeq. This will not override an existing assetsSeq. |
| 801 | * @hide |
| 802 | */ |
| 803 | public static final int ASSETS_SEQ_UNDEFINED = 0; |
| 804 | |
| 805 | /** |
| 806 | * Internal counter that allows us to piggyback off the configuration change mechanism to |
| 807 | * signal to apps that the the assets for an Application have changed. A difference in these |
| 808 | * between two Configurations will yield a diff flag of |
| 809 | * {@link ActivityInfo#CONFIG_ASSETS_PATHS}. |
| 810 | * @hide |
| 811 | */ |
Artur Satayev | f0b7d0b | 2019-11-04 11:16:45 +0000 | [diff] [blame] | 812 | @UnsupportedAppUsage |
Riddle Hsu | e716d72 | 2019-01-09 15:56:46 +0800 | [diff] [blame] | 813 | @TestApi |
Mårten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 814 | public int assetsSeq; |
| 815 | |
| 816 | /** |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 817 | * @hide Internal book-keeping. |
| 818 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 819 | @UnsupportedAppUsage |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 820 | public int seq; |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 821 | |
Alan Viverette | ac85f90 | 2016-03-11 15:15:51 -0500 | [diff] [blame] | 822 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 823 | @IntDef(flag = true, prefix = { "NATIVE_CONFIG_" }, value = { |
| 824 | NATIVE_CONFIG_MCC, |
| 825 | NATIVE_CONFIG_MNC, |
| 826 | NATIVE_CONFIG_LOCALE, |
| 827 | NATIVE_CONFIG_TOUCHSCREEN, |
| 828 | NATIVE_CONFIG_KEYBOARD, |
| 829 | NATIVE_CONFIG_KEYBOARD_HIDDEN, |
| 830 | NATIVE_CONFIG_NAVIGATION, |
| 831 | NATIVE_CONFIG_ORIENTATION, |
| 832 | NATIVE_CONFIG_DENSITY, |
| 833 | NATIVE_CONFIG_SCREEN_SIZE, |
| 834 | NATIVE_CONFIG_VERSION, |
| 835 | NATIVE_CONFIG_SCREEN_LAYOUT, |
| 836 | NATIVE_CONFIG_UI_MODE, |
| 837 | NATIVE_CONFIG_SMALLEST_SCREEN_SIZE, |
| 838 | NATIVE_CONFIG_LAYOUTDIR, |
| 839 | NATIVE_CONFIG_COLOR_MODE, |
| 840 | }) |
Alan Viverette | ac85f90 | 2016-03-11 15:15:51 -0500 | [diff] [blame] | 841 | @Retention(RetentionPolicy.SOURCE) |
| 842 | public @interface NativeConfig {} |
| 843 | |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 844 | /** @hide Native-specific bit mask for MCC config; DO NOT USE UNLESS YOU ARE SURE. */ |
| 845 | public static final int NATIVE_CONFIG_MCC = 0x0001; |
| 846 | /** @hide Native-specific bit mask for MNC config; DO NOT USE UNLESS YOU ARE SURE. */ |
| 847 | public static final int NATIVE_CONFIG_MNC = 0x0002; |
| 848 | /** @hide Native-specific bit mask for LOCALE config; DO NOT USE UNLESS YOU ARE SURE. */ |
| 849 | public static final int NATIVE_CONFIG_LOCALE = 0x0004; |
| 850 | /** @hide Native-specific bit mask for TOUCHSCREEN config; DO NOT USE UNLESS YOU ARE SURE. */ |
| 851 | public static final int NATIVE_CONFIG_TOUCHSCREEN = 0x0008; |
| 852 | /** @hide Native-specific bit mask for KEYBOARD config; DO NOT USE UNLESS YOU ARE SURE. */ |
| 853 | public static final int NATIVE_CONFIG_KEYBOARD = 0x0010; |
| 854 | /** @hide Native-specific bit mask for KEYBOARD_HIDDEN config; DO NOT USE UNLESS YOU |
| 855 | * ARE SURE. */ |
| 856 | public static final int NATIVE_CONFIG_KEYBOARD_HIDDEN = 0x0020; |
| 857 | /** @hide Native-specific bit mask for NAVIGATION config; DO NOT USE UNLESS YOU ARE SURE. */ |
| 858 | public static final int NATIVE_CONFIG_NAVIGATION = 0x0040; |
| 859 | /** @hide Native-specific bit mask for ORIENTATION config; DO NOT USE UNLESS YOU ARE SURE. */ |
| 860 | public static final int NATIVE_CONFIG_ORIENTATION = 0x0080; |
| 861 | /** @hide Native-specific bit mask for DENSITY config; DO NOT USE UNLESS YOU ARE SURE. */ |
| 862 | public static final int NATIVE_CONFIG_DENSITY = 0x0100; |
| 863 | /** @hide Native-specific bit mask for SCREEN_SIZE config; DO NOT USE UNLESS YOU ARE SURE. */ |
| 864 | public static final int NATIVE_CONFIG_SCREEN_SIZE = 0x0200; |
| 865 | /** @hide Native-specific bit mask for VERSION config; DO NOT USE UNLESS YOU ARE SURE. */ |
| 866 | public static final int NATIVE_CONFIG_VERSION = 0x0400; |
| 867 | /** @hide Native-specific bit mask for SCREEN_LAYOUT config; DO NOT USE UNLESS YOU ARE SURE. */ |
| 868 | public static final int NATIVE_CONFIG_SCREEN_LAYOUT = 0x0800; |
| 869 | /** @hide Native-specific bit mask for UI_MODE config; DO NOT USE UNLESS YOU ARE SURE. */ |
| 870 | public static final int NATIVE_CONFIG_UI_MODE = 0x1000; |
| 871 | /** @hide Native-specific bit mask for SMALLEST_SCREEN_SIZE config; DO NOT USE UNLESS YOU |
| 872 | * ARE SURE. */ |
| 873 | public static final int NATIVE_CONFIG_SMALLEST_SCREEN_SIZE = 0x2000; |
| 874 | /** @hide Native-specific bit mask for LAYOUTDIR config ; DO NOT USE UNLESS YOU ARE SURE.*/ |
| 875 | public static final int NATIVE_CONFIG_LAYOUTDIR = 0x4000; |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 876 | /** @hide Native-specific bit mask for COLOR_MODE config ; DO NOT USE UNLESS YOU ARE SURE.*/ |
| 877 | public static final int NATIVE_CONFIG_COLOR_MODE = 0x10000; |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 878 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 879 | /** |
Adam Lesinski | bad43fc | 2016-07-19 13:35:01 -0700 | [diff] [blame] | 880 | * <p>Construct an invalid Configuration. This state is only suitable for constructing a |
| 881 | * Configuration delta that will be applied to some valid Configuration object. In order to |
| 882 | * create a valid standalone Configuration, you must call {@link #setToDefaults}. </p> |
| 883 | * |
| 884 | * <p>Example:</p> |
| 885 | * <pre class="prettyprint"> |
| 886 | * Configuration validConfig = new Configuration(); |
| 887 | * validConfig.setToDefaults(); |
| 888 | * |
| 889 | * Configuration deltaOnlyConfig = new Configuration(); |
| 890 | * deltaOnlyConfig.orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 891 | * |
| 892 | * validConfig.updateFrom(deltaOnlyConfig); |
| 893 | * </pre> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 894 | */ |
| 895 | public Configuration() { |
Adam Lesinski | bad43fc | 2016-07-19 13:35:01 -0700 | [diff] [blame] | 896 | unset(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | /** |
| 900 | * Makes a deep copy suitable for modification. |
| 901 | */ |
| 902 | public Configuration(Configuration o) { |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 903 | setTo(o); |
| 904 | } |
| 905 | |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 906 | /* This brings mLocaleList in sync with locale in case a user of the older API who doesn't know |
| 907 | * about setLocales() has changed locale directly. */ |
| 908 | private void fixUpLocaleList() { |
| 909 | if ((locale == null && !mLocaleList.isEmpty()) || |
Roozbeh Pournader | fee4484 | 2016-02-04 15:24:24 -0800 | [diff] [blame] | 910 | (locale != null && !locale.equals(mLocaleList.get(0)))) { |
Raph Levien | 10ea92a | 2016-05-02 12:56:01 -0700 | [diff] [blame] | 911 | mLocaleList = locale == null ? LocaleList.getEmptyLocaleList() : new LocaleList(locale); |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 912 | } |
| 913 | } |
| 914 | |
Chet Haase | d30149e | 2017-01-13 12:55:16 -0800 | [diff] [blame] | 915 | /** |
| 916 | * Sets the fields in this object to those in the given Configuration. |
| 917 | * |
| 918 | * @param o The Configuration object used to set the values of this Configuration's fields. |
| 919 | */ |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 920 | public void setTo(Configuration o) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 921 | fontScale = o.fontScale; |
| 922 | mcc = o.mcc; |
| 923 | mnc = o.mnc; |
Roozbeh Pournader | 8a412e0 | 2015-12-02 18:39:50 -0800 | [diff] [blame] | 924 | locale = o.locale == null ? null : (Locale) o.locale.clone(); |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 925 | o.fixUpLocaleList(); |
| 926 | mLocaleList = o.mLocaleList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 927 | userSetLocale = o.userSetLocale; |
| 928 | touchscreen = o.touchscreen; |
| 929 | keyboard = o.keyboard; |
| 930 | keyboardHidden = o.keyboardHidden; |
| 931 | hardKeyboardHidden = o.hardKeyboardHidden; |
| 932 | navigation = o.navigation; |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 933 | navigationHidden = o.navigationHidden; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 934 | orientation = o.orientation; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 935 | screenLayout = o.screenLayout; |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 936 | colorMode = o.colorMode; |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 937 | uiMode = o.uiMode; |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 938 | screenWidthDp = o.screenWidthDp; |
| 939 | screenHeightDp = o.screenHeightDp; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 940 | smallestScreenWidthDp = o.smallestScreenWidthDp; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 941 | densityDpi = o.densityDpi; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 942 | compatScreenWidthDp = o.compatScreenWidthDp; |
| 943 | compatScreenHeightDp = o.compatScreenHeightDp; |
| 944 | compatSmallestScreenWidthDp = o.compatSmallestScreenWidthDp; |
Mårten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 945 | assetsSeq = o.assetsSeq; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 946 | seq = o.seq; |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 947 | windowConfiguration.setTo(o.windowConfiguration); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 948 | } |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 949 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 950 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 951 | StringBuilder sb = new StringBuilder(128); |
Dianne Hackborn | 2973568 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 952 | sb.append("{"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 953 | sb.append(fontScale); |
Dianne Hackborn | 5be8de3 | 2011-05-24 18:11:57 -0700 | [diff] [blame] | 954 | sb.append(" "); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 955 | if (mcc != 0) { |
| 956 | sb.append(mcc); |
| 957 | sb.append("mcc"); |
| 958 | } else { |
| 959 | sb.append("?mcc"); |
| 960 | } |
| 961 | if (mnc != 0) { |
| 962 | sb.append(mnc); |
| 963 | sb.append("mnc"); |
| 964 | } else { |
| 965 | sb.append("?mnc"); |
| 966 | } |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 967 | fixUpLocaleList(); |
| 968 | if (!mLocaleList.isEmpty()) { |
Dianne Hackborn | 9a84983 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 969 | sb.append(" "); |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 970 | sb.append(mLocaleList); |
Dianne Hackborn | 9a84983 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 971 | } else { |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 972 | sb.append(" ?localeList"); |
Daniel Sandler | 7d6bddc | 2010-07-22 16:11:55 -0400 | [diff] [blame] | 973 | } |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 974 | int layoutDir = (screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK); |
| 975 | switch (layoutDir) { |
| 976 | case SCREENLAYOUT_LAYOUTDIR_UNDEFINED: sb.append(" ?layoutDir"); break; |
Fabrice Di Meglio | 8a802db | 2012-09-05 13:12:02 -0700 | [diff] [blame] | 977 | case SCREENLAYOUT_LAYOUTDIR_LTR: sb.append(" ldltr"); break; |
| 978 | case SCREENLAYOUT_LAYOUTDIR_RTL: sb.append(" ldrtl"); break; |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 979 | default: sb.append(" layoutDir="); |
| 980 | sb.append(layoutDir >> SCREENLAYOUT_LAYOUTDIR_SHIFT); break; |
Fabrice Di Meglio | 7a736fb | 2011-06-09 20:20:36 -0700 | [diff] [blame] | 981 | } |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 982 | if (smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) { |
| 983 | sb.append(" sw"); sb.append(smallestScreenWidthDp); sb.append("dp"); |
| 984 | } else { |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 985 | sb.append(" ?swdp"); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 986 | } |
| 987 | if (screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED) { |
| 988 | sb.append(" w"); sb.append(screenWidthDp); sb.append("dp"); |
| 989 | } else { |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 990 | sb.append(" ?wdp"); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 991 | } |
| 992 | if (screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED) { |
| 993 | sb.append(" h"); sb.append(screenHeightDp); sb.append("dp"); |
| 994 | } else { |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 995 | sb.append(" ?hdp"); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 996 | } |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 997 | if (densityDpi != DENSITY_DPI_UNDEFINED) { |
| 998 | sb.append(" "); sb.append(densityDpi); sb.append("dpi"); |
| 999 | } else { |
| 1000 | sb.append(" ?density"); |
| 1001 | } |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1002 | switch ((screenLayout&SCREENLAYOUT_SIZE_MASK)) { |
| 1003 | case SCREENLAYOUT_SIZE_UNDEFINED: sb.append(" ?lsize"); break; |
| 1004 | case SCREENLAYOUT_SIZE_SMALL: sb.append(" smll"); break; |
| 1005 | case SCREENLAYOUT_SIZE_NORMAL: sb.append(" nrml"); break; |
| 1006 | case SCREENLAYOUT_SIZE_LARGE: sb.append(" lrg"); break; |
| 1007 | case SCREENLAYOUT_SIZE_XLARGE: sb.append(" xlrg"); break; |
| 1008 | default: sb.append(" layoutSize="); |
| 1009 | sb.append(screenLayout&SCREENLAYOUT_SIZE_MASK); break; |
| 1010 | } |
| 1011 | switch ((screenLayout&SCREENLAYOUT_LONG_MASK)) { |
| 1012 | case SCREENLAYOUT_LONG_UNDEFINED: sb.append(" ?long"); break; |
| 1013 | case SCREENLAYOUT_LONG_NO: /* not-long is not interesting to print */ break; |
| 1014 | case SCREENLAYOUT_LONG_YES: sb.append(" long"); break; |
| 1015 | default: sb.append(" layoutLong="); |
| 1016 | sb.append(screenLayout&SCREENLAYOUT_LONG_MASK); break; |
| 1017 | } |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 1018 | switch ((colorMode &COLOR_MODE_HDR_MASK)) { |
| 1019 | case COLOR_MODE_HDR_UNDEFINED: sb.append(" ?ldr"); break; // most likely not HDR |
| 1020 | case COLOR_MODE_HDR_NO: /* ldr is not interesting to print */ break; |
| 1021 | case COLOR_MODE_HDR_YES: sb.append(" hdr"); break; |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 1022 | default: sb.append(" dynamicRange="); |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 1023 | sb.append(colorMode &COLOR_MODE_HDR_MASK); break; |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 1024 | } |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 1025 | switch ((colorMode &COLOR_MODE_WIDE_COLOR_GAMUT_MASK)) { |
| 1026 | case COLOR_MODE_WIDE_COLOR_GAMUT_UNDEFINED: sb.append(" ?wideColorGamut"); break; |
| 1027 | case COLOR_MODE_WIDE_COLOR_GAMUT_NO: /* not wide is not interesting to print */ break; |
| 1028 | case COLOR_MODE_WIDE_COLOR_GAMUT_YES: sb.append(" widecg"); break; |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 1029 | default: sb.append(" wideColorGamut="); |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 1030 | sb.append(colorMode &COLOR_MODE_WIDE_COLOR_GAMUT_MASK); break; |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 1031 | } |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1032 | switch (orientation) { |
| 1033 | case ORIENTATION_UNDEFINED: sb.append(" ?orien"); break; |
| 1034 | case ORIENTATION_LANDSCAPE: sb.append(" land"); break; |
| 1035 | case ORIENTATION_PORTRAIT: sb.append(" port"); break; |
| 1036 | default: sb.append(" orien="); sb.append(orientation); break; |
| 1037 | } |
| 1038 | switch ((uiMode&UI_MODE_TYPE_MASK)) { |
| 1039 | case UI_MODE_TYPE_UNDEFINED: sb.append(" ?uimode"); break; |
| 1040 | case UI_MODE_TYPE_NORMAL: /* normal is not interesting to print */ break; |
| 1041 | case UI_MODE_TYPE_DESK: sb.append(" desk"); break; |
| 1042 | case UI_MODE_TYPE_CAR: sb.append(" car"); break; |
Dianne Hackborn | e360bb6 | 2011-05-20 16:11:04 -0700 | [diff] [blame] | 1043 | case UI_MODE_TYPE_TELEVISION: sb.append(" television"); break; |
Joe Onorato | 44fcb83 | 2011-12-14 20:59:30 -0800 | [diff] [blame] | 1044 | case UI_MODE_TYPE_APPLIANCE: sb.append(" appliance"); break; |
John Spurlock | 6c19129 | 2014-04-03 16:37:27 -0400 | [diff] [blame] | 1045 | case UI_MODE_TYPE_WATCH: sb.append(" watch"); break; |
Zak Cohen | 1a6acdb | 2016-12-12 15:21:21 -0800 | [diff] [blame] | 1046 | case UI_MODE_TYPE_VR_HEADSET: sb.append(" vrheadset"); break; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1047 | default: sb.append(" uimode="); sb.append(uiMode&UI_MODE_TYPE_MASK); break; |
| 1048 | } |
| 1049 | switch ((uiMode&UI_MODE_NIGHT_MASK)) { |
| 1050 | case UI_MODE_NIGHT_UNDEFINED: sb.append(" ?night"); break; |
| 1051 | case UI_MODE_NIGHT_NO: /* not-night is not interesting to print */ break; |
| 1052 | case UI_MODE_NIGHT_YES: sb.append(" night"); break; |
| 1053 | default: sb.append(" night="); sb.append(uiMode&UI_MODE_NIGHT_MASK); break; |
| 1054 | } |
Dianne Hackborn | 9a84983 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1055 | switch (touchscreen) { |
| 1056 | case TOUCHSCREEN_UNDEFINED: sb.append(" ?touch"); break; |
| 1057 | case TOUCHSCREEN_NOTOUCH: sb.append(" -touch"); break; |
| 1058 | case TOUCHSCREEN_STYLUS: sb.append(" stylus"); break; |
| 1059 | case TOUCHSCREEN_FINGER: sb.append(" finger"); break; |
| 1060 | default: sb.append(" touch="); sb.append(touchscreen); break; |
| 1061 | } |
| 1062 | switch (keyboard) { |
| 1063 | case KEYBOARD_UNDEFINED: sb.append(" ?keyb"); break; |
| 1064 | case KEYBOARD_NOKEYS: sb.append(" -keyb"); break; |
| 1065 | case KEYBOARD_QWERTY: sb.append(" qwerty"); break; |
| 1066 | case KEYBOARD_12KEY: sb.append(" 12key"); break; |
| 1067 | default: sb.append(" keys="); sb.append(keyboard); break; |
| 1068 | } |
| 1069 | switch (keyboardHidden) { |
| 1070 | case KEYBOARDHIDDEN_UNDEFINED: sb.append("/?"); break; |
| 1071 | case KEYBOARDHIDDEN_NO: sb.append("/v"); break; |
| 1072 | case KEYBOARDHIDDEN_YES: sb.append("/h"); break; |
| 1073 | case KEYBOARDHIDDEN_SOFT: sb.append("/s"); break; |
| 1074 | default: sb.append("/"); sb.append(keyboardHidden); break; |
| 1075 | } |
| 1076 | switch (hardKeyboardHidden) { |
| 1077 | case HARDKEYBOARDHIDDEN_UNDEFINED: sb.append("/?"); break; |
| 1078 | case HARDKEYBOARDHIDDEN_NO: sb.append("/v"); break; |
| 1079 | case HARDKEYBOARDHIDDEN_YES: sb.append("/h"); break; |
| 1080 | default: sb.append("/"); sb.append(hardKeyboardHidden); break; |
| 1081 | } |
| 1082 | switch (navigation) { |
| 1083 | case NAVIGATION_UNDEFINED: sb.append(" ?nav"); break; |
| 1084 | case NAVIGATION_NONAV: sb.append(" -nav"); break; |
| 1085 | case NAVIGATION_DPAD: sb.append(" dpad"); break; |
| 1086 | case NAVIGATION_TRACKBALL: sb.append(" tball"); break; |
| 1087 | case NAVIGATION_WHEEL: sb.append(" wheel"); break; |
| 1088 | default: sb.append(" nav="); sb.append(navigation); break; |
| 1089 | } |
| 1090 | switch (navigationHidden) { |
| 1091 | case NAVIGATIONHIDDEN_UNDEFINED: sb.append("/?"); break; |
| 1092 | case NAVIGATIONHIDDEN_NO: sb.append("/v"); break; |
| 1093 | case NAVIGATIONHIDDEN_YES: sb.append("/h"); break; |
| 1094 | default: sb.append("/"); sb.append(navigationHidden); break; |
| 1095 | } |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 1096 | sb.append(" winConfig="); sb.append(windowConfiguration); |
Mårten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1097 | if (assetsSeq != 0) { |
| 1098 | sb.append(" as.").append(assetsSeq); |
| 1099 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1100 | if (seq != 0) { |
Mårten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1101 | sb.append(" s.").append(seq); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1102 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1103 | sb.append('}'); |
| 1104 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | /** |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 1108 | * Write to a protocol buffer output stream. |
| 1109 | * Protocol buffer message definition at {@link android.content.ConfigurationProto} |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 1110 | * Has the option to ignore fields that don't need to be persisted to disk. |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 1111 | * |
| 1112 | * @param protoOutputStream Stream to write the Configuration object to. |
| 1113 | * @param fieldId Field Id of the Configuration as defined in the parent message |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 1114 | * @param persisted Note if this proto will be persisted to disk |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 1115 | * @param critical If true, reduce amount of data written. |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 1116 | * @hide |
| 1117 | */ |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 1118 | public void dumpDebug(ProtoOutputStream protoOutputStream, long fieldId, boolean persisted, |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 1119 | boolean critical) { |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 1120 | final long token = protoOutputStream.start(fieldId); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 1121 | if (!critical) { |
| 1122 | protoOutputStream.write(FONT_SCALE, fontScale); |
| 1123 | protoOutputStream.write(MCC, mcc); |
| 1124 | protoOutputStream.write(MNC, mnc); |
| 1125 | if (mLocaleList != null) { |
Varun Shah | bd0ce4d | 2019-09-10 15:51:37 -0400 | [diff] [blame] | 1126 | protoOutputStream.write(LOCALE_LIST, mLocaleList.toLanguageTags()); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 1127 | } |
| 1128 | protoOutputStream.write(SCREEN_LAYOUT, screenLayout); |
| 1129 | protoOutputStream.write(COLOR_MODE, colorMode); |
| 1130 | protoOutputStream.write(TOUCHSCREEN, touchscreen); |
| 1131 | protoOutputStream.write(KEYBOARD, keyboard); |
| 1132 | protoOutputStream.write(KEYBOARD_HIDDEN, keyboardHidden); |
| 1133 | protoOutputStream.write(HARD_KEYBOARD_HIDDEN, hardKeyboardHidden); |
| 1134 | protoOutputStream.write(NAVIGATION, navigation); |
| 1135 | protoOutputStream.write(NAVIGATION_HIDDEN, navigationHidden); |
| 1136 | protoOutputStream.write(UI_MODE, uiMode); |
| 1137 | protoOutputStream.write(SMALLEST_SCREEN_WIDTH_DP, smallestScreenWidthDp); |
| 1138 | protoOutputStream.write(DENSITY_DPI, densityDpi); |
| 1139 | // For persistence, we do not care about window configuration |
| 1140 | if (!persisted && windowConfiguration != null) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 1141 | windowConfiguration.dumpDebug(protoOutputStream, WINDOW_CONFIGURATION); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 1142 | } |
Kweku Adams | 15afdeb | 2018-09-04 11:54:46 -0700 | [diff] [blame] | 1143 | } |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 1144 | protoOutputStream.write(ORIENTATION, orientation); |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 1145 | protoOutputStream.write(SCREEN_WIDTH_DP, screenWidthDp); |
| 1146 | protoOutputStream.write(SCREEN_HEIGHT_DP, screenHeightDp); |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 1147 | protoOutputStream.end(token); |
| 1148 | } |
| 1149 | |
| 1150 | /** |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 1151 | * Write to a protocol buffer output stream. |
| 1152 | * Protocol buffer message definition at {@link android.content.ConfigurationProto} |
| 1153 | * |
| 1154 | * @param protoOutputStream Stream to write the Configuration object to. |
| 1155 | * @param fieldId Field Id of the Configuration as defined in the parent message |
| 1156 | * @hide |
| 1157 | */ |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 1158 | public void dumpDebug(ProtoOutputStream protoOutputStream, long fieldId) { |
| 1159 | dumpDebug(protoOutputStream, fieldId, false /* persisted */, false /* critical */); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | /** |
| 1163 | * Write to a protocol buffer output stream. |
| 1164 | * Protocol buffer message definition at {@link android.content.ConfigurationProto} |
| 1165 | * |
| 1166 | * @param protoOutputStream Stream to write the Configuration object to. |
| 1167 | * @param fieldId Field Id of the Configuration as defined in the parent message |
| 1168 | * @param critical If true, reduce amount of data written. |
| 1169 | * @hide |
| 1170 | */ |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 1171 | public void dumpDebug(ProtoOutputStream protoOutputStream, long fieldId, boolean critical) { |
| 1172 | dumpDebug(protoOutputStream, fieldId, false /* persisted */, critical); |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | /** |
| 1176 | * Read from a protocol buffer output stream. |
| 1177 | * Protocol buffer message definition at {@link android.content.ConfigurationProto} |
| 1178 | * |
| 1179 | * @param protoInputStream Stream to read the Configuration object from. |
| 1180 | * @param fieldId Field Id of the Configuration as defined in the parent message |
| 1181 | * @hide |
| 1182 | */ |
| 1183 | public void readFromProto(ProtoInputStream protoInputStream, long fieldId) throws IOException { |
| 1184 | final long token = protoInputStream.start(fieldId); |
| 1185 | final List<Locale> list = new ArrayList(); |
| 1186 | try { |
| 1187 | while (protoInputStream.nextField() != ProtoInputStream.NO_MORE_FIELDS) { |
| 1188 | switch (protoInputStream.getFieldNumber()) { |
| 1189 | case (int) FONT_SCALE: |
| 1190 | fontScale = protoInputStream.readFloat(FONT_SCALE); |
| 1191 | break; |
| 1192 | case (int) MCC: |
| 1193 | mcc = protoInputStream.readInt(MCC); |
| 1194 | break; |
| 1195 | case (int) MNC: |
| 1196 | mnc = protoInputStream.readInt(MNC); |
| 1197 | break; |
| 1198 | case (int) LOCALES: |
| 1199 | // Parse the Locale here to handle all the repeated Locales |
| 1200 | // The LocaleList will be created when the message is completed |
| 1201 | final long localeToken = protoInputStream.start(LOCALES); |
| 1202 | String language = ""; |
| 1203 | String country = ""; |
| 1204 | String variant = ""; |
Varun Shah | 95fabaf | 2019-05-01 12:45:37 -0700 | [diff] [blame] | 1205 | String script = ""; |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 1206 | try { |
| 1207 | while (protoInputStream.nextField() |
| 1208 | != ProtoInputStream.NO_MORE_FIELDS) { |
| 1209 | switch (protoInputStream.getFieldNumber()) { |
| 1210 | case (int) LocaleProto.LANGUAGE: |
| 1211 | language = protoInputStream.readString( |
| 1212 | LocaleProto.LANGUAGE); |
| 1213 | break; |
| 1214 | case (int) LocaleProto.COUNTRY: |
| 1215 | country = protoInputStream.readString(LocaleProto.COUNTRY); |
| 1216 | break; |
| 1217 | case (int) LocaleProto.VARIANT: |
| 1218 | variant = protoInputStream.readString(LocaleProto.VARIANT); |
| 1219 | break; |
Varun Shah | 95fabaf | 2019-05-01 12:45:37 -0700 | [diff] [blame] | 1220 | case (int) LocaleProto.SCRIPT: |
| 1221 | script = protoInputStream.readString(LocaleProto.SCRIPT); |
| 1222 | break; |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 1223 | } |
| 1224 | } |
| 1225 | } catch (WireTypeMismatchException wtme) { |
| 1226 | // rethrow for caller deal with |
| 1227 | throw wtme; |
| 1228 | } finally { |
| 1229 | protoInputStream.end(localeToken); |
Varun Shah | 95fabaf | 2019-05-01 12:45:37 -0700 | [diff] [blame] | 1230 | try { |
| 1231 | final Locale locale = new Locale.Builder() |
| 1232 | .setLanguage(language) |
| 1233 | .setRegion(country) |
| 1234 | .setVariant(variant) |
| 1235 | .setScript(script) |
| 1236 | .build(); |
Varun Shah | 5d9031d | 2019-09-04 12:04:02 -0700 | [diff] [blame] | 1237 | // Log a WTF here if a repeated locale is found to avoid throwing an |
| 1238 | // exception in system server when LocaleList is created below |
| 1239 | final int inListIndex = list.indexOf(locale); |
| 1240 | if (inListIndex != -1) { |
| 1241 | Slog.wtf(TAG, "Repeated locale (" + list.get(inListIndex) + ")" |
| 1242 | + " found when trying to add: " + locale.toString()); |
| 1243 | } else { |
| 1244 | list.add(locale); |
| 1245 | } |
Varun Shah | 95fabaf | 2019-05-01 12:45:37 -0700 | [diff] [blame] | 1246 | } catch (IllformedLocaleException e) { |
| 1247 | Slog.e(TAG, "readFromProto error building locale with: " |
| 1248 | + "language-" + language + ";country-" + country |
| 1249 | + ";variant-" + variant + ";script-" + script); |
| 1250 | } |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 1251 | } |
| 1252 | break; |
| 1253 | case (int) SCREEN_LAYOUT: |
| 1254 | screenLayout = protoInputStream.readInt(SCREEN_LAYOUT); |
| 1255 | break; |
| 1256 | case (int) COLOR_MODE: |
| 1257 | colorMode = protoInputStream.readInt(COLOR_MODE); |
| 1258 | break; |
| 1259 | case (int) TOUCHSCREEN: |
| 1260 | touchscreen = protoInputStream.readInt(TOUCHSCREEN); |
| 1261 | break; |
| 1262 | case (int) KEYBOARD: |
| 1263 | keyboard = protoInputStream.readInt(KEYBOARD); |
| 1264 | break; |
| 1265 | case (int) KEYBOARD_HIDDEN: |
| 1266 | keyboardHidden = protoInputStream.readInt(KEYBOARD_HIDDEN); |
| 1267 | break; |
| 1268 | case (int) HARD_KEYBOARD_HIDDEN: |
| 1269 | hardKeyboardHidden = protoInputStream.readInt(HARD_KEYBOARD_HIDDEN); |
| 1270 | break; |
| 1271 | case (int) NAVIGATION: |
| 1272 | navigation = protoInputStream.readInt(NAVIGATION); |
| 1273 | break; |
| 1274 | case (int) NAVIGATION_HIDDEN: |
| 1275 | navigationHidden = protoInputStream.readInt(NAVIGATION_HIDDEN); |
| 1276 | break; |
| 1277 | case (int) ORIENTATION: |
| 1278 | orientation = protoInputStream.readInt(ORIENTATION); |
| 1279 | break; |
| 1280 | case (int) UI_MODE: |
| 1281 | uiMode = protoInputStream.readInt(UI_MODE); |
| 1282 | break; |
| 1283 | case (int) SCREEN_WIDTH_DP: |
| 1284 | screenWidthDp = protoInputStream.readInt(SCREEN_WIDTH_DP); |
| 1285 | break; |
| 1286 | case (int) SCREEN_HEIGHT_DP: |
| 1287 | screenHeightDp = protoInputStream.readInt(SCREEN_HEIGHT_DP); |
| 1288 | break; |
| 1289 | case (int) SMALLEST_SCREEN_WIDTH_DP: |
| 1290 | smallestScreenWidthDp = protoInputStream.readInt(SMALLEST_SCREEN_WIDTH_DP); |
| 1291 | break; |
| 1292 | case (int) DENSITY_DPI: |
| 1293 | densityDpi = protoInputStream.readInt(DENSITY_DPI); |
| 1294 | break; |
| 1295 | case (int) WINDOW_CONFIGURATION: |
| 1296 | windowConfiguration.readFromProto(protoInputStream, WINDOW_CONFIGURATION); |
| 1297 | break; |
Varun Shah | bd0ce4d | 2019-09-10 15:51:37 -0400 | [diff] [blame] | 1298 | case (int) LOCALE_LIST: |
| 1299 | try { |
| 1300 | setLocales(LocaleList.forLanguageTags(protoInputStream.readString( |
| 1301 | LOCALE_LIST))); |
| 1302 | } catch (Exception e) { |
| 1303 | Slog.e(TAG, "error parsing locale list in configuration.", e); |
| 1304 | } |
| 1305 | break; |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 1306 | } |
| 1307 | } |
| 1308 | } finally { |
| 1309 | // Let caller handle any exceptions |
| 1310 | if (list.size() > 0) { |
| 1311 | //Create the LocaleList from the collected Locales |
| 1312 | setLocales(new LocaleList(list.toArray(new Locale[list.size()]))); |
| 1313 | } |
| 1314 | protoInputStream.end(token); |
| 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | /** |
Dianne Hackborn | bf5ba6b | 2018-02-20 10:31:02 -0800 | [diff] [blame] | 1319 | * Write full {@link android.content.ResourcesConfigurationProto} to protocol buffer output |
| 1320 | * stream. |
| 1321 | * |
| 1322 | * @param protoOutputStream Stream to write the Configuration object to. |
| 1323 | * @param fieldId Field Id of the Configuration as defined in the parent message |
| 1324 | * @param metrics Current display information |
| 1325 | * @hide |
| 1326 | */ |
| 1327 | public void writeResConfigToProto(ProtoOutputStream protoOutputStream, long fieldId, |
| 1328 | DisplayMetrics metrics) { |
| 1329 | final int width, height; |
| 1330 | if (metrics.widthPixels >= metrics.heightPixels) { |
| 1331 | width = metrics.widthPixels; |
| 1332 | height = metrics.heightPixels; |
| 1333 | } else { |
| 1334 | //noinspection SuspiciousNameCombination |
| 1335 | width = metrics.heightPixels; |
| 1336 | //noinspection SuspiciousNameCombination |
| 1337 | height = metrics.widthPixels; |
| 1338 | } |
| 1339 | |
| 1340 | final long token = protoOutputStream.start(fieldId); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 1341 | dumpDebug(protoOutputStream, CONFIGURATION); |
Dianne Hackborn | bf5ba6b | 2018-02-20 10:31:02 -0800 | [diff] [blame] | 1342 | protoOutputStream.write(SDK_VERSION, Build.VERSION.RESOURCES_SDK_INT); |
| 1343 | protoOutputStream.write(SCREEN_WIDTH_PX, width); |
| 1344 | protoOutputStream.write(SCREEN_HEIGHT_PX, height); |
| 1345 | protoOutputStream.end(token); |
| 1346 | } |
| 1347 | |
| 1348 | /** |
Michael Wright | 1985976 | 2017-09-18 20:57:58 +0100 | [diff] [blame] | 1349 | * Convert the UI mode to a human readable format. |
| 1350 | * @hide |
| 1351 | */ |
| 1352 | public static String uiModeToString(int uiMode) { |
| 1353 | switch (uiMode) { |
| 1354 | case UI_MODE_TYPE_UNDEFINED: |
| 1355 | return "UI_MODE_TYPE_UNDEFINED"; |
| 1356 | case UI_MODE_TYPE_NORMAL: |
| 1357 | return "UI_MODE_TYPE_NORMAL"; |
| 1358 | case UI_MODE_TYPE_DESK: |
| 1359 | return "UI_MODE_TYPE_DESK"; |
| 1360 | case UI_MODE_TYPE_CAR: |
| 1361 | return "UI_MODE_TYPE_CAR"; |
| 1362 | case UI_MODE_TYPE_TELEVISION: |
| 1363 | return "UI_MODE_TYPE_TELEVISION"; |
| 1364 | case UI_MODE_TYPE_APPLIANCE: |
| 1365 | return "UI_MODE_TYPE_APPLIANCE"; |
| 1366 | case UI_MODE_TYPE_WATCH: |
| 1367 | return "UI_MODE_TYPE_WATCH"; |
| 1368 | case UI_MODE_TYPE_VR_HEADSET: |
| 1369 | return "UI_MODE_TYPE_VR_HEADSET"; |
| 1370 | default: |
| 1371 | return Integer.toString(uiMode); |
| 1372 | } |
| 1373 | } |
| 1374 | |
| 1375 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1376 | * Set this object to the system defaults. |
| 1377 | */ |
| 1378 | public void setToDefaults() { |
| 1379 | fontScale = 1; |
| 1380 | mcc = mnc = 0; |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 1381 | mLocaleList = LocaleList.getEmptyLocaleList(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1382 | locale = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1383 | userSetLocale = false; |
| 1384 | touchscreen = TOUCHSCREEN_UNDEFINED; |
| 1385 | keyboard = KEYBOARD_UNDEFINED; |
| 1386 | keyboardHidden = KEYBOARDHIDDEN_UNDEFINED; |
| 1387 | hardKeyboardHidden = HARDKEYBOARDHIDDEN_UNDEFINED; |
| 1388 | navigation = NAVIGATION_UNDEFINED; |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 1389 | navigationHidden = NAVIGATIONHIDDEN_UNDEFINED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1390 | orientation = ORIENTATION_UNDEFINED; |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 1391 | screenLayout = SCREENLAYOUT_UNDEFINED; |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 1392 | colorMode = COLOR_MODE_UNDEFINED; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 1393 | uiMode = UI_MODE_TYPE_UNDEFINED; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1394 | screenWidthDp = compatScreenWidthDp = SCREEN_WIDTH_DP_UNDEFINED; |
| 1395 | screenHeightDp = compatScreenHeightDp = SCREEN_HEIGHT_DP_UNDEFINED; |
| 1396 | smallestScreenWidthDp = compatSmallestScreenWidthDp = SMALLEST_SCREEN_WIDTH_DP_UNDEFINED; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1397 | densityDpi = DENSITY_DPI_UNDEFINED; |
Mårten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1398 | assetsSeq = ASSETS_SEQ_UNDEFINED; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1399 | seq = 0; |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 1400 | windowConfiguration.setToDefaults(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1401 | } |
| 1402 | |
Adam Lesinski | bad43fc | 2016-07-19 13:35:01 -0700 | [diff] [blame] | 1403 | /** |
| 1404 | * Set this object to completely undefined. |
| 1405 | * @hide |
| 1406 | */ |
| 1407 | public void unset() { |
| 1408 | setToDefaults(); |
| 1409 | fontScale = 0; |
| 1410 | } |
| 1411 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1412 | /** {@hide} */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 1413 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1414 | @Deprecated public void makeDefault() { |
| 1415 | setToDefaults(); |
| 1416 | } |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1417 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1418 | /** |
Alan Viverette | ac85f90 | 2016-03-11 15:15:51 -0500 | [diff] [blame] | 1419 | * Copies the fields from delta into this Configuration object, keeping |
| 1420 | * track of which ones have changed. Any undefined fields in {@code delta} |
| 1421 | * are ignored and not copied in to the current Configuration. |
| 1422 | * |
| 1423 | * @return a bit mask of the changed fields, as per {@link #diff} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1424 | */ |
Alan Viverette | ac85f90 | 2016-03-11 15:15:51 -0500 | [diff] [blame] | 1425 | public @Config int updateFrom(@NonNull Configuration delta) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1426 | int changed = 0; |
| 1427 | if (delta.fontScale > 0 && fontScale != delta.fontScale) { |
| 1428 | changed |= ActivityInfo.CONFIG_FONT_SCALE; |
| 1429 | fontScale = delta.fontScale; |
| 1430 | } |
| 1431 | if (delta.mcc != 0 && mcc != delta.mcc) { |
| 1432 | changed |= ActivityInfo.CONFIG_MCC; |
| 1433 | mcc = delta.mcc; |
| 1434 | } |
| 1435 | if (delta.mnc != 0 && mnc != delta.mnc) { |
| 1436 | changed |= ActivityInfo.CONFIG_MNC; |
| 1437 | mnc = delta.mnc; |
| 1438 | } |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 1439 | fixUpLocaleList(); |
| 1440 | delta.fixUpLocaleList(); |
| 1441 | if (!delta.mLocaleList.isEmpty() && !mLocaleList.equals(delta.mLocaleList)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1442 | changed |= ActivityInfo.CONFIG_LOCALE; |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 1443 | mLocaleList = delta.mLocaleList; |
| 1444 | // delta.locale can't be null, since delta.mLocaleList is not empty. |
| 1445 | if (!delta.locale.equals(locale)) { |
| 1446 | locale = (Locale) delta.locale.clone(); |
| 1447 | // If locale has changed, then layout direction is also changed ... |
| 1448 | changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION; |
| 1449 | // ... and we need to update the layout direction (represented by the first |
| 1450 | // 2 most significant bits in screenLayout). |
| 1451 | setLayoutDirection(locale); |
| 1452 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1453 | } |
Craig Mautner | 31678b5 | 2013-08-12 17:56:34 -0700 | [diff] [blame] | 1454 | final int deltaScreenLayoutDir = delta.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK; |
| 1455 | if (deltaScreenLayoutDir != SCREENLAYOUT_LAYOUTDIR_UNDEFINED && |
| 1456 | deltaScreenLayoutDir != (screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK)) { |
| 1457 | screenLayout = (screenLayout & ~SCREENLAYOUT_LAYOUTDIR_MASK) | deltaScreenLayoutDir; |
Amith Yamasani | d8415f4 | 2013-08-07 20:15:10 -0700 | [diff] [blame] | 1458 | changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION; |
Amith Yamasani | d8415f4 | 2013-08-07 20:15:10 -0700 | [diff] [blame] | 1459 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1460 | if (delta.userSetLocale && (!userSetLocale || ((changed & ActivityInfo.CONFIG_LOCALE) != 0))) |
| 1461 | { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1462 | changed |= ActivityInfo.CONFIG_LOCALE; |
Amith Yamasani | d8415f4 | 2013-08-07 20:15:10 -0700 | [diff] [blame] | 1463 | userSetLocale = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1464 | } |
| 1465 | if (delta.touchscreen != TOUCHSCREEN_UNDEFINED |
| 1466 | && touchscreen != delta.touchscreen) { |
| 1467 | changed |= ActivityInfo.CONFIG_TOUCHSCREEN; |
| 1468 | touchscreen = delta.touchscreen; |
| 1469 | } |
| 1470 | if (delta.keyboard != KEYBOARD_UNDEFINED |
| 1471 | && keyboard != delta.keyboard) { |
| 1472 | changed |= ActivityInfo.CONFIG_KEYBOARD; |
| 1473 | keyboard = delta.keyboard; |
| 1474 | } |
| 1475 | if (delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED |
| 1476 | && keyboardHidden != delta.keyboardHidden) { |
| 1477 | changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; |
| 1478 | keyboardHidden = delta.keyboardHidden; |
| 1479 | } |
| 1480 | if (delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED |
| 1481 | && hardKeyboardHidden != delta.hardKeyboardHidden) { |
| 1482 | changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; |
| 1483 | hardKeyboardHidden = delta.hardKeyboardHidden; |
| 1484 | } |
| 1485 | if (delta.navigation != NAVIGATION_UNDEFINED |
| 1486 | && navigation != delta.navigation) { |
| 1487 | changed |= ActivityInfo.CONFIG_NAVIGATION; |
| 1488 | navigation = delta.navigation; |
| 1489 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 1490 | if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED |
| 1491 | && navigationHidden != delta.navigationHidden) { |
| 1492 | changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; |
| 1493 | navigationHidden = delta.navigationHidden; |
| 1494 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1495 | if (delta.orientation != ORIENTATION_UNDEFINED |
| 1496 | && orientation != delta.orientation) { |
| 1497 | changed |= ActivityInfo.CONFIG_ORIENTATION; |
| 1498 | orientation = delta.orientation; |
| 1499 | } |
Robert Carr | df259d3 | 2016-12-05 20:33:10 -0800 | [diff] [blame] | 1500 | if (((delta.screenLayout & SCREENLAYOUT_SIZE_MASK) != SCREENLAYOUT_SIZE_UNDEFINED) |
| 1501 | && (delta.screenLayout & SCREENLAYOUT_SIZE_MASK) |
| 1502 | != (screenLayout & SCREENLAYOUT_SIZE_MASK)) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1503 | changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT; |
Robert Carr | df259d3 | 2016-12-05 20:33:10 -0800 | [diff] [blame] | 1504 | screenLayout = (screenLayout & ~SCREENLAYOUT_SIZE_MASK) |
| 1505 | | (delta.screenLayout & SCREENLAYOUT_SIZE_MASK); |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1506 | } |
Robert Carr | df259d3 | 2016-12-05 20:33:10 -0800 | [diff] [blame] | 1507 | if (((delta.screenLayout & SCREENLAYOUT_LONG_MASK) != SCREENLAYOUT_LONG_UNDEFINED) |
| 1508 | && (delta.screenLayout & SCREENLAYOUT_LONG_MASK) |
| 1509 | != (screenLayout & SCREENLAYOUT_LONG_MASK)) { |
| 1510 | changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT; |
| 1511 | screenLayout = (screenLayout & ~SCREENLAYOUT_LONG_MASK) |
| 1512 | | (delta.screenLayout & SCREENLAYOUT_LONG_MASK); |
| 1513 | } |
| 1514 | if (((delta.screenLayout & SCREENLAYOUT_ROUND_MASK) != SCREENLAYOUT_ROUND_UNDEFINED) |
| 1515 | && (delta.screenLayout & SCREENLAYOUT_ROUND_MASK) |
| 1516 | != (screenLayout & SCREENLAYOUT_ROUND_MASK)) { |
| 1517 | changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT; |
| 1518 | screenLayout = (screenLayout & ~SCREENLAYOUT_ROUND_MASK) |
| 1519 | | (delta.screenLayout & SCREENLAYOUT_ROUND_MASK); |
| 1520 | } |
| 1521 | if ((delta.screenLayout & SCREENLAYOUT_COMPAT_NEEDED) |
| 1522 | != (screenLayout & SCREENLAYOUT_COMPAT_NEEDED) |
| 1523 | && delta.screenLayout != 0) { |
| 1524 | changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT; |
| 1525 | screenLayout = (screenLayout & ~SCREENLAYOUT_COMPAT_NEEDED) |
| 1526 | | (delta.screenLayout & SCREENLAYOUT_COMPAT_NEEDED); |
| 1527 | } |
| 1528 | |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 1529 | if (((delta.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK) != |
| 1530 | COLOR_MODE_WIDE_COLOR_GAMUT_UNDEFINED) |
| 1531 | && (delta.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK) |
| 1532 | != (colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK)) { |
| 1533 | changed |= ActivityInfo.CONFIG_COLOR_MODE; |
| 1534 | colorMode = (colorMode & ~COLOR_MODE_WIDE_COLOR_GAMUT_MASK) |
| 1535 | | (delta.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK); |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 1536 | } |
| 1537 | |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 1538 | if (((delta.colorMode & COLOR_MODE_HDR_MASK) != COLOR_MODE_HDR_UNDEFINED) |
| 1539 | && (delta.colorMode & COLOR_MODE_HDR_MASK) |
| 1540 | != (colorMode & COLOR_MODE_HDR_MASK)) { |
| 1541 | changed |= ActivityInfo.CONFIG_COLOR_MODE; |
| 1542 | colorMode = (colorMode & ~COLOR_MODE_HDR_MASK) |
| 1543 | | (delta.colorMode & COLOR_MODE_HDR_MASK); |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 1544 | } |
| 1545 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 1546 | if (delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED) |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 1547 | && uiMode != delta.uiMode) { |
| 1548 | changed |= ActivityInfo.CONFIG_UI_MODE; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 1549 | if ((delta.uiMode&UI_MODE_TYPE_MASK) != UI_MODE_TYPE_UNDEFINED) { |
| 1550 | uiMode = (uiMode&~UI_MODE_TYPE_MASK) |
| 1551 | | (delta.uiMode&UI_MODE_TYPE_MASK); |
| 1552 | } |
| 1553 | if ((delta.uiMode&UI_MODE_NIGHT_MASK) != UI_MODE_NIGHT_UNDEFINED) { |
| 1554 | uiMode = (uiMode&~UI_MODE_NIGHT_MASK) |
| 1555 | | (delta.uiMode&UI_MODE_NIGHT_MASK); |
| 1556 | } |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 1557 | } |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 1558 | if (delta.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED |
| 1559 | && screenWidthDp != delta.screenWidthDp) { |
| 1560 | changed |= ActivityInfo.CONFIG_SCREEN_SIZE; |
| 1561 | screenWidthDp = delta.screenWidthDp; |
| 1562 | } |
| 1563 | if (delta.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED |
| 1564 | && screenHeightDp != delta.screenHeightDp) { |
| 1565 | changed |= ActivityInfo.CONFIG_SCREEN_SIZE; |
| 1566 | screenHeightDp = delta.screenHeightDp; |
| 1567 | } |
Danny Baumann | e7123a6 | 2013-05-15 10:21:40 +0200 | [diff] [blame] | 1568 | if (delta.smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED |
| 1569 | && smallestScreenWidthDp != delta.smallestScreenWidthDp) { |
| 1570 | changed |= ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1571 | smallestScreenWidthDp = delta.smallestScreenWidthDp; |
| 1572 | } |
Danny Baumann | e7123a6 | 2013-05-15 10:21:40 +0200 | [diff] [blame] | 1573 | if (delta.densityDpi != DENSITY_DPI_UNDEFINED && |
| 1574 | densityDpi != delta.densityDpi) { |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1575 | changed |= ActivityInfo.CONFIG_DENSITY; |
| 1576 | densityDpi = delta.densityDpi; |
| 1577 | } |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1578 | if (delta.compatScreenWidthDp != SCREEN_WIDTH_DP_UNDEFINED) { |
| 1579 | compatScreenWidthDp = delta.compatScreenWidthDp; |
| 1580 | } |
| 1581 | if (delta.compatScreenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED) { |
| 1582 | compatScreenHeightDp = delta.compatScreenHeightDp; |
| 1583 | } |
| 1584 | if (delta.compatSmallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) { |
| 1585 | compatSmallestScreenWidthDp = delta.compatSmallestScreenWidthDp; |
| 1586 | } |
Adam Lesinski | 4eb4129 | 2017-07-06 12:06:13 -0700 | [diff] [blame] | 1587 | if (delta.assetsSeq != ASSETS_SEQ_UNDEFINED && delta.assetsSeq != assetsSeq) { |
Mårten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1588 | changed |= ActivityInfo.CONFIG_ASSETS_PATHS; |
| 1589 | assetsSeq = delta.assetsSeq; |
| 1590 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1591 | if (delta.seq != 0) { |
| 1592 | seq = delta.seq; |
| 1593 | } |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 1594 | if (windowConfiguration.updateFrom(delta.windowConfiguration) != 0) { |
| 1595 | changed |= ActivityInfo.CONFIG_WINDOW_CONFIGURATION; |
| 1596 | } |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1597 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1598 | return changed; |
| 1599 | } |
| 1600 | |
| 1601 | /** |
Evan Rosky | ddedfd4 | 2019-10-04 13:38:38 -0700 | [diff] [blame] | 1602 | * Copies the fields specified by mask from delta into this Configuration object. This will |
| 1603 | * copy anything allowed by the mask (including undefined values). |
| 1604 | * @hide |
| 1605 | */ |
| 1606 | public void setTo(@NonNull Configuration delta, @Config int mask, |
| 1607 | @WindowConfiguration.WindowConfig int windowMask) { |
| 1608 | if ((mask & ActivityInfo.CONFIG_FONT_SCALE) != 0) { |
| 1609 | fontScale = delta.fontScale; |
| 1610 | } |
| 1611 | if ((mask & ActivityInfo.CONFIG_MCC) != 0) { |
| 1612 | mcc = delta.mcc; |
| 1613 | } |
| 1614 | if ((mask & ActivityInfo.CONFIG_MNC) != 0) { |
| 1615 | mnc = delta.mnc; |
| 1616 | } |
| 1617 | if ((mask & ActivityInfo.CONFIG_LOCALE) != 0) { |
| 1618 | mLocaleList = delta.mLocaleList; |
| 1619 | if (!mLocaleList.isEmpty()) { |
| 1620 | locale = (Locale) delta.locale.clone(); |
| 1621 | } |
| 1622 | } |
| 1623 | if ((mask & ActivityInfo.CONFIG_LAYOUT_DIRECTION) != 0) { |
| 1624 | final int deltaScreenLayoutDir = delta.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK; |
| 1625 | screenLayout = (screenLayout & ~SCREENLAYOUT_LAYOUTDIR_MASK) | deltaScreenLayoutDir; |
| 1626 | } |
| 1627 | if ((mask & ActivityInfo.CONFIG_LOCALE) != 0) { |
| 1628 | userSetLocale = delta.userSetLocale; |
| 1629 | } |
| 1630 | if ((mask & ActivityInfo.CONFIG_TOUCHSCREEN) != 0) { |
| 1631 | touchscreen = delta.touchscreen; |
| 1632 | } |
| 1633 | if ((mask & ActivityInfo.CONFIG_KEYBOARD) != 0) { |
| 1634 | keyboard = delta.keyboard; |
| 1635 | } |
| 1636 | if ((mask & ActivityInfo.CONFIG_KEYBOARD_HIDDEN) != 0) { |
| 1637 | keyboardHidden = delta.keyboardHidden; |
| 1638 | hardKeyboardHidden = delta.hardKeyboardHidden; |
| 1639 | navigationHidden = delta.navigationHidden; |
| 1640 | } |
| 1641 | if ((mask & ActivityInfo.CONFIG_NAVIGATION) != 0) { |
| 1642 | navigation = delta.navigation; |
| 1643 | } |
| 1644 | if ((mask & ActivityInfo.CONFIG_ORIENTATION) != 0) { |
| 1645 | orientation = delta.orientation; |
| 1646 | } |
| 1647 | if ((mask & ActivityInfo.CONFIG_SCREEN_LAYOUT) != 0) { |
| 1648 | // Not enough granularity for each component unfortunately. |
| 1649 | screenLayout = screenLayout | (delta.screenLayout & ~SCREENLAYOUT_LAYOUTDIR_MASK); |
| 1650 | } |
| 1651 | if ((mask & ActivityInfo.CONFIG_COLOR_MODE) != 0) { |
| 1652 | colorMode = delta.colorMode; |
| 1653 | } |
| 1654 | if ((mask & ActivityInfo.CONFIG_UI_MODE) != 0) { |
| 1655 | uiMode = delta.uiMode; |
| 1656 | } |
| 1657 | if ((mask & ActivityInfo.CONFIG_SCREEN_SIZE) != 0) { |
| 1658 | screenWidthDp = delta.screenWidthDp; |
| 1659 | screenHeightDp = delta.screenHeightDp; |
| 1660 | } |
| 1661 | if ((mask & ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE) != 0) { |
| 1662 | smallestScreenWidthDp = delta.smallestScreenWidthDp; |
| 1663 | } |
| 1664 | if ((mask & ActivityInfo.CONFIG_DENSITY) != 0) { |
| 1665 | densityDpi = delta.densityDpi; |
| 1666 | } |
| 1667 | if ((mask & ActivityInfo.CONFIG_ASSETS_PATHS) != 0) { |
| 1668 | assetsSeq = delta.assetsSeq; |
| 1669 | } |
| 1670 | if ((mask & ActivityInfo.CONFIG_WINDOW_CONFIGURATION) != 0) { |
| 1671 | windowConfiguration.setTo(delta.windowConfiguration, windowMask); |
| 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1676 | * Return a bit mask of the differences between this Configuration |
| 1677 | * object and the given one. Does not change the values of either. Any |
| 1678 | * undefined fields in <var>delta</var> are ignored. |
| 1679 | * @return Returns a bit mask indicating which configuration |
| 1680 | * values has changed, containing any combination of |
| 1681 | * {@link android.content.pm.ActivityInfo#CONFIG_FONT_SCALE |
| 1682 | * PackageManager.ActivityInfo.CONFIG_FONT_SCALE}, |
| 1683 | * {@link android.content.pm.ActivityInfo#CONFIG_MCC |
| 1684 | * PackageManager.ActivityInfo.CONFIG_MCC}, |
| 1685 | * {@link android.content.pm.ActivityInfo#CONFIG_MNC |
| 1686 | * PackageManager.ActivityInfo.CONFIG_MNC}, |
| 1687 | * {@link android.content.pm.ActivityInfo#CONFIG_LOCALE |
| 1688 | * PackageManager.ActivityInfo.CONFIG_LOCALE}, |
| 1689 | * {@link android.content.pm.ActivityInfo#CONFIG_TOUCHSCREEN |
| 1690 | * PackageManager.ActivityInfo.CONFIG_TOUCHSCREEN}, |
| 1691 | * {@link android.content.pm.ActivityInfo#CONFIG_KEYBOARD |
| 1692 | * PackageManager.ActivityInfo.CONFIG_KEYBOARD}, |
| 1693 | * {@link android.content.pm.ActivityInfo#CONFIG_NAVIGATION |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1694 | * PackageManager.ActivityInfo.CONFIG_NAVIGATION}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1695 | * {@link android.content.pm.ActivityInfo#CONFIG_ORIENTATION |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 1696 | * PackageManager.ActivityInfo.CONFIG_ORIENTATION}, |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1697 | * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_LAYOUT |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 1698 | * PackageManager.ActivityInfo.CONFIG_SCREEN_LAYOUT}, or |
| 1699 | * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_SIZE |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1700 | * PackageManager.ActivityInfo.CONFIG_SCREEN_SIZE}, or |
| 1701 | * {@link android.content.pm.ActivityInfo#CONFIG_SMALLEST_SCREEN_SIZE |
| 1702 | * PackageManager.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE}. |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 1703 | * {@link android.content.pm.ActivityInfo#CONFIG_LAYOUT_DIRECTION |
| 1704 | * PackageManager.ActivityInfo.CONFIG_LAYOUT_DIRECTION}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1705 | */ |
| 1706 | public int diff(Configuration delta) { |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 1707 | return diff(delta, false /* compareUndefined */, false /* publicOnly */); |
| 1708 | } |
| 1709 | |
| 1710 | /** |
| 1711 | * Returns the diff against the provided {@link Configuration} excluding values that would |
| 1712 | * publicly be equivalent, such as appBounds. |
| 1713 | * @param delta {@link Configuration} to compare to. |
| 1714 | * |
| 1715 | * TODO(b/36812336): Remove once appBounds has been moved out of Configuration. |
| 1716 | * {@hide} |
| 1717 | */ |
| 1718 | public int diffPublicOnly(Configuration delta) { |
| 1719 | return diff(delta, false /* compareUndefined */, true /* publicOnly */); |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | /** |
| 1723 | * Variation of {@link #diff(Configuration)} with an option to skip checks for undefined values. |
| 1724 | * |
| 1725 | * @hide |
| 1726 | */ |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 1727 | public int diff(Configuration delta, boolean compareUndefined, boolean publicOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1728 | int changed = 0; |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 1729 | if ((compareUndefined || delta.fontScale > 0) && fontScale != delta.fontScale) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1730 | changed |= ActivityInfo.CONFIG_FONT_SCALE; |
| 1731 | } |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 1732 | if ((compareUndefined || delta.mcc != 0) && mcc != delta.mcc) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1733 | changed |= ActivityInfo.CONFIG_MCC; |
| 1734 | } |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 1735 | if ((compareUndefined || delta.mnc != 0) && mnc != delta.mnc) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1736 | changed |= ActivityInfo.CONFIG_MNC; |
| 1737 | } |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 1738 | fixUpLocaleList(); |
| 1739 | delta.fixUpLocaleList(); |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 1740 | if ((compareUndefined || !delta.mLocaleList.isEmpty()) |
| 1741 | && !mLocaleList.equals(delta.mLocaleList)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1742 | changed |= ActivityInfo.CONFIG_LOCALE; |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 1743 | changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1744 | } |
Craig Mautner | 31678b5 | 2013-08-12 17:56:34 -0700 | [diff] [blame] | 1745 | final int deltaScreenLayoutDir = delta.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK; |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 1746 | if ((compareUndefined || deltaScreenLayoutDir != SCREENLAYOUT_LAYOUTDIR_UNDEFINED) |
| 1747 | && deltaScreenLayoutDir != (screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK)) { |
Amith Yamasani | d8415f4 | 2013-08-07 20:15:10 -0700 | [diff] [blame] | 1748 | changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION; |
| 1749 | } |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 1750 | if ((compareUndefined || delta.touchscreen != TOUCHSCREEN_UNDEFINED) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1751 | && touchscreen != delta.touchscreen) { |
| 1752 | changed |= ActivityInfo.CONFIG_TOUCHSCREEN; |
| 1753 | } |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 1754 | if ((compareUndefined || delta.keyboard != KEYBOARD_UNDEFINED) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1755 | && keyboard != delta.keyboard) { |
| 1756 | changed |= ActivityInfo.CONFIG_KEYBOARD; |
| 1757 | } |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 1758 | if ((compareUndefined || delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1759 | && keyboardHidden != delta.keyboardHidden) { |
| 1760 | changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; |
| 1761 | } |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 1762 | if ((compareUndefined || delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1763 | && hardKeyboardHidden != delta.hardKeyboardHidden) { |
| 1764 | changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; |
| 1765 | } |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 1766 | if ((compareUndefined || delta.navigation != NAVIGATION_UNDEFINED) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1767 | && navigation != delta.navigation) { |
| 1768 | changed |= ActivityInfo.CONFIG_NAVIGATION; |
| 1769 | } |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 1770 | if ((compareUndefined || delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED) |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 1771 | && navigationHidden != delta.navigationHidden) { |
| 1772 | changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; |
| 1773 | } |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 1774 | if ((compareUndefined || delta.orientation != ORIENTATION_UNDEFINED) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1775 | && orientation != delta.orientation) { |
| 1776 | changed |= ActivityInfo.CONFIG_ORIENTATION; |
| 1777 | } |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 1778 | if ((compareUndefined || getScreenLayoutNoDirection(delta.screenLayout) != |
| 1779 | (SCREENLAYOUT_SIZE_UNDEFINED | SCREENLAYOUT_LONG_UNDEFINED)) |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 1780 | && getScreenLayoutNoDirection(screenLayout) != |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 1781 | getScreenLayoutNoDirection(delta.screenLayout)) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1782 | changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT; |
| 1783 | } |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 1784 | if ((compareUndefined || |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 1785 | (delta.colorMode & COLOR_MODE_HDR_MASK) != COLOR_MODE_HDR_UNDEFINED) |
| 1786 | && (colorMode & COLOR_MODE_HDR_MASK) != |
| 1787 | (delta.colorMode & COLOR_MODE_HDR_MASK)) { |
| 1788 | changed |= ActivityInfo.CONFIG_COLOR_MODE; |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 1789 | } |
| 1790 | if ((compareUndefined || |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 1791 | (delta.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK) != |
| 1792 | COLOR_MODE_WIDE_COLOR_GAMUT_UNDEFINED) |
| 1793 | && (colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK) != |
| 1794 | (delta.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK)) { |
| 1795 | changed |= ActivityInfo.CONFIG_COLOR_MODE; |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 1796 | } |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 1797 | if ((compareUndefined || delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED)) |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 1798 | && uiMode != delta.uiMode) { |
| 1799 | changed |= ActivityInfo.CONFIG_UI_MODE; |
| 1800 | } |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 1801 | if ((compareUndefined || delta.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED) |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 1802 | && screenWidthDp != delta.screenWidthDp) { |
| 1803 | changed |= ActivityInfo.CONFIG_SCREEN_SIZE; |
| 1804 | } |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 1805 | if ((compareUndefined || delta.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED) |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 1806 | && screenHeightDp != delta.screenHeightDp) { |
| 1807 | changed |= ActivityInfo.CONFIG_SCREEN_SIZE; |
| 1808 | } |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 1809 | if ((compareUndefined || delta.smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1810 | && smallestScreenWidthDp != delta.smallestScreenWidthDp) { |
| 1811 | changed |= ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE; |
| 1812 | } |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 1813 | if ((compareUndefined || delta.densityDpi != DENSITY_DPI_UNDEFINED) |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1814 | && densityDpi != delta.densityDpi) { |
| 1815 | changed |= ActivityInfo.CONFIG_DENSITY; |
| 1816 | } |
Mårten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1817 | if ((compareUndefined || delta.assetsSeq != ASSETS_SEQ_UNDEFINED) |
| 1818 | && assetsSeq != delta.assetsSeq) { |
| 1819 | changed |= ActivityInfo.CONFIG_ASSETS_PATHS; |
| 1820 | } |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 1821 | |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 1822 | // WindowConfiguration differences aren't considered public... |
| 1823 | if (!publicOnly |
| 1824 | && windowConfiguration.diff(delta.windowConfiguration, compareUndefined) != 0) { |
| 1825 | changed |= ActivityInfo.CONFIG_WINDOW_CONFIGURATION; |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1828 | return changed; |
| 1829 | } |
| 1830 | |
| 1831 | /** |
Alan Viverette | ac85f90 | 2016-03-11 15:15:51 -0500 | [diff] [blame] | 1832 | * Determines if a new resource needs to be loaded from the bit set of |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1833 | * configuration changes returned by {@link #updateFrom(Configuration)}. |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1834 | * |
Alan Viverette | ac85f90 | 2016-03-11 15:15:51 -0500 | [diff] [blame] | 1835 | * @param configChanges the mask of changes configurations as returned by |
| 1836 | * {@link #updateFrom(Configuration)} |
| 1837 | * @param interestingChanges the configuration changes that the resource |
| 1838 | * can handle as given in |
| 1839 | * {@link android.util.TypedValue#changingConfigurations} |
| 1840 | * @return {@code true} if the resource needs to be loaded, {@code false} |
| 1841 | * otherwise |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1842 | */ |
Alan Viverette | ac85f90 | 2016-03-11 15:15:51 -0500 | [diff] [blame] | 1843 | public static boolean needNewResources(@Config int configChanges, |
| 1844 | @Config int interestingChanges) { |
Mårten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1845 | // CONFIG_ASSETS_PATHS and CONFIG_FONT_SCALE are higher level configuration changes that |
| 1846 | // all resources are subject to change with. |
| 1847 | interestingChanges = interestingChanges | ActivityInfo.CONFIG_ASSETS_PATHS |
| 1848 | | ActivityInfo.CONFIG_FONT_SCALE; |
| 1849 | return (configChanges & interestingChanges) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1850 | } |
Amith Yamasani | d8415f4 | 2013-08-07 20:15:10 -0700 | [diff] [blame] | 1851 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1852 | /** |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1853 | * @hide Return true if the sequence of 'other' is better than this. Assumes |
| 1854 | * that 'this' is your current sequence and 'other' is a new one you have |
| 1855 | * received some how and want to compare with what you have. |
| 1856 | */ |
| 1857 | public boolean isOtherSeqNewer(Configuration other) { |
| 1858 | if (other == null) { |
| 1859 | // Sanity check. |
| 1860 | return false; |
| 1861 | } |
| 1862 | if (other.seq == 0) { |
| 1863 | // If the other sequence is not specified, then we must assume |
| 1864 | // it is newer since we don't know any better. |
| 1865 | return true; |
| 1866 | } |
| 1867 | if (seq == 0) { |
| 1868 | // If this sequence is not specified, then we also consider the |
| 1869 | // other is better. Yes we have a preference for other. Sue us. |
| 1870 | return true; |
| 1871 | } |
| 1872 | int diff = other.seq - seq; |
| 1873 | if (diff > 0x10000) { |
| 1874 | // If there has been a sufficiently large jump, assume the |
| 1875 | // sequence has wrapped around. |
| 1876 | return false; |
| 1877 | } |
| 1878 | return diff > 0; |
| 1879 | } |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1880 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1881 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1882 | * Parcelable methods |
| 1883 | */ |
| 1884 | public int describeContents() { |
| 1885 | return 0; |
| 1886 | } |
| 1887 | |
| 1888 | public void writeToParcel(Parcel dest, int flags) { |
| 1889 | dest.writeFloat(fontScale); |
| 1890 | dest.writeInt(mcc); |
| 1891 | dest.writeInt(mnc); |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 1892 | |
| 1893 | fixUpLocaleList(); |
Siyamed Sinir | 27ddd8a | 2018-02-27 13:07:22 -0800 | [diff] [blame] | 1894 | dest.writeParcelable(mLocaleList, flags); |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 1895 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1896 | if(userSetLocale) { |
| 1897 | dest.writeInt(1); |
| 1898 | } else { |
| 1899 | dest.writeInt(0); |
| 1900 | } |
| 1901 | dest.writeInt(touchscreen); |
| 1902 | dest.writeInt(keyboard); |
| 1903 | dest.writeInt(keyboardHidden); |
| 1904 | dest.writeInt(hardKeyboardHidden); |
| 1905 | dest.writeInt(navigation); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 1906 | dest.writeInt(navigationHidden); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1907 | dest.writeInt(orientation); |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1908 | dest.writeInt(screenLayout); |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 1909 | dest.writeInt(colorMode); |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 1910 | dest.writeInt(uiMode); |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 1911 | dest.writeInt(screenWidthDp); |
| 1912 | dest.writeInt(screenHeightDp); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1913 | dest.writeInt(smallestScreenWidthDp); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1914 | dest.writeInt(densityDpi); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1915 | dest.writeInt(compatScreenWidthDp); |
| 1916 | dest.writeInt(compatScreenHeightDp); |
| 1917 | dest.writeInt(compatSmallestScreenWidthDp); |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 1918 | dest.writeValue(windowConfiguration); |
Mårten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1919 | dest.writeInt(assetsSeq); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1920 | dest.writeInt(seq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1921 | } |
| 1922 | |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 1923 | public void readFromParcel(Parcel source) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1924 | fontScale = source.readFloat(); |
| 1925 | mcc = source.readInt(); |
| 1926 | mnc = source.readInt(); |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 1927 | |
Siyamed Sinir | 27ddd8a | 2018-02-27 13:07:22 -0800 | [diff] [blame] | 1928 | mLocaleList = source.readParcelable(LocaleList.class.getClassLoader()); |
Roozbeh Pournader | fee4484 | 2016-02-04 15:24:24 -0800 | [diff] [blame] | 1929 | locale = mLocaleList.get(0); |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 1930 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1931 | userSetLocale = (source.readInt()==1); |
| 1932 | touchscreen = source.readInt(); |
| 1933 | keyboard = source.readInt(); |
| 1934 | keyboardHidden = source.readInt(); |
| 1935 | hardKeyboardHidden = source.readInt(); |
| 1936 | navigation = source.readInt(); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 1937 | navigationHidden = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1938 | orientation = source.readInt(); |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1939 | screenLayout = source.readInt(); |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 1940 | colorMode = source.readInt(); |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 1941 | uiMode = source.readInt(); |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 1942 | screenWidthDp = source.readInt(); |
| 1943 | screenHeightDp = source.readInt(); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1944 | smallestScreenWidthDp = source.readInt(); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1945 | densityDpi = source.readInt(); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1946 | compatScreenWidthDp = source.readInt(); |
| 1947 | compatScreenHeightDp = source.readInt(); |
| 1948 | compatSmallestScreenWidthDp = source.readInt(); |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 1949 | windowConfiguration.setTo((WindowConfiguration) source.readValue(null)); |
Mårten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1950 | assetsSeq = source.readInt(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1951 | seq = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1952 | } |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1953 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 1954 | public static final @android.annotation.NonNull Parcelable.Creator<Configuration> CREATOR |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 1955 | = new Parcelable.Creator<Configuration>() { |
| 1956 | public Configuration createFromParcel(Parcel source) { |
| 1957 | return new Configuration(source); |
| 1958 | } |
| 1959 | |
| 1960 | public Configuration[] newArray(int size) { |
| 1961 | return new Configuration[size]; |
| 1962 | } |
| 1963 | }; |
| 1964 | |
| 1965 | /** |
| 1966 | * Construct this Configuration object, reading from the Parcel. |
| 1967 | */ |
| 1968 | private Configuration(Parcel source) { |
| 1969 | readFromParcel(source); |
| 1970 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1971 | |
| 1972 | public int compareTo(Configuration that) { |
| 1973 | int n; |
| 1974 | float a = this.fontScale; |
| 1975 | float b = that.fontScale; |
| 1976 | if (a < b) return -1; |
| 1977 | if (a > b) return 1; |
| 1978 | n = this.mcc - that.mcc; |
| 1979 | if (n != 0) return n; |
| 1980 | n = this.mnc - that.mnc; |
| 1981 | if (n != 0) return n; |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 1982 | |
| 1983 | fixUpLocaleList(); |
| 1984 | that.fixUpLocaleList(); |
| 1985 | // for backward compatibility, we consider an empty locale list to be greater |
| 1986 | // than any non-empty locale list. |
| 1987 | if (this.mLocaleList.isEmpty()) { |
| 1988 | if (!that.mLocaleList.isEmpty()) return 1; |
| 1989 | } else if (that.mLocaleList.isEmpty()) { |
Dianne Hackborn | a839703 | 2010-03-12 10:52:22 -0800 | [diff] [blame] | 1990 | return -1; |
| 1991 | } else { |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 1992 | final int minSize = Math.min(this.mLocaleList.size(), that.mLocaleList.size()); |
| 1993 | for (int i = 0; i < minSize; ++i) { |
| 1994 | final Locale thisLocale = this.mLocaleList.get(i); |
| 1995 | final Locale thatLocale = that.mLocaleList.get(i); |
| 1996 | n = thisLocale.getLanguage().compareTo(thatLocale.getLanguage()); |
| 1997 | if (n != 0) return n; |
| 1998 | n = thisLocale.getCountry().compareTo(thatLocale.getCountry()); |
| 1999 | if (n != 0) return n; |
| 2000 | n = thisLocale.getVariant().compareTo(thatLocale.getVariant()); |
| 2001 | if (n != 0) return n; |
| 2002 | n = thisLocale.toLanguageTag().compareTo(thatLocale.toLanguageTag()); |
| 2003 | if (n != 0) return n; |
| 2004 | } |
| 2005 | n = this.mLocaleList.size() - that.mLocaleList.size(); |
Dianne Hackborn | a839703 | 2010-03-12 10:52:22 -0800 | [diff] [blame] | 2006 | if (n != 0) return n; |
| 2007 | } |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 2008 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2009 | n = this.touchscreen - that.touchscreen; |
| 2010 | if (n != 0) return n; |
| 2011 | n = this.keyboard - that.keyboard; |
| 2012 | if (n != 0) return n; |
| 2013 | n = this.keyboardHidden - that.keyboardHidden; |
| 2014 | if (n != 0) return n; |
| 2015 | n = this.hardKeyboardHidden - that.hardKeyboardHidden; |
| 2016 | if (n != 0) return n; |
| 2017 | n = this.navigation - that.navigation; |
| 2018 | if (n != 0) return n; |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2019 | n = this.navigationHidden - that.navigationHidden; |
| 2020 | if (n != 0) return n; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2021 | n = this.orientation - that.orientation; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2022 | if (n != 0) return n; |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 2023 | n = this.colorMode - that.colorMode; |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 2024 | if (n != 0) return n; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2025 | n = this.screenLayout - that.screenLayout; |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 2026 | if (n != 0) return n; |
| 2027 | n = this.uiMode - that.uiMode; |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 2028 | if (n != 0) return n; |
| 2029 | n = this.screenWidthDp - that.screenWidthDp; |
| 2030 | if (n != 0) return n; |
| 2031 | n = this.screenHeightDp - that.screenHeightDp; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2032 | if (n != 0) return n; |
| 2033 | n = this.smallestScreenWidthDp - that.smallestScreenWidthDp; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 2034 | if (n != 0) return n; |
| 2035 | n = this.densityDpi - that.densityDpi; |
Mårten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 2036 | if (n != 0) return n; |
| 2037 | n = this.assetsSeq - that.assetsSeq; |
Bryce Lee | c5fe0ee | 2017-06-30 09:03:09 -0700 | [diff] [blame] | 2038 | if (n != 0) return n; |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 2039 | n = windowConfiguration.compareTo(that.windowConfiguration); |
| 2040 | if (n != 0) return n; |
Bryce Lee | c5fe0ee | 2017-06-30 09:03:09 -0700 | [diff] [blame] | 2041 | |
| 2042 | // if (n != 0) return n; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2043 | return n; |
| 2044 | } |
| 2045 | |
| 2046 | public boolean equals(Configuration that) { |
| 2047 | if (that == null) return false; |
| 2048 | if (that == this) return true; |
| 2049 | return this.compareTo(that) == 0; |
| 2050 | } |
| 2051 | |
| 2052 | public boolean equals(Object that) { |
| 2053 | try { |
| 2054 | return equals((Configuration)that); |
| 2055 | } catch (ClassCastException e) { |
| 2056 | } |
| 2057 | return false; |
| 2058 | } |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 2059 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2060 | public int hashCode() { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2061 | int result = 17; |
| 2062 | result = 31 * result + Float.floatToIntBits(fontScale); |
| 2063 | result = 31 * result + mcc; |
| 2064 | result = 31 * result + mnc; |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 2065 | result = 31 * result + mLocaleList.hashCode(); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2066 | result = 31 * result + touchscreen; |
| 2067 | result = 31 * result + keyboard; |
| 2068 | result = 31 * result + keyboardHidden; |
| 2069 | result = 31 * result + hardKeyboardHidden; |
| 2070 | result = 31 * result + navigation; |
| 2071 | result = 31 * result + navigationHidden; |
| 2072 | result = 31 * result + orientation; |
| 2073 | result = 31 * result + screenLayout; |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 2074 | result = 31 * result + colorMode; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2075 | result = 31 * result + uiMode; |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 2076 | result = 31 * result + screenWidthDp; |
| 2077 | result = 31 * result + screenHeightDp; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2078 | result = 31 * result + smallestScreenWidthDp; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 2079 | result = 31 * result + densityDpi; |
Mårten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 2080 | result = 31 * result + assetsSeq; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2081 | return result; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2082 | } |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 2083 | |
| 2084 | /** |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 2085 | * Get the locale list. This is the preferred way for getting the locales (instead of using |
| 2086 | * the direct accessor to {@link #locale}, which would only provide the primary locale). |
| 2087 | * |
| 2088 | * @return The locale list. |
| 2089 | */ |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 2090 | public @NonNull LocaleList getLocales() { |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 2091 | fixUpLocaleList(); |
| 2092 | return mLocaleList; |
| 2093 | } |
| 2094 | |
| 2095 | /** |
| 2096 | * Set the locale list. This is the preferred way for setting up the locales (instead of using |
| 2097 | * the direct accessor or {@link #setLocale(Locale)}). This will also set the layout direction |
| 2098 | * according to the first locale in the list. |
| 2099 | * |
| 2100 | * Note that the layout direction will always come from the first locale in the locale list, |
| 2101 | * even if the locale is not supported by the resources (the resources may only support |
| 2102 | * another locale further down the list which has a different direction). |
| 2103 | * |
| 2104 | * @param locales The locale list. If null, an empty LocaleList will be assigned. |
| 2105 | */ |
| 2106 | public void setLocales(@Nullable LocaleList locales) { |
| 2107 | mLocaleList = locales == null ? LocaleList.getEmptyLocaleList() : locales; |
Roozbeh Pournader | fee4484 | 2016-02-04 15:24:24 -0800 | [diff] [blame] | 2108 | locale = mLocaleList.get(0); |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 2109 | setLayoutDirection(locale); |
| 2110 | } |
| 2111 | |
| 2112 | /** |
| 2113 | * Set the locale list to a list of just one locale. This will also set the layout direction |
| 2114 | * according to the locale. |
| 2115 | * |
| 2116 | * Note that after this is run, calling <code>.equals()</code> on the input locale and the |
| 2117 | * {@link #locale} attribute would return <code>true</code> if they are not null, but there is |
| 2118 | * no guarantee that they would be the same object. |
| 2119 | * |
| 2120 | * See also the note about layout direction in {@link #setLocales(LocaleList)}. |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 2121 | * |
| 2122 | * @param loc The locale. Can be null. |
| 2123 | */ |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 2124 | public void setLocale(@Nullable Locale loc) { |
Raph Levien | 10ea92a | 2016-05-02 12:56:01 -0700 | [diff] [blame] | 2125 | setLocales(loc == null ? LocaleList.getEmptyLocaleList() : new LocaleList(loc)); |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 2126 | } |
| 2127 | |
| 2128 | /** |
Seigo Nonaka | bd5cac6 | 2016-05-13 15:11:37 +0900 | [diff] [blame] | 2129 | * @hide |
| 2130 | * |
| 2131 | * Clears the locale without changing layout direction. |
| 2132 | */ |
| 2133 | public void clearLocales() { |
| 2134 | mLocaleList = LocaleList.getEmptyLocaleList(); |
| 2135 | locale = null; |
| 2136 | } |
| 2137 | |
| 2138 | /** |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 2139 | * Return the layout direction. Will be either {@link View#LAYOUT_DIRECTION_LTR} or |
| 2140 | * {@link View#LAYOUT_DIRECTION_RTL}. |
| 2141 | * |
Dianne Hackborn | f1ae269 | 2013-04-19 14:09:37 -0700 | [diff] [blame] | 2142 | * @return Returns {@link View#LAYOUT_DIRECTION_RTL} if the configuration |
| 2143 | * is {@link #SCREENLAYOUT_LAYOUTDIR_RTL}, otherwise {@link View#LAYOUT_DIRECTION_LTR}. |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 2144 | */ |
| 2145 | public int getLayoutDirection() { |
Dianne Hackborn | f1ae269 | 2013-04-19 14:09:37 -0700 | [diff] [blame] | 2146 | return (screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK) == SCREENLAYOUT_LAYOUTDIR_RTL |
| 2147 | ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR; |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | /** |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 2151 | * Set the layout direction from a Locale. |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 2152 | * |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 2153 | * @param loc The Locale. If null will set the layout direction to |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 2154 | * {@link View#LAYOUT_DIRECTION_LTR}. If not null will set it to the layout direction |
| 2155 | * corresponding to the Locale. |
| 2156 | * |
John Spurlock | bc4cf00 | 2015-03-24 21:51:20 -0400 | [diff] [blame] | 2157 | * @see View#LAYOUT_DIRECTION_LTR |
| 2158 | * @see View#LAYOUT_DIRECTION_RTL |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 2159 | */ |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 2160 | public void setLayoutDirection(Locale loc) { |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 2161 | // There is a "1" difference between the configuration values for |
| 2162 | // layout direction and View constants for layout direction, just add "1". |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 2163 | final int layoutDirection = 1 + TextUtils.getLayoutDirectionFromLocale(loc); |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 2164 | screenLayout = (screenLayout&~SCREENLAYOUT_LAYOUTDIR_MASK)| |
| 2165 | (layoutDirection << SCREENLAYOUT_LAYOUTDIR_SHIFT); |
| 2166 | } |
| 2167 | |
| 2168 | private static int getScreenLayoutNoDirection(int screenLayout) { |
| 2169 | return screenLayout&~SCREENLAYOUT_LAYOUTDIR_MASK; |
| 2170 | } |
Adam Lesinski | 2c749d2 | 2014-06-04 13:00:29 -0700 | [diff] [blame] | 2171 | |
| 2172 | /** |
Adam Powell | 49e7ff9 | 2015-05-14 16:18:53 -0700 | [diff] [blame] | 2173 | * Return whether the screen has a round shape. Apps may choose to change styling based |
| 2174 | * on this property, such as the alignment or layout of text or informational icons. |
| 2175 | * |
| 2176 | * @return true if the screen is rounded, false otherwise |
| 2177 | */ |
| 2178 | public boolean isScreenRound() { |
| 2179 | return (screenLayout & SCREENLAYOUT_ROUND_MASK) == SCREENLAYOUT_ROUND_YES; |
| 2180 | } |
| 2181 | |
| 2182 | /** |
Romain Guy | e89d0bb | 2017-06-20 12:23:42 -0700 | [diff] [blame] | 2183 | * Return whether the screen has a wide color gamut and wide color gamut rendering |
| 2184 | * is supported by this device. |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 2185 | * |
Chia-I Wu | 53e86ba | 2018-05-02 10:13:22 -0700 | [diff] [blame] | 2186 | * When true, it implies the screen is colorspace aware but not |
| 2187 | * necessarily color-managed. The final colors may still be changed by the |
| 2188 | * screen depending on user settings. |
| 2189 | * |
Romain Guy | e89d0bb | 2017-06-20 12:23:42 -0700 | [diff] [blame] | 2190 | * @return true if the screen has a wide color gamut and wide color gamut rendering |
| 2191 | * is supported, false otherwise |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 2192 | */ |
| 2193 | public boolean isScreenWideColorGamut() { |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 2194 | return (colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK) == COLOR_MODE_WIDE_COLOR_GAMUT_YES; |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 2195 | } |
| 2196 | |
| 2197 | /** |
| 2198 | * Return whether the screen has a high dynamic range. |
| 2199 | * |
| 2200 | * @return true if the screen has a high dynamic range, false otherwise |
| 2201 | */ |
| 2202 | public boolean isScreenHdr() { |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 2203 | return (colorMode & COLOR_MODE_HDR_MASK) == COLOR_MODE_HDR_YES; |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 2204 | } |
| 2205 | |
| 2206 | /** |
Adam Lesinski | 2c749d2 | 2014-06-04 13:00:29 -0700 | [diff] [blame] | 2207 | * |
| 2208 | * @hide |
| 2209 | */ |
Roozbeh Pournader | 47f71a6 | 2015-11-07 11:55:38 -0800 | [diff] [blame] | 2210 | public static String localesToResourceQualifier(LocaleList locs) { |
Roozbeh Pournader | 309ebd6 | 2016-06-17 22:13:12 -0700 | [diff] [blame] | 2211 | final StringBuilder sb = new StringBuilder(); |
Roozbeh Pournader | 47f71a6 | 2015-11-07 11:55:38 -0800 | [diff] [blame] | 2212 | for (int i = 0; i < locs.size(); i++) { |
Roozbeh Pournader | 309ebd6 | 2016-06-17 22:13:12 -0700 | [diff] [blame] | 2213 | final Locale loc = locs.get(i); |
| 2214 | final int l = loc.getLanguage().length(); |
| 2215 | if (l == 0) { |
| 2216 | continue; |
| 2217 | } |
| 2218 | final int s = loc.getScript().length(); |
| 2219 | final int c = loc.getCountry().length(); |
| 2220 | final int v = loc.getVariant().length(); |
| 2221 | // We ignore locale extensions, since they are not supported by AAPT |
| 2222 | |
| 2223 | if (sb.length() != 0) { |
| 2224 | sb.append(","); |
| 2225 | } |
| 2226 | if (l == 2 && s == 0 && (c == 0 || c == 2) && v == 0) { |
| 2227 | // Traditional locale format: xx or xx-rYY |
Roozbeh Pournader | 47f71a6 | 2015-11-07 11:55:38 -0800 | [diff] [blame] | 2228 | sb.append(loc.getLanguage()); |
Roozbeh Pournader | 309ebd6 | 2016-06-17 22:13:12 -0700 | [diff] [blame] | 2229 | if (c == 2) { |
Roozbeh Pournader | 47f71a6 | 2015-11-07 11:55:38 -0800 | [diff] [blame] | 2230 | sb.append("-r").append(loc.getCountry()); |
Roozbeh Pournader | 309ebd6 | 2016-06-17 22:13:12 -0700 | [diff] [blame] | 2231 | } |
| 2232 | } else { |
| 2233 | sb.append("b+"); |
| 2234 | sb.append(loc.getLanguage()); |
| 2235 | if (s != 0) { |
| 2236 | sb.append("+"); |
| 2237 | sb.append(loc.getScript()); |
| 2238 | } |
| 2239 | if (c != 0) { |
| 2240 | sb.append("+"); |
| 2241 | sb.append(loc.getCountry()); |
| 2242 | } |
| 2243 | if (v != 0) { |
| 2244 | sb.append("+"); |
| 2245 | sb.append(loc.getVariant()); |
Adam Lesinski | 2c749d2 | 2014-06-04 13:00:29 -0700 | [diff] [blame] | 2246 | } |
| 2247 | } |
| 2248 | } |
| 2249 | return sb.toString(); |
| 2250 | } |
| 2251 | |
| 2252 | |
| 2253 | /** |
| 2254 | * Returns a string representation of the configuration that can be parsed |
Dianne Hackborn | bf5ba6b | 2018-02-20 10:31:02 -0800 | [diff] [blame] | 2255 | * by build tools (like AAPT), without display metrics included |
Adam Lesinski | 2c749d2 | 2014-06-04 13:00:29 -0700 | [diff] [blame] | 2256 | * |
Adam Lesinski | 2c749d2 | 2014-06-04 13:00:29 -0700 | [diff] [blame] | 2257 | * @hide |
| 2258 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 2259 | @UnsupportedAppUsage |
Adam Lesinski | 2c749d2 | 2014-06-04 13:00:29 -0700 | [diff] [blame] | 2260 | public static String resourceQualifierString(Configuration config) { |
Dianne Hackborn | bf5ba6b | 2018-02-20 10:31:02 -0800 | [diff] [blame] | 2261 | return resourceQualifierString(config, null); |
| 2262 | } |
| 2263 | |
| 2264 | /** |
| 2265 | * Returns a string representation of the configuration that can be parsed |
| 2266 | * by build tools (like AAPT). |
| 2267 | * |
| 2268 | * @hide |
| 2269 | */ |
| 2270 | public static String resourceQualifierString(Configuration config, DisplayMetrics metrics) { |
Adam Lesinski | 2c749d2 | 2014-06-04 13:00:29 -0700 | [diff] [blame] | 2271 | ArrayList<String> parts = new ArrayList<String>(); |
| 2272 | |
| 2273 | if (config.mcc != 0) { |
Adam Lesinski | 9086562 | 2014-10-16 18:18:10 -0700 | [diff] [blame] | 2274 | parts.add("mcc" + config.mcc); |
Adam Lesinski | 2c749d2 | 2014-06-04 13:00:29 -0700 | [diff] [blame] | 2275 | if (config.mnc != 0) { |
Adam Lesinski | 9086562 | 2014-10-16 18:18:10 -0700 | [diff] [blame] | 2276 | parts.add("mnc" + config.mnc); |
Adam Lesinski | 2c749d2 | 2014-06-04 13:00:29 -0700 | [diff] [blame] | 2277 | } |
| 2278 | } |
| 2279 | |
Roozbeh Pournader | 47f71a6 | 2015-11-07 11:55:38 -0800 | [diff] [blame] | 2280 | if (!config.mLocaleList.isEmpty()) { |
Roozbeh Pournader | 417bbe0 | 2015-11-09 17:09:15 -0800 | [diff] [blame] | 2281 | final String resourceQualifier = localesToResourceQualifier(config.mLocaleList); |
| 2282 | if (!resourceQualifier.isEmpty()) { |
| 2283 | parts.add(resourceQualifier); |
| 2284 | } |
Adam Lesinski | 2c749d2 | 2014-06-04 13:00:29 -0700 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | switch (config.screenLayout & Configuration.SCREENLAYOUT_LAYOUTDIR_MASK) { |
| 2288 | case Configuration.SCREENLAYOUT_LAYOUTDIR_LTR: |
| 2289 | parts.add("ldltr"); |
| 2290 | break; |
| 2291 | case Configuration.SCREENLAYOUT_LAYOUTDIR_RTL: |
| 2292 | parts.add("ldrtl"); |
| 2293 | break; |
| 2294 | default: |
| 2295 | break; |
| 2296 | } |
| 2297 | |
| 2298 | if (config.smallestScreenWidthDp != 0) { |
| 2299 | parts.add("sw" + config.smallestScreenWidthDp + "dp"); |
| 2300 | } |
| 2301 | |
| 2302 | if (config.screenWidthDp != 0) { |
| 2303 | parts.add("w" + config.screenWidthDp + "dp"); |
| 2304 | } |
| 2305 | |
| 2306 | if (config.screenHeightDp != 0) { |
| 2307 | parts.add("h" + config.screenHeightDp + "dp"); |
| 2308 | } |
| 2309 | |
| 2310 | switch (config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) { |
| 2311 | case Configuration.SCREENLAYOUT_SIZE_SMALL: |
| 2312 | parts.add("small"); |
| 2313 | break; |
| 2314 | case Configuration.SCREENLAYOUT_SIZE_NORMAL: |
| 2315 | parts.add("normal"); |
| 2316 | break; |
| 2317 | case Configuration.SCREENLAYOUT_SIZE_LARGE: |
| 2318 | parts.add("large"); |
| 2319 | break; |
| 2320 | case Configuration.SCREENLAYOUT_SIZE_XLARGE: |
| 2321 | parts.add("xlarge"); |
| 2322 | break; |
| 2323 | default: |
| 2324 | break; |
| 2325 | } |
| 2326 | |
| 2327 | switch (config.screenLayout & Configuration.SCREENLAYOUT_LONG_MASK) { |
| 2328 | case Configuration.SCREENLAYOUT_LONG_YES: |
| 2329 | parts.add("long"); |
| 2330 | break; |
| 2331 | case Configuration.SCREENLAYOUT_LONG_NO: |
| 2332 | parts.add("notlong"); |
| 2333 | break; |
| 2334 | default: |
| 2335 | break; |
| 2336 | } |
| 2337 | |
Adam Powell | 49e7ff9 | 2015-05-14 16:18:53 -0700 | [diff] [blame] | 2338 | switch (config.screenLayout & Configuration.SCREENLAYOUT_ROUND_MASK) { |
| 2339 | case Configuration.SCREENLAYOUT_ROUND_YES: |
| 2340 | parts.add("round"); |
| 2341 | break; |
| 2342 | case Configuration.SCREENLAYOUT_ROUND_NO: |
| 2343 | parts.add("notround"); |
| 2344 | break; |
| 2345 | default: |
| 2346 | break; |
| 2347 | } |
| 2348 | |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 2349 | switch (config.colorMode & Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_MASK) { |
| 2350 | case Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES: |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 2351 | parts.add("widecg"); |
| 2352 | break; |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 2353 | case Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO: |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 2354 | parts.add("nowidecg"); |
| 2355 | break; |
| 2356 | default: |
| 2357 | break; |
| 2358 | } |
| 2359 | |
Chia-I Wu | 0d8acf5 | 2018-05-09 12:08:05 -0700 | [diff] [blame] | 2360 | switch (config.colorMode & Configuration.COLOR_MODE_HDR_MASK) { |
| 2361 | case Configuration.COLOR_MODE_HDR_YES: |
| 2362 | parts.add("highdr"); |
| 2363 | break; |
| 2364 | case Configuration.COLOR_MODE_HDR_NO: |
| 2365 | parts.add("lowdr"); |
| 2366 | break; |
| 2367 | default: |
| 2368 | break; |
| 2369 | } |
| 2370 | |
Adam Lesinski | 2c749d2 | 2014-06-04 13:00:29 -0700 | [diff] [blame] | 2371 | switch (config.orientation) { |
| 2372 | case Configuration.ORIENTATION_LANDSCAPE: |
| 2373 | parts.add("land"); |
| 2374 | break; |
| 2375 | case Configuration.ORIENTATION_PORTRAIT: |
| 2376 | parts.add("port"); |
| 2377 | break; |
| 2378 | default: |
| 2379 | break; |
| 2380 | } |
| 2381 | |
| 2382 | switch (config.uiMode & Configuration.UI_MODE_TYPE_MASK) { |
| 2383 | case Configuration.UI_MODE_TYPE_APPLIANCE: |
| 2384 | parts.add("appliance"); |
| 2385 | break; |
| 2386 | case Configuration.UI_MODE_TYPE_DESK: |
| 2387 | parts.add("desk"); |
| 2388 | break; |
| 2389 | case Configuration.UI_MODE_TYPE_TELEVISION: |
| 2390 | parts.add("television"); |
| 2391 | break; |
| 2392 | case Configuration.UI_MODE_TYPE_CAR: |
| 2393 | parts.add("car"); |
| 2394 | break; |
| 2395 | case Configuration.UI_MODE_TYPE_WATCH: |
| 2396 | parts.add("watch"); |
| 2397 | break; |
Zak Cohen | 1a6acdb | 2016-12-12 15:21:21 -0800 | [diff] [blame] | 2398 | case Configuration.UI_MODE_TYPE_VR_HEADSET: |
| 2399 | parts.add("vrheadset"); |
| 2400 | break; |
Adam Lesinski | 2c749d2 | 2014-06-04 13:00:29 -0700 | [diff] [blame] | 2401 | default: |
| 2402 | break; |
| 2403 | } |
| 2404 | |
| 2405 | switch (config.uiMode & Configuration.UI_MODE_NIGHT_MASK) { |
| 2406 | case Configuration.UI_MODE_NIGHT_YES: |
| 2407 | parts.add("night"); |
| 2408 | break; |
| 2409 | case Configuration.UI_MODE_NIGHT_NO: |
| 2410 | parts.add("notnight"); |
| 2411 | break; |
| 2412 | default: |
| 2413 | break; |
| 2414 | } |
| 2415 | |
| 2416 | switch (config.densityDpi) { |
Adam Lesinski | 31245b4 | 2014-08-22 19:10:56 -0700 | [diff] [blame] | 2417 | case DENSITY_DPI_UNDEFINED: |
Adam Lesinski | 2c749d2 | 2014-06-04 13:00:29 -0700 | [diff] [blame] | 2418 | break; |
| 2419 | case 120: |
| 2420 | parts.add("ldpi"); |
| 2421 | break; |
| 2422 | case 160: |
| 2423 | parts.add("mdpi"); |
| 2424 | break; |
| 2425 | case 213: |
| 2426 | parts.add("tvdpi"); |
| 2427 | break; |
| 2428 | case 240: |
| 2429 | parts.add("hdpi"); |
| 2430 | break; |
| 2431 | case 320: |
| 2432 | parts.add("xhdpi"); |
| 2433 | break; |
Adam Lesinski | ebc3e4c | 2014-08-21 12:21:45 -0700 | [diff] [blame] | 2434 | case 480: |
| 2435 | parts.add("xxhdpi"); |
| 2436 | break; |
| 2437 | case 640: |
| 2438 | parts.add("xxxhdpi"); |
| 2439 | break; |
Adam Lesinski | 31245b4 | 2014-08-22 19:10:56 -0700 | [diff] [blame] | 2440 | case DENSITY_DPI_ANY: |
| 2441 | parts.add("anydpi"); |
| 2442 | break; |
| 2443 | case DENSITY_DPI_NONE: |
| 2444 | parts.add("nodpi"); |
Christian Williams | b709f3c | 2017-11-02 17:19:27 -0700 | [diff] [blame] | 2445 | break; |
Adam Lesinski | 2c749d2 | 2014-06-04 13:00:29 -0700 | [diff] [blame] | 2446 | default: |
| 2447 | parts.add(config.densityDpi + "dpi"); |
| 2448 | break; |
| 2449 | } |
| 2450 | |
| 2451 | switch (config.touchscreen) { |
| 2452 | case Configuration.TOUCHSCREEN_NOTOUCH: |
| 2453 | parts.add("notouch"); |
| 2454 | break; |
| 2455 | case Configuration.TOUCHSCREEN_FINGER: |
| 2456 | parts.add("finger"); |
| 2457 | break; |
| 2458 | default: |
| 2459 | break; |
| 2460 | } |
| 2461 | |
| 2462 | switch (config.keyboardHidden) { |
| 2463 | case Configuration.KEYBOARDHIDDEN_NO: |
| 2464 | parts.add("keysexposed"); |
| 2465 | break; |
| 2466 | case Configuration.KEYBOARDHIDDEN_YES: |
| 2467 | parts.add("keyshidden"); |
| 2468 | break; |
| 2469 | case Configuration.KEYBOARDHIDDEN_SOFT: |
| 2470 | parts.add("keyssoft"); |
| 2471 | break; |
| 2472 | default: |
| 2473 | break; |
| 2474 | } |
| 2475 | |
| 2476 | switch (config.keyboard) { |
| 2477 | case Configuration.KEYBOARD_NOKEYS: |
| 2478 | parts.add("nokeys"); |
| 2479 | break; |
| 2480 | case Configuration.KEYBOARD_QWERTY: |
| 2481 | parts.add("qwerty"); |
| 2482 | break; |
| 2483 | case Configuration.KEYBOARD_12KEY: |
| 2484 | parts.add("12key"); |
| 2485 | break; |
| 2486 | default: |
| 2487 | break; |
| 2488 | } |
| 2489 | |
| 2490 | switch (config.navigationHidden) { |
| 2491 | case Configuration.NAVIGATIONHIDDEN_NO: |
| 2492 | parts.add("navexposed"); |
| 2493 | break; |
| 2494 | case Configuration.NAVIGATIONHIDDEN_YES: |
| 2495 | parts.add("navhidden"); |
| 2496 | break; |
| 2497 | default: |
| 2498 | break; |
| 2499 | } |
| 2500 | |
| 2501 | switch (config.navigation) { |
| 2502 | case Configuration.NAVIGATION_NONAV: |
| 2503 | parts.add("nonav"); |
| 2504 | break; |
| 2505 | case Configuration.NAVIGATION_DPAD: |
| 2506 | parts.add("dpad"); |
| 2507 | break; |
| 2508 | case Configuration.NAVIGATION_TRACKBALL: |
| 2509 | parts.add("trackball"); |
| 2510 | break; |
| 2511 | case Configuration.NAVIGATION_WHEEL: |
| 2512 | parts.add("wheel"); |
| 2513 | break; |
| 2514 | default: |
| 2515 | break; |
| 2516 | } |
| 2517 | |
Dianne Hackborn | bf5ba6b | 2018-02-20 10:31:02 -0800 | [diff] [blame] | 2518 | if (metrics != null) { |
| 2519 | final int width, height; |
| 2520 | if (metrics.widthPixels >= metrics.heightPixels) { |
| 2521 | width = metrics.widthPixels; |
| 2522 | height = metrics.heightPixels; |
| 2523 | } else { |
| 2524 | //noinspection SuspiciousNameCombination |
| 2525 | width = metrics.heightPixels; |
| 2526 | //noinspection SuspiciousNameCombination |
| 2527 | height = metrics.widthPixels; |
| 2528 | } |
| 2529 | parts.add(width + "x" + height); |
| 2530 | } |
| 2531 | |
Adam Lesinski | ebc3e4c | 2014-08-21 12:21:45 -0700 | [diff] [blame] | 2532 | parts.add("v" + Build.VERSION.RESOURCES_SDK_INT); |
Adam Lesinski | 2c749d2 | 2014-06-04 13:00:29 -0700 | [diff] [blame] | 2533 | return TextUtils.join("-", parts); |
| 2534 | } |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 2535 | |
| 2536 | /** |
| 2537 | * Generate a delta Configuration between <code>base</code> and <code>change</code>. The |
| 2538 | * resulting delta can be used with {@link #updateFrom(Configuration)}. |
| 2539 | * <p /> |
| 2540 | * Caveat: If the any of the Configuration's members becomes undefined, then |
| 2541 | * {@link #updateFrom(Configuration)} will treat it as a no-op and not update that member. |
| 2542 | * |
| 2543 | * This is fine for device configurations as no member is ever undefined. |
| 2544 | * {@hide} |
| 2545 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 2546 | @UnsupportedAppUsage |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 2547 | public static Configuration generateDelta(Configuration base, Configuration change) { |
| 2548 | final Configuration delta = new Configuration(); |
| 2549 | if (base.fontScale != change.fontScale) { |
| 2550 | delta.fontScale = change.fontScale; |
| 2551 | } |
| 2552 | |
| 2553 | if (base.mcc != change.mcc) { |
| 2554 | delta.mcc = change.mcc; |
| 2555 | } |
| 2556 | |
| 2557 | if (base.mnc != change.mnc) { |
| 2558 | delta.mnc = change.mnc; |
| 2559 | } |
| 2560 | |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 2561 | base.fixUpLocaleList(); |
| 2562 | change.fixUpLocaleList(); |
| 2563 | if (!base.mLocaleList.equals(change.mLocaleList)) { |
| 2564 | delta.mLocaleList = change.mLocaleList; |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 2565 | delta.locale = change.locale; |
| 2566 | } |
| 2567 | |
| 2568 | if (base.touchscreen != change.touchscreen) { |
| 2569 | delta.touchscreen = change.touchscreen; |
| 2570 | } |
| 2571 | |
| 2572 | if (base.keyboard != change.keyboard) { |
| 2573 | delta.keyboard = change.keyboard; |
| 2574 | } |
| 2575 | |
| 2576 | if (base.keyboardHidden != change.keyboardHidden) { |
| 2577 | delta.keyboardHidden = change.keyboardHidden; |
| 2578 | } |
| 2579 | |
| 2580 | if (base.navigation != change.navigation) { |
| 2581 | delta.navigation = change.navigation; |
| 2582 | } |
| 2583 | |
| 2584 | if (base.navigationHidden != change.navigationHidden) { |
| 2585 | delta.navigationHidden = change.navigationHidden; |
| 2586 | } |
| 2587 | |
| 2588 | if (base.orientation != change.orientation) { |
| 2589 | delta.orientation = change.orientation; |
| 2590 | } |
| 2591 | |
| 2592 | if ((base.screenLayout & SCREENLAYOUT_SIZE_MASK) != |
| 2593 | (change.screenLayout & SCREENLAYOUT_SIZE_MASK)) { |
| 2594 | delta.screenLayout |= change.screenLayout & SCREENLAYOUT_SIZE_MASK; |
| 2595 | } |
| 2596 | |
| 2597 | if ((base.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK) != |
| 2598 | (change.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK)) { |
| 2599 | delta.screenLayout |= change.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK; |
| 2600 | } |
| 2601 | |
| 2602 | if ((base.screenLayout & SCREENLAYOUT_LONG_MASK) != |
| 2603 | (change.screenLayout & SCREENLAYOUT_LONG_MASK)) { |
| 2604 | delta.screenLayout |= change.screenLayout & SCREENLAYOUT_LONG_MASK; |
| 2605 | } |
| 2606 | |
Adam Powell | 49e7ff9 | 2015-05-14 16:18:53 -0700 | [diff] [blame] | 2607 | if ((base.screenLayout & SCREENLAYOUT_ROUND_MASK) != |
| 2608 | (change.screenLayout & SCREENLAYOUT_ROUND_MASK)) { |
| 2609 | delta.screenLayout |= change.screenLayout & SCREENLAYOUT_ROUND_MASK; |
| 2610 | } |
| 2611 | |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 2612 | if ((base.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK) != |
| 2613 | (change.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK)) { |
| 2614 | delta.colorMode |= change.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK; |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 2615 | } |
| 2616 | |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 2617 | if ((base.colorMode & COLOR_MODE_HDR_MASK) != |
| 2618 | (change.colorMode & COLOR_MODE_HDR_MASK)) { |
| 2619 | delta.colorMode |= change.colorMode & COLOR_MODE_HDR_MASK; |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 2620 | } |
| 2621 | |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 2622 | if ((base.uiMode & UI_MODE_TYPE_MASK) != (change.uiMode & UI_MODE_TYPE_MASK)) { |
| 2623 | delta.uiMode |= change.uiMode & UI_MODE_TYPE_MASK; |
| 2624 | } |
| 2625 | |
| 2626 | if ((base.uiMode & UI_MODE_NIGHT_MASK) != (change.uiMode & UI_MODE_NIGHT_MASK)) { |
| 2627 | delta.uiMode |= change.uiMode & UI_MODE_NIGHT_MASK; |
| 2628 | } |
| 2629 | |
| 2630 | if (base.screenWidthDp != change.screenWidthDp) { |
| 2631 | delta.screenWidthDp = change.screenWidthDp; |
| 2632 | } |
| 2633 | |
| 2634 | if (base.screenHeightDp != change.screenHeightDp) { |
| 2635 | delta.screenHeightDp = change.screenHeightDp; |
| 2636 | } |
| 2637 | |
| 2638 | if (base.smallestScreenWidthDp != change.smallestScreenWidthDp) { |
| 2639 | delta.smallestScreenWidthDp = change.smallestScreenWidthDp; |
| 2640 | } |
| 2641 | |
| 2642 | if (base.densityDpi != change.densityDpi) { |
| 2643 | delta.densityDpi = change.densityDpi; |
| 2644 | } |
Mårten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 2645 | |
| 2646 | if (base.assetsSeq != change.assetsSeq) { |
| 2647 | delta.assetsSeq = change.assetsSeq; |
| 2648 | } |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 2649 | |
| 2650 | if (!base.windowConfiguration.equals(change.windowConfiguration)) { |
| 2651 | delta.windowConfiguration.setTo(change.windowConfiguration); |
| 2652 | } |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 2653 | return delta; |
| 2654 | } |
| 2655 | |
| 2656 | private static final String XML_ATTR_FONT_SCALE = "fs"; |
| 2657 | private static final String XML_ATTR_MCC = "mcc"; |
| 2658 | private static final String XML_ATTR_MNC = "mnc"; |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 2659 | private static final String XML_ATTR_LOCALES = "locales"; |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 2660 | private static final String XML_ATTR_TOUCHSCREEN = "touch"; |
| 2661 | private static final String XML_ATTR_KEYBOARD = "key"; |
| 2662 | private static final String XML_ATTR_KEYBOARD_HIDDEN = "keyHid"; |
| 2663 | private static final String XML_ATTR_HARD_KEYBOARD_HIDDEN = "hardKeyHid"; |
| 2664 | private static final String XML_ATTR_NAVIGATION = "nav"; |
| 2665 | private static final String XML_ATTR_NAVIGATION_HIDDEN = "navHid"; |
| 2666 | private static final String XML_ATTR_ORIENTATION = "ori"; |
Bryce Lee | c1f2f2a | 2017-06-22 15:29:42 -0700 | [diff] [blame] | 2667 | private static final String XML_ATTR_ROTATION = "rot"; |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 2668 | private static final String XML_ATTR_SCREEN_LAYOUT = "scrLay"; |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 2669 | private static final String XML_ATTR_COLOR_MODE = "clrMod"; |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 2670 | private static final String XML_ATTR_UI_MODE = "ui"; |
| 2671 | private static final String XML_ATTR_SCREEN_WIDTH = "width"; |
| 2672 | private static final String XML_ATTR_SCREEN_HEIGHT = "height"; |
| 2673 | private static final String XML_ATTR_SMALLEST_WIDTH = "sw"; |
| 2674 | private static final String XML_ATTR_DENSITY = "density"; |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 2675 | private static final String XML_ATTR_APP_BOUNDS = "app_bounds"; |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 2676 | |
| 2677 | /** |
| 2678 | * Reads the attributes corresponding to Configuration member fields from the Xml parser. |
| 2679 | * The parser is expected to be on a tag which has Configuration attributes. |
| 2680 | * |
| 2681 | * @param parser The Xml parser from which to read attributes. |
| 2682 | * @param configOut The Configuration to populate from the Xml attributes. |
| 2683 | * {@hide} |
| 2684 | */ |
| 2685 | public static void readXmlAttrs(XmlPullParser parser, Configuration configOut) |
| 2686 | throws XmlPullParserException, IOException { |
| 2687 | configOut.fontScale = Float.intBitsToFloat( |
| 2688 | XmlUtils.readIntAttribute(parser, XML_ATTR_FONT_SCALE, 0)); |
| 2689 | configOut.mcc = XmlUtils.readIntAttribute(parser, XML_ATTR_MCC, 0); |
| 2690 | configOut.mnc = XmlUtils.readIntAttribute(parser, XML_ATTR_MNC, 0); |
| 2691 | |
Roozbeh Pournader | b46fdd4 | 2015-08-19 14:56:22 -0700 | [diff] [blame] | 2692 | final String localesStr = XmlUtils.readStringAttribute(parser, XML_ATTR_LOCALES); |
| 2693 | configOut.mLocaleList = LocaleList.forLanguageTags(localesStr); |
Roozbeh Pournader | fee4484 | 2016-02-04 15:24:24 -0800 | [diff] [blame] | 2694 | configOut.locale = configOut.mLocaleList.get(0); |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 2695 | |
| 2696 | configOut.touchscreen = XmlUtils.readIntAttribute(parser, XML_ATTR_TOUCHSCREEN, |
| 2697 | TOUCHSCREEN_UNDEFINED); |
| 2698 | configOut.keyboard = XmlUtils.readIntAttribute(parser, XML_ATTR_KEYBOARD, |
| 2699 | KEYBOARD_UNDEFINED); |
| 2700 | configOut.keyboardHidden = XmlUtils.readIntAttribute(parser, XML_ATTR_KEYBOARD_HIDDEN, |
| 2701 | KEYBOARDHIDDEN_UNDEFINED); |
| 2702 | configOut.hardKeyboardHidden = |
| 2703 | XmlUtils.readIntAttribute(parser, XML_ATTR_HARD_KEYBOARD_HIDDEN, |
| 2704 | HARDKEYBOARDHIDDEN_UNDEFINED); |
| 2705 | configOut.navigation = XmlUtils.readIntAttribute(parser, XML_ATTR_NAVIGATION, |
| 2706 | NAVIGATION_UNDEFINED); |
| 2707 | configOut.navigationHidden = XmlUtils.readIntAttribute(parser, XML_ATTR_NAVIGATION_HIDDEN, |
| 2708 | NAVIGATIONHIDDEN_UNDEFINED); |
| 2709 | configOut.orientation = XmlUtils.readIntAttribute(parser, XML_ATTR_ORIENTATION, |
| 2710 | ORIENTATION_UNDEFINED); |
| 2711 | configOut.screenLayout = XmlUtils.readIntAttribute(parser, XML_ATTR_SCREEN_LAYOUT, |
| 2712 | SCREENLAYOUT_UNDEFINED); |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 2713 | configOut.colorMode = XmlUtils.readIntAttribute(parser, XML_ATTR_COLOR_MODE, |
| 2714 | COLOR_MODE_UNDEFINED); |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 2715 | configOut.uiMode = XmlUtils.readIntAttribute(parser, XML_ATTR_UI_MODE, 0); |
| 2716 | configOut.screenWidthDp = XmlUtils.readIntAttribute(parser, XML_ATTR_SCREEN_WIDTH, |
| 2717 | SCREEN_WIDTH_DP_UNDEFINED); |
| 2718 | configOut.screenHeightDp = XmlUtils.readIntAttribute(parser, XML_ATTR_SCREEN_HEIGHT, |
| 2719 | SCREEN_HEIGHT_DP_UNDEFINED); |
| 2720 | configOut.smallestScreenWidthDp = |
| 2721 | XmlUtils.readIntAttribute(parser, XML_ATTR_SMALLEST_WIDTH, |
| 2722 | SMALLEST_SCREEN_WIDTH_DP_UNDEFINED); |
| 2723 | configOut.densityDpi = XmlUtils.readIntAttribute(parser, XML_ATTR_DENSITY, |
| 2724 | DENSITY_DPI_UNDEFINED); |
Mårten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 2725 | |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 2726 | // For persistence, we don't care about assetsSeq and WindowConfiguration, so do not read it |
| 2727 | // out. |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 2728 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2729 | } |