• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.car.settings.quicksettings;
17 
18 
19 import android.annotation.DrawableRes;
20 import android.annotation.Nullable;
21 import android.app.UiModeManager;
22 import android.content.Context;
23 import android.graphics.drawable.Drawable;
24 import android.view.View;
25 import android.view.View.OnClickListener;
26 
27 import com.android.car.settings.R;
28 
29 /**
30  * Controls Day night mode tile on quick setting page.
31  */
32 public class DayNightTile implements QuickSettingGridAdapter.Tile {
33     private final Context mContext;
34     private final StateChangedListener mStateChangedListener;
35     private final UiModeManager mUiModeManager;
36 
37     @DrawableRes
38     private int mIconRes = R.drawable.ic_settings_night_display;
39 
40     private final String mText;
41 
42     private State mState = State.ON;
43 
DayNightTile(Context context, StateChangedListener stateChangedListener)44     DayNightTile(Context context, StateChangedListener stateChangedListener) {
45         mStateChangedListener = stateChangedListener;
46         mContext = context;
47         mUiModeManager = (UiModeManager) mContext.getSystemService(Context.UI_MODE_SERVICE);
48         if (mUiModeManager.getNightMode() == UiModeManager.MODE_NIGHT_YES) {
49             mState = State.ON;
50         } else {
51             mState = State.OFF;
52         }
53         mText = mContext.getString(R.string.night_mode_tile_label);
54     }
55 
56     @Nullable
getDeepDiveListener()57     public OnClickListener getDeepDiveListener() {
58         return null;
59     }
60 
61     @Override
isAvailable()62     public boolean isAvailable() {
63         return true;
64     }
65 
66     @Override
getIcon()67     public Drawable getIcon() {
68         return mContext.getDrawable(mIconRes);
69     }
70 
71     @Override
72     @Nullable
getText()73     public String getText() {
74         return mText;
75     }
76 
77     @Override
getState()78     public State getState() {
79         return mState;
80     }
81 
82     @Override
stop()83     public void stop() {
84     }
85 
86     @Override
onClick(View v)87     public void onClick(View v) {
88         if (mUiModeManager.getNightMode() == UiModeManager.MODE_NIGHT_YES) {
89             mUiModeManager.setNightMode(UiModeManager.MODE_NIGHT_NO);
90         } else {
91             mUiModeManager.setNightMode(UiModeManager.MODE_NIGHT_YES);
92         }
93     }
94 }
95