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