• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.settings.development;
18 
19 import static android.provider.Settings.Global.DEVELOPMENT_ENABLE_NON_RESIZABLE_MULTI_WINDOW;
20 
21 import android.content.Context;
22 import android.provider.Settings;
23 
24 import androidx.annotation.VisibleForTesting;
25 import androidx.preference.Preference;
26 import androidx.preference.SwitchPreference;
27 
28 import com.android.settings.core.PreferenceControllerMixin;
29 import com.android.settingslib.development.DeveloperOptionsPreferenceController;
30 
31 /**
32  * Preference Controller for whether to allow launching non-resizable apps in multi window,
33  * such as freeform and splitscreen.
34  */
35 public class NonResizableMultiWindowPreferenceController
36         extends DeveloperOptionsPreferenceController
37         implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
38 
39     private static final String ENABLE_NON_RESIZABLE_MULTI_WINDOW_KEY =
40             "enable_non_resizable_multi_window";
41 
42     @VisibleForTesting
43     static final int SETTING_VALUE_OFF = 0;
44     @VisibleForTesting
45     static final int SETTING_VALUE_ON = 1;
46 
NonResizableMultiWindowPreferenceController(Context context)47     public NonResizableMultiWindowPreferenceController(Context context) {
48         super(context);
49     }
50 
51     @Override
getPreferenceKey()52     public String getPreferenceKey() {
53         return ENABLE_NON_RESIZABLE_MULTI_WINDOW_KEY;
54     }
55 
56     @Override
onPreferenceChange(Preference preference, Object newValue)57     public boolean onPreferenceChange(Preference preference, Object newValue) {
58         final boolean isEnabled = (Boolean) newValue;
59         Settings.Global.putInt(mContext.getContentResolver(),
60                 DEVELOPMENT_ENABLE_NON_RESIZABLE_MULTI_WINDOW,
61                 isEnabled ? SETTING_VALUE_ON : SETTING_VALUE_OFF);
62         return true;
63     }
64 
65     @Override
updateState(Preference preference)66     public void updateState(Preference preference) {
67         final int mode = Settings.Global.getInt(mContext.getContentResolver(),
68                 DEVELOPMENT_ENABLE_NON_RESIZABLE_MULTI_WINDOW, SETTING_VALUE_OFF);
69         ((SwitchPreference) mPreference).setChecked(mode != SETTING_VALUE_OFF);
70     }
71 
72     @Override
onDeveloperOptionsSwitchDisabled()73     protected void onDeveloperOptionsSwitchDisabled() {
74         super.onDeveloperOptionsSwitchDisabled();
75         Settings.Global.putInt(mContext.getContentResolver(),
76                 DEVELOPMENT_ENABLE_NON_RESIZABLE_MULTI_WINDOW, SETTING_VALUE_OFF);
77         ((SwitchPreference) mPreference).setChecked(false);
78     }
79 }
80