blob: ef4107c2119004d1586190f13c1eaab80a6641f2 [file] [log] [blame]
Lujiang Xue48bca2a2018-02-13 09:23:53 -08001/*
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 */
16package com.android.car.settings.quicksettings;
17
18
19import android.annotation.DrawableRes;
20import android.annotation.Nullable;
21import android.app.UiModeManager;
Lujiang Xue48bca2a2018-02-13 09:23:53 -080022import android.content.Context;
Lujiang Xue48bca2a2018-02-13 09:23:53 -080023import android.graphics.drawable.Drawable;
Lujiang Xue48bca2a2018-02-13 09:23:53 -080024import android.view.View;
Lujiang Xueeaff6c32018-04-10 08:20:29 -070025import android.view.View.OnClickListener;
Lujiang Xue48bca2a2018-02-13 09:23:53 -080026
27import com.android.car.settings.R;
Lujiang Xue48bca2a2018-02-13 09:23:53 -080028
29/**
30 * Controls Day night mode tile on quick setting page.
31 */
32public 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
Lujiang Xueeaff6c32018-04-10 08:20:29 -070040 private final String mText;
Lujiang Xue48bca2a2018-02-13 09:23:53 -080041
42 private State mState = State.ON;
43
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) {
Lujiang Xue48bca2a2018-02-13 09:23:53 -080049 mState = State.ON;
Lujiang Xueeaff6c32018-04-10 08:20:29 -070050 } else {
51 mState = State.OFF;
Lujiang Xue48bca2a2018-02-13 09:23:53 -080052 }
Lujiang Xueeaff6c32018-04-10 08:20:29 -070053 mText = mContext.getString(R.string.night_mode_tile_label);
54 }
55
56 @Nullable
57 public OnClickListener getDeepDiveListener() {
58 return null;
59 }
60
61 @Override
62 public boolean isAvailable() {
63 return true;
Lujiang Xue48bca2a2018-02-13 09:23:53 -080064 }
65
66 @Override
67 public Drawable getIcon() {
68 return mContext.getDrawable(mIconRes);
69 }
70
71 @Override
72 @Nullable
73 public String getText() {
74 return mText;
75 }
76
77 @Override
78 public State getState() {
79 return mState;
80 }
81
82 @Override
83 public void stop() {
84 }
85
86 @Override
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}