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