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