blob: 6f65b081afc403cc9b8e7fa7d1077a5a41bdc4a0 [file] [log] [blame]
John Spurlock3346a802014-05-20 16:25:37 -04001/*
2 * Copyright (C) 2014 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
John Spurlockcdb57ae2015-02-11 19:04:11 -050017package com.android.systemui.volume;
18
John Spurlockcdb57ae2015-02-11 19:04:11 -050019import android.content.res.Configuration;
John Spurlockcdb57ae2015-02-11 19:04:11 -050020import android.os.Handler;
John Spurlockcdb57ae2015-02-11 19:04:11 -050021import android.util.Log;
22
23import com.android.systemui.R;
24import com.android.systemui.SystemUI;
John Spurlock3c4076a2015-02-24 12:12:25 -050025import com.android.systemui.qs.tiles.DndTile;
John Spurlockcdb57ae2015-02-11 19:04:11 -050026import com.android.systemui.statusbar.policy.ZenModeController;
27import com.android.systemui.statusbar.policy.ZenModeControllerImpl;
28
29import java.io.FileDescriptor;
30import java.io.PrintWriter;
31
John Spurlock3346a802014-05-20 16:25:37 -040032public class VolumeUI extends SystemUI {
33 private static final String TAG = "VolumeUI";
John Spurlockcdb57ae2015-02-11 19:04:11 -050034 private static boolean LOGD = Log.isLoggable(TAG, Log.DEBUG);
John Spurlock3346a802014-05-20 16:25:37 -040035
John Spurlock86005342014-05-23 11:58:00 -040036 private final Handler mHandler = new Handler();
John Spurlock1dad2722014-07-11 11:07:53 -040037
John Spurlockf2565a82014-10-23 20:16:22 -040038 private boolean mEnabled;
John Spurlock90be3792015-04-16 12:09:15 -040039 private VolumeDialogComponent mVolumeComponent;
John Spurlock3346a802014-05-20 16:25:37 -040040
41 @Override
42 public void start() {
Luke Songe0036662017-12-12 12:27:08 -080043 boolean enableVolumeUi = mContext.getResources().getBoolean(R.bool.enable_volume_ui);
44 boolean enableSafetyWarning =
45 mContext.getResources().getBoolean(R.bool.enable_safety_warning);
46 mEnabled = enableVolumeUi || enableSafetyWarning;
John Spurlockf2565a82014-10-23 20:16:22 -040047 if (!mEnabled) return;
Jason Monk9c7844c2017-01-18 15:21:53 -050048 mVolumeComponent = new VolumeDialogComponent(this, mContext, null);
Luke Songe0036662017-12-12 12:27:08 -080049 mVolumeComponent.setEnableDialogs(enableVolumeUi, enableSafetyWarning);
John Spurlockf88d8082015-03-25 18:09:51 -040050 putComponent(VolumeComponent.class, getVolumeComponent());
Julia Reynoldsbb983d202017-01-06 09:54:20 -050051 setDefaultVolumeController();
John Spurlock3346a802014-05-20 16:25:37 -040052 }
53
John Spurlockf88d8082015-03-25 18:09:51 -040054 private VolumeComponent getVolumeComponent() {
John Spurlock90be3792015-04-16 12:09:15 -040055 return mVolumeComponent;
John Spurlockf88d8082015-03-25 18:09:51 -040056 }
57
John Spurlockad494bc2014-07-19 15:56:19 -040058 @Override
John Spurlock7e6809a2014-08-06 16:03:14 -040059 protected void onConfigurationChanged(Configuration newConfig) {
60 super.onConfigurationChanged(newConfig);
John Spurlockf88d8082015-03-25 18:09:51 -040061 if (!mEnabled) return;
62 getVolumeComponent().onConfigurationChanged(newConfig);
John Spurlock7e6809a2014-08-06 16:03:14 -040063 }
64
65 @Override
John Spurlockad494bc2014-07-19 15:56:19 -040066 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
John Spurlockf2565a82014-10-23 20:16:22 -040067 pw.print("mEnabled="); pw.println(mEnabled);
John Spurlockf88d8082015-03-25 18:09:51 -040068 if (!mEnabled) return;
John Spurlockf88d8082015-03-25 18:09:51 -040069 getVolumeComponent().dump(fd, pw, args);
John Spurlockad494bc2014-07-19 15:56:19 -040070 }
71
Julia Reynoldsbb983d202017-01-06 09:54:20 -050072 private void setDefaultVolumeController() {
73 DndTile.setVisible(mContext, true);
74 if (LOGD) Log.d(TAG, "Registering default volume controller");
75 getVolumeComponent().register();
John Spurlockcdb57ae2015-02-11 19:04:11 -050076 }
John Spurlock3346a802014-05-20 16:25:37 -040077}