1 /* 2 * Copyright (C) 2016 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.dashboard.conditional; 18 19 import android.graphics.drawable.Icon; 20 21 import com.android.internal.app.NightDisplayController; 22 import com.android.internal.logging.nano.MetricsProto.MetricsEvent; 23 import com.android.settings.R; 24 import com.android.settings.Utils; 25 import com.android.settings.display.NightDisplaySettings; 26 27 public final class NightDisplayCondition extends Condition 28 implements NightDisplayController.Callback { 29 30 private NightDisplayController mController; 31 NightDisplayCondition(ConditionManager manager)32 NightDisplayCondition(ConditionManager manager) { 33 super(manager); 34 mController = new NightDisplayController(manager.getContext()); 35 mController.setListener(this); 36 } 37 38 @Override getMetricsConstant()39 public int getMetricsConstant() { 40 return MetricsEvent.SETTINGS_CONDITION_NIGHT_DISPLAY; 41 } 42 43 @Override getIcon()44 public Icon getIcon() { 45 return Icon.createWithResource(mManager.getContext(), R.drawable.ic_settings_night_display); 46 } 47 48 @Override getTitle()49 public CharSequence getTitle() { 50 return mManager.getContext().getString(R.string.condition_night_display_title); 51 } 52 53 @Override getSummary()54 public CharSequence getSummary() { 55 return mManager.getContext().getString(R.string.condition_night_display_summary); 56 } 57 58 @Override getActions()59 public CharSequence[] getActions() { 60 return new CharSequence[] { mManager.getContext().getString(R.string.condition_turn_off) }; 61 } 62 63 @Override onPrimaryClick()64 public void onPrimaryClick() { 65 Utils.startWithFragment(mManager.getContext(), NightDisplaySettings.class.getName(), null, 66 null, 0, R.string.night_display_title, null, MetricsEvent.DASHBOARD_SUMMARY); 67 } 68 69 @Override onActionClick(int index)70 public void onActionClick(int index) { 71 if (index == 0) { 72 mController.setActivated(false); 73 } else { 74 throw new IllegalArgumentException("Unexpected index " + index); 75 } 76 } 77 78 @Override refreshState()79 public void refreshState() { 80 setActive(mController.isActivated()); 81 } 82 83 @Override onActivated(boolean activated)84 public void onActivated(boolean activated) { 85 refreshState(); 86 } 87 } 88