Home | History | Annotate | Download | only in display
      1 /*
      2  * Copyright (C) 2018 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 static android.provider.Settings.Secure.THEME_MODE;
     20 
     21 import android.content.Context;
     22 import android.provider.Settings;
     23 import android.support.v7.preference.ListPreference;
     24 import android.support.v7.preference.Preference;
     25 import android.support.v7.preference.PreferenceScreen;
     26 import android.util.FeatureFlagUtils;
     27 
     28 import com.android.settings.core.BasePreferenceController;
     29 import com.android.settings.core.PreferenceControllerMixin;
     30 import com.android.settingslib.core.AbstractPreferenceController;
     31 
     32 /**
     33  * Setting where user can pick if SystemUI will be light, dark or try to match
     34  * the wallpaper colors.
     35  */
     36 public class SystemUiThemePreferenceController extends BasePreferenceController
     37         implements Preference.OnPreferenceChangeListener {
     38 
     39     private ListPreference mSystemUiThemePref;
     40 
     41     public SystemUiThemePreferenceController(Context context, String preferenceKey) {
     42         super(context, preferenceKey);
     43     }
     44 
     45     @Override
     46     public int getAvailabilityStatus() {
     47         boolean enabled = FeatureFlagUtils.isEnabled(mContext, "settings_systemui_theme");
     48         return enabled ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
     49     }
     50 
     51     @Override
     52     public void displayPreference(PreferenceScreen screen) {
     53         super.displayPreference(screen);
     54         mSystemUiThemePref = (ListPreference) screen.findPreference(getPreferenceKey());
     55         int value = Settings.Secure.getInt(mContext.getContentResolver(), THEME_MODE, 0);
     56         mSystemUiThemePref.setValue(Integer.toString(value));
     57     }
     58 
     59     @Override
     60     public boolean onPreferenceChange(Preference preference, Object newValue) {
     61         int value = Integer.parseInt((String) newValue);
     62         Settings.Secure.putInt(mContext.getContentResolver(), THEME_MODE, value);
     63         refreshSummary(preference);
     64         return true;
     65     }
     66 
     67     @Override
     68     public CharSequence getSummary() {
     69         int value = Settings.Secure.getInt(mContext.getContentResolver(), THEME_MODE, 0);
     70         int index = mSystemUiThemePref.findIndexOfValue(Integer.toString(value));
     71         return mSystemUiThemePref.getEntries()[index];
     72     }
     73 }
     74