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