• 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.display;
18 
19 import android.content.Context;
20 import android.graphics.drawable.Drawable;
21 import android.provider.Settings;
22 import android.text.TextUtils;
23 
24 import com.android.internal.logging.nano.MetricsProto;
25 import com.android.settings.R;
26 import com.android.settings.widget.RadioButtonPickerFragment;
27 
28 import java.util.ArrayList;
29 import java.util.List;
30 
31 public class VrDisplayPreferencePicker extends RadioButtonPickerFragment {
32 
33     static final String PREF_KEY_PREFIX = "vr_display_pref_";
34 
35     @Override
getMetricsCategory()36     public int getMetricsCategory() {
37         return MetricsProto.MetricsEvent.VR_DISPLAY_PREFERENCE;
38     }
39 
40     @Override
getCandidates()41     protected List<VrCandidateInfo> getCandidates() {
42         List<VrCandidateInfo> candidates = new ArrayList<>();
43         final Context context = getContext();
44         candidates.add(new VrCandidateInfo(context, 0, R.string.display_vr_pref_low_persistence));
45         candidates.add(new VrCandidateInfo(context, 1, R.string.display_vr_pref_off));
46         return candidates;
47     }
48 
49     @Override
getDefaultKey()50     protected String getDefaultKey() {
51         int current = Settings.Secure.getIntForUser(getContext().getContentResolver(),
52                 Settings.Secure.VR_DISPLAY_MODE, Settings.Secure.VR_DISPLAY_MODE_LOW_PERSISTENCE,
53                 mUserId);
54         return PREF_KEY_PREFIX + current;
55     }
56 
57     @Override
setDefaultKey(String key)58     protected boolean setDefaultKey(String key) {
59         if (TextUtils.isEmpty(key)) {
60             return false;
61         }
62         switch (key) {
63             case PREF_KEY_PREFIX + 0:
64                 return Settings.Secure.putIntForUser(getContext().getContentResolver(),
65                         Settings.Secure.VR_DISPLAY_MODE, 0, mUserId);
66             case PREF_KEY_PREFIX + 1:
67                 return Settings.Secure.putIntForUser(getContext().getContentResolver(),
68                         Settings.Secure.VR_DISPLAY_MODE, 1, mUserId);
69         }
70         return false;
71     }
72 
73     static class VrCandidateInfo extends CandidateInfo {
74 
75         public final String label;
76         public final int value;
77 
VrCandidateInfo(Context context, int value, int resId)78         public VrCandidateInfo(Context context, int value, int resId) {
79             super(true);
80             this.value = value;
81             label = context.getString(resId);
82         }
83 
84         @Override
loadLabel()85         public CharSequence loadLabel() {
86             return label;
87         }
88 
89         @Override
loadIcon()90         public Drawable loadIcon() {
91             return null;
92         }
93 
94         @Override
getKey()95         public String getKey() {
96             return PREF_KEY_PREFIX + value;
97         }
98     }
99 }
100