• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.content.Intent;
20 import android.graphics.drawable.Drawable;
21 
22 import com.android.internal.app.ColorDisplayController;
23 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
24 import com.android.settings.R;
25 import com.android.settings.core.SubSettingLauncher;
26 import com.android.settings.display.NightDisplaySettings;
27 
28 public final class NightDisplayCondition extends Condition
29         implements ColorDisplayController.Callback {
30 
31     private ColorDisplayController mController;
32 
NightDisplayCondition(ConditionManager manager)33     NightDisplayCondition(ConditionManager manager) {
34         super(manager);
35         mController = new ColorDisplayController(manager.getContext());
36         mController.setListener(this);
37     }
38 
39     @Override
getMetricsConstant()40     public int getMetricsConstant() {
41         return MetricsEvent.SETTINGS_CONDITION_NIGHT_DISPLAY;
42     }
43 
44     @Override
getIcon()45     public Drawable getIcon() {
46         return mManager.getContext().getDrawable(R.drawable.ic_settings_night_display);
47     }
48 
49     @Override
getTitle()50     public CharSequence getTitle() {
51         return mManager.getContext().getString(R.string.condition_night_display_title);
52     }
53 
54     @Override
getSummary()55     public CharSequence getSummary() {
56         return mManager.getContext().getString(R.string.condition_night_display_summary);
57     }
58 
59     @Override
getActions()60     public CharSequence[] getActions() {
61         return new CharSequence[] {mManager.getContext().getString(R.string.condition_turn_off)};
62     }
63 
64     @Override
onPrimaryClick()65     public void onPrimaryClick() {
66         new SubSettingLauncher(mManager.getContext())
67                 .setDestination(NightDisplaySettings.class.getName())
68                 .setSourceMetricsCategory(MetricsEvent.DASHBOARD_SUMMARY)
69                 .setTitle(R.string.night_display_title)
70                 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
71                 .launch();
72     }
73 
74     @Override
onActionClick(int index)75     public void onActionClick(int index) {
76         if (index == 0) {
77             mController.setActivated(false);
78         } else {
79             throw new IllegalArgumentException("Unexpected index " + index);
80         }
81     }
82 
83     @Override
refreshState()84     public void refreshState() {
85         setActive(mController.isActivated());
86     }
87 
88     @Override
onActivated(boolean activated)89     public void onActivated(boolean activated) {
90         refreshState();
91     }
92 }
93