1 /* 2 * Copyright (C) 2019 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.car.developeroptions.development; 18 19 import android.content.Context; 20 21 import androidx.annotation.VisibleForTesting; 22 import androidx.preference.PreferenceScreen; 23 24 import com.android.car.developeroptions.core.PreferenceControllerMixin; 25 import com.android.settingslib.core.lifecycle.Lifecycle; 26 import com.android.settingslib.core.lifecycle.LifecycleObserver; 27 import com.android.settingslib.core.lifecycle.events.OnPause; 28 import com.android.settingslib.core.lifecycle.events.OnResume; 29 import com.android.settingslib.development.DeveloperOptionsPreferenceController; 30 31 public class PictureColorModePreferenceController extends DeveloperOptionsPreferenceController 32 implements LifecycleObserver, OnResume, OnPause, PreferenceControllerMixin { 33 34 private static final String KEY_COLOR_MODE = "picture_color_mode"; 35 36 private ColorModePreference mPreference; 37 PictureColorModePreferenceController(Context context, Lifecycle lifecycle)38 public PictureColorModePreferenceController(Context context, Lifecycle lifecycle) { 39 super(context); 40 41 if (lifecycle != null) { 42 lifecycle.addObserver(this); 43 } 44 } 45 46 @Override isAvailable()47 public boolean isAvailable() { 48 return getColorModeDescriptionsSize() > 1 && !isWideColorGamut(); 49 } 50 51 @Override getPreferenceKey()52 public String getPreferenceKey() { 53 return KEY_COLOR_MODE; 54 } 55 56 @Override displayPreference(PreferenceScreen screen)57 public void displayPreference(PreferenceScreen screen) { 58 super.displayPreference(screen); 59 mPreference = screen.findPreference(getPreferenceKey()); 60 if (mPreference != null) { 61 mPreference.updateCurrentAndSupported(); 62 } 63 } 64 65 @Override onResume()66 public void onResume() { 67 if (mPreference == null) { 68 return; 69 } 70 mPreference.startListening(); 71 mPreference.updateCurrentAndSupported(); 72 } 73 74 @Override onPause()75 public void onPause() { 76 if (mPreference == null) { 77 return; 78 } 79 mPreference.stopListening(); 80 } 81 82 @VisibleForTesting isWideColorGamut()83 boolean isWideColorGamut() { 84 return mContext.getResources().getConfiguration().isScreenWideColorGamut(); 85 } 86 87 @VisibleForTesting getColorModeDescriptionsSize()88 int getColorModeDescriptionsSize() { 89 return ColorModePreference.getColorModeDescriptions(mContext).size(); 90 } 91 } 92