1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16 
17 package com.android.settingslib.applications;
18 
19 import android.annotation.SuppressLint;
20 import android.content.pm.ActivityInfo;
21 import android.content.res.Configuration;
22 import android.content.res.Resources;
23 
24 /**
25  * A class for applying config changes and determing if doing so resulting in any "interesting"
26  * changes.
27  */
28 public class InterestingConfigChanges {
29     private final Configuration mLastConfiguration = new Configuration();
30     private final int mFlags;
31 
InterestingConfigChanges()32     public InterestingConfigChanges() {
33         this(ActivityInfo.CONFIG_LOCALE | ActivityInfo.CONFIG_LAYOUT_DIRECTION
34                 | ActivityInfo.CONFIG_UI_MODE | ActivityInfo.CONFIG_ASSETS_PATHS
35                 | ActivityInfo.CONFIG_DENSITY);
36     }
37 
InterestingConfigChanges(int flags)38     public InterestingConfigChanges(int flags) {
39         mFlags = flags;
40     }
41 
42     /**
43      * Applies the given config change and returns whether an "interesting" change happened.
44      *
45      * @param res The source of the new config to apply
46      *
47      * @return Whether interesting changes occurred
48      */
49     @SuppressLint("NewApi")
applyNewConfig(Resources res)50     public boolean applyNewConfig(Resources res) {
51         int configChanges = mLastConfiguration.updateFrom(
52                 Configuration.generateDelta(mLastConfiguration, res.getConfiguration()));
53         return (configChanges & (mFlags)) != 0;
54     }
55 }
56