1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 package com.android.settings.display; 15 16 import android.content.Context; 17 import android.graphics.drawable.Drawable; 18 import android.support.annotation.VisibleForTesting; 19 20 import com.android.internal.app.NightDisplayController; 21 import com.android.internal.logging.nano.MetricsProto; 22 23 import com.android.settings.R; 24 import com.android.settings.widget.RadioButtonPickerFragment; 25 26 import java.util.Arrays; 27 import java.util.List; 28 29 @SuppressWarnings("WeakerAccess") 30 public class ColorModePreferenceFragment extends RadioButtonPickerFragment { 31 32 @VisibleForTesting 33 static final String KEY_COLOR_MODE_NATURAL = "color_mode_natural"; 34 @VisibleForTesting 35 static final String KEY_COLOR_MODE_BOOSTED = "color_mode_boosted"; 36 @VisibleForTesting 37 static final String KEY_COLOR_MODE_SATURATED = "color_mode_saturated"; 38 39 private NightDisplayController mController; 40 41 @Override 42 public void onAttach(Context context) { 43 super.onAttach(context); 44 mController = new NightDisplayController(context); 45 } 46 47 @Override 48 protected List<? extends CandidateInfo> getCandidates() { 49 Context c = getContext(); 50 return Arrays.asList( 51 new ColorModeCandidateInfo(c.getString(R.string.color_mode_option_natural), 52 KEY_COLOR_MODE_NATURAL), 53 new ColorModeCandidateInfo(c.getString(R.string.color_mode_option_boosted), 54 KEY_COLOR_MODE_BOOSTED), 55 new ColorModeCandidateInfo(c.getString(R.string.color_mode_option_saturated), 56 KEY_COLOR_MODE_SATURATED) 57 ); 58 } 59 60 @Override 61 protected String getDefaultKey() { 62 if (mController.getColorMode() == NightDisplayController.COLOR_MODE_SATURATED) { 63 return KEY_COLOR_MODE_SATURATED; 64 } 65 if (mController.getColorMode() == NightDisplayController.COLOR_MODE_BOOSTED) { 66 return KEY_COLOR_MODE_BOOSTED; 67 } 68 return KEY_COLOR_MODE_NATURAL; 69 } 70 71 @Override 72 protected boolean setDefaultKey(String key) { 73 switch (key) { 74 case KEY_COLOR_MODE_NATURAL: 75 mController.setColorMode(NightDisplayController.COLOR_MODE_NATURAL); 76 break; 77 case KEY_COLOR_MODE_BOOSTED: 78 mController.setColorMode(NightDisplayController.COLOR_MODE_BOOSTED); 79 break; 80 case KEY_COLOR_MODE_SATURATED: 81 mController.setColorMode(NightDisplayController.COLOR_MODE_SATURATED); 82 break; 83 } 84 return true; 85 } 86 87 @Override 88 public int getMetricsCategory() { 89 return MetricsProto.MetricsEvent.COLOR_MODE_SETTINGS; 90 } 91 92 @VisibleForTesting 93 static class ColorModeCandidateInfo extends CandidateInfo { 94 private final CharSequence mLabel; 95 private final String mKey; 96 97 ColorModeCandidateInfo(CharSequence label, String key) { 98 super(true); 99 mLabel = label; 100 mKey = key; 101 } 102 103 @Override 104 public CharSequence loadLabel() { 105 return mLabel; 106 } 107 108 @Override 109 public Drawable loadIcon() { 110 return null; 111 } 112 113 @Override 114 public String getKey() { 115 return mKey; 116 } 117 } 118 119 } 120