195357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler/*
295357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler * Copyright (C) 2015 The Android Open Source Project
395357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler *
495357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler * Licensed under the Apache License, Version 2.0 (the "License");
595357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler * you may not use this file except in compliance with the License.
695357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler * You may obtain a copy of the License at
795357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler *
895357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler *      http://www.apache.org/licenses/LICENSE-2.0
995357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler *
1095357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler * Unless required by applicable law or agreed to in writing, software
1195357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler * distributed under the License is distributed on an "AS IS" BASIS,
1295357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1395357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler * See the License for the specific language governing permissions and
1495357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler * limitations under the License
1595357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler */
1695357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler
1795357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantlerpackage com.android.settingslib.applications;
1895357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler
1995357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantlerimport android.content.pm.ActivityInfo;
2095357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantlerimport android.content.res.Configuration;
2195357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantlerimport android.content.res.Resources;
2295357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler
2395357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantlerpublic class InterestingConfigChanges {
2495357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler    private final Configuration mLastConfiguration = new Configuration();
259c7844cb91b43929d0a86b1c90aa1efb37f5463aJason Monk    private final int mFlags;
2695357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler    private int mLastDensity;
2795357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler
289c7844cb91b43929d0a86b1c90aa1efb37f5463aJason Monk    public InterestingConfigChanges() {
293edad31233d391eb55ffe688beb1234b5b79be8fJason Monk        this(ActivityInfo.CONFIG_LOCALE
303edad31233d391eb55ffe688beb1234b5b79be8fJason Monk                | ActivityInfo.CONFIG_UI_MODE | ActivityInfo.CONFIG_SCREEN_LAYOUT
313edad31233d391eb55ffe688beb1234b5b79be8fJason Monk                | ActivityInfo.CONFIG_ASSETS_PATHS);
329c7844cb91b43929d0a86b1c90aa1efb37f5463aJason Monk    }
339c7844cb91b43929d0a86b1c90aa1efb37f5463aJason Monk
343edad31233d391eb55ffe688beb1234b5b79be8fJason Monk    public InterestingConfigChanges(int flags) {
353edad31233d391eb55ffe688beb1234b5b79be8fJason Monk        mFlags = flags;
369c7844cb91b43929d0a86b1c90aa1efb37f5463aJason Monk    }
379c7844cb91b43929d0a86b1c90aa1efb37f5463aJason Monk
3895357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler    public boolean applyNewConfig(Resources res) {
39f3fe3bf5b97c78b141e7cee738a3011998840bf7Jason Monk        int configChanges = mLastConfiguration.updateFrom(
40f3fe3bf5b97c78b141e7cee738a3011998840bf7Jason Monk                Configuration.generateDelta(mLastConfiguration, res.getConfiguration()));
4195357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler        boolean densityChanged = mLastDensity != res.getDisplayMetrics().densityDpi;
429c7844cb91b43929d0a86b1c90aa1efb37f5463aJason Monk        if (densityChanged || (configChanges & (mFlags)) != 0) {
4395357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler            mLastDensity = res.getDisplayMetrics().densityDpi;
4495357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler            return true;
4595357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler        }
4695357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler        return false;
4795357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler    }
4895357fd49a0ffce4c0b653753c013cf951ebac21Tony Mantler}
49