• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 android.content.Context;
20 import android.os.SystemProperties;
21 import android.text.TextUtils;
22 import android.view.ThreadedRenderer;
23 
24 import androidx.preference.ListPreference;
25 import androidx.preference.Preference;
26 
27 import com.android.settings.R;
28 import com.android.settings.core.PreferenceControllerMixin;
29 import com.android.settingslib.development.DeveloperOptionsPreferenceController;
30 import com.android.settingslib.development.SystemPropPoker;
31 
32 public class DebugNonRectClipOperationsPreferenceController extends
33         DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener,
34         PreferenceControllerMixin {
35 
36     private static final String SHOW_NON_RECTANGULAR_CLIP_KEY = "show_non_rect_clip";
37 
38     private final String[] mListValues;
39     private final String[] mListSummaries;
40 
DebugNonRectClipOperationsPreferenceController(Context context)41     public DebugNonRectClipOperationsPreferenceController(Context context) {
42         super(context);
43 
44         mListValues = context.getResources().getStringArray(R.array.show_non_rect_clip_values);
45         mListSummaries = context.getResources().getStringArray(R.array.show_non_rect_clip_entries);
46     }
47 
48     @Override
getPreferenceKey()49     public String getPreferenceKey() {
50         return SHOW_NON_RECTANGULAR_CLIP_KEY;
51     }
52 
53     @Override
onPreferenceChange(Preference preference, Object newValue)54     public boolean onPreferenceChange(Preference preference, Object newValue) {
55         writeShowNonRectClipOptions(newValue);
56         updateShowNonRectClipOptions();
57         return true;
58     }
59 
60     @Override
updateState(Preference preference)61     public void updateState(Preference preference) {
62         updateShowNonRectClipOptions();
63     }
64 
writeShowNonRectClipOptions(Object newValue)65     private void writeShowNonRectClipOptions(Object newValue) {
66         SystemProperties.set(ThreadedRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY,
67                 newValue == null ? "" : newValue.toString());
68         SystemPropPoker.getInstance().poke();
69     }
70 
updateShowNonRectClipOptions()71     private void updateShowNonRectClipOptions() {
72         final String value = SystemProperties.get(
73                 ThreadedRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY, "hide" /* default */);
74 
75         int index = 0; // default
76         for (int i = 0; i < mListValues.length; i++) {
77             if (TextUtils.equals(value, mListValues[i])) {
78                 index = i;
79                 break;
80             }
81         }
82         final ListPreference listPreference = (ListPreference) mPreference;
83         listPreference.setValue(mListValues[index]);
84         listPreference.setSummary(mListSummaries[index]);
85     }
86 }
87